From ad197828299502abd31ed3cdd5a4427da745f686 Mon Sep 17 00:00:00 2001 From: Mattes Mohr Date: Wed, 4 Jan 2023 22:03:46 +0100 Subject: [PATCH] Upgrade the package (#115) * Remove deprecations * Remove the tag helpers * Bump the minimum swift version to 5.7 * Remove the tag helper tests * Remove the statements and conditions * Remove the current rendering The rendering should managed centrally and internally. * Remove the context management * Remove the pre-rendering parts * Revise the renderer * Remove the definable protocol * Fix build failing * Revise the vapor provider * Revise the renderer and the provider to work with localization * Remove the other layouts * Rename the anyattribute protocol * Rename the anycontent protocol * Rename the anyelement protocol * Rename the anynode protocol * Abstract the global attributes into the nodes protocols * Extend the contentbuilder to work with the native statements * Fix component tests failing * Revise the content builder * Revise the onhover method * Add event modifiers and actions to the components * Revise the event modifiers from yesterday * Revise the class modifiers * Rename and move the event modifiers * Revert the abstraction of the global attributes * Add a custom element If an element is new or not yet implemented, the custom element can be used as a workaround. * Add vectorelement to the globalelement alias * Add a symbol component * Revise an javascript method * Add a modal component * Distinguish an actionbutton from a linkbutton * Revise the collection component * Extend the form component to accept the method as parameter * Merge the different buttons into one * Add a card component * Refactor some code * Revise the environment handling * Add a test to test the environment integration on the vapor layer * Fix test failing * Update the documentation --- .github/workflows/test.yml | 2 +- Package.swift | 2 +- .../Attributes/AriaAttributes.swift | 506 +- .../Attributes/BasicAttributes.swift | 1147 ++--- .../Attributes/EventAttributes.swift | 26 +- .../Attributes/VectorAttributes.swift | 96 +- .../Abstraction/Elements/BasicElements.swift | 115 +- .../Abstraction/Elements/BodyElements.swift | 4263 +++-------------- .../Elements/DefinitionElements.swift | 108 +- .../Abstraction/Elements/FigureElements.swift | 54 +- .../Abstraction/Elements/FormElements.swift | 362 +- .../Abstraction/Elements/HeadElements.swift | 262 +- .../Abstraction/Elements/HtmlElements.swift | 96 +- .../Abstraction/Elements/InputElements.swift | 214 +- .../Abstraction/Elements/ListElements.swift | 58 +- .../Abstraction/Elements/MapElements.swift | 58 +- .../Abstraction/Elements/MediaElements.swift | 101 +- .../Abstraction/Elements/ObjectElements.swift | 56 +- .../Abstraction/Elements/RubyElements.swift | 108 +- .../Abstraction/Elements/TableElements.swift | 492 +- .../Abstraction/Elements/VectorElements.swift | 426 +- .../Abstraction/Helpers/TagHelpers.swift | 272 -- .../Core/Builders/ContentBuilder.swift | 116 +- .../Core/Extensions/Datatypes+Content.swift | 376 +- .../{AnyAttribute.swift => Attribute.swift} | 20 +- .../Core/Primitives/Elements/AnyElement.swift | 8 - .../Core/Primitives/Elements/Element.swift | 23 + .../Core/Primitives/Elements/Elements.swift | 32 +- .../Core/Primitives/Layouts/AnyLayout.swift | 25 - .../Core/Primitives/Layouts/Layouts.swift | 13 +- .../Nodes/{AnyNode.swift => Node.swift} | 2 +- .../Core/Primitives/Nodes/Nodes.swift | 349 +- .../Core/Primitives/Shared/AnyContent.swift | 54 - .../Core/Primitives/Shared/Content.swift | 9 + .../Core/Primitives/Shared/Defineable.swift | 5 - .../Primitives/Statements/Conditionable.swift | 21 - .../Primitives/Statements/Conditions.swift | 259 - .../Annotations/ContextManager.swift | 85 - .../Annotations/DateVariable.swift | 84 - .../Annotations/EscapingOption.swift | 24 - .../Environment/Annotations/HTMLContext.swift | 121 - .../Annotations/TemplateValue.swift | 265 - .../Localization/EnvironmentModifier.swift | 37 - .../Localization/Localizable.swift | 6 +- .../Localization/Localization.swift | 30 - .../Environment/Localization/Localized.swift | 65 - .../Localization/LocalizedStringKey.swift | 21 + .../Statements/BranchStatements.swift | 144 - .../Statements/LoopStatements.swift | 146 - .../Statements/OptionalChaining.swift | 59 - .../Environment/Storage/Environment.swift | 17 + .../Environment/Storage/EnvironmentKeys.swift | 12 + .../Storage/EnvironmentModifier.swift | 25 + .../Storage/EnvironmentObject.swift | 64 + .../Storage/EnvironmentValue.swift | 18 + .../Environment/Storage/Manager.swift | 29 + .../Framework/Rendering/Caching/Cache.swift | 29 - .../HTMLKit/Framework/Rendering/Formula.swift | 43 - .../Framework/Rendering/Renderer.swift | 380 +- .../HTMLKit.docc/Essentials/GettingStarted.md | 19 +- .../Essentials/VaporIntegration.md | 31 +- .../HTMLKit.docc/Framework/Components.md | 41 +- .../Components/{ResetButton.md => Button.md} | 8 +- .../HTMLKit.docc/Framework/Components/Card.md | 16 + .../Framework/Components/CheckField.md | 2 +- .../Framework/Components/DatePicker.md | 2 +- .../Framework/Components/Divider.md | 2 +- .../Framework/Components/FieldLabel.md | 2 +- .../HTMLKit.docc/Framework/Components/Form.md | 4 +- .../Components/{Collection.md => Grid.md} | 12 +- .../Framework/Components/HStack.md | 2 +- .../Framework/Components/Image.md | 2 +- .../HTMLKit.docc/Framework/Components/Link.md | 2 +- .../{ActionButton.md => LinkButton.md} | 6 +- .../HTMLKit.docc/Framework/Components/List.md | 2 +- .../Framework/Components/Modal.md | 16 + .../{ProgressView.md => Progress.md} | 6 +- .../Framework/Components/RadioSelect.md | 2 +- .../Framework/Components/SearchField.md | 2 +- .../Framework/Components/SecureField.md | 2 +- .../Framework/Components/SelectField.md | 2 +- .../Framework/Components/Slider.md | 2 +- .../Framework/Components/Snippet.md | 2 +- .../Framework/Components/SubmitButton.md | 27 - .../Framework/Components/Symbol.md | 15 + .../HTMLKit.docc/Framework/Components/Text.md | 2 +- .../Framework/Components/TextEditor.md | 2 +- .../Framework/Components/TextField.md | 2 +- .../Framework/Components/Toggle.md | 2 +- .../Framework/Components/VStack.md | 2 +- .../Framework/Components/ZStack.md | 2 +- .../HTMLKit.docc/Framework/Elements.md | 161 +- .../HTMLKit.docc/Framework/Environment.md | 15 + .../Environment/EnvironmentObject.md | 33 + .../HTMLKit.docc/Framework/Globalization.md | 43 - .../Framework/Globalization/Localization.md | 34 - .../HTMLKit/HTMLKit.docc/Framework/Layouts.md | 88 + .../Framework/{Template => }/Layouts/View.md | 2 +- .../HTMLKit.docc/Framework/Localization.md | 68 + .../HTMLKit.docc/Framework/Statements.md | 29 - .../Framework/Statements/Foreach.md | 16 - .../Framework/Statements/Ifelse.md | 5 - .../Framework/Statements/Unwrap.md | 13 - .../HTMLKit.docc/Framework/Template.md | 34 - .../Template/Annotations/TemplateValue.md | 5 - .../Framework/Template/Context.md | 35 - .../Framework/Template/Layouts.md | 51 - .../Framework/Template/Layouts/Page.md | 25 - Sources/HTMLKit/HTMLKit.docc/HTMLKit.md | 11 +- .../HTMLKit.docc/Plugins/ComponentsPlugin.md | 6 +- .../HTMLKit.docc/Plugins/ConverterPlugin.md | 2 +- Sources/HTMLKitComponents/Actions.swift | 19 +- .../HTMLKitComponents/Components/Button.swift | 203 +- .../HTMLKitComponents/Components/Card.swift | 21 + .../Components/Divider.swift | 4 +- .../HTMLKitComponents/Components/Form.swift | 344 +- .../{Collection.swift => Grid.swift} | 80 +- .../HTMLKitComponents/Components/Group.swift | 69 +- .../HTMLKitComponents/Components/Image.swift | 48 +- .../HTMLKitComponents/Components/Link.swift | 78 +- .../HTMLKitComponents/Components/List.swift | 83 +- .../HTMLKitComponents/Components/Modal.swift | 37 + .../Components/Snippet.swift | 8 +- .../HTMLKitComponents/Components/Stack.swift | 197 +- .../HTMLKitComponents/Components/Symbol.swift | 135 + .../HTMLKitComponents/Components/Text.swift | 127 +- .../HTMLKitComponents/Components/Toggle.swift | 20 +- Sources/HTMLKitComponents/Events.swift | 45 +- .../Modifiers/ButtonModifier.swift | 18 + .../Modifiers/DragModifier.swift | 29 + .../Modifiers/HoverModifier.swift | 29 + .../Modifiers/ImageModifier.swift | 15 + .../Modifiers/InputModifier.swift | 12 + .../Modifiers/PressModifier.swift | 40 + .../Modifiers/TextModifier.swift | 39 + .../Modifiers/ViewModifier.swift | 15 + .../Properties/Actionable.swift | 24 + .../Properties/Identifiable.swift | 23 + .../Properties/Modifiable.swift | 15 + .../Resources/collection.css | 39 - .../Resources/{ => css}/background.css | 0 .../Resources/{ => css}/button.css | 0 .../HTMLKitComponents/Resources/css/card.css | 15 + .../Resources/{ => css}/divider.css | 0 .../Resources/{ => css}/form.css | 0 .../HTMLKitComponents/Resources/css/grid.css | 43 + .../Resources/{ => css}/group.css | 0 .../Resources/{ => css}/image.css | 0 .../Resources/{ => css}/link.css | 0 .../Resources/{ => css}/list.css | 0 .../HTMLKitComponents/Resources/css/modal.css | 18 + .../Resources/{ => css}/roots.css | 47 +- .../Resources/{ => css}/snippet.css | 0 .../Resources/{ => css}/stack.css | 0 .../Resources/css/symbol.css | 100 + .../Resources/{ => css}/text.css | 0 .../Resources/{ => css}/toggle.css | 0 .../Resources/{position.css => css/utils.css} | 6 +- Sources/HTMLKitComponents/Resources/js/all.js | 142 + .../Resources/symbols/folder.svg | 11 + Sources/HTMLKitComponents/Tokens.swift | 7 - .../Extensions/Vapor+HTMLKit.swift | 35 +- Sources/HTMLKitVapor/LingoConfiguration.swift | 5 + Sources/HTMLKitVapor/ViewCache.swift | 50 - Sources/HTMLKitVapor/ViewRenderer.swift | 67 +- .../ComponentTests.swift | 209 +- Tests/HTMLKitTests/AttributesTests.swift | 798 +-- Tests/HTMLKitTests/ComponentTests.swift | 112 - Tests/HTMLKitTests/ConditionsTests.swift | 290 -- Tests/HTMLKitTests/ContextTests.swift | 36 +- Tests/HTMLKitTests/ElementTests.swift | 726 +-- Tests/HTMLKitTests/EnvironmentTests.swift | 61 + Tests/HTMLKitTests/LocalizationTests.swift | 58 +- Tests/HTMLKitTests/Performance/Samples.swift | 15 +- Tests/HTMLKitTests/PerformanceTests.swift | 4 +- Tests/HTMLKitTests/RenderingTests.swift | 86 +- Tests/HTMLKitTests/StatementTests.swift | 99 + Tests/HTMLKitTests/StatementsTests.swift | 199 - Tests/HTMLKitTests/TemplatingTests.swift | 53 +- Tests/HTMLKitVaporTests/ProviderTests.swift | 152 +- 180 files changed, 5091 insertions(+), 12926 deletions(-) delete mode 100644 Sources/HTMLKit/Abstraction/Helpers/TagHelpers.swift rename Sources/HTMLKit/Framework/Core/Primitives/Attributes/{AnyAttribute.swift => Attribute.swift} (66%) delete mode 100644 Sources/HTMLKit/Framework/Core/Primitives/Elements/AnyElement.swift create mode 100644 Sources/HTMLKit/Framework/Core/Primitives/Elements/Element.swift delete mode 100644 Sources/HTMLKit/Framework/Core/Primitives/Layouts/AnyLayout.swift rename Sources/HTMLKit/Framework/Core/Primitives/Nodes/{AnyNode.swift => Node.swift} (87%) delete mode 100644 Sources/HTMLKit/Framework/Core/Primitives/Shared/AnyContent.swift create mode 100644 Sources/HTMLKit/Framework/Core/Primitives/Shared/Content.swift delete mode 100644 Sources/HTMLKit/Framework/Core/Primitives/Shared/Defineable.swift delete mode 100644 Sources/HTMLKit/Framework/Core/Primitives/Statements/Conditionable.swift delete mode 100644 Sources/HTMLKit/Framework/Core/Primitives/Statements/Conditions.swift delete mode 100644 Sources/HTMLKit/Framework/Environment/Annotations/ContextManager.swift delete mode 100644 Sources/HTMLKit/Framework/Environment/Annotations/DateVariable.swift delete mode 100644 Sources/HTMLKit/Framework/Environment/Annotations/EscapingOption.swift delete mode 100644 Sources/HTMLKit/Framework/Environment/Annotations/HTMLContext.swift delete mode 100644 Sources/HTMLKit/Framework/Environment/Annotations/TemplateValue.swift delete mode 100644 Sources/HTMLKit/Framework/Environment/Localization/EnvironmentModifier.swift delete mode 100644 Sources/HTMLKit/Framework/Environment/Localization/Localization.swift delete mode 100644 Sources/HTMLKit/Framework/Environment/Localization/Localized.swift create mode 100644 Sources/HTMLKit/Framework/Environment/Localization/LocalizedStringKey.swift delete mode 100644 Sources/HTMLKit/Framework/Environment/Statements/BranchStatements.swift delete mode 100644 Sources/HTMLKit/Framework/Environment/Statements/LoopStatements.swift delete mode 100644 Sources/HTMLKit/Framework/Environment/Statements/OptionalChaining.swift create mode 100644 Sources/HTMLKit/Framework/Environment/Storage/Environment.swift create mode 100644 Sources/HTMLKit/Framework/Environment/Storage/EnvironmentKeys.swift create mode 100644 Sources/HTMLKit/Framework/Environment/Storage/EnvironmentModifier.swift create mode 100644 Sources/HTMLKit/Framework/Environment/Storage/EnvironmentObject.swift create mode 100644 Sources/HTMLKit/Framework/Environment/Storage/EnvironmentValue.swift create mode 100644 Sources/HTMLKit/Framework/Environment/Storage/Manager.swift delete mode 100644 Sources/HTMLKit/Framework/Rendering/Caching/Cache.swift delete mode 100644 Sources/HTMLKit/Framework/Rendering/Formula.swift rename Sources/HTMLKit/HTMLKit.docc/Framework/Components/{ResetButton.md => Button.md} (81%) create mode 100644 Sources/HTMLKit/HTMLKit.docc/Framework/Components/Card.md rename Sources/HTMLKit/HTMLKit.docc/Framework/Components/{Collection.md => Grid.md} (53%) rename Sources/HTMLKit/HTMLKit.docc/Framework/Components/{ActionButton.md => LinkButton.md} (79%) create mode 100644 Sources/HTMLKit/HTMLKit.docc/Framework/Components/Modal.md rename Sources/HTMLKit/HTMLKit.docc/Framework/Components/{ProgressView.md => Progress.md} (57%) delete mode 100644 Sources/HTMLKit/HTMLKit.docc/Framework/Components/SubmitButton.md create mode 100644 Sources/HTMLKit/HTMLKit.docc/Framework/Components/Symbol.md create mode 100644 Sources/HTMLKit/HTMLKit.docc/Framework/Environment.md create mode 100644 Sources/HTMLKit/HTMLKit.docc/Framework/Environment/EnvironmentObject.md delete mode 100644 Sources/HTMLKit/HTMLKit.docc/Framework/Globalization.md delete mode 100644 Sources/HTMLKit/HTMLKit.docc/Framework/Globalization/Localization.md create mode 100644 Sources/HTMLKit/HTMLKit.docc/Framework/Layouts.md rename Sources/HTMLKit/HTMLKit.docc/Framework/{Template => }/Layouts/View.md (91%) create mode 100644 Sources/HTMLKit/HTMLKit.docc/Framework/Localization.md delete mode 100644 Sources/HTMLKit/HTMLKit.docc/Framework/Statements.md delete mode 100644 Sources/HTMLKit/HTMLKit.docc/Framework/Statements/Foreach.md delete mode 100644 Sources/HTMLKit/HTMLKit.docc/Framework/Statements/Ifelse.md delete mode 100644 Sources/HTMLKit/HTMLKit.docc/Framework/Statements/Unwrap.md delete mode 100644 Sources/HTMLKit/HTMLKit.docc/Framework/Template.md delete mode 100644 Sources/HTMLKit/HTMLKit.docc/Framework/Template/Annotations/TemplateValue.md delete mode 100644 Sources/HTMLKit/HTMLKit.docc/Framework/Template/Context.md delete mode 100644 Sources/HTMLKit/HTMLKit.docc/Framework/Template/Layouts.md delete mode 100644 Sources/HTMLKit/HTMLKit.docc/Framework/Template/Layouts/Page.md create mode 100644 Sources/HTMLKitComponents/Components/Card.swift rename Sources/HTMLKitComponents/Components/{Collection.swift => Grid.swift} (55%) create mode 100644 Sources/HTMLKitComponents/Components/Modal.swift create mode 100644 Sources/HTMLKitComponents/Components/Symbol.swift create mode 100644 Sources/HTMLKitComponents/Modifiers/DragModifier.swift create mode 100644 Sources/HTMLKitComponents/Modifiers/HoverModifier.swift create mode 100644 Sources/HTMLKitComponents/Modifiers/PressModifier.swift create mode 100644 Sources/HTMLKitComponents/Properties/Actionable.swift create mode 100644 Sources/HTMLKitComponents/Properties/Identifiable.swift create mode 100644 Sources/HTMLKitComponents/Properties/Modifiable.swift delete mode 100644 Sources/HTMLKitComponents/Resources/collection.css rename Sources/HTMLKitComponents/Resources/{ => css}/background.css (100%) rename Sources/HTMLKitComponents/Resources/{ => css}/button.css (100%) create mode 100644 Sources/HTMLKitComponents/Resources/css/card.css rename Sources/HTMLKitComponents/Resources/{ => css}/divider.css (100%) rename Sources/HTMLKitComponents/Resources/{ => css}/form.css (100%) create mode 100644 Sources/HTMLKitComponents/Resources/css/grid.css rename Sources/HTMLKitComponents/Resources/{ => css}/group.css (100%) rename Sources/HTMLKitComponents/Resources/{ => css}/image.css (100%) rename Sources/HTMLKitComponents/Resources/{ => css}/link.css (100%) rename Sources/HTMLKitComponents/Resources/{ => css}/list.css (100%) create mode 100644 Sources/HTMLKitComponents/Resources/css/modal.css rename Sources/HTMLKitComponents/Resources/{ => css}/roots.css (84%) rename Sources/HTMLKitComponents/Resources/{ => css}/snippet.css (100%) rename Sources/HTMLKitComponents/Resources/{ => css}/stack.css (100%) create mode 100644 Sources/HTMLKitComponents/Resources/css/symbol.css rename Sources/HTMLKitComponents/Resources/{ => css}/text.css (100%) rename Sources/HTMLKitComponents/Resources/{ => css}/toggle.css (100%) rename Sources/HTMLKitComponents/Resources/{position.css => css/utils.css} (80%) create mode 100644 Sources/HTMLKitComponents/Resources/js/all.js create mode 100644 Sources/HTMLKitComponents/Resources/symbols/folder.svg delete mode 100644 Sources/HTMLKitVapor/ViewCache.swift delete mode 100644 Tests/HTMLKitTests/ComponentTests.swift delete mode 100644 Tests/HTMLKitTests/ConditionsTests.swift create mode 100644 Tests/HTMLKitTests/EnvironmentTests.swift create mode 100644 Tests/HTMLKitTests/StatementTests.swift delete mode 100644 Tests/HTMLKitTests/StatementsTests.swift diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5bcddf99..b41ef696 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,7 +9,7 @@ on: jobs: test-pushpull: runs-on: ubuntu-latest - container: swift:5.6-focal + container: swift:5.7-focal steps: - uses: actions/checkout@v3 - name: Run tests diff --git a/Package.swift b/Package.swift index 03c2285e..d97ee005 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.6 +// swift-tools-version:5.7 import PackageDescription diff --git a/Sources/HTMLKit/Abstraction/Attributes/AriaAttributes.swift b/Sources/HTMLKit/Abstraction/Attributes/AriaAttributes.swift index 3265f0fc..d85672c9 100644 --- a/Sources/HTMLKit/Abstraction/Attributes/AriaAttributes.swift +++ b/Sources/HTMLKit/Abstraction/Attributes/AriaAttributes.swift @@ -9,7 +9,7 @@ public typealias GlobalAriaAttributes = AriaAtomicAttribute & AriaBusyAttribute & AriaControlsAttribute & AriaCurrentAttribute & AriaDescribedAttribute & AriaDetailsAttribute & AriaDisabledAttribute & AriaErrorMessageAttribute & AriaFlowToAttribute & AriaPopupAttribute & AriaHiddenAttribute & AriaInvalidAttribute & AriaShortcutsAttribute & AriaLabelAttribute & AriaLabeledAttribute & AriaLiveAttribute & AriaOwnsAttribute & AriaRelevantAttribute & AriaRoleDescriptionAttribute /// The protocol provides the element with accessibility handler. -public protocol AriaActiveDescendantAttribute: AnyAttribute { +public protocol AriaActiveDescendantAttribute: Attribute { /// The function represents the html-attribute 'aria-activedescendant'. /// @@ -19,28 +19,23 @@ public protocol AriaActiveDescendantAttribute: AnyAttribute { func aria(activeDescendant value: String) -> Self } -extension AriaActiveDescendantAttribute { - - internal var key: String { "aria-activedescendant" } -} - extension AriaActiveDescendantAttribute where Self: ContentNode { internal func mutate(ariaactivedescendant value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-activedescendant", value: value) } } extension AriaActiveDescendantAttribute where Self: EmptyNode { internal func mutate(ariaactivedescendant value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-activedescendant", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaAtomicAttribute: AnyAttribute { +public protocol AriaAtomicAttribute: Attribute { /// The function represents the html-attribute 'aria-atomic'. /// @@ -50,27 +45,22 @@ public protocol AriaAtomicAttribute: AnyAttribute { func aria(atomic value: Bool) -> Self } -extension AriaAtomicAttribute { - - internal var key: String { "aria-atomic" } -} - extension AriaAtomicAttribute where Self: ContentNode { internal func mutate(ariaatomic value: Bool) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-atomic", value: value) } } extension AriaAtomicAttribute where Self: EmptyNode { internal func mutate(ariaatomic value: Bool) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-atomic", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaAutoCompleteAttribute: AnyAttribute { +public protocol AriaAutoCompleteAttribute: Attribute { /// The function represents the html-attribute 'aria-autocomplete'. /// @@ -80,27 +70,22 @@ public protocol AriaAutoCompleteAttribute: AnyAttribute { func aria(autoComplete value: Values.Accessibility.Complete) -> Self } -extension AriaAutoCompleteAttribute { - - internal var key: String { "aria-autocomplete" } -} - extension AriaAutoCompleteAttribute where Self: ContentNode { internal func mutate(ariaautocomplete value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-autocomplete", value: value) } } extension AriaAutoCompleteAttribute where Self: EmptyNode { internal func mutate(ariaautocomplete value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-autocomplete", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaBusyAttribute: AnyAttribute { +public protocol AriaBusyAttribute: Attribute { /// The function represents the html-attribute 'aria-busy'. /// @@ -110,27 +95,22 @@ public protocol AriaBusyAttribute: AnyAttribute { func aria(busy value: Bool) -> Self } -extension AriaBusyAttribute { - - internal var key: String { "aria-busy" } -} - extension AriaBusyAttribute where Self: ContentNode { internal func mutate(ariabusy value: Bool) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-busy", value: value) } } extension AriaBusyAttribute where Self: EmptyNode { internal func mutate(ariabusy value: Bool) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-busy", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaCheckedAttribute: AnyAttribute { +public protocol AriaCheckedAttribute: Attribute { /// The function represents the html-attribute 'aria-checked'. /// @@ -140,27 +120,22 @@ public protocol AriaCheckedAttribute: AnyAttribute { func aria(checked value: Values.Accessibility.Check) -> Self } -extension AriaCheckedAttribute { - - internal var key: String { "aria-checked" } -} - extension AriaCheckedAttribute where Self: ContentNode { internal func mutate(ariachecked value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-checked", value: value) } } extension AriaCheckedAttribute where Self: EmptyNode { internal func mutate(ariachecked value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-checked", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaColumnCountAttribute: AnyAttribute { +public protocol AriaColumnCountAttribute: Attribute { /// The function represents the html-attribute 'aria-colcount'. /// @@ -170,27 +145,22 @@ public protocol AriaColumnCountAttribute: AnyAttribute { func aria(columnCount value: Int) -> Self } -extension AriaColumnCountAttribute { - - internal var key: String { "aria-colcount" } -} - extension AriaColumnCountAttribute where Self: ContentNode { internal func mutate(ariacolcount value: Int) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-colcount", value: value) } } extension AriaColumnCountAttribute where Self: EmptyNode { internal func mutate(ariacolcount value: Int) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-colcount", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaColumnIndexAttribute: AnyAttribute { +public protocol AriaColumnIndexAttribute: Attribute { /// The function represents the html-attribute 'aria-colindex'. /// @@ -200,27 +170,22 @@ public protocol AriaColumnIndexAttribute: AnyAttribute { func aria(columnIndex value: Int) -> Self } -extension AriaColumnIndexAttribute { - - internal var key: String { "aria-colindex" } -} - extension AriaColumnIndexAttribute where Self: ContentNode { internal func mutate(ariacolindex value: Int) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-colindex", value: value) } } extension AriaColumnIndexAttribute where Self: EmptyNode { internal func mutate(ariacolindex value: Int) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-colindex", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaColumnSpanAttribute: AnyAttribute { +public protocol AriaColumnSpanAttribute: Attribute { /// The function represents the html-attribute 'aria-colspan'. /// @@ -230,27 +195,22 @@ public protocol AriaColumnSpanAttribute: AnyAttribute { func aria(columnSpan value: Int) -> Self } -extension AriaColumnSpanAttribute { - - internal var key: String { "aria-colspan" } -} - extension AriaColumnSpanAttribute where Self: ContentNode { internal func mutate(ariacolspan value: Int) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-colspan", value: value) } } extension AriaColumnSpanAttribute where Self: EmptyNode { internal func mutate(ariacolspan value: Int) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-colspan", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaControlsAttribute: AnyAttribute { +public protocol AriaControlsAttribute: Attribute { /// The function represents the html-attribute 'aria-controls'. /// @@ -260,27 +220,22 @@ public protocol AriaControlsAttribute: AnyAttribute { func aria(controls value: String) -> Self } -extension AriaControlsAttribute { - - internal var key: String { "aria-controls" } -} - extension AriaControlsAttribute where Self: ContentNode { internal func mutate(ariacontrols value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-controls", value: value) } } extension AriaControlsAttribute where Self: EmptyNode { internal func mutate(ariacontrols value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-controls", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaCurrentAttribute: AnyAttribute { +public protocol AriaCurrentAttribute: Attribute { /// The function represents the html-attribute 'aria-current'. /// @@ -290,27 +245,22 @@ public protocol AriaCurrentAttribute: AnyAttribute { func aria(current value: Values.Accessibility.Current) -> Self } -extension AriaCurrentAttribute { - - internal var key: String { "aria-current" } -} - extension AriaCurrentAttribute where Self: ContentNode { internal func mutate(ariacurrent value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-current", value: value) } } extension AriaCurrentAttribute where Self: EmptyNode { internal func mutate(ariacurrent value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-current", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaDescribedAttribute: AnyAttribute { +public protocol AriaDescribedAttribute: Attribute { /// The function represents the html-attribute 'aria-describedby'. /// @@ -320,27 +270,22 @@ public protocol AriaDescribedAttribute: AnyAttribute { func aria(describedBy value: String) -> Self } -extension AriaDescribedAttribute { - - internal var key: String { "aria-describedby" } -} - extension AriaDescribedAttribute where Self: ContentNode { internal func mutate(ariadescribedby value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-describedby", value: value) } } extension AriaDescribedAttribute where Self: EmptyNode { internal func mutate(ariadescribedby value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-describedby", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaDetailsAttribute: AnyAttribute { +public protocol AriaDetailsAttribute: Attribute { /// The function represents the html-attribute 'aria-details'. /// @@ -350,27 +295,22 @@ public protocol AriaDetailsAttribute: AnyAttribute { func aria(details value: String) -> Self } -extension AriaDetailsAttribute { - - internal var key: String { "aria-details" } -} - extension AriaDetailsAttribute where Self: ContentNode { internal func mutate(ariadetails value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-details", value: value) } } extension AriaDetailsAttribute where Self: EmptyNode { internal func mutate(ariadetails value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-details", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaDisabledAttribute: AnyAttribute { +public protocol AriaDisabledAttribute: Attribute { /// The function represents the html-attribute 'aria-disabled'. /// @@ -380,27 +320,22 @@ public protocol AriaDisabledAttribute: AnyAttribute { func aria(disabled value: Bool) -> Self } -extension AriaDisabledAttribute { - - internal var key: String { "aria-disabled" } -} - extension AriaDisabledAttribute where Self: ContentNode { internal func mutate(ariadisabled value: Bool) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-disabled", value: value) } } extension AriaDisabledAttribute where Self: EmptyNode { internal func mutate(ariadisabled value: Bool) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-disabled", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaErrorMessageAttribute: AnyAttribute { +public protocol AriaErrorMessageAttribute: Attribute { /// The function represents the html-attribute 'aria-errormessage'. /// @@ -410,27 +345,22 @@ public protocol AriaErrorMessageAttribute: AnyAttribute { func aria(errorMessage value: String) -> Self } -extension AriaErrorMessageAttribute { - - internal var key: String { "aria-errormessage" } -} - extension AriaErrorMessageAttribute where Self: ContentNode { internal func mutate(ariaerrormessage value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-errormessage", value: value) } } extension AriaErrorMessageAttribute where Self: EmptyNode { internal func mutate(ariaerrormessage value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-errormessage", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaExpandedAttribute: AnyAttribute { +public protocol AriaExpandedAttribute: Attribute { /// The function represents the html-attribute 'aria-expanded'. /// @@ -440,27 +370,22 @@ public protocol AriaExpandedAttribute: AnyAttribute { func aria(expanded value: Bool) -> Self } -extension AriaExpandedAttribute { - - internal var key: String { "aria-expanded" } -} - extension AriaExpandedAttribute where Self: ContentNode { internal func mutate(ariaexpanded value: Bool) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-expanded", value: value) } } extension AriaExpandedAttribute where Self: EmptyNode { internal func mutate(ariaexpanded value: Bool) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-expanded", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaFlowToAttribute: AnyAttribute { +public protocol AriaFlowToAttribute: Attribute { /// The function represents the html-attribute 'aria-flowto'. /// @@ -470,27 +395,22 @@ public protocol AriaFlowToAttribute: AnyAttribute { func aria(flowTo value: String) -> Self } -extension AriaFlowToAttribute { - - internal var key: String { "aria-flowto" } -} - extension AriaFlowToAttribute where Self: ContentNode { internal func mutate(ariaflowto value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-flowto", value: value) } } extension AriaFlowToAttribute where Self: EmptyNode { internal func mutate(ariaflowto value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-flowto", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaPopupAttribute: AnyAttribute { +public protocol AriaPopupAttribute: Attribute { /// The function represents the html-attribute 'aria-haspopup'. /// @@ -500,27 +420,22 @@ public protocol AriaPopupAttribute: AnyAttribute { func aria(hasPopup value: Values.Accessibility.Popup) -> Self } -extension AriaPopupAttribute { - - internal var key: String { "aria-haspopup" } -} - extension AriaPopupAttribute where Self: ContentNode { internal func mutate(ariahaspopup value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-haspopup", value: value) } } extension AriaPopupAttribute where Self: EmptyNode { internal func mutate(ariahaspopup value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-haspopup", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaHiddenAttribute: AnyAttribute { +public protocol AriaHiddenAttribute: Attribute { /// The function represents the html-attribute 'aria-hidden'. /// @@ -530,27 +445,22 @@ public protocol AriaHiddenAttribute: AnyAttribute { func aria(hidden value: Bool) -> Self } -extension AriaHiddenAttribute { - - internal var key: String { "aria-hidden" } -} - extension AriaHiddenAttribute where Self: ContentNode { internal func mutate(ariahidden value: Bool) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-hidden", value: value) } } extension AriaHiddenAttribute where Self: EmptyNode { internal func mutate(ariahidden value: Bool) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-hidden", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaInvalidAttribute: AnyAttribute { +public protocol AriaInvalidAttribute: Attribute { /// The function represents the html-attribute 'aria-invalid'. /// @@ -560,27 +470,22 @@ public protocol AriaInvalidAttribute: AnyAttribute { func aria(invalid value: Values.Accessibility.Invalid) -> Self } -extension AriaInvalidAttribute { - - internal var key: String { "aria-invalid" } -} - extension AriaInvalidAttribute where Self: ContentNode { internal func mutate(ariainvalid value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-invalid", value: value) } } extension AriaInvalidAttribute where Self: EmptyNode { internal func mutate(ariainvalid value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-invalid", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaShortcutsAttribute: AnyAttribute { +public protocol AriaShortcutsAttribute: Attribute { /// The function represents the html-attribute 'aria-keyshortcuts'. /// @@ -590,27 +495,22 @@ public protocol AriaShortcutsAttribute: AnyAttribute { func aria(keyShortcuts value: String) -> Self } -extension AriaShortcutsAttribute { - - internal var key: String { "aria-keyshortcuts" } -} - extension AriaShortcutsAttribute where Self: ContentNode { internal func mutate(ariakeyshortcuts value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-keyshortcuts", value: value) } } extension AriaShortcutsAttribute where Self: EmptyNode { internal func mutate(ariakeyshortcuts value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-keyshortcuts", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaLabelAttribute: AnyAttribute { +public protocol AriaLabelAttribute: Attribute { /// The function represents the html-attribute 'aria-label'. /// @@ -620,27 +520,22 @@ public protocol AriaLabelAttribute: AnyAttribute { func aria(label value: String) -> Self } -extension AriaLabelAttribute { - - internal var key: String { "aria-label" } -} - extension AriaLabelAttribute where Self: ContentNode { internal func mutate(arialabel value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-label", value: value) } } extension AriaLabelAttribute where Self: EmptyNode { internal func mutate(arialabel value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-label", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaLabeledAttribute: AnyAttribute { +public protocol AriaLabeledAttribute: Attribute { /// The function represents the html-attribute 'aria-labeledby'. /// @@ -650,27 +545,22 @@ public protocol AriaLabeledAttribute: AnyAttribute { func aria(labeledBy value: String) -> Self } -extension AriaLabeledAttribute { - - internal var key: String { "aria-labeledby" } -} - extension AriaLabeledAttribute where Self: ContentNode { internal func mutate(arialabeledby value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-labeledby", value: value) } } extension AriaLabeledAttribute where Self: EmptyNode { internal func mutate(arialabeledby value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-labeledby", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaLevelAttribute: AnyAttribute { +public protocol AriaLevelAttribute: Attribute { /// The function represents the html-attribute 'aria-level'. /// @@ -680,27 +570,22 @@ public protocol AriaLevelAttribute: AnyAttribute { func aria(level value: Int) -> Self } -extension AriaLevelAttribute { - - internal var key: String { "aria-level" } -} - extension AriaLevelAttribute where Self: ContentNode { internal func mutate(arialevel value: Int) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-level", value: value) } } extension AriaLevelAttribute where Self: EmptyNode { internal func mutate(arialevel value: Int) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-level", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaLiveAttribute: AnyAttribute { +public protocol AriaLiveAttribute: Attribute { /// The function represents the html-attribute 'aria-live'. /// @@ -710,27 +595,22 @@ public protocol AriaLiveAttribute: AnyAttribute { func aria(live value: Values.Accessibility.Live) -> Self } -extension AriaLiveAttribute { - - internal var key: String { "aria-live" } -} - extension AriaLiveAttribute where Self: ContentNode { internal func mutate(arialive value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-live", value: value) } } extension AriaLiveAttribute where Self: EmptyNode { internal func mutate(arialive value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-live", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaModalAttribute: AnyAttribute { +public protocol AriaModalAttribute: Attribute { /// The function represents the html-attribute 'aria-modal'. /// @@ -740,27 +620,22 @@ public protocol AriaModalAttribute: AnyAttribute { func aria(modal value: Bool) -> Self } -extension AriaModalAttribute { - - internal var key: String { "aria-modal" } -} - extension AriaModalAttribute where Self: ContentNode { internal func mutate(ariamodal value: Bool) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-modal", value: value) } } extension AriaModalAttribute where Self: EmptyNode { internal func mutate(ariamodal value: Bool) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-modal", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaMultilineAttribute: AnyAttribute { +public protocol AriaMultilineAttribute: Attribute { /// The function represents the html-attribute 'aria-multiline'. /// @@ -770,27 +645,22 @@ public protocol AriaMultilineAttribute: AnyAttribute { func aria(multiline value: Bool) -> Self } -extension AriaMultilineAttribute { - - internal var key: String { "aria-multiline" } -} - extension AriaMultilineAttribute where Self: ContentNode { internal func mutate(ariamultiline value: Bool) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-multiline", value: value) } } extension AriaMultilineAttribute where Self: EmptyNode { internal func mutate(ariamultiline value: Bool) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-multiline", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaMultiselectAttribute: AnyAttribute { +public protocol AriaMultiselectAttribute: Attribute { /// The function represents the html-attribute 'aria-multiselectable'. /// @@ -800,27 +670,22 @@ public protocol AriaMultiselectAttribute: AnyAttribute { func aria(multiselectable value: Bool) -> Self } -extension AriaMultiselectAttribute { - - internal var key: String { "aria-multiselectable" } -} - extension AriaMultiselectAttribute where Self: ContentNode { internal func mutate(ariamultiselectable value: Bool) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-multiselectable", value: value) } } extension AriaMultiselectAttribute where Self: EmptyNode { internal func mutate(ariamultiselectable value: Bool) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-multiselectable", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaOrientationAttribute: AnyAttribute { +public protocol AriaOrientationAttribute: Attribute { /// The function represents the html-attribute 'aria-orientation'. /// @@ -830,27 +695,22 @@ public protocol AriaOrientationAttribute: AnyAttribute { func aria(orientation value: Values.Accessibility.Orientation) -> Self } -extension AriaOrientationAttribute { - - internal var key: String { "aria-orientation" } -} - extension AriaOrientationAttribute where Self: ContentNode { internal func mutate(ariaorientation value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-orientation", value: value) } } extension AriaOrientationAttribute where Self: EmptyNode { internal func mutate(ariaorientation value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-orientation", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaOwnsAttribute: AnyAttribute { +public protocol AriaOwnsAttribute: Attribute { /// The function represents the html-attribute 'aria-owns'. /// @@ -860,27 +720,22 @@ public protocol AriaOwnsAttribute: AnyAttribute { func aria(owns value: String) -> Self } -extension AriaOwnsAttribute { - - internal var key: String { "aria-owns" } -} - extension AriaOwnsAttribute where Self: ContentNode { internal func mutate(ariaowns value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-owns", value: value) } } extension AriaOwnsAttribute where Self: EmptyNode { internal func mutate(ariaowns value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-owns", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaPlaceholderAttribute: AnyAttribute { +public protocol AriaPlaceholderAttribute: Attribute { /// The function represents the html-attribute 'aria-placeholder'. /// @@ -890,27 +745,22 @@ public protocol AriaPlaceholderAttribute: AnyAttribute { func aria(placeholder value: String) -> Self } -extension AriaPlaceholderAttribute { - - internal var key: String { "aria-placeholder" } -} - extension AriaPlaceholderAttribute where Self: ContentNode { internal func mutate(ariaplaceholder value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-placeholder", value: value) } } extension AriaPlaceholderAttribute where Self: EmptyNode { internal func mutate(ariaplaceholder value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-placeholder", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaPositionInsetAttribute: AnyAttribute { +public protocol AriaPositionInsetAttribute: Attribute { /// The function represents the html-attribute 'aria-posinset'. /// @@ -920,27 +770,22 @@ public protocol AriaPositionInsetAttribute: AnyAttribute { func aria(positionInset_ value: Int) -> Self } -extension AriaPositionInsetAttribute { - - internal var key: String { "aria-posinset" } -} - extension AriaPositionInsetAttribute where Self: ContentNode { internal func mutate(ariaposinset value: Int) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-posinset", value: value) } } extension AriaPositionInsetAttribute where Self: EmptyNode { internal func mutate(ariaposinset value: Int) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-posinset", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaPressedAttribute: AnyAttribute { +public protocol AriaPressedAttribute: Attribute { /// The function represents the html-attribute 'aria-pressed'. /// @@ -950,27 +795,22 @@ public protocol AriaPressedAttribute: AnyAttribute { func aria(presssed value: Values.Accessibility.Pressed) -> Self } -extension AriaPressedAttribute { - - internal var key: String { "aria-pressed" } -} - extension AriaPressedAttribute where Self: ContentNode { internal func mutate(ariapressed value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-pressed", value: value) } } extension AriaPressedAttribute where Self: EmptyNode { internal func mutate(ariapressed value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-pressed", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaReadonlyAttribute: AnyAttribute { +public protocol AriaReadonlyAttribute: Attribute { /// The function represents the html-attribute 'aria-readonly'. /// @@ -980,27 +820,22 @@ public protocol AriaReadonlyAttribute: AnyAttribute { func aria(readonly value: Bool) -> Self } -extension AriaReadonlyAttribute { - - internal var key: String { "aria-readonly" } -} - extension AriaReadonlyAttribute where Self: ContentNode { internal func mutate(ariareadonly value: Bool) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-readonly", value: value) } } extension AriaReadonlyAttribute where Self: EmptyNode { internal func mutate(ariareadonly value: Bool) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-readonly", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaRelevantAttribute: AnyAttribute { +public protocol AriaRelevantAttribute: Attribute { /// The function represents the html-attribute 'aria-relevant'. /// @@ -1010,27 +845,22 @@ public protocol AriaRelevantAttribute: AnyAttribute { func aria(relevant value: Values.Accessibility.Relevant) -> Self } -extension AriaRelevantAttribute { - - internal var key: String { "aria-relevant" } -} - extension AriaRelevantAttribute where Self: ContentNode { internal func mutate(ariarelevant value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-relevant", value: value) } } extension AriaRelevantAttribute where Self: EmptyNode { internal func mutate(ariarelevant value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-relevant", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaRequiredAttribute: AnyAttribute { +public protocol AriaRequiredAttribute: Attribute { /// The function represents the html-attribute 'aria-required'. /// @@ -1040,27 +870,22 @@ public protocol AriaRequiredAttribute: AnyAttribute { func aria(required value: Bool) -> Self } -extension AriaRequiredAttribute { - - internal var key: String { "aria-required" } -} - extension AriaRequiredAttribute where Self: ContentNode { internal func mutate(ariarequired value: Bool) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-required", value: value) } } extension AriaRequiredAttribute where Self: EmptyNode { internal func mutate(ariarequired value: Bool) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-required", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaRoleDescriptionAttribute: AnyAttribute { +public protocol AriaRoleDescriptionAttribute: Attribute { /// The function represents the html-attribute 'aria-roledescription'. /// @@ -1070,27 +895,22 @@ public protocol AriaRoleDescriptionAttribute: AnyAttribute { func aria(roleDescription value: String) -> Self } -extension AriaRoleDescriptionAttribute { - - internal var key: String { "aria-roledescription" } -} - extension AriaRoleDescriptionAttribute where Self: ContentNode { internal func mutate(ariaroledescription value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-roledescription", value: value) } } extension AriaRoleDescriptionAttribute where Self: EmptyNode { internal func mutate(ariaroledescription value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-roledescription", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaRowCountAttribute: AnyAttribute { +public protocol AriaRowCountAttribute: Attribute { /// The function represents the html-attribute 'aria-rowcount'. /// @@ -1100,27 +920,22 @@ public protocol AriaRowCountAttribute: AnyAttribute { func aria(rowCount value: Int) -> Self } -extension AriaRowCountAttribute { - - internal var key: String { "aria-rowcount" } -} - extension AriaRowCountAttribute where Self: ContentNode { internal func mutate(ariarowcount value: Int) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-rowcount", value: value) } } extension AriaRowCountAttribute where Self: EmptyNode { internal func mutate(ariarowcount value: Int) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-rowcount", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaRowIndexAttribute: AnyAttribute { +public protocol AriaRowIndexAttribute: Attribute { /// The function represents the html-attribute 'aria-rowindex'. /// @@ -1130,27 +945,22 @@ public protocol AriaRowIndexAttribute: AnyAttribute { func aria(rowIndex value: Int) -> Self } -extension AriaRowIndexAttribute { - - internal var key: String { "aria-rowindex" } -} - extension AriaRowIndexAttribute where Self: ContentNode { internal func mutate(ariarowindex value: Int) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-rowindex", value: value) } } extension AriaRowIndexAttribute where Self: EmptyNode { internal func mutate(ariarowindex value: Int) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-rowindex", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaRowSpanAttribute: AnyAttribute { +public protocol AriaRowSpanAttribute: Attribute { /// The function represents the html-attribute 'aria-rowspan'. /// @@ -1160,27 +970,22 @@ public protocol AriaRowSpanAttribute: AnyAttribute { func aria(rowSpan value: Int) -> Self } -extension AriaRowSpanAttribute { - - internal var key: String { "aria-rowspan" } -} - extension AriaRowSpanAttribute where Self: ContentNode { internal func mutate(ariarowspan value: Int) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-rowspan", value: value) } } extension AriaRowSpanAttribute where Self: EmptyNode { internal func mutate(ariarowspan value: Int) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-rowspan", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaSelectedAttribute: AnyAttribute { +public protocol AriaSelectedAttribute: Attribute { /// The function represents the html-attribute 'aria-selected'. /// @@ -1190,27 +995,22 @@ public protocol AriaSelectedAttribute: AnyAttribute { func aria(selected value: Values.Accessibility.Selected) -> Self } -extension AriaSelectedAttribute { - - internal var key: String { "aria-selected" } -} - extension AriaSelectedAttribute where Self: ContentNode { internal func mutate(ariaselected value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-selected", value: value) } } extension AriaSelectedAttribute where Self: EmptyNode { internal func mutate(ariaselected value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-selected", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaSetSizeAttribute: AnyAttribute { +public protocol AriaSetSizeAttribute: Attribute { /// The function represents the html-attribute 'aria-setsize'. /// @@ -1220,27 +1020,22 @@ public protocol AriaSetSizeAttribute: AnyAttribute { func aria(setSize value: Int) -> Self } -extension AriaSetSizeAttribute { - - internal var key: String { "aria-setsize" } -} - extension AriaSetSizeAttribute where Self: ContentNode { internal func mutate(ariasetsize value: Int) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-setsize", value: value) } } extension AriaSetSizeAttribute where Self: EmptyNode { internal func mutate(ariasetsize value: Int) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-setsize", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaSortAttribute: AnyAttribute { +public protocol AriaSortAttribute: Attribute { /// The function represents the html-attribute 'aria-sort'. /// @@ -1250,27 +1045,22 @@ public protocol AriaSortAttribute: AnyAttribute { func aria(sort value: Values.Accessibility.Sort) -> Self } -extension AriaSortAttribute { - - internal var key: String { "aria-sort" } -} - extension AriaSortAttribute where Self: ContentNode { internal func mutate(ariasort value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-sort", value: value) } } extension AriaSortAttribute where Self: EmptyNode { internal func mutate(ariasort value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-sort", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaValueMaximumAttribute: AnyAttribute { +public protocol AriaValueMaximumAttribute: Attribute { /// The function represents the html-attribute 'aria-valuemax'. /// @@ -1280,27 +1070,22 @@ public protocol AriaValueMaximumAttribute: AnyAttribute { func aria(valueMaximum value: Float) -> Self } -extension AriaValueMaximumAttribute { - - internal var key: String { "aria-valuemax" } -} - extension AriaValueMaximumAttribute where Self: ContentNode { internal func mutate(ariavaluemax value: Float) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-valuemax", value: value) } } extension AriaValueMaximumAttribute where Self: EmptyNode { internal func mutate(ariavaluemax value: Float) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-valuemax", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaValueMininumAttribute: AnyAttribute { +public protocol AriaValueMininumAttribute: Attribute { /// The function represents the html-attribute 'aria-valuemin'. /// @@ -1310,27 +1095,22 @@ public protocol AriaValueMininumAttribute: AnyAttribute { func aria(valueMinimum value: Float) -> Self } -extension AriaValueMininumAttribute { - - internal var key: String { "aria-valuemin" } -} - extension AriaValueMininumAttribute where Self: ContentNode { internal func mutate(ariavaluemin value: Float) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-valuemin", value: value) } } extension AriaValueMininumAttribute where Self: EmptyNode { internal func mutate(ariavaluemin value: Float) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-valuemin", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaValueNowAttribute: AnyAttribute { +public protocol AriaValueNowAttribute: Attribute { /// The function represents the html-attribute 'aria-valuenow"'. /// @@ -1340,27 +1120,22 @@ public protocol AriaValueNowAttribute: AnyAttribute { func aria(valueNow value: Float) -> Self } -extension AriaValueNowAttribute { - - internal var key: String { "aria-valuenow" } -} - extension AriaValueNowAttribute where Self: ContentNode { internal func mutate(ariavaluenow value: Float) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-valuenow", value: value) } } extension AriaValueNowAttribute where Self: EmptyNode { internal func mutate(ariavaluenow value: Float) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-valuenow", value: value) } } /// The protocol provides the element with accessibility handler. -public protocol AriaValueTextAttribute: AnyAttribute { +public protocol AriaValueTextAttribute: Attribute { /// The function represents the html-attribute 'aria-valuetext'. /// @@ -1370,21 +1145,16 @@ public protocol AriaValueTextAttribute: AnyAttribute { func aria(valueText value: String) -> Self } -extension AriaValueTextAttribute { - - internal var key: String { "aria-valuetext" } -} - extension AriaValueTextAttribute where Self: ContentNode { internal func mutate(ariavaluetext value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-valuetext", value: value) } } extension AriaValueTextAttribute where Self: EmptyNode { internal func mutate(ariavaluetext value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "aria-valuetext", value: value) } } diff --git a/Sources/HTMLKit/Abstraction/Attributes/BasicAttributes.swift b/Sources/HTMLKit/Abstraction/Attributes/BasicAttributes.swift index cee18181..e510aa45 100644 --- a/Sources/HTMLKit/Abstraction/Attributes/BasicAttributes.swift +++ b/Sources/HTMLKit/Abstraction/Attributes/BasicAttributes.swift @@ -12,7 +12,7 @@ import OrderedCollections public typealias GlobalAttributes = AccessKeyAttribute & AutocapitalizeAttribute & AutofocusAttribute & ClassAttribute & EditAttribute & DirectionAttribute & DragAttribute & EnterKeyHintAttribute & HiddenAttribute & InputModeAttribute & IsAttribute & ItemIdAttribute & ItemPropertyAttribute & ItemReferenceAttribute & ItemScopeAttribute & ItemTypeAttribute & IdentifierAttribute & LanguageAttribute & NonceAttribute & RoleAttribute & SpellCheckAttribute & StyleAttribute & TabulatorAttribute & TitleAttribute & TranslateAttribute /// The protocol provides the element with the accesskey handler. -public protocol AccessKeyAttribute: AnyAttribute { +public protocol AccessKeyAttribute: Attribute { /// The function represents the html-attribute 'accesskey'. /// @@ -25,27 +25,22 @@ public protocol AccessKeyAttribute: AnyAttribute { func accessKey(_ value: Character) -> Self } -extension AccessKeyAttribute { - - internal var key: String { "accesskey" } -} - extension AccessKeyAttribute where Self: ContentNode { internal func mutate(accesskey value: Character) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "accesskey", value: value) } } extension AccessKeyAttribute where Self: EmptyNode { internal func mutate(accesskey value: Character) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "accesskey", value: value) } } /// The protocol provides the element with the accept handler. -public protocol AcceptAttribute: AnyAttribute { +public protocol AcceptAttribute: Attribute { /// The function represents the html-attribute 'accept'. /// @@ -55,27 +50,22 @@ public protocol AcceptAttribute: AnyAttribute { func accept(_ value: String) -> Self } -extension AcceptAttribute { - - internal var key: String { "accept" } -} - extension AcceptAttribute where Self: ContentNode { internal func mutate(accept value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "accept", value: value) } } extension AcceptAttribute where Self: EmptyNode { internal func mutate(accept value: String) -> Self { - return self.mutate(key: key, value: value) + return self.mutate(key: "accept", value: value) } } /// The protocol provides the element with the action handler. -public protocol ActionAttribute: AnyAttribute { +public protocol ActionAttribute: Attribute { /// The function represents the html-attribute 'action'. /// @@ -85,27 +75,22 @@ public protocol ActionAttribute: AnyAttribute { func action(_ value: String) -> Self } -extension ActionAttribute { - - internal var key: String { "action" } -} - extension ActionAttribute where Self: ContentNode { internal func mutate(action value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "action", value: value) } } extension ActionAttribute where Self: EmptyNode { internal func mutate(action value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "action", value: value) } } /// The protocol provides the element with the alternate handler. -public protocol AlternateAttribute: AnyAttribute { +public protocol AlternateAttribute: Attribute { /// The function represents the html-attribute 'alt'. /// @@ -115,27 +100,22 @@ public protocol AlternateAttribute: AnyAttribute { func alternate(_ value: String) -> Self } -extension AlternateAttribute { - - internal var key: String { "alt" } -} - extension AlternateAttribute where Self: ContentNode { internal func mutate(alternate value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "alt", value: value) } } extension AlternateAttribute where Self: EmptyNode { internal func mutate(alternate value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "alt", value: value) } } /// The protocol provides the element with the asynchronously handler. -public protocol AsynchronouslyAttribute: AnyAttribute { +public protocol AsynchronouslyAttribute: Attribute { /// The function represents the html-attribute 'async'. /// @@ -145,27 +125,22 @@ public protocol AsynchronouslyAttribute: AnyAttribute { func asynchronously() -> Self } -extension AsynchronouslyAttribute { - - internal var key: String { "async" } -} - extension AsynchronouslyAttribute where Self: ContentNode { internal func mutate(async value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "async", value: value) } } extension AsynchronouslyAttribute where Self: EmptyNode { internal func mutate(async value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "async", value: value) } } /// The protocol provides the element with the autocapitalize handler. -public protocol AutocapitalizeAttribute: AnyAttribute { +public protocol AutocapitalizeAttribute: Attribute { /// The function represents the html-attribute 'autocapitalize'. /// @@ -175,27 +150,22 @@ public protocol AutocapitalizeAttribute: AnyAttribute { func autocapitalize(_ value: Values.Capitalization) -> Self } -extension AutocapitalizeAttribute { - - internal var key: String { "autocapitalize" } -} - extension AutocapitalizeAttribute where Self: ContentNode { internal func mutate(autocapitalize value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "autocapitalize", value: value) } } extension AutocapitalizeAttribute where Self: EmptyNode { internal func mutate(autocapitalize value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "autocapitalize", value: value) } } /// The protocol provides the element with the autocomplete handler. -public protocol AutocompleteAttribute: AnyAttribute { +public protocol AutocompleteAttribute: Attribute { /// The function represents the html-attribute 'autocomplete'. /// @@ -205,27 +175,22 @@ public protocol AutocompleteAttribute: AnyAttribute { func hasCompletion(_ value: Bool) -> Self } -extension AutocompleteAttribute { - - internal var key: String { "autocomplete" } -} - extension AutocompleteAttribute where Self: ContentNode { internal func mutate(autocomplete value: Bool) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "autocomplete", value: value) } } extension AutocompleteAttribute where Self: EmptyNode { internal func mutate(autocomplete value: Bool) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "autocomplete", value: value) } } /// The protocol provides the element with the autofocus handler. -public protocol AutofocusAttribute: AnyAttribute { +public protocol AutofocusAttribute: Attribute { /// The function represents the html-attribute 'autofocus'. /// @@ -235,27 +200,22 @@ public protocol AutofocusAttribute: AnyAttribute { func autofocus() -> Self } -extension AutofocusAttribute { - - internal var key: String { "autofocus" } -} - extension AutofocusAttribute where Self: ContentNode { internal func mutate(autofocus value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "autofocus", value: value) } } extension AutofocusAttribute where Self: EmptyNode { internal func mutate(autofocus value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "autofocus", value: value) } } /// The protocol provides the element with the autoplay handler. -public protocol AutoplayAttribute: AnyAttribute { +public protocol AutoplayAttribute: Attribute { /// The function represents the html-attribute 'autoplay'. /// @@ -265,27 +225,22 @@ public protocol AutoplayAttribute: AnyAttribute { func autoplay() -> Self } -extension AutoplayAttribute { - - internal var key: String { "autoplay" } -} - extension AutoplayAttribute where Self: ContentNode { internal func mutate(autoplay value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "autoplay", value: value) } } extension AutoplayAttribute where Self: EmptyNode { internal func mutate(autoplay value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "autoplay", value: value) } } /// The protocol provides the element with the charset handler. -public protocol CharsetAttribute: AnyAttribute { +public protocol CharsetAttribute: Attribute { /// The function represents the html-attribute 'charset'. /// @@ -295,27 +250,22 @@ public protocol CharsetAttribute: AnyAttribute { func charset(_ value: Values.Charset) -> Self } -extension CharsetAttribute { - - internal var key: String { "charset" } -} - extension CharsetAttribute where Self: ContentNode { internal func mutate(charset value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "charset", value: value) } } extension CharsetAttribute where Self: EmptyNode { internal func mutate(charset value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "charset", value: value) } } /// The protocol provides the element with the checked handler. -public protocol CheckedAttribute: AnyAttribute { +public protocol CheckedAttribute: Attribute { /// The function represents the html-attribute 'checked'. /// @@ -325,27 +275,22 @@ public protocol CheckedAttribute: AnyAttribute { func checked() -> Self } -extension CheckedAttribute { - - internal var key: String { "checked" } -} - extension CheckedAttribute where Self: ContentNode { internal func mutate(checked value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "checked", value: value) } } extension CheckedAttribute where Self: EmptyNode { internal func mutate(checked value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "checked", value: value) } } /// The protocol provides the element with the cite handler. -public protocol CiteAttribute: AnyAttribute { +public protocol CiteAttribute: Attribute { /// The function represents the html-attribute 'cite'. /// @@ -355,27 +300,22 @@ public protocol CiteAttribute: AnyAttribute { func cite(_ value: String) -> Self } -extension CiteAttribute { - - internal var key: String { "cite" } -} - extension CiteAttribute where Self: ContentNode { internal func mutate(cite value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "cite", value: value) } } extension CiteAttribute where Self: EmptyNode { internal func mutate(cite value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "cite", value: value) } } /// The protocol provides the element with the class handler. -public protocol ClassAttribute: AnyAttribute{ +public protocol ClassAttribute: Attribute{ /// The function represents the html-attribute 'class'. /// @@ -385,27 +325,22 @@ public protocol ClassAttribute: AnyAttribute{ func `class`(_ value: String) -> Self } -extension ClassAttribute { - - internal var key: String { "class" } -} - extension ClassAttribute where Self: ContentNode { internal func mutate(class value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "class", value: value) } } extension ClassAttribute where Self: EmptyNode { internal func mutate(class value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "class", value: value) } } /// The protocol provides the element with the columns handler. -public protocol ColumnsAttribute: AnyAttribute { +public protocol ColumnsAttribute: Attribute { /// The function represents the html-attribute 'cols'. /// @@ -415,27 +350,22 @@ public protocol ColumnsAttribute: AnyAttribute { func columns(_ size: Int) -> Self } -extension ColumnsAttribute { - - internal var key: String { "cols" } -} - extension ColumnsAttribute where Self: ContentNode { internal func mutate(cols value: Int) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "cols", value: value) } } extension ColumnsAttribute where Self: EmptyNode { internal func mutate(cols value: Int) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "cols", value: value) } } /// The protocol provides the element with the columnspan handler. -public protocol ColumnSpanAttribute: AnyAttribute { +public protocol ColumnSpanAttribute: Attribute { /// The function represents the html-attribute 'colspan'. /// @@ -445,27 +375,22 @@ public protocol ColumnSpanAttribute: AnyAttribute { func columnSpan(_ size: Int) -> Self } -extension ColumnSpanAttribute { - - internal var key: String { "colspan" } -} - extension ColumnSpanAttribute where Self: ContentNode { internal func mutate(colspan value: Int) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "colspan", value: value) } } extension ColumnSpanAttribute where Self: EmptyNode { internal func mutate(colspan value: Int) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "colspan", value: value) } } /// The protocol provides the element with the content handler. -public protocol ContentAttribute: AnyAttribute { +public protocol ContentAttribute: Attribute { /// The function represents the html-attribute 'content'. /// @@ -473,32 +398,24 @@ public protocol ContentAttribute: AnyAttribute { /// /// ``` func content(_ value: String) -> Self - - /// The func adds - func content(_ value: TemplateValue) -> Self -} - -extension ContentAttribute { - - internal var key: String { "content" } } extension ContentAttribute where Self: ContentNode { internal func mutate(content value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "content", value: value) } } extension ContentAttribute where Self: EmptyNode { internal func mutate(content value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "content", value: value) } } /// The protocol provides the element with the iseditable handler. -public protocol EditAttribute: AnyAttribute { +public protocol EditAttribute: Attribute { /// The function represents the html-attribute 'contenteditable'. /// @@ -508,27 +425,22 @@ public protocol EditAttribute: AnyAttribute { func isEditable(_ value: Bool) -> Self } -extension EditAttribute { - - internal var key: String { "contenteditable" } -} - extension EditAttribute where Self: ContentNode { internal func mutate(contenteditable value: Bool) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "contenteditable", value: value) } } extension EditAttribute where Self: EmptyNode { internal func mutate(contenteditable value: Bool) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "contenteditable", value: value) } } /// The protocol provides the element with the controls handler. -public protocol ControlsAttribute: AnyAttribute { +public protocol ControlsAttribute: Attribute { /// The function represents the html-attribute 'controls'. /// @@ -538,27 +450,22 @@ public protocol ControlsAttribute: AnyAttribute { func controls() -> Self } -extension ControlsAttribute { - - internal var key: String { "controls" } -} - extension ControlsAttribute where Self: ContentNode { internal func mutate(controls value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "controls", value: value) } } extension ControlsAttribute where Self: EmptyNode { internal func mutate(controls value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "controls", value: value) } } /// The protocol provides the element with the coordinates handler. -public protocol CoordinatesAttribute: AnyAttribute { +public protocol CoordinatesAttribute: Attribute { /// The function represents the html-attribute 'coordinates'. /// @@ -568,27 +475,22 @@ public protocol CoordinatesAttribute: AnyAttribute { func coordinates(_ value: String) -> Self } -extension CoordinatesAttribute { - - internal var key: String { "coords" } -} - extension CoordinatesAttribute where Self: ContentNode { internal func mutate(coords value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "coords", value: value) } } extension CoordinatesAttribute where Self: EmptyNode { internal func mutate(coords value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "coords", value: value) } } /// The protocol provides the element with the date handler. -public protocol DataAttribute: AnyAttribute{ +public protocol DataAttribute: Attribute{ /// The function represents the html-attribute 'data'. /// @@ -598,27 +500,22 @@ public protocol DataAttribute: AnyAttribute{ func data(_ value: String) -> Self } -extension DataAttribute { - - internal var key: String { "data" } -} - extension DataAttribute where Self: ContentNode { internal func mutate(data value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "data", value: value) } } extension DataAttribute where Self: EmptyNode { internal func mutate(data value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "data", value: value) } } /// The protocol provides the element with the datetime handler. -public protocol DateTimeAttribute: AnyAttribute { +public protocol DateTimeAttribute: Attribute { /// The function represents the html-attribute 'datetime'. /// @@ -628,27 +525,22 @@ public protocol DateTimeAttribute: AnyAttribute { func dateTime(_ value: String) -> Self } -extension DateTimeAttribute { - - internal var key: String { "datetime" } -} - extension DateTimeAttribute where Self: ContentNode { internal func mutate(datetime value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "datetime", value: value) } } extension DateTimeAttribute where Self: EmptyNode { internal func mutate(datetime value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "datetime", value: value) } } /// The protocol provides the element with the default handler. -public protocol DefaultAttribute: AnyAttribute { +public protocol DefaultAttribute: Attribute { /// The function represents the html-attribute 'default'. /// @@ -658,27 +550,22 @@ public protocol DefaultAttribute: AnyAttribute { func `default`() -> Self } -extension DefaultAttribute { - - internal var key: String { "default" } -} - extension DefaultAttribute where Self: ContentNode { internal func mutate(default value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "default", value: value) } } extension DefaultAttribute where Self: EmptyNode { internal func mutate(default value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "default", value: value) } } /// The protocol provides the element with the defer handler. -public protocol DeferAttribute: AnyAttribute { +public protocol DeferAttribute: Attribute { /// The function represents the html-attribute 'defer'. /// @@ -688,27 +575,22 @@ public protocol DeferAttribute: AnyAttribute { func `defer`() -> Self } -extension DeferAttribute { - - internal var key: String { "defer" } -} - extension DeferAttribute where Self: ContentNode { internal func mutate(defer value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "defer", value: value) } } extension DeferAttribute where Self: EmptyNode { internal func mutate(defer value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "defer", value: value) } } /// The protocol provides the element with the direction handler. -public protocol DirectionAttribute: AnyAttribute { +public protocol DirectionAttribute: Attribute { /// The function represents the html-attribute 'dir'. /// @@ -720,27 +602,22 @@ public protocol DirectionAttribute: AnyAttribute { func direction(_ value: Values.Direction) -> Self } -extension DirectionAttribute { - - internal var key: String { "dir" } -} - extension DirectionAttribute where Self: ContentNode { internal func mutate(dir value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "dir", value: value) } } extension DirectionAttribute where Self: EmptyNode { internal func mutate(dir value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "dir", value: value) } } /// The protocol provides the element with the disabled handler -public protocol DisabledAttribute: AnyAttribute { +public protocol DisabledAttribute: Attribute { /// The function represents the html-attribute 'disabled'. /// @@ -750,27 +627,22 @@ public protocol DisabledAttribute: AnyAttribute { func disabled() -> Self } -extension DisabledAttribute { - - internal var key: String { "disabled" } -} - extension DisabledAttribute where Self: ContentNode { internal func mutate(disabled value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "disabled", value: value) } } extension DisabledAttribute where Self: EmptyNode { internal func mutate(disabled value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "disabled", value: value) } } /// The protocol provides the element with the download handler. -public protocol DownloadAttribute: AnyAttribute { +public protocol DownloadAttribute: Attribute { /// The function represents the html-attribute 'download'. /// @@ -780,27 +652,22 @@ public protocol DownloadAttribute: AnyAttribute { func download() -> Self } -extension DownloadAttribute { - - internal var key: String { "download" } -} - extension DownloadAttribute where Self: ContentNode { internal func mutate(download value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "download", value: value) } } extension DownloadAttribute where Self: EmptyNode { internal func mutate(download value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "download", value: value) } } /// The protocol provides the element with the isdraggable handler. -public protocol DragAttribute: AnyAttribute { +public protocol DragAttribute: Attribute { /// The function represents the html-attribute 'draggable'. /// @@ -810,27 +677,22 @@ public protocol DragAttribute: AnyAttribute { func isDraggable(_ value: Bool) -> Self } -extension DragAttribute { - - internal var key: String { "draggable" } -} - extension DragAttribute where Self: ContentNode { internal func mutate(draggable value: Bool) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "draggable", value: value) } } extension DragAttribute where Self: EmptyNode { internal func mutate(draggable value: Bool) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "draggable", value: value) } } /// The protocol provides the element with the encoding handler. -public protocol EncodingAttribute: AnyAttribute { +public protocol EncodingAttribute: Attribute { /// The function represents the html-attribute 'enctype'. /// @@ -842,27 +704,22 @@ public protocol EncodingAttribute: AnyAttribute { func encoding(_ value: Values.Encoding) -> Self } -extension EncodingAttribute { - - internal var key: String { "enctype" } -} - extension EncodingAttribute where Self: ContentNode { internal func mutate(enctype value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "enctype", value: value) } } extension EncodingAttribute where Self: EmptyNode { internal func mutate(enctype value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "enctype", value: value) } } /// The protocol provides the element with the enterkeyhint handler. -public protocol EnterKeyHintAttribute: AnyAttribute { +public protocol EnterKeyHintAttribute: Attribute { /// The function represents the html-attribute 'enterkeyhint'. /// @@ -874,27 +731,22 @@ public protocol EnterKeyHintAttribute: AnyAttribute { func enterKeyHint(_ value: Values.Hint) -> Self } -extension EnterKeyHintAttribute { - - internal var key: String { "enterkeyhint" } -} - extension EnterKeyHintAttribute where Self: ContentNode { internal func mutate(enterkeyhint value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "enterkeyhint", value: value) } } extension EnterKeyHintAttribute where Self: EmptyNode { internal func mutate(enterkeyhint value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "enterkeyhint", value: value) } } /// The protocol provides the element with the for handler. -public protocol ForAttribute: AnyAttribute { +public protocol ForAttribute: Attribute { /// The function represents the html-attribute 'for'. /// @@ -906,27 +758,22 @@ public protocol ForAttribute: AnyAttribute { func `for`(_ value: String) -> Self } -extension ForAttribute { - - internal var key: String { "for" } -} - extension ForAttribute where Self: ContentNode { internal func mutate(for value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "for", value: value) } } extension ForAttribute where Self: EmptyNode { internal func mutate(for value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "for", value: value) } } /// The protocol provides the element with the form handler. -public protocol FormAttribute: AnyAttribute { +public protocol FormAttribute: Attribute { /// The function represents the html-attribute 'form'. /// @@ -936,27 +783,22 @@ public protocol FormAttribute: AnyAttribute { func form(_ value: String) -> Self } -extension FormAttribute { - - internal var key: String { "form" } -} - extension FormAttribute where Self: ContentNode { internal func mutate(form value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "form", value: value) } } extension FormAttribute where Self: EmptyNode { internal func mutate(form value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "form", value: value) } } /// The protocol provides the element with the formaction handler. -public protocol FormActionAttribute: AnyAttribute { +public protocol FormActionAttribute: Attribute { /// The function represents the html-attribute 'formaction'. /// @@ -968,27 +810,22 @@ public protocol FormActionAttribute: AnyAttribute { func formAction(_ value: String) -> Self } -extension FormActionAttribute { - - internal var key: String { "formaction" } -} - extension FormActionAttribute where Self: ContentNode { internal func mutate(formaction value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "formaction", value: value) } } extension FormActionAttribute where Self: EmptyNode { internal func mutate(formaction value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "formaction", value: value) } } /// The protocol provides the element with the http-equiv handler. -public protocol EquivalentAttribute: AnyAttribute { +public protocol EquivalentAttribute: Attribute { /// The function represents the html-attribute 'http-equiv'. /// @@ -1000,27 +837,22 @@ public protocol EquivalentAttribute: AnyAttribute { func equivalent(_ value: Values.Equivalent) -> Self } -extension EquivalentAttribute { - - internal var key: String { "http-equiv" } -} - extension HeaderAttribute where Self: ContentNode { internal func mutate(httpequiv value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "http-equiv", value: value) } } extension EquivalentAttribute where Self: EmptyNode { internal func mutate(httpequiv value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "http-equiv", value: value) } } /// The protocol provides the element with the headers handler. -public protocol HeaderAttribute: AnyAttribute { +public protocol HeaderAttribute: Attribute { /// The function represents the html-attribute 'headers'. /// @@ -1032,27 +864,22 @@ public protocol HeaderAttribute: AnyAttribute { func headers(_ value: String) -> Self } -extension HeaderAttribute { - - internal var key: String { "headers" } -} - extension HeaderAttribute where Self: ContentNode { internal func mutate(headers value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "headers", value: value) } } extension HeaderAttribute where Self: EmptyNode { internal func mutate(headers value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "headers", value: value) } } /// The protocol provides the element with the height handler. -public protocol HeightAttribute: AnyAttribute { +public protocol HeightAttribute: Attribute { /// The function represents the html-attribute 'height'. /// @@ -1064,27 +891,22 @@ public protocol HeightAttribute: AnyAttribute { func height(_ size: Int) -> Self } -extension HeightAttribute { - - internal var key: String { "height" } -} - extension HeightAttribute where Self: ContentNode { internal func mutate(height value: Int) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "height", value: value) } } extension HeightAttribute where Self: EmptyNode { internal func mutate(height value: Int) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "height", value: value) } } /// The protocol provides the element with hidden handler. -public protocol HiddenAttribute: AnyAttribute { +public protocol HiddenAttribute: Attribute { /// The function represents the html-attribute 'hidden'. /// @@ -1094,27 +916,22 @@ public protocol HiddenAttribute: AnyAttribute { func hidden() -> Self } -extension HiddenAttribute { - - internal var key: String { "hidden" } -} - extension HiddenAttribute where Self: ContentNode { internal func mutate(hidden value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "hidden", value: value) } } extension HiddenAttribute where Self: EmptyNode { internal func mutate(hidden value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "hidden", value: value) } } /// The protocol provides the element with high handler. -public protocol HighAttribute: AnyAttribute { +public protocol HighAttribute: Attribute { /// The function represents the html-attribute 'high'. /// @@ -1126,27 +943,22 @@ public protocol HighAttribute: AnyAttribute { func high(_ value: Float) -> Self } -extension HighAttribute { - - internal var key: String { "high" } -} - extension HighAttribute where Self: ContentNode { internal func mutate(high value: Float) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "high", value: value) } } extension HighAttribute where Self: EmptyNode { internal func mutate(high value: Float) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "high", value: value) } } /// The protocol provides the element with reference handler. -public protocol ReferenceAttribute: AnyAttribute { +public protocol ReferenceAttribute: Attribute { /// The function represents the html-attribute 'href'. /// @@ -1156,31 +968,24 @@ public protocol ReferenceAttribute: AnyAttribute { /// /// ``` func reference(_ value: String) -> Self - - func reference(_ value: TemplateValue) -> Self -} - -extension ReferenceAttribute { - - internal var key: String { "href" } } extension ReferenceAttribute where Self: ContentNode { internal func mutate(href value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "href", value: value) } } extension ReferenceAttribute where Self: EmptyNode { internal func mutate(href value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "href", value: value) } } /// The protocol provides the element with the language reference handler. -public protocol ReferenceLanguageAttribute: AnyAttribute { +public protocol ReferenceLanguageAttribute: Attribute { /// The function represents the html-attribute 'hreflang'. /// @@ -1192,27 +997,22 @@ public protocol ReferenceLanguageAttribute: AnyAttribute { func referenceLanguage(_ value: Values.Language) -> Self } -extension ReferenceLanguageAttribute { - - internal var key: String { "hreflang" } -} - extension ReferenceLanguageAttribute where Self: ContentNode { internal func mutate(hreflang value: String) -> Self { - self.mutate(key: key, value: value) + return self.mutate(key: "hreflang", value: value) } } extension ReferenceLanguageAttribute where Self: EmptyNode { internal func mutate(hreflang value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "hreflang", value: value) } } /// The protocol provides the element with the id handler. -public protocol IdentifierAttribute: AnyAttribute { +public protocol IdentifierAttribute: Attribute { /// The function represents the html-attribute 'id'. /// @@ -1222,31 +1022,24 @@ public protocol IdentifierAttribute: AnyAttribute { /// /// ``` func id(_ value: String) -> Self - - func id(_ value: TemplateValue) -> Self -} - -extension IdentifierAttribute { - - internal var key: String { "id" } } extension IdentifierAttribute where Self: ContentNode { internal func mutate(id value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "id", value: value) } } extension IdentifierAttribute where Self: EmptyNode { internal func mutate(id value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "id", value: value) } } /// The protocol provides the element with the ismap handler. -public protocol IsMapAttribute: AnyAttribute { +public protocol IsMapAttribute: Attribute { /// The function represents the html-attribute 'ismap'. /// @@ -1256,27 +1049,22 @@ public protocol IsMapAttribute: AnyAttribute { func isMap() -> Self } -extension IsMapAttribute { - - internal var key: String { "ismap" } -} - extension IsMapAttribute where Self: ContentNode { internal func mutate(ismap value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "ismap", value: value) } } extension IsMapAttribute where Self: EmptyNode { internal func mutate(ismap value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "ismap", value: value) } } /// The protocol provides the element with the inputmode handler. -public protocol InputModeAttribute: AnyAttribute { +public protocol InputModeAttribute: Attribute { /// The function represents the html-attribute 'inputmode'. /// @@ -1286,27 +1074,22 @@ public protocol InputModeAttribute: AnyAttribute { func inputMode(_ value: String) -> Self } -extension InputModeAttribute { - - internal var key: String { "inputmode" } -} - extension InputModeAttribute where Self: ContentNode { internal func mutate(inputmode value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "inputmode", value: value) } } extension InputModeAttribute where Self: EmptyNode { internal func mutate(inputmode value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "inputmode", value: value) } } /// The protocol provides the element with the inputmode handler. -public protocol IsAttribute: AnyAttribute { +public protocol IsAttribute: Attribute { /// The function represents the html-attribute 'is'. /// @@ -1316,27 +1099,22 @@ public protocol IsAttribute: AnyAttribute { func `is`(_ value: String) -> Self } -extension IsAttribute { - - internal var key: String { "is" } -} - extension IsAttribute where Self: ContentNode { internal func mutate(is value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "is", value: value) } } extension IsAttribute where Self: EmptyNode { internal func mutate(is value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "is", value: value) } } /// The protocol provides the element with the itemid handler. -public protocol ItemIdAttribute: AnyAttribute { +public protocol ItemIdAttribute: Attribute { /// The function represents the html-attribute 'itemid'. /// @@ -1346,27 +1124,22 @@ public protocol ItemIdAttribute: AnyAttribute { func itemId(_ value: String) -> Self } -extension ItemIdAttribute { - - internal var key: String { "itemid" } -} - extension ItemIdAttribute where Self: ContentNode { internal func mutate(itemid value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "itemid", value: value) } } extension ItemIdAttribute where Self: EmptyNode { internal func mutate(itemid value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "itemid", value: value) } } /// The protocol provides the element with the itemproperty handler. -public protocol ItemPropertyAttribute: AnyAttribute { +public protocol ItemPropertyAttribute: Attribute { /// The function represents the html-attribute 'itemprop'. /// @@ -1376,27 +1149,22 @@ public protocol ItemPropertyAttribute: AnyAttribute { func itemProperty(_ value: String) -> Self } -extension ItemPropertyAttribute { - - internal var key: String { "itemprop" } -} - extension ItemPropertyAttribute where Self: ContentNode { internal func mutate(itemprop value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "itemprop", value: value) } } extension ItemPropertyAttribute where Self: EmptyNode { internal func mutate(itemprop value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "itemprop", value: value) } } /// The protocol provides the element with the itemreference handler. -public protocol ItemReferenceAttribute: AnyAttribute { +public protocol ItemReferenceAttribute: Attribute { /// The function represents the html-attribute 'itemref'. /// @@ -1406,27 +1174,22 @@ public protocol ItemReferenceAttribute: AnyAttribute { func itemReference(_ value: String) -> Self } -extension ItemReferenceAttribute { - - internal var key: String { "itemref" } -} - extension ItemReferenceAttribute where Self: ContentNode { internal func mutate(itemref value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "itemref", value: value) } } extension ItemReferenceAttribute where Self: EmptyNode { internal func mutate(itemref value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "itemref", value: value) } } /// The protocol provides the element with the itemscope handler. -public protocol ItemScopeAttribute: AnyAttribute { +public protocol ItemScopeAttribute: Attribute { /// The function represents the html-attribute 'itemscope'. /// @@ -1436,27 +1199,22 @@ public protocol ItemScopeAttribute: AnyAttribute { func itemScope(_ value: String) -> Self } -extension ItemScopeAttribute { - - internal var key: String { "itemscope" } -} - extension ItemScopeAttribute where Self: ContentNode { internal func mutate(itemscope value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "itemscope", value: value) } } extension ItemScopeAttribute where Self: EmptyNode { internal func mutate(itemscope value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "itemscope", value: value) } } /// The protocol provides the element with the itemtype handler -public protocol ItemTypeAttribute: AnyAttribute { +public protocol ItemTypeAttribute: Attribute { /// The function represents the html-attribute 'itemtype'. /// @@ -1466,27 +1224,22 @@ public protocol ItemTypeAttribute: AnyAttribute { func itemType(_ value: String) -> Self } -extension ItemTypeAttribute { - - internal var key: String { "itemtype" } -} - extension ItemTypeAttribute where Self: ContentNode { internal func mutate(itemtype value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "itemtype", value: value) } } extension ItemTypeAttribute where Self: EmptyNode { internal func mutate(itemtype value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "itemtype", value: value) } } /// The protocol provides the element with the kind handler. -public protocol KindAttribute: AnyAttribute { +public protocol KindAttribute: Attribute { /// The function represents the html-attribute 'kind'. /// @@ -1496,27 +1249,22 @@ public protocol KindAttribute: AnyAttribute { func kind(_ value: Values.Kind) -> Self } -extension KindAttribute { - - internal var key: String { "kind" } -} - extension KindAttribute where Self: ContentNode { internal func mutate(kind value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "kind", value: value) } } extension KindAttribute where Self: EmptyNode { internal func mutate(kind value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "kind", value: value) } } /// The protocol provides the element with the label handler. -public protocol LabelAttribute: AnyAttribute { +public protocol LabelAttribute: Attribute { /// The function represents the html-attribute 'label'. /// @@ -1526,27 +1274,22 @@ public protocol LabelAttribute: AnyAttribute { func label(_ value: String) -> Self } -extension LabelAttribute { - - internal var key: String { "label" } -} - extension LabelAttribute where Self: ContentNode { internal func mutate(label value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "label", value: value) } } extension LabelAttribute where Self: EmptyNode { internal func mutate(label value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "label", value: value) } } /// The protocol provides the element with the language handler. -public protocol LanguageAttribute: AnyAttribute { +public protocol LanguageAttribute: Attribute { /// The function represents the html-attribute 'lang'. /// @@ -1556,27 +1299,22 @@ public protocol LanguageAttribute: AnyAttribute { func language(_ value: Values.Language) -> Self } -extension LanguageAttribute { - - internal var key: String { "lang" } -} - extension LanguageAttribute where Self: ContentNode { internal func mutate(lang value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "lang", value: value) } } extension LanguageAttribute where Self: EmptyNode { internal func mutate(lang value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "lang", value: value) } } /// The protocol provides the element with the list handler. -public protocol ListAttribute: AnyAttribute { +public protocol ListAttribute: Attribute { /// The function represents the html-attribute 'list'. /// @@ -1586,27 +1324,22 @@ public protocol ListAttribute: AnyAttribute { func list(_ value: String) -> Self } -extension ListAttribute { - - internal var key: String { "list" } -} - extension ListAttribute where Self: ContentNode { internal func mutate(list value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "list", value: value) } } extension ListAttribute where Self: EmptyNode { internal func mutate(list value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "list", value: value) } } /// The protocol provides the element with the loop handler. -public protocol LoopAttribute: AnyAttribute { +public protocol LoopAttribute: Attribute { /// The function represents the html-attribute 'loop'. /// @@ -1616,27 +1349,22 @@ public protocol LoopAttribute: AnyAttribute { func loop() -> Self } -extension LoopAttribute { - - internal var key: String { "loop" } -} - extension LoopAttribute where Self: ContentNode { internal func mutate(loop value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "loop", value: value) } } extension LoopAttribute where Self: EmptyNode { internal func mutate(loop value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "loop", value: value) } } /// The protocol provides the element with the low handler. -public protocol LowAttribute: AnyAttribute { +public protocol LowAttribute: Attribute { /// The function represents the html-attribute 'low'. /// @@ -1646,27 +1374,22 @@ public protocol LowAttribute: AnyAttribute { func low(_ value: Float) -> Self } -extension LowAttribute { - - internal var key: String { "low" } -} - extension LowAttribute where Self: ContentNode { internal func mutate(low value: Float) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "low", value: value) } } extension LowAttribute where Self: EmptyNode { internal func mutate(low value: Float) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "low", value: value) } } /// The protocol provides the element with the maximumvalue handler. -public protocol MaximumValueAttribute: AnyAttribute { +public protocol MaximumValueAttribute: Attribute { associatedtype MaximumValueType @@ -1678,27 +1401,22 @@ public protocol MaximumValueAttribute: AnyAttribute { func maximum(_ value: MaximumValueType) -> Self } -extension MaximumValueAttribute { - - internal var key: String { "max" } -} - extension MaximumValueAttribute where Self: ContentNode { internal func mutate(max value: MaximumValueType) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "max", value: value) } } extension MaximumValueAttribute where Self: EmptyNode { internal func mutate(max value: MaximumValueType) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "max", value: value) } } /// The protocol provides the element with the maximumlength handler. -public protocol MaximumLengthAttribute: AnyAttribute { +public protocol MaximumLengthAttribute: Attribute { /// The function represents the html-attribute 'maxlength'. /// @@ -1708,27 +1426,22 @@ public protocol MaximumLengthAttribute: AnyAttribute { func maximum(length value: Int) -> Self } -extension MaximumLengthAttribute { - - internal var key: String { "maxlength" } -} - extension MaximumLengthAttribute where Self: ContentNode { internal func mutate(maxlength value: Int) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "maxlength", value: value) } } extension MaximumLengthAttribute where Self: EmptyNode { internal func mutate(maxlength value: Int) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "maxlength", value: value) } } /// The protocol provides the element with the media handler. -public protocol MediaAttribute: AnyAttribute { +public protocol MediaAttribute: Attribute { /// The function represents the html-attribute 'media'. /// @@ -1738,27 +1451,22 @@ public protocol MediaAttribute: AnyAttribute { func media(_ value: String) -> Self } -extension MediaAttribute { - - internal var key: String { "media" } -} - extension MediaAttribute where Self: ContentNode { internal func mutate(media value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "media", value: value) } } extension MediaAttribute where Self: EmptyNode { internal func mutate(media value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "media", value: value) } } /// The protocol provides the element with the method handler. -public protocol MethodAttribute: AnyAttribute { +public protocol MethodAttribute: Attribute { /// The function represents the html-attribute 'method'. /// @@ -1768,27 +1476,22 @@ public protocol MethodAttribute: AnyAttribute { func method(_ value: Values.Method) -> Self } -extension MethodAttribute { - - internal var key: String { "method" } -} - extension MethodAttribute where Self: ContentNode { internal func mutate(method value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "method", value: value) } } extension MethodAttribute where Self: EmptyNode { internal func mutate(method value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "method", value: value) } } /// The protocol provides the element with the minimumvalue handler. -public protocol MinimumValueAttribute: AnyAttribute { +public protocol MinimumValueAttribute: Attribute { associatedtype MinimumValueType @@ -1800,27 +1503,22 @@ public protocol MinimumValueAttribute: AnyAttribute { func minimum(_ value: MinimumValueType) -> Self } -extension MinimumValueAttribute { - - internal var key: String { "min" } -} - extension MinimumValueAttribute where Self: ContentNode { internal func mutate(min value: MinimumValueType) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "min", value: value) } } extension MinimumValueAttribute where Self: EmptyNode { internal func mutate(min value: MinimumValueType) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "min", value: value) } } /// The protocol provides the element with the minimumlength handler. -public protocol MinimumLengthAttribute: AnyAttribute { +public protocol MinimumLengthAttribute: Attribute { /// The function represents the html-attribute 'minlength'. /// @@ -1830,27 +1528,22 @@ public protocol MinimumLengthAttribute: AnyAttribute { func minimum(length value: Int) -> Self } -extension MinimumLengthAttribute { - - internal var key: String { "minlength" } -} - extension MinimumLengthAttribute where Self: ContentNode { internal func mutate(minlength value: Int) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "minlength", value: value) } } extension MinimumLengthAttribute where Self: EmptyNode { internal func mutate(minlength value: Int) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "minlength", value: value) } } /// The protocol provides the element with the multiple handler. -public protocol MultipleAttribute: AnyAttribute { +public protocol MultipleAttribute: Attribute { /// The function represents the html-attribute 'multiple'. /// @@ -1860,27 +1553,22 @@ public protocol MultipleAttribute: AnyAttribute { func multiple() -> Self } -extension MultipleAttribute { - - internal var key: String { "multiple" } -} - extension MultipleAttribute where Self: ContentNode { internal func mutate(multiple value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "multiple", value: value) } } extension MultipleAttribute where Self: EmptyNode { internal func mutate(multiple value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "multiple", value: value) } } /// The protocol provides the element with the muted handler. -public protocol MutedAttribute: AnyAttribute { +public protocol MutedAttribute: Attribute { /// The function represents the html-attribute 'muted'. /// @@ -1890,27 +1578,22 @@ public protocol MutedAttribute: AnyAttribute { func muted() -> Self } -extension MutedAttribute { - - internal var key: String { "muted" } -} - extension MutedAttribute where Self: ContentNode { internal func mutate(muted value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "muted", value: value) } } extension MutedAttribute where Self: EmptyNode { internal func mutate(muted value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "muted", value: value) } } /// The protocol provides the element with the name handler. -public protocol NameAttribute: AnyAttribute { +public protocol NameAttribute: Attribute { associatedtype NameValue @@ -1920,32 +1603,24 @@ public protocol NameAttribute: AnyAttribute { /// /// ``` func name(_ value: NameValue) -> Self - - /// The func adds - func name(_ value: TemplateValue) -> Self -} - -extension NameAttribute { - - internal var key: String { "name" } } extension NameAttribute where Self: ContentNode { internal func mutate(name value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "name", value: value) } } extension NameAttribute where Self: EmptyNode { internal func mutate(name value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "name", value: value) } } /// The protocol provides the element with the nonce handler. -public protocol NonceAttribute: AnyAttribute { +public protocol NonceAttribute: Attribute { /// The function represents the html-attribute 'nonce'. /// @@ -1955,27 +1630,22 @@ public protocol NonceAttribute: AnyAttribute { func nonce(_ value: String) -> Self } -extension NonceAttribute { - - internal var key: String { "nonce" } -} - extension NonceAttribute where Self: ContentNode { internal func mutate(nonce value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "nonce" , value: value) } } extension NonceAttribute where Self: EmptyNode { internal func mutate(nonce value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "nonce" , value: value) } } /// The protocol provides the element with the novalidate handler. -public protocol NoValidateAttribute: AnyAttribute { +public protocol NoValidateAttribute: Attribute { /// The function represents the html-attribute 'novalidate'. /// @@ -1985,27 +1655,22 @@ public protocol NoValidateAttribute: AnyAttribute { func novalidate() -> Self } -extension NoValidateAttribute { - - internal var key: String { "novalidate" } -} - extension NoValidateAttribute where Self: ContentNode { internal func mutate(novalidate value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "novalidate", value: value) } } extension NoValidateAttribute where Self: EmptyNode { internal func mutate(novalidate value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "novalidate", value: value) } } /// The protocol provides the element with the open handler. -public protocol OpenAttribute: AnyAttribute { +public protocol OpenAttribute: Attribute { /// The function represents the html-attribute 'open'. /// @@ -2015,27 +1680,22 @@ public protocol OpenAttribute: AnyAttribute { func isOpen(_ value: Bool) -> Self } -extension OpenAttribute { - - internal var key: String { "open" } -} - extension OpenAttribute where Self: ContentNode { internal func mutate(open value: Bool) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "open", value: value) } } extension OpenAttribute where Self: EmptyNode { internal func mutate(open value: Bool) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "open", value: value) } } /// The protocol provides the element with the optimum handler. -public protocol OptimumAttribute: AnyAttribute { +public protocol OptimumAttribute: Attribute { /// The function represents the html-attribute 'optimum'. /// @@ -2045,27 +1705,22 @@ public protocol OptimumAttribute: AnyAttribute { func optimum(_ value: Float) -> Self } -extension OptimumAttribute { - - internal var key: String { "optimum" } -} - extension OptimumAttribute where Self: ContentNode { internal func mutate(optimum value: Float) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "optimum", value: value) } } extension OptimumAttribute where Self: EmptyNode { internal func mutate(optimum value: Float) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "optimum", value: value) } } /// The protocol provides the element with the pattern handler. -public protocol PatternAttribute: AnyAttribute { +public protocol PatternAttribute: Attribute { /// The function represents the html-attribute 'pattern'. /// @@ -2075,27 +1730,22 @@ public protocol PatternAttribute: AnyAttribute { func pattern(_ regex: String) -> Self } -extension PatternAttribute { - - internal var key: String { "pattern" } -} - extension PatternAttribute where Self: ContentNode { internal func mutate(pattern value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "pattern", value: value) } } extension PatternAttribute where Self: EmptyNode { internal func mutate(pattern value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "pattern", value: value) } } /// The protocol provides the element with the part handler. -public protocol PartAttribute: AnyAttribute { +public protocol PartAttribute: Attribute { /// The function represents the html-attribute 'part'. /// @@ -2105,27 +1755,22 @@ public protocol PartAttribute: AnyAttribute { func part(_ value: String) -> Self } -extension PartAttribute { - - internal var key: String { "part" } -} - extension PartAttribute where Self: ContentNode { internal func mutate(part value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "part", value: value) } } extension PartAttribute where Self: EmptyNode { internal func mutate(part value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "part", value: value) } } /// The protocol provides the element with the ping handler. -public protocol PingAttribute: AnyAttribute { +public protocol PingAttribute: Attribute { /// The function represents the html-attribute 'ping'. /// @@ -2135,27 +1780,22 @@ public protocol PingAttribute: AnyAttribute { func ping(_ value: String) -> Self } -extension PingAttribute { - - internal var key: String { "ping" } -} - extension PingAttribute where Self: ContentNode { internal func mutate(ping value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "ping", value: value) } } extension PingAttribute where Self: EmptyNode { internal func mutate(ping value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "ping", value: value) } } /// The protocol provides the element with the placeholder handler. -public protocol PlaceholderAttribute: AnyAttribute { +public protocol PlaceholderAttribute: Attribute { /// The function represents the html-attribute 'placeholder'. /// @@ -2163,31 +1803,24 @@ public protocol PlaceholderAttribute: AnyAttribute { /// /// ``` func placeholder(_ value: String) -> Self - - func placeholder(_ value: TemplateValue) -> Self -} - -extension PlaceholderAttribute { - - internal var key: String { "placeholder" } } extension PlaceholderAttribute where Self: ContentNode { internal func mutate(placeholder value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "placeholder", value: value) } } extension PlaceholderAttribute where Self: EmptyNode { internal func mutate(placeholder value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "placeholder", value: value) } } /// The protocol provides the element with the poster handler. -public protocol PosterAttribute: AnyAttribute { +public protocol PosterAttribute: Attribute { /// The function represents the html-attribute 'poster'. /// @@ -2197,27 +1830,22 @@ public protocol PosterAttribute: AnyAttribute { func poster(_ value: String) -> Self } -extension PosterAttribute { - - internal var key: String { "poster" } -} - extension PosterAttribute where Self: ContentNode { internal func mutate(poster value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "poster", value: value) } } extension PosterAttribute where Self: EmptyNode { internal func mutate(poster value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "poster", value: value) } } /// The protocol provides the element with the preload handler. -public protocol PreloadAttribute: AnyAttribute { +public protocol PreloadAttribute: Attribute { /// The function represents the html-attribute 'preload'. /// @@ -2227,27 +1855,22 @@ public protocol PreloadAttribute: AnyAttribute { func preload(_ value: Values.Preload) -> Self } -extension PreloadAttribute { - - internal var key: String { "preload" } -} - extension PreloadAttribute where Self: ContentNode { internal func mutate(preload value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "preload", value: value) } } extension PreloadAttribute where Self: EmptyNode { internal func mutate(preload value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "preload", value: value) } } /// The protocol provides the element with the readonly handler. -public protocol ReadyOnlyAttribute: AnyAttribute { +public protocol ReadyOnlyAttribute: Attribute { /// The function represents the html-attribute 'readonly'. /// @@ -2257,27 +1880,22 @@ public protocol ReadyOnlyAttribute: AnyAttribute { func readonly() -> Self } -extension ReadyOnlyAttribute { - - internal var key: String { "readonly" } -} - extension ReadyOnlyAttribute where Self: ContentNode { internal func mutate(readonly value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "readonly", value: value) } } extension ReadyOnlyAttribute where Self: EmptyNode { internal func mutate(readonly value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "readonly", value: value) } } /// The protocol provides the element with the referrerpolicy handler. -public protocol ReferrerPolicyAttribute: AnyAttribute { +public protocol ReferrerPolicyAttribute: Attribute { /// The function represents the html-attribute 'referrerpolicy'. /// @@ -2287,27 +1905,22 @@ public protocol ReferrerPolicyAttribute: AnyAttribute { func referrerPolicy(_ value: Values.Policy) -> Self } -extension ReferrerPolicyAttribute { - - internal var key: String { "referrerpolicy" } -} - extension ReferrerPolicyAttribute where Self: ContentNode { internal func mutate(referrerpolicy value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "referrerpolicy", value: value) } } extension ReferrerPolicyAttribute where Self: EmptyNode { internal func mutate(referrerpolicy value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "referrerpolicy", value: value) } } /// The protocol provides the element with the relationship handler. -public protocol RelationshipAttribute: AnyAttribute { +public protocol RelationshipAttribute: Attribute { /// The function represents the html-attribute 'rel'. /// @@ -2317,27 +1930,22 @@ public protocol RelationshipAttribute: AnyAttribute { func relationship(_ value: Values.Relation) -> Self } -extension RelationshipAttribute { - - internal var key: String { "rel" } -} - extension RelationshipAttribute where Self: ContentNode { internal func mutate(rel value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "rel", value: value) } } extension RelationshipAttribute where Self: EmptyNode { internal func mutate(rel value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "rel", value: value) } } /// The protocol provides the element with the required handler. -public protocol RequiredAttribute: AnyAttribute { +public protocol RequiredAttribute: Attribute { /// The function represents the html-attribute 'required'. /// @@ -2347,27 +1955,22 @@ public protocol RequiredAttribute: AnyAttribute { func required() -> Self } -extension RequiredAttribute { - - internal var key: String { "required" } -} - extension RequiredAttribute where Self: ContentNode { internal func mutate(required value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "required", value: value) } } extension RequiredAttribute where Self: EmptyNode { internal func mutate(required value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "required", value: value) } } /// The protocol provides the element with the reversed handler. -public protocol ReversedAttribute: AnyAttribute { +public protocol ReversedAttribute: Attribute { /// The function represents the html-attribute 'reversed'. /// @@ -2377,27 +1980,22 @@ public protocol ReversedAttribute: AnyAttribute { func reversed() -> Self } -extension ReversedAttribute { - - internal var key: String { "reversed" } -} - extension ReversedAttribute where Self: ContentNode { internal func mutate(reversed value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "reversed", value: value) } } extension ReversedAttribute where Self: EmptyNode { internal func mutate(reversed value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "reversed", value: value) } } /// The protocol provides the element with the role handler. -public protocol RoleAttribute: AnyAttribute { +public protocol RoleAttribute: Attribute { /// The function represents the html-attribute 'role'. /// @@ -2407,27 +2005,22 @@ public protocol RoleAttribute: AnyAttribute { func role(_ value: Values.Role) -> Self } -extension RoleAttribute { - - internal var key: String { "role" } -} - extension RoleAttribute where Self: ContentNode { internal func mutate(role value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "role", value: value) } } extension RoleAttribute where Self: EmptyNode { internal func mutate(role value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "role", value: value) } } /// The protocol provides the element with the rows handler. -public protocol RowsAttribute: AnyAttribute { +public protocol RowsAttribute: Attribute { /// The function represents the html-attribute 'rows'. /// @@ -2437,27 +2030,22 @@ public protocol RowsAttribute: AnyAttribute { func rows(_ size: Int) -> Self } -extension RowsAttribute { - - internal var key: String { "rows" } -} - extension RowsAttribute where Self: ContentNode { internal func mutate(rows value: Int) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "rows", value: value) } } extension RowsAttribute where Self: EmptyNode { internal func mutate(rows value: Int) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "rows", value: value) } } /// The protocol provides the element with the rowspan handler. -public protocol RowSpanAttribute: AnyAttribute { +public protocol RowSpanAttribute: Attribute { /// The function represents the html-attribute 'rowspan'. /// @@ -2467,27 +2055,22 @@ public protocol RowSpanAttribute: AnyAttribute { func rowSpan(_ size: Int) -> Self } -extension RowSpanAttribute { - - internal var key: String { "rowspan" } -} - extension RowSpanAttribute where Self: ContentNode { internal func mutate(rowspan value: Int) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "rowspan", value: value) } } extension RowSpanAttribute where Self: EmptyNode { internal func mutate(rowspan value: Int) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "rowspan", value: value) } } /// The protocol provides the element with the sandbox handler. -public protocol SandboxAttribute: AnyAttribute { +public protocol SandboxAttribute: Attribute { /// The function represents the html-attribute 'sandbox'. /// @@ -2497,27 +2080,22 @@ public protocol SandboxAttribute: AnyAttribute { func sandbox() -> Self } -extension SandboxAttribute { - - internal var key: String { "sandbox" } -} - extension SandboxAttribute where Self: ContentNode { internal func mutate(sandbox value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "sandbox", value: value) } } extension SandboxAttribute where Self: EmptyNode { internal func mutate(sandbox value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "sandbox", value: value) } } /// The protocol provides the element with the scope handler. -public protocol ScopeAttribute: AnyAttribute { +public protocol ScopeAttribute: Attribute { /// The function represents the html-attribute 'scope'. /// @@ -2527,27 +2105,22 @@ public protocol ScopeAttribute: AnyAttribute { func scope(_ value: String) -> Self } -extension ScopeAttribute { - - internal var key: String { "scope" } -} - extension ScopeAttribute where Self: ContentNode { internal func mutate(scope value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "scope", value: value) } } extension ScopeAttribute where Self: EmptyNode { internal func mutate(scope value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "scope", value: value) } } /// The protocol provides the element with the shape handler. -public protocol ShapeAttribute: AnyAttribute { +public protocol ShapeAttribute: Attribute { /// The function represents the html-attribute 'shape'. /// @@ -2557,27 +2130,22 @@ public protocol ShapeAttribute: AnyAttribute { func shape(_ value: Values.Shape) -> Self } -extension ShapeAttribute { - - internal var key: String { "shape" } -} - extension ShapeAttribute where Self: ContentNode { internal func mutate(shape value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "shape", value: value) } } extension ShapeAttribute where Self: EmptyNode { internal func mutate(shape value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "shape", value: value) } } /// The protocol provides the element with the size handler. -public protocol SizeAttribute: AnyAttribute { +public protocol SizeAttribute: Attribute { /// The function represents the html-attribute 'size'. /// @@ -2587,27 +2155,22 @@ public protocol SizeAttribute: AnyAttribute { func size(_ size: Int) -> Self } -extension SizeAttribute { - - internal var key: String { "size" } -} - extension SizeAttribute where Self: ContentNode { internal func mutate(size value: Int) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "size", value: value) } } extension SizeAttribute where Self: EmptyNode { internal func mutate(size value: Int) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "size", value: value) } } /// The protocol provides the element with the sizes handler. -public protocol SizesAttribute: AnyAttribute { +public protocol SizesAttribute: Attribute { /// The function represents the html-attribute 'sizes'. /// @@ -2617,27 +2180,22 @@ public protocol SizesAttribute: AnyAttribute { func sizes(_ size: Int) -> Self } -extension SizesAttribute { - - internal var key: String { "sizes" } -} - extension SizesAttribute where Self: ContentNode { internal func mutate(sizes value: Int) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "sizes", value: value) } } extension SizesAttribute where Self: EmptyNode { internal func mutate(sizes value: Int) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "sizes", value: value) } } /// The protocol provides the element with the slot handler. -public protocol SlotAttribute: AnyAttribute { +public protocol SlotAttribute: Attribute { /// The function represents the html-attribute 'slot'. /// @@ -2647,27 +2205,22 @@ public protocol SlotAttribute: AnyAttribute { func slot(_ value: String) -> Self } -extension SlotAttribute { - - internal var key: String { "slot" } -} - extension SlotAttribute where Self: ContentNode { internal func mutate(slot value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "slot", value: value) } } extension SlotAttribute where Self: EmptyNode { internal func mutate(slot value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "slot", value: value) } } /// The protocol provides the element with the span handler. -public protocol SpanAttribute: AnyAttribute { +public protocol SpanAttribute: Attribute { /// The function represents the html-attribute 'span'. /// @@ -2677,27 +2230,22 @@ public protocol SpanAttribute: AnyAttribute { func span(_ size: Int) -> Self } -extension SpanAttribute { - - internal var key: String { "span" } -} - extension SpanAttribute where Self: ContentNode { internal func mutate(span value: Int) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "span", value: value) } } extension SpanAttribute where Self: EmptyNode { internal func mutate(span value: Int) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "span", value: value) } } /// The protocol provides the element with the hasspellcheck handler. -public protocol SpellCheckAttribute: AnyAttribute { +public protocol SpellCheckAttribute: Attribute { /// The function represents the html-attribute 'spellcheck'. /// @@ -2707,27 +2255,22 @@ public protocol SpellCheckAttribute: AnyAttribute { func hasSpellCheck(_ value: Bool) -> Self } -extension SpellCheckAttribute { - - internal var key: String { "spellcheck" } -} - extension SpellCheckAttribute where Self: ContentNode { internal func mutate(spellcheck value: Bool) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "spellcheck", value: value) } } extension SpellCheckAttribute where Self: EmptyNode { internal func mutate(spellcheck value: Bool) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "spellcheck", value: value) } } /// The protocol provides the element with the source handler. -public protocol SourceAttribute: AnyAttribute { +public protocol SourceAttribute: Attribute { /// The function represents the html-attribute 'src'. /// @@ -2737,27 +2280,22 @@ public protocol SourceAttribute: AnyAttribute { func source(_ value: String) -> Self } -extension SourceAttribute { - - internal var key: String { "src" } -} - extension SourceAttribute where Self: ContentNode { internal func mutate(source value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "src", value: value) } } extension SourceAttribute where Self: EmptyNode { internal func mutate(source value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "src", value: value) } } /// The protocol provides the element with the start handler. -public protocol StartAttribute: AnyAttribute { +public protocol StartAttribute: Attribute { /// The function represents the html-attribute 'start'. /// @@ -2767,27 +2305,22 @@ public protocol StartAttribute: AnyAttribute { func start(_ size: Int) -> Self } -extension StartAttribute { - - internal var key: String { "start" } -} - extension StartAttribute where Self: ContentNode { internal func mutate(start value: Int) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "start", value: value) } } extension StartAttribute where Self: EmptyNode { internal func mutate(start value: Int) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "start", value: value) } } /// The protocol provides the element with the step handler. -public protocol StepAttribute: AnyAttribute { +public protocol StepAttribute: Attribute { /// The function represents the html-attribute 'step'. /// @@ -2797,27 +2330,22 @@ public protocol StepAttribute: AnyAttribute { func step(_ size: Int) -> Self } -extension StepAttribute { - - internal var key: String { "step" } -} - extension StepAttribute where Self: ContentNode { internal func mutate(step value: Int) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "step", value: value) } } extension StepAttribute where Self: EmptyNode { internal func mutate(step value: Int) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "step", value: value) } } /// The protocol provides the element with the style handler. -public protocol StyleAttribute: AnyAttribute { +public protocol StyleAttribute: Attribute { /// The function represents the html-attribute 'style'. /// @@ -2827,27 +2355,22 @@ public protocol StyleAttribute: AnyAttribute { func style(_ value: String) -> Self } -extension StyleAttribute { - - internal var key: String { "style" } -} - extension StyleAttribute where Self: ContentNode { internal func mutate(style value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "style", value: value) } } extension StyleAttribute where Self: EmptyNode { internal func mutate(style value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "style", value: value) } } /// The protocol provides the element with the tabindex handler. -public protocol TabulatorAttribute: AnyAttribute { +public protocol TabulatorAttribute: Attribute { /// The function represents the html-attribute 'tabindex'. /// @@ -2857,27 +2380,22 @@ public protocol TabulatorAttribute: AnyAttribute { func tabIndex(_ value: Int) -> Self } -extension TabulatorAttribute { - - internal var key: String { "tabindex" } -} - extension TabulatorAttribute where Self: ContentNode { internal func mutate(tabindex value: Int) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "tabindex", value: value) } } extension TabulatorAttribute where Self: EmptyNode { internal func mutate(tabindex value: Int) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "tabindex", value: value) } } /// The protocol provides the element with the target handler. -public protocol TargetAttribute: AnyAttribute { +public protocol TargetAttribute: Attribute { /// The function represents the html-attribute 'target'. /// @@ -2887,27 +2405,22 @@ public protocol TargetAttribute: AnyAttribute { func target(_ value: Values.Target) -> Self } -extension TargetAttribute { - - internal var key: String { "target" } -} - extension TargetAttribute where Self: ContentNode { internal func mutate(target value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "target", value: value) } } extension TargetAttribute where Self: EmptyNode { internal func mutate(target value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "target", value: value) } } /// The protocol provides the element with the title handler. -public protocol TitleAttribute: AnyAttribute { +public protocol TitleAttribute: Attribute { /// The function represents the html-attribute 'title'. /// @@ -2917,27 +2430,22 @@ public protocol TitleAttribute: AnyAttribute { func title(_ value: String) -> Self } -extension TitleAttribute { - - internal var key: String { "title" } -} - extension TitleAttribute where Self: ContentNode { internal func mutate(title value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "title", value: value) } } extension TitleAttribute where Self: EmptyNode { internal func mutate(title value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "title", value: value) } } /// The protocol provides the element with the translate handler. -public protocol TranslateAttribute: AnyAttribute { +public protocol TranslateAttribute: Attribute { /// The function represents the html-attribute 'translate'. /// @@ -2947,27 +2455,22 @@ public protocol TranslateAttribute: AnyAttribute { func translate(_ value: Values.Decision) -> Self } -extension TranslateAttribute { - - internal var key: String { "translate" } -} - extension TranslateAttribute where Self: ContentNode { internal func mutate(translate value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "translate", value: value) } } extension TranslateAttribute where Self: EmptyNode { internal func mutate(translate value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "translate", value: value) } } /// The protocol provides the element with the type handler. -public protocol TypeAttribute: AnyAttribute { +public protocol TypeAttribute: Attribute { associatedtype TypeValue @@ -2979,27 +2482,22 @@ public protocol TypeAttribute: AnyAttribute { func type(_ value: TypeValue) -> Self } -extension TypeAttribute { - - internal var key: String { "type" } -} - extension TypeAttribute where Self: ContentNode { internal func mutate(type value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "type", value: value) } } extension TypeAttribute where Self: EmptyNode { internal func mutate(type value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "type", value: value) } } /// The protocol provides the element with the value handler. -public protocol ValueAttribute: AnyAttribute { +public protocol ValueAttribute: Attribute { /// The function represents the html-attribute 'value'. /// @@ -3007,31 +2505,24 @@ public protocol ValueAttribute: AnyAttribute { /// /// ``` func value(_ value: String) -> Self - - func value(_ value: TemplateValue) -> Self -} - -extension ValueAttribute { - - internal var key: String { "value" } } extension ValueAttribute where Self: ContentNode { internal func mutate(value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "value", value: value) } } extension ValueAttribute where Self: EmptyNode { internal func mutate(value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "value", value: value) } } /// The protocol provides the element with the width handler. -public protocol WidthAttribute: AnyAttribute { +public protocol WidthAttribute: Attribute { /// The function represents the html-attribute 'width'. /// @@ -3041,27 +2532,22 @@ public protocol WidthAttribute: AnyAttribute { func width(_ size: Int) -> Self } -extension WidthAttribute { - - internal var key: String { "width" } -} - extension WidthAttribute where Self: ContentNode { internal func mutate(width value: Int) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "width", value: value) } } extension WidthAttribute where Self: EmptyNode { internal func mutate(width value: Int) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "width", value: value) } } /// The protocol provides the element with the wrap handler. -public protocol WrapAttribute: AnyAttribute { +public protocol WrapAttribute: Attribute { /// The function represents the html-attribute 'wrap'. /// @@ -3071,27 +2557,22 @@ public protocol WrapAttribute: AnyAttribute { func wrap(_ value: Values.Wrapping) -> Self } -extension WrapAttribute { - - internal var key: String { "wrap" } -} - extension WrapAttribute where Self: ContentNode { internal func mutate(wrap value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "wrap", value: value) } } extension WrapAttribute where Self: EmptyNode { internal func mutate(wrap value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "wrap", value: value) } } /// The protocol provides the element with the property handler. -public protocol PropertyAttribute: AnyAttribute { +public protocol PropertyAttribute: Attribute { /// The function represents the html-attribute 'property'. /// @@ -3103,27 +2584,22 @@ public protocol PropertyAttribute: AnyAttribute { func property(_ value: Values.Graph) -> Self } -extension PropertyAttribute { - - internal var key: String { "property" } -} - extension PropertyAttribute where Self: ContentNode { internal func mutate(property value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "property", value: value) } } extension PropertyAttribute where Self: EmptyNode { internal func mutate(property value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "property", value: value) } } /// The protocol provides the element with the selected handler. -public protocol SelectedAttribute: AnyAttribute { +public protocol SelectedAttribute: Attribute { /// The function represents the html-attribute 'selected'. /// @@ -3133,21 +2609,16 @@ public protocol SelectedAttribute: AnyAttribute { func selected() -> Self } -extension SelectedAttribute { - - internal var key: String { "selected" } -} - extension SelectedAttribute where Self: ContentNode { internal func mutate(selected value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "selected", value: value) } } extension SelectedAttribute where Self: EmptyNode { internal func mutate(selected value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "selected", value: value) } } diff --git a/Sources/HTMLKit/Abstraction/Attributes/EventAttributes.swift b/Sources/HTMLKit/Abstraction/Attributes/EventAttributes.swift index cf98c2a9..2d538a91 100644 --- a/Sources/HTMLKit/Abstraction/Attributes/EventAttributes.swift +++ b/Sources/HTMLKit/Abstraction/Attributes/EventAttributes.swift @@ -12,7 +12,7 @@ import OrderedCollections public typealias GlobalEventAttributes = ClipboardEventAttribute & DragEventAttribute & WheelEventAttribute & KeyboardEventAttribute & MouseEventAttribute /// The protocol provides the element with event handler. -public protocol WindowEventAttribute: AnyAttribute { +public protocol WindowEventAttribute: Attribute { /// The function represents the html-attribute 'on'. /// @@ -23,7 +23,7 @@ public protocol WindowEventAttribute: AnyAttribute { } /// The protocol provides the element with event handler. -public protocol FocusEventAttribute: AnyAttribute { +public protocol FocusEventAttribute: Attribute { /// The function represents the html-attribute 'on'. /// @@ -34,7 +34,7 @@ public protocol FocusEventAttribute: AnyAttribute { } /// The protocol provides the element with event handler. -public protocol PointerEventAttribute: AnyAttribute { +public protocol PointerEventAttribute: Attribute { /// The function represents the html-attribute 'on'. /// @@ -45,7 +45,7 @@ public protocol PointerEventAttribute: AnyAttribute { } /// The protocol provides the element with event handler. -public protocol MouseEventAttribute: AnyAttribute { +public protocol MouseEventAttribute: Attribute { /// The function represents the html-attribute 'on'. /// @@ -56,7 +56,7 @@ public protocol MouseEventAttribute: AnyAttribute { } /// The protocol provides the element with event handler. -public protocol WheelEventAttribute: AnyAttribute { +public protocol WheelEventAttribute: Attribute { /// The function represents the html-attribute 'on'. /// @@ -67,7 +67,7 @@ public protocol WheelEventAttribute: AnyAttribute { } /// The protocol provides the element with event handler. -public protocol InputEventAttribute: AnyAttribute { +public protocol InputEventAttribute: Attribute { /// The function represents the html-attribute 'on'. /// @@ -78,7 +78,7 @@ public protocol InputEventAttribute: AnyAttribute { } /// The protocol provides the element with event handler. -public protocol KeyboardEventAttribute: AnyAttribute { +public protocol KeyboardEventAttribute: Attribute { /// The function represents the html-attribute 'on'. /// @@ -89,7 +89,7 @@ public protocol KeyboardEventAttribute: AnyAttribute { } /// The protocol provides the element with event handler. -public protocol DragEventAttribute: AnyAttribute { +public protocol DragEventAttribute: Attribute { /// The function represents the html-attribute 'on'. /// @@ -100,7 +100,7 @@ public protocol DragEventAttribute: AnyAttribute { } /// The protocol provides the element with event handler. -public protocol ClipboardEventAttribute: AnyAttribute { +public protocol ClipboardEventAttribute: Attribute { /// The function represents the html-attribute 'on'. /// @@ -111,7 +111,7 @@ public protocol ClipboardEventAttribute: AnyAttribute { } /// The protocol provides the element with event handler. -public protocol SelectionEventAttribute: AnyAttribute { +public protocol SelectionEventAttribute: Attribute { /// The function represents the html-attribute 'on'. /// @@ -122,7 +122,7 @@ public protocol SelectionEventAttribute: AnyAttribute { } /// The protocol provides the element with event handler.r. -public protocol MediaEventAttribute: AnyAttribute { +public protocol MediaEventAttribute: Attribute { /// The function represents the html-attribute 'on'. /// @@ -133,7 +133,7 @@ public protocol MediaEventAttribute: AnyAttribute { } /// The protocol provides the element with event handler. -public protocol FormEventAttribute: AnyAttribute { +public protocol FormEventAttribute: Attribute { /// The function represents the html-attribute 'on'. /// @@ -144,7 +144,7 @@ public protocol FormEventAttribute: AnyAttribute { } /// The protocol provides the element with event handler. -public protocol DetailEventAttribute: AnyAttribute { +public protocol DetailEventAttribute: Attribute { /// The function represents the html-attribute 'on'. /// diff --git a/Sources/HTMLKit/Abstraction/Attributes/VectorAttributes.swift b/Sources/HTMLKit/Abstraction/Attributes/VectorAttributes.swift index 903881f3..0501b911 100644 --- a/Sources/HTMLKit/Abstraction/Attributes/VectorAttributes.swift +++ b/Sources/HTMLKit/Abstraction/Attributes/VectorAttributes.swift @@ -12,7 +12,7 @@ import OrderedCollections public typealias GlobalVectorAttributes = IdentifierAttribute & TabulatorAttribute & ClassAttribute & StyleAttribute & FillAttribute & FillOpacityAttribute & StrokeAttribute & StrokeWidthAttribute & StrokeOpacityAttribute & StrokeLineCapAttribute & StrokeLineJoinAttribute /// The protocol provides the element with the draw handler. -public protocol DrawAttribute: AnyAttribute { +public protocol DrawAttribute: Attribute { /// The function represents the html-attribute 'd'. /// @@ -22,21 +22,16 @@ public protocol DrawAttribute: AnyAttribute { func draw(_ value: String) -> Self } -extension DrawAttribute { - - internal var key: String { "d" } -} - extension DrawAttribute where Self: ContentNode { internal func mutate(draw value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "d", value: value) } } /// The protocol provides the element with the fill handler. -public protocol FillAttribute: AnyAttribute { +public protocol FillAttribute: Attribute { /// The function represents the html-attribute 'fill'. /// @@ -46,20 +41,15 @@ public protocol FillAttribute: AnyAttribute { func fill(_ value: String) -> Self } -extension FillAttribute { - - internal var key: String { "fill" } -} - extension FillAttribute where Self: ContentNode { internal func mutate(fill value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "fill", value: value) } } /// The protocol provides the element with the fill-opacity handler. -public protocol FillOpacityAttribute: AnyAttribute { +public protocol FillOpacityAttribute: Attribute { /// The function represents the html-attribute 'fill-opacity"'. /// @@ -69,20 +59,15 @@ public protocol FillOpacityAttribute: AnyAttribute { func fillOpacity(_ value: Double) -> Self } -extension FillOpacityAttribute { - - internal var key: String { "fill-opacity" } -} - extension FillOpacityAttribute where Self: ContentNode { internal func mutate(fillopacity value: Double) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "fill-opacity", value: value) } } /// The protocol provides the element with the stroke handler. -public protocol StrokeAttribute: AnyAttribute { +public protocol StrokeAttribute: Attribute { /// The function represents the html-attribute 'stroke'. /// @@ -92,20 +77,15 @@ public protocol StrokeAttribute: AnyAttribute { func stroke(_ value: String) -> Self } -extension StrokeAttribute { - - internal var key: String { "stroke" } -} - extension StrokeAttribute where Self: ContentNode { internal func mutate(stroke value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "stroke", value: value) } } /// The protocol provides the element with the stroke-width handler. -public protocol StrokeWidthAttribute: AnyAttribute { +public protocol StrokeWidthAttribute: Attribute { /// The function represents the html-attribute 'stroke-width'. /// @@ -115,20 +95,15 @@ public protocol StrokeWidthAttribute: AnyAttribute { func strokeWidth(_ size: Int) -> Self } -extension StrokeWidthAttribute { - - internal var key: String { "stroke-width" } -} - extension StrokeWidthAttribute where Self: ContentNode { internal func mutate(strokewidth value: Int) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "stroke-width", value: value) } } /// The protocol provides the element with the stroke-opacity handler. -public protocol StrokeOpacityAttribute: AnyAttribute { +public protocol StrokeOpacityAttribute: Attribute { /// The function represents the html-attribute 'stroke-opacity'. /// @@ -138,20 +113,15 @@ public protocol StrokeOpacityAttribute: AnyAttribute { func strokeOpacity(_ value: Double) -> Self } -extension StrokeOpacityAttribute { - - internal var key: String { "stroke-opacity" } -} - extension StrokeOpacityAttribute where Self: ContentNode { internal func mutate(strokeopacity value: Double) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "stroke-opacity", value: value) } } /// The protocol provides the element with the stroke-linecap handler. -public protocol StrokeLineCapAttribute: AnyAttribute { +public protocol StrokeLineCapAttribute: Attribute { /// The function represents the html-attribute 'stroke-linecap'. /// @@ -161,20 +131,15 @@ public protocol StrokeLineCapAttribute: AnyAttribute { func strokeLineCap(_ value: Values.Linecap) -> Self } -extension StrokeLineCapAttribute { - - internal var key: String { "stroke-linecap" } -} - extension StrokeLineCapAttribute where Self: ContentNode { internal func mutate(strokelinecap value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "stroke-linecap", value: value) } } /// The protocol provides the element with the stroke-linejoin handler. -public protocol StrokeLineJoinAttribute: AnyAttribute { +public protocol StrokeLineJoinAttribute: Attribute { /// The function represents the html-attribute 'stroke-linejoin'. /// @@ -184,20 +149,15 @@ public protocol StrokeLineJoinAttribute: AnyAttribute { func strokeLineJoin(_ value: Values.Linejoin) -> Self } -extension StrokeLineJoinAttribute { - - internal var key: String { "stroke-linejoin" } -} - extension StrokeLineJoinAttribute where Self: ContentNode { internal func mutate(strokelinejoin value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "stroke-linejoin", value: value) } } /// The protocol provides the element with the radius handler. -public protocol RadiusAttribute: AnyAttribute { +public protocol RadiusAttribute: Attribute { /// The function represents the html-attribute 'r'. /// @@ -207,20 +167,15 @@ public protocol RadiusAttribute: AnyAttribute { func radius(_ size: Int) -> Self } -extension RadiusAttribute { - - internal var key: String { "r" } -} - extension RadiusAttribute where Self: ContentNode { internal func mutate(radius value: Int) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "r", value: value) } } /// The protocol provides the element with the radius handler. -public protocol PositionPointAttribute: AnyAttribute { +public protocol PositionPointAttribute: Attribute { /// The function represents the html-attribute 'x' and 'y'. /// @@ -251,7 +206,7 @@ extension PositionPointAttribute where Self: ContentNode { } /// The protocol provides the element with the radius handler. -public protocol RadiusPointAttribute: AnyAttribute { +public protocol RadiusPointAttribute: Attribute { /// The function represents the html-attribute 'rx' and 'ry'. /// @@ -282,7 +237,7 @@ extension RadiusPointAttribute where Self: ContentNode { } /// The protocol provides the element with the radius handler. -public protocol CenterPointAttribute: AnyAttribute { +public protocol CenterPointAttribute: Attribute { /// The function represents the html-attribute 'cx' and 'cy'. /// @@ -313,7 +268,7 @@ extension CenterPointAttribute where Self: ContentNode { } /// The protocol provides the element with the viewbox handler. -public protocol ViewBoxAttribute: AnyAttribute { +public protocol ViewBoxAttribute: Attribute { /// The function represents the html-attribute 'viewbox'. /// @@ -323,14 +278,9 @@ public protocol ViewBoxAttribute: AnyAttribute { func viewBox(_ value: String) -> Self } -extension ViewBoxAttribute { - - internal var key: String { "viewbox" } -} - extension ViewBoxAttribute where Self: ContentNode { internal func mutate(viewbox value: String) -> Self { - return self.mutate(key: self.key, value: value) + return self.mutate(key: "viewbox", value: value) } } diff --git a/Sources/HTMLKit/Abstraction/Elements/BasicElements.swift b/Sources/HTMLKit/Abstraction/Elements/BasicElements.swift index 536b3b06..997614cb 100644 --- a/Sources/HTMLKit/Abstraction/Elements/BasicElements.swift +++ b/Sources/HTMLKit/Abstraction/Elements/BasicElements.swift @@ -22,17 +22,6 @@ public struct Comment: CommentNode, GlobalElement { } } -extension Comment: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents the document type. /// /// ```html @@ -47,27 +36,6 @@ public struct Document: DocumentNode, BasicElement { } } -extension Document: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - -extension Document { - - // MARK: Deprecations - - @available(*, deprecated, message: "Use Document(_ value: Values.Doctype) instead.") - public init(type: Values.Doctype) { - self.content = type.rawValue - } -} - /// The element represents the document's root element. /// /// ```html @@ -99,26 +67,13 @@ public struct Html: ContentNode, BasicElement { return self } - public func modify(unwrap value: TemplateValue, element: (Html, TemplateValue) -> Html) -> Html { + public func modify(unwrap value: T?, element: (Html, T) -> Html) -> Html { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -191,10 +146,6 @@ extension Html: GlobalAttributes, GlobalEventAttributes { public func id(_ value: String) -> Html { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Html { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Html { return mutate(lang: value.rawValue) @@ -204,11 +155,6 @@ extension Html: GlobalAttributes, GlobalEventAttributes { return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Html { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Html { return mutate(role: value.rawValue) } @@ -228,11 +174,6 @@ extension Html: GlobalAttributes, GlobalEventAttributes { public func title(_ value: String) -> Html { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Html { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Html { return mutate(translate: value.rawValue) @@ -263,13 +204,49 @@ extension Html: GlobalAttributes, GlobalEventAttributes { } } -extension Html: AnyContent { +public struct Custom: CustomNode, GlobalElement { + + public var name: String + + public var attributes: OrderedDictionary? + + public var content: [Content] + + public init(name: String, @ContentBuilder content: () -> [Content]) { + + self.name = name + self.content = content() + } - public func prerender(_ formula: Formula) throws { - try self.build(formula) + public init(name: String, attributes: OrderedDictionary?, content: [Content]) { + + self.name = name + self.attributes = attributes + self.content = content } - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) + public func modify(if condition: Bool, element: (Custom) -> Custom) -> Custom { + + if condition { + return self.modify(element(self)) + } + + return self + } + + public func modify(unwrap value: T?, element: (Custom, T) -> Custom) -> Custom { + + guard let value = value else { + return self + } + + return self.modify(element(self, value as T)) + } +} + +extension Custom: Attribute { + + public func custom(key: String, value: Any) -> Custom { + return mutate(key: key, value: value) } } diff --git a/Sources/HTMLKit/Abstraction/Elements/BodyElements.swift b/Sources/HTMLKit/Abstraction/Elements/BodyElements.swift index 86b0b7d5..b301a538 100644 --- a/Sources/HTMLKit/Abstraction/Elements/BodyElements.swift +++ b/Sources/HTMLKit/Abstraction/Elements/BodyElements.swift @@ -352,13 +352,13 @@ public struct Article: ContentNode, HtmlElement, BodyElement, FormElement, Figur internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -372,26 +372,13 @@ public struct Article: ContentNode, HtmlElement, BodyElement, FormElement, Figur return self } - public func modify(unwrap value: TemplateValue, element: (Article, TemplateValue) -> Article) -> Article { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Article, T) -> Article) -> Article { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -464,10 +451,6 @@ extension Article: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes public func id(_ value: String) -> Article { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Article { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Article { return mutate(lang: value.rawValue) @@ -477,11 +460,6 @@ extension Article: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Article { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Article { return mutate(role: value.rawValue) } @@ -501,11 +479,6 @@ extension Article: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes public func title(_ value: String) -> Article { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Article { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Article { return mutate(translate: value.rawValue) @@ -612,17 +585,6 @@ extension Article: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes } } -extension Article: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a generic section of the document. /// /// ```html @@ -634,13 +596,13 @@ public struct Section: ContentNode, HtmlElement, BodyElement, FigureElement, For internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -654,26 +616,13 @@ public struct Section: ContentNode, HtmlElement, BodyElement, FigureElement, For return self } - public func modify(unwrap value: TemplateValue, element: (Section, TemplateValue) -> Section) -> Section { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Section, T) -> Section) -> Section { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -746,10 +695,6 @@ extension Section: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes public func id(_ value: String) -> Section { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Section { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Section { return mutate(lang: value.rawValue) @@ -759,11 +704,6 @@ extension Section: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Section { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Section { return mutate(role: value.rawValue) } @@ -783,11 +723,6 @@ extension Section: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes public func title(_ value: String) -> Section { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Section { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Section { return mutate(translate: value.rawValue) @@ -894,17 +829,6 @@ extension Section: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes } } -extension Section: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a section of a page that links to other pages or parts within the page. /// /// ```html @@ -916,13 +840,13 @@ public struct Navigation: ContentNode, HtmlElement, BodyElement, FormElement, Fi internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -936,26 +860,13 @@ public struct Navigation: ContentNode, HtmlElement, BodyElement, FormElement, Fi return self } - public func modify(unwrap value: TemplateValue, element: (Navigation, TemplateValue) -> Navigation) -> Navigation { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Navigation, T) -> Navigation) -> Navigation { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -1028,10 +939,6 @@ extension Navigation: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribu public func id(_ value: String) -> Navigation { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Navigation { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Navigation { return mutate(lang: value.rawValue) @@ -1041,11 +948,6 @@ extension Navigation: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribu return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Navigation { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Navigation { return mutate(role: value.rawValue) } @@ -1065,11 +967,6 @@ extension Navigation: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribu public func title(_ value: String) -> Navigation { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Navigation { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Navigation { return mutate(translate: value.rawValue) @@ -1176,17 +1073,6 @@ extension Navigation: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribu } } -extension Navigation: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element defines some content aside from the content it is placed in. /// /// ```html @@ -1198,13 +1084,13 @@ public struct Aside: ContentNode, HtmlElement, BodyElement, FormElement, FigureE internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -1218,26 +1104,13 @@ public struct Aside: ContentNode, HtmlElement, BodyElement, FormElement, FigureE return self } - public func modify(unwrap value: TemplateValue, element: (Aside, TemplateValue) -> Aside) -> Aside { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Aside, T) -> Aside) -> Aside { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -1310,10 +1183,6 @@ extension Aside: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { public func id(_ value: String) -> Aside { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Aside { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Aside { return mutate(lang: value.rawValue) @@ -1323,11 +1192,6 @@ extension Aside: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Aside { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Aside { return mutate(role: value.rawValue) } @@ -1347,11 +1211,6 @@ extension Aside: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { public func title(_ value: String) -> Aside { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Aside { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Aside { return mutate(translate: value.rawValue) @@ -1458,17 +1317,6 @@ extension Aside: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { } } -extension Aside: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a heading. /// /// ```html @@ -1480,13 +1328,13 @@ public struct Heading1: ContentNode, HtmlElement, BodyElement, FormElement, Figu internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -1500,26 +1348,13 @@ public struct Heading1: ContentNode, HtmlElement, BodyElement, FormElement, Figu return self } - public func modify(unwrap value: TemplateValue, element: (Heading1, TemplateValue) -> Heading1) -> Heading1 { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Heading1, T) -> Heading1) -> Heading1 { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -1528,59 +1363,59 @@ extension Heading1: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func accessKey(_ value: Character) -> Heading1 { return mutate(accesskey: value) } - + public func autocapitalize(_ value: Values.Capitalization) -> Heading1 { return mutate(autocapitalize: value.rawValue) } - + public func autofocus() -> Heading1 { return mutate(autofocus: "autofocus") } - + public func `class`(_ value: String) -> Heading1 { return mutate(class: value) } - + public func isEditable(_ value: Bool) -> Heading1 { return mutate(contenteditable: value) } - + public func direction(_ value: Values.Direction) -> Heading1 { return mutate(dir: value.rawValue) } - + public func isDraggable(_ value: Bool) -> Heading1 { return mutate(draggable: value) } - + public func enterKeyHint(_ value: Values.Hint) -> Heading1 { return mutate(enterkeyhint: value.rawValue) } - + public func hidden() -> Heading1 { return mutate(hidden: "hidden") } - + public func inputMode(_ value: String) -> Heading1 { return mutate(inputmode: value) } - + public func `is`(_ value: String) -> Heading1 { return mutate(is: value) } - + public func itemId(_ value: String) -> Heading1 { return mutate(itemid: value) } - + public func itemProperty(_ value: String) -> Heading1 { return mutate(itemprop: value) } - + public func itemReference(_ value: String) -> Heading1 { return mutate(itemref: value) } - + public func itemScope(_ value: String) -> Heading1 { return mutate(itemscope: value) } @@ -1588,52 +1423,38 @@ extension Heading1: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func itemType(_ value: String) -> Heading1 { return mutate(itemtype: value) } - + public func id(_ value: String) -> Heading1 { return mutate(id: value) } - public func id(_ value: TemplateValue) -> Heading1 { - return mutate(id: value.rawValue) - } - public func language(_ value: Values.Language) -> Heading1 { return mutate(lang: value.rawValue) } - + public func nonce(_ value: String) -> Heading1 { return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Heading1 { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Heading1 { return mutate(role: value.rawValue) } - + public func hasSpellCheck(_ value: Bool) -> Heading1 { return mutate(spellcheck: value) } - + public func style(_ value: String) -> Heading1 { return mutate(style: value) } - + public func tabIndex(_ value: Int) -> Heading1 { return mutate(tabindex: value) } - + public func title(_ value: String) -> Heading1 { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Heading1 { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Heading1 { return mutate(translate: value.rawValue) @@ -1740,25 +1561,14 @@ extension Heading1: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute } } -extension Heading1: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - extension Heading1: Localizable { public init(_ localizedKey: String) { - self.content = [Localized(key: localizedKey)] + self.content = [LocalizedStringKey(key: localizedKey)] } - public init(_ localizedKey: String, with context: TemplateValue) where B : Encodable { - self.content = [Localized(key: localizedKey, context: context)] + public init(_ localizedKey: String, with context: some Encodable) { + self.content = [LocalizedStringKey(key: localizedKey, context: context)] } } @@ -1773,13 +1583,13 @@ public struct Heading2: ContentNode, HtmlElement, BodyElement, FormElement, Figu internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -1793,26 +1603,13 @@ public struct Heading2: ContentNode, HtmlElement, BodyElement, FormElement, Figu return self } - public func modify(unwrap value: TemplateValue, element: (Heading2, TemplateValue) -> Heading2) -> Heading2 { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Heading2, T) -> Heading2) -> Heading2 { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -1821,59 +1618,59 @@ extension Heading2: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func accessKey(_ value: Character) -> Heading2 { return mutate(accesskey: value) } - + public func autocapitalize(_ value: Values.Capitalization) -> Heading2 { return mutate(autocapitalize: value.rawValue) } - + public func autofocus() -> Heading2 { return mutate(autofocus: "autofocus") } - + public func `class`(_ value: String) -> Heading2 { return mutate(class: value) } - + public func isEditable(_ value: Bool) -> Heading2 { return mutate(contenteditable: value) } - + public func direction(_ value: Values.Direction) -> Heading2 { return mutate(dir: value.rawValue) } - + public func isDraggable(_ value: Bool) -> Heading2 { return mutate(draggable: value) } - + public func enterKeyHint(_ value: Values.Hint) -> Heading2 { return mutate(enterkeyhint: value.rawValue) } - + public func hidden() -> Heading2 { return mutate(hidden: "hidden") } - + public func inputMode(_ value: String) -> Heading2 { return mutate(inputmode: value) } - + public func `is`(_ value: String) -> Heading2 { return mutate(is: value) } - + public func itemId(_ value: String) -> Heading2 { return mutate(itemid: value) } - + public func itemProperty(_ value: String) -> Heading2 { return mutate(itemprop: value) } - + public func itemReference(_ value: String) -> Heading2 { return mutate(itemref: value) } - + public func itemScope(_ value: String) -> Heading2 { return mutate(itemscope: value) } @@ -1881,52 +1678,38 @@ extension Heading2: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func itemType(_ value: String) -> Heading2 { return mutate(itemtype: value) } - + public func id(_ value: String) -> Heading2 { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Heading2 { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Heading2 { return mutate(lang: value.rawValue) } - + public func nonce(_ value: String) -> Heading2 { return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Heading2 { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Heading2 { return mutate(role: value.rawValue) } - + public func hasSpellCheck(_ value: Bool) -> Heading2 { return mutate(spellcheck: value) } - + public func style(_ value: String) -> Heading2 { return mutate(style: value) } - + public func tabIndex(_ value: Int) -> Heading2 { return mutate(tabindex: value) } - + public func title(_ value: String) -> Heading2 { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Heading2 { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Heading2 { return mutate(translate: value.rawValue) @@ -2033,25 +1816,14 @@ extension Heading2: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute } } -extension Heading2: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - extension Heading2: Localizable { public init(_ localizedKey: String) { - self.content = [Localized(key: localizedKey)] + self.content = [LocalizedStringKey(key: localizedKey)] } - public init(_ localizedKey: String, with context: TemplateValue) where B : Encodable { - self.content = [Localized(key: localizedKey, context: context)] + public init(_ localizedKey: String, with context: some Encodable) { + self.content = [LocalizedStringKey(key: localizedKey, context: context)] } } @@ -2066,13 +1838,13 @@ public struct Heading3: ContentNode, HtmlElement, BodyElement, FormElement, Figu internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -2086,26 +1858,13 @@ public struct Heading3: ContentNode, HtmlElement, BodyElement, FormElement, Figu return self } - public func modify(unwrap value: TemplateValue, element: (Heading3, TemplateValue) -> Heading3) -> Heading3 { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Heading3, T) -> Heading3) -> Heading3 { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -2178,10 +1937,6 @@ extension Heading3: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func id(_ value: String) -> Heading3 { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Heading3 { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Heading3 { return mutate(lang: value.rawValue) @@ -2190,11 +1945,6 @@ extension Heading3: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func nonce(_ value: String) -> Heading3 { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Heading3 { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Heading3 { return mutate(role: value.rawValue) @@ -2215,11 +1965,6 @@ extension Heading3: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func title(_ value: String) -> Heading3 { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Heading3 { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Heading3 { return mutate(translate: value.rawValue) @@ -2326,25 +2071,14 @@ extension Heading3: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute } } -extension Heading3: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - extension Heading3: Localizable { public init(_ localizedKey: String) { - self.content = [Localized(key: localizedKey)] + self.content = [LocalizedStringKey(key: localizedKey)] } - public init(_ localizedKey: String, with context: TemplateValue) where B : Encodable { - self.content = [Localized(key: localizedKey, context: context)] + public init(_ localizedKey: String, with context: some Encodable) { + self.content = [LocalizedStringKey(key: localizedKey, context: context)] } } @@ -2359,13 +2093,13 @@ public struct Heading4: ContentNode, HtmlElement, BodyElement, FormElement, Figu internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -2379,26 +2113,13 @@ public struct Heading4: ContentNode, HtmlElement, BodyElement, FormElement, Figu return self } - public func modify(unwrap value: TemplateValue, element: (Heading4, TemplateValue) -> Heading4) -> Heading4 { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Heading4, T) -> Heading4) -> Heading4 { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -2471,10 +2192,6 @@ extension Heading4: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func id(_ value: String) -> Heading4 { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Heading4 { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Heading4 { return mutate(lang: value.rawValue) @@ -2483,11 +2200,6 @@ extension Heading4: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func nonce(_ value: String) -> Heading4 { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Heading4 { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Heading4 { return mutate(role: value.rawValue) @@ -2508,11 +2220,6 @@ extension Heading4: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func title(_ value: String) -> Heading4 { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Heading4 { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Heading4 { return mutate(translate: value.rawValue) @@ -2619,25 +2326,14 @@ extension Heading4: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute } } -extension Heading4: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - extension Heading4: Localizable { public init(_ localizedKey: String) { - self.content = [Localized(key: localizedKey)] + self.content = [LocalizedStringKey(key: localizedKey)] } - public init(_ localizedKey: String, with context: TemplateValue) where B : Encodable { - self.content = [Localized(key: localizedKey, context: context)] + public init(_ localizedKey: String, with context: some Encodable) { + self.content = [LocalizedStringKey(key: localizedKey, context: context)] } } @@ -2652,13 +2348,13 @@ public struct Heading5: ContentNode, HtmlElement, BodyElement, FormElement, Figu internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -2672,26 +2368,13 @@ public struct Heading5: ContentNode, HtmlElement, BodyElement, FormElement, Figu return self } - public func modify(unwrap value: TemplateValue, element: (Heading5, TemplateValue) -> Heading5) -> Heading5 { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Heading5, T) -> Heading5) -> Heading5 { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -2764,10 +2447,6 @@ extension Heading5: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func id(_ value: String) -> Heading5 { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Heading5 { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Heading5 { return mutate(lang: value.rawValue) @@ -2776,11 +2455,6 @@ extension Heading5: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func nonce(_ value: String) -> Heading5 { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Heading5 { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Heading5 { return mutate(role: value.rawValue) @@ -2801,11 +2475,6 @@ extension Heading5: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func title(_ value: String) -> Heading5 { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Heading5 { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Heading5 { return mutate(translate: value.rawValue) @@ -2912,25 +2581,14 @@ extension Heading5: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute } } -extension Heading5: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - extension Heading5: Localizable { public init(_ localizedKey: String) { - self.content = [Localized(key: localizedKey)] + self.content = [LocalizedStringKey(key: localizedKey)] } - public init(_ localizedKey: String, with context: TemplateValue) where B : Encodable { - self.content = [Localized(key: localizedKey, context: context)] + public init(_ localizedKey: String, with context: some Encodable) { + self.content = [LocalizedStringKey(key: localizedKey, context: context)] } } @@ -2945,13 +2603,13 @@ public struct Heading6: ContentNode, HtmlElement, BodyElement, FormElement, Figu internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -2965,26 +2623,13 @@ public struct Heading6: ContentNode, HtmlElement, BodyElement, FormElement, Figu return self } - public func modify(unwrap value: TemplateValue, element: (Heading6, TemplateValue) -> Heading6) -> Heading6 { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Heading6, T) -> Heading6) -> Heading6 { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -3057,10 +2702,6 @@ extension Heading6: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func id(_ value: String) -> Heading6 { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Heading6 { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Heading6 { return mutate(lang: value.rawValue) @@ -3069,11 +2710,6 @@ extension Heading6: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func nonce(_ value: String) -> Heading6 { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Heading6 { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Heading6 { return mutate(role: value.rawValue) @@ -3094,11 +2730,6 @@ extension Heading6: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func title(_ value: String) -> Heading6 { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Heading6 { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Heading6 { return mutate(translate: value.rawValue) @@ -3205,25 +2836,14 @@ extension Heading6: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute } } -extension Heading6: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - extension Heading6: Localizable { public init(_ localizedKey: String) { - self.content = [Localized(key: localizedKey)] + self.content = [LocalizedStringKey(key: localizedKey)] } - public init(_ localizedKey: String, with context: TemplateValue) where B : Encodable { - self.content = [Localized(key: localizedKey, context: context)] + public init(_ localizedKey: String, with context: some Encodable) { + self.content = [LocalizedStringKey(key: localizedKey, context: context)] } } @@ -3238,13 +2858,13 @@ public struct HeadingGroup: ContentNode, HtmlElement, BodyElement, FormElement, internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -3258,26 +2878,13 @@ public struct HeadingGroup: ContentNode, HtmlElement, BodyElement, FormElement, return self } - public func modify(unwrap value: TemplateValue, element: (HeadingGroup, TemplateValue) -> HeadingGroup) -> HeadingGroup { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (HeadingGroup, T) -> HeadingGroup) -> HeadingGroup { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -3350,10 +2957,6 @@ extension HeadingGroup: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttri public func id(_ value: String) -> HeadingGroup { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> HeadingGroup { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> HeadingGroup { return mutate(lang: value.rawValue) @@ -3363,11 +2966,6 @@ extension HeadingGroup: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttri return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> HeadingGroup { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> HeadingGroup { return mutate(role: value.rawValue) } @@ -3387,11 +2985,6 @@ extension HeadingGroup: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttri public func title(_ value: String) -> HeadingGroup { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> HeadingGroup { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> HeadingGroup { return mutate(translate: value.rawValue) @@ -3498,17 +3091,6 @@ extension HeadingGroup: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttri } } -extension HeadingGroup: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a header. /// /// ```html @@ -3520,13 +3102,13 @@ public struct Header: ContentNode, HtmlElement, BodyElement, FormElement, Figure internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -3540,26 +3122,13 @@ public struct Header: ContentNode, HtmlElement, BodyElement, FormElement, Figure return self } - public func modify(unwrap value: TemplateValue, element: (Header, TemplateValue) -> Header) -> Header { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Header, T) -> Header) -> Header { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -3632,10 +3201,6 @@ extension Header: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes public func id(_ value: String) -> Header { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Header { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Header { return mutate(lang: value.rawValue) @@ -3644,11 +3209,6 @@ extension Header: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes public func nonce(_ value: String) -> Header { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Header { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Header { return mutate(role: value.rawValue) @@ -3669,11 +3229,6 @@ extension Header: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes public func title(_ value: String) -> Header { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Header { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Header { return mutate(translate: value.rawValue) @@ -3780,17 +3335,6 @@ extension Header: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes } } -extension Header: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a footer. /// /// ```html @@ -3802,13 +3346,13 @@ public struct Footer: ContentNode, HtmlElement, BodyElement, FormElement, Figure internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -3822,26 +3366,13 @@ public struct Footer: ContentNode, HtmlElement, BodyElement, FormElement, Figure return self } - public func modify(unwrap value: TemplateValue, element: (Footer, TemplateValue) -> Footer) -> Footer { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Footer, T) -> Footer) -> Footer { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -3914,10 +3445,6 @@ extension Footer: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes public func id(_ value: String) -> Footer { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Footer { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Footer { return mutate(lang: value.rawValue) @@ -3926,11 +3453,6 @@ extension Footer: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes public func nonce(_ value: String) -> Footer { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Footer { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Footer { return mutate(role: value.rawValue) @@ -3951,11 +3473,6 @@ extension Footer: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes public func title(_ value: String) -> Footer { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Footer { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Footer { return mutate(translate: value.rawValue) @@ -4062,17 +3579,6 @@ extension Footer: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes } } -extension Footer: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents the contact information. /// /// ```html @@ -4084,13 +3590,13 @@ public struct Address: ContentNode, HtmlElement, BodyElement, FormElement, Figur internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -4104,26 +3610,13 @@ public struct Address: ContentNode, HtmlElement, BodyElement, FormElement, Figur return self } - public func modify(unwrap value: TemplateValue, element: (Address, TemplateValue) -> Address) -> Address { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Address, T) -> Address) -> Address { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -4196,10 +3689,6 @@ extension Address: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes public func id(_ value: String) -> Address { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Address { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Address { return mutate(lang: value.rawValue) @@ -4208,11 +3697,6 @@ extension Address: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes public func nonce(_ value: String) -> Address { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Address { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Address { return mutate(role: value.rawValue) @@ -4233,11 +3717,6 @@ extension Address: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes public func title(_ value: String) -> Address { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Address { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Address { return mutate(translate: value.rawValue) @@ -4344,17 +3823,6 @@ extension Address: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes } } -extension Address: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element is used to define a paragraph. /// /// ```html @@ -4366,13 +3834,13 @@ public struct Paragraph: ContentNode, HtmlElement, BodyElement, FormElement, Fig internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -4386,26 +3854,13 @@ public struct Paragraph: ContentNode, HtmlElement, BodyElement, FormElement, Fig return self } - public func modify(unwrap value: TemplateValue, element: (Paragraph, TemplateValue) -> Paragraph) -> Paragraph { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Paragraph, T) -> Paragraph) -> Paragraph { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -4479,10 +3934,6 @@ extension Paragraph: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut return mutate(id: value) } - public func id(_ value: TemplateValue) -> Paragraph { - return mutate(id: value.rawValue) - } - public func language(_ value: Values.Language) -> Paragraph { return mutate(lang: value.rawValue) } @@ -4490,11 +3941,6 @@ extension Paragraph: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut public func nonce(_ value: String) -> Paragraph { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Paragraph { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Paragraph { return mutate(role: value.rawValue) @@ -4515,11 +3961,6 @@ extension Paragraph: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut public func title(_ value: String) -> Paragraph { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Paragraph { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Paragraph { return mutate(translate: value.rawValue) @@ -4626,25 +4067,14 @@ extension Paragraph: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut } } -extension Paragraph: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - extension Paragraph: Localizable { public init(_ localizedKey: String) { - self.content = [Localized(key: localizedKey)] + self.content = [LocalizedStringKey(key: localizedKey)] } - public init(_ localizedKey: String, with context: TemplateValue) where B : Encodable { - self.content = [Localized(key: localizedKey, context: context)] + public init(_ localizedKey: String, with context: some Encodable) { + self.content = [LocalizedStringKey(key: localizedKey, context: context)] } } @@ -4674,26 +4104,13 @@ public struct HorizontalRule: EmptyNode, HtmlElement, BodyElement, FormElement, return self } - public func modify(unwrap value: TemplateValue, element: (HorizontalRule, TemplateValue) -> HorizontalRule) -> HorizontalRule { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (HorizontalRule, T) -> HorizontalRule) -> HorizontalRule { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -4766,10 +4183,6 @@ extension HorizontalRule: GlobalAttributes, GlobalEventAttributes, GlobalAriaAtt public func id(_ value: String) -> HorizontalRule { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> HorizontalRule { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> HorizontalRule { return mutate(lang: value.rawValue) @@ -4779,11 +4192,6 @@ extension HorizontalRule: GlobalAttributes, GlobalEventAttributes, GlobalAriaAtt return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> HorizontalRule { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> HorizontalRule { return mutate(role: value.rawValue) } @@ -4803,11 +4211,6 @@ extension HorizontalRule: GlobalAttributes, GlobalEventAttributes, GlobalAriaAtt public func title(_ value: String) -> HorizontalRule { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> HorizontalRule { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> HorizontalRule { return mutate(translate: value.rawValue) @@ -4914,17 +4317,6 @@ extension HorizontalRule: GlobalAttributes, GlobalEventAttributes, GlobalAriaAtt } } -extension HorizontalRule: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a block of preformatted text. /// /// ```html @@ -4936,13 +4328,13 @@ public struct PreformattedText: ContentNode, HtmlElement, BodyElement, FormEleme internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -4956,26 +4348,13 @@ public struct PreformattedText: ContentNode, HtmlElement, BodyElement, FormEleme return self } - public func modify(unwrap value: TemplateValue, element: (PreformattedText, TemplateValue) -> PreformattedText) -> PreformattedText { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (PreformattedText, T) -> PreformattedText) -> PreformattedText { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -5048,10 +4427,6 @@ extension PreformattedText: GlobalAttributes, GlobalEventAttributes, GlobalAriaA public func id(_ value: String) -> PreformattedText { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> PreformattedText { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> PreformattedText { return mutate(lang: value.rawValue) @@ -5060,11 +4435,6 @@ extension PreformattedText: GlobalAttributes, GlobalEventAttributes, GlobalAriaA public func nonce(_ value: String) -> PreformattedText { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> PreformattedText { - return mutate(role: value) - } public func role(_ value: Values.Role) -> PreformattedText { return mutate(role: value.rawValue) @@ -5085,11 +4455,6 @@ extension PreformattedText: GlobalAttributes, GlobalEventAttributes, GlobalAriaA public func title(_ value: String) -> PreformattedText { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> PreformattedText { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> PreformattedText { return mutate(translate: value.rawValue) @@ -5196,17 +4561,6 @@ extension PreformattedText: GlobalAttributes, GlobalEventAttributes, GlobalAriaA } } -extension PreformattedText: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a section that is quoted from another source. /// /// ```html @@ -5218,13 +4572,13 @@ public struct Blockquote: ContentNode, HtmlElement, BodyElement, FormElement, Fi internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -5238,26 +4592,13 @@ public struct Blockquote: ContentNode, HtmlElement, BodyElement, FormElement, Fi return self } - public func modify(unwrap value: TemplateValue, element: (Blockquote, TemplateValue) -> Blockquote) -> Blockquote { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Blockquote, T) -> Blockquote) -> Blockquote { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -5330,10 +4671,6 @@ extension Blockquote: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribu public func id(_ value: String) -> Blockquote { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Blockquote { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Blockquote { return mutate(lang: value.rawValue) @@ -5342,11 +4679,6 @@ extension Blockquote: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribu public func nonce(_ value: String) -> Blockquote { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Blockquote { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Blockquote { return mutate(role: value.rawValue) @@ -5367,11 +4699,6 @@ extension Blockquote: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribu public func title(_ value: String) -> Blockquote { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Blockquote { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Blockquote { return mutate(translate: value.rawValue) @@ -5482,25 +4809,14 @@ extension Blockquote: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribu } } -extension Blockquote: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - extension Blockquote: Localizable { public init(_ localizedKey: String) { - self.content = [Localized(key: localizedKey)] + self.content = [LocalizedStringKey(key: localizedKey)] } - public init(_ localizedKey: String, with context: TemplateValue) where B : Encodable { - self.content = [Localized(key: localizedKey, context: context)] + public init(_ localizedKey: String, with context: some Encodable) { + self.content = [LocalizedStringKey(key: localizedKey, context: context)] } } @@ -5535,26 +4851,13 @@ public struct OrderedList: ContentNode, HtmlElement, BodyElement, FormElement, F return self } - public func modify(unwrap value: TemplateValue, element: (OrderedList, TemplateValue) -> OrderedList) -> OrderedList { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (OrderedList, T) -> OrderedList) -> OrderedList { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -5627,10 +4930,6 @@ extension OrderedList: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttrib public func id(_ value: String) -> OrderedList { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> OrderedList { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> OrderedList { return mutate(lang: value.rawValue) @@ -5639,11 +4938,6 @@ extension OrderedList: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttrib public func nonce(_ value: String) -> OrderedList { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> OrderedList { - return mutate(role: value) - } public func role(_ value: Values.Role) -> OrderedList { return mutate(role: value.rawValue) @@ -5664,11 +4958,6 @@ extension OrderedList: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttrib public func title(_ value: String) -> OrderedList { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> OrderedList { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> OrderedList { return mutate(translate: value.rawValue) @@ -5787,17 +5076,6 @@ extension OrderedList: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttrib } } -extension OrderedList: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a list of items, where the order of the items is not important. /// /// ```html @@ -5829,26 +5107,13 @@ public struct UnorderedList: ContentNode, HtmlElement, BodyElement, FormElement, return self } - public func modify(unwrap value: TemplateValue, element: (UnorderedList, TemplateValue) -> UnorderedList) -> UnorderedList { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (UnorderedList, T) -> UnorderedList) -> UnorderedList { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -5921,10 +5186,6 @@ extension UnorderedList: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttr public func id(_ value: String) -> UnorderedList { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> UnorderedList { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> UnorderedList { return mutate(lang: value.rawValue) @@ -5934,11 +5195,6 @@ extension UnorderedList: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttr return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> UnorderedList { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> UnorderedList { return mutate(role: value.rawValue) } @@ -5958,11 +5214,6 @@ extension UnorderedList: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttr public func title(_ value: String) -> UnorderedList { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> UnorderedList { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> UnorderedList { return mutate(translate: value.rawValue) @@ -6069,17 +5320,6 @@ extension UnorderedList: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttr } } -extension UnorderedList: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element defines a list of terms and corresponding definitions. /// /// ```html @@ -6111,26 +5351,13 @@ public struct DescriptionList: ContentNode, HtmlElement, BodyElement, FormElemen return self } - public func modify(unwrap value: TemplateValue, element: (DescriptionList, TemplateValue) -> DescriptionList) -> DescriptionList { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (DescriptionList, T) -> DescriptionList) -> DescriptionList { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -6203,10 +5430,6 @@ extension DescriptionList: GlobalAttributes, GlobalEventAttributes, GlobalAriaAt public func id(_ value: String) -> DescriptionList { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> DescriptionList { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> DescriptionList { return mutate(lang: value.rawValue) @@ -6216,11 +5439,6 @@ extension DescriptionList: GlobalAttributes, GlobalEventAttributes, GlobalAriaAt return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> DescriptionList { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> DescriptionList { return mutate(role: value.rawValue) } @@ -6240,11 +5458,6 @@ extension DescriptionList: GlobalAttributes, GlobalEventAttributes, GlobalAriaAt public func title(_ value: String) -> DescriptionList { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> DescriptionList { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> DescriptionList { return mutate(translate: value.rawValue) @@ -6351,17 +5564,6 @@ extension DescriptionList: GlobalAttributes, GlobalEventAttributes, GlobalAriaAt } } -extension DescriptionList: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element can thus be used to annotate illustrations, diagrams, photos, code listings. /// /// ```html @@ -6393,26 +5595,13 @@ public struct Figure: ContentNode, HtmlElement, BodyElement, FormElement, Figure return self } - public func modify(unwrap value: TemplateValue, element: (Figure, TemplateValue) -> Figure) -> Figure { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Figure, T) -> Figure) -> Figure { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -6485,10 +5674,6 @@ extension Figure: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes public func id(_ value: String) -> Figure { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Figure { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Figure { return mutate(lang: value.rawValue) @@ -6498,11 +5683,6 @@ extension Figure: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Figure { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Figure { return mutate(role: value.rawValue) } @@ -6522,11 +5702,6 @@ extension Figure: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes public func title(_ value: String) -> Figure { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Figure { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Figure { return mutate(translate: value.rawValue) @@ -6633,17 +5808,6 @@ extension Figure: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes } } -extension Figure: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a comment output. /// /// ```html @@ -6655,13 +5819,13 @@ public struct Anchor: ContentNode, HtmlElement, BodyElement, FormElement, Figure internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -6675,26 +5839,13 @@ public struct Anchor: ContentNode, HtmlElement, BodyElement, FormElement, Figure return self } - public func modify(unwrap value: TemplateValue, element: (Anchor, TemplateValue) -> Anchor) -> Anchor { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Anchor, T) -> Anchor) -> Anchor { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -6767,10 +5918,6 @@ extension Anchor: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func id(_ value: String) -> Anchor { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Anchor { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Anchor { return mutate(lang: value.rawValue) @@ -6779,11 +5926,6 @@ extension Anchor: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func nonce(_ value: String) -> Anchor { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Anchor { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Anchor { return mutate(role: value.rawValue) @@ -6804,11 +5946,6 @@ extension Anchor: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func title(_ value: String) -> Anchor { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Anchor { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Anchor { return mutate(translate: value.rawValue) @@ -6822,10 +5959,6 @@ extension Anchor: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, return mutate(href: value) } - public func reference(_ value: TemplateValue) -> Anchor { - return mutate(href: value.rawValue) - } - public func referenceLanguage(_ value: Values.Language) -> Anchor { return mutate(hreflang: value.rawValue) } @@ -6955,25 +6088,14 @@ extension Anchor: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, } } -extension Anchor: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - extension Anchor: Localizable { public init(_ localizedKey: String) { - self.content = [Localized(key: localizedKey)] + self.content = [LocalizedStringKey(key: localizedKey)] } - public init(_ localizedKey: String, with context: TemplateValue) where B : Encodable { - self.content = [Localized(key: localizedKey, context: context)] + public init(_ localizedKey: String, with context: some Encodable) { + self.content = [LocalizedStringKey(key: localizedKey, context: context)] } } @@ -6988,13 +6110,13 @@ public struct Emphasize: ContentNode, HtmlElement, BodyElement, FormElement, Fig internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -7008,26 +6130,13 @@ public struct Emphasize: ContentNode, HtmlElement, BodyElement, FormElement, Fig return self } - public func modify(unwrap value: TemplateValue, element: (Emphasize, TemplateValue) -> Emphasize) -> Emphasize { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Emphasize, T) -> Emphasize) -> Emphasize { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -7100,10 +6209,6 @@ extension Emphasize: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut public func id(_ value: String) -> Emphasize { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Emphasize { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Emphasize { return mutate(lang: value.rawValue) @@ -7112,11 +6217,6 @@ extension Emphasize: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut public func nonce(_ value: String) -> Emphasize { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Emphasize { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Emphasize { return mutate(role: value.rawValue) @@ -7137,11 +6237,6 @@ extension Emphasize: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut public func title(_ value: String) -> Emphasize { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Emphasize { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Emphasize { return mutate(translate: value.rawValue) @@ -7248,17 +6343,6 @@ extension Emphasize: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut } } -extension Emphasize: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element provides strong typographic emphasis. /// /// ```html @@ -7270,13 +6354,13 @@ public struct Strong: ContentNode, HtmlElement, BodyElement, FormElement, Figure internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -7290,26 +6374,13 @@ public struct Strong: ContentNode, HtmlElement, BodyElement, FormElement, Figure return self } - public func modify(unwrap value: TemplateValue, element: (Strong, TemplateValue) -> Strong) -> Strong { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Strong, T) -> Strong) -> Strong { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -7382,10 +6453,6 @@ extension Strong: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes public func id(_ value: String) -> Strong { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Strong { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Strong { return mutate(lang: value.rawValue) @@ -7394,11 +6461,6 @@ extension Strong: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes public func nonce(_ value: String) -> Strong { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Strong { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Strong { return mutate(role: value.rawValue) @@ -7419,11 +6481,6 @@ extension Strong: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes public func title(_ value: String) -> Strong { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Strong { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Strong { return mutate(translate: value.rawValue) @@ -7530,17 +6587,6 @@ extension Strong: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes } } -extension Strong: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents side comments such as small print. /// /// ```html @@ -7552,13 +6598,13 @@ public struct Small: ContentNode, HtmlElement, BodyElement, FormElement, FigureE internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -7572,26 +6618,13 @@ public struct Small: ContentNode, HtmlElement, BodyElement, FormElement, FigureE return self } - public func modify(unwrap value: TemplateValue, element: (Small, TemplateValue) -> Small) -> Small { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Small, T) -> Small) -> Small { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -7664,10 +6697,6 @@ extension Small: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { public func id(_ value: String) -> Small { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Small { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Small { return mutate(lang: value.rawValue) @@ -7676,11 +6705,6 @@ extension Small: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { public func nonce(_ value: String) -> Small { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Small { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Small { return mutate(role: value.rawValue) @@ -7701,11 +6725,6 @@ extension Small: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { public func title(_ value: String) -> Small { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Small { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Small { return mutate(translate: value.rawValue) @@ -7812,25 +6831,14 @@ extension Small: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { } } -extension Small: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - extension Small: Localizable { public init(_ localizedKey: String) { - self.content = [Localized(key: localizedKey)] + self.content = [LocalizedStringKey(key: localizedKey)] } - public init(_ localizedKey: String, with context: TemplateValue) where B : Encodable { - self.content = [Localized(key: localizedKey, context: context)] + public init(_ localizedKey: String, with context: some Encodable) { + self.content = [LocalizedStringKey(key: localizedKey, context: context)] } } @@ -7845,13 +6853,13 @@ public struct StrikeThrough: ContentNode, HtmlElement, BodyElement, FormElement, internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -7865,26 +6873,13 @@ public struct StrikeThrough: ContentNode, HtmlElement, BodyElement, FormElement, return self } - public func modify(unwrap value: TemplateValue, element: (StrikeThrough, TemplateValue) -> StrikeThrough) -> StrikeThrough { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (StrikeThrough, T) -> StrikeThrough) -> StrikeThrough { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -7957,10 +6952,6 @@ extension StrikeThrough: GlobalAttributes, GlobalEventAttributes { public func id(_ value: String) -> StrikeThrough { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> StrikeThrough { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> StrikeThrough { return mutate(lang: value.rawValue) @@ -7969,11 +6960,6 @@ extension StrikeThrough: GlobalAttributes, GlobalEventAttributes { public func nonce(_ value: String) -> StrikeThrough { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> StrikeThrough { - return mutate(role: value) - } public func role(_ value: Values.Role) -> StrikeThrough { return mutate(role: value.rawValue) @@ -7994,11 +6980,6 @@ extension StrikeThrough: GlobalAttributes, GlobalEventAttributes { public func title(_ value: String) -> StrikeThrough { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> StrikeThrough { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> StrikeThrough { return mutate(translate: value.rawValue) @@ -8029,25 +7010,14 @@ extension StrikeThrough: GlobalAttributes, GlobalEventAttributes { } } -extension StrikeThrough: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - extension StrikeThrough: Localizable { public init(_ localizedKey: String) { - self.content = [Localized(key: localizedKey)] + self.content = [LocalizedStringKey(key: localizedKey)] } - public init(_ localizedKey: String, with context: TemplateValue) where B : Encodable { - self.content = [Localized(key: localizedKey, context: context)] + public init(_ localizedKey: String, with context: some Encodable) { + self.content = [LocalizedStringKey(key: localizedKey, context: context)] } } @@ -8062,13 +7032,13 @@ public struct Main: ContentNode, HtmlElement, BodyElement, FormElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -8082,26 +7052,13 @@ public struct Main: ContentNode, HtmlElement, BodyElement, FormElement { return self } - public func modify(unwrap value: TemplateValue, element: (Main, TemplateValue) -> Main) -> Main { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Main, T) -> Main) -> Main { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -8174,10 +7131,6 @@ extension Main: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { public func id(_ value: String) -> Main { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Main { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Main { return mutate(lang: value.rawValue) @@ -8186,11 +7139,6 @@ extension Main: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { public func nonce(_ value: String) -> Main { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Main { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Main { return mutate(role: value.rawValue) @@ -8211,11 +7159,6 @@ extension Main: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { public func title(_ value: String) -> Main { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Main { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Main { return mutate(translate: value.rawValue) @@ -8322,17 +7265,6 @@ extension Main: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { } } -extension Main: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element is used to represent different kinds of containers. /// /// ```html @@ -8344,13 +7276,13 @@ public struct Division: ContentNode, HtmlElement, BodyElement, FormElement, Figu internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -8364,26 +7296,13 @@ public struct Division: ContentNode, HtmlElement, BodyElement, FormElement, Figu return self } - public func modify(unwrap value: TemplateValue, element: (Division, TemplateValue) -> Division) -> Division { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Division, T) -> Division) -> Division { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -8456,10 +7375,6 @@ extension Division: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func id(_ value: String) -> Division { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Division { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Division { return mutate(lang: value.rawValue) @@ -8468,11 +7383,6 @@ extension Division: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func nonce(_ value: String) -> Division { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Division { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Division { return mutate(role: value.rawValue) @@ -8493,11 +7403,6 @@ extension Division: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func title(_ value: String) -> Division { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Division { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Division { return mutate(translate: value.rawValue) @@ -8604,17 +7509,6 @@ extension Division: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute } } -extension Division: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a comment output. /// /// ```html @@ -8626,13 +7520,13 @@ public struct Definition: ContentNode, HtmlElement, BodyElement, FormElement, Fi internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -8646,26 +7540,13 @@ public struct Definition: ContentNode, HtmlElement, BodyElement, FormElement, Fi return self } - public func modify(unwrap value: TemplateValue, element: (Definition, TemplateValue) -> Definition) -> Definition { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Definition, T) -> Definition) -> Definition { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -8738,10 +7619,6 @@ extension Definition: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribu public func id(_ value: String) -> Definition { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Definition { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Definition { return mutate(lang: value.rawValue) @@ -8750,11 +7627,6 @@ extension Definition: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribu public func nonce(_ value: String) -> Definition { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Definition { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Definition { return mutate(role: value.rawValue) @@ -8775,11 +7647,6 @@ extension Definition: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribu public func title(_ value: String) -> Definition { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Definition { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Definition { return mutate(translate: value.rawValue) @@ -8886,17 +7753,6 @@ extension Definition: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribu } } -extension Definition: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element specifies a citation. /// /// ```html @@ -8908,13 +7764,13 @@ public struct Cite: ContentNode, HtmlElement, BodyElement, FormElement, FigureEl internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -8928,26 +7784,13 @@ public struct Cite: ContentNode, HtmlElement, BodyElement, FormElement, FigureEl return self } - public func modify(unwrap value: TemplateValue, element: (Cite, TemplateValue) -> Cite) -> Cite { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Cite, T) -> Cite) -> Cite { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -9020,10 +7863,6 @@ extension Cite: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { public func id(_ value: String) -> Cite { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Cite { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Cite { return mutate(lang: value.rawValue) @@ -9033,11 +7872,6 @@ extension Cite: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Cite { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Cite { return mutate(role: value.rawValue) } @@ -9057,11 +7891,6 @@ extension Cite: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { public func title(_ value: String) -> Cite { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Cite { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Cite { return mutate(translate: value.rawValue) @@ -9168,17 +7997,6 @@ extension Cite: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { } } -extension Cite: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element is used for a short quotation. /// /// ```html @@ -9190,13 +8008,13 @@ public struct ShortQuote: ContentNode, HtmlElement, BodyElement, FormElement, Fi internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -9210,26 +8028,13 @@ public struct ShortQuote: ContentNode, HtmlElement, BodyElement, FormElement, Fi return self } - public func modify(unwrap value: TemplateValue, element: (ShortQuote, TemplateValue) -> ShortQuote) -> ShortQuote { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (ShortQuote, T) -> ShortQuote) -> ShortQuote { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -9302,10 +8107,6 @@ extension ShortQuote: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribu public func id(_ value: String) -> ShortQuote { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> ShortQuote { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> ShortQuote { return mutate(lang: value.rawValue) @@ -9314,11 +8115,6 @@ extension ShortQuote: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribu public func nonce(_ value: String) -> ShortQuote { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> ShortQuote { - return mutate(role: value) - } public func role(_ value: Values.Role) -> ShortQuote { return mutate(role: value.rawValue) @@ -9339,11 +8135,6 @@ extension ShortQuote: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribu public func title(_ value: String) -> ShortQuote { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> ShortQuote { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> ShortQuote { return mutate(translate: value.rawValue) @@ -9454,17 +8245,6 @@ extension ShortQuote: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribu } } -extension ShortQuote: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents an abbreviation or acronym. /// /// ```html @@ -9476,13 +8256,13 @@ public struct Abbreviation: ContentNode, HtmlElement, BodyElement, FormElement, internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -9496,26 +8276,13 @@ public struct Abbreviation: ContentNode, HtmlElement, BodyElement, FormElement, return self } - public func modify(unwrap value: TemplateValue, element: (Abbreviation, TemplateValue) -> Abbreviation) -> Abbreviation { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Abbreviation, T) -> Abbreviation) -> Abbreviation { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -9588,10 +8355,6 @@ extension Abbreviation: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttri public func id(_ value: String) -> Abbreviation { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Abbreviation { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Abbreviation { return mutate(lang: value.rawValue) @@ -9601,11 +8364,6 @@ extension Abbreviation: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttri return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Abbreviation { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Abbreviation { return mutate(role: value.rawValue) } @@ -9625,11 +8383,6 @@ extension Abbreviation: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttri public func title(_ value: String) -> Abbreviation { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Abbreviation { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Abbreviation { return mutate(translate: value.rawValue) @@ -9736,17 +8489,6 @@ extension Abbreviation: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttri } } -extension Abbreviation: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element allows one or more spans of phrasing content to be marked with ruby annotations. /// /// ```html @@ -9778,26 +8520,13 @@ public struct Ruby: ContentNode, HtmlElement, BodyElement, FormElement, FigureEl return self } - public func modify(unwrap value: TemplateValue, element: (Ruby, TemplateValue) -> Ruby) -> Ruby { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Ruby, T) -> Ruby) -> Ruby { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -9806,59 +8535,59 @@ extension Ruby: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { public func accessKey(_ value: Character) -> Ruby { return mutate(accesskey: value) } - + public func autocapitalize(_ value: Values.Capitalization) -> Ruby { return mutate(autocapitalize: value.rawValue) } - + public func autofocus() -> Ruby { return mutate(autofocus: "autofocus") } - + public func `class`(_ value: String) -> Ruby { return mutate(class: value) } - + public func isEditable(_ value: Bool) -> Ruby { return mutate(contenteditable: value) } - + public func direction(_ value: Values.Direction) -> Ruby { return mutate(dir: value.rawValue) } - + public func isDraggable(_ value: Bool) -> Ruby { return mutate(draggable: value) } - + public func enterKeyHint(_ value: Values.Hint) -> Ruby { return mutate(enterkeyhint: value.rawValue) } - + public func hidden() -> Ruby { return mutate(hidden: "hidden") } - + public func inputMode(_ value: String) -> Ruby { return mutate(inputmode: value) } - + public func `is`(_ value: String) -> Ruby { return mutate(is: value) } - + public func itemId(_ value: String) -> Ruby { return mutate(itemid: value) } - + public func itemProperty(_ value: String) -> Ruby { return mutate(itemprop: value) } - + public func itemReference(_ value: String) -> Ruby { return mutate(itemref: value) } - + public func itemScope(_ value: String) -> Ruby { return mutate(itemscope: value) } @@ -9866,52 +8595,38 @@ extension Ruby: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { public func itemType(_ value: String) -> Ruby { return mutate(itemtype: value) } - + public func id(_ value: String) -> Ruby { return mutate(id: value) } - public func id(_ value: TemplateValue) -> Ruby { - return mutate(id: value.rawValue) - } - public func language(_ value: Values.Language) -> Ruby { return mutate(lang: value.rawValue) } - + public func nonce(_ value: String) -> Ruby { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Ruby { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Ruby { return mutate(role: value.rawValue) } - + public func hasSpellCheck(_ value: Bool) -> Ruby { return mutate(spellcheck: value) } - + public func style(_ value: String) -> Ruby { return mutate(style: value) } - + public func tabIndex(_ value: Int) -> Ruby { return mutate(tabindex: value) } - + public func title(_ value: String) -> Ruby { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Ruby { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Ruby { return mutate(translate: value.rawValue) @@ -10018,17 +8733,6 @@ extension Ruby: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { } } -extension Ruby: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a comment output. /// /// ```html @@ -10040,13 +8744,13 @@ public struct Data: ContentNode, HtmlElement, BodyElement, FormElement, FigureEl internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -10060,26 +8764,13 @@ public struct Data: ContentNode, HtmlElement, BodyElement, FormElement, FigureEl return self } - public func modify(unwrap value: TemplateValue, element: (Data, TemplateValue) -> Data) -> Data { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Data, T) -> Data) -> Data { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -10152,10 +8843,6 @@ extension Data: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, V public func id(_ value: String) -> Data { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Data { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Data { return mutate(lang: value.rawValue) @@ -10165,11 +8852,6 @@ extension Data: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, V return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Data { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Data { return mutate(role: value.rawValue) } @@ -10189,11 +8871,6 @@ extension Data: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, V public func title(_ value: String) -> Data { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Data { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Data { return mutate(translate: value.rawValue) @@ -10203,10 +8880,6 @@ extension Data: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, V return mutate(value: value) } - public func value(_ value: TemplateValue) -> Data { - return mutate(value: value.rawValue) - } - public func custom(key: String, value: Any) -> Data { return mutate(key: key, value: value) } @@ -10308,17 +8981,6 @@ extension Data: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, V } } -extension Data: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents its contents, along with a machine-readable form of those contents in the datetime attribute. /// /// ```html @@ -10330,13 +8992,13 @@ public struct Time: ContentNode, HtmlElement, BodyElement, FormElement, FigureEl internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -10350,26 +9012,13 @@ public struct Time: ContentNode, HtmlElement, BodyElement, FormElement, FigureEl return self } - public func modify(unwrap value: TemplateValue, element: (Time, TemplateValue) -> Time) -> Time { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Time, T) -> Time) -> Time { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -10442,10 +9091,6 @@ extension Time: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, D public func id(_ value: String) -> Time { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Time { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Time { return mutate(lang: value.rawValue) @@ -10454,11 +9099,6 @@ extension Time: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, D public func nonce(_ value: String) -> Time { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Time { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Time { return mutate(role: value.rawValue) @@ -10479,11 +9119,6 @@ extension Time: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, D public func title(_ value: String) -> Time { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Time { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Time { return mutate(translate: value.rawValue) @@ -10594,17 +9229,6 @@ extension Time: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, D } } -extension Time: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents an example of code. /// /// ```html @@ -10616,13 +9240,13 @@ public struct Code: ContentNode, HtmlElement, BodyElement, FormElement, FigureEl internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -10636,26 +9260,13 @@ public struct Code: ContentNode, HtmlElement, BodyElement, FormElement, FigureEl return self } - public func modify(unwrap value: TemplateValue, element: (Code, TemplateValue) -> Code) -> Code { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Code, T) -> Code) -> Code { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -10728,10 +9339,6 @@ extension Code: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { public func id(_ value: String) -> Code { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Code { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Code { return mutate(lang: value.rawValue) @@ -10740,11 +9347,6 @@ extension Code: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { public func nonce(_ value: String) -> Code { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Code { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Code { return mutate(role: value.rawValue) @@ -10765,11 +9367,6 @@ extension Code: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { public func title(_ value: String) -> Code { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Code { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Code { return mutate(translate: value.rawValue) @@ -10876,17 +9473,6 @@ extension Code: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { } } -extension Code: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element indicates a variable name. /// /// ```html @@ -10898,13 +9484,13 @@ public struct Variable: ContentNode, HtmlElement, BodyElement, FormElement, Figu internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -10918,26 +9504,13 @@ public struct Variable: ContentNode, HtmlElement, BodyElement, FormElement, Figu return self } - public func modify(unwrap value: TemplateValue, element: (Variable, TemplateValue) -> Variable) -> Variable { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Variable, T) -> Variable) -> Variable { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -11010,10 +9583,6 @@ extension Variable: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func id(_ value: String) -> Variable { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Variable { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Variable { return mutate(lang: value.rawValue) @@ -11022,11 +9591,6 @@ extension Variable: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func nonce(_ value: String) -> Variable { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Variable { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Variable { return mutate(role: value.rawValue) @@ -11047,11 +9611,6 @@ extension Variable: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func title(_ value: String) -> Variable { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Variable { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Variable { return mutate(translate: value.rawValue) @@ -11158,17 +9717,6 @@ extension Variable: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute } } -extension Variable: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents sample or quoted output from another program or computing system. /// /// ```html @@ -11180,13 +9728,13 @@ public struct SampleOutput: ContentNode, HtmlElement, BodyElement, FormElement, internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -11200,26 +9748,13 @@ public struct SampleOutput: ContentNode, HtmlElement, BodyElement, FormElement, return self } - public func modify(unwrap value: TemplateValue, element: (SampleOutput, TemplateValue) -> SampleOutput) -> SampleOutput { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (SampleOutput, T) -> SampleOutput) -> SampleOutput { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -11290,11 +9825,7 @@ extension SampleOutput: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttri } public func id(_ value: String) -> SampleOutput { - return mutate(id: value) - } - - public func id(_ value: TemplateValue) -> SampleOutput { - return mutate(id: value.rawValue) + return mutate(id: value) } public func language(_ value: Values.Language) -> SampleOutput { @@ -11305,11 +9836,6 @@ extension SampleOutput: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttri return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> SampleOutput { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> SampleOutput { return mutate(role: value.rawValue) } @@ -11329,11 +9855,6 @@ extension SampleOutput: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttri public func title(_ value: String) -> SampleOutput { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> SampleOutput { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> SampleOutput { return mutate(translate: value.rawValue) @@ -11440,17 +9961,6 @@ extension SampleOutput: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttri } } -extension SampleOutput: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents user input. /// /// ```html @@ -11462,13 +9972,13 @@ public struct KeyboardInput: ContentNode, HtmlElement, BodyElement, FormElement, internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -11482,26 +9992,13 @@ public struct KeyboardInput: ContentNode, HtmlElement, BodyElement, FormElement, return self } - public func modify(unwrap value: TemplateValue, element: (KeyboardInput, TemplateValue) -> KeyboardInput) -> KeyboardInput { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (KeyboardInput, T) -> KeyboardInput) -> KeyboardInput { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -11574,10 +10071,6 @@ extension KeyboardInput: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttr public func id(_ value: String) -> KeyboardInput { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> KeyboardInput { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> KeyboardInput { return mutate(lang: value.rawValue) @@ -11586,11 +10079,6 @@ extension KeyboardInput: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttr public func nonce(_ value: String) -> KeyboardInput { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> KeyboardInput { - return mutate(role: value) - } public func role(_ value: Values.Role) -> KeyboardInput { return mutate(role: value.rawValue) @@ -11611,11 +10099,6 @@ extension KeyboardInput: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttr public func title(_ value: String) -> KeyboardInput { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> KeyboardInput { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> KeyboardInput { return mutate(translate: value.rawValue) @@ -11722,17 +10205,6 @@ extension KeyboardInput: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttr } } -extension KeyboardInput: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a subscript. /// /// ```html @@ -11744,13 +10216,13 @@ public struct Subscript: ContentNode, HtmlElement, BodyElement, FormElement, Fig internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -11764,26 +10236,13 @@ public struct Subscript: ContentNode, HtmlElement, BodyElement, FormElement, Fig return self } - public func modify(unwrap value: TemplateValue, element: (Subscript, TemplateValue) -> Subscript) -> Subscript { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Subscript, T) -> Subscript) -> Subscript { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -11856,11 +10315,6 @@ extension Subscript: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut public func id(_ value: String) -> Subscript { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Subscript { - return mutate(id: value.rawValue) - } - public func language(_ value: Values.Language) -> Subscript { return mutate(lang: value.rawValue) } @@ -11869,11 +10323,6 @@ extension Subscript: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Subscript { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Subscript { return mutate(role: value.rawValue) } @@ -11893,11 +10342,6 @@ extension Subscript: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut public func title(_ value: String) -> Subscript { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Subscript { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Subscript { return mutate(translate: value.rawValue) @@ -12004,17 +10448,6 @@ extension Subscript: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut } } -extension Subscript: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a superscript. /// /// ```html @@ -12026,13 +10459,13 @@ public struct Superscript: ContentNode, HtmlElement, BodyElement, FormElement, F internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -12046,26 +10479,13 @@ public struct Superscript: ContentNode, HtmlElement, BodyElement, FormElement, F return self } - public func modify(unwrap value: TemplateValue, element: (Superscript, TemplateValue) -> Superscript) -> Superscript { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Superscript, T) -> Superscript) -> Superscript { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -12138,10 +10558,6 @@ extension Superscript: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttrib public func id(_ value: String) -> Superscript { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Superscript { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Superscript { return mutate(lang: value.rawValue) @@ -12150,11 +10566,6 @@ extension Superscript: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttrib public func nonce(_ value: String) -> Superscript { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Superscript { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Superscript { return mutate(role: value.rawValue) @@ -12175,11 +10586,6 @@ extension Superscript: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttrib public func title(_ value: String) -> Superscript { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Superscript { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Superscript { return mutate(translate: value.rawValue) @@ -12286,17 +10692,6 @@ extension Superscript: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttrib } } -extension Superscript: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents an italic font text. /// /// ```html @@ -12308,13 +10703,13 @@ public struct Italic: ContentNode, HtmlElement, BodyElement, FormElement, Figure internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -12328,26 +10723,13 @@ public struct Italic: ContentNode, HtmlElement, BodyElement, FormElement, Figure return self } - public func modify(unwrap value: TemplateValue, element: (Italic, TemplateValue) -> Italic) -> Italic { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Italic, T) -> Italic) -> Italic { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -12420,10 +10802,6 @@ extension Italic: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes public func id(_ value: String) -> Italic { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Italic { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Italic { return mutate(lang: value.rawValue) @@ -12432,11 +10810,6 @@ extension Italic: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes public func nonce(_ value: String) -> Italic { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Italic { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Italic { return mutate(role: value.rawValue) @@ -12457,11 +10830,6 @@ extension Italic: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes public func title(_ value: String) -> Italic { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Italic { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Italic { return mutate(translate: value.rawValue) @@ -12571,22 +10939,11 @@ extension Italic: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes extension Italic: Localizable { public init(_ localizedKey: String) { - self.content = [Localized(key: localizedKey)] - } - - public init(_ localizedKey: String, with context: TemplateValue) where B : Encodable { - self.content = [Localized(key: localizedKey, context: context)] + self.content = [LocalizedStringKey(key: localizedKey)] } -} -extension Italic: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) + public init(_ localizedKey: String, with context: some Encodable) { + self.content = [LocalizedStringKey(key: localizedKey, context: context)] } } @@ -12601,13 +10958,13 @@ public struct Bold: ContentNode, HtmlElement, BodyElement, FormElement, FigureEl internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -12621,26 +10978,13 @@ public struct Bold: ContentNode, HtmlElement, BodyElement, FormElement, FigureEl return self } - public func modify(unwrap value: TemplateValue, element: (Bold, TemplateValue) -> Bold) -> Bold { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Bold, T) -> Bold) -> Bold { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -12713,10 +11057,6 @@ extension Bold: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { public func id(_ value: String) -> Bold { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Bold { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Bold { return mutate(lang: value.rawValue) @@ -12725,11 +11065,6 @@ extension Bold: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { public func nonce(_ value: String) -> Bold { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Bold { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Bold { return mutate(role: value.rawValue) @@ -12750,11 +11085,6 @@ extension Bold: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { public func title(_ value: String) -> Bold { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Bold { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Bold { return mutate(translate: value.rawValue) @@ -12864,22 +11194,11 @@ extension Bold: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { extension Bold: Localizable { public init(_ localizedKey: String) { - self.content = [Localized(key: localizedKey)] + self.content = [LocalizedStringKey(key: localizedKey)] } - public init(_ localizedKey: String, with context: TemplateValue) where B : Encodable { - self.content = [Localized(key: localizedKey, context: context)] - } -} - -extension Bold: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) + public init(_ localizedKey: String, with context: some Encodable) { + self.content = [LocalizedStringKey(key: localizedKey, context: context)] } } @@ -12894,13 +11213,13 @@ public struct Underline: ContentNode, HtmlElement, BodyElement, FormElement, Fig internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -12914,26 +11233,13 @@ public struct Underline: ContentNode, HtmlElement, BodyElement, FormElement, Fig return self } - public func modify(unwrap value: TemplateValue, element: (Underline, TemplateValue) -> Underline) -> Underline { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Underline, T) -> Underline) -> Underline { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -13006,10 +11312,6 @@ extension Underline: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut public func id(_ value: String) -> Underline { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Underline { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Underline { return mutate(lang: value.rawValue) @@ -13018,11 +11320,6 @@ extension Underline: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut public func nonce(_ value: String) -> Underline { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Underline { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Underline { return mutate(role: value.rawValue) @@ -13043,11 +11340,6 @@ extension Underline: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut public func title(_ value: String) -> Underline { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Underline { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Underline { return mutate(translate: value.rawValue) @@ -13157,22 +11449,11 @@ extension Underline: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut extension Underline: Localizable { public init(_ localizedKey: String) { - self.content = [Localized(key: localizedKey)] - } - - public init(_ localizedKey: String, with context: TemplateValue) where B : Encodable { - self.content = [Localized(key: localizedKey, context: context)] + self.content = [LocalizedStringKey(key: localizedKey)] } -} -extension Underline: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) + public init(_ localizedKey: String, with context: some Encodable) { + self.content = [LocalizedStringKey(key: localizedKey, context: context)] } } @@ -13187,13 +11468,13 @@ public struct Mark: ContentNode, HtmlElement, BodyElement, FormElement, FigureEl internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -13207,26 +11488,13 @@ public struct Mark: ContentNode, HtmlElement, BodyElement, FormElement, FigureEl return self } - public func modify(unwrap value: TemplateValue, element: (Mark, TemplateValue) -> Mark) -> Mark { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Mark, T) -> Mark) -> Mark { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -13299,10 +11567,6 @@ extension Mark: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { public func id(_ value: String) -> Mark { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Mark { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Mark { return mutate(lang: value.rawValue) @@ -13311,11 +11575,6 @@ extension Mark: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { public func nonce(_ value: String) -> Mark { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Mark { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Mark { return mutate(role: value.rawValue) @@ -13336,11 +11595,6 @@ extension Mark: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { public func title(_ value: String) -> Mark { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Mark { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Mark { return mutate(translate: value.rawValue) @@ -13447,17 +11701,6 @@ extension Mark: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { } } -extension Mark: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a span of text that is to be isolated from its surroundings for the purposes of bidirectional text formatting. /// /// ```html @@ -13469,13 +11712,13 @@ public struct Bdi: ContentNode, HtmlElement, BodyElement, FormElement, FigureEle internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -13489,26 +11732,13 @@ public struct Bdi: ContentNode, HtmlElement, BodyElement, FormElement, FigureEle return self } - public func modify(unwrap value: TemplateValue, element: (Bdi, TemplateValue) -> Bdi) -> Bdi { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Bdi, T) -> Bdi) -> Bdi { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -13581,10 +11811,6 @@ extension Bdi: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { public func id(_ value: String) -> Bdi { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Bdi { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Bdi { return mutate(lang: value.rawValue) @@ -13593,11 +11819,6 @@ extension Bdi: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { public func nonce(_ value: String) -> Bdi { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Bdi { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Bdi { return mutate(role: value.rawValue) @@ -13618,11 +11839,6 @@ extension Bdi: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { public func title(_ value: String) -> Bdi { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Bdi { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Bdi { return mutate(translate: value.rawValue) @@ -13729,17 +11945,6 @@ extension Bdi: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { } } -extension Bdi: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents explicit text directionality formatting control. /// /// ```html @@ -13766,26 +11971,13 @@ public struct Bdo: EmptyNode, HtmlElement, BodyElement, FormElement, FigureEleme return self } - public func modify(unwrap value: TemplateValue, element: (Bdo, TemplateValue) -> Bdo) -> Bdo { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Bdo, T) -> Bdo) -> Bdo { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -13858,10 +12050,6 @@ extension Bdo: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { public func id(_ value: String) -> Bdo { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Bdo { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Bdo { return mutate(lang: value.rawValue) @@ -13871,11 +12059,6 @@ extension Bdo: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Bdo { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Bdo { return mutate(role: value.rawValue) } @@ -13895,11 +12078,6 @@ extension Bdo: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { public func title(_ value: String) -> Bdo { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Bdo { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Bdo { return mutate(translate: value.rawValue) @@ -14006,17 +12184,6 @@ extension Bdo: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { } } -extension Bdo: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element doesn't mean anything on its own. /// /// ```html @@ -14028,13 +12195,13 @@ public struct Span: ContentNode, HtmlElement, BodyElement, FormElement, FigureEl internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -14048,26 +12215,13 @@ public struct Span: ContentNode, HtmlElement, BodyElement, FormElement, FigureEl return self } - public func modify(unwrap value: TemplateValue, element: (Span, TemplateValue) -> Span) -> Span { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Span, T) -> Span) -> Span { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -14140,10 +12294,6 @@ extension Span: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { public func id(_ value: String) -> Span { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Span { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Span { return mutate(lang: value.rawValue) @@ -14152,11 +12302,6 @@ extension Span: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { public func nonce(_ value: String) -> Span { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Span { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Span { return mutate(role: value.rawValue) @@ -14177,11 +12322,6 @@ extension Span: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { public func title(_ value: String) -> Span { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Span { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Span { return mutate(translate: value.rawValue) @@ -14288,17 +12428,6 @@ extension Span: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes { } } -extension Span: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a line break. /// /// ```html @@ -14325,26 +12454,13 @@ public struct LineBreak: EmptyNode, HtmlElement, BodyElement, FormElement, Figur return self } - public func modify(unwrap value: TemplateValue, element: (LineBreak, TemplateValue) -> LineBreak) -> LineBreak { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (LineBreak, T) -> LineBreak) -> LineBreak { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -14417,10 +12533,6 @@ extension LineBreak: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut public func id(_ value: String) -> LineBreak { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> LineBreak { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> LineBreak { return mutate(lang: value.rawValue) @@ -14430,11 +12542,6 @@ extension LineBreak: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> LineBreak { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> LineBreak { return mutate(role: value.rawValue) } @@ -14454,11 +12561,6 @@ extension LineBreak: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut public func title(_ value: String) -> LineBreak { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> LineBreak { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> LineBreak { return mutate(translate: value.rawValue) @@ -14565,17 +12667,6 @@ extension LineBreak: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut } } -extension LineBreak: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a line break opportunity. /// /// ```html @@ -14602,26 +12693,13 @@ public struct WordBreak: EmptyNode, HtmlElement, BodyElement, FormElement, Figur return self } - public func modify(unwrap value: TemplateValue, element: (WordBreak, TemplateValue) -> WordBreak) -> WordBreak { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (WordBreak, T) -> WordBreak) -> WordBreak { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -14694,10 +12772,6 @@ extension WordBreak: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut public func id(_ value: String) -> WordBreak { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> WordBreak { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> WordBreak { return mutate(lang: value.rawValue) @@ -14706,11 +12780,6 @@ extension WordBreak: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut public func nonce(_ value: String) -> WordBreak { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> WordBreak { - return mutate(role: value) - } public func role(_ value: Values.Role) -> WordBreak { return mutate(role: value.rawValue) @@ -14731,11 +12800,6 @@ extension WordBreak: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut public func title(_ value: String) -> WordBreak { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> WordBreak { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> WordBreak { return mutate(translate: value.rawValue) @@ -14842,17 +12906,6 @@ extension WordBreak: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut } } -extension WordBreak: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents an addition to the document. /// /// ```html @@ -14864,13 +12917,13 @@ public struct InsertedText: ContentNode, HtmlElement, BodyElement, FormElement, internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -14884,26 +12937,13 @@ public struct InsertedText: ContentNode, HtmlElement, BodyElement, FormElement, return self } - public func modify(unwrap value: TemplateValue, element: (InsertedText, TemplateValue) -> InsertedText) -> InsertedText { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (InsertedText, T) -> InsertedText) -> InsertedText { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -14976,10 +13016,6 @@ extension InsertedText: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttri public func id(_ value: String) -> InsertedText { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> InsertedText { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> InsertedText { return mutate(lang: value.rawValue) @@ -14988,11 +13024,6 @@ extension InsertedText: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttri public func nonce(_ value: String) -> InsertedText { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> InsertedText { - return mutate(role: value) - } public func role(_ value: Values.Role) -> InsertedText { return mutate(role: value.rawValue) @@ -15013,11 +13044,6 @@ extension InsertedText: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttri public func title(_ value: String) -> InsertedText { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> InsertedText { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> InsertedText { return mutate(translate: value.rawValue) @@ -15132,17 +13158,6 @@ extension InsertedText: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttri } } -extension InsertedText: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a removal from the document. /// /// ```html @@ -15154,13 +13169,13 @@ public struct DeletedText: ContentNode, HtmlElement, BodyElement, FormElement, F internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -15174,26 +13189,13 @@ public struct DeletedText: ContentNode, HtmlElement, BodyElement, FormElement, F return self } - public func modify(unwrap value: TemplateValue, element: (DeletedText, TemplateValue) -> DeletedText) -> DeletedText { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (DeletedText, T) -> DeletedText) -> DeletedText { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -15266,10 +13268,6 @@ extension DeletedText: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttrib public func id(_ value: String) -> DeletedText { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> DeletedText { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> DeletedText { return mutate(lang: value.rawValue) @@ -15278,11 +13276,6 @@ extension DeletedText: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttrib public func nonce(_ value: String) -> DeletedText { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> DeletedText { - return mutate(role: value) - } public func role(_ value: Values.Role) -> DeletedText { return mutate(role: value.rawValue) @@ -15303,11 +13296,6 @@ extension DeletedText: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttrib public func title(_ value: String) -> DeletedText { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> DeletedText { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> DeletedText { return mutate(translate: value.rawValue) @@ -15422,17 +13410,6 @@ extension DeletedText: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttrib } } -extension DeletedText: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element is a container which provides multiple sources to its contained image element. /// /// ```html @@ -15444,13 +13421,13 @@ public struct Picture: ContentNode, HtmlElement, BodyElement, FormElement, Figur internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -15464,26 +13441,13 @@ public struct Picture: ContentNode, HtmlElement, BodyElement, FormElement, Figur return self } - public func modify(unwrap value: TemplateValue, element: (Picture, TemplateValue) -> Picture) -> Picture { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Picture, T) -> Picture) -> Picture { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -15556,10 +13520,6 @@ extension Picture: GlobalAttributes, GlobalEventAttributes { public func id(_ value: String) -> Picture { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Picture { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Picture { return mutate(lang: value.rawValue) @@ -15569,11 +13529,6 @@ extension Picture: GlobalAttributes, GlobalEventAttributes { return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Picture { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Picture { return mutate(role: value.rawValue) } @@ -15593,11 +13548,6 @@ extension Picture: GlobalAttributes, GlobalEventAttributes { public func title(_ value: String) -> Picture { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Picture { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Picture { return mutate(translate: value.rawValue) @@ -15628,17 +13578,6 @@ extension Picture: GlobalAttributes, GlobalEventAttributes { } } -extension Picture: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents an image. /// /// ```html @@ -15665,26 +13604,13 @@ public struct Image: EmptyNode, HtmlElement, BodyElement, FormElement, FigureEle return self } - public func modify(unwrap value: TemplateValue, element: (Image, TemplateValue) -> Image) -> Image { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Image, T) -> Image) -> Image { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -15757,10 +13683,6 @@ extension Image: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func id(_ value: String) -> Image { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Image { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Image { return mutate(lang: value.rawValue) @@ -15770,11 +13692,6 @@ extension Image: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Image { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Image { return mutate(role: value.rawValue) } @@ -15794,11 +13711,6 @@ extension Image: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func title(_ value: String) -> Image { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Image { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Image { return mutate(translate: value.rawValue) @@ -15929,17 +13841,6 @@ extension Image: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, } } -extension Image: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents its nested browsing context. /// /// ```html @@ -15951,13 +13852,13 @@ public struct InlineFrame: ContentNode, HtmlElement, BodyElement, FormElement, F internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -15971,26 +13872,13 @@ public struct InlineFrame: ContentNode, HtmlElement, BodyElement, FormElement, F return self } - public func modify(unwrap value: TemplateValue, element: (InlineFrame, TemplateValue) -> InlineFrame) -> InlineFrame { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (InlineFrame, T) -> InlineFrame) -> InlineFrame { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -16063,10 +13951,6 @@ extension InlineFrame: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttrib public func id(_ value: String) -> InlineFrame { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> InlineFrame { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> InlineFrame { return mutate(lang: value.rawValue) @@ -16075,11 +13959,6 @@ extension InlineFrame: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttrib public func nonce(_ value: String) -> InlineFrame { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> InlineFrame { - return mutate(role: value) - } public func role(_ value: Values.Role) -> InlineFrame { return mutate(role: value.rawValue) @@ -16100,11 +13979,6 @@ extension InlineFrame: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttrib public func title(_ value: String) -> InlineFrame { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> InlineFrame { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> InlineFrame { return mutate(translate: value.rawValue) @@ -16118,10 +13992,6 @@ extension InlineFrame: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttrib return mutate(name: value) } - public func name(_ value: TemplateValue) -> InlineFrame { - return mutate(name: value.rawValue) - } - public func width(_ size: Int) -> InlineFrame { return mutate(width: size) } @@ -16235,17 +14105,6 @@ extension InlineFrame: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttrib } } -extension InlineFrame: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element provides an integration point for an external application or interactive content. /// /// ```html @@ -16272,26 +14131,13 @@ public struct Embed: EmptyNode, HtmlElement, BodyElement, FormElement, FigureEle return self } - public func modify(unwrap value: TemplateValue, element: (Embed, TemplateValue) -> Embed) -> Embed { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Embed, T) -> Embed) -> Embed { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -16364,10 +14210,6 @@ extension Embed: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func id(_ value: String) -> Embed { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Embed { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Embed { return mutate(lang: value.rawValue) @@ -16376,11 +14218,6 @@ extension Embed: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func nonce(_ value: String) -> Embed { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Embed { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Embed { return mutate(role: value.rawValue) @@ -16401,11 +14238,6 @@ extension Embed: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func title(_ value: String) -> Embed { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Embed { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Embed { return mutate(translate: value.rawValue) @@ -16528,17 +14360,6 @@ extension Embed: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, } } -extension Embed: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents an external resource. /// /// ```html @@ -16570,26 +14391,13 @@ public struct Object: ContentNode, HtmlElement, BodyElement, FormElement, Figure return self } - public func modify(unwrap value: TemplateValue, element: (Object, TemplateValue) -> Object) -> Object { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Object, T) -> Object) -> Object { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -16662,10 +14470,6 @@ extension Object: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func id(_ value: String) -> Object { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Object { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Object { return mutate(lang: value.rawValue) @@ -16674,11 +14478,6 @@ extension Object: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func nonce(_ value: String) -> Object { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Object { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Object { return mutate(role: value.rawValue) @@ -16699,11 +14498,6 @@ extension Object: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func title(_ value: String) -> Object { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Object { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Object { return mutate(translate: value.rawValue) @@ -16721,10 +14515,6 @@ extension Object: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, return mutate(name: value) } - public func name(_ value: TemplateValue) -> Object { - return mutate(name: value.rawValue) - } - public func form(_ value: String) -> Object { return mutate(form: value) } @@ -16838,17 +14628,6 @@ extension Object: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, } } -extension Object: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element is used to embed video content in a document. /// /// ```html @@ -16880,26 +14659,13 @@ public struct Video: ContentNode, HtmlElement, BodyElement, FormElement, FigureE return self } - public func modify(unwrap value: TemplateValue, element: (Video, TemplateValue) -> Video) -> Video { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Video, T) -> Video) -> Video { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -16972,10 +14738,6 @@ extension Video: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func id(_ value: String) -> Video { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Video { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Video { return mutate(lang: value.rawValue) @@ -16985,11 +14747,6 @@ extension Video: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Video { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Video { return mutate(role: value.rawValue) } @@ -17009,11 +14766,6 @@ extension Video: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func title(_ value: String) -> Video { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Video { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Video { return mutate(translate: value.rawValue) @@ -17152,17 +14904,6 @@ extension Video: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, } } -extension Video: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element is used to embed audio content in a document. /// /// ```html @@ -17194,26 +14935,13 @@ public struct Audio: ContentNode, HtmlElement, BodyElement, FormElement, FigureE return self } - public func modify(unwrap value: TemplateValue, element: (Audio, TemplateValue) -> Audio) -> Audio { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Audio, T) -> Audio) -> Audio { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -17286,10 +15014,6 @@ extension Audio: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func id(_ value: String) -> Audio { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Audio { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Audio { return mutate(lang: value.rawValue) @@ -17298,11 +15022,6 @@ extension Audio: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func nonce(_ value: String) -> Audio { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Audio { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Audio { return mutate(role: value.rawValue) @@ -17323,11 +15042,6 @@ extension Audio: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func title(_ value: String) -> Audio { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Audio { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Audio { return mutate(translate: value.rawValue) @@ -17458,17 +15172,6 @@ extension Audio: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, } } -extension Audio: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element is used to define a image map. /// /// ```html @@ -17500,26 +15203,13 @@ public struct Map: ContentNode, HtmlElement, BodyElement, FormElement, FigureEle return self } - public func modify(unwrap value: TemplateValue, element: (Map, TemplateValue) -> Map) -> Map { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Map, T) -> Map) -> Map { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -17592,10 +15282,6 @@ extension Map: GlobalAttributes, GlobalEventAttributes, NameAttribute { public func id(_ value: String) -> Map { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Map { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Map { return mutate(lang: value.rawValue) @@ -17604,11 +15290,6 @@ extension Map: GlobalAttributes, GlobalEventAttributes, NameAttribute { public func nonce(_ value: String) -> Map { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Map { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Map { return mutate(role: value.rawValue) @@ -17629,11 +15310,6 @@ extension Map: GlobalAttributes, GlobalEventAttributes, NameAttribute { public func title(_ value: String) -> Map { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Map { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Map { return mutate(translate: value.rawValue) @@ -17643,10 +15319,6 @@ extension Map: GlobalAttributes, GlobalEventAttributes, NameAttribute { return mutate(name: value) } - public func name(_ value: TemplateValue) -> Map { - return mutate(name: value.rawValue) - } - public func custom(key: String, value: Any) -> Map { return mutate(key: key, value: value) } @@ -17672,17 +15344,6 @@ extension Map: GlobalAttributes, GlobalEventAttributes, NameAttribute { } } -extension Map: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element is used as a container for all the form elements. /// /// ```html @@ -17714,26 +15375,13 @@ public struct Form: ContentNode, HtmlElement, BodyElement, FigureElement, Object return self } - public func modify(unwrap value: TemplateValue, element: (Form, TemplateValue) -> Form) -> Form { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Form, T) -> Form) -> Form { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -17806,10 +15454,6 @@ extension Form: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, A public func id(_ value: String) -> Form { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Form { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Form { return mutate(lang: value.rawValue) @@ -17818,11 +15462,6 @@ extension Form: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, A public func nonce(_ value: String) -> Form { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Form { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Form { return mutate(role: value.rawValue) @@ -17843,11 +15482,6 @@ extension Form: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, A public func title(_ value: String) -> Form { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Form { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Form { return mutate(translate: value.rawValue) @@ -17873,10 +15507,6 @@ extension Form: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, A return mutate(name: value) } - public func name(_ value: TemplateValue) -> Form { - return mutate(name: value.rawValue) - } - public func target(_ value: Values.Target) -> Form { return mutate(target: value.rawValue) } @@ -17986,17 +15616,6 @@ extension Form: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, A } } -extension Form: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a set of options. /// /// ```html @@ -18008,13 +15627,13 @@ public struct DataList: ContentNode, HtmlElement, BodyElement, FormElement, Figu internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -18028,26 +15647,13 @@ public struct DataList: ContentNode, HtmlElement, BodyElement, FormElement, Figu return self } - public func modify(unwrap value: TemplateValue, element: (DataList, TemplateValue) -> DataList) -> DataList { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (DataList, T) -> DataList) -> DataList { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -18120,10 +15726,6 @@ extension DataList: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func id(_ value: String) -> DataList { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> DataList { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> DataList { return mutate(lang: value.rawValue) @@ -18132,11 +15734,6 @@ extension DataList: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func nonce(_ value: String) -> DataList { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> DataList { - return mutate(role: value) - } public func role(_ value: Values.Role) -> DataList { return mutate(role: value.rawValue) @@ -18157,11 +15754,6 @@ extension DataList: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func title(_ value: String) -> DataList { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> DataList { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> DataList { return mutate(translate: value.rawValue) @@ -18268,17 +15860,6 @@ extension DataList: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute } } -extension DataList: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents the result of a calculation. /// /// ```html @@ -18290,13 +15871,13 @@ public struct Output: ContentNode, HtmlElement, BodyElement, FormElement, Figure internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -18310,26 +15891,13 @@ public struct Output: ContentNode, HtmlElement, BodyElement, FormElement, Figure return self } - public func modify(unwrap value: TemplateValue, element: (Output, TemplateValue) -> Output) -> Output { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Output, T) -> Output) -> Output { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -18402,10 +15970,6 @@ extension Output: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func id(_ value: String) -> Output { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Output { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Output { return mutate(lang: value.rawValue) @@ -18414,11 +15978,6 @@ extension Output: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func nonce(_ value: String) -> Output { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Output { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Output { return mutate(role: value.rawValue) @@ -18439,11 +15998,6 @@ extension Output: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func title(_ value: String) -> Output { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Output { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Output { return mutate(translate: value.rawValue) @@ -18461,10 +16015,6 @@ extension Output: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, return mutate(name: value) } - public func name(_ value: TemplateValue) -> Output { - return mutate(name: value.rawValue) - } - public func custom(key: String, value: Any) -> Output { return mutate(key: key, value: value) } @@ -18566,17 +16116,6 @@ extension Output: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, } } -extension Output: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents the completion progress of a task. /// /// ```html @@ -18588,13 +16127,13 @@ public struct Progress: ContentNode, HtmlElement, BodyElement, FormElement, Figu internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -18608,26 +16147,13 @@ public struct Progress: ContentNode, HtmlElement, BodyElement, FormElement, Figu return self } - public func modify(unwrap value: TemplateValue, element: (Progress, TemplateValue) -> Progress) -> Progress { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Progress, T) -> Progress) -> Progress { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -18700,10 +16226,6 @@ extension Progress: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func id(_ value: String) -> Progress { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Progress { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Progress { return mutate(lang: value.rawValue) @@ -18713,11 +16235,6 @@ extension Progress: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Progress { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Progress { return mutate(role: value.rawValue) } @@ -18737,11 +16254,6 @@ extension Progress: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func title(_ value: String) -> Progress { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Progress { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Progress { return mutate(translate: value.rawValue) @@ -18755,10 +16267,6 @@ extension Progress: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute return mutate(value: value) } - public func value(_ value: TemplateValue) -> Progress { - return mutate(value: value.rawValue) - } - public func custom(key: String, value: Any) -> Progress { return mutate(key: key, value: value) } @@ -18860,17 +16368,6 @@ extension Progress: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute } } -extension Progress: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a scalar measurement within a known range, or a fractional value. /// /// ```html @@ -18882,13 +16379,13 @@ public struct Meter: ContentNode, HtmlElement, BodyElement, FormElement, FigureE internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -18902,26 +16399,13 @@ public struct Meter: ContentNode, HtmlElement, BodyElement, FormElement, FigureE return self } - public func modify(unwrap value: TemplateValue, element: (Meter, TemplateValue) -> Meter) -> Meter { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Meter, T) -> Meter) -> Meter { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -18994,10 +16478,6 @@ extension Meter: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func id(_ value: String) -> Meter { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Meter { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Meter { return mutate(lang: value.rawValue) @@ -19006,11 +16486,6 @@ extension Meter: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func nonce(_ value: String) -> Meter { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Meter { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Meter { return mutate(role: value.rawValue) @@ -19031,11 +16506,6 @@ extension Meter: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func title(_ value: String) -> Meter { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Meter { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Meter { return mutate(translate: value.rawValue) @@ -19065,10 +16535,6 @@ extension Meter: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, return mutate(value: value) } - public func value(_ value: TemplateValue) -> Meter { - return mutate(value: value.rawValue) - } - public func custom(key: String, value: Any) -> Meter { return mutate(key: key, value: value) } @@ -19170,17 +16636,6 @@ extension Meter: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, } } -extension Meter: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a disclosure widget from which the user can obtain additional information or controls. /// /// ```html @@ -19192,13 +16647,13 @@ public struct Details: ContentNode, HtmlElement, BodyElement, FormElement, Figur internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -19212,26 +16667,13 @@ public struct Details: ContentNode, HtmlElement, BodyElement, FormElement, Figur return self } - public func modify(unwrap value: TemplateValue, element: (Details, TemplateValue) -> Details) -> Details { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Details, T) -> Details) -> Details { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -19304,10 +16746,6 @@ extension Details: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes public func id(_ value: String) -> Details { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Details { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Details { return mutate(lang: value.rawValue) @@ -19317,11 +16755,6 @@ extension Details: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Details { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Details { return mutate(role: value.rawValue) } @@ -19341,11 +16774,6 @@ extension Details: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes public func title(_ value: String) -> Details { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Details { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Details { return mutate(translate: value.rawValue) @@ -19460,17 +16888,6 @@ extension Details: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes } } -extension Details: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element defines a dialog box or window. public struct Dialog: ContentNode, BodyElement { @@ -19478,13 +16895,13 @@ public struct Dialog: ContentNode, BodyElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -19498,26 +16915,13 @@ public struct Dialog: ContentNode, BodyElement { return self } - public func modify(unwrap value: TemplateValue, element: (Dialog, TemplateValue) -> Dialog) -> Dialog { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Dialog, T) -> Dialog) -> Dialog { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -19590,10 +16994,6 @@ extension Dialog: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func id(_ value: String) -> Dialog { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Dialog { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Dialog { return mutate(lang: value.rawValue) @@ -19603,11 +17003,6 @@ extension Dialog: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Dialog { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Dialog { return mutate(role: value.rawValue) } @@ -19627,11 +17022,6 @@ extension Dialog: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func title(_ value: String) -> Dialog { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Dialog { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Dialog { return mutate(translate: value.rawValue) @@ -19742,17 +17132,6 @@ extension Dialog: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, } } -extension Dialog: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element allows to include dynamic script and data blocks in a document. /// /// ```html @@ -19784,26 +17163,13 @@ public struct Script: ContentNode, HeadElement, BodyElement, FormElement, Figure return self } - public func modify(unwrap value: TemplateValue, element: (Script, TemplateValue) -> Script) -> Script { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Script, T) -> Script) -> Script { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -19876,10 +17242,6 @@ extension Script: GlobalAttributes, GlobalEventAttributes, AsynchronouslyAttribu public func id(_ value: String) -> Script { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Script { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Script { return mutate(lang: value.rawValue) @@ -19889,11 +17251,6 @@ extension Script: GlobalAttributes, GlobalEventAttributes, AsynchronouslyAttribu return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Script { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Script { return mutate(role: value.rawValue) } @@ -19913,11 +17270,6 @@ extension Script: GlobalAttributes, GlobalEventAttributes, AsynchronouslyAttribu public func title(_ value: String) -> Script { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Script { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Script { return mutate(translate: value.rawValue) @@ -19964,17 +17316,6 @@ extension Script: GlobalAttributes, GlobalEventAttributes, AsynchronouslyAttribu } } -extension Script: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a caption for the rest of the contents of a fieldset. /// /// ```html @@ -19986,13 +17327,13 @@ public struct NoScript: ContentNode, HtmlElement, HeadElement, BodyElement, Form internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -20006,26 +17347,13 @@ public struct NoScript: ContentNode, HtmlElement, HeadElement, BodyElement, Form return self } - public func modify(unwrap value: TemplateValue, element: (NoScript, TemplateValue) -> NoScript) -> NoScript { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (NoScript, T) -> NoScript) -> NoScript { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -20098,10 +17426,6 @@ extension NoScript: GlobalAttributes, GlobalEventAttributes { public func id(_ value: String) -> NoScript { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> NoScript { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> NoScript { return mutate(lang: value.rawValue) @@ -20111,11 +17435,6 @@ extension NoScript: GlobalAttributes, GlobalEventAttributes { return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> NoScript { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> NoScript { return mutate(role: value.rawValue) } @@ -20135,11 +17454,6 @@ extension NoScript: GlobalAttributes, GlobalEventAttributes { public func title(_ value: String) -> NoScript { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> NoScript { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> NoScript { return mutate(translate: value.rawValue) @@ -20170,17 +17484,6 @@ extension NoScript: GlobalAttributes, GlobalEventAttributes { } } -extension NoScript: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element is used to declare fragments of HTML that can be cloned and inserted in the document by script. /// /// ```html @@ -20192,13 +17495,13 @@ public struct Template: ContentNode, BodyElement, FormElement, FigureElement, Ob internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -20212,26 +17515,13 @@ public struct Template: ContentNode, BodyElement, FormElement, FigureElement, Ob return self } - public func modify(unwrap value: TemplateValue, element: (Template, TemplateValue) -> Template) -> Template { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Template, T) -> Template) -> Template { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -20304,10 +17594,6 @@ extension Template: GlobalAttributes, GlobalEventAttributes { public func id(_ value: String) -> Template { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Template { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Template { return mutate(lang: value.rawValue) @@ -20316,11 +17602,6 @@ extension Template: GlobalAttributes, GlobalEventAttributes { public func nonce(_ value: String) -> Template { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Template { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Template { return mutate(role: value.rawValue) @@ -20341,11 +17622,6 @@ extension Template: GlobalAttributes, GlobalEventAttributes { public func title(_ value: String) -> Template { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Template { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Template { return mutate(translate: value.rawValue) @@ -20376,17 +17652,6 @@ extension Template: GlobalAttributes, GlobalEventAttributes { } } -extension Template: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a comment output. /// /// ```html @@ -20398,13 +17663,13 @@ public struct Canvas: ContentNode, HtmlElement, BodyElement, FormElement, Figure internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -20418,26 +17683,13 @@ public struct Canvas: ContentNode, HtmlElement, BodyElement, FormElement, Figure return self } - public func modify(unwrap value: TemplateValue, element: (Canvas, TemplateValue) -> Canvas) -> Canvas { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Canvas, T) -> Canvas) -> Canvas { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -20510,10 +17762,6 @@ extension Canvas: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func id(_ value: String) -> Canvas { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Canvas { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Canvas { return mutate(lang: value.rawValue) @@ -20522,11 +17770,6 @@ extension Canvas: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func nonce(_ value: String) -> Canvas { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Canvas { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Canvas { return mutate(role: value.rawValue) @@ -20547,11 +17790,6 @@ extension Canvas: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func title(_ value: String) -> Canvas { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Canvas { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Canvas { return mutate(translate: value.rawValue) @@ -20666,17 +17904,6 @@ extension Canvas: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, } } -extension Canvas: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a comment output. /// /// ```html @@ -20708,26 +17935,13 @@ public struct Table: ContentNode, HtmlElement, BodyElement, FormElement, FigureE return self } - public func modify(unwrap value: TemplateValue, element: (Table, TemplateValue) -> Table) -> Table { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Table, T) -> Table) -> Table { + + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -20800,10 +18014,6 @@ extension Table: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func id(_ value: String) -> Table { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Table { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Table { return mutate(lang: value.rawValue) @@ -20812,11 +18022,6 @@ extension Table: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func nonce(_ value: String) -> Table { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Table { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Table { return mutate(role: value.rawValue) @@ -20837,11 +18042,6 @@ extension Table: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func title(_ value: String) -> Table { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Table { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Table { return mutate(translate: value.rawValue) @@ -20956,17 +18156,6 @@ extension Table: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, } } -extension Table: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a vector. /// /// ```html @@ -20998,37 +18187,13 @@ public struct Vector: ContentNode, HtmlElement, BodyElement, FormElement, Figure return self } - public func modify(unwrap value: TemplateValue, element: (Vector, TemplateValue) -> Vector) -> Vector { - - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + public func modify(unwrap value: T?, element: (Vector, T) -> Vector) -> Vector { + + guard let value = value else { + return self } - } -} - -extension Vector: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - return try self.build(with: manager) + + return self.modify(element(self, value as T)) } } @@ -21038,10 +18203,6 @@ extension Vector: GlobalVectorAttributes, WidthAttribute, HeightAttribute, ViewB return self.mutate(id: value) } - public func id(_ value: TemplateValue) -> Vector { - return self.mutate(id: value.rawValue) - } - public func tabIndex(_ value: Int) -> Vector { return self.mutate(tabindex: value) } diff --git a/Sources/HTMLKit/Abstraction/Elements/DefinitionElements.swift b/Sources/HTMLKit/Abstraction/Elements/DefinitionElements.swift index faedcba3..257b44ae 100644 --- a/Sources/HTMLKit/Abstraction/Elements/DefinitionElements.swift +++ b/Sources/HTMLKit/Abstraction/Elements/DefinitionElements.swift @@ -37,13 +37,13 @@ public struct TermName: ContentNode, DescriptionElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -57,26 +57,13 @@ public struct TermName: ContentNode, DescriptionElement { return self } - public func modify(unwrap value: TemplateValue, element: (TermName, TemplateValue) -> TermName) -> TermName { + public func modify(unwrap value: T?, element: (TermName, T) -> TermName) -> TermName { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -149,10 +136,6 @@ extension TermName: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func id(_ value: String) -> TermName { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> TermName { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> TermName { return mutate(lang: value.rawValue) @@ -162,11 +145,6 @@ extension TermName: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> TermName { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> TermName { return mutate(role: value.rawValue) } @@ -186,11 +164,6 @@ extension TermName: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func title(_ value: String) -> TermName { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> TermName { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> TermName { return mutate(translate: value.rawValue) @@ -297,17 +270,6 @@ extension TermName: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute } } -extension TermName: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element specifies a term definition. /// /// ```html @@ -319,13 +281,13 @@ public struct TermDefinition: ContentNode, DescriptionElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -339,26 +301,13 @@ public struct TermDefinition: ContentNode, DescriptionElement { return self } - public func modify(unwrap value: TemplateValue, element: (TermDefinition, TemplateValue) -> TermDefinition) -> TermDefinition { + public func modify(unwrap value: T?, element: (TermDefinition, T) -> TermDefinition) -> TermDefinition { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -431,10 +380,6 @@ extension TermDefinition: GlobalAttributes, GlobalEventAttributes, GlobalAriaAtt public func id(_ value: String) -> TermDefinition { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> TermDefinition { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> TermDefinition { return mutate(lang: value.rawValue) @@ -443,11 +388,6 @@ extension TermDefinition: GlobalAttributes, GlobalEventAttributes, GlobalAriaAtt public func nonce(_ value: String) -> TermDefinition { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> TermDefinition { - return mutate(role: value) - } public func role(_ value: Values.Role) -> TermDefinition { return mutate(role: value.rawValue) @@ -468,11 +408,6 @@ extension TermDefinition: GlobalAttributes, GlobalEventAttributes, GlobalAriaAtt public func title(_ value: String) -> TermDefinition { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> TermDefinition { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> TermDefinition { return mutate(translate: value.rawValue) @@ -578,14 +513,3 @@ extension TermDefinition: GlobalAttributes, GlobalEventAttributes, GlobalAriaAtt return mutate(ariaroledescription: value) } } - -extension TermDefinition: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} diff --git a/Sources/HTMLKit/Abstraction/Elements/FigureElements.swift b/Sources/HTMLKit/Abstraction/Elements/FigureElements.swift index 160e00b1..5a40c5a2 100644 --- a/Sources/HTMLKit/Abstraction/Elements/FigureElements.swift +++ b/Sources/HTMLKit/Abstraction/Elements/FigureElements.swift @@ -28,13 +28,13 @@ public struct FigureCaption: ContentNode, FigureElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -48,26 +48,13 @@ public struct FigureCaption: ContentNode, FigureElement { return self } - public func modify(unwrap value: TemplateValue, element: (FigureCaption, TemplateValue) -> FigureCaption) -> FigureCaption { + public func modify(unwrap value: T?, element: (FigureCaption, T) -> FigureCaption) -> FigureCaption { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -140,10 +127,6 @@ extension FigureCaption: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttr public func id(_ value: String) -> FigureCaption { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> FigureCaption { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> FigureCaption { return mutate(lang: value.rawValue) @@ -152,11 +135,6 @@ extension FigureCaption: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttr public func nonce(_ value: String) -> FigureCaption { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> FigureCaption { - return mutate(role: value) - } public func role(_ value: Values.Role) -> FigureCaption { return mutate(role: value.rawValue) @@ -177,11 +155,6 @@ extension FigureCaption: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttr public func title(_ value: String) -> FigureCaption { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> FigureCaption { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> FigureCaption { return mutate(translate: value.rawValue) @@ -287,14 +260,3 @@ extension FigureCaption: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttr return mutate(ariaroledescription: value) } } - -extension FigureCaption: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} diff --git a/Sources/HTMLKit/Abstraction/Elements/FormElements.swift b/Sources/HTMLKit/Abstraction/Elements/FormElements.swift index 5a4b4ec6..6a98307a 100644 --- a/Sources/HTMLKit/Abstraction/Elements/FormElements.swift +++ b/Sources/HTMLKit/Abstraction/Elements/FormElements.swift @@ -34,28 +34,13 @@ public struct Input: EmptyNode, FormElement { return self } - public func modify(unwrap value: TemplateValue, element: (Input, TemplateValue) -> Input) -> Input { + public func modify(unwrap value: T?, element: (Input, T) -> Input) -> Input { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -128,10 +113,6 @@ extension Input: GlobalAttributes, GlobalEventAttributes, AcceptAttribute, Alter public func id(_ value: String) -> Input { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Input { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Input { return mutate(lang: value.rawValue) @@ -141,11 +122,6 @@ extension Input: GlobalAttributes, GlobalEventAttributes, AcceptAttribute, Alter return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Input { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Input { return mutate(role: value.rawValue) } @@ -165,11 +141,6 @@ extension Input: GlobalAttributes, GlobalEventAttributes, AcceptAttribute, Alter public func title(_ value: String) -> Input { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Input { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Input { return mutate(translate: value.rawValue) @@ -235,10 +206,6 @@ extension Input: GlobalAttributes, GlobalEventAttributes, AcceptAttribute, Alter return mutate(name: value) } - public func name(_ value: TemplateValue) -> Input { - return mutate(name: value.rawValue) - } - public func pattern(_ regex: String) -> Input { return mutate(pattern: regex) } @@ -247,10 +214,6 @@ extension Input: GlobalAttributes, GlobalEventAttributes, AcceptAttribute, Alter return mutate(placeholder: value) } - public func placeholder(_ value: TemplateValue) -> Input { - return mutate(placeholder: value.rawValue) - } - public func readonly() -> Input { return mutate(readonly: "readonly") } @@ -279,10 +242,6 @@ extension Input: GlobalAttributes, GlobalEventAttributes, AcceptAttribute, Alter return mutate(value: value) } - public func value(_ value: TemplateValue) -> Input { - return mutate(value: value.rawValue) - } - public func width(_ size: Int) -> Input { return mutate(width: size) } @@ -312,17 +271,6 @@ extension Input: GlobalAttributes, GlobalEventAttributes, AcceptAttribute, Alter } } -extension Input: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a caption for a form control. /// /// ```html @@ -334,13 +282,13 @@ public struct Label: ContentNode, FormElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -354,26 +302,13 @@ public struct Label: ContentNode, FormElement { return self } - public func modify(unwrap value: TemplateValue, element: (Label, TemplateValue) -> Label) -> Label { + public func modify(unwrap value: T?, element: (Label, T) -> Label) -> Label { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -446,10 +381,6 @@ extension Label: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func id(_ value: String) -> Label { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Label { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Label { return mutate(lang: value.rawValue) @@ -458,11 +389,6 @@ extension Label: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func nonce(_ value: String) -> Label { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Label { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Label { return mutate(role: value.rawValue) @@ -483,11 +409,6 @@ extension Label: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func title(_ value: String) -> Label { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Label { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Label { return mutate(translate: value.rawValue) @@ -598,25 +519,14 @@ extension Label: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, } } -extension Label: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - extension Label: Localizable { public init(_ localizedKey: String) { - self.content = [Localized(key: localizedKey)] + self.content = [LocalizedStringKey(key: localizedKey)] } - public init(_ localizedKey: String, with context: TemplateValue) where B : Encodable { - self.content = [Localized(key: localizedKey, context: context)] + public init(_ localizedKey: String, with context: B) where B : Encodable { + self.content = [LocalizedStringKey(key: localizedKey, context: context)] } } @@ -631,13 +541,13 @@ public struct Select: ContentNode, FormElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -651,26 +561,13 @@ public struct Select: ContentNode, FormElement { return self } - public func modify(unwrap value: TemplateValue, element: (Select, TemplateValue) -> Select) -> Select { + public func modify(unwrap value: T?, element: (Select, T) -> Select) -> Select { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -743,10 +640,6 @@ extension Select: GlobalAttributes, GlobalEventAttributes, AutocompleteAttribute public func id(_ value: String) -> Select { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Select { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Select { return mutate(lang: value.rawValue) @@ -755,11 +648,6 @@ extension Select: GlobalAttributes, GlobalEventAttributes, AutocompleteAttribute public func nonce(_ value: String) -> Select { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Select { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Select { return mutate(role: value.rawValue) @@ -780,11 +668,6 @@ extension Select: GlobalAttributes, GlobalEventAttributes, AutocompleteAttribute public func title(_ value: String) -> Select { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Select { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Select { return mutate(translate: value.rawValue) @@ -810,10 +693,6 @@ extension Select: GlobalAttributes, GlobalEventAttributes, AutocompleteAttribute return mutate(name: value) } - public func name(_ value: TemplateValue) -> Select { - return mutate(name: value.rawValue) - } - public func required() -> Select { return mutate(required: "required") } @@ -847,17 +726,6 @@ extension Select: GlobalAttributes, GlobalEventAttributes, AutocompleteAttribute } } -extension Select: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a multiline plain text edit control. /// /// ```html @@ -889,26 +757,13 @@ public struct TextArea: ContentNode, FormElement { return self } - public func modify(unwrap value: TemplateValue, element: (TextArea, TemplateValue) -> TextArea) -> TextArea { + public func modify(unwrap value: T?, element: (TextArea, T) -> TextArea) -> TextArea { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -981,10 +836,6 @@ extension TextArea: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func id(_ value: String) -> TextArea { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> TextArea { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> TextArea { return mutate(lang: value.rawValue) @@ -993,11 +844,6 @@ extension TextArea: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func nonce(_ value: String) -> TextArea { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> TextArea { - return mutate(role: value) - } public func role(_ value: Values.Role) -> TextArea { return mutate(role: value.rawValue) @@ -1018,11 +864,6 @@ extension TextArea: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func title(_ value: String) -> TextArea { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> TextArea { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> TextArea { return mutate(translate: value.rawValue) @@ -1056,18 +897,10 @@ extension TextArea: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute return mutate(name: value) } - public func name(_ value: TemplateValue) -> TextArea { - return mutate(name: value.rawValue) - } - public func placeholder(_ value: String) -> TextArea { return mutate(placeholder: value) } - public func placeholder(_ value: TemplateValue) -> TextArea { - return mutate(placeholder: value.rawValue) - } - public func readonly() -> TextArea { return mutate(readonly: "readonly") } @@ -1185,17 +1018,6 @@ extension TextArea: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute } } -extension TextArea: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a comment output. /// /// ```html @@ -1207,13 +1029,13 @@ public struct Button: ContentNode, FormElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -1227,26 +1049,13 @@ public struct Button: ContentNode, FormElement { return self } - public func modify(unwrap value: TemplateValue, element: (Button, TemplateValue) -> Button) -> Button { + public func modify(unwrap value: T?, element: (Button, T) -> Button) -> Button { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -1319,10 +1128,6 @@ extension Button: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func id(_ value: String) -> Button { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Button { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Button { return mutate(lang: value.rawValue) @@ -1331,11 +1136,6 @@ extension Button: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func nonce(_ value: String) -> Button { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Button { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Button { return mutate(role: value.rawValue) @@ -1356,11 +1156,6 @@ extension Button: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func title(_ value: String) -> Button { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Button { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Button { return mutate(translate: value.rawValue) @@ -1382,10 +1177,6 @@ extension Button: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, return mutate(name: value) } - public func name(_ value: TemplateValue) -> Button { - return mutate(name: value.rawValue) - } - public func type(_ value: Values.Button) -> Button { return mutate(type: value.rawValue) } @@ -1394,10 +1185,6 @@ extension Button: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, return mutate(value: value) } - public func value(_ value: TemplateValue) -> Button { - return mutate(value: value.rawValue) - } - public func custom(key: String, value: Any) -> Button { return mutate(key: key, value: value) } @@ -1499,25 +1286,14 @@ extension Button: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, } } -extension Button: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - extension Button: Localizable { public init(_ localizedKey: String) { - self.content = [Localized(key: localizedKey)] + self.content = [LocalizedStringKey(key: localizedKey)] } - public init(_ localizedKey: String, with context: TemplateValue) where B : Encodable { - self.content = [Localized(key: localizedKey, context: context)] + public init(_ localizedKey: String, with context: some Encodable) { + self.content = [LocalizedStringKey(key: localizedKey, context: context)] } } @@ -1532,13 +1308,13 @@ public struct Fieldset: ContentNode, FormElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -1552,26 +1328,13 @@ public struct Fieldset: ContentNode, FormElement { return self } - public func modify(unwrap value: TemplateValue, element: (Fieldset, TemplateValue) -> Fieldset) -> Fieldset { + public func modify(unwrap value: T?, element: (Fieldset, T) -> Fieldset) -> Fieldset { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -1644,10 +1407,6 @@ extension Fieldset: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func id(_ value: String) -> Fieldset { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Fieldset { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Fieldset { return mutate(lang: value.rawValue) @@ -1656,11 +1415,6 @@ extension Fieldset: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func nonce(_ value: String) -> Fieldset { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Fieldset { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Fieldset { return mutate(role: value.rawValue) @@ -1681,11 +1435,6 @@ extension Fieldset: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func title(_ value: String) -> Fieldset { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Fieldset { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Fieldset { return mutate(translate: value.rawValue) @@ -1703,10 +1452,6 @@ extension Fieldset: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute return mutate(name: value) } - public func name(_ value: TemplateValue) -> Fieldset { - return mutate(name: value.rawValue) - } - public func custom(key: String, value: Any) -> Fieldset { return mutate(key: key, value: value) } @@ -1807,14 +1552,3 @@ extension Fieldset: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute return mutate(ariaroledescription: value) } } - -extension Fieldset: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} diff --git a/Sources/HTMLKit/Abstraction/Elements/HeadElements.swift b/Sources/HTMLKit/Abstraction/Elements/HeadElements.swift index 873a90ef..aa36b751 100644 --- a/Sources/HTMLKit/Abstraction/Elements/HeadElements.swift +++ b/Sources/HTMLKit/Abstraction/Elements/HeadElements.swift @@ -39,26 +39,13 @@ public struct Title: ContentNode, HeadElement { return self } - public func modify(unwrap value: TemplateValue, element: (Title, TemplateValue) -> Title) -> Title { + public func modify(unwrap value: T?, element: (Title, T) -> Title) -> Title { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -132,10 +119,6 @@ extension Title: GlobalAttributes, GlobalEventAttributes { return mutate(id: value) } - public func id(_ value: TemplateValue) -> Title { - return mutate(id: value.rawValue) - } - public func language(_ value: Values.Language) -> Title { return mutate(lang: value.rawValue) } @@ -144,11 +127,6 @@ extension Title: GlobalAttributes, GlobalEventAttributes { return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Title { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Title { return mutate(role: value.rawValue) } @@ -169,11 +147,6 @@ extension Title: GlobalAttributes, GlobalEventAttributes { return mutate(title: value) } - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Title { - return mutate(translate: value) - } - public func translate(_ value: Values.Decision) -> Title { return mutate(translate: value.rawValue) } @@ -203,17 +176,6 @@ extension Title: GlobalAttributes, GlobalEventAttributes { } } -extension Title: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element specifies the document base url.# /// /// ```html @@ -240,26 +202,13 @@ public struct Base: EmptyNode, HeadElement { return self } - public func modify(unwrap value: TemplateValue, element: (Base, TemplateValue) -> Base) -> Base { + public func modify(unwrap value: T?, element: (Base, T) -> Base) -> Base { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -333,10 +282,6 @@ extension Base: GlobalAttributes, GlobalEventAttributes, ReferenceAttribute, Tar return mutate(id: value) } - public func id(_ value: TemplateValue) -> Base { - return mutate(id: value.rawValue) - } - public func language(_ value: Values.Language) -> Base { return mutate(lang: value.rawValue) } @@ -345,11 +290,6 @@ extension Base: GlobalAttributes, GlobalEventAttributes, ReferenceAttribute, Tar return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Base { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Base { return mutate(role: value.rawValue) } @@ -370,11 +310,6 @@ extension Base: GlobalAttributes, GlobalEventAttributes, ReferenceAttribute, Tar return mutate(title: value) } - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Base { - return mutate(translate: value) - } - public func translate(_ value: Values.Decision) -> Base { return mutate(translate: value.rawValue) } @@ -383,10 +318,6 @@ extension Base: GlobalAttributes, GlobalEventAttributes, ReferenceAttribute, Tar return mutate(href: value) } - public func reference(_ value: TemplateValue) -> Base { - return mutate(href: value.rawValue) - } - public func target(_ value: Values.Target) -> Base { return mutate(target: value.rawValue) } @@ -416,17 +347,6 @@ extension Base: GlobalAttributes, GlobalEventAttributes, ReferenceAttribute, Tar } } -extension Base: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element provides meta information about the document. /// /// ```html @@ -453,26 +373,13 @@ public struct Meta: EmptyNode, HeadElement { return self } - public func modify(unwrap value: TemplateValue, element: (Meta, TemplateValue) -> Meta) -> Meta { + public func modify(unwrap value: T?, element: (Meta, T) -> Meta) -> Meta { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -545,10 +452,6 @@ extension Meta: GlobalAttributes, GlobalEventAttributes, ContentAttribute, NameA public func id(_ value: String) -> Meta { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Meta { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Meta { return mutate(lang: value.rawValue) @@ -558,11 +461,6 @@ extension Meta: GlobalAttributes, GlobalEventAttributes, ContentAttribute, NameA return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Meta { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Meta { return mutate(role: value.rawValue) } @@ -582,11 +480,6 @@ extension Meta: GlobalAttributes, GlobalEventAttributes, ContentAttribute, NameA public func title(_ value: String) -> Meta { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Meta { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Meta { return mutate(translate: value.rawValue) @@ -596,18 +489,10 @@ extension Meta: GlobalAttributes, GlobalEventAttributes, ContentAttribute, NameA return mutate(content: value) } - public func content(_ value: TemplateValue) -> Meta { - return mutate(content: value.rawValue) - } - public func name(_ value: Values.Name) -> Meta { return mutate(name: value.rawValue) } - public func name(_ value: TemplateValue) -> Meta { - return mutate(name: value.rawValue) - } - public func property(_ value: Values.Graph) -> Meta { return mutate(property: value.rawValue) } @@ -645,17 +530,6 @@ extension Meta: GlobalAttributes, GlobalEventAttributes, ContentAttribute, NameA } } -extension Meta: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element contains style information for the document. /// /// ```html @@ -667,13 +541,13 @@ public struct Style: ContentNode, HeadElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -687,26 +561,13 @@ public struct Style: ContentNode, HeadElement { return self } - public func modify(unwrap value: TemplateValue, element: (Style, TemplateValue) -> Style) -> Style { + public func modify(unwrap value: T?, element: (Style, T) -> Style) -> Style { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -779,10 +640,6 @@ extension Style: GlobalAttributes, GlobalEventAttributes, TypeAttribute, MediaAt public func id(_ value: String) -> Style { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Style { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Style { return mutate(lang: value.rawValue) @@ -792,11 +649,6 @@ extension Style: GlobalAttributes, GlobalEventAttributes, TypeAttribute, MediaAt return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Style { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Style { return mutate(role: value.rawValue) } @@ -816,11 +668,6 @@ extension Style: GlobalAttributes, GlobalEventAttributes, TypeAttribute, MediaAt public func title(_ value: String) -> Style { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Style { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Style { return mutate(translate: value.rawValue) @@ -859,17 +706,6 @@ extension Style: GlobalAttributes, GlobalEventAttributes, TypeAttribute, MediaAt } } -extension Style: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a comment output. /// /// ```html @@ -896,26 +732,13 @@ public struct Link: EmptyNode, HeadElement { return self } - public func modify(unwrap value: TemplateValue, element: (Link, TemplateValue) -> Link) -> Link { + public func modify(unwrap value: T?, element: (Link, T) -> Link) -> Link { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -988,10 +811,6 @@ extension Link: GlobalAttributes, GlobalEventAttributes, ReferenceAttribute, Ref public func id(_ value: String) -> Link { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Link { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Link { return mutate(lang: value.rawValue) @@ -1001,11 +820,6 @@ extension Link: GlobalAttributes, GlobalEventAttributes, ReferenceAttribute, Ref return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Link { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Link { return mutate(role: value.rawValue) } @@ -1025,11 +839,6 @@ extension Link: GlobalAttributes, GlobalEventAttributes, ReferenceAttribute, Ref public func title(_ value: String) -> Link { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Link { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Link { return mutate(translate: value.rawValue) @@ -1039,10 +848,6 @@ extension Link: GlobalAttributes, GlobalEventAttributes, ReferenceAttribute, Ref return mutate(href: value) } - public func reference(_ value: TemplateValue) -> Link { - return mutate(href: value.rawValue) - } - public func referenceLanguage(_ value: Values.Language) -> Link { return mutate(hreflang: value.rawValue) } @@ -1095,14 +900,3 @@ extension Link: GlobalAttributes, GlobalEventAttributes, ReferenceAttribute, Ref return mutate(key: event.rawValue, value: value) } } - -extension Link: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} diff --git a/Sources/HTMLKit/Abstraction/Elements/HtmlElements.swift b/Sources/HTMLKit/Abstraction/Elements/HtmlElements.swift index fd1c19fe..372839c1 100644 --- a/Sources/HTMLKit/Abstraction/Elements/HtmlElements.swift +++ b/Sources/HTMLKit/Abstraction/Elements/HtmlElements.swift @@ -39,26 +39,13 @@ public struct Head: ContentNode, HtmlElement { return self } - public func modify(unwrap value: TemplateValue, element: (Head, TemplateValue) -> Head) -> Head { + public func modify(unwrap value: T?, element: (Head, T) -> Head) -> Head { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -132,10 +119,6 @@ extension Head: GlobalAttributes, GlobalEventAttributes { return mutate(id: value) } - public func id(_ value: TemplateValue) -> Head { - return mutate(id: value.rawValue) - } - public func language(_ value: Values.Language) -> Head { return mutate(lang: value.rawValue) } @@ -144,11 +127,6 @@ extension Head: GlobalAttributes, GlobalEventAttributes { return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Head { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Head { return mutate(role: value.rawValue) } @@ -169,11 +147,6 @@ extension Head: GlobalAttributes, GlobalEventAttributes { return mutate(title: value) } - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Head { - return mutate(translate: value) - } - public func translate(_ value: Values.Decision) -> Head { return mutate(translate: value.rawValue) } @@ -203,17 +176,6 @@ extension Head: GlobalAttributes, GlobalEventAttributes { } } -extension Head: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element contains the document's content. /// /// ```html @@ -245,26 +207,13 @@ public struct Body: ContentNode, HtmlElement { return self } - public func modify(unwrap value: TemplateValue, element: (Body, TemplateValue) -> Body) -> Body { + public func modify(unwrap value: T?, element: (Body, T) -> Body) -> Body { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -337,10 +286,6 @@ extension Body: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, W public func id(_ value: String) -> Body { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Body { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Body { return mutate(lang: value.rawValue) @@ -350,11 +295,6 @@ extension Body: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, W return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Body { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Body { return mutate(role: value.rawValue) } @@ -374,11 +314,6 @@ extension Body: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, W public func title(_ value: String) -> Body { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Body { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Body { return mutate(translate: value.rawValue) @@ -488,14 +423,3 @@ extension Body: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, W return mutate(ariaroledescription: value) } } - -extension Body: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} diff --git a/Sources/HTMLKit/Abstraction/Elements/InputElements.swift b/Sources/HTMLKit/Abstraction/Elements/InputElements.swift index 5cc60893..02f98d73 100644 --- a/Sources/HTMLKit/Abstraction/Elements/InputElements.swift +++ b/Sources/HTMLKit/Abstraction/Elements/InputElements.swift @@ -28,13 +28,13 @@ public struct OptionGroup: ContentNode, InputElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -48,26 +48,13 @@ public struct OptionGroup: ContentNode, InputElement { return self } - public func modify(unwrap value: TemplateValue, element: (OptionGroup, TemplateValue) -> OptionGroup) -> OptionGroup { + public func modify(unwrap value: T?, element: (OptionGroup, T) -> OptionGroup) -> OptionGroup { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -140,10 +127,6 @@ extension OptionGroup: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttrib public func id(_ value: String) -> OptionGroup { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> OptionGroup { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> OptionGroup { return mutate(lang: value.rawValue) @@ -152,11 +135,6 @@ extension OptionGroup: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttrib public func nonce(_ value: String) -> OptionGroup { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> OptionGroup { - return mutate(role: value) - } public func role(_ value: Values.Role) -> OptionGroup { return mutate(role: value.rawValue) @@ -177,11 +155,6 @@ extension OptionGroup: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttrib public func title(_ value: String) -> OptionGroup { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> OptionGroup { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> OptionGroup { return mutate(translate: value.rawValue) @@ -296,17 +269,6 @@ extension OptionGroup: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttrib } } -extension OptionGroup: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents an option. /// /// ```html @@ -338,26 +300,13 @@ public struct Option: ContentNode, InputElement { return self } - public func modify(unwrap value: TemplateValue, element: (Option, TemplateValue) -> Option) -> Option { + public func modify(unwrap value: T?, element: (Option, T) -> Option) -> Option { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -430,10 +379,6 @@ extension Option: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func id(_ value: String) -> Option { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Option { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Option { return mutate(lang: value.rawValue) @@ -442,11 +387,6 @@ extension Option: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func nonce(_ value: String) -> Option { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Option { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Option { return mutate(role: value.rawValue) @@ -467,11 +407,6 @@ extension Option: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, public func title(_ value: String) -> Option { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Option { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Option { return mutate(translate: value.rawValue) @@ -489,10 +424,6 @@ extension Option: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, return mutate(value: value) } - public func value(_ value: TemplateValue) -> Option { - return mutate(value: value.rawValue) - } - public func selected() -> Option { return mutate(selected: "selected") } @@ -598,17 +529,6 @@ extension Option: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, } } -extension Option: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a caption for the rest of the contents of a fieldset. /// /// ```html @@ -620,14 +540,14 @@ public struct Legend: ContentNode, InputElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content @@ -642,26 +562,13 @@ public struct Legend: ContentNode, InputElement { return self } - public func modify(unwrap value: TemplateValue, element: (Legend, TemplateValue) -> Legend) -> Legend { + public func modify(unwrap value: T?, element: (Legend, T) -> Legend) -> Legend { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -734,10 +641,6 @@ extension Legend: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes public func id(_ value: String) -> Legend { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Legend { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Legend { return mutate(lang: value.rawValue) @@ -747,11 +650,6 @@ extension Legend: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Legend { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Legend { return mutate(role: value.rawValue) } @@ -771,11 +669,6 @@ extension Legend: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes public func title(_ value: String) -> Legend { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Legend { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Legend { return mutate(translate: value.rawValue) @@ -882,17 +775,6 @@ extension Legend: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes } } -extension Legend: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a summary, caption, or legend for the rest of the content. /// /// ```html @@ -904,13 +786,13 @@ public struct Summary: ContentNode, InputElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -924,26 +806,13 @@ public struct Summary: ContentNode, InputElement { return self } - public func modify(unwrap value: TemplateValue, element: (Summary, TemplateValue) -> Summary) -> Summary { + public func modify(unwrap value: T?, element: (Summary, T) -> Summary) -> Summary { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -1016,10 +885,6 @@ extension Summary: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes public func id(_ value: String) -> Summary { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Summary { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Summary { return mutate(lang: value.rawValue) @@ -1028,11 +893,6 @@ extension Summary: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes public func nonce(_ value: String) -> Summary { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Summary { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Summary { return mutate(role: value.rawValue) @@ -1053,11 +913,6 @@ extension Summary: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes public func title(_ value: String) -> Summary { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Summary { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Summary { return mutate(translate: value.rawValue) @@ -1163,14 +1018,3 @@ extension Summary: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes return mutate(ariaroledescription: value) } } - -extension Summary: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} diff --git a/Sources/HTMLKit/Abstraction/Elements/ListElements.swift b/Sources/HTMLKit/Abstraction/Elements/ListElements.swift index b279fc1f..9af694f1 100644 --- a/Sources/HTMLKit/Abstraction/Elements/ListElements.swift +++ b/Sources/HTMLKit/Abstraction/Elements/ListElements.swift @@ -28,13 +28,13 @@ public struct ListItem: ContentNode, ListElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -48,26 +48,13 @@ public struct ListItem: ContentNode, ListElement { return self } - public func modify(unwrap value: TemplateValue, element: (ListItem, TemplateValue) -> ListItem) -> ListItem { + public func modify(unwrap value: T?, element: (ListItem, T) -> ListItem) -> ListItem { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -140,10 +127,6 @@ extension ListItem: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func id(_ value: String) -> ListItem { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> ListItem { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> ListItem { return mutate(lang: value.rawValue) @@ -153,11 +136,6 @@ extension ListItem: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> ListItem { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> ListItem { return mutate(role: value.rawValue) } @@ -177,11 +155,6 @@ extension ListItem: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func title(_ value: String) -> ListItem { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> ListItem { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> ListItem { return mutate(translate: value.rawValue) @@ -191,10 +164,6 @@ extension ListItem: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute return mutate(value: value) } - public func value(_ value: TemplateValue) -> ListItem { - return mutate(value: value.rawValue) - } - public func custom(key: String, value: Any) -> ListItem { return mutate(key: key, value: value) } @@ -295,14 +264,3 @@ extension ListItem: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute return mutate(ariaroledescription: value) } } - -extension ListItem: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} diff --git a/Sources/HTMLKit/Abstraction/Elements/MapElements.swift b/Sources/HTMLKit/Abstraction/Elements/MapElements.swift index fb12910e..64fb9ac3 100644 --- a/Sources/HTMLKit/Abstraction/Elements/MapElements.swift +++ b/Sources/HTMLKit/Abstraction/Elements/MapElements.swift @@ -19,13 +19,13 @@ public struct Area: ContentNode, MapElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -39,26 +39,13 @@ public struct Area: ContentNode, MapElement { return self } - public func modify(unwrap value: TemplateValue, element: (Area, TemplateValue) -> Area) -> Area { + public func modify(unwrap value: T?, element: (Area, T) -> Area) -> Area { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -131,10 +118,6 @@ extension Area: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, A public func id(_ value: String) -> Area { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Area { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Area { return mutate(lang: value.rawValue) @@ -143,11 +126,6 @@ extension Area: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, A public func nonce(_ value: String) -> Area { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Area { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Area { return mutate(role: value.rawValue) @@ -168,11 +146,6 @@ extension Area: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, A public func title(_ value: String) -> Area { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Area { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Area { return mutate(translate: value.rawValue) @@ -194,10 +167,6 @@ extension Area: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, A return mutate(href: value) } - public func reference(_ value: TemplateValue) -> Area { - return mutate(href: value.rawValue) - } - public func target(_ value: Values.Target) -> Area { return mutate(target: value.rawValue) } @@ -318,14 +287,3 @@ extension Area: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes, A return mutate(ariaroledescription: value) } } - -extension Area: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} diff --git a/Sources/HTMLKit/Abstraction/Elements/MediaElements.swift b/Sources/HTMLKit/Abstraction/Elements/MediaElements.swift index 748a52e7..ec23c71d 100644 --- a/Sources/HTMLKit/Abstraction/Elements/MediaElements.swift +++ b/Sources/HTMLKit/Abstraction/Elements/MediaElements.swift @@ -34,26 +34,13 @@ public struct Source: EmptyNode, MediaElement { return self } - public func modify(unwrap value: TemplateValue, element: (Source, TemplateValue) -> Source) -> Source { + public func modify(unwrap value: T?, element: (Source, T) -> Source) -> Source { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -126,10 +113,6 @@ extension Source: GlobalAttributes, GlobalEventAttributes, TypeAttribute, Source public func id(_ value: String) -> Source { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Source { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Source { return mutate(lang: value.rawValue) @@ -139,11 +122,6 @@ extension Source: GlobalAttributes, GlobalEventAttributes, TypeAttribute, Source return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Source { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Source { return mutate(role: value.rawValue) } @@ -163,11 +141,6 @@ extension Source: GlobalAttributes, GlobalEventAttributes, TypeAttribute, Source public func title(_ value: String) -> Source { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Source { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Source { return mutate(translate: value.rawValue) @@ -222,17 +195,6 @@ extension Source: GlobalAttributes, GlobalEventAttributes, TypeAttribute, Source } } -extension Source: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element allows to specify explicit external timed text tracks for media elements. /// /// ```html @@ -259,26 +221,13 @@ public struct Track: EmptyNode, MediaElement { return self } - public func modify(unwrap value: TemplateValue, element: (Track, TemplateValue) -> Track) -> Track { + public func modify(unwrap value: T?, element: (Track, T) -> Track) -> Track { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -351,10 +300,6 @@ extension Track: GlobalAttributes, GlobalEventAttributes, KindAttribute, SourceA public func id(_ value: String) -> Track { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Track { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Track { return mutate(lang: value.rawValue) @@ -364,11 +309,6 @@ extension Track: GlobalAttributes, GlobalEventAttributes, KindAttribute, SourceA return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Track { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Track { return mutate(role: value.rawValue) } @@ -388,20 +328,10 @@ extension Track: GlobalAttributes, GlobalEventAttributes, KindAttribute, SourceA public func title(_ value: String) -> Track { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Track { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Track { return mutate(translate: value.rawValue) } - - @available(*, deprecated, message: "use translate(_ value: Values.Kinds) instead") - public func kind(_ value: String) -> Track { - return mutate(kind: value) - } public func kind(_ value: Values.Kind) -> Track { return mutate(kind: value.rawValue) @@ -443,14 +373,3 @@ extension Track: GlobalAttributes, GlobalEventAttributes, KindAttribute, SourceA return mutate(key: event.rawValue, value: value) } } - -extension Track: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} diff --git a/Sources/HTMLKit/Abstraction/Elements/ObjectElements.swift b/Sources/HTMLKit/Abstraction/Elements/ObjectElements.swift index 736d180b..b8a77d5f 100644 --- a/Sources/HTMLKit/Abstraction/Elements/ObjectElements.swift +++ b/Sources/HTMLKit/Abstraction/Elements/ObjectElements.swift @@ -34,26 +34,13 @@ public struct Parameter: EmptyNode, ObjectElement { return self } - public func modify(unwrap value: TemplateValue, element: (Parameter, TemplateValue) -> Parameter) -> Parameter { + public func modify(unwrap value: T?, element: (Parameter, T) -> Parameter) -> Parameter { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -126,10 +113,6 @@ extension Parameter: GlobalAttributes, GlobalEventAttributes, NameAttribute, Val public func id(_ value: String) -> Parameter { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Parameter { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Parameter { return mutate(lang: value.rawValue) @@ -139,11 +122,6 @@ extension Parameter: GlobalAttributes, GlobalEventAttributes, NameAttribute, Val return mutate(nonce: value) } - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Parameter { - return mutate(role: value) - } - public func role(_ value: Values.Role) -> Parameter { return mutate(role: value.rawValue) } @@ -163,11 +141,6 @@ extension Parameter: GlobalAttributes, GlobalEventAttributes, NameAttribute, Val public func title(_ value: String) -> Parameter { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Parameter { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Parameter { return mutate(translate: value.rawValue) @@ -177,18 +150,10 @@ extension Parameter: GlobalAttributes, GlobalEventAttributes, NameAttribute, Val return mutate(name: value) } - public func name(_ value: TemplateValue) -> Parameter { - return mutate(name: value.rawValue) - } - public func value(_ value: String) -> Parameter { return mutate(value: value) } - public func value(_ value: TemplateValue) -> Parameter { - return mutate(value: value.rawValue) - } - public func custom(key: String, value: Any) -> Parameter { return mutate(key: key, value: value) } @@ -213,14 +178,3 @@ extension Parameter: GlobalAttributes, GlobalEventAttributes, NameAttribute, Val return mutate(key: event.rawValue, value: value) } } - -extension Parameter: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} diff --git a/Sources/HTMLKit/Abstraction/Elements/RubyElements.swift b/Sources/HTMLKit/Abstraction/Elements/RubyElements.swift index 5af6767b..18a9c7a4 100644 --- a/Sources/HTMLKit/Abstraction/Elements/RubyElements.swift +++ b/Sources/HTMLKit/Abstraction/Elements/RubyElements.swift @@ -37,13 +37,13 @@ public struct RubyText: ContentNode, RubyElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -57,26 +57,13 @@ public struct RubyText: ContentNode, RubyElement { return self } - public func modify(unwrap value: TemplateValue, element: (RubyText, TemplateValue) -> RubyText) -> RubyText { + public func modify(unwrap value: T?, element: (RubyText, T) -> RubyText) -> RubyText { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -149,10 +136,6 @@ extension RubyText: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func id(_ value: String) -> RubyText { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> RubyText { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> RubyText { return mutate(lang: value.rawValue) @@ -161,11 +144,6 @@ extension RubyText: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func nonce(_ value: String) -> RubyText { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> RubyText { - return mutate(role: value) - } public func role(_ value: Values.Role) -> RubyText { return mutate(role: value.rawValue) @@ -186,11 +164,6 @@ extension RubyText: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func title(_ value: String) -> RubyText { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> RubyText { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> RubyText { return mutate(translate: value.rawValue) @@ -297,17 +270,6 @@ extension RubyText: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute } } -extension RubyText: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents nothing. /// /// ```html @@ -319,13 +281,13 @@ public struct RubyPronunciation: ContentNode, RubyElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -339,26 +301,13 @@ public struct RubyPronunciation: ContentNode, RubyElement { return self } - public func modify(unwrap value: TemplateValue, element: (RubyPronunciation, TemplateValue) -> RubyPronunciation) -> RubyPronunciation { + public func modify(unwrap value: T?, element: (RubyPronunciation, T) -> RubyPronunciation) -> RubyPronunciation { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -431,10 +380,6 @@ extension RubyPronunciation: GlobalAttributes, GlobalEventAttributes, GlobalAria public func id(_ value: String) -> RubyPronunciation { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> RubyPronunciation { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> RubyPronunciation { return mutate(lang: value.rawValue) @@ -443,11 +388,6 @@ extension RubyPronunciation: GlobalAttributes, GlobalEventAttributes, GlobalAria public func nonce(_ value: String) -> RubyPronunciation { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> RubyPronunciation { - return mutate(role: value) - } public func role(_ value: Values.Role) -> RubyPronunciation { return mutate(role: value.rawValue) @@ -469,11 +409,6 @@ extension RubyPronunciation: GlobalAttributes, GlobalEventAttributes, GlobalAria return mutate(title: value) } - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> RubyPronunciation { - return mutate(translate: value) - } - public func translate(_ value: Values.Decision) -> RubyPronunciation { return mutate(translate: value.rawValue) } @@ -578,14 +513,3 @@ extension RubyPronunciation: GlobalAttributes, GlobalEventAttributes, GlobalAria return mutate(ariaroledescription: value) } } - -extension RubyPronunciation: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} diff --git a/Sources/HTMLKit/Abstraction/Elements/TableElements.swift b/Sources/HTMLKit/Abstraction/Elements/TableElements.swift index cbcf5ece..a75831e2 100644 --- a/Sources/HTMLKit/Abstraction/Elements/TableElements.swift +++ b/Sources/HTMLKit/Abstraction/Elements/TableElements.swift @@ -91,13 +91,13 @@ public struct Caption: ContentNode, TableElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -111,26 +111,13 @@ public struct Caption: ContentNode, TableElement { return self } - public func modify(unwrap value: TemplateValue, element: (Caption, TemplateValue) -> Caption) -> Caption { + public func modify(unwrap value: T?, element: (Caption, T) -> Caption) -> Caption { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -203,10 +190,6 @@ extension Caption: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes public func id(_ value: String) -> Caption { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Caption { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Caption { return mutate(lang: value.rawValue) @@ -215,11 +198,6 @@ extension Caption: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes public func nonce(_ value: String) -> Caption { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Caption { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Caption { return mutate(role: value.rawValue) @@ -240,11 +218,6 @@ extension Caption: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes public func title(_ value: String) -> Caption { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Caption { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Caption { return mutate(translate: value.rawValue) @@ -351,17 +324,6 @@ extension Caption: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttributes } } -extension Caption: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element specifies a group of one or more columns. /// /// ```html @@ -373,13 +335,13 @@ public struct ColumnGroup: ContentNode, TableElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -393,26 +355,13 @@ public struct ColumnGroup: ContentNode, TableElement { return self } - public func modify(unwrap value: TemplateValue, element: (ColumnGroup, TemplateValue) -> ColumnGroup) -> ColumnGroup { + public func modify(unwrap value: T?, element: (ColumnGroup, T) -> ColumnGroup) -> ColumnGroup { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -485,10 +434,6 @@ extension ColumnGroup: GlobalAttributes, GlobalEventAttributes, SpanAttribute { public func id(_ value: String) -> ColumnGroup { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> ColumnGroup { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> ColumnGroup { return mutate(lang: value.rawValue) @@ -497,11 +442,6 @@ extension ColumnGroup: GlobalAttributes, GlobalEventAttributes, SpanAttribute { public func nonce(_ value: String) -> ColumnGroup { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> ColumnGroup { - return mutate(role: value) - } public func role(_ value: Values.Role) -> ColumnGroup { return mutate(role: value.rawValue) @@ -522,11 +462,6 @@ extension ColumnGroup: GlobalAttributes, GlobalEventAttributes, SpanAttribute { public func title(_ value: String) -> ColumnGroup { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> ColumnGroup { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> ColumnGroup { return mutate(translate: value.rawValue) @@ -561,17 +496,6 @@ extension ColumnGroup: GlobalAttributes, GlobalEventAttributes, SpanAttribute { } } -extension ColumnGroup: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a column in a table. /// /// ```html @@ -583,13 +507,13 @@ public struct Column: ContentNode, TableElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -603,26 +527,13 @@ public struct Column: ContentNode, TableElement { return self } - public func modify(unwrap value: TemplateValue, element: (Column, TemplateValue) -> Column) -> Column { + public func modify(unwrap value: T?, element: (Column, T) -> Column) -> Column { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -695,10 +606,6 @@ extension Column: GlobalAttributes, GlobalEventAttributes, SpanAttribute { public func id(_ value: String) -> Column { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> Column { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> Column { return mutate(lang: value.rawValue) @@ -707,11 +614,6 @@ extension Column: GlobalAttributes, GlobalEventAttributes, SpanAttribute { public func nonce(_ value: String) -> Column { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> Column { - return mutate(role: value) - } public func role(_ value: Values.Role) -> Column { return mutate(role: value.rawValue) @@ -732,11 +634,6 @@ extension Column: GlobalAttributes, GlobalEventAttributes, SpanAttribute { public func title(_ value: String) -> Column { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> Column { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> Column { return mutate(translate: value.rawValue) @@ -771,17 +668,6 @@ extension Column: GlobalAttributes, GlobalEventAttributes, SpanAttribute { } } -extension Column: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a block of rows in a table. /// /// ```html @@ -793,13 +679,13 @@ public struct TableBody: ContentNode, TableElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -813,26 +699,13 @@ public struct TableBody: ContentNode, TableElement { return self } - public func modify(unwrap value: TemplateValue, element: (TableBody, TemplateValue) -> TableBody) -> TableBody { + public func modify(unwrap value: T?, element: (TableBody, T) -> TableBody) -> TableBody { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -905,10 +778,6 @@ extension TableBody: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut public func id(_ value: String) -> TableBody { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> TableBody { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> TableBody { return mutate(lang: value.rawValue) @@ -917,11 +786,6 @@ extension TableBody: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut public func nonce(_ value: String) -> TableBody { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> TableBody { - return mutate(role: value) - } public func role(_ value: Values.Role) -> TableBody { return mutate(role: value.rawValue) @@ -942,11 +806,6 @@ extension TableBody: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut public func title(_ value: String) -> TableBody { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> TableBody { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> TableBody { return mutate(translate: value.rawValue) @@ -1061,17 +920,6 @@ extension TableBody: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut } } -extension TableBody: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents the block of rows that consist of the column labels. /// /// ```html @@ -1083,13 +931,13 @@ public struct TableHead: ContentNode, TableElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -1103,26 +951,13 @@ public struct TableHead: ContentNode, TableElement { return self } - public func modify(unwrap value: TemplateValue, element: (TableHead, TemplateValue) -> TableHead) -> TableHead { + public func modify(unwrap value: T?, element: (TableHead, T) -> TableHead) -> TableHead { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -1195,10 +1030,6 @@ extension TableHead: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut public func id(_ value: String) -> TableHead { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> TableHead { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> TableHead { return mutate(lang: value.rawValue) @@ -1207,11 +1038,6 @@ extension TableHead: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut public func nonce(_ value: String) -> TableHead { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> TableHead { - return mutate(role: value) - } public func role(_ value: Values.Role) -> TableHead { return mutate(role: value.rawValue) @@ -1232,11 +1058,6 @@ extension TableHead: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut public func title(_ value: String) -> TableHead { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> TableHead { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> TableHead { return mutate(translate: value.rawValue) @@ -1351,17 +1172,6 @@ extension TableHead: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut } } -extension TableHead: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents the block of rows that consist of the column summaries. /// /// ```html @@ -1373,13 +1183,13 @@ public struct TableFoot: ContentNode, TableElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -1393,26 +1203,13 @@ public struct TableFoot: ContentNode, TableElement { return self } - public func modify(unwrap value: TemplateValue, element: (TableFoot, TemplateValue) -> TableFoot) -> TableFoot { + public func modify(unwrap value: T?, element: (TableFoot, T) -> TableFoot) -> TableFoot { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -1485,10 +1282,6 @@ extension TableFoot: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut public func id(_ value: String) -> TableFoot { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> TableFoot { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> TableFoot { return mutate(lang: value.rawValue) @@ -1497,11 +1290,6 @@ extension TableFoot: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut public func nonce(_ value: String) -> TableFoot { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> TableFoot { - return mutate(role: value) - } public func role(_ value: Values.Role) -> TableFoot { return mutate(role: value.rawValue) @@ -1522,11 +1310,6 @@ extension TableFoot: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut public func title(_ value: String) -> TableFoot { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> TableFoot { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> TableFoot { return mutate(translate: value.rawValue) @@ -1633,17 +1416,6 @@ extension TableFoot: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribut } } -extension TableFoot: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a row of cells in a table. /// /// ```html @@ -1655,13 +1427,13 @@ public struct TableRow: ContentNode, TableElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -1675,26 +1447,13 @@ public struct TableRow: ContentNode, TableElement { return self } - public func modify(unwrap value: TemplateValue, element: (TableRow, TemplateValue) -> TableRow) -> TableRow { + public func modify(unwrap value: T?, element: (TableRow, T) -> TableRow) -> TableRow { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -1767,10 +1526,6 @@ extension TableRow: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func id(_ value: String) -> TableRow { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> TableRow { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> TableRow { return mutate(lang: value.rawValue) @@ -1779,11 +1534,6 @@ extension TableRow: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func nonce(_ value: String) -> TableRow { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> TableRow { - return mutate(role: value) - } public func role(_ value: Values.Role) -> TableRow { return mutate(role: value.rawValue) @@ -1804,11 +1554,6 @@ extension TableRow: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func title(_ value: String) -> TableRow { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> TableRow { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> TableRow { return mutate(translate: value.rawValue) @@ -1923,17 +1668,6 @@ extension TableRow: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute } } -extension TableRow: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a data cell in a table. /// /// ```html @@ -1945,13 +1679,13 @@ public struct DataCell: ContentNode, TableElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -1965,26 +1699,13 @@ public struct DataCell: ContentNode, TableElement { return self } - public func modify(unwrap value: TemplateValue, element: (DataCell, TemplateValue) -> DataCell) -> DataCell { + public func modify(unwrap value: T?, element: (DataCell, T) -> DataCell) -> DataCell { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -2057,10 +1778,6 @@ extension DataCell: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func id(_ value: String) -> DataCell { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> DataCell { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> DataCell { return mutate(lang: value.rawValue) @@ -2069,11 +1786,6 @@ extension DataCell: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func nonce(_ value: String) -> DataCell { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> DataCell { - return mutate(role: value) - } public func role(_ value: Values.Role) -> DataCell { return mutate(role: value.rawValue) @@ -2094,11 +1806,6 @@ extension DataCell: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute public func title(_ value: String) -> DataCell { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> DataCell { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> DataCell { return mutate(translate: value.rawValue) @@ -2217,17 +1924,6 @@ extension DataCell: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribute } } -extension DataCell: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a header cell in a table. /// /// ```html @@ -2239,13 +1935,13 @@ public struct HeaderCell: ContentNode, TableElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -2259,26 +1955,13 @@ public struct HeaderCell: ContentNode, TableElement { return self } - public func modify(unwrap value: TemplateValue, element: (HeaderCell, TemplateValue) -> HeaderCell) -> HeaderCell { + public func modify(unwrap value: T?, element: (HeaderCell, T) -> HeaderCell) -> HeaderCell { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -2351,10 +2034,6 @@ extension HeaderCell: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribu public func id(_ value: String) -> HeaderCell { return mutate(id: value) } - - public func id(_ value: TemplateValue) -> HeaderCell { - return mutate(id: value.rawValue) - } public func language(_ value: Values.Language) -> HeaderCell { return mutate(lang: value.rawValue) @@ -2363,11 +2042,6 @@ extension HeaderCell: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribu public func nonce(_ value: String) -> HeaderCell { return mutate(nonce: value) } - - @available(*, deprecated, message: "use role(_ value: Values.Roles) instead") - public func role(_ value: String) -> HeaderCell { - return mutate(role: value) - } public func role(_ value: Values.Role) -> HeaderCell { return mutate(role: value.rawValue) @@ -2388,11 +2062,6 @@ extension HeaderCell: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribu public func title(_ value: String) -> HeaderCell { return mutate(title: value) } - - @available(*, deprecated, message: "use translate(_ value: Values.Decision) instead") - public func translate(_ value: String) -> HeaderCell { - return mutate(translate: value) - } public func translate(_ value: Values.Decision) -> HeaderCell { return mutate(translate: value.rawValue) @@ -2515,24 +2184,13 @@ extension HeaderCell: GlobalAttributes, GlobalEventAttributes, GlobalAriaAttribu } } -extension HeaderCell: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - extension HeaderCell: Localizable { public init(_ localizedKey: String) { - self.content = [Localized(key: localizedKey)] + self.content = [LocalizedStringKey(key: localizedKey)] } - public init(_ localizedKey: String, with context: TemplateValue) where B : Encodable { - self.content = [Localized(key: localizedKey, context: context)] + public init(_ localizedKey: String, with context: some Encodable) { + self.content = [LocalizedStringKey(key: localizedKey, context: context)] } } diff --git a/Sources/HTMLKit/Abstraction/Elements/VectorElements.swift b/Sources/HTMLKit/Abstraction/Elements/VectorElements.swift index 4836653e..a8e16543 100644 --- a/Sources/HTMLKit/Abstraction/Elements/VectorElements.swift +++ b/Sources/HTMLKit/Abstraction/Elements/VectorElements.swift @@ -28,13 +28,13 @@ public struct Circle: ContentNode, VectorElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -48,26 +48,13 @@ public struct Circle: ContentNode, VectorElement { return self } - public func modify(unwrap value: TemplateValue, element: (Circle, TemplateValue) -> Circle) -> Circle { + public func modify(unwrap value: T?, element: (Circle, T) -> Circle) -> Circle { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -77,10 +64,6 @@ extension Circle: GlobalVectorAttributes, CenterPointAttribute, RadiusAttribute return self.mutate(id: value) } - public func id(_ value: TemplateValue) -> Circle { - return self.mutate(id: value.rawValue) - } - public func tabIndex(_ value: Int) -> Circle { return self.mutate(tabindex: value) } @@ -134,17 +117,6 @@ extension Circle: GlobalVectorAttributes, CenterPointAttribute, RadiusAttribute } } -extension Circle: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents ... /// /// ```html @@ -156,13 +128,13 @@ public struct Rectangle: ContentNode, VectorElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -176,26 +148,13 @@ public struct Rectangle: ContentNode, VectorElement { return self } - public func modify(unwrap value: TemplateValue, element: (Rectangle, TemplateValue) -> Rectangle) -> Rectangle { + public func modify(unwrap value: T?, element: (Rectangle, T) -> Rectangle) -> Rectangle { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -205,10 +164,6 @@ extension Rectangle: GlobalVectorAttributes, WidthAttribute, HeightAttribute, Ra return self.mutate(id: value) } - public func id(_ value: TemplateValue) -> Rectangle { - return self.mutate(id: value.rawValue) - } - public func tabIndex(_ value: Int) -> Rectangle { return self.mutate(tabindex: value) } @@ -266,17 +221,6 @@ extension Rectangle: GlobalVectorAttributes, WidthAttribute, HeightAttribute, Ra } } -extension Rectangle: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a comment output. /// /// ```html @@ -288,13 +232,13 @@ public struct Ellipse: ContentNode, VectorElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -308,26 +252,13 @@ public struct Ellipse: ContentNode, VectorElement { return self } - public func modify(unwrap value: TemplateValue, element: (Ellipse, TemplateValue) -> Ellipse) -> Ellipse { + public func modify(unwrap value: T?, element: (Ellipse, T) -> Ellipse) -> Ellipse { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -337,10 +268,6 @@ extension Ellipse: GlobalVectorAttributes, CenterPointAttribute, RadiusPointAttr return self.mutate(id: value) } - public func id(_ value: TemplateValue) -> Ellipse { - return self.mutate(id: value.rawValue) - } - public func tabIndex(_ value: Int) -> Ellipse { return self.mutate(tabindex: value) } @@ -394,17 +321,6 @@ extension Ellipse: GlobalVectorAttributes, CenterPointAttribute, RadiusPointAttr } } -extension Ellipse: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents ... /// /// ```html @@ -416,13 +332,13 @@ public struct Line: ContentNode, VectorElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -436,26 +352,13 @@ public struct Line: ContentNode, VectorElement { return self } - public func modify(unwrap value: TemplateValue, element: (Line, TemplateValue) -> Line) -> Line { + public func modify(unwrap value: T?, element: (Line, T) -> Line) -> Line { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -465,10 +368,6 @@ extension Line: GlobalVectorAttributes { return self.mutate(id: value) } - public func id(_ value: TemplateValue) -> Line { - return self.mutate(id: value.rawValue) - } - public func tabIndex(_ value: Int) -> Line { return self.mutate(tabindex: value) } @@ -514,17 +413,6 @@ extension Line: GlobalVectorAttributes { } } -extension Line: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents a comment output. /// /// ```html @@ -536,13 +424,13 @@ public struct Polygon: ContentNode, VectorElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -556,26 +444,13 @@ public struct Polygon: ContentNode, VectorElement { return self } - public func modify(unwrap value: TemplateValue, element: (Polygon, TemplateValue) -> Polygon) -> Polygon { + public func modify(unwrap value: T?, element: (Polygon, T) -> Polygon) -> Polygon { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -585,10 +460,6 @@ extension Polygon: GlobalVectorAttributes { return self.mutate(id: value) } - public func id(_ value: TemplateValue) -> Polygon { - return self.mutate(id: value.rawValue) - } - public func tabIndex(_ value: Int) -> Polygon { return self.mutate(tabindex: value) } @@ -634,17 +505,6 @@ extension Polygon: GlobalVectorAttributes { } } -extension Polygon: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents ... /// /// ```html @@ -656,13 +516,13 @@ public struct Polyline: ContentNode, VectorElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -676,26 +536,13 @@ public struct Polyline: ContentNode, VectorElement { return self } - public func modify(unwrap value: TemplateValue, element: (Polyline, TemplateValue) -> Polyline) -> Polyline { + public func modify(unwrap value: T?, element: (Polyline, T) -> Polyline) -> Polyline { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -705,10 +552,6 @@ extension Polyline: GlobalVectorAttributes { return self.mutate(id: value) } - public func id(_ value: TemplateValue) -> Polyline { - return self.mutate(id: value.rawValue) - } - public func tabIndex(_ value: Int) -> Polyline { return self.mutate(tabindex: value) } @@ -754,17 +597,6 @@ extension Polyline: GlobalVectorAttributes { } } -extension Polyline: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents ... /// /// ```html @@ -776,13 +608,13 @@ public struct Path: ContentNode, VectorElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -796,26 +628,13 @@ public struct Path: ContentNode, VectorElement { return self } - public func modify(unwrap value: TemplateValue, element: (Path, TemplateValue) -> Path) -> Path { + public func modify(unwrap value: T?, element: (Path, T) -> Path) -> Path { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -825,10 +644,6 @@ extension Path: GlobalVectorAttributes, DrawAttribute { return self.mutate(id: value) } - public func id(_ value: TemplateValue) -> Path { - return self.mutate(id: value.rawValue) - } - public func tabIndex(_ value: Int) -> Path { return self.mutate(tabindex: value) } @@ -878,17 +693,6 @@ extension Path: GlobalVectorAttributes, DrawAttribute { } } -extension Path: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents ... /// /// ```html @@ -900,13 +704,13 @@ public struct Group: ContentNode, VectorElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -920,95 +724,67 @@ public struct Group: ContentNode, VectorElement { return self } - public func modify(unwrap value: TemplateValue, element: (Group, TemplateValue) -> Group) -> Group { + public func modify(unwrap value: T?, element: (Group, T) -> Group) -> Group { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } extension Group: GlobalVectorAttributes { - public func id(_ value: String) -> Self { + public func id(_ value: String) -> Group { return self.mutate(id: value) } - public func id(_ value: TemplateValue) -> Self { - return self.mutate(id: value.rawValue) - } - - public func tabIndex(_ value: Int) -> Self { + public func tabIndex(_ value: Int) -> Group { return self.mutate(tabindex: value) } - public func `class`(_ value: String) -> Self { + public func `class`(_ value: String) -> Group { return self.mutate(class: value) } - public func style(_ value: String) -> Self { + public func style(_ value: String) -> Group { return self.mutate(style: value) } - public func fill(_ value: String) -> Self { + public func fill(_ value: String) -> Group { return self.mutate(fill: value) } - public func stroke(_ value: String) -> Self { + public func stroke(_ value: String) -> Group { return self.mutate(stroke: value) } - public func strokeWidth(_ size: Int) -> Self { + public func strokeWidth(_ size: Int) -> Group { return self.mutate(strokewidth: size) } - public func fillOpacity(_ value: Double) -> Self { + public func fillOpacity(_ value: Double) -> Group { return self.mutate(fillopacity: value) } - public func strokeOpacity(_ value: Double) -> Self { + public func strokeOpacity(_ value: Double) -> Group { return self.mutate(strokeopacity: value) } - public func strokeLineCap(_ value: Values.Linecap) -> Self { + public func strokeLineCap(_ value: Values.Linecap) -> Group { return self.mutate(strokelinecap: value.rawValue) } - public func strokeLineJoin(_ value: Values.Linejoin) -> Self { + public func strokeLineJoin(_ value: Values.Linejoin) -> Group { return self.mutate(strokelinejoin: value.rawValue) } - - public func custom(key: String, value: Any) -> Self { + + public func custom(key: String, value: Any) -> Group { return self.mutate(key: key, value: value) } } -extension Group: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} - /// The element represents ... /// /// ```html @@ -1020,13 +796,13 @@ public struct Use: ContentNode, VectorElement { internal var attributes: OrderedDictionary? - internal var content: [AnyContent] + internal var content: [Content] - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() } - internal init(attributes: OrderedDictionary?, content: [AnyContent]) { + internal init(attributes: OrderedDictionary?, content: [Content]) { self.attributes = attributes self.content = content } @@ -1040,26 +816,13 @@ public struct Use: ContentNode, VectorElement { return self } - public func modify(unwrap value: TemplateValue, element: (Use, TemplateValue) -> Use) -> Use { + public func modify(unwrap value: T?, element: (Use, T) -> Use) -> Use { - switch value { - case .constant(let optional): - - guard let value = optional else { - return self - } - - return self.modify(element(self, .constant(value))) - - case .dynamic(let context): - - if context.isMasqueradingOptional { - return self.modify(element(self, .dynamic(context.unsafeCast(to: T.self)))) - - } else { - return self.modify(element(self, .dynamic(context.unsafelyUnwrapped))) - } + guard let value = value else { + return self } + + return self.modify(element(self, value as T)) } } @@ -1069,10 +832,6 @@ extension Use: GlobalVectorAttributes, ReferenceAttribute, WidthAttribute, Heigh return self.mutate(id: value) } - public func id(_ value: TemplateValue) -> Use { - return self.mutate(id: value.rawValue) - } - public func tabIndex(_ value: Int) -> Use { return self.mutate(tabindex: value) } @@ -1081,10 +840,6 @@ extension Use: GlobalVectorAttributes, ReferenceAttribute, WidthAttribute, Heigh return self.mutate(href: value) } - public func reference(_ value: TemplateValue) -> Use { - return self.mutate(href: value.rawValue) - } - public func width(_ size: Int) -> Use { return self.mutate(width: size) } @@ -1133,14 +888,3 @@ extension Use: GlobalVectorAttributes, ReferenceAttribute, WidthAttribute, Heigh return self.mutate(key: key, value: value) } } - -extension Use: AnyContent { - - public func prerender(_ formula: Formula) throws { - try self.build(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try self.build(with: manager) - } -} diff --git a/Sources/HTMLKit/Abstraction/Helpers/TagHelpers.swift b/Sources/HTMLKit/Abstraction/Helpers/TagHelpers.swift deleted file mode 100644 index 9d1a37a4..00000000 --- a/Sources/HTMLKit/Abstraction/Helpers/TagHelpers.swift +++ /dev/null @@ -1,272 +0,0 @@ -/* - Abstract: - The file contains the tag helpers. A helper combine several html elements, wich are commonly used. - - Note: - If you about to add something to the file, stick to the official documentation to keep the code consistent. - */ - -import Foundation - -/// The component returns a meta element with twitter and opengraph. -public struct MetaTitle: Component { - - private var title: TemplateValue - - private let useOpenGraph: Conditionable - - private let useTwitter: Conditionable - - public init(title: TemplateValue, useOpenGraph: Conditionable = true, useTwitter: Conditionable = true) { - self.title = title - self.useOpenGraph = useOpenGraph - self.useTwitter = useTwitter - } - - public var body: AnyContent { - Title { - self.title.rawValue - } - IF(useOpenGraph) { - Meta() - .property(.title) - .content(self.title) - } - IF(useTwitter) { - Meta() - .custom(key: "name", value: "twitter:title") - .content(self.title.rawValue) - } - } -} - -/// The component returns a meta element with twitter and opengraph. -public struct MetaDescription: Component { - - private var description: TemplateValue - - private let useOpenGraph: Conditionable - - private let useTwitter: Conditionable - - public var body: AnyContent { - Meta() - .name(.description) - .content(self.description) - IF(useOpenGraph) { - Meta() - .property(.description) - .content(self.description) - } - IF(useTwitter) { - Meta() - .custom(key: "name", value: "twitter:description") - .content(self.description.rawValue) - } - } - - public init(description: TemplateValue, useOpenGraph: Conditionable = true, useTwitter: Conditionable = true) { - self.description = description - self.useOpenGraph = useOpenGraph - self.useTwitter = useTwitter - } -} - -/// The component returns a link element. -public struct Favicon: Component { - - private let url: TemplateValue - - public init(url: TemplateValue) { - self.url = url - } - - public var body: AnyContent { - Link() - .relationship(.shortcutIcon) - .reference(self.url.rawValue) - } -} - -/// The component returns a link element. -public struct Stylesheet: Component { - - private var url: TemplateValue - - public init(url: TemplateValue) { - self.url = url - } - - public var body: AnyContent { - Link() - .relationship(.stylesheet) - .reference(self.url) - .type(.css) - } -} - -/// The component returns a meta element. -public struct Viewport: Component { - - private var mode: WidthMode - private var internalScale: Double = 1 - - public enum WidthMode { - case accordingToDevice - case constant(Int) - - public var width: String { - switch self { - case .accordingToDevice: return "device-width" - case .constant(let width): return "\(width)" - } - } - } - - public init(_ mode: WidthMode, internalScale: Double = 1) { - self.mode = mode - self.internalScale = internalScale - } - - public var body: AnyContent { - Meta() - .name(.viewport) - .content("width=\(self.mode.width), initial-scale=\(self.internalScale)") - } -} - -/// The component returns a meta element. -public struct Author: Component { - - private var author: TemplateValue - - private var handle: TemplateValue - - public var body: AnyContent { - Meta() - .name(.author) - .content(self.author) - Unwrap(self.handle) { handle in - Meta() - .custom(key: "name", value: "twitter:creator") - .content(handle) - } - } - - public init(author: TemplateValue, handle: TemplateValue) { - self.author = author - self.handle = handle - } -} - -/// The component returns a meta element useful for tell visiting robots whether a document may be indexed, or used to harvest more links. -public struct Robots: Component { - public enum IndexingOption: CustomStringConvertible { - /// There are no restrictions for indexing or serving. This directive is the default value and has no effect if explicitly listed. - case all - /// Do not show this page, media, or resource in search results. If you don't specify this directive, the page, media, or resource may be indexed and shown in search results. - case noIndex - /// Do not follow the links on this page. If you don't specify this directive, search engines may use the links on the page to discover those linked pages. - case noFollow - /// Equivalent to ``noIndex``, ``noFollow``. - case none - /// Do not show a cached link in search results. If you don't specify this directive, search engines may generate a cached page and users may access it through the search results. - case noArchive - /// Do not show a sitelinks search box in the search results for this page. If you don't specify this directive, search engines may generate a search box specific to your site in search results, along with other direct links to your site. - case noSiteLinksSearchBox - /// Do not show a text snippet or video preview in the search results for this page. A static image thumbnail (if available) may still be visible, when it results in a better user experience. This applies to all forms of search results. - /// - /// If you don't specify this directive, search engines may generate a text snippet and video preview based on information found on the page. - case noSnippet - /// Search engines are allowed to index the content of a page if it's embedded in another page through iframes or similar HTML tags, in spite of a ``noIndex`` directive. - /// - /// ``indexIfEmbedded`` only has an effect if it's accompanied by ``noIndex``. - case indexIfEmbedded - /// Use a maximum number characters as a textual snippet for this search result. (Note that a URL may appear as multiple search results within a search results page.) This does not affect image or video previews. This directive is ignored if no parseable number is specified. - /// - /// If you don't specify this directive, search engines will choose the length of the snippet. - /// - /// Special values: - /// - /// - `0`: No snippet is to be shown. Equivalent to ``noSnippet``. - /// - `-1`: Search engines will choose the snippet length that it believes is most effective to help users discover your content and direct users to your site. - case maximumSnippetLength(Int) - /// Set the maximum size of an image preview for this page in a search results. - /// - /// If you don't specify the `max-image-preview` directive, search engines may show an image preview of the default size. - case maximumImagePreview(MaximumImagePreview) - /// Use a maximum of number of seconds as a video snippet for videos on this page in search results. - /// - /// Special values: - /// - /// - `0`: At most, a static image may be used, in accordance to the max-image-preview setting. - /// - `-1`: There is no limit. - case maximumVideoPreview(Int) - /// Don't offer translation of this page in search results. - case noTranslate - /// Do not index images on this page. If you don't specify this value, images on the page may be indexed and shown in search results. - case noImageIndex - /// Do not show this page in search results after the specified date/time. - /// - /// The directive is ignored if no valid date/time is specified. By default there is no expiration date for content. - /// - /// If you don't specify this directive, this page may be shown in search results indefinitely. - case unavailableAfter(Date) - - public var description: String { - switch self { - case .all: - return "all" - case .noIndex: - return "noindex" - case .noFollow: - return "nofollow" - case .none: - return "none" - case .noArchive: - return "noarchive" - case .noSiteLinksSearchBox: - return "nositelinkssearchbox" - case .noSnippet: - return "nosnippet" - case .indexIfEmbedded: - return "indexifembedded" - case .maximumSnippetLength(let value): - return "max-snippet-length: \(value)" - case .maximumImagePreview(let value): - return "max-image-preview: \(value.rawValue)" - case .maximumVideoPreview(let value): - return "max-video-preview: \(value)" - case .noTranslate: - return "notranslate" - case .noImageIndex: - return "noimageindex" - case .unavailableAfter(let date): - return "unavailable-after: \(Self.dateFormatter.string(from: date))" - } - } - - static let dateFormatter = ISO8601DateFormatter() - } - - public enum MaximumImagePreview: String { - /// No image preview is to be shown. - case none - /// A default image preview may be shown. - case standard - /// A larger image preview, up to the width of the viewport, may be shown. - case large - } - - private var indexingOptions: [IndexingOption] - - public var body: AnyContent { - Meta() - .name(.robots) - .content(self.indexingOptions.map(\.description).joined(separator: ", ")) - } - - public init(indexing: [IndexingOption]) { - self.indexingOptions = indexing - } -} diff --git a/Sources/HTMLKit/Framework/Core/Builders/ContentBuilder.swift b/Sources/HTMLKit/Framework/Core/Builders/ContentBuilder.swift index 34632908..31f00d59 100644 --- a/Sources/HTMLKit/Framework/Core/Builders/ContentBuilder.swift +++ b/Sources/HTMLKit/Framework/Core/Builders/ContentBuilder.swift @@ -3,42 +3,122 @@ The file contains the builder to build up the result from a sequence of elements. */ -/// The builder builds up a result value from a sequence of any content. +/// The builder builds up a result value from a sequence of elements. @resultBuilder public class ContentBuilder { + /// Builds an empty block + /// + /// ```swift + /// Tag { + /// } + /// ``` public static func buildBlock() -> [T] { return [] } + /// Builds a block with one element. + /// + /// ```swift + /// Tag { + /// Tag { + /// } + /// } + /// ``` public static func buildBlock(_ component: T) -> [T] { return [component] } + /// Builds a block with more than one element. + /// + /// ```swift + /// Tag { + /// Tag { + /// } + /// Tag { + /// } + /// } + /// ``` public static func buildBlock(_ components: T...) -> [T] { - return components + return components.compactMap { $0 } } - public static func buildBlock(_ components: [T], _ trailing: T...) -> [T] { - return components + trailing - } - - public static func buildBlock(_ c1: T, _ components: [T], _ trailing: T...) -> [T] { - return [c1] + components + trailing + /// Builds a block with one element. + /// + /// ```swift + /// Tag { + /// if let unwrapped = optional { + /// Tag { + /// unwrapped + /// } + /// } + /// } + /// ``` + public static func buildOptional(_ component: T?) -> [T] { + + if let component = component { + return [component] + } + + return [] } - - public static func buildBlock(_ c1: T, _ c2: T, _ components: [T], _ trailing: T...) -> [T] { - return [c1, c2] + components + trailing + + /// Builds a block, if the condition is true. + /// + /// ```swift + /// Tag { + /// if(true) { + /// Tag { + /// } + /// } + /// } + /// ``` + public static func buildEither(first component: T) -> [T] { + return [component] } - - public static func buildBlock(_ c1: T, _ c2: T, _ c3: T, _ components: [T], _ trailing: T...) -> [T] { - return [c1, c2, c3] + components + trailing + + /// Builds a block, if the condition is false. + /// + /// ```swift + /// Tag { + /// if(false) { + /// Tag { + /// } + /// } + /// else { + /// Tag { + /// } + /// } + /// } + /// ``` + public static func buildEither(second component: T) -> [T] { + return [component] } - public static func buildBlock(_ cs1: [T], _ components: [T], _ trailing: T...) -> [T] { - return cs1 + components + trailing + /// Builds blocks by running through a sequence of elements. + /// + /// ```swift + /// Tag { + /// for element in sequence { + /// Tag { + /// element + /// } + /// } + /// } + /// ``` + public static func buildArray(_ components: [[T]]) -> [T] { + return components.flatMap { $0 } } - public static func buildBlock(_ cs1: [T], _ cs2: [T], _ components: [T], _ trailing: T...) -> [T] { - return cs1 + cs2 + components + trailing + /// Builds a block with embeded content. + /// + /// ```swift + /// Tag { + /// content + /// Tag { + /// } + /// } + /// ``` + public static func buildBlock(_ content: [T], _ components: T...) -> [T] { + return content + components.compactMap { $0 } } } diff --git a/Sources/HTMLKit/Framework/Core/Extensions/Datatypes+Content.swift b/Sources/HTMLKit/Framework/Core/Extensions/Datatypes+Content.swift index c47f7d4f..a5e58306 100644 --- a/Sources/HTMLKit/Framework/Core/Extensions/Datatypes+Content.swift +++ b/Sources/HTMLKit/Framework/Core/Extensions/Datatypes+Content.swift @@ -5,378 +5,20 @@ import Foundation -extension Array: AnyContent where Element == AnyContent { +extension Array: Content {} - public func prerender(_ formula: Formula) throws { - try forEach { try $0.prerender(formula) } - } +extension Bool: Content {} - public func render(with manager: ContextManager) throws -> String { - return try self.reduce("") { try $0 + $1.render(with: manager) } - } +extension Double: Content {} - public var scripts: AnyContent { - return self.reduce("") { $0 + $1.scripts } - } -} +extension Float: Content {} -extension Array where Element == String { +extension Int: Content {} - public func prerender(_ formula: Formula) throws { - try forEach { try $0.prerender(formula) } - } +extension Optional: Content{} - public func render(with manager: ContextManager) throws -> String { - return try self.reduce("") { try $0 + $1.render(with: manager) } - } +extension String: Content {} - public var scripts: AnyContent { - return self.reduce("") { $0 + $1.scripts } - } -} +extension UUID: Content {} -extension Array where Element == BodyElement { - - public func prerender(_ formula: Formula) throws { - try forEach { try $0.prerender(formula) } - } - - public func render(with manager: ContextManager) throws -> String { - return try self.reduce("") { try $0 + $1.render(with: manager) } - } - - public var scripts: AnyContent { - return self.reduce("") { $0 + $1.scripts } - } -} - -extension Array where Element == DescriptionElement { - - public func prerender(_ formula: Formula) throws { - try forEach { try $0.prerender(formula) } - } - - public func render(with manager: ContextManager) throws -> String { - return try self.reduce("") { try $0 + $1.render(with: manager) } - } - - public var scripts: AnyContent { - return self.reduce("") { $0 + $1.scripts } - } -} - -extension Array where Element == FigureElement { - - public func prerender(_ formula: Formula) throws { - try forEach { try $0.prerender(formula) } - } - - public func render(with manager: ContextManager) throws -> String { - return try self.reduce("") { try $0 + $1.render(with: manager) } - } - - public var scripts: AnyContent { - return self.reduce("") { $0 + $1.scripts } - } -} - -extension Array where Element == FormElement { - - public func prerender(_ formula: Formula) throws { - try forEach { try $0.prerender(formula) } - } - - public func render(with manager: ContextManager) throws -> String { - return try self.reduce("") { try $0 + $1.render(with: manager) } - } - - public var scripts: AnyContent { - return self.reduce("") { $0 + $1.scripts } - } -} - -extension Array where Element == BasicElement { - - public func prerender(_ formula: Formula) throws { - try forEach { try $0.prerender(formula) } - } - - public func render(with manager: ContextManager) throws -> String { - return try self.reduce("") { try $0 + $1.render(with: manager) } - } - - public var scripts: AnyContent { - return self.reduce("") { $0 + $1.scripts } - } -} - -extension Array where Element == HeadElement { - - public func prerender(_ formula: Formula) throws { - try forEach { try $0.prerender(formula) } - } - - public func render(with manager: ContextManager) throws -> String { - return try self.reduce("") { try $0 + $1.render(with: manager) } - } - - public var scripts: AnyContent { - return self.reduce("") { $0 + $1.scripts } - } -} - -extension Array where Element == InputElement { - - public func prerender(_ formula: Formula) throws { - try forEach { try $0.prerender(formula) } - } - - public func render(with manager: ContextManager) throws -> String { - return try self.reduce("") { try $0 + $1.render(with: manager) } - } - - public var scripts: AnyContent { - return self.reduce("") { $0 + $1.scripts } - } -} - -extension Array where Element == ListElement { - - public func prerender(_ formula: Formula) throws { - try forEach { try $0.prerender(formula) } - } - - public func render(with manager: ContextManager) throws -> String { - return try self.reduce("") { try $0 + $1.render(with: manager) } - } - - public var scripts: AnyContent { - return self.reduce("") { $0 + $1.scripts } - } -} - -extension Array where Element == MapElement { - - public func prerender(_ formula: Formula) throws { - try forEach { try $0.prerender(formula) } - } - - public func render(with manager: ContextManager) throws -> String { - return try self.reduce("") { try $0 + $1.render(with: manager) } - } - - public var scripts: AnyContent { - return self.reduce("") { $0 + $1.scripts } - } -} - -extension Array where Element == MediaElement { - - public func prerender(_ formula: Formula) throws { - try forEach { try $0.prerender(formula) } - } - - public func render(with manager: ContextManager) throws -> String { - return try self.reduce("") { try $0 + $1.render(with: manager) } - } - - public var scripts: AnyContent { - return self.reduce("") { $0 + $1.scripts } - } -} - -extension Array where Element == ObjectElement { - - public func prerender(_ formula: Formula) throws { - try forEach { try $0.prerender(formula) } - } - - public func render(with manager: ContextManager) throws -> String { - return try self.reduce("") { try $0 + $1.render(with: manager) } - } - - public var scripts: AnyContent { - return self.reduce("") { $0 + $1.scripts } - } -} - -extension Array where Element == RubyElement { - - public func prerender(_ formula: Formula) throws { - try forEach { try $0.prerender(formula) } - } - - public func render(with manager: ContextManager) throws -> String { - return try self.reduce("") { try $0 + $1.render(with: manager) } - } - - public var scripts: AnyContent { - return self.reduce("") { $0 + $1.scripts } - } -} - -extension Array where Element == TableElement { - - public func prerender(_ formula: Formula) throws { - try forEach { try $0.prerender(formula) } - } - - public func render(with manager: ContextManager) throws -> String { - return try self.reduce("") { try $0 + $1.render(with: manager) } - } - - public var scripts: AnyContent { - return self.reduce("") { $0 + $1.scripts } - } -} - -extension Array where Element == HtmlElement { - - public func prerender(_ formula: Formula) throws { - try forEach { try $0.prerender(formula) } - } - - public func render(with manager: ContextManager) throws -> String { - return try self.reduce("") { try $0 + $1.render(with: manager) } - } - - public var scripts: AnyContent { - return self.reduce("") { $0 + $1.scripts } - } -} - -extension Array where Element == VectorElement { - - public func prerender(_ formula: Formula) throws { - try forEach { try $0.prerender(formula) } - } - - public func render(with manager: ContextManager) throws -> String { - return try self.reduce("") { try $0 + $1.render(with: manager) } - } - - public var scripts: AnyContent { - return self.reduce("") { $0 + $1.scripts } - } -} - -extension Bool: AnyContent { - - public func render(with manager: ContextManager) throws -> String { - return String(self) - } - - public func prerender(_ formula: Formula) throws { - formula.add(content: String(self)) - } - - public var renderWhenLocalizing: Bool { return false } -} - -extension Bool: Conditionable { - public func evaluate(with manager: ContextManager) throws -> Bool { - return self - } -} - -extension Double: AnyContent { - - public func render(with manager: ContextManager) throws -> String { - return String(self) - } - - public func prerender(_ formula: Formula) throws { - formula.add(content: String(self)) - } - - public var renderWhenLocalizing: Bool { return false } -} - -extension Float: AnyContent { - - public func render(with manager: ContextManager) throws -> String { - return String(self) - } - - public func prerender(_ formula: Formula) throws { - formula.add(content: String(self)) - } - - public var renderWhenLocalizing: Bool { return false } -} - -extension Int: AnyContent { - - public func render(with manager: ContextManager) throws -> String { - return String(self) - } - - public func prerender(_ formula: Formula) throws { - formula.add(content: String(self)) - } - - public var renderWhenLocalizing: Bool { return false } -} - -extension Optional: AnyContent where Wrapped: AnyContent { - - public func prerender(_ formula: Formula) throws { - switch self { - case .some(let wrapped): try wrapped.prerender(formula) - default: break - } - } - - public func render(with manager: ContextManager) throws -> String { - switch self { - case .none: return "" - case .some(let wrapped): return try wrapped.render(with: manager) - } - } - - public var scripts: AnyContent { - switch self { - case .none: return "" - case .some(let wrapped): return wrapped.scripts - } - } -} - -extension Optional: Defineable { - - var isDefinded: Bool { - switch self { - case .none: return false - default: return true - } - } -} - -extension String: AnyContent { - - public func render(with manager: ContextManager) throws -> String { - return self - } - - public func prerender(_ formula: Formula) throws { - formula.add(content: self) - } -} - -extension UUID: AnyContent { - - public func render(with manager: ContextManager) throws -> String { - return self.uuidString - } - - public func prerender(_ formula: Formula) throws { - formula.add(content: self.uuidString) - } -} - -extension Sequence { - - public func htmlForEach(@ContentBuilder content: (TemplateValue) -> AnyContent) -> AnyContent { - ForEach(in: .constant(self), content: content) - } -} +extension Date: Content {} diff --git a/Sources/HTMLKit/Framework/Core/Primitives/Attributes/AnyAttribute.swift b/Sources/HTMLKit/Framework/Core/Primitives/Attributes/Attribute.swift similarity index 66% rename from Sources/HTMLKit/Framework/Core/Primitives/Attributes/AnyAttribute.swift rename to Sources/HTMLKit/Framework/Core/Primitives/Attributes/Attribute.swift index 570d758e..22871d39 100644 --- a/Sources/HTMLKit/Framework/Core/Primitives/Attributes/AnyAttribute.swift +++ b/Sources/HTMLKit/Framework/Core/Primitives/Attributes/Attribute.swift @@ -8,13 +8,13 @@ import OrderedCollections /// A type that represents any html-attribute. /// /// A attribute is a modifier of a html-element. -public protocol AnyAttribute { +public protocol Attribute { /// The func adds func custom(key: String, value: Any) -> Self } -extension AnyAttribute where Self: ContentNode { +extension Attribute where Self: ContentNode { internal func mutate(key: String, value: Any) -> Self { @@ -28,7 +28,7 @@ extension AnyAttribute where Self: ContentNode { } } -extension AnyAttribute where Self: EmptyNode { +extension Attribute where Self: EmptyNode { internal func mutate(key: String, value: Any) -> Self { @@ -41,3 +41,17 @@ extension AnyAttribute where Self: EmptyNode { return .init(attributes: attributes) } } + +extension Attribute where Self: CustomNode { + + internal func mutate(key: String, value: Any) -> Self { + + guard var attributes = self.attributes else { + return .init(name: name, attributes: [key: value], content: content) + } + + attributes[key] = value + + return .init(name: name, attributes: attributes, content: content) + } +} diff --git a/Sources/HTMLKit/Framework/Core/Primitives/Elements/AnyElement.swift b/Sources/HTMLKit/Framework/Core/Primitives/Elements/AnyElement.swift deleted file mode 100644 index a64e26c6..00000000 --- a/Sources/HTMLKit/Framework/Core/Primitives/Elements/AnyElement.swift +++ /dev/null @@ -1,8 +0,0 @@ -/* - Abstract: - The file contains the default definition of an element. It defines which properties and methods an element should come with. - */ - -/// A type that represents any html-element. -public protocol AnyElement: AnyContent { -} diff --git a/Sources/HTMLKit/Framework/Core/Primitives/Elements/Element.swift b/Sources/HTMLKit/Framework/Core/Primitives/Elements/Element.swift new file mode 100644 index 00000000..bb2ee5c1 --- /dev/null +++ b/Sources/HTMLKit/Framework/Core/Primitives/Elements/Element.swift @@ -0,0 +1,23 @@ +/* + Abstract: + The file contains the default definition of an element. It defines which properties and methods an element should come with. + */ + +/// A type that represents any html-element. +public protocol Element: Content { +} + +extension Element { + + public func environment(key: KeyPath) -> EnvironmentModifier { + return .init(key: key, content: [self]) + } + + public func environment(key: KeyPath, value: V) -> EnvironmentModifier { + return .init(key: key, value: value, content: [self]) + } + + public func environment(object: T) -> EnvironmentModifier { + return .init(key: \T.self, value: object, content: [self]) + } +} diff --git a/Sources/HTMLKit/Framework/Core/Primitives/Elements/Elements.swift b/Sources/HTMLKit/Framework/Core/Primitives/Elements/Elements.swift index d62880fb..0235e492 100644 --- a/Sources/HTMLKit/Framework/Core/Primitives/Elements/Elements.swift +++ b/Sources/HTMLKit/Framework/Core/Primitives/Elements/Elements.swift @@ -3,64 +3,64 @@ The file contains the default definition of different elements. */ -public typealias GlobalElement = BodyElement & DescriptionElement & FigureElement & FormElement & BasicElement & HeadElement & ListElement & MapElement & MediaElement & ObjectElement & RubyElement & TableElement & HtmlElement & InputElement +public typealias GlobalElement = BodyElement & DescriptionElement & FigureElement & FormElement & BasicElement & HeadElement & ListElement & MapElement & MediaElement & ObjectElement & RubyElement & TableElement & HtmlElement & InputElement & VectorElement /// The protocol defines a body element. -public protocol BodyElement: AnyElement { +public protocol BodyElement: Element { } /// The protocol defines a description element. -public protocol DescriptionElement: AnyElement { +public protocol DescriptionElement: Element { } /// The protocol defines a figure element. -public protocol FigureElement: AnyElement { +public protocol FigureElement: Element { } /// The protocol defines a form element. -public protocol FormElement: AnyElement { +public protocol FormElement: Element { } /// The protocol defines a basic element. -public protocol BasicElement: AnyElement { +public protocol BasicElement: Element { } /// The protocol defines a head element. -public protocol HeadElement: AnyElement { +public protocol HeadElement: Element { } /// The protocol defines a input element./ -public protocol InputElement: AnyElement { +public protocol InputElement: Element { } /// The protocol defines a list element. -public protocol ListElement: AnyElement { +public protocol ListElement: Element { } /// The protocol defines a map element. -public protocol MapElement: AnyElement { +public protocol MapElement: Element { } /// The protocol defines a media element. -public protocol MediaElement: AnyElement { +public protocol MediaElement: Element { } /// The protocol defines a object element. -public protocol ObjectElement: AnyElement { +public protocol ObjectElement: Element { } /// The protocol defines a ruby element. -public protocol RubyElement: AnyElement { +public protocol RubyElement: Element { } /// The protocol defines a table element. -public protocol TableElement: AnyElement { +public protocol TableElement: Element { } /// The protocol defines a html element. -public protocol HtmlElement: AnyElement { +public protocol HtmlElement: Element { } /// The protocol defines a vector element. -public protocol VectorElement: AnyElement { +public protocol VectorElement: Element { } diff --git a/Sources/HTMLKit/Framework/Core/Primitives/Layouts/AnyLayout.swift b/Sources/HTMLKit/Framework/Core/Primitives/Layouts/AnyLayout.swift deleted file mode 100644 index 5ec83dc2..00000000 --- a/Sources/HTMLKit/Framework/Core/Primitives/Layouts/AnyLayout.swift +++ /dev/null @@ -1,25 +0,0 @@ -/* - Abstract: - The file contains the default definition of a layout. It defines which properties and methods a layout should come with. - */ - -import Foundation - -public protocol AnyLayout: AnyContent { - - /// The content of the page. - @ContentBuilder var body: AnyContent { get } -} - -extension AnyLayout { - - public func render(with manager: ContextManager) throws -> String { - try body.render(with: manager) - } - - public func prerender(_ formula: Formula) throws { - try body.prerender(formula) - } - - public var scripts: AnyContent { body.scripts } -} diff --git a/Sources/HTMLKit/Framework/Core/Primitives/Layouts/Layouts.swift b/Sources/HTMLKit/Framework/Core/Primitives/Layouts/Layouts.swift index e57a35c1..9055bd0c 100644 --- a/Sources/HTMLKit/Framework/Core/Primitives/Layouts/Layouts.swift +++ b/Sources/HTMLKit/Framework/Core/Primitives/Layouts/Layouts.swift @@ -3,14 +3,9 @@ The file contains the default definition of different types of layouts. */ -/// A type that defines a page layout. -public protocol Page: AnyLayout, GlobalElement { -} - /// A type that defines a view layout. -public protocol View: AnyLayout, GlobalElement { -} - -/// A type that defines a component layout. -public protocol Component: AnyLayout, GlobalElement { +public protocol View: GlobalElement { + + /// The content of the page. + @ContentBuilder var body: Content { get } } diff --git a/Sources/HTMLKit/Framework/Core/Primitives/Nodes/AnyNode.swift b/Sources/HTMLKit/Framework/Core/Primitives/Nodes/Node.swift similarity index 87% rename from Sources/HTMLKit/Framework/Core/Primitives/Nodes/AnyNode.swift rename to Sources/HTMLKit/Framework/Core/Primitives/Nodes/Node.swift index b1bd5606..773d621c 100644 --- a/Sources/HTMLKit/Framework/Core/Primitives/Nodes/AnyNode.swift +++ b/Sources/HTMLKit/Framework/Core/Primitives/Nodes/Node.swift @@ -4,5 +4,5 @@ */ /// A type that represents any html-node. -public protocol AnyNode { +public protocol Node { } diff --git a/Sources/HTMLKit/Framework/Core/Primitives/Nodes/Nodes.swift b/Sources/HTMLKit/Framework/Core/Primitives/Nodes/Nodes.swift index 4cd812e4..7b4c5744 100644 --- a/Sources/HTMLKit/Framework/Core/Primitives/Nodes/Nodes.swift +++ b/Sources/HTMLKit/Framework/Core/Primitives/Nodes/Nodes.swift @@ -6,7 +6,7 @@ import OrderedCollections /// A type that defines a node with content. -internal protocol ContentNode: AnyNode { +internal protocol ContentNode: Node { associatedtype Content @@ -54,280 +54,8 @@ extension ContentNode { } } -extension ContentNode where Content == AnyContent { - - internal func build(_ formula: Formula) throws { - - formula.add(content: startTag) - - try content.prerender(formula) - - formula.add(content: endTag) - } - - internal func build(with manager: ContextManager) throws -> String { - return try startTag + content.render(with: manager) + endTag - } -} - -extension ContentNode where Content == BodyElement { - - internal func build(_ formula: Formula) throws { - - formula.add(content: startTag) - - try content.prerender(formula) - - formula.add(content: endTag) - } - - internal func build(with manager: ContextManager) throws -> String { - return try startTag + content.render(with: manager) + endTag - } -} - -extension ContentNode where Content == DescriptionElement { - - internal func build(_ formula: Formula) throws { - - formula.add(content: startTag) - - try content.prerender(formula) - - formula.add(content: endTag) - } - - internal func build(with manager: ContextManager) throws -> String { - return try startTag + content.render(with: manager) + endTag - } -} - -extension ContentNode where Content == FigureElement { - - internal func build(_ formula: Formula) throws { - - formula.add(content: startTag) - - try content.prerender(formula) - - formula.add(content: endTag) - } - - internal func build(with manager: ContextManager) throws -> String { - return try startTag + content.render(with: manager) + endTag - } -} - -extension ContentNode where Content == FormElement { - - internal func build(_ formula: Formula) throws { - - formula.add(content: startTag) - - try content.prerender(formula) - - formula.add(content: endTag) - } - - internal func build(with manager: ContextManager) throws -> String { - return try startTag + content.render(with: manager) + endTag - } -} - -extension ContentNode where Content == BasicElement { - - internal func build(_ formula: Formula) throws { - - formula.add(content: startTag) - - try content.prerender(formula) - - formula.add(content: endTag) - } - - internal func build(with manager: ContextManager) throws -> String { - return try startTag + content.render(with: manager) + endTag - } -} - -extension ContentNode where Content == HeadElement { - - internal func build(_ formula: Formula) throws { - - formula.add(content: startTag) - - try content.prerender(formula) - - formula.add(content: endTag) - } - - internal func build(with manager: ContextManager) throws -> String { - return try startTag + content.render(with: manager) + endTag - } -} - -extension ContentNode where Content == InputElement { - - internal func build(_ formula: Formula) throws { - - formula.add(content: startTag) - - try content.prerender(formula) - - formula.add(content: endTag) - } - - internal func build(with manager: ContextManager) throws -> String { - return try startTag + content.render(with: manager) + endTag - } -} - -extension ContentNode where Content == ListElement { - - internal func build(_ formula: Formula) throws { - - formula.add(content: startTag) - - try content.prerender(formula) - - formula.add(content: endTag) - } - - internal func build(with manager: ContextManager) throws -> String { - return try startTag + content.render(with: manager) + endTag - } -} - -extension ContentNode where Content == MapElement { - - internal func build(_ formula: Formula) throws { - - formula.add(content: startTag) - - try content.prerender(formula) - - formula.add(content: endTag) - } - - internal func build(with manager: ContextManager) throws -> String { - return try startTag + content.render(with: manager) + endTag - } -} - -extension ContentNode where Content == MediaElement { - - internal func build(_ formula: Formula) throws { - - formula.add(content: startTag) - - try content.prerender(formula) - - formula.add(content: endTag) - } - - internal func build(with manager: ContextManager) throws -> String { - return try startTag + content.render(with: manager) + endTag - } -} - -extension ContentNode where Content == ObjectElement { - - internal func build(_ formula: Formula) throws { - - formula.add(content: startTag) - - try content.prerender(formula) - - formula.add(content: endTag) - } - - internal func build(with manager: ContextManager) throws -> String { - return try startTag + content.render(with: manager) + endTag - } -} - -extension ContentNode where Content == RubyElement { - - internal func build(_ formula: Formula) throws { - - formula.add(content: startTag) - - try content.prerender(formula) - - formula.add(content: endTag) - } - - internal func build(with manager: ContextManager) throws -> String { - return try startTag + content.render(with: manager) + endTag - } -} - -extension ContentNode where Content == TableElement { - - internal func build(_ formula: Formula) throws { - - formula.add(content: startTag) - - try content.prerender(formula) - - formula.add(content: endTag) - } - - internal func build(with manager: ContextManager) throws -> String { - return try startTag + content.render(with: manager) + endTag - } -} - -extension ContentNode where Content == HtmlElement { - - internal func build(_ formula: Formula) throws { - - formula.add(content: startTag) - - try content.prerender(formula) - - formula.add(content: endTag) - } - - internal func build(with manager: ContextManager) throws -> String { - return try startTag + content.render(with: manager) + endTag - } -} - -extension ContentNode where Content == VectorElement { - - internal func build(_ formula: Formula) throws { - - formula.add(content: startTag) - - try content.prerender(formula) - - formula.add(content: endTag) - } - - internal func build(with manager: ContextManager) throws -> String { - return try startTag + content.render(with: manager) + endTag - } -} - -extension ContentNode where Content == String { - - internal func build(_ formula: Formula) throws { - - formula.add(content: startTag) - - try content.prerender(formula) - - formula.add(content: endTag) - } - - internal func build(with manager: ContextManager) throws -> String { - return try startTag + content.render(with: manager) + endTag - } -} - /// A type that defines a node without any content. -internal protocol EmptyNode: AnyNode { +internal protocol EmptyNode: Node { /// The name of the node. var name: String { get } @@ -353,14 +81,6 @@ extension EmptyNode { return "<\(name) \(attributes.map { "\($0.key)=\"\($0.value)\"" }.joined(separator: " "))>" } - internal func build(_ formula: Formula) throws { - formula.add(content: startTag) - } - - internal func build(with manager: ContextManager) throws -> String { - return startTag - } - internal func modify(_ element: Self) -> Self { guard var attributes = self.attributes else { @@ -374,7 +94,7 @@ extension EmptyNode { } /// A type that defines a comment node. -internal protocol CommentNode: AnyNode { +internal protocol CommentNode: Node { /// The content of the node. var content: String { get } @@ -389,21 +109,10 @@ extension CommentNode { internal var endTag: String { return "-->" } - - internal func build(_ formula: Formula) throws { - - formula.add(content: startTag) - formula.add(content: content) - formula.add(content: endTag) - } - - internal func build(with manager: ContextManager) throws -> String { - return try startTag + content.render(with: manager) + endTag - } } /// The protocol defines the document node. -internal protocol DocumentNode: AnyNode { +internal protocol DocumentNode: Node { /// The content of the node. var content: String { get } @@ -414,12 +123,52 @@ extension DocumentNode { internal var startTag: String { return "" } +} + +public protocol CustomNode: Node { + + associatedtype Content - internal func build(_ formula: Formula) throws { - formula.add(content: startTag) - } + /// The name of the node. + var name: String { get set } + + /// The attributes of the node. + var attributes: OrderedDictionary? { get } + + /// The content of the node. + var content: [Content] { get } + + /// Initiates a node. + /// + /// - Parameters: + /// - attributes: + /// - content: + init(name: String, attributes: OrderedDictionary?, content: [Content]) +} - internal func build(with manager: ContextManager) throws -> String { - return startTag +extension CustomNode { + + internal var startTag: String { + + guard let attributes = attributes else { + return "<\(name)>" + } + + return "<\(name) \(attributes.map { "\($0.key)=\"\($0.value)\"" }.joined(separator: " "))>" + } + + internal var endTag: String { + return "" + } + + internal func modify(_ element: Self) -> Self { + + guard var attributes = self.attributes else { + return .init(name: element.name, attributes: element.attributes, content: self.content) + } + + attributes.merge(element.attributes!) { (_, new) in new } + + return .init(name: element.name, attributes: attributes, content: self.content) } } diff --git a/Sources/HTMLKit/Framework/Core/Primitives/Shared/AnyContent.swift b/Sources/HTMLKit/Framework/Core/Primitives/Shared/AnyContent.swift deleted file mode 100644 index 48e2d9f6..00000000 --- a/Sources/HTMLKit/Framework/Core/Primitives/Shared/AnyContent.swift +++ /dev/null @@ -1,54 +0,0 @@ -/* - Abstract: - The file contains the default definition of the content. It defines which properties and methods a content should come with. - */ - -import Foundation - -/// A type that represents any html-content. -public protocol AnyContent { - - var renderWhenLocalizing: Bool { get } - - var scripts: AnyContent { get } - - func render(with manager: ContextManager) throws -> String - - func prerender(_ formula: Formula) throws -} - -extension AnyContent { - - public var renderWhenLocalizing: Bool { return true } - - public var scripts: AnyContent { "" } - - public func environment(locale: String) -> EnvironmentModifier { - return EnvironmentModifier(view: self, locale: locale) - } - - public func environment(locale: TemplateValue) -> EnvironmentModifier { - return EnvironmentModifier(view: self, locale: locale) - } -} - -public func + (lhs: AnyContent, rhs: AnyContent) -> AnyContent { - var output: Array = [] - - if let list = lhs as? Array { - output.append(contentsOf: list) - } else { - output.append(lhs) - } - - if let list = rhs as? Array { - output.append(list) - } else { - output.append(rhs) - } - return output -} - -public func +=(lhs: inout AnyContent, rhs: AnyContent) { - lhs = lhs + rhs -} diff --git a/Sources/HTMLKit/Framework/Core/Primitives/Shared/Content.swift b/Sources/HTMLKit/Framework/Core/Primitives/Shared/Content.swift new file mode 100644 index 00000000..fab256ef --- /dev/null +++ b/Sources/HTMLKit/Framework/Core/Primitives/Shared/Content.swift @@ -0,0 +1,9 @@ +/* + Abstract: + The file contains the default definition of the content. It defines which properties and methods a content should come with. + */ + +import Foundation + +/// A type that represents any html-content. +public protocol Content {} diff --git a/Sources/HTMLKit/Framework/Core/Primitives/Shared/Defineable.swift b/Sources/HTMLKit/Framework/Core/Primitives/Shared/Defineable.swift deleted file mode 100644 index 075b811b..00000000 --- a/Sources/HTMLKit/Framework/Core/Primitives/Shared/Defineable.swift +++ /dev/null @@ -1,5 +0,0 @@ -/// The protocol defines -protocol Defineable { - - var isDefinded: Bool { get } -} diff --git a/Sources/HTMLKit/Framework/Core/Primitives/Statements/Conditionable.swift b/Sources/HTMLKit/Framework/Core/Primitives/Statements/Conditionable.swift deleted file mode 100644 index db36336c..00000000 --- a/Sources/HTMLKit/Framework/Core/Primitives/Statements/Conditionable.swift +++ /dev/null @@ -1,21 +0,0 @@ -/* - Abstract: - The file contains the default definition of a condition. It defines which properties and methods a condition should come with. - */ - -/// The protocol defines -public protocol Conditionable: AnyContent { - - func evaluate(with manager: ContextManager) throws -> Bool -} - -extension Conditionable { - - public func render(with manager: ContextManager) throws -> String { - try evaluate(with: manager).render(with: manager) - } - - public func prerender(_ formula: Formula) throws { - formula.add(content: self) - } -} diff --git a/Sources/HTMLKit/Framework/Core/Primitives/Statements/Conditions.swift b/Sources/HTMLKit/Framework/Core/Primitives/Statements/Conditions.swift deleted file mode 100644 index 5d597288..00000000 --- a/Sources/HTMLKit/Framework/Core/Primitives/Statements/Conditions.swift +++ /dev/null @@ -1,259 +0,0 @@ -/* - Abstract: - The file contains the conditions. - - Markings: - - Equal - - NotEqual - - LessThan - - LessThanOrEqual - - GreaterThan - - GreaterThanOrEqual - - Between - - And - - Or - */ - -/// A condition that evaluates an equal expression between a variable and a constant value -internal struct EqualCondition: Conditionable { - - private let lhs: TemplateValue - - private let rhs: Value - - internal init(lhs: TemplateValue, rhs: Value) { - - self.lhs = lhs - self.rhs = rhs - } - - internal func evaluate(with manager: ContextManager) throws -> Bool { - return try lhs.value(from: manager) == rhs - } -} - -/// A condition that evaluates an not equal expression between a variable and a constant value -internal struct NotEqualCondition: Conditionable { - - private let lhs: TemplateValue - - private let rhs: Value - - internal init(lhs: TemplateValue, rhs: Value) { - - self.lhs = lhs - self.rhs = rhs - } - - internal func evaluate(with manager: ContextManager) throws -> Bool { - return try lhs.value(from: manager) != rhs - } -} - -/// A condition that evaluates a less than expression between a variable and a constant value -internal struct LessThanCondition: Conditionable { - - private let lhs: TemplateValue - - private let rhs: Value - - internal init(lhs: TemplateValue, rhs: Value) { - - self.lhs = lhs - self.rhs = rhs - } - - internal func evaluate(with manager: ContextManager) throws -> Bool { - return try lhs.value(from: manager) < rhs - } -} - -/// A condition that evaluates a greater than expression between a variable and a constant value -internal struct GreaterThanCondition: Conditionable { - - private let lhs: TemplateValue - - private let rhs: Value - - internal init(lhs: TemplateValue, rhs: Value) { - - self.lhs = lhs - self.rhs = rhs - } - - internal func evaluate(with manager: ContextManager) throws -> Bool { - return try lhs.value(from: manager) > rhs - } -} - -/// A condition... -internal struct BetweenCondition: Conditionable { - - private let lhs: TemplateValue - - private let rhs: ClosedRange - - internal init(lhs: TemplateValue, rhs: ClosedRange) { - - self.lhs = lhs - self.rhs = rhs - } - - internal init(lhs: TemplateValue, rhs: Range) { - - self.lhs = lhs - self.rhs = rhs.lowerBound...rhs.upperBound - } - - internal func evaluate(with manager: ContextManager) throws -> Bool { - return try rhs ~= lhs.value(from: manager) - } -} - -/// A condition that is always true -internal struct AlwaysTrueCondition: Conditionable { - - internal init() {} - - internal func evaluate(with manager: ContextManager) throws -> Bool { - return true - } -} - -/// A condition... -internal struct NotNullCondition: Conditionable { - - private let lhs: TemplateValue - - internal init(lhs: TemplateValue) { - - self.lhs = lhs - } - - internal func evaluate(with manager: ContextManager) throws -> Bool { - return try lhs.value(from: manager) != nil - } -} - -/// A condition... -internal struct NotNullConditionGeneral: Conditionable { - - private let lhs: TemplateValue - - internal init(lhs: TemplateValue) { - - self.lhs = lhs - } - - internal func evaluate(with manager: ContextManager) throws -> Bool { - - if let value = try lhs.value(from: manager) as? Defineable { - return value.isDefinded - - } else { - return true - } - } -} - -/// A condition... -internal struct IsNullCondition: Conditionable { - - private let lhs: TemplateValue - - internal init(lhs: TemplateValue) { - - self.lhs = lhs - } - - internal func evaluate(with manager: ContextManager) throws -> Bool { - return try lhs.value(from: manager) == nil - } -} - -/// A condition... -internal struct IsNullConditionGeneral: Conditionable { - - private let lhs: TemplateValue - - internal init(lhs: TemplateValue) { - - self.lhs = lhs - } - - internal func evaluate(with manager: ContextManager) throws -> Bool { - - if let value = try lhs.value(from: manager) as? Defineable { - return value.isDefinded == false - - } else { - return false - } - } -} - -/// A condition... -internal struct InvertCondition: Conditionable { - - private let lhs: Conditionable - - internal init(lhs: Conditionable) { - - self.lhs = lhs - } - - internal func evaluate(with manager: ContextManager) throws -> Bool { - return try !lhs.evaluate(with: manager) - } -} - -/// A condition... -internal struct AndCondition: Conditionable { - - private let lhs: Conditionable - - private let rhs: Conditionable - - internal init(lhs: Conditionable, rhs: Conditionable) { - - self.lhs = lhs - self.rhs = rhs - } - - internal func evaluate(with manager: ContextManager) throws -> Bool { - return try lhs.evaluate(with: manager) && rhs.evaluate(with: manager) - } -} - -/// A condition... -internal struct OrCondition: Conditionable { - - private let lhs: Conditionable - - private let rhs: Conditionable - - internal init(lhs: Conditionable, rhs: Conditionable) { - - self.lhs = lhs - self.rhs = rhs - } - - internal func evaluate(with manager: ContextManager) throws -> Bool { - return try lhs.evaluate(with: manager) || rhs.evaluate(with: manager) - } -} - -/// The operator -public func && (lhs: Conditionable, rhs: Conditionable) -> Conditionable { - return AndCondition(lhs: lhs, rhs: rhs) -} - -/// The operator -public func || (lhs: Conditionable, rhs: Conditionable) -> Conditionable { - return OrCondition(lhs: lhs, rhs: rhs) -} - -/// The operator to invert a condition -public prefix func ! (condition: Conditionable) -> Conditionable { - return InvertCondition(lhs: condition) -} diff --git a/Sources/HTMLKit/Framework/Environment/Annotations/ContextManager.swift b/Sources/HTMLKit/Framework/Environment/Annotations/ContextManager.swift deleted file mode 100644 index b7655c07..00000000 --- a/Sources/HTMLKit/Framework/Environment/Annotations/ContextManager.swift +++ /dev/null @@ -1,85 +0,0 @@ -/* - Abstract: - The file contains the context manager. - */ - -import Foundation -import Lingo - -public class ContextManager { - - public enum Errors: LocalizedError { - - case unableToRetrieveValue - case unableToCastVariable - - public var errorDescription: String? { - - switch self { - case .unableToRetrieveValue: - return "Unable to retrieve the wanted value in the context" - - case .unableToCastVariable: - return "Unable to cast value when retrieving variable" - } - } - - public var failureReason: String? { - return self.errorDescription ?? "" - } - - public var recoverySuggestion: String? { - - switch self { - default: - return nil - } - } - } - - public let lingo: Lingo? - public var locale: String? - public var contexts: [String: Any] - - @available(*, deprecated, message: "Use init(context:, lingo:) instead.") - public init(rootContext: Context, lingo: Lingo? = nil) { - - self.contexts = ["": rootContext] - self.lingo = lingo - self.locale = nil - } - - public init(context: Context, lingo: Lingo? = nil) { - - self.contexts = ["": context] - self.lingo = lingo - self.locale = nil - } - - public init(contexts: [String: Any], lingo: Lingo? = nil) { - - self.contexts = contexts - self.lingo = lingo - self.locale = nil - } - - public func value(for variable: HTMLContext) throws -> T { - - if let context = contexts[variable.rootId] { - - if let value = context[keyPath: variable.keyPath] as? T { - return value - - } else { - throw Errors.unableToCastVariable - } - - } else { - throw Errors.unableToRetrieveValue - } - } - - public func set(_ context: T, for variable: HTMLContext) { - self.contexts[variable.rootId] = context - } -} diff --git a/Sources/HTMLKit/Framework/Environment/Annotations/DateVariable.swift b/Sources/HTMLKit/Framework/Environment/Annotations/DateVariable.swift deleted file mode 100644 index 4aab49ce..00000000 --- a/Sources/HTMLKit/Framework/Environment/Annotations/DateVariable.swift +++ /dev/null @@ -1,84 +0,0 @@ -/* - Abstract: - The file contains a type for a datetime variable. - */ - -import Foundation - -/// A struct that renders a data in a specified format -/// -/// -public struct DateVariable: AnyContent { - - public enum Errors: LocalizedError { - - case unableToCopyFormatter - - public var errorDescription: String? { - return "Unable to copy the DateFormatter when rendering a date with a locale" - } - } - - public enum Reference { - - case solid(TemplateValue) - case optional(TemplateValue) - } - - public enum Format { - - case style(Style) - case literal(String) - - public struct Style { - - let dateStyle: DateFormatter.Style - let timeStyle: DateFormatter.Style - } - } - - public let dateReference: Reference - - public var format: Format - - public func render(with manager: ContextManager) throws -> String { - - var optionalDate: Date? - - switch dateReference { - case .solid(let path): - - optionalDate = try path.value(from: manager) - - case .optional(let path): - - optionalDate = try path.value(from: manager) - } - - guard let date = optionalDate else { return "" } - - let formatter = DateFormatter() - - if let locale = manager.locale { - - formatter.locale = .init(identifier: locale) - } - - switch format { - case .literal(let format): - - formatter.dateFormat = format - - case .style(let style): - - formatter.dateStyle = style.dateStyle - formatter.timeStyle = style.timeStyle - } - - return formatter.string(from: date) - } - - public func prerender(_ formula: Formula) throws { - formula.add(content: self) - } -} diff --git a/Sources/HTMLKit/Framework/Environment/Annotations/EscapingOption.swift b/Sources/HTMLKit/Framework/Environment/Annotations/EscapingOption.swift deleted file mode 100644 index c0cccbc9..00000000 --- a/Sources/HTMLKit/Framework/Environment/Annotations/EscapingOption.swift +++ /dev/null @@ -1,24 +0,0 @@ -/* - Abstract: - The file contains the escaping option. - */ - -/// The enum is for -/// -/// -public enum EscapingOption: CustomDebugStringConvertible { - - case unsafeNone - case safeHTML - - public var debugDescription: String { - - switch self { - case .unsafeNone: - return "Unsafe" - - case .safeHTML: - return "Safe" - } - } -} diff --git a/Sources/HTMLKit/Framework/Environment/Annotations/HTMLContext.swift b/Sources/HTMLKit/Framework/Environment/Annotations/HTMLContext.swift deleted file mode 100644 index 42b907c5..00000000 --- a/Sources/HTMLKit/Framework/Environment/Annotations/HTMLContext.swift +++ /dev/null @@ -1,121 +0,0 @@ -/* - Abstract: - The file contains the html context. - */ - -/// The class is for -@propertyWrapper @dynamicMemberLookup public class HTMLContext { - - internal let pathId: String - - internal let rootId: String - - internal let escaping: EscapingOption - - internal let isMasqueradingOptional: Bool - - internal let keyPath: AnyKeyPath - - public var wrappedValue: HTMLContext { self } - - public init(keyPath: KeyPath, pathId: String, rootId: String = "", escaping: EscapingOption = .safeHTML, isMasqueradingOptional: Bool = false) { - - self.keyPath = keyPath - self.pathId = pathId - self.rootId = rootId - self.escaping = escaping - self.isMasqueradingOptional = isMasqueradingOptional - } - - public init(keyPath: AnyKeyPath, pathId: String, rootId: String = "", escaping: EscapingOption = .safeHTML, isMasqueradingOptional: Bool = false) { - - self.keyPath = keyPath - self.pathId = pathId - self.rootId = rootId - self.escaping = escaping - self.isMasqueradingOptional = isMasqueradingOptional - } - - public init(_ value: Value.Type, pathId: String = "", rootId: String = "", escaping: EscapingOption = .safeHTML, isMasqueradingOptional: Bool = false) { - - self.keyPath = \Value.self - self.pathId = pathId - self.rootId = rootId - self.escaping = escaping - self.isMasqueradingOptional = isMasqueradingOptional - } - - public subscript(dynamicMember keyPath: KeyPath) -> HTMLContext { - - guard let newPath = self.keyPath.appending(path: keyPath) else { - fatalError() - } - - return .init(keyPath: newPath, pathId: pathId + "-" + String(reflecting: Subject.self), rootId: rootId, isMasqueradingOptional: isMasqueradingOptional) - } - - public func makeOptional() -> HTMLContext { - return .init(keyPath: keyPath, pathId: pathId, rootId: rootId, escaping: escaping, isMasqueradingOptional: true) - } - - public func escaping(_ option: EscapingOption) -> HTMLContext { - return .init(keyPath: keyPath, pathId: pathId, rootId: rootId, escaping: option, isMasqueradingOptional: isMasqueradingOptional) - } - - public func unsafeCast(to type: T.Type) -> HTMLContext { - return .init(keyPath: keyPath, pathId: pathId, rootId: rootId, escaping: escaping, isMasqueradingOptional: isMasqueradingOptional) - } -} - -extension HTMLContext: AnyContent where Value: AnyContent { - - public func render(with manager: ContextManager) throws -> String { - return applyEscaping( - try manager.value(for: self).render(with: manager) - ) - } - - public func prerender(_ formula: Formula) throws { - formula.add(content: self) - } - - internal func applyEscaping(_ render: String) -> String { - - switch escaping { - case .safeHTML: - - return render.reduce(into: "") { (result, char) in - - switch char { - case "&": - return result += "&" - - case "<": - return result += "<" - - case ">": - return result += ">" - - case "\"": - return result += """ - - case "'": - return result += "'" - - default: - return result += String(char) - } - } - - case .unsafeNone: - return render - } - } -} - -extension HTMLContext: Conditionable where Value == Bool { - - public func evaluate(with manager: ContextManager) throws -> Bool { - return try manager.value(for: self) - } -} diff --git a/Sources/HTMLKit/Framework/Environment/Annotations/TemplateValue.swift b/Sources/HTMLKit/Framework/Environment/Annotations/TemplateValue.swift deleted file mode 100644 index 467d8ea7..00000000 --- a/Sources/HTMLKit/Framework/Environment/Annotations/TemplateValue.swift +++ /dev/null @@ -1,265 +0,0 @@ -/* - Abstract: - The file contains the template value. - */ - -import Foundation - -/// The enum is for -@propertyWrapper @dynamicMemberLookup public enum TemplateValue { - - case constant(Value) - case dynamic(HTMLContext) - - public var wrappedValue: TemplateValue { - - get { self } - set { self = newValue } - } - - public var rawValue: String { - - get { - switch self { - case .constant(let value): - return "\(value)" - - default: - return "" - } - } - } - - internal var isMasqueradingOptional: Bool { - - switch self { - case .constant: - return false - - case .dynamic(let variable): - return variable.isMasqueradingOptional - } - } - - public var isDefined: Conditionable { - - if isMasqueradingOptional { - return true - - } else { - return NotNullConditionGeneral(lhs: self) - } - } - - public var isNotDefined: Conditionable { - - if isMasqueradingOptional { - return false - - } else { - return IsNullConditionGeneral(lhs: self) - } - } - - public init(_ value: Value.Type) { - self = .dynamic(HTMLContext(value.self)) - } - - public subscript(dynamicMember keyPath: KeyPath) -> TemplateValue { - - switch self { - case .constant(let value): - return .constant(value[keyPath: keyPath]) - - case .dynamic(let variable): - return .dynamic(variable[dynamicMember: keyPath]) - } - } - - public func value(at keyPath: KeyPath) -> TemplateValue { - return self[dynamicMember: keyPath] - } - - public func value(from manager: ContextManager) throws -> Value { - - switch self { - case .constant(let value): - return value - - case .dynamic(let variable): - return try manager.value(for: variable) - } - } - - public func makeOptional() -> TemplateValue { - - switch self { - case .constant(let value): - return .constant(value) - - case .dynamic(let variable): - return .dynamic(variable.makeOptional()) - } - } - - public func escaping(_ option: EscapingOption) -> TemplateValue { - - switch self { - case .dynamic(let variable): - return .dynamic(variable.escaping(option)) - - default: - return self - } - } - - public func unsafeCast(to type: T.Type) -> TemplateValue { - - switch self { - case .constant(let value): - return .constant(value as! T) - - case .dynamic(let variable): - return .dynamic(variable.unsafeCast(to: T.self)) - } - } -} - -extension TemplateValue: AnyContent where Value: AnyContent { - - public func prerender(_ formula: Formula) throws { - - switch self { - case .constant(let value): - try value.prerender(formula) - - case .dynamic(let variable): - try variable.prerender(formula) - } - } - - public func render(with manager: ContextManager) throws -> String { - - switch self { - case .constant(let value): - return try value.render(with: manager) - - case .dynamic(let variable): - return try variable.render(with: manager) - } - } -} - -extension TemplateValue: ExpressibleByStringLiteral, ExpressibleByUnicodeScalarLiteral, ExpressibleByExtendedGraphemeClusterLiteral where Value == String { - - public init(stringLiteral value: String) { - self = .constant(value) - } - - public init(unicodeScalarLiteral value: String) { - self = .constant(value) - } - - public init(extendedGraphemeClusterLiteral value: String) { - self = .constant(value) - } -} - -extension TemplateValue: ExpressibleByIntegerLiteral where Value == Int { - - public init(integerLiteral value: Int) { - self = .constant(value) - } -} - -extension TemplateValue where Value: Sequence { - - func forEach(@ContentBuilder content: (TemplateValue) -> AnyContent) -> AnyContent { - ForEach(in: self, content: content) - } -} - -extension TemplateValue: Conditionable where Value == Bool { - - public func evaluate(with manager: ContextManager) throws -> Bool { - - switch self { - case .constant(let value): - return value - - case .dynamic(let variable): - return try manager.value(for: variable) - } - } -} - -extension TemplateValue where Value == Date { - - public func style(date: DateFormatter.Style = .short, time: DateFormatter.Style = .short) -> AnyContent { - return DateVariable(dateReference: .solid(self), format: .style(.init(dateStyle: date, timeStyle: time))) - } - - public func formatted(string format: String) -> AnyContent { - return DateVariable(dateReference: .solid(self), format: .literal(format)) - } -} - -extension TemplateValue where Value == Date? { - - public func style(date: DateFormatter.Style = .short, time: DateFormatter.Style = .short) -> AnyContent { - return DateVariable(dateReference: .optional(self), format: .style(.init(dateStyle: date, timeStyle: time))) - } - - public func formatted(string format: String) -> AnyContent { - return DateVariable(dateReference: .optional(self), format: .literal(format)) - } -} - -extension TemplateValue where Value: Equatable { - - /// The operator for a equal condition - public static func ==(lhs: TemplateValue, rhs: Value) -> Conditionable { - return EqualCondition(lhs: lhs, rhs: rhs) - } - - /// The operator for a not-equal condition - public static func !=(lhs: TemplateValue, rhs: Value) -> Conditionable { - return NotEqualCondition(lhs: lhs, rhs: rhs) - } -} - -extension TemplateValue where Value: Comparable { - - /// The operator for a less-than condition - public static func <(lhs: TemplateValue, rhs: Value) -> Conditionable { - return LessThanCondition(lhs: lhs, rhs: rhs) - } - - /// The operator for a less-than-or-equal condition - public static func <=(lhs: TemplateValue, rhs: Value) -> Conditionable { - return InvertCondition(lhs: GreaterThanCondition(lhs: lhs, rhs: rhs)) - } - - /// The operator for a greater-than condition - public static func >(lhs: TemplateValue, rhs: Value) -> Conditionable { - return GreaterThanCondition(lhs: lhs, rhs: rhs) - } - - /// The operator for a greater-than-or-equal condition - public static func >=(lhs: TemplateValue, rhs: Value) -> Conditionable { - return InvertCondition(lhs: LessThanCondition(lhs: lhs, rhs: rhs)) - } -} - -extension TemplateValue where Value: Strideable { - - /// The operator for a range condition - public static func ~=(lhs: TemplateValue, rhs: Range) -> Conditionable { - return BetweenCondition(lhs: lhs, rhs: rhs) - } - - /// The operator for a range condition - public static func ~=(lhs: TemplateValue, rhs: ClosedRange) -> Conditionable { - return BetweenCondition(lhs: lhs, rhs: rhs) - } -} diff --git a/Sources/HTMLKit/Framework/Environment/Localization/EnvironmentModifier.swift b/Sources/HTMLKit/Framework/Environment/Localization/EnvironmentModifier.swift deleted file mode 100644 index eda3f1ca..00000000 --- a/Sources/HTMLKit/Framework/Environment/Localization/EnvironmentModifier.swift +++ /dev/null @@ -1,37 +0,0 @@ -/* - Abstract: - The file contains the environment modifier. - */ - -/// The modifier is for -/// -/// -public struct EnvironmentModifier: GlobalElement { - - public let view: AnyContent - - public let locale: AnyContent - - public let localFormula = Formula() - - public func prerender(_ formula: Formula) throws { - - try view.prerender(localFormula) - - formula.add(content: self) - } - - public func render(with manager: ContextManager) throws -> String { - - let prevLocale = manager.locale - - manager.locale = try locale.render(with: manager) - - let rendering = try localFormula.render(with: manager) - - manager.locale = prevLocale - - return rendering - - } -} diff --git a/Sources/HTMLKit/Framework/Environment/Localization/Localizable.swift b/Sources/HTMLKit/Framework/Environment/Localization/Localizable.swift index 6ca7eaeb..5f24918d 100644 --- a/Sources/HTMLKit/Framework/Environment/Localization/Localizable.swift +++ b/Sources/HTMLKit/Framework/Environment/Localization/Localizable.swift @@ -8,12 +8,12 @@ public protocol Localizable { init(_ localizedKey: String) - init(_ localizedKey: String, with context: TemplateValue) where B: Encodable + init(_ localizedKey: String, with context: some Encodable) } extension Localizable { - public init(_ localizedKey: String, with context: T) where T: Encodable { - self.init(localizedKey, with: TemplateValue.constant(context)) + public init(_ localizedKey: String, with context: some Encodable) { + self.init(localizedKey, with: context) } } diff --git a/Sources/HTMLKit/Framework/Environment/Localization/Localization.swift b/Sources/HTMLKit/Framework/Environment/Localization/Localization.swift deleted file mode 100644 index 51ef68d7..00000000 --- a/Sources/HTMLKit/Framework/Environment/Localization/Localization.swift +++ /dev/null @@ -1,30 +0,0 @@ -/* - Abstract: - The file contains the localization. - */ - -public class Localization { - - public enum Locale: String { - - case arabic = "ar" - case english = "en" - case french = "fr" - case german = "de" - case hindi = "es" - case bengali = "bn" - case russian = "ru" - case portuguese = "pt" - case indonesian = "id" - } - - internal let source: String - - internal let locale: Locale - - public init(source: String, locale: Locale) { - - self.source = source - self.locale = locale - } -} diff --git a/Sources/HTMLKit/Framework/Environment/Localization/Localized.swift b/Sources/HTMLKit/Framework/Environment/Localization/Localized.swift deleted file mode 100644 index 159e025b..00000000 --- a/Sources/HTMLKit/Framework/Environment/Localization/Localized.swift +++ /dev/null @@ -1,65 +0,0 @@ -/* - Abstract: - The file contains the localized. - */ - -import Foundation - -/// The struct ist for -public struct NoData: Encodable {} - -/// The struct ist for -public struct Localized: AnyContent where B: Encodable { - - public enum Errors: Error { - case missingLingoConfig - } - - public let key: String - - public let context: TemplateValue? - - public init(key: String, context: TemplateValue) { - self.key = key - self.context = context - } - - public func prerender(_ formula: Formula) throws { - formula.add(content: self) - } - - public func render(with manager: ContextManager) throws -> String { - - guard let lingo = manager.lingo else { - throw Errors.missingLingoConfig - } - - let locale = manager.locale ?? lingo.defaultLocale - - if let value = try context?.value(from: manager) { - - guard let data = try? JSONEncoder().encode(value) else { - - print("-- ERROR: Not able to encode content when localizing \(key), in \(locale), with content: \(String(describing: context)).") - - return "" - } - - let dict = (try? JSONSerialization.jsonObject(with: data, options: .allowFragments)).flatMap { $0 as? [String: Any] } - - return lingo.localize(key, locale: locale, interpolations: dict) - - } else { - - return lingo.localize(key, locale: locale) - } - } -} - -extension Localized where B == NoData { - - public init(key: String) { - self.key = key - self.context = nil - } -} diff --git a/Sources/HTMLKit/Framework/Environment/Localization/LocalizedStringKey.swift b/Sources/HTMLKit/Framework/Environment/Localization/LocalizedStringKey.swift new file mode 100644 index 00000000..a5f4de87 --- /dev/null +++ b/Sources/HTMLKit/Framework/Environment/Localization/LocalizedStringKey.swift @@ -0,0 +1,21 @@ +/* + Abstract: + The file contains the localized. + */ + +import Foundation + +/// The struct thats contains the information for the localization +public struct LocalizedStringKey: Content { + + public let key: String + + public let context: Encodable? + + /// Initiates a localized string key with a context + public init(key: String, context: Encodable? = nil) { + + self.key = key + self.context = context + } +} diff --git a/Sources/HTMLKit/Framework/Environment/Statements/BranchStatements.swift b/Sources/HTMLKit/Framework/Environment/Statements/BranchStatements.swift deleted file mode 100644 index 34e7b7d9..00000000 --- a/Sources/HTMLKit/Framework/Environment/Statements/BranchStatements.swift +++ /dev/null @@ -1,144 +0,0 @@ -/* - Abstract: - The file contains the branch statements. - - Markings: - - If - */ - -/// The statement is for -public struct IF: GlobalElement { - - internal class Condition { - - internal let condition: Conditionable - - internal var content: AnyContent - - internal init(condition: Conditionable) { - - self.condition = condition - self.content = "" - } - } - - internal let conditions: [Condition] - - internal init(conditions: [Condition]) { - self.conditions = conditions - } - - public init(_ condition: Conditionable, @ContentBuilder content: () -> AnyContent) { - - let condition = Condition(condition: condition) - condition.content = content() - - self.conditions = [condition] - } - - public func elseIf(_ condition: Conditionable, @ContentBuilder content: () -> AnyContent) -> IF { - - let condition = Condition(condition: condition) - condition.content = content() - - return .init(conditions: conditions + [condition]) - } - - public func elseIf(isNil path: TemplateValue, @ContentBuilder content: () -> AnyContent) -> IF { - - let condition = Condition(condition: IsNullCondition(lhs: path)) - condition.content = content() - - return .init(conditions: conditions + [condition]) - } - - public func elseIf(isNotNil path: TemplateValue, @ContentBuilder content: () -> AnyContent) -> IF { - - let condition = Condition(condition: NotNullCondition(lhs: path)) - condition.content = content() - - return .init(conditions: conditions + [condition]) - } - - public func `else`(@ContentBuilder content: () -> AnyContent) -> IF { - - let condition = Condition(condition: AlwaysTrueCondition()) - condition.content = content() - - return .init(conditions: conditions + [condition]) - } -} - -extension IF: AnyContent { - - public var scripts: AnyContent { - - IF(conditions: conditions.map { htmlCondition in - - let scriptCondition = IF.Condition(condition: htmlCondition.condition) - scriptCondition.content = htmlCondition.content.scripts - - return scriptCondition - }) - } - - public func prerender(_ formula: Formula) throws { - - var isStaticallyEvaluated = true - - for condition in conditions { - - do { - - guard isStaticallyEvaluated else { - break - } - - if try condition.condition.evaluate(with: ContextManager(contexts: [:])) { - - try condition.content.prerender(formula) - - break - } - - } catch { - isStaticallyEvaluated = false - } - } - - if isStaticallyEvaluated == false { - formula.add(content: self) - } - } - - public func render(with manager: ContextManager) throws -> String { - - for condition in conditions { - - if try condition.evaluate(with: manager) { - return try condition.render(with: manager) - } - } - - return "" - } -} - -extension IF.Condition: AnyContent { - - public func prerender(_ formula: Formula) throws { - try content.prerender(formula) - } - - public func render(with manager: ContextManager) throws -> String { - return try content.render(with: manager) - } -} - -extension IF.Condition: Conditionable { - - public func evaluate(with manager: ContextManager) throws -> Bool { - return try condition.evaluate(with: manager) - } -} - diff --git a/Sources/HTMLKit/Framework/Environment/Statements/LoopStatements.swift b/Sources/HTMLKit/Framework/Environment/Statements/LoopStatements.swift deleted file mode 100644 index c7728f47..00000000 --- a/Sources/HTMLKit/Framework/Environment/Statements/LoopStatements.swift +++ /dev/null @@ -1,146 +0,0 @@ -/* - Abstract: - The file contains the loop statements. - - Markings: - - ForEach - */ - -/// The statement is for -public struct ForEach: GlobalElement where Values: Sequence { - - internal var isEnumerated: Bool - - internal let condition: Conditionable - - internal let context: TemplateValue - - internal let formula: Formula - - internal let content: AnyContent - - public init(in context: TemplateValue, @ContentBuilder content: (TemplateValue) -> AnyContent) { - - self.isEnumerated = false - self.condition = true - self.context = context - self.formula = Formula() - - switch context { - case .constant(let values): - - self.content = values.reduce(into: "") { (result, value) in - return result += content(.constant(value)) - } - - case .dynamic(let variable): - self.content = content(.dynamic(HTMLContext(Values.Element.self, rootId: "\(variable.pathId)-loop"))) - } - } - - public init(in values: Values, @ContentBuilder content: (TemplateValue) -> AnyContent) { - self.init(in: .constant(values), content: content) - } - - public init(in context: TemplateValue, @ContentBuilder content: (TemplateValue) -> AnyContent) { - - self.isEnumerated = false - self.condition = context.isDefined - self.context = context.unsafelyUnwrapped - self.formula = Formula() - - switch context { - case .constant(let values): - - if let values = values { - - self.content = values.reduce(into: "") { (result, value) in - return result += content(.constant(value)) - } - - } else { - self.content = "" - } - - case .dynamic(let variable): - self.content = content(.dynamic(HTMLContext(Values.Element.self, rootId: variable.unsafelyUnwrapped.pathId + "-loop"))) - } - } - - public init(enumerated context: TemplateValue, @ContentBuilder content: ((element: TemplateValue, index: TemplateValue)) -> AnyContent) { - - self.isEnumerated = true - self.condition = true - self.context = context - self.formula = Formula() - - switch context { - case .constant(let values): - - self.content = values.enumerated().reduce(into: "") { (result, value) in - return result += content((.constant(value.element), .constant(value.offset))) - } - - case .dynamic(let variable): - self.content = content( - ( - .dynamic(HTMLContext(Values.Element.self, rootId: "\(variable.pathId)-loop")), - .dynamic(HTMLContext(Int.self, rootId: "\(variable.pathId)-loop-index")) - )) - } - } - - public init(enumerated context: Values, @ContentBuilder content: ((element: TemplateValue, index: TemplateValue)) -> AnyContent) { - self.init(enumerated: .constant(context), content: content) - } -} - -extension ForEach: AnyContent { - - public func prerender(_ formula: Formula) throws { - - formula.add(content: self) - - try content.prerender(formula) - } - - public func render(with manager: ContextManager) throws -> String { - - switch context { - case .constant(_): - return try formula.render(with: manager) - - case .dynamic(let variable): - - guard try condition.evaluate(with: manager) else { - return "" - } - - var rendering = "" - - let elements = try manager.value(for: variable) - - if isEnumerated { - - for (index, element) in elements.enumerated() { - - manager.set(index, for: HTMLContext(Int.self, rootId: variable.pathId + "-loop-index")) - - manager.set(element, for: HTMLContext(Values.Element.self, rootId: variable.pathId + "-loop")) - - rendering += try formula.render(with: manager) - } - - } else { - - for element in elements { - - manager.set(element, for: HTMLContext(Values.Element.self, rootId: variable.pathId + "-loop")) - rendering += try formula.render(with: manager) - } - } - - return rendering - } - } -} diff --git a/Sources/HTMLKit/Framework/Environment/Statements/OptionalChaining.swift b/Sources/HTMLKit/Framework/Environment/Statements/OptionalChaining.swift deleted file mode 100644 index f431aae4..00000000 --- a/Sources/HTMLKit/Framework/Environment/Statements/OptionalChaining.swift +++ /dev/null @@ -1,59 +0,0 @@ -/* - Abstract: - The file contains statements for optional chaining. - - Markings: - - Unwrap - */ - -/// The function is for -public struct Unwrap: GlobalElement { - - internal let content: IF - - internal init(content: IF) { - self.content = content - } - - public init(_ value: TemplateValue, @ContentBuilder content: (TemplateValue) -> AnyContent) { - - var ifContent: AnyContent = "" - - if value.isMasqueradingOptional { - - ifContent = content(value.unsafeCast(to: T.self)) - - } else { - - switch value { - case .constant(let value): - - if value != nil { - ifContent = content(.constant(value!)) - } - - case .dynamic(let variable): - ifContent = content(.dynamic(variable.unsafelyUnwrapped)) - } - } - - self.content = IF(value.isDefined) { - ifContent - } - } - - public func `else`(@ContentBuilder content: () -> AnyContent) -> AnyContent { - self.content.else(content: content) - } -} - -extension Unwrap: AnyContent { - - public func prerender(_ formula: Formula) throws { - try content.prerender(formula) - } - - public func render(with manager: ContextManager) throws -> String { - try content.render(with: manager) - } -} diff --git a/Sources/HTMLKit/Framework/Environment/Storage/Environment.swift b/Sources/HTMLKit/Framework/Environment/Storage/Environment.swift new file mode 100644 index 00000000..3f298aec --- /dev/null +++ b/Sources/HTMLKit/Framework/Environment/Storage/Environment.swift @@ -0,0 +1,17 @@ +import Foundation + +/// A type that represents the environment +public struct Environment { + + /// The current time zone of the environment + public var timeZone: TimeZone? + + /// The current calender of the environment + public var calendar: Calendar? + + /// The current local of the environment + public var locale: String? + + /// The current color scheme of the environment + public var colorScheme: String? +} diff --git a/Sources/HTMLKit/Framework/Environment/Storage/EnvironmentKeys.swift b/Sources/HTMLKit/Framework/Environment/Storage/EnvironmentKeys.swift new file mode 100644 index 00000000..eea6e65a --- /dev/null +++ b/Sources/HTMLKit/Framework/Environment/Storage/EnvironmentKeys.swift @@ -0,0 +1,12 @@ +import Foundation + +public struct EnvironmentKeys: Hashable { + + public var calender: Calendar + + public var timeZone: TimeZone + + public var locale: String + + public var colorScheme: String +} diff --git a/Sources/HTMLKit/Framework/Environment/Storage/EnvironmentModifier.swift b/Sources/HTMLKit/Framework/Environment/Storage/EnvironmentModifier.swift new file mode 100644 index 00000000..2628d3a1 --- /dev/null +++ b/Sources/HTMLKit/Framework/Environment/Storage/EnvironmentModifier.swift @@ -0,0 +1,25 @@ +/* + Abstract: + The file contains the environment modifier. + */ + +/// A type that contains the value and the following content, after modifing the environment. +public struct EnvironmentModifier: Content { + + /// The environment key + public var key: AnyKeyPath + + /// The environment value + public var value: Any? + + /// The following content + public var content: [Content] + + /// Initiates a environment modifier + public init(key: AnyKeyPath, value: Any? = nil, content: [Content]) { + + self.key = key + self.value = value + self.content = content + } +} diff --git a/Sources/HTMLKit/Framework/Environment/Storage/EnvironmentObject.swift b/Sources/HTMLKit/Framework/Environment/Storage/EnvironmentObject.swift new file mode 100644 index 00000000..6d4a858c --- /dev/null +++ b/Sources/HTMLKit/Framework/Environment/Storage/EnvironmentObject.swift @@ -0,0 +1,64 @@ +import Foundation + +/// A property wrapper type to initate an environment object +@frozen @propertyWrapper public struct EnvironmentObject { + + /// The wrapped value + public var wrappedValue: Wrapper + + /// Converts the type into the wrapped value + public init(_ type: Value.Type) { + + self.wrappedValue = .init() + } + + /// A type, that holds the environment object informationen + @dynamicMemberLookup public struct Wrapper { + + /// The path of the parent + internal var parent: AnyKeyPath? + + /// The path of the value + internal var path: AnyKeyPath + + /// Initiates a wrapper + public init() { + + self.path = \Value.self + } + + /// Initiates a wrapper with the necessary information for the environment object + internal init(parent: AnyKeyPath, path: AnyKeyPath) { + + self.parent = parent + self.path = path + } + + /// Looks up for a containing property + public subscript(dynamicMember member: KeyPath) -> EnvironmentValue { + + guard let newPath = self.path.appending(path: member) else { + fatalError() + } + + if let parent = self.parent { + return .init(parentPath: parent, valuePath: newPath) + } + + return .init(parentPath: self.path, valuePath: newPath) + } + + /// Looks up for a containing model + public subscript(dynamicMember member: KeyPath) -> Wrapper where T: ViewModel { + + guard let newPath = self.path.appending(path: member) else { + fatalError() + } + + return .init(parent: self.path, path: newPath) + } + } +} + +/// A type, that defines a view model +public protocol ViewModel: Encodable {} diff --git a/Sources/HTMLKit/Framework/Environment/Storage/EnvironmentValue.swift b/Sources/HTMLKit/Framework/Environment/Storage/EnvironmentValue.swift new file mode 100644 index 00000000..f439beb2 --- /dev/null +++ b/Sources/HTMLKit/Framework/Environment/Storage/EnvironmentValue.swift @@ -0,0 +1,18 @@ +import Foundation + +/// A type, that acts as a binding value +public struct EnvironmentValue: Content { + + /// The path of the values parent + internal var parentPath: AnyKeyPath + + /// The path of the value + internal var valuePath: AnyKeyPath + + /// Initiates a environment value + public init(parentPath: AnyKeyPath, valuePath: AnyKeyPath) { + + self.parentPath = parentPath + self.valuePath = valuePath + } +} diff --git a/Sources/HTMLKit/Framework/Environment/Storage/Manager.swift b/Sources/HTMLKit/Framework/Environment/Storage/Manager.swift new file mode 100644 index 00000000..2a34b1ae --- /dev/null +++ b/Sources/HTMLKit/Framework/Environment/Storage/Manager.swift @@ -0,0 +1,29 @@ +import Foundation + +/// A type, that manages the environment storage +internal class Manager { + + /// The storage of the environment + internal var storage: [AnyKeyPath: Any] + + /// Initiates a manager + internal init() { + + self.storage = [:] + } + + /// Retrieves an item from storage by its path + internal func retrieve(for path: AnyKeyPath) -> Any? { + + if let value = self.storage[path] { + return value + } + + return nil + } + + /// Adds und updates an item to the storage + internal func upsert(_ value: T, for path: AnyKeyPath) { + self.storage[path] = value + } +} diff --git a/Sources/HTMLKit/Framework/Rendering/Caching/Cache.swift b/Sources/HTMLKit/Framework/Rendering/Caching/Cache.swift deleted file mode 100644 index a80041f8..00000000 --- a/Sources/HTMLKit/Framework/Rendering/Caching/Cache.swift +++ /dev/null @@ -1,29 +0,0 @@ -/* - Abstract: - The file contains the cache. The cache stacks the formulas of the renderer. - */ - -public class Cache { - - private var stack: [ObjectIdentifier: Formula] - - public var count: Int { - return self.stack.keys.count - } - - public init() { - self.stack = [:] - } - - public func retrieve(identifier: ObjectIdentifier) -> Formula? { - return self.stack[identifier] ?? nil - } - - public func upsert(formula: Formula, for identifier: ObjectIdentifier) { - self.stack.updateValue(formula, forKey: identifier) - } - - public func remove(identifier: ObjectIdentifier) { - self.stack.removeValue(forKey: identifier) - } -} diff --git a/Sources/HTMLKit/Framework/Rendering/Formula.swift b/Sources/HTMLKit/Framework/Rendering/Formula.swift deleted file mode 100644 index 398d27aa..00000000 --- a/Sources/HTMLKit/Framework/Rendering/Formula.swift +++ /dev/null @@ -1,43 +0,0 @@ -/* - Abstract: - The file contains the formula. The formula contains the string output given by the renderer. - */ - -import Foundation -import Lingo - -public class Formula { - - /// The different ingredients of the content. - public var ingredients: [AnyContent] - - /// The calender for localization. - public var calendar: Calendar - - /// The time zone for localization. - public var timeZone: TimeZone - - /// Initiates a formula. - public init(calendar: Calendar = .current, timeZone: TimeZone = .current) { - - self.ingredients = [] - self.calendar = calendar - self.timeZone = timeZone - } - - /// Appends the ingredients - public func add(content: T) { - self.ingredients.append(content) - } - - public func render(with context: T, lingo: Lingo?) throws -> String { - return try render(with: ContextManager(context: context, lingo: lingo)) - } - - public func render(with manager: ContextManager) throws -> String { - - return try ingredients.reduce(into: "") { (result, ingridient) in - return result += try ingridient.render(with: manager) - } - } -} diff --git a/Sources/HTMLKit/Framework/Rendering/Renderer.swift b/Sources/HTMLKit/Framework/Rendering/Renderer.swift index 02fa4df9..568112cd 100644 --- a/Sources/HTMLKit/Framework/Rendering/Renderer.swift +++ b/Sources/HTMLKit/Framework/Rendering/Renderer.swift @@ -9,138 +9,338 @@ import Lingo /// A struct containing the different formulas for the different views. public class Renderer { - public enum Errors: LocalizedError { + /// A enumeration of possible render errors + public enum Errors: Error { - case unableToFindFormula + case unableToCastEnvironmentValue + case unindendedEnvironmentKey + case environmentObjectNotFound + case environmentValueNotFound + case missingLingoConfiguration - public var errorDescription: String? { + public var description: String { switch self { - case .unableToFindFormula: - return "Unable to find a formula for the given view type" - } - } - - public var failureReason: String? { - return self.errorDescription ?? "" - } - - public var recoverySuggestion: String? { - - switch self { - case .unableToFindFormula: - return "Remember to add the template to the renderer with .add(template: ) or .add(view: )" + case .unableToCastEnvironmentValue: + return "Unable to cast the environment value." + + case .unindendedEnvironmentKey: + return "The environment key is not indended." + + case .environmentValueNotFound: + return "Unable to retrieve environment value." + + case .environmentObjectNotFound: + return "Unable to retrieve environment object." + + case .missingLingoConfiguration: + return "The lingo configuration seem to missing." } } } - - /// A cache that contains all the composed content. - private var cache: Cache - - /// The localization to use when rendering. - private var lingo: Lingo? - /// The calendar to use when rendering dates. - public var calendar: Calendar + private var environment: Environment - /// The time zone to use when rendering dates. - public var timeZone: TimeZone + private var manager: Manager + + /// The localization to use when rendering. + private var lingo: Lingo? /// Initiates the renderer. - public init(calendar: Calendar = .current, timeZone: TimeZone = .current) { + public init(lingo: Lingo? = nil) { - self.cache = .init() - self.calendar = calendar - self.timeZone = timeZone + self.environment = Environment() + self.manager = Manager() + self.lingo = lingo } - /// Adds a formula to the cache. - public func add(layout: T) throws { + public func add(model: T) where T: Encodable { + manager.upsert(model, for: \T.self) + } + + /// Renders a view + public func render(view: some View) throws -> String { - let formula = Formula() + var result = "" - try layout.prerender(formula) + if let contents = view.body as? [Content] { + result += try render(contents: contents) + } - self.cache.upsert(formula: formula, for: ObjectIdentifier(T.self)) + return result } - /// Registers a localization. - public func add(localization: Localization) throws { - self.lingo = try Lingo(rootPath: localization.source, defaultLocale: localization.locale.rawValue) - } - - /// Renders a formula. - public func render(layout: T.Type) throws -> String { + internal func render(contents: [Content]) throws -> String { + + var result = "" - guard let formula = self.cache.retrieve(identifier: ObjectIdentifier(layout)) else { - throw Errors.unableToFindFormula + for content in contents { + + if let contents = content as? [Content] { + result += try render(contents: contents) + } + + if let element = content as? (any View) { + result += try render(view: element) + } + + if let element = content as? (any ContentNode) { + result += try render(element: element) + } + + if let element = content as? (any EmptyNode) { + result += render(element: element) + } + + if let element = content as? (any DocumentNode) { + result += render(element: element) + } + + if let element = content as? (any CommentNode) { + result += render(element: element) + } + + if let element = content as? (any CustomNode) { + result += try render(element: element) + } + + if let stringkey = content as? LocalizedStringKey { + result += try render(stringkey: stringkey) + } + + if let modifier = content as? EnvironmentModifier { + result += try render(modifier: modifier) + } + + if let element = content as? String { + result += element + } } - return try formula.render(with: (), lingo: lingo) + return result } - /// Renders a formula. - public func render(layout: T.Type, with context: C) throws -> String { + /// Renders a content element + internal func render(element: some ContentNode) throws -> String { + + var result = "" - guard let formula = self.cache.retrieve(identifier: ObjectIdentifier(layout)) else { - throw Errors.unableToFindFormula + result += element.startTag + + if let contents = element.content as? [Content] { + + for content in contents { + + if let contents = content as? [Content] { + result += try render(contents: contents) + } + + if let element = content as? (any View) { + result += try render(view: element) + } + + if let element = content as? (any ContentNode) { + result += try render(element: element) + } + + if let element = content as? (any EmptyNode) { + result += render(element: element) + } + + if let element = content as? (any DocumentNode) { + result += render(element: element) + } + + if let element = content as? (any CommentNode) { + result += render(element: element) + } + + if let element = content as? (any CustomNode) { + result += try render(element: element) + } + + if let stringkey = content as? LocalizedStringKey { + result += try render(stringkey: stringkey) + } + + if let modifier = content as? EnvironmentModifier { + result += try render(modifier: modifier) + } + + if let value = content as? EnvironmentValue { + result += try render(value: value) + } + + if let element = content as? String { + result += element + } + } } - return try formula.render(with: context, lingo: lingo) + result += element.endTag + + return result } -} - -extension Renderer { - // MARK: Deprecations + /// Renders a empty element + internal func render(element: some EmptyNode) -> String { + return element.startTag + } - /// Adds a formula to the cache. - @available(*, deprecated, message: "Use add(layout:) instead.") - public func add(view: T) throws { + /// Renders a document element + internal func render(element: some DocumentNode) -> String { + return element.startTag + } + + /// Renders a comment element + internal func render(element: some CommentNode) -> String { + return element.startTag + element.content + element.endTag + } + + /// Renders a content element + internal func render(element: some CustomNode) throws -> String { - let formula = Formula() - - try view.prerender(formula) + var result = "" + + result += element.startTag - self.cache.upsert(formula: formula, for: ObjectIdentifier(T.self)) + if let contents = element.content as? [Content] { + + for content in contents { + + if let contents = content as? [Content] { + result += try render(contents: contents) + } + + if let element = content as? (any View) { + result += try render(view: element) + } + + if let element = content as? (any ContentNode) { + result += try render(element: element) + } + + if let element = content as? (any EmptyNode) { + result += render(element: element) + } + + if let element = content as? (any DocumentNode) { + result += render(element: element) + } + + if let element = content as? (any CommentNode) { + result += render(element: element) + } + + if let element = content as? (any CustomNode) { + result += try render(element: element) + } + + if let stringkey = content as? LocalizedStringKey { + result += try render(stringkey: stringkey) + } + + if let element = content as? String { + result += element + } + } + } + + result += element.endTag + + return result } - /// Adds a formula to the cache. - @available(*, deprecated, message: "Use add(layout:) instead.") - public func add(view: T) throws { - - let formula = Formula() - - try view.prerender(formula) - - self.cache.upsert(formula: formula, for: ObjectIdentifier(T.self)) + /// Renders a localized string key + internal func render(stringkey: LocalizedStringKey) throws -> String { + + guard let lingo = self.lingo else { + throw Errors.missingLingoConfiguration + } + + if let context = stringkey.context { + + if let data = try? JSONEncoder().encode(context) { + + if let dictionary = try? JSONSerialization.jsonObject(with: data, options: .fragmentsAllowed) as? [String: Any] { + return lingo.localize(stringkey.key, locale: lingo.defaultLocale, interpolations: dictionary) + } + } + } + + return lingo.localize(stringkey.key, locale: environment.locale ?? lingo.defaultLocale) } - /// Renders a formula. - @available(*, deprecated, message: "Use render(layout:) instead.") - public func render(raw type: T.Type) throws -> String { + /// Renders a environment modifier + internal func render(modifier: EnvironmentModifier) throws -> String { - guard let formula = self.cache.retrieve(identifier: ObjectIdentifier(type)) else { - throw Errors.unableToFindFormula + if let value = modifier.value { + self.manager.upsert(value, for: modifier.key) + + } else { + + if let value = manager.retrieve(for: modifier.key) { + + if let key = modifier.key as? PartialKeyPath { + + switch key { + case \.locale: + self.environment.locale = value as? String + + case \.calender: + self.environment.calendar = value as? Calendar + + case \.timeZone: + self.environment.timeZone = value as? TimeZone + + case \.colorScheme: + self.environment.colorScheme = value as? String + + default: + throw Errors.unindendedEnvironmentKey + } + } + } } - - return try formula.render(with: (), lingo: lingo) + + return try render(contents: modifier.content) } - /// Renders a formula. - @available(*, deprecated, message: "Use render(layout:, with:) instead.") - public func render(raw type: T.Type, with context: Any) throws -> String { + /// Renders a environment value + internal func render(value: EnvironmentValue) throws -> String { - guard let formula = self.cache.retrieve(identifier: ObjectIdentifier(type)) else { - throw Errors.unableToFindFormula + guard let parent = manager.retrieve(for: value.parentPath) else { + throw Errors.environmentObjectNotFound } - return try formula.render(with: context, lingo: lingo) - } - - /// Registers a localization directory for the renderer. - @available(*, deprecated, message: "Use add(localization:) instead.") - public func registerLocalization(atPath path: String = "Resources/Localization", defaultLocale: String = "en") throws { - self.lingo = try Lingo(rootPath: path, defaultLocale: defaultLocale) + guard let value = parent[keyPath: value.valuePath] else { + throw Errors.environmentValueNotFound + } + + switch value { + case let floatValue as Float: + return String(floatValue) + + case let intValue as Int: + return String(intValue) + + case let doubleValue as Double: + return String(doubleValue) + + case let stringValue as String: + return String(stringValue) + + case let dateValue as Date: + + let formatter = DateFormatter() + formatter.timeZone = self.environment.timeZone ?? TimeZone.current + formatter.dateStyle = .medium + formatter.timeStyle = .short + + return formatter.string(from: dateValue) + + default: + throw Errors.unableToCastEnvironmentValue + } } } diff --git a/Sources/HTMLKit/HTMLKit.docc/Essentials/GettingStarted.md b/Sources/HTMLKit/HTMLKit.docc/Essentials/GettingStarted.md index 2c975fc2..16670f7e 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Essentials/GettingStarted.md +++ b/Sources/HTMLKit/HTMLKit.docc/Essentials/GettingStarted.md @@ -2,7 +2,7 @@ Learn how to use the framework. -> Important: The framework requires Swift 5.6 or higher. +> Important: The framework requires Swift 5.7 or higher. ### Manifest @@ -13,7 +13,7 @@ let package = Package( ... dependencies: [ // 1. Add the package - .package(url: "https://github.com/vapor-community/HTMLKit.git", from: "2.8.0"), + .package(url: "https://github.com/vapor-community/HTMLKit.git", from: "3.0.0"), ], targets: [ .target( @@ -28,4 +28,17 @@ let package = Package( ) ``` -Import the module in one of your files next. +### Imports + +Import one of the modules, by using the import declaration in one of your files next. + +```swift +/// Loads the html abstraction +import HTMLKit + +/// Loads the component library +import HTMLKitComponents + +/// Loads the vapor intergration +import HTMLKitVapor +``` diff --git a/Sources/HTMLKit/HTMLKit.docc/Essentials/VaporIntegration.md b/Sources/HTMLKit/HTMLKit.docc/Essentials/VaporIntegration.md index 897005b3..ad86e4ec 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Essentials/VaporIntegration.md +++ b/Sources/HTMLKit/HTMLKit.docc/Essentials/VaporIntegration.md @@ -4,42 +4,23 @@ Use the framework together with Vapor. ## Overview -The HTMLKit framework uses the web framework [Vapor](https://swiftpackageindex.com/vapor/vapor) as its standard view renderer. - -### Configure - -Before you can use the view renderer, you need to do some adjustments in the *configure.swift* file of your Vapor project: - -```swift -/// 1. Load the module -import HTMLKitVapor -import Vapor - -public func configure(_ app: Application) throws { - - /// 2. Specify the view renderer - app.views.use(.htmlkit) - - /// 3. Add the layout - app.htmlkit.views.add(view: ExampleTemplate.ExampleView()) - - try routes(app) -} -``` +The HTMLKit framework uses the web framework [Vapor](https://swiftpackageindex.com/vapor/vapor) as its default view renderer. ### Request -Now you can call the method *render* on the request in one of your controllers: +Call the method *render(_:)* on a request in one of your controller handlers to render a instance of a view. ```swift +/// 1. Import the module +import HTMLKitVapor import Vapor final class ExampleController { func getIndex(_ request: Request) async throws -> View { - /// 1. Name the layout - return try await request.view.render("ExampleTemplate.IndexView") + /// 2. Name the view instance + return try await request.htmlkit.render(ExampleView()) } } ``` diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Components.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Components.md index c49a9e74..7f41b45b 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Components.md +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Components.md @@ -4,27 +4,25 @@ Construct UI interfaces using the components. ## Overview -The components library follows the idea of a complete design system. It offers you standardized, reusable components imitating the syntax and semantic of SwiftUI. The library also comes with CSS (Cascading Style Sheet) to help you constructing your vision, without the need to completely rebuild it or furthermore any knowledge in CSS. +The components library follows the idea of a design system. It offers you standardized, reusable components imitating the syntax and semantic of SwiftUI. The library also comes with CSS (Cascading Style Sheet) and JS (JavaScript) to help you constructing your vision, without the need to completely rebuild it or furthermore any knowledge in one of these languages. ```swift HStack { StackColumn(size: .twelve) { - Paragraph { + Text { "Lorem ipsum..." } } } ``` -```css -.hstack { - position: relative; - width: 100%; - height: 100%; - display: flex; - flex-direction: row; - flex-wrap: nowrap; +### Interactions + +```swift +Text { + "Lorem ipsum..." } +.onHover(perfom: .show("navigation")) ``` ## Topics @@ -41,16 +39,10 @@ HStack { - - - -- -- +- - - -### List components - -- -- - ### Section components - @@ -58,17 +50,28 @@ HStack { - - +### Group components + +- +- +- + ### Text components - +- ### Link components - -- +- ### Media components - -- +- - + +### Active components + +- diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/ResetButton.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Button.md similarity index 81% rename from Sources/HTMLKit/HTMLKit.docc/Framework/Components/ResetButton.md rename to Sources/HTMLKit/HTMLKit.docc/Framework/Components/Button.md index 8972fdfe..af5c9f93 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/ResetButton.md +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Button.md @@ -1,18 +1,18 @@ -# ResetButton +# Button A component that initiates a form reset. ## Declaration ```swift -struct ResetButton : Component +struct Button : View ``` ## Overview ```swift -ResetButton { - "Reset" +Button(role: .submit) { + "Submit" } ``` diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Card.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Card.md new file mode 100644 index 00000000..afcac13e --- /dev/null +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Card.md @@ -0,0 +1,16 @@ +# Card + +A component that initiates a form reset. + +## Declaration + +```swift +struct Card : View +``` + +## Overview + +```swift +Card { +} +``` diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/CheckField.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/CheckField.md index 66c652d2..585a5f41 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/CheckField.md +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/CheckField.md @@ -5,7 +5,7 @@ A component for selecting one or multiple options. ## Declaration ```swift -struct CheckField : Component +struct CheckField : View ``` ## Overview diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/DatePicker.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/DatePicker.md index 37dc4b63..84656098 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/DatePicker.md +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/DatePicker.md @@ -5,7 +5,7 @@ A component for selecting a specific date and year. ## Declaration ```swift -struct DatePicker : Component +struct DatePicker : View ``` ## Overview diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Divider.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Divider.md index 3663a3ec..c43ebd53 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Divider.md +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Divider.md @@ -5,7 +5,7 @@ A component to seperate content visually. ## Declaration ```swift -struct Divider : Component +struct Divider : View ``` ## Overview diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/FieldLabel.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/FieldLabel.md index b612c799..e1e2c0ca 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/FieldLabel.md +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/FieldLabel.md @@ -5,7 +5,7 @@ A component that displays the name of the form control. ## Declaration ```swift -struct FieldLabel : Component +struct FieldLabel : View ``` ## Overview diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Form.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Form.md index 79f0cf03..79f0efa4 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Form.md +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Form.md @@ -5,13 +5,13 @@ A component that collects form controls. ## Declaration ```swift -struct Form : Component +struct Form : View ``` ## Overview ```swift -Form { +Form(method: .post) { FieldLabel(name: "firstname") { "Firstname" } diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Collection.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Grid.md similarity index 53% rename from Sources/HTMLKit/HTMLKit.docc/Framework/Components/Collection.md rename to Sources/HTMLKit/HTMLKit.docc/Framework/Components/Grid.md index 4cff1345..0eb0905c 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Collection.md +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Grid.md @@ -1,23 +1,19 @@ -# Collection +# Grid A component to collect and arrange collection items horizontally. ## Declaration ```swift -struct Collection : Component +struct Grid : View ``` ## Overview ```swift -Collection(ratio: .half) { - CollectionItem { +Grid(ratio: .half) { + GridItem { Image(source: "../assets/thumbnail.png") } } ``` - -### Modifiers - -- collectionStyle(_ style: Token.CollectionStyle) diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/HStack.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/HStack.md index fc163bb2..401a34ef 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/HStack.md +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/HStack.md @@ -5,7 +5,7 @@ A component to arrange content horizontally. ## Declaration ```swift -struct HStack : Component +struct HStack : View ``` ## Overview diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Image.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Image.md index 84ba8c53..ab7a31dc 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Image.md +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Image.md @@ -5,7 +5,7 @@ A component that displays a image. ## Declaration ```swift -struct Image : Component +struct Image : View ``` ## Overview diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Link.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Link.md index 4a8bd348..d8d232fb 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Link.md +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Link.md @@ -5,7 +5,7 @@ A component that navigates to an target. ## Declaration ```swift -struct Link : Component +struct Link : View ``` ## Overview diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/ActionButton.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/LinkButton.md similarity index 79% rename from Sources/HTMLKit/HTMLKit.docc/Framework/Components/ActionButton.md rename to Sources/HTMLKit/HTMLKit.docc/Framework/Components/LinkButton.md index e830ce61..ac8efbcc 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/ActionButton.md +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/LinkButton.md @@ -1,17 +1,17 @@ -# ActionButton +# LinkButton A component that initiates an action. ## Declaration ```swift -struct ActionButton : Component +struct LinkButton : View ``` ## Overview ```swift -ActionButton(destination: "/home") { +LinkButton(destination: "/home") { "Home" } ``` diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/List.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/List.md index 6f4e0a65..254518c1 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/List.md +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/List.md @@ -5,7 +5,7 @@ A component to collect and arrange list items vertically. ## Declaration ```swift -struct List : Component +struct List : View ``` ## Overview diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Modal.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Modal.md new file mode 100644 index 00000000..9d7b56b8 --- /dev/null +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Modal.md @@ -0,0 +1,16 @@ +# Modal + +A component that navigates to an target. + +## Declaration + +```swift +struct Modal : View +``` + +## Overview + +```swift +Modal { +} +``` diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/ProgressView.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Progress.md similarity index 57% rename from Sources/HTMLKit/HTMLKit.docc/Framework/Components/ProgressView.md rename to Sources/HTMLKit/HTMLKit.docc/Framework/Components/Progress.md index e114ce60..6d04e74c 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/ProgressView.md +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Progress.md @@ -1,16 +1,16 @@ -# ProgressView +# Progress A component to display the progress of a task. ## Declaration ```swift -struct ProgressView : Component +struct Progress : View ``` ## Overview ```swift -ProgressView(name: "delivery") { +Progress(max: 100, value: 10) { } ``` diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/RadioSelect.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/RadioSelect.md index 248a2a20..1ea924bc 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/RadioSelect.md +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/RadioSelect.md @@ -5,7 +5,7 @@ A component for selecting only one of multiple options. ## Declaration ```swift -struct RadioSelect : Component +struct RadioSelect : View ``` ## Overview diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/SearchField.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/SearchField.md index 21b79f6a..fff842ed 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/SearchField.md +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/SearchField.md @@ -5,7 +5,7 @@ A component to initiate a search or filter. ## Declaration ```swift -struct SearchField : Component +struct SearchField : View ``` ## Overview diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/SecureField.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/SecureField.md index fca2f16d..f1e66df3 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/SecureField.md +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/SecureField.md @@ -5,7 +5,7 @@ A component to enter sensitive information. ## Declaration ```swift -struct SecureField : Component +struct SecureField : View ``` ## Overview diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/SelectField.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/SelectField.md index 2542702e..84eed5bc 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/SelectField.md +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/SelectField.md @@ -5,7 +5,7 @@ A component for selecting one or multiple options. ## Declaration ```swift -struct SelectField : Component +struct SelectField : View ``` ## Overview diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Slider.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Slider.md index 91ee1ccc..14925314 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Slider.md +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Slider.md @@ -5,7 +5,7 @@ A component for selecting a value within a given range. ## Declaration ```swift -struct Slider : Component +struct Slider : View ``` ## Overview diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Snippet.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Snippet.md index ae129f5c..ead41689 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Snippet.md +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Snippet.md @@ -5,7 +5,7 @@ A component to display code content. ## Declaration ```swift -struct Snippet : Component +struct Snippet : View ``` ## Overview diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/SubmitButton.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/SubmitButton.md deleted file mode 100644 index e303d73f..00000000 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/SubmitButton.md +++ /dev/null @@ -1,27 +0,0 @@ -# SubmitButton - -A component that initiates a form submit. - -## Declaration - -```swift -struct SubmitButton : Component -``` - -## Overview - -```swift -SubmitButton { - "Submit" -} -``` - -## Modifiers - -- func buttonSize(_ size: Tokens.ButtonSize) - -- func borderShape(_ shape: Tokens.BorderShape) - -- func buttonStyle(_ style: Tokens.ButtonStyle) - -- func backgroundColor(_ color: Tokens.BackgroundColor) diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Symbol.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Symbol.md new file mode 100644 index 00000000..81129503 --- /dev/null +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Symbol.md @@ -0,0 +1,15 @@ +# Symbol + +A component to collect and arrange list items vertically. + +## Declaration + +```swift +struct Symbol : View +``` + +## Overview + +```swift +Symbol(system: "house") +``` diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Text.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Text.md index 7c0b5490..9cbfc693 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Text.md +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Text.md @@ -5,7 +5,7 @@ A component that displays text. ## Declaration ```swift -struct Text : Component +struct Text : View ``` ## Overview diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/TextEditor.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/TextEditor.md index c13007b9..4bc0a3b4 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/TextEditor.md +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/TextEditor.md @@ -5,7 +5,7 @@ A component that displays a editable and expandable form control. ## Declaration ```swift -struct TextEditor : Component +struct TextEditor : View ``` ## Overview diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/TextField.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/TextField.md index 3e487527..9627ed03 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/TextField.md +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/TextField.md @@ -5,7 +5,7 @@ A component that displays an editable form control. ## Declaration ```swift -struct TextField : Component +struct TextField : View ``` ## Overview diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Toggle.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Toggle.md index f37c5eda..3f80ba8b 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Toggle.md +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/Toggle.md @@ -5,7 +5,7 @@ A component that shows an on or off state. ## Declaration ```swift -struct Toggle : Component +struct Toggle : View ``` ## Overview diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/VStack.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/VStack.md index cfcff1e6..e739fc4b 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/VStack.md +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/VStack.md @@ -5,7 +5,7 @@ A component to arrange content vertically. ## Declaration ```swift -struct VStack : Component +struct VStack : View ``` ## Overview diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/ZStack.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/ZStack.md index 91167ea2..f5ae8564 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Components/ZStack.md +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Components/ZStack.md @@ -5,7 +5,7 @@ A component that overlays content. ## Declaration ```swift -struct ZStack : Component +struct ZStack : View ``` ## Overview diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Elements.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Elements.md index 57321240..e5daf652 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Elements.md +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Elements.md @@ -4,9 +4,9 @@ Write HTML markup using the abstraction. ## Overview -The elements in HTMLKit are an abstraction of the elements in HTML (Hyper Text Markup Language). If you have written HTML before, then you know, there are elements with or without an endtag. An Element with an end tag, will be represented in HTMLKit as an element with curly brackets, while an element without will be represented with the round brackets. +The elements in HTMLKit are an abstraction of the elements in HTML (Hyper Text Markup Language). If you have written HTML before, then you know, there are elements with or without an endtag. -If you would like to add attributes, use the offered methods on the element. In most cases the method name matches the attribute name in HTML. +An element with an endtag, will be represented in HTMLKit as an element with curly brackets, while an element without, will be represented with the round brackets. ```swift /// element with content @@ -14,15 +14,20 @@ Body { Paragraph { "Lorem ipsum..." } - .class("value") } /// element without content Input() - .required() ``` -To prevent writing invalid code, each element in HTMLKit owns an element limitation. For example the element *Heading1* is a type of *BodyElement*, so it is only valid as content of a body element. +If you would like to add attributes, use the methods on the element. In most cases the method name matches the attribute name in HTML. + +```swift +Input() + .class("input") +``` + +To prevent writing invalid code, each element in HTMLKit owns an element limitation. For example the element *Heading1* is a type of *BodyElement*, so it is only valid as descendant of a body element. ```swift public struct Heading1: ContentNode, BodyElement { @@ -53,12 +58,16 @@ extension FormContainer: GlobalElement { ### Basic elements +- ``HTMLKit/Document`` + - ``HTMLKit/Html`` - ``HTMLKit/Head`` - ``HTMLKit/Body`` +- ``HTMLKit/Comment`` + ### Head elements - ``HTMLKit/Title`` @@ -87,8 +96,30 @@ extension FormContainer: GlobalElement { - ``HTMLKit/Footer`` +- ``HTMLKit/Article`` + +- ``HTMLKit/Span`` + +- ``HTMLKit/Dialog`` + +- ``HTMLKit/Details`` + +- ``HTMLKit/Summary`` + +- ``HTMLKit/DescriptionList`` + +- ``HTMLKit/TermName`` + +- ``HTMLKit/TermDefinition`` + +- ``HTMLKit/Address`` + +- ``HTMLKit/Template`` + ### Paragraph elements +- ``HTMLKit/HeadingGroup`` + - ``HTMLKit/Heading1`` - ``HTMLKit/Heading2`` @@ -115,6 +146,50 @@ extension FormContainer: GlobalElement { - ``HTMLKit/Strong`` +- ``HTMLKit/StrikeThrough`` + +- ``HTMLKit/ShortQuote`` + +- ``HTMLKit/DeletedText`` + +- ``HTMLKit/InsertedText`` + +- ``HTMLKit/Code`` + +- ``HTMLKit/SampleOutput`` + +- ``HTMLKit/KeyboardInput`` + +- ``HTMLKit/Cite`` + +- ``HTMLKit/Blockquote`` + +- ``HTMLKit/PreformattedText`` + +- ``HTMLKit/Subscript`` + +- ``HTMLKit/Superscript`` + +- ``HTMLKit/Ruby`` + +- ``HTMLKit/RubyPronunciation`` + +- ``HTMLKit/RubyText`` + +- ``HTMLKit/Mark`` + +- ``HTMLKit/Abbreviation`` + +- ``HTMLKit/Time`` + +- ``HTMLKit/Definition`` + +- ``HTMLKit/Bdi`` + +- ``HTMLKit/Bdo`` + +- ``HTMLKit/Variable`` + ### List elements - ``HTMLKit/UnorderedList`` @@ -123,6 +198,8 @@ extension FormContainer: GlobalElement { - ``HTMLKit/ListItem`` +- ``HTMLKit/Data`` + ### Table elements - ``HTMLKit/Table`` @@ -139,6 +216,12 @@ extension FormContainer: GlobalElement { - ``HTMLKit/DataCell`` +- ``HTMLKit/ColumnGroup`` + +- ``HTMLKit/Column`` + +- ``HTMLKit/Caption`` + ### Form elements - ``HTMLKit/Form`` @@ -147,22 +230,62 @@ extension FormContainer: GlobalElement { - ``HTMLKit/Input`` +- ``HTMLKit/DataList`` + - ``HTMLKit/TextArea`` - ``HTMLKit/Select`` +- ``HTMLKit/OptionGroup`` + +- ``HTMLKit/Option`` + - ``HTMLKit/Button`` - ``HTMLKit/Fieldset`` +- ``HTMLKit/Legend`` + +- ``HTMLKit/Progress`` + +- ``HTMLKit/Meter`` + +- ``HTMLKit/Output`` + +### Link elements + +- ``HTMLKit/Anchor`` + ### Media elements - ``HTMLKit/Audio`` - ``HTMLKit/Video`` +- ``HTMLKit/Source`` + +- ``HTMLKit/Track`` + +- ``HTMLKit/Image`` + +- ``HTMLKit/Map`` + +- ``HTMLKit/Area`` + +- ``HTMLKit/Picture`` + +- ``HTMLKit/Figure`` + +- ``HTMLKit/FigureCaption`` + +- ``HTMLKit/Object`` + +- ``HTMLKit/Parameter`` + ### Vector elements +- ``HTMLKit/Vector`` + - ``HTMLKit/Circle`` - ``HTMLKit/Rectangle`` @@ -180,3 +303,31 @@ extension FormContainer: GlobalElement { - ``HTMLKit/Group`` - ``HTMLKit/Use`` + +### Break elements + +- ``HTMLKit/LineBreak`` + +- ``HTMLKit/WordBreak`` + +- ``HTMLKit/HorizontalRule`` + +### Embed elements + +- ``HTMLKit/Embed`` + +- ``HTMLKit/InlineFrame`` + +- ``HTMLKit/Canvas`` + +### Script elements + +- ``HTMLKit/Script`` + +- ``HTMLKit/NoScript`` + +- ``HTMLKit/Template`` + +### Custom elements + +- ``HTMLKit/Custom`` diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Environment.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Environment.md new file mode 100644 index 00000000..93dab469 --- /dev/null +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Environment.md @@ -0,0 +1,15 @@ +# Environment + +Store values globally. + +## Overview + +The environment is way to store values globally and to use them in the whole scope without explicitly providing them through a DTO (Data Transfer Object). The environment has keys you can use to store a single value for a specific key or you can store a whole object too. + +## Topics + +### Keys + +### Annotations + +- diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Environment/EnvironmentObject.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Environment/EnvironmentObject.md new file mode 100644 index 00000000..22798361 --- /dev/null +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Environment/EnvironmentObject.md @@ -0,0 +1,33 @@ +# EnvironmentObject + +Summary + +## Overview + +```swift +struct MainView: View { + + var body: Content { + Division { + "Lorem ipsum..." + } + .environment(object: Object()) + } +} +``` + +```swift +struct ChildView: View { + + @EnvironmentObject(Object.self) + var object + + var body: Content { + MainView { + Paragraph { + object.property + } + } + } +} +``` diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Globalization.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Globalization.md deleted file mode 100644 index 8c6e68c9..00000000 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Globalization.md +++ /dev/null @@ -1,43 +0,0 @@ -# Globalization - -Localize your content for a wider audience. - -## Overview - -The framework uses the localization framework [Lingo](https://swiftpackageindex.com/miroslavkovac/Lingo) to translate and formate the content by local language and culture. - -### Configure - -Before you can use the localization, you need to set it up in the *configure.swift* file of your Vapor project: - -```swift -import HTMLKitVapor -import Vapor - -public func configure(_ app: Application) throws { - - /// 1. Specify the directory path - app.htmlkit.lingo.set(directory: currentDirectory) - - /// 2. Specify the default language - app.htmlkit.lingo.set(locale: .english) - - try routes(app) -} -``` - -### Message file - -Next you have to create a message file (for example en.json), wich contains the the translations strings for the given language. - -```json -{ - "Hallo Welt": "Hello World" -} -``` - -## Topics - -### Localization - -- diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Globalization/Localization.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Globalization/Localization.md deleted file mode 100644 index 35eeaecb..00000000 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Globalization/Localization.md +++ /dev/null @@ -1,34 +0,0 @@ -# ``HTMLKit/Localization`` - -@Metadata { - @DocumentationExtension(mergeBehavior: append) -} - -```swift -struct IndexView: View { - - var body: AnyContent { - Article { - Heading1("Hallo.Welt") - } - } -} -``` - -Also the locale for the environment can be changed for example by user input. Use the environment modifier on the element and pass the specific local identifier for it. - -```swift -struct IndexView: View { - - struct Context { - let date: Date - let locale: String - } - - var body: AnyContent { - Article { - ... - } - .environment(locale: context.locale) - } -} diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Layouts.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Layouts.md new file mode 100644 index 00000000..1ff5d7d8 --- /dev/null +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Layouts.md @@ -0,0 +1,88 @@ +# Layouts + +Embed or extend views to create a layout. + + +## Overview + +There will be situations, where you would like to use certain views at multiple places in your project and that's where the layout system comes in handy. You can embed the view in another or extend the view to be used for a different view. + +### Embed a view + +Embed a view by calling an another view in the content body. + +```swift +struct ChildView: View { + + var body: Content { + Paragraph { + "Hello World!" + } + } +} +``` + +```swift +struct MainView: View { + + var body: Content { + Document(.html5) + Head { + Title { + "MainView" + } + } + Body { + /// 1. Embed the child view + ChildView() + } + } +} +``` + +### Extend a view + +Extend a view by using the trailing closure of a view. + +```swift +struct MainView: View { + + var content: [BodyElement] + + init(@ContentBuilder content: () -> [BodyElement]) { + self.content = content + } + + var body: Content { + Document(.html5) + Head { + Title { + "MainView" + } + } + Body { + content + } + } +} +``` + +```swift +struct ChildView: View { + + var body: Content { + /// 1. Extend the main view + MainView { + Paragraph { + "Hello World!" + } + } + } +} +``` + +## Topics + +### Layouts + +- diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Template/Layouts/View.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Layouts/View.md similarity index 91% rename from Sources/HTMLKit/HTMLKit.docc/Framework/Template/Layouts/View.md rename to Sources/HTMLKit/HTMLKit.docc/Framework/Layouts/View.md index 17ec1335..a87a1760 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Template/Layouts/View.md +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Layouts/View.md @@ -9,7 +9,7 @@ A view is a single part of a page. You create a view by declaring a type that co ```swift struct ExampleView: View { - var body: AnyContent { + var body: Content { Heading1 { "Lorem ipsum..." } diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Localization.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Localization.md new file mode 100644 index 00000000..b1f6ee86 --- /dev/null +++ b/Sources/HTMLKit/HTMLKit.docc/Framework/Localization.md @@ -0,0 +1,68 @@ +# Localization + +Localize your content for a wider audience. + +## Overview + +The framework uses the localization framework [Lingo](https://swiftpackageindex.com/miroslavkovac/Lingo) to translate and formate the content by local language and culture. + +### Configure + +Before you can use the localization, you need to set up the directory path for the message files and the default language in the *configure.swift* file of your Vapor project. + +```swift +import HTMLKitVapor +import Vapor + +public func configure(_ app: Application) throws { + + /// 1. Specify the directory path + app.htmlkit.lingo.set(directory: currentDirectory) + + /// 2. Specify the default language + app.htmlkit.lingo.set(locale: .english) + + try routes(app) +} +``` + +### Message file + +Next you have to create a message file (for example en.json), wich contains the the translations strings for the given language. + +```json +{ + "greeting.world": "Hello World", + "greeting.person": "Hello %{name}" +} +``` + +### String key + +Then you can use the string key on a paragraph element to get the localized string. + +```swift +struct IndexView: View { + + var body: AnyContent { + Article { + Heading1("greeting.world") + } + } +} +``` + +### String interpolation + +Or interpolate the localized string. + +```swift +struct IndexView: View { + + var body: AnyContent { + Article { + Heading1("greeting.person", with: ["name": "Tim Cook"]) + } + } +} +``` diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Statements.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Statements.md deleted file mode 100644 index 06967d70..00000000 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Statements.md +++ /dev/null @@ -1,29 +0,0 @@ -# Statements - -Control the flow of your content using statements. - -## Overview - -Similar to other frameworks there exit various statements to control the flow of your content. Use the branch statements to perfom certain code depending on a condition, run through a sequence using the loop statements or unwrap an optional value with the optional statements. - -```swift -ForEach(in: fruits) { fruit in - Paragraph { - fruit.name - } -} -``` - -## Topics - -### Branch Statements - -- - -### Loop Statements - -- - -### Optional Statements - -- diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Statements/Foreach.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Statements/Foreach.md deleted file mode 100644 index cd874627..00000000 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Statements/Foreach.md +++ /dev/null @@ -1,16 +0,0 @@ -# ``HTMLKit/ForEach`` - -@Metadata { - @DocumentationExtension(mergeBehavior: append) -} - -```swift -ForEach(in: context.categories) { category in - Division { - Paragraph { - category.title - } - ... - } -} -``` diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Statements/Ifelse.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Statements/Ifelse.md deleted file mode 100644 index ec75217f..00000000 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Statements/Ifelse.md +++ /dev/null @@ -1,5 +0,0 @@ -# ``HTMLKit/IF`` - -@Metadata { - @DocumentationExtension(mergeBehavior: append) -} diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Statements/Unwrap.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Statements/Unwrap.md deleted file mode 100644 index 2dcd4e6f..00000000 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Statements/Unwrap.md +++ /dev/null @@ -1,13 +0,0 @@ -# ``HTMLKit/Unwrap`` - -@Metadata { - @DocumentationExtension(mergeBehavior: append) -} - -```swift -Unwrap(category.content) { content in - Paragraph { - content - } -} -``` diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Template.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Template.md deleted file mode 100644 index cb3685ed..00000000 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Template.md +++ /dev/null @@ -1,34 +0,0 @@ -# Template - -Scaffold your written content and apply context. - - -## Overview - -In HTMLKit a template consist of two parts. The first part is the view logic, wich gives the template the structure to display the content as you want. The second part is the data logic, wich gives the template the data to process the variables, that you may set in between the content. - -```swift -struct SimpleView: View { - - @TemplateValue(String.self) - var context - - var body: AnyContent { - SimplePage { - Heading1 { - context - } - } - } -} -``` - -## Topics - -### View logic - -- - -### Data logic - -- diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Template/Annotations/TemplateValue.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Template/Annotations/TemplateValue.md deleted file mode 100644 index 52ba2ef6..00000000 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Template/Annotations/TemplateValue.md +++ /dev/null @@ -1,5 +0,0 @@ -# TemplateValue - -@Metadata { - @DocumentationExtension(mergeBehavior: append) -} diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Template/Context.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Template/Context.md deleted file mode 100644 index 64c63eca..00000000 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Template/Context.md +++ /dev/null @@ -1,35 +0,0 @@ -# Context - -Add data to your template. - -## Overview - -The context holds the data for the content variables, wich get replaced when the template is evaulated. - -```swift -struct SimpleContext: Codable { - - var headline: String - var categories: [Category] -} -``` - -```swift -struct SimpleView: View { - - @TemplateValue(SimpleContext.self) - var context - - var body: AnyContent { - Heading1 { - context.headline - } - } -} -``` - -## Topics - -### Annotations - -- ``HTMLKit/TemplateValue`` diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Template/Layouts.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Template/Layouts.md deleted file mode 100644 index 8c227cad..00000000 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Template/Layouts.md +++ /dev/null @@ -1,51 +0,0 @@ -# Layouts - -Embed or extend views to create a layout. - - -## Overview - -There will be situations, where you would like to use certain views at multiple places in your project and that's where the layout system comes in handy. You can embed the view in another or extend the view to be used for a different view. - -### Embed the view - -```swift -struct SimplePage: Page { - - var body: AnyContent { - Document(type: .html5) - Head { - Title { - "SimplePage" - } - } - Body { - SimpleView(context: "Hello World!") - } - } -} -``` - -### Extend the page - -```swift -struct SimpleView: View { - - var context: String - - var body: AnyContent { - SimplePage { - Heading1 { - context - } - } - } -} -``` - -## Topics - -### Layouts - -- -- diff --git a/Sources/HTMLKit/HTMLKit.docc/Framework/Template/Layouts/Page.md b/Sources/HTMLKit/HTMLKit.docc/Framework/Template/Layouts/Page.md deleted file mode 100644 index 98e1ac26..00000000 --- a/Sources/HTMLKit/HTMLKit.docc/Framework/Template/Layouts/Page.md +++ /dev/null @@ -1,25 +0,0 @@ -# ``HTMLKit/Page`` - -@Metadata { - @DocumentationExtension(mergeBehavior: append) -} - -A page is a container that holds the views. You create a page by declaring a type that conforms to the Page protocol. - -```swift -struct ExamplePage: Page { - - var body: AnyContent { - Document(.html5) - Html { - Head { - Title { - "ExamplePage" - } - } - Body { - } - } - } -} -``` diff --git a/Sources/HTMLKit/HTMLKit.docc/HTMLKit.md b/Sources/HTMLKit/HTMLKit.docc/HTMLKit.md index d647941e..8c7b6cd5 100644 --- a/Sources/HTMLKit/HTMLKit.docc/HTMLKit.md +++ b/Sources/HTMLKit/HTMLKit.docc/HTMLKit.md @@ -10,16 +10,15 @@ The HTMLKit framework consists a list of features to create HTML templates in a - **Declarative syntax** - The declarative syntax helps you write valid HTML markup. -- **Template system** - You can scaffold your written code into various, reusable layouts to create an entire template. +- **Template system** - You can scaffold your written code into various, reusable views to create an entire template. - **Dynamic context** - Apply context to your template to process content dynamically. -- **Preprocess content** - The static content of the template will be preprocessed, to spare time and performance, when the template is executed. - - **Language localization** - Specify the parts of the template, that should be translated or formatted for local languages and cultures. - **UI components** - Construct user interfaces with the components library. +- **Symbol bundle** - Use the symbols wich come within the framework. ## Integration @@ -37,9 +36,9 @@ The framework comes with an intergration for the web framework [Vapor](https://s - - -- -- -- +- +- +- ### Plugins diff --git a/Sources/HTMLKit/HTMLKit.docc/Plugins/ComponentsPlugin.md b/Sources/HTMLKit/HTMLKit.docc/Plugins/ComponentsPlugin.md index 857f1acc..fdc868b1 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Plugins/ComponentsPlugin.md +++ b/Sources/HTMLKit/HTMLKit.docc/Plugins/ComponentsPlugin.md @@ -1,14 +1,14 @@ # Use the components -Deploys the CSS files +Deploys the components dependencies ## Overview -The framework comes with a plugin, wich minifies and deploys the CSS files of the components into the public directory of your Vapor project. +The framework comes with a plugin, wich minifies and deploys the dependencies of the components into the public directory of your Vapor project. ### Command -Use the following command in your terminal: +Use the following command in your terminal to start the deployment. ```sh swift package --allow-writing-to-package-directory deploy diff --git a/Sources/HTMLKit/HTMLKit.docc/Plugins/ConverterPlugin.md b/Sources/HTMLKit/HTMLKit.docc/Plugins/ConverterPlugin.md index e425cfa0..74540fc8 100644 --- a/Sources/HTMLKit/HTMLKit.docc/Plugins/ConverterPlugin.md +++ b/Sources/HTMLKit/HTMLKit.docc/Plugins/ConverterPlugin.md @@ -8,7 +8,7 @@ The framework comes with a plugin, wich converts HTML markup into the HTMLKit sy ### Command -Use the following command in your terminal: +Use the following command in your terminal to start the conversion. ```sh swift package --allow-writing-to-package-directory convert --source-path [source-path] --target-path [target-path] --output-option debug diff --git a/Sources/HTMLKitComponents/Actions.swift b/Sources/HTMLKitComponents/Actions.swift index de28d9e0..aed9d6b2 100644 --- a/Sources/HTMLKitComponents/Actions.swift +++ b/Sources/HTMLKitComponents/Actions.swift @@ -8,6 +8,8 @@ public enum Actions { case show(_ target: String) case hide(_ target: String) case animate(_ target: String) + case open(_ target: String) + case close(_ target: String) public var script: String { @@ -20,21 +22,32 @@ public enum Actions { case .animate(let target): return animate(target) + + case .open(let target): + return open(target) + + case .close(let target): + return close(target) } } private func show(_ target: String) -> String { - return "$('#\(target)').show();" } private func hide(_ target: String) -> String { - return "$('#\(target)').hide();" } private func animate(_ target: String) -> String { - return "$('#\(target)').animate();" } + + private func open(_ target: String) -> String { + return "$('#\(target)').open();" + } + + private func close(_ target: String) -> String { + return "$('#\(target)').close();" + } } diff --git a/Sources/HTMLKitComponents/Components/Button.swift b/Sources/HTMLKitComponents/Components/Button.swift index b5a5d3c5..c42f56a7 100644 --- a/Sources/HTMLKitComponents/Components/Button.swift +++ b/Sources/HTMLKitComponents/Components/Button.swift @@ -7,215 +7,150 @@ import HTMLKit import Foundation /// A component that initiates an action. -public struct ActionButton: Component { +public struct Button: View, Modifiable, Actionable { - /// The url path of the target. - internal let destination: TemplateValue + internal var id: String? + + /// The role of the button + internal var role: HTMLKit.Values.Button /// The content of the button. - internal var content: [AnyContent] + internal var content: [Content] /// The classes of the button. internal var classes: [String] - /// The events of the button. internal var events: [String]? /// Creates a action button. - public init(destination: TemplateValue, @ContentBuilder content: () -> [AnyContent]) { + public init(role: HTMLKit.Values.Button, @ContentBuilder content: () -> [Content]) { - self.destination = destination + self.role = role self.content = content() self.classes = ["button"] } /// Creates a action button. - internal init(destination: TemplateValue, content: [AnyContent], classes: [String], events: [String]?) { + internal init(role: HTMLKit.Values.Button, content: [Content], classes: [String], events: [String]?) { - self.destination = destination + self.role = role self.content = content self.classes = classes self.events = events } - public var body: AnyContent { - Anchor { + public var body: Content { + HTMLKit.Button { self.content } - .reference(self.destination.rawValue) + .type(role) .class(self.classes.joined(separator: " ")) - .role(.button) - } - - /// The behaviour of the button. - public var scripts: AnyContent { - + .modify(unwrap: id) { + $0.id($1) + } if let events = self.events { - return [self.content.scripts, Script { events }] + Script { + events + } } - - return [self.content.scripts] - } -} - -extension ActionButton: ButtonModifier { - - public func buttonSize(_ size: Tokens.ButtonSize) -> ActionButton { - - var newSelf = self - newSelf.classes.append(size.rawValue) - - return newSelf } - public func borderShape(_ shape: Tokens.BorderShape) -> ActionButton { - - var newSelf = self - newSelf.classes.append(shape.rawValue) - - return newSelf - } - - public func buttonStyle(_ style: Tokens.ButtonStyle) -> ActionButton { - - var newSelf = self - newSelf.classes.append(style.rawValue) - - return newSelf - } - - public func backgroundColor(_ color: Tokens.BackgroundColor) -> ActionButton { - - var newSelf = self - newSelf.classes.append(color.rawValue) - - return newSelf + public func id(_ value: String) -> Button { + return self.mutate(id: value) } } -/// A component that initiates a form submit. -public struct SubmitButton: Component { +extension Button: ButtonModifier { - /// The content of the button. - internal var content: [AnyContent] + public func buttonSize(_ size: Tokens.ButtonSize) -> Button { + return self.mutate(buttonsize: size.rawValue) + } - /// The classes of the button. - internal var classes: [String] + public func borderShape(_ shape: Tokens.BorderShape) -> Button { + return self.mutate(bordershape: shape.rawValue) + } - /// Creates a submit button. - public init(@ContentBuilder content: () -> [AnyContent]) { - - self.content = content() - self.classes = ["button"] + public func buttonStyle(_ style: Tokens.ButtonStyle) -> Button { + return self.mutate(buttonstyle: style.rawValue) } - public var body: AnyContent { - Button { - self.content - } - .type(.submit) - .class(self.classes.joined(separator: " ")) + public func backgroundColor(_ color: Tokens.BackgroundColor) -> Button { + return self.mutate(backgroundcolor: color.rawValue) } } -extension SubmitButton: ButtonModifier { +extension Button: PressModifier { - public func buttonSize(_ size: Tokens.ButtonSize) -> SubmitButton { - - var newSelf = self - newSelf.classes.append(size.rawValue) - - return newSelf - } - - public func borderShape(_ shape: Tokens.BorderShape) -> SubmitButton { - - var newSelf = self - newSelf.classes.append(shape.rawValue) - - return newSelf + public func onClick(perfom action: Actions) -> Button { + return self.mutate(clickevent: action.script) } - public func buttonStyle(_ style: Tokens.ButtonStyle) -> SubmitButton { - - var newSelf = self - newSelf.classes.append(style.rawValue) - - return newSelf + public func onTap(perfom action: Actions) -> Button { + return self.mutate(tapevent: action.script) } - public func backgroundColor(_ color: Tokens.BackgroundColor) -> SubmitButton { - - var newSelf = self - newSelf.classes.append(color.rawValue) - - return newSelf + public func onPress(perfom action: Actions) -> Button { + return self.mutate(pressevent: action.script) } } -/// A component that initiates a form reset. -public struct ResetButton: Component { +/// A component that initiates an action. +public struct LinkButton: View, Modifiable { + + /// The url path of the target. + internal let destination: String /// The content of the button. - internal var content: [AnyContent] + internal var content: [Content] /// The classes of the button. internal var classes: [String] - /// Creates a reset button. - public init(@ContentBuilder content: () -> [AnyContent]) { + /// The events of the button. + internal var events: [String]? + + /// Creates a action button. + public init(destination: String, @ContentBuilder content: () -> [Content]) { + self.destination = destination self.content = content() self.classes = ["button"] } - /// Creates a sbumit button. - internal init(content: [AnyContent], classes: [String]) { + /// Creates a action button. + internal init(destination: String, content: [Content], classes: [String], events: [String]?) { + self.destination = destination self.content = content self.classes = classes + self.events = events } - - public var body: AnyContent { - Button { + + public var body: Content { + Anchor { self.content } - .type(.reset) + .reference(self.destination) .class(self.classes.joined(separator: " ")) + .role(.button) } } -extension ResetButton: ButtonModifier { +extension LinkButton: ButtonModifier { - public func buttonSize(_ size: Tokens.ButtonSize) -> ResetButton { - - var newSelf = self - newSelf.classes.append(size.rawValue) - - return newSelf + public func buttonSize(_ size: Tokens.ButtonSize) -> LinkButton { + return self.mutate(buttonsize: size.rawValue) } - public func borderShape(_ shape: Tokens.BorderShape) -> ResetButton { - - var newSelf = self - newSelf.classes.append(shape.rawValue) - - return newSelf + public func borderShape(_ shape: Tokens.BorderShape) -> LinkButton { + return self.mutate(bordershape: shape.rawValue) } - public func buttonStyle(_ style: Tokens.ButtonStyle) -> ResetButton { - - var newSelf = self - newSelf.classes.append(style.rawValue) - - return newSelf + public func buttonStyle(_ style: Tokens.ButtonStyle) -> LinkButton { + return self.mutate(buttonstyle: style.rawValue) } - public func backgroundColor(_ color: Tokens.BackgroundColor) -> ResetButton { - - var newSelf = self - newSelf.classes.append(color.rawValue) - - return newSelf + public func backgroundColor(_ color: Tokens.BackgroundColor) -> LinkButton { + return self.mutate(backgroundcolor: color.rawValue) } } diff --git a/Sources/HTMLKitComponents/Components/Card.swift b/Sources/HTMLKitComponents/Components/Card.swift new file mode 100644 index 00000000..2f73d355 --- /dev/null +++ b/Sources/HTMLKitComponents/Components/Card.swift @@ -0,0 +1,21 @@ +import HTMLKit + +public struct Card: View, Modifiable { + + internal var content: [Content] + + internal var classes: [String] + + public init(@ContentBuilder content: () -> [Content]) { + + self.content = content() + self.classes = ["card"] + } + + public var body: Content { + Division { + content + } + .class(self.classes.joined(separator: " ")) + } +} diff --git a/Sources/HTMLKitComponents/Components/Divider.swift b/Sources/HTMLKitComponents/Components/Divider.swift index 8eabd536..f40e6428 100644 --- a/Sources/HTMLKitComponents/Components/Divider.swift +++ b/Sources/HTMLKitComponents/Components/Divider.swift @@ -6,7 +6,7 @@ import HTMLKit /// A component that seperates content visually. -public struct Divider: Component { +public struct Divider: View { /// The classes of the divider. internal var classes: [String] @@ -21,7 +21,7 @@ public struct Divider: Component { self.classes = classes } - public var body: AnyContent { + public var body: Content { HorizontalRule() .class(classes.joined(separator: " ")) } diff --git a/Sources/HTMLKitComponents/Components/Form.swift b/Sources/HTMLKitComponents/Components/Form.swift index 5928e38c..3a5210fb 100644 --- a/Sources/HTMLKitComponents/Components/Form.swift +++ b/Sources/HTMLKitComponents/Components/Form.swift @@ -6,7 +6,9 @@ import HTMLKit /// A component that collects form controls. -public struct Form: Component { +public struct Form: View { + + internal var method: HTMLKit.Values.Method /// The content of the container. internal var content: [FormElement] @@ -18,47 +20,39 @@ public struct Form: Component { internal var events: [String]? /// Creates a form container. - public init(@ContentBuilder content: () -> [FormElement]) { + public init(method: Values.Method, @ContentBuilder content: () -> [FormElement]) { + self.method = method self.content = content() self.classes = ["form"] } /// Creates a form container. - internal init(content: [FormElement], classes: [String], events: [String]?) { + internal init(method: Values.Method, content: [FormElement], classes: [String], events: [String]?) { + self.method = method self.content = content self.classes = classes self.events = events } - public var body: AnyContent { + public var body: Content { HTMLKit.Form { content } - .method(.post) + .method(method) .class(classes.joined(separator: " ")) } - - /// The behaviour of the container. - public var scripts: AnyContent { - - if let events = self.events { - return [content.scripts, Script { events }] - } - - return [content.scripts] - } } /// A component that displays the name of the form control. -public struct FieldLabel: Component { +public struct FieldLabel: View { /// The identifier of the element the label is related to. - internal let id: TemplateValue + internal let id: String /// The content of the label. - internal var content: [AnyContent] + internal var content: [Content] /// The classes of the label. internal var classes: [String] @@ -67,7 +61,7 @@ public struct FieldLabel: Component { internal var events: [String]? /// Creates a field label. - public init(for id: TemplateValue, @ContentBuilder content: () -> [AnyContent]) { + public init(for id: String, @ContentBuilder content: () -> [Content]) { self.id = id self.content = content() @@ -75,7 +69,7 @@ public struct FieldLabel: Component { } /// Creates a field label. - internal init(for id: TemplateValue, content: [AnyContent], classes: [String], events: [String]?) { + internal init(for id: String, content: [Content], classes: [String], events: [String]?) { self.id = id self.content = content @@ -83,23 +77,23 @@ public struct FieldLabel: Component { self.events = events } - public var body: AnyContent { + public var body: Content { Label { content } - .for(id.rawValue) + .for(id) .class(classes.joined(separator: " ")) } } /// A component that displays an editable form control. -public struct TextField: Component { +public struct TextField: View, Modifiable { /// The identifier of the field. - internal let name: TemplateValue + internal let name: String /// The content of the field. - internal let value: TemplateValue + internal let value: String? /// The classes of the field. internal var classes: [String] @@ -108,7 +102,7 @@ public struct TextField: Component { internal var events: [String]? /// Creates a text field. - public init(name: TemplateValue, value: TemplateValue = .constant(nil)) { + public init(name: String, value: String? = nil) { self.name = name self.value = value @@ -116,7 +110,7 @@ public struct TextField: Component { } /// Creates a text field. - internal init(name: TemplateValue, value: TemplateValue, classes: [String], events: [String]?) { + internal init(name: String, value: String?, classes: [String], events: [String]?) { self.name = name self.value = value @@ -124,7 +118,7 @@ public struct TextField: Component { self.events = events } - public var body: AnyContent { + public var body: Content { Input() .type(.text) .id(name) @@ -134,42 +128,24 @@ public struct TextField: Component { $0.value($1) } } - - /// The behaviour of the text field. - public var scripts: AnyContent { - - if let events = self.events { - return [Script { events }] - } - - return [] - } } extension TextField: InputModifier { public func borderShape(_ shape: Tokens.BorderShape) -> TextField { - - var newSelf = self - newSelf.classes.append(shape.rawValue) - - return newSelf + return self.mutate(bordershape: shape.rawValue) } public func backgroundColor(_ color: Tokens.BackgroundColor) -> TextField { - - var newSelf = self - newSelf.classes.append(color.rawValue) - - return newSelf + return self.mutate(backgroundcolor: color.rawValue) } } /// A component that displays a editable and expandable form control. -public struct TextEditor: Component { +public struct TextEditor: View, Modifiable { /// The identifier of the editor. - internal let name: TemplateValue + internal let name: String /// The number of lines. internal var rows: Int = 1 @@ -184,7 +160,7 @@ public struct TextEditor: Component { internal var events: [String]? /// Creates a text editor. - public init(name: TemplateValue, @ContentBuilder content: () -> [String]) { + public init(name: String, @ContentBuilder content: () -> [String]) { self.name = name self.content = content() @@ -192,7 +168,7 @@ public struct TextEditor: Component { } /// Creates a text editor. - internal init(name: TemplateValue, rows: Int, content: [String], classes: [String], events: [String]?) { + internal init(name: String, rows: Int, content: [String], classes: [String], events: [String]?) { self.name = name self.rows = rows @@ -201,7 +177,7 @@ public struct TextEditor: Component { self.events = events } - public var body: AnyContent { + public var body: Content { TextArea { content } @@ -211,16 +187,6 @@ public struct TextEditor: Component { .rows(rows) } - /// The behaviour of the editor. - public var scripts: AnyContent { - - if let events = self.events { - return [content.scripts, Script { events }] - } - - return [content.scripts] - } - /// Sets the limit of the maximum lines. public func lineLimit(_ value: Int) -> TextEditor { @@ -234,36 +200,28 @@ public struct TextEditor: Component { extension TextEditor: InputModifier { public func borderShape(_ shape: Tokens.BorderShape) -> TextEditor { - - var newSelf = self - newSelf.classes.append(shape.rawValue) - - return newSelf + return self.mutate(bordershape: shape.rawValue) } public func backgroundColor(_ color: Tokens.BackgroundColor) -> TextEditor { - - var newSelf = self - newSelf.classes.append(color.rawValue) - - return newSelf + return self.mutate(backgroundcolor: color.rawValue) } } /// A component that displays a form control -public struct CheckField: Component { +public struct CheckField: View, Modifiable { /// The identifier of the field. - internal let name: TemplateValue + internal let name: String /// The content of the field. - internal let value: TemplateValue + internal let value: String /// The classes of the field. internal var classes: [String] /// Creates a check field. - public init(name: TemplateValue, value: TemplateValue) { + public init(name: String, value: String) { self.name = name self.value = value @@ -271,14 +229,14 @@ public struct CheckField: Component { } /// Creates a check field. - internal init(name: TemplateValue, value: TemplateValue, classes: [String]) { + internal init(name: String, value: String, classes: [String]) { self.name = name self.value = value self.classes = classes } - public var body: AnyContent { + public var body: Content { Input() .type(.checkbox) .id(name) @@ -291,36 +249,28 @@ public struct CheckField: Component { extension CheckField: InputModifier { public func borderShape(_ shape: Tokens.BorderShape) -> CheckField { - - var newSelf = self - newSelf.classes.append(shape.rawValue) - - return newSelf + return self.mutate(bordershape: shape.rawValue) } public func backgroundColor(_ color: Tokens.BackgroundColor) -> CheckField { - - var newSelf = self - newSelf.classes.append(color.rawValue) - - return newSelf + return self.mutate(backgroundcolor: color.rawValue) } } /// A component that displays -public struct RadioSelect: Component { +public struct RadioSelect: View, Modifiable { /// The identifier of the select. - internal let name: TemplateValue + internal let name: String /// The content of the select. - internal let value: TemplateValue + internal let value: String /// The classes of the select. internal var classes: [String] /// Creates a radio select. - public init(name: TemplateValue, value: TemplateValue) { + public init(name: String, value: String) { self.name = name self.value = value @@ -328,14 +278,14 @@ public struct RadioSelect: Component { } /// Creates a radio select. - internal init(name: TemplateValue, value: TemplateValue, classes: [String]) { + internal init(name: String, value: String, classes: [String]) { self.name = name self.value = value self.classes = classes } - public var body: AnyContent { + public var body: Content { Input() .type(.radio) .id(name) @@ -348,27 +298,19 @@ public struct RadioSelect: Component { extension RadioSelect: InputModifier { public func borderShape(_ shape: Tokens.BorderShape) -> RadioSelect { - - var newSelf = self - newSelf.classes.append(shape.rawValue) - - return newSelf + return self.mutate(bordershape: shape.rawValue) } public func backgroundColor(_ color: Tokens.BackgroundColor) -> RadioSelect { - - var newSelf = self - newSelf.classes.append(color.rawValue) - - return newSelf + return self.mutate(backgroundcolor: color.rawValue) } } /// A component that displays -public struct SelectField: Component { +public struct SelectField: View, Modifiable { /// The identifier of the field. - internal let name: TemplateValue + internal let name: String /// The content of the field. internal var content: [InputElement] @@ -380,7 +322,7 @@ public struct SelectField: Component { internal var events: [String]? /// Creates a select field. - public init(name: TemplateValue, @ContentBuilder content: () -> [InputElement]) { + public init(name: String, @ContentBuilder content: () -> [InputElement]) { self.name = name self.content = content() @@ -388,7 +330,7 @@ public struct SelectField: Component { } /// Creates a select field. - internal init(name: TemplateValue, content: [InputElement], classes: [String], events: [String]?) { + internal init(name: String, content: [InputElement], classes: [String], events: [String]?) { self.name = name self.content = content @@ -396,7 +338,7 @@ public struct SelectField: Component { self.events = events } - public var body: AnyContent { + public var body: Content { Select { content } @@ -404,45 +346,27 @@ public struct SelectField: Component { .name(name) .class(classes.joined(separator: " ")) } - - /// The behaviour of the field. - public var scripts: AnyContent { - - if let events = self.events { - return [content.scripts, Script { events }] - } - - return [content.scripts] - } } extension SelectField: InputModifier { public func borderShape(_ shape: Tokens.BorderShape) -> SelectField { - - var newSelf = self - newSelf.classes.append(shape.rawValue) - - return newSelf + return self.mutate(bordershape: shape.rawValue) } public func backgroundColor(_ color: Tokens.BackgroundColor) -> SelectField { - - var newSelf = self - newSelf.classes.append(color.rawValue) - - return newSelf + return self.mutate(backgroundcolor: color.rawValue) } } /// A component that displays -public struct SecureField: Component { +public struct SecureField: View, Modifiable { /// The identifier of the field. - internal let name: TemplateValue + internal let name: String /// The content of the field. - internal let value: TemplateValue + internal let value: String? /// The classes of the field. internal var classes: [String] @@ -451,7 +375,7 @@ public struct SecureField: Component { internal var events: [String]? /// Creates a password field. - public init(name: TemplateValue, value: TemplateValue = .constant(nil)) { + public init(name: String, value: String? = nil) { self.name = name self.value = value @@ -459,7 +383,7 @@ public struct SecureField: Component { } /// Creates a password field. - internal init(name: TemplateValue, value: TemplateValue, classes: [String], events: [String]?) { + internal init(name: String, value: String?, classes: [String], events: [String]?) { self.name = name self.value = value @@ -467,7 +391,7 @@ public struct SecureField: Component { self.events = events } - public var body: AnyContent { + public var body: Content { Input() .type(.password) .id(name) @@ -477,42 +401,24 @@ public struct SecureField: Component { $0.value($1) } } - - /// The behaviour of the field. - public var scripts: AnyContent { - - if let events = self.events { - return [Script { events }] - } - - return [] - } } extension SecureField: InputModifier { public func borderShape(_ shape: Tokens.BorderShape) -> SecureField { - - var newSelf = self - newSelf.classes.append(shape.rawValue) - - return newSelf + return self.mutate(bordershape: shape.rawValue) } public func backgroundColor(_ color: Tokens.BackgroundColor) -> SecureField { - - var newSelf = self - newSelf.classes.append(color.rawValue) - - return newSelf + return self.mutate(backgroundcolor: color.rawValue) } } /// A component that displays -public struct Slider: Component { +public struct Slider: View { /// The identifier of the slider. - internal let name: TemplateValue + internal let name: String /// The classes of the slider. internal var classes: [String] @@ -521,47 +427,37 @@ public struct Slider: Component { internal var events: [String]? /// Creates a slider. - public init(name: TemplateValue) { + public init(name: String) { self.name = name self.classes = ["input", "type:slider"] } /// Creates a slider. - internal init(name: TemplateValue, classes: [String], events: [String]?) { + internal init(name: String, classes: [String], events: [String]?) { self.name = name self.classes = classes self.events = events } - public var body: AnyContent { + public var body: Content { Input() .type(.range) .id(name) .name(name) .class(classes.joined(separator: " ")) } - - /// The behaviour of the slider. - public var scripts: AnyContent { - - if let events = self.events { - return [Script { events }] - } - - return [] - } } /// A component that displays -public struct DatePicker: Component { +public struct DatePicker: View, Modifiable { /// The identifier of the picker. - internal let name: TemplateValue + internal let name: String /// The content of the picker. - internal let value: TemplateValue + internal let value: String? /// The classes of the picker. internal var classes: [String] @@ -570,7 +466,7 @@ public struct DatePicker: Component { internal var events: [String]? /// Creates a date picker. - public init(name: TemplateValue, value: TemplateValue = .constant(nil)) { + public init(name: String, value: String? = nil) { self.name = name self.value = value @@ -578,7 +474,7 @@ public struct DatePicker: Component { } /// Creates a date picker. - internal init(name: TemplateValue, value: TemplateValue, classes: [String], events: [String]?) { + internal init(name: String, value: String?, classes: [String], events: [String]?) { self.name = name self.value = value @@ -586,7 +482,7 @@ public struct DatePicker: Component { self.events = events } - public var body: AnyContent { + public var body: Content { Input() .type(.date) .id(name) @@ -596,45 +492,27 @@ public struct DatePicker: Component { $0.value($1) } } - - /// The behaviour of the picker. - public var scripts: AnyContent { - - if let events = self.events { - return [Script { events }] - } - - return [] - } } extension DatePicker: InputModifier { public func borderShape(_ shape: Tokens.BorderShape) -> DatePicker { - - var newSelf = self - newSelf.classes.append(shape.rawValue) - - return newSelf + return self.mutate(bordershape: shape.rawValue) } public func backgroundColor(_ color: Tokens.BackgroundColor) -> DatePicker { - - var newSelf = self - newSelf.classes.append(color.rawValue) - - return newSelf + return self.mutate(backgroundcolor: color.rawValue) } } /// A component that displays -public struct SearchField: Component { +public struct SearchField: View, Modifiable { /// The identifier of the search field. - internal let name: TemplateValue + internal let name: String /// The content of the field. - internal let value: TemplateValue + internal let value: String? /// The classes of the field. internal var classes: [String] @@ -643,7 +521,7 @@ public struct SearchField: Component { internal var events: [String]? /// Creates a search field. - public init(name: TemplateValue, value: TemplateValue = .constant(nil)) { + public init(name: String, value: String? = nil) { self.name = name self.value = value @@ -651,7 +529,7 @@ public struct SearchField: Component { } /// Creates a search field. - internal init(name: TemplateValue, value: TemplateValue, classes: [String], events: [String]?) { + internal init(name: String, value: String?, classes: [String], events: [String]?) { self.name = name self.value = value @@ -659,7 +537,7 @@ public struct SearchField: Component { self.events = events } - public var body: AnyContent { + public var body: Content { Input() .type(.search) .id(name) @@ -669,47 +547,28 @@ public struct SearchField: Component { $0.value($1) } } - - /// The behaviour of the field. - public var scripts: AnyContent { - - if let events = self.events { - return [Script { events }] - } - - return [] - } } extension SearchField: InputModifier { public func borderShape(_ shape: Tokens.BorderShape) -> SearchField { - - var newSelf = self - newSelf.classes.append(shape.rawValue) - - return newSelf + return self.mutate(bordershape: shape.rawValue) } public func backgroundColor(_ color: Tokens.BackgroundColor) -> SearchField { - - var newSelf = self - newSelf.classes.append(color.rawValue) - - return newSelf + return self.mutate(backgroundcolor: color.rawValue) } } /// A component that displays the progress of a task. -public struct ProgressView: Component { +public struct Progress: View { - /// The identifier of the progress view. - internal let name: TemplateValue + internal let maximum: Float - internal let value: TemplateValue + internal let value: String /// The content of the view. - internal var content: [AnyContent] + internal var content: [Content] /// The classes of the view. internal var classes: [String] @@ -718,41 +577,30 @@ public struct ProgressView: Component { internal var events: [String]? /// Creates a progress view. - public init(name: TemplateValue, value: TemplateValue = .constant(nil), @ContentBuilder content: () -> [AnyContent]) { + public init(maximum: Float, value: Float, @ContentBuilder content: () -> [Content]) { - self.name = name - self.value = value + self.maximum = maximum + self.value = String(value) self.content = content() self.classes = ["progress"] } /// Creates a progress bar. - internal init(name: TemplateValue, value: TemplateValue, content: [AnyContent], classes: [String], events: [String]?) { + internal init(maximum: Float, value: String, content: [Content], classes: [String], events: [String]?) { - self.name = name + self.maximum = maximum self.value = value self.content = content self.classes = classes self.events = events } - public var body: AnyContent { - Progress { + public var body: Content { + HTMLKit.Progress { content } + .value(value) + .maximum(maximum) .class(classes.joined(separator: " ")) - .modify(unwrap: value) { - $0.value($1) - } - } - - /// The behaviour of the view. - public var scripts: AnyContent { - - if let events = self.events { - return [Script { events }] - } - - return [] } } diff --git a/Sources/HTMLKitComponents/Components/Collection.swift b/Sources/HTMLKitComponents/Components/Grid.swift similarity index 55% rename from Sources/HTMLKitComponents/Components/Collection.swift rename to Sources/HTMLKitComponents/Components/Grid.swift index c0a79454..7d84f0d5 100644 --- a/Sources/HTMLKitComponents/Components/Collection.swift +++ b/Sources/HTMLKitComponents/Components/Grid.swift @@ -6,7 +6,9 @@ import HTMLKit /// A component that collects and arranges collection items horizontally. -public struct Collection: Component { +public struct Grid: View, Actionable { + + internal var id: String? /// The content of the collection. internal var content: [ListElement] @@ -14,92 +16,100 @@ public struct Collection: Component { /// The classes of the collection. internal var classes: [String] - /// The events of the collection. internal var events: [String]? /// Creates a collection. public init(ratio: Tokens.ItemRatio = .half, @ContentBuilder content: () -> [ListElement]) { self.content = content() - self.classes = ["collection", ratio.rawValue] + self.classes = ["grid", ratio.rawValue] } /// Creates a collection. - internal init(content: [ListElement], classes: [String], events: [String]?) { + internal init(content: [ListElement], classes: [String], events: [String]?, id: String?) { self.content = content self.classes = classes self.events = events + self.id = id } - public var body: AnyContent { + public var body: Content { UnorderedList { content } .class(classes.joined(separator: " ")) - } - - /// The behaviour of the collection. - public var scripts: AnyContent { - + .modify(unwrap: id) { + $0.id($1) + } if let events = self.events { - return [content.scripts, Script { events }] + Script { + events + } } - - return [content.scripts] } - /// Sets the style for the collection. - public func collectionStyle(_ style: Tokens.CollectionStyle) -> Collection { - - var newSelf = self - newSelf.classes.append(style.rawValue) - - return newSelf + public func id(_ value: String) -> Grid { + return self.mutate(id: value) } } /// A component that represents a collection item. -public struct CollectionItem: Component { +public struct GridItem: View, Actionable { + + internal var id: String? /// The content of the item. - internal var content: [AnyContent] + internal var content: [Content] /// The classes for the item. internal var classes: [String] - /// The events of the item. internal var events: [String]? /// Creates a collection item. - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() - self.classes = ["collection-item"] + self.classes = ["grid-item"] } /// Creates a collection item. - internal init(content: [AnyContent], classes: [String], events: [String]?) { + internal init(content: [Content], classes: [String], events: [String]?, id: String?) { self.content = content self.classes = classes self.events = events + self.id = id } - public var body: AnyContent { + public var body: Content { ListItem { content } .class(classes.joined(separator: " ")) - } - - /// The behaviour of the collection. - public var scripts: AnyContent { - + .modify(unwrap: id) { + $0.id($1) + } if let events = self.events { - return [content.scripts, Script { events }] + Script { + events + } } - - return [content.scripts] + } + + public func id(_ value: String) -> GridItem { + return self.mutate(id: value) + } +} + +extension GridItem: HoverModifier { + + public func onHover(perfom action: Actions) -> GridItem { + return self.mutate(hoverevent: action.script) + } + + public func onLeave(perfom action: Actions) -> GridItem { + return self.mutate(leaveevent: action.script) } } diff --git a/Sources/HTMLKitComponents/Components/Group.swift b/Sources/HTMLKitComponents/Components/Group.swift index a7e0b81d..46e2c03c 100644 --- a/Sources/HTMLKitComponents/Components/Group.swift +++ b/Sources/HTMLKitComponents/Components/Group.swift @@ -5,112 +5,71 @@ import HTMLKit /// A component that collects content. -public struct Group: Component { +public struct Group: View, Modifiable { /// The content of the group. - internal var content: [AnyContent] + internal var content: [Content] /// The classes of the group. internal var classes: [String] /// Creates a group. - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() self.classes = ["group"] } /// Creates a group. - internal init(content: [AnyContent], classes: [String]) { + internal init(content: [Content], classes: [String]) { self.content = content self.classes = classes } - public var body: AnyContent { + public var body: Content { Division { content } .class(classes.joined(separator: " ")) } - - /// The behaviour of the group. - public var scripts: AnyContent { - return [content.scripts] - } } extension Group: TextModifier { public func font(_ style: Tokens.TextStyle) -> Group { - - var newSelf = self - newSelf.classes.append(style.rawValue) - - return newSelf + return self.mutate(font: style.rawValue) } public func foregroundColor(_ color: Tokens.ForegroundColor) -> Group { - - var newSelf = self - newSelf.classes.append(color.rawValue) - - return newSelf + return self.mutate(foregroundcolor: color.rawValue) } public func fontSize(_ size: Tokens.FontSize) -> Group { - - var newSelf = self - newSelf.classes.append(size.rawValue) - - return newSelf + return self.mutate(fontsize: size.rawValue) } public func fontWeight(_ weight: Tokens.FontWeight) -> Group { - - var newSelf = self - newSelf.classes.append(weight.rawValue) - - return newSelf + return self.mutate(fontweight: weight.rawValue) } public func fontTransformation(_ transformation: Tokens.TextTransformation) -> Group { - - var newSelf = self - newSelf.classes.append(transformation.rawValue) - - return newSelf + return self.mutate(fonttransformation: transformation.rawValue) } public func fontStyle(_ style: Tokens.FontStyle) -> Group { - - var newSelf = self - newSelf.classes.append(style.rawValue) - - return newSelf + return self.mutate(fontstyle: style.rawValue) } public func bold() -> Group { - - var newSelf = self - newSelf.classes.append(Tokens.FontWeight.bold.rawValue) - - return newSelf + return self.mutate(bold: Tokens.FontWeight.bold.rawValue) } public func italic() -> Group { - - var newSelf = self - newSelf.classes.append(Tokens.FontStyle.italic.rawValue) - - return newSelf + return self.mutate(italic: Tokens.FontStyle.italic.rawValue) } public func underline() -> Group { - - var newSelf = self - newSelf.classes.append(Tokens.TextDecoration.underline.rawValue) - - return newSelf + return self.mutate(underline: Tokens.TextDecoration.underline.rawValue) } } diff --git a/Sources/HTMLKitComponents/Components/Image.swift b/Sources/HTMLKitComponents/Components/Image.swift index 033cf4b4..14aa4820 100644 --- a/Sources/HTMLKitComponents/Components/Image.swift +++ b/Sources/HTMLKitComponents/Components/Image.swift @@ -6,32 +6,32 @@ import HTMLKit /// A component that displays an image. -public struct Image: Component { +public struct Image: View, Modifiable { /// The url path of the image. - internal let source: TemplateValue + internal let source: String /// The classes of the image view. internal var classes: [String] /// Creates a image view. - public init(source: TemplateValue) { + public init(source: String) { self.source = source self.classes = ["image"] } /// Creates a image view. - internal init(source: TemplateValue, classes: [String]) { + internal init(source: String, classes: [String]) { self.source = source self.classes = classes } - public var body: AnyContent { + public var body: Content { Division { HTMLKit.Image() - .source(source.rawValue) + .source(source) .role(.img) } .class(classes.joined(separator: " ")) @@ -41,53 +41,29 @@ public struct Image: Component { extension Image: ImageModifier { public func objectFit(_ fit: Tokens.ObjectFit) -> Image { - - var newSelf = self - newSelf.classes.append(fit.rawValue) - - return newSelf + return self.mutate(objectfit: fit.rawValue) } public func imageScale(_ scale: Tokens.ImageScale) -> Image { - - var newSelf = self - newSelf.classes.append(scale.rawValue) - - return newSelf + return self.mutate(imagescale: scale.rawValue) } public func clipShape(_ shape: Tokens.ClipShape) -> Image { - - var newSelf = self - newSelf.classes.append(shape.rawValue) - - return newSelf + return self.mutate(clipshape: shape.rawValue) } } extension Image: ViewModifier { public func backgroundColor(_ color: Tokens.BackgroundColor) -> Image { - - var newSelf = self - newSelf.classes.append(color.rawValue) - - return newSelf + return self.mutate(backgroundcolor: color.rawValue) } public func zIndex(_ index: Tokens.PositionIndex) -> Image { - - var newSelf = self - newSelf.classes.append(index.rawValue) - - return newSelf + return self.mutate(zindex: index.rawValue) } public func opacity(_ value: Tokens.OpacityValue) -> Image { - - var newSelf = self - newSelf.classes.append(value.rawValue) - - return newSelf + return self.mutate(opacity: value.rawValue) } } diff --git a/Sources/HTMLKitComponents/Components/Link.swift b/Sources/HTMLKitComponents/Components/Link.swift index 9630fe2c..842b8690 100644 --- a/Sources/HTMLKitComponents/Components/Link.swift +++ b/Sources/HTMLKitComponents/Components/Link.swift @@ -7,13 +7,13 @@ import HTMLKit import Foundation /// A component that navigates to an target. -public struct Link: Component { +public struct Link: View, Modifiable { /// The url path of the target. - internal let destination: TemplateValue + internal let destination: String /// The content of the link. - internal var content: [AnyContent] + internal var content: [Content] /// The classes of the link. internal var classes: [String] @@ -22,7 +22,7 @@ public struct Link: Component { internal var events: [String]? /// Creates a link. - public init(destination: TemplateValue, @ContentBuilder content: () -> [AnyContent]) { + public init(destination: String, @ContentBuilder content: () -> [Content]) { self.destination = destination self.content = content() @@ -30,7 +30,7 @@ public struct Link: Component { } /// Creates a link. - internal init(destination: TemplateValue, content: [AnyContent], classes: [String], events: [String]?) { + internal init(destination: String, content: [Content], classes: [String], events: [String]?) { self.destination = destination self.content = content @@ -38,96 +38,50 @@ public struct Link: Component { self.events = events } - public var body: AnyContent { + public var body: Content { Anchor { content } - .reference(destination.rawValue) + .reference(destination) .class(classes.joined(separator: " ")) } - - /// The behaviour of the link. - public var scripts: AnyContent { - - if let events = self.events { - return [content.scripts, Script { events }] - } - - return [content.scripts] - } } extension Link: TextModifier { public func font(_ style: Tokens.TextStyle) -> Link { - - var newSelf = self - newSelf.classes.append(style.rawValue) - - return newSelf + return self.mutate(font: style.rawValue) } public func foregroundColor(_ color: Tokens.ForegroundColor) -> Link { - - var newSelf = self - newSelf.classes.append(color.rawValue) - - return newSelf + return self.mutate(foregroundcolor: color.rawValue) } public func fontSize(_ size: Tokens.FontSize) -> Link { - - var newSelf = self - newSelf.classes.append(size.rawValue) - - return newSelf + return self.mutate(fontsize: size.rawValue) } public func fontWeight(_ weight: Tokens.FontWeight) -> Link { - - var newSelf = self - newSelf.classes.append(weight.rawValue) - - return newSelf + return self.mutate(fontweight: weight.rawValue) } public func fontTransformation(_ transformation: Tokens.TextTransformation) -> Link { - - var newSelf = self - newSelf.classes.append(transformation.rawValue) - - return newSelf + return self.mutate(fonttransformation: transformation.rawValue) } public func fontStyle(_ style: Tokens.FontStyle) -> Link { - - var newSelf = self - newSelf.classes.append(style.rawValue) - - return newSelf + return self.mutate(fontstyle: style.rawValue) } public func bold() -> Link { - - var newSelf = self - newSelf.classes.append(Tokens.FontWeight.bold.rawValue) - - return newSelf + return self.mutate(bold: Tokens.FontWeight.bold.rawValue) } public func italic() -> Link { - - var newSelf = self - newSelf.classes.append(Tokens.FontStyle.italic.rawValue) - - return newSelf + return self.mutate(italic: Tokens.FontStyle.italic.rawValue) } public func underline() -> Link { - - var newSelf = self - newSelf.classes.append(Tokens.TextDecoration.underline.rawValue) - - return newSelf + return self.mutate(underline: Tokens.TextDecoration.underline.rawValue) } } diff --git a/Sources/HTMLKitComponents/Components/List.swift b/Sources/HTMLKitComponents/Components/List.swift index c945a5f9..837f31e6 100644 --- a/Sources/HTMLKitComponents/Components/List.swift +++ b/Sources/HTMLKitComponents/Components/List.swift @@ -6,7 +6,9 @@ import HTMLKit /// A component that collects and arranges list items vertically. -public struct List: Component { +public struct List: View, Actionable { + + var id: String? /// The content of the list. internal var content: [ListElement] @@ -14,7 +16,6 @@ public struct List: Component { /// The classes of the list. internal var classes: [String] - /// The events of the list. internal var events: [String]? /// Creates a list. @@ -25,28 +26,27 @@ public struct List: Component { } /// Creates a list. - internal init(content: [ListElement], classes: [String], events: [String]?) { + internal init(content: [ListElement], classes: [String], events: [String]?, id: String?) { self.content = content self.classes = classes self.events = events + self.id = id } - public var body: AnyContent { + public var body: Content { UnorderedList { content } .class(classes.joined(separator: " ")) - } - - /// The behaviour of the list. - public var scripts: AnyContent { - + .modify(unwrap: id) { + $0.id($1) + } if let events = self.events { - return [content.scripts, Script { events }] + Script { + events + } } - - return [content.scripts] } /// Sets the style for the list. @@ -59,48 +59,77 @@ public struct List: Component { } } -/// A component that represents a list item. -public struct ListRow: Component { +extension List: HoverModifier { + + public func id(_ value: String) -> List { + return self.mutate(id: value) + } + public func onHover(perfom action: Actions) -> List { + return self.mutate(hoverevent: action.script) + } + + public func onLeave(perfom action: Actions) -> List { + return self.mutate(leaveevent: action.script) + } +} + +/// A component that represents a list item. +public struct ListRow: View, Actionable { + + var id: String? + /// The content of the row. - internal var content: [AnyContent] + internal var content: [Content] /// The classes of the row. internal var classes: [String] - /// The events of the row. internal var events: [String]? /// Creates a list row. - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() self.classes = ["list-row"] } /// Creates a list row. - internal init(content: [AnyContent], classes: [String], events: [String]?) { + internal init(content: [Content], classes: [String], events: [String]?, id: String?) { self.content = content self.classes = classes self.events = events + self.id = id } - public var body: AnyContent { + public var body: Content { ListItem { content } .class(classes.joined(separator: " ")) - } - - /// The behaviour of the row. - public var scripts: AnyContent { - + .modify(unwrap: id) { + $0.id($1) + } if let events = self.events { - return [content.scripts, Script { events }] + Script { + events + } } - - return [content.scripts] + } + + public func id(_ value: String) -> ListRow { + return self.mutate(id: value) } } +extension ListRow: HoverModifier { + + public func onHover(perfom action: Actions) -> ListRow { + return self.mutate(hoverevent: action.script) + } + + public func onLeave(perfom action: Actions) -> ListRow { + return self.mutate(leaveevent: action.script) + } +} diff --git a/Sources/HTMLKitComponents/Components/Modal.swift b/Sources/HTMLKitComponents/Components/Modal.swift new file mode 100644 index 00000000..0a415e45 --- /dev/null +++ b/Sources/HTMLKitComponents/Components/Modal.swift @@ -0,0 +1,37 @@ +import HTMLKit + +public struct Modal: View, Modifiable, Actionable { + + internal var id: String? + + internal var content: [Content] + + internal var classes: [String] + + internal var events: [String]? + + public init(@ContentBuilder content: () -> [Content]) { + + self.content = content() + self.classes = ["modal"] + } + + public var body: Content { + Dialog { + content + } + .class(classes.joined(separator: " ")) + .modify(unwrap: id) { + $0.id($1) + } + if let events = self.events { + Script { + events + } + } + } + + public func id(_ value: String) -> Modal { + return self.mutate(id: value) + } +} diff --git a/Sources/HTMLKitComponents/Components/Snippet.swift b/Sources/HTMLKitComponents/Components/Snippet.swift index ef7990ff..d7981022 100644 --- a/Sources/HTMLKitComponents/Components/Snippet.swift +++ b/Sources/HTMLKitComponents/Components/Snippet.swift @@ -6,10 +6,10 @@ import HTMLKit /// A component that displays code content. -public struct Snippet: Component { +public struct Snippet: View { /// The content of the snippet. - internal var content: [AnyContent] + internal var content: [Content] /// The classes of the snippet. internal var classes: [String] @@ -30,13 +30,13 @@ public struct Snippet: Component { } /// Creates a snippet. - internal init(content: [AnyContent], classes: [String]) { + internal init(content: [Content], classes: [String]) { self.content = content self.classes = classes } - public var body: AnyContent { + public var body: Content { PreformattedText { content } diff --git a/Sources/HTMLKitComponents/Components/Stack.swift b/Sources/HTMLKitComponents/Components/Stack.swift index 10afcef3..e5c098f2 100644 --- a/Sources/HTMLKitComponents/Components/Stack.swift +++ b/Sources/HTMLKitComponents/Components/Stack.swift @@ -6,38 +6,53 @@ import HTMLKit /// A component that arranges content horizontally. -public struct HStack: Component { +public struct HStack: View, Actionable, Modifiable { + + /// The identifier of the text. + internal var id: String? /// The content of the stack. - internal var content: [AnyContent] + internal var content: [Content] /// The classes of the stack. internal var classes: [String] + /// The events of the text. + internal var events: [String]? + /// Creates a horizontal stack. - public init(alignment: Tokens.VerticalAlignment = .center, @ContentBuilder content: () -> [AnyContent]) { + public init(alignment: Tokens.VerticalAlignment = .center, @ContentBuilder content: () -> [Content]) { self.content = content() self.classes = ["hstack", alignment.rawValue] } /// Creates a horizontal stack. - internal init(content: [AnyContent], classes: [String]) { + internal init(content: [Content], classes: [String], events: [String]?, id: String?) { self.content = content self.classes = classes + self.events = events + self.id = id } - public var body: AnyContent { + public var body: Content { Division { content } .class(classes.joined(separator: " ")) + .modify(unwrap: id) { + $0.id($1) + } + if let events = self.events { + Script { + events + } + } } - /// The behaviour of the stack. - public var scripts: AnyContent { - return [content.scripts] + public func id(_ value: String) -> HStack { + return self.mutate(id: value) } /// Sets the space of the content. @@ -50,212 +65,230 @@ public struct HStack: Component { } } +extension HStack: HoverModifier { + + public func onHover(perfom action: Actions) -> HStack { + return self.mutate(hoverevent: action.script) + } + + public func onLeave(perfom action: Actions) -> HStack { + return self.mutate(leaveevent: action.script) + } +} + extension HStack: ViewModifier { public func backgroundColor(_ color: Tokens.BackgroundColor) -> HStack { - - var newSelf = self - newSelf.classes.append(color.rawValue) - - return newSelf + return self.mutate(backgroundcolor: color.rawValue) } public func opacity(_ value: Tokens.OpacityValue) -> HStack { - - var newSelf = self - newSelf.classes.append(value.rawValue) - - return newSelf + return self.mutate(opacity: value.rawValue) } public func zIndex(_ index: Tokens.PositionIndex) -> HStack { - - var newSelf = self - newSelf.classes.append(index.rawValue) - - return newSelf + return self.mutate(zindex: index.rawValue) } } /// A component that arranges content vertically. -public struct VStack: Component { +public struct VStack: View, Actionable, Modifiable { + + var id: String? /// The content of the stack. - internal var content: [AnyContent] + internal var content: [Content] /// The classes of the stack. internal var classes: [String] + var events: [String]? + /// Creates a vertical stack. - public init(alignment: Tokens.HorizontalAlignment = .leading, @ContentBuilder content: () -> [AnyContent]) { + public init(alignment: Tokens.HorizontalAlignment = .leading, @ContentBuilder content: () -> [Content]) { self.content = content() self.classes = ["vstack", alignment.rawValue] } /// Creates a vertical stack. - internal init(content: [AnyContent], classes: [String]) { + internal init(content: [Content], classes: [String], events: [String]?, id: String?) { self.content = content self.classes = classes + self.events = events + self.id = id } - public var body: AnyContent { + public var body: Content { Division { content } .class(classes.joined(separator: " ")) + .modify(unwrap: id) { + $0.id($1) + } + if let events = self.events { + Script { + events + } + } } - /// The behaviour of the stack. - public var scripts: AnyContent { - return [content.scripts] + public func id(_ value: String) -> VStack { + return self.mutate(id: value) + } +} + +extension VStack: HoverModifier { + + public func onHover(perfom action: Actions) -> VStack { + return self.mutate(hoverevent: action.script) + } + + public func onLeave(perfom action: Actions) -> VStack { + return self.mutate(leaveevent: action.script) } } extension VStack: ViewModifier { public func backgroundColor(_ color: Tokens.BackgroundColor) -> VStack { - - var newSelf = self - newSelf.classes.append(color.rawValue) - - return newSelf + return self.mutate(backgroundcolor: color.rawValue) } public func opacity(_ value: Tokens.OpacityValue) -> VStack { - - var newSelf = self - newSelf.classes.append(value.rawValue) - - return newSelf + return self.mutate(opacity: value.rawValue) } public func zIndex(_ index: Tokens.PositionIndex) -> VStack { - - var newSelf = self - newSelf.classes.append(index.rawValue) - - return newSelf + return self.mutate(zindex: index.rawValue) } } /// A component that overlays content. -public struct ZStack: Component { +public struct ZStack: View, Actionable, Modifiable { + + var id: String? /// The content of the stack. - internal var content: [AnyContent] + internal var content: [Content] /// The classes of the stack. internal var classes: [String] + var events: [String]? + /// Creates a stack. - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() self.classes = ["zstack"] } /// Creates a stack. - internal init(content: [AnyContent], classes: [String]) { + internal init(content: [Content], classes: [String], events: [String]?, id: String?) { self.content = content self.classes = classes + self.events = events + self.id = id } - public var body: AnyContent { + public var body: Content { Division { content } .class(classes.joined(separator: " ")) + .modify(unwrap: id) { + $0.id($1) + } + if let events = self.events { + Script { + events + } + } } - /// The behaviour of the stack. - public var scripts: AnyContent { - return [content.scripts] + public func id(_ value: String) -> ZStack { + return self.mutate(id: value) + } +} + +extension ZStack: HoverModifier { + + public func onHover(perfom action: Actions) -> ZStack { + return self.mutate(hoverevent: action.script) + } + + public func onLeave(perfom action: Actions) -> ZStack { + return self.mutate(leaveevent: action.script) } } extension ZStack: ViewModifier { public func backgroundColor(_ color: Tokens.BackgroundColor) -> ZStack { - - var newSelf = self - newSelf.classes.append(color.rawValue) - - return newSelf + return self.mutate(backgroundcolor: color.rawValue) } public func opacity(_ value: Tokens.OpacityValue) -> ZStack { - - var newSelf = self - newSelf.classes.append(value.rawValue) - - return newSelf + return self.mutate(opacity: value.rawValue) } public func zIndex(_ index: Tokens.PositionIndex) -> ZStack { - - var newSelf = self - newSelf.classes.append(index.rawValue) - - return newSelf + return self.mutate(zindex: index.rawValue) } } /// A component that represents a stack column. -public struct StackColumn: Component { +public struct StackColumn: View { /// The content of the column. - internal var content: [AnyContent] + internal var content: [Content] /// The content of the column. internal var classes: [String] /// Creates a stack column. - public init(size: Tokens.ColumnSize, @ContentBuilder content: () -> [AnyContent]) { + public init(size: Tokens.ColumnSize, @ContentBuilder content: () -> [Content]) { self.content = content() self.classes = ["stack-column", size.rawValue] } /// Creates a stack column. - public init(size: Tokens.ColumnSize, alignment: Tokens.TextAlignment, @ContentBuilder content: () -> [AnyContent]) { + public init(size: Tokens.ColumnSize, alignment: Tokens.TextAlignment, @ContentBuilder content: () -> [Content]) { self.content = content() self.classes = ["stack-column", size.rawValue, alignment.rawValue] } /// Creates a stack column. - public init(size: Tokens.ColumnSize, offset: Tokens.ColumnOffset, @ContentBuilder content: () -> [AnyContent]) { + public init(size: Tokens.ColumnSize, offset: Tokens.ColumnOffset, @ContentBuilder content: () -> [Content]) { self.content = content() self.classes = ["stack-column", size.rawValue, offset.rawValue] } /// Creates a stack column. - public init(size: Tokens.ColumnSize, alignment: Tokens.TextAlignment, offset: Tokens.ColumnOffset, @ContentBuilder content: () -> [AnyContent]) { + public init(size: Tokens.ColumnSize, alignment: Tokens.TextAlignment, offset: Tokens.ColumnOffset, @ContentBuilder content: () -> [Content]) { self.content = content() self.classes = ["stack-column", size.rawValue, alignment.rawValue, offset.rawValue] } /// Creates a stack column. - internal init(content: [AnyContent], classes: [String]) { + internal init(content: [Content], classes: [String]) { self.content = content self.classes = classes } - public var body: AnyContent { + public var body: Content { Division { content } .class(classes.joined(separator: " ")) } - - /// The behaviour of the column. - public var scripts: AnyContent { - return [content.scripts] - } } diff --git a/Sources/HTMLKitComponents/Components/Symbol.swift b/Sources/HTMLKitComponents/Components/Symbol.swift new file mode 100644 index 00000000..1073c308 --- /dev/null +++ b/Sources/HTMLKitComponents/Components/Symbol.swift @@ -0,0 +1,135 @@ +/* + Abstract: + The file contains everything related to the symbol component. + */ + +import Foundation +import HTMLKit +import OrderedCollections + +#if canImport(FoundationXML) +import FoundationXML +#endif + +public struct Symbol: View, Modifiable { + + /// The content of the symbol. + internal let content: [VectorElement] + + /// The classes of the symbol. + internal var classes: [String] + + /// Retrieves a symbol. + public init(system name: String) { + + if let url = Bundle.module.url(forResource: name, withExtension: "svg") { + + if let content = try? Symbol.load(contentsOfFile: url) { + self.content = content + + } else { + self.content = [] + } + + } else { + self.content = [] + } + + self.classes = ["symbol"] + } + + /// Creates a symbol. + internal init(content: [VectorElement], classes: [String]) { + + self.content = content + self.classes = classes + } + + public var body: Content { + Vector { + content + } + .width(16) + .height(16) + .viewBox("0 0 16 16") + .fill("currentColor") + .class(classes.joined(separator: " ")) + } + + public func fontSize(_ size: Tokens.FontSize) -> Symbol { + + var newSelf = self + newSelf.classes.append(size.rawValue) + + return newSelf + } + + public func foregroundColor(_ color: Tokens.ForegroundColor) -> Symbol { + + var newSelf = self + newSelf.classes.append(color.rawValue) + + return newSelf + } +} + +extension Symbol { + + fileprivate static func load(contentsOfFile path: URL) throws -> [VectorElement] { + + var elements = [VectorElement]() + + let document = try XMLDocument(contentsOf: path, options: .documentIncludeContentTypeDeclaration) + + if let root = document.rootElement() { + + if let children = root.children { + + for child in children { + + if let element = try parse(node: child) { + elements.append(element) + } + } + } + } + + return elements + } + + fileprivate static func parse(node: XMLNode) throws -> VectorElement? { + + var tempAttributes: OrderedDictionary = [:] + var tempContent: [Content] = [] + + guard let element = node as? XMLElement else { + return nil + } + + guard let localName = element.localName else { + return nil + } + + if let attributes = element.attributes { + + for attribute in attributes { + + if let attributeName = attribute.localName { + tempAttributes[attributeName] = attribute.stringValue + } + } + } + + if let children = element.children { + + for child in children { + + if let model = try parse(node: child) { + tempContent.append(model) + } + } + } + + return Custom(name: localName, attributes: tempAttributes, content: tempContent) + } +} diff --git a/Sources/HTMLKitComponents/Components/Text.swift b/Sources/HTMLKitComponents/Components/Text.swift index 0494cc0e..285ca745 100644 --- a/Sources/HTMLKitComponents/Components/Text.swift +++ b/Sources/HTMLKitComponents/Components/Text.swift @@ -6,30 +6,27 @@ import HTMLKit /// A component that displays text. -public struct Text: Component { +public struct Text: View, Actionable, Modifiable { - /// The identifier of the text. - internal var id: TemplateValue + internal var id: String? /// The content of the text. - internal var content: [AnyContent] + internal var content: [Content] /// The classes of the text. internal var classes: [String] - /// The events of the text. internal var events: [String]? /// Creates a text. - public init(@ContentBuilder content: () -> [AnyContent]) { + public init(@ContentBuilder content: () -> [Content]) { self.content = content() self.classes = ["text"] - self.id = .constant(nil) } /// Creates a text. - internal init(content: [AnyContent], classes: [String], events: [String]?, id: TemplateValue) { + internal init(content: [Content], classes: [String], events: [String]?, id: String?) { self.content = content self.classes = classes @@ -37,7 +34,7 @@ public struct Text: Component { self.id = id } - public var body: AnyContent { + public var body: Content { Paragraph { content } @@ -45,134 +42,64 @@ public struct Text: Component { .modify(unwrap: id) { $0.id($1) } - } - - /// The behaviour of the text. - public var scripts: AnyContent { - if let events = self.events { - return [content.scripts, Script { events }] + Script { + events + } } - - return [content.scripts] } public func id(_ value: String) -> Text { - - var newSelf = self - newSelf.id = .constant(value) - - return newSelf + return self.mutate(id: value) } +} + +extension Text: HoverModifier { public func onHover(perfom action: Actions) -> Text { - - var newSelf = self - - let id: TemplateValue - - switch newSelf.id { - case .constant(let optional): - - guard let value = optional else { - return self - } - - id = .constant(value) - - default: - - id = .constant("") - } - - let event = Events.hover(selector: id.rawValue, action: action.script) - - if var events = newSelf.events { - - events.append(event) - - newSelf.events = events - - } else { - - newSelf.events = [event] - } - - return newSelf + return self.mutate(hoverevent: action.script) + } + + public func onLeave(perfom action: Actions) -> Text { + return self.mutate(leaveevent: action.script) } } extension Text: TextModifier { public func font(_ style: Tokens.TextStyle) -> Text { - - var newSelf = self - newSelf.classes.append(style.rawValue) - - return newSelf + return self.mutate(font: style.rawValue) } public func foregroundColor(_ color: Tokens.ForegroundColor) -> Text { - - var newSelf = self - newSelf.classes.append(color.rawValue) - - return newSelf + return self.mutate(foregroundcolor: color.rawValue) } public func fontSize(_ size: Tokens.FontSize) -> Text { - - var newSelf = self - newSelf.classes.append(size.rawValue) - - return newSelf + return self.mutate(fontsize: size.rawValue) } public func fontWeight(_ weight: Tokens.FontWeight) -> Text { - - var newSelf = self - newSelf.classes.append(weight.rawValue) - - return newSelf + return self.mutate(fontweight: weight.rawValue) } public func fontTransformation(_ transformation: Tokens.TextTransformation) -> Text { - - var newSelf = self - newSelf.classes.append(transformation.rawValue) - - return newSelf + return self.mutate(fonttransformation: transformation.rawValue) } public func fontStyle(_ style: Tokens.FontStyle) -> Text { - - var newSelf = self - newSelf.classes.append(style.rawValue) - - return newSelf + return self.mutate(fontstyle: style.rawValue) } public func bold() -> Text { - - var newSelf = self - newSelf.classes.append(Tokens.FontWeight.bold.rawValue) - - return newSelf + return self.mutate(bold: Tokens.FontWeight.bold.rawValue) } public func italic() -> Text { - - var newSelf = self - newSelf.classes.append(Tokens.FontStyle.italic.rawValue) - - return newSelf + return self.mutate(italic: Tokens.FontStyle.italic.rawValue) } public func underline() -> Text { - - var newSelf = self - newSelf.classes.append(Tokens.TextDecoration.underline.rawValue) - - return newSelf + return self.mutate(underline: Tokens.TextDecoration.underline.rawValue) } } diff --git a/Sources/HTMLKitComponents/Components/Toggle.swift b/Sources/HTMLKitComponents/Components/Toggle.swift index 475e5f0d..fa2c3e9d 100644 --- a/Sources/HTMLKitComponents/Components/Toggle.swift +++ b/Sources/HTMLKitComponents/Components/Toggle.swift @@ -6,10 +6,10 @@ import HTMLKit /// A component that shows an on or off state. -public struct Toggle: Component { +public struct Toggle: View { /// The identifier of the toggle. - internal let name: TemplateValue + internal let name: String /// The classes of the toggle. internal var classes: [String] @@ -18,21 +18,21 @@ public struct Toggle: Component { internal var events: [String]? /// Creates a toggle. - public init(name: TemplateValue) { + public init(name: String) { self.name = name self.classes = ["toggle"] } /// Creates a toggle. - internal init(name: TemplateValue, classes: [String], events: [String]?) { + internal init(name: String, classes: [String], events: [String]?) { self.name = name self.classes = classes self.events = events } - public var body: AnyContent { + public var body: Content { Label { Input() .type(.checkbox) @@ -45,14 +45,4 @@ public struct Toggle: Component { .tabIndex(0) .class(classes.joined(separator: " ")) } - - /// The behaviour of the toggle. - public var scripts: AnyContent { - - if let events = self.events { - return [Script { events }] - } - - return [] - } } diff --git a/Sources/HTMLKitComponents/Events.swift b/Sources/HTMLKitComponents/Events.swift index cb0bc447..54e8fb2a 100644 --- a/Sources/HTMLKitComponents/Events.swift +++ b/Sources/HTMLKitComponents/Events.swift @@ -5,83 +5,92 @@ public enum Events { - static func hover(selector: String, action: String) -> String { + static func hover(selector: String, script: String) -> String { return """ $('#\(selector)').onHover(function() { - \(action) + \(script) }); """ } - static func change(selector: String, action: String) -> String { + static func leave(selector: String, script: String) -> String { + + return """ + $('#\(selector)').onLeave(function() { + \(script) + }); + """ + } + + static func change(selector: String, script: String) -> String { return """ $('#\(selector)').onChange(function() { - \(action) + \(script) }); """ } - static func click(selector: String, action: String) -> String { + static func click(selector: String, script: String) -> String { return """ $('#\(selector)').onClick(function() { - \(action) + \(script) }); """ } - static func tap(selector: String, action: String) -> String { + static func tap(selector: String, script: String) -> String { return """ $('#\(selector)').onTapGesture(function() { - \(action) + \(script) }); """ } - static func press(selector: String, action: String) -> String { + static func press(selector: String, script: String) -> String { return """ $('#\(selector)').onLongPressGesture(function() { - \(action) + \(script) }); """ } - static func drag(selector: String, action: String) -> String { + static func drag(selector: String, script: String) -> String { return """ $('#\(selector)').onDrag(function() { - \(action) + \(script) }); """ } - static func drop(selector: String, action: String) -> String { + static func drop(selector: String, script: String) -> String { return """ $('#\(selector)').onDrop(function() { - \(action) + \(script) }); """ } - static func focus(selector: String, action: String) -> String { + static func focus(selector: String, script: String) -> String { return """ $('#\(selector)').onFocus(function() { - \(action) + \(script) }); """ } - static func submit(selector: String, action: String) -> String { + static func submit(selector: String, script: String) -> String { return """ $('#\(selector)').onSubmit(function() { - \(action) + \(script) }) """ } diff --git a/Sources/HTMLKitComponents/Modifiers/ButtonModifier.swift b/Sources/HTMLKitComponents/Modifiers/ButtonModifier.swift index 28353fc1..f3c79641 100644 --- a/Sources/HTMLKitComponents/Modifiers/ButtonModifier.swift +++ b/Sources/HTMLKitComponents/Modifiers/ButtonModifier.swift @@ -38,3 +38,21 @@ public protocol ButtonModifier { func backgroundColor(_ color: Tokens.BackgroundColor) -> Self } +extension ButtonModifier where Self: Modifiable { + + internal func mutate(buttonsize class: String) -> Self { + return self.mutate(class: `class`) + } + + internal func mutate(buttonstyle class: String) -> Self { + return self.mutate(class: `class`) + } + + internal func mutate(bordershape class: String) -> Self { + return self.mutate(class: `class`) + } + + internal func mutate(backgroundcolor class: String) -> Self { + return self.mutate(class: `class`) + } +} diff --git a/Sources/HTMLKitComponents/Modifiers/DragModifier.swift b/Sources/HTMLKitComponents/Modifiers/DragModifier.swift new file mode 100644 index 00000000..1d96e790 --- /dev/null +++ b/Sources/HTMLKitComponents/Modifiers/DragModifier.swift @@ -0,0 +1,29 @@ +public protocol DragModifier { + + func id(_ value: String) -> Self + + func onDrag(perfom action: Actions) -> Self + + func onDrop(perfom action: Actions) -> Self +} + +extension DragModifier where Self: Actionable { + + internal func mutate(dragevent script: String) -> Self { + + guard let identifier = self.id else { + fatalError("Initiative identifier unkown.") + } + + return self.mutate(event: Events.drag(selector: identifier, script: script)) + } + + internal func mutate(dropevent script: String) -> Self { + + guard let identifier = self.id else { + fatalError("Initiative identifier unkown.") + } + + return self.mutate(event: Events.drop(selector: identifier, script: script)) + } +} diff --git a/Sources/HTMLKitComponents/Modifiers/HoverModifier.swift b/Sources/HTMLKitComponents/Modifiers/HoverModifier.swift new file mode 100644 index 00000000..502dff10 --- /dev/null +++ b/Sources/HTMLKitComponents/Modifiers/HoverModifier.swift @@ -0,0 +1,29 @@ +public protocol HoverModifier { + + func id(_ value: String) -> Self + + func onHover(perfom action: Actions) -> Self + + func onLeave(perfom action: Actions) -> Self +} + +extension HoverModifier where Self: Actionable { + + internal func mutate(hoverevent script: String) -> Self { + + guard let identifier = self.id else { + fatalError("Initiative identifier unkown.") + } + + return self.mutate(event: Events.hover(selector: identifier, script: script)) + } + + internal func mutate(leaveevent script: String) -> Self { + + guard let identifier = self.id else { + fatalError("Initiative identifier unkown.") + } + + return self.mutate(event: Events.leave(selector: identifier, script: script)) + } +} diff --git a/Sources/HTMLKitComponents/Modifiers/ImageModifier.swift b/Sources/HTMLKitComponents/Modifiers/ImageModifier.swift index efb378f4..c6033160 100644 --- a/Sources/HTMLKitComponents/Modifiers/ImageModifier.swift +++ b/Sources/HTMLKitComponents/Modifiers/ImageModifier.swift @@ -29,3 +29,18 @@ public protocol ImageModifier { /// - Returns: A component func clipShape(_ shape: Tokens.ClipShape) -> Self } + +extension ImageModifier where Self: Modifiable { + + internal func mutate(objectfit class: String) -> Self { + return self.mutate(class: `class`) + } + + internal func mutate(imagescale class: String) -> Self { + return self.mutate(class: `class`) + } + + internal func mutate(clipshape class: String) -> Self { + return self.mutate(class: `class`) + } +} diff --git a/Sources/HTMLKitComponents/Modifiers/InputModifier.swift b/Sources/HTMLKitComponents/Modifiers/InputModifier.swift index 2b08f558..427b01ce 100644 --- a/Sources/HTMLKitComponents/Modifiers/InputModifier.swift +++ b/Sources/HTMLKitComponents/Modifiers/InputModifier.swift @@ -21,3 +21,15 @@ public protocol InputModifier { /// - Returns: A component func backgroundColor(_ color: Tokens.BackgroundColor) -> Self } + +extension InputModifier where Self: Modifiable { + + internal func mutate(bordershape class: String) -> Self { + return self.mutate(class: `class`) + } + + internal func mutate(backgroundcolor class: String) -> Self { + return self.mutate(class: `class`) + } +} + diff --git a/Sources/HTMLKitComponents/Modifiers/PressModifier.swift b/Sources/HTMLKitComponents/Modifiers/PressModifier.swift new file mode 100644 index 00000000..ab44e46e --- /dev/null +++ b/Sources/HTMLKitComponents/Modifiers/PressModifier.swift @@ -0,0 +1,40 @@ +public protocol PressModifier { + + func id(_ value: String) -> Self + + func onClick(perfom action: Actions) -> Self + + func onTap(perfom action: Actions) -> Self + + func onPress(perfom action: Actions) -> Self +} + +extension PressModifier where Self: Actionable { + + internal func mutate(clickevent script: String) -> Self { + + guard let identifier = self.id else { + fatalError("Initiative identifier unkown.") + } + + return self.mutate(event: Events.click(selector: identifier, script: script)) + } + + internal func mutate(tapevent script: String) -> Self { + + guard let identifier = self.id else { + fatalError("Initiative identifier unkown.") + } + + return self.mutate(event: Events.tap(selector: identifier, script: script)) + } + + internal func mutate(pressevent script: String) -> Self { + + guard let identifier = self.id else { + fatalError("Initiative identifier unkown.") + } + + return self.mutate(event: Events.press(selector: identifier, script: script)) + } +} diff --git a/Sources/HTMLKitComponents/Modifiers/TextModifier.swift b/Sources/HTMLKitComponents/Modifiers/TextModifier.swift index b03a0b37..2f65e87d 100644 --- a/Sources/HTMLKitComponents/Modifiers/TextModifier.swift +++ b/Sources/HTMLKitComponents/Modifiers/TextModifier.swift @@ -68,3 +68,42 @@ public protocol TextModifier { /// - Returns: A component func underline() -> Self } + +extension TextModifier where Self: Modifiable { + + internal func mutate(font class: String) -> Self { + return self.mutate(class: `class`) + } + + internal func mutate(foregroundcolor class: String) -> Self { + return self.mutate(class: `class`) + } + + internal func mutate(fontsize class: String) -> Self { + return self.mutate(class: `class`) + } + + internal func mutate(fontweight class: String) -> Self { + return self.mutate(class: `class`) + } + + internal func mutate(fonttransformation class: String) -> Self { + return self.mutate(class: `class`) + } + + internal func mutate(fontstyle class: String) -> Self { + return self.mutate(class: `class`) + } + + internal func mutate(bold class: String) -> Self { + return self.mutate(class: `class`) + } + + internal func mutate(italic class: String) -> Self { + return self.mutate(class: `class`) + } + + internal func mutate(underline class: String) -> Self { + return self.mutate(class: `class`) + } +} diff --git a/Sources/HTMLKitComponents/Modifiers/ViewModifier.swift b/Sources/HTMLKitComponents/Modifiers/ViewModifier.swift index 236f864e..0c3f1896 100644 --- a/Sources/HTMLKitComponents/Modifiers/ViewModifier.swift +++ b/Sources/HTMLKitComponents/Modifiers/ViewModifier.swift @@ -29,3 +29,18 @@ public protocol ViewModifier { /// - Returns: A component func backgroundColor(_ color: Tokens.BackgroundColor) -> Self } + +extension ViewModifier where Self: Modifiable { + + internal func mutate(opacity class: String) -> Self { + return self.mutate(class: `class`) + } + + internal func mutate(zindex class: String) -> Self { + return self.mutate(class: `class`) + } + + internal func mutate(backgroundcolor class: String) -> Self { + return self.mutate(class: `class`) + } +} diff --git a/Sources/HTMLKitComponents/Properties/Actionable.swift b/Sources/HTMLKitComponents/Properties/Actionable.swift new file mode 100644 index 00000000..fcc4efd5 --- /dev/null +++ b/Sources/HTMLKitComponents/Properties/Actionable.swift @@ -0,0 +1,24 @@ +internal protocol Actionable: Identifiable { + + var events: [String]? { get set } +} + +extension Actionable { + + internal func mutate(event: String) -> Self { + + var newSelf = self + + if var events = newSelf.events { + + events.append(event) + + newSelf.events = events + + } else { + newSelf.events = [event] + } + + return newSelf + } +} diff --git a/Sources/HTMLKitComponents/Properties/Identifiable.swift b/Sources/HTMLKitComponents/Properties/Identifiable.swift new file mode 100644 index 00000000..27f508d1 --- /dev/null +++ b/Sources/HTMLKitComponents/Properties/Identifiable.swift @@ -0,0 +1,23 @@ +// +// File.swift +// +// +// Created by Mattes Mohr on 25.12.22. +// + +internal protocol Identifiable { + + /// The identifier of the component. + var id: String? { get set } +} + +extension Identifiable { + + internal func mutate(id: String) -> Self { + + var newSelf = self + newSelf.id = id + + return newSelf + } +} diff --git a/Sources/HTMLKitComponents/Properties/Modifiable.swift b/Sources/HTMLKitComponents/Properties/Modifiable.swift new file mode 100644 index 00000000..b47c9d8e --- /dev/null +++ b/Sources/HTMLKitComponents/Properties/Modifiable.swift @@ -0,0 +1,15 @@ +internal protocol Modifiable { + + var classes: [String] { get set } +} + +extension Modifiable { + + internal func mutate(`class`: String) -> Self { + + var newSelf = self + newSelf.classes.append(`class`) + + return newSelf + } +} diff --git a/Sources/HTMLKitComponents/Resources/collection.css b/Sources/HTMLKitComponents/Resources/collection.css deleted file mode 100644 index df4733be..00000000 --- a/Sources/HTMLKitComponents/Resources/collection.css +++ /dev/null @@ -1,39 +0,0 @@ -/** - collection component - */ - -.collection { - display: grid; - gap: var(--collectionGapSize); -} - -.collection-item { - overflow: hidden; -} - -.collection.style\:grid > .collection-item { - border-width: var(--collectionBorderWidth); - border-style: solid; - border-color: var(--collectionBorderColor); - border-radius: var(--collectionBorderRadius); -} - -.collection.ratio\:50 { - grid-template-columns: repeat(2, 1fr); -} - -.collection.ratio\:33 { - grid-template-columns: repeat(3, 1fr); -} - -.collection.ratio\:25 { - grid-template-columns: repeat(4, 1fr); -} - -.collection.ratio\:20 { - grid-template-columns: repeat(5, 1fr); -} - -.collection.ratio\:15 { - grid-template-columns: repeat(6, 1fr); -} diff --git a/Sources/HTMLKitComponents/Resources/background.css b/Sources/HTMLKitComponents/Resources/css/background.css similarity index 100% rename from Sources/HTMLKitComponents/Resources/background.css rename to Sources/HTMLKitComponents/Resources/css/background.css diff --git a/Sources/HTMLKitComponents/Resources/button.css b/Sources/HTMLKitComponents/Resources/css/button.css similarity index 100% rename from Sources/HTMLKitComponents/Resources/button.css rename to Sources/HTMLKitComponents/Resources/css/button.css diff --git a/Sources/HTMLKitComponents/Resources/css/card.css b/Sources/HTMLKitComponents/Resources/css/card.css new file mode 100644 index 00000000..cf5ead72 --- /dev/null +++ b/Sources/HTMLKitComponents/Resources/css/card.css @@ -0,0 +1,15 @@ +/** + card component + */ + +.card { + padding-top: var(--cardPaddingY); + padding-right: var(--cardPaddingX); + padding-bottom: var(--cardPaddingY); + padding-left: var(--cardPaddingX); + border-width: var(--cardBorderWidth); + border-style: solid; + border-radius: var(--cardBorderRadius); + border-color: var(--cardBorderColor); + background-color: var(--cardBackgroundColor); +} diff --git a/Sources/HTMLKitComponents/Resources/divider.css b/Sources/HTMLKitComponents/Resources/css/divider.css similarity index 100% rename from Sources/HTMLKitComponents/Resources/divider.css rename to Sources/HTMLKitComponents/Resources/css/divider.css diff --git a/Sources/HTMLKitComponents/Resources/form.css b/Sources/HTMLKitComponents/Resources/css/form.css similarity index 100% rename from Sources/HTMLKitComponents/Resources/form.css rename to Sources/HTMLKitComponents/Resources/css/form.css diff --git a/Sources/HTMLKitComponents/Resources/css/grid.css b/Sources/HTMLKitComponents/Resources/css/grid.css new file mode 100644 index 00000000..ab57661b --- /dev/null +++ b/Sources/HTMLKitComponents/Resources/css/grid.css @@ -0,0 +1,43 @@ +/** + grid component + */ + +.grid { + display: grid; + gap: var(--gridGapSize); + list-style-type: none; +} + +.grid-item { + + padding-top: var(--gridItemPaddingY); + padding-right: var(--gridItemPaddingX); + padding-bottom: var(--gridItemPaddingY); + padding-left: var(--gridItemPaddingX); + border-width: var(--gridItemBorderWidth); + border-style: solid; + border-color: var(--gridItemBorderColor); + border-radius: var(--gridItemBorderRadius); + + overflow: hidden; +} + +.grid.ratio\:50 { + grid-template-columns: repeat(2, 1fr); +} + +.grid.ratio\:33 { + grid-template-columns: repeat(3, 1fr); +} + +.grid.ratio\:25 { + grid-template-columns: repeat(4, 1fr); +} + +.grid.ratio\:20 { + grid-template-columns: repeat(5, 1fr); +} + +.grid.ratio\:15 { + grid-template-columns: repeat(6, 1fr); +} diff --git a/Sources/HTMLKitComponents/Resources/group.css b/Sources/HTMLKitComponents/Resources/css/group.css similarity index 100% rename from Sources/HTMLKitComponents/Resources/group.css rename to Sources/HTMLKitComponents/Resources/css/group.css diff --git a/Sources/HTMLKitComponents/Resources/image.css b/Sources/HTMLKitComponents/Resources/css/image.css similarity index 100% rename from Sources/HTMLKitComponents/Resources/image.css rename to Sources/HTMLKitComponents/Resources/css/image.css diff --git a/Sources/HTMLKitComponents/Resources/link.css b/Sources/HTMLKitComponents/Resources/css/link.css similarity index 100% rename from Sources/HTMLKitComponents/Resources/link.css rename to Sources/HTMLKitComponents/Resources/css/link.css diff --git a/Sources/HTMLKitComponents/Resources/list.css b/Sources/HTMLKitComponents/Resources/css/list.css similarity index 100% rename from Sources/HTMLKitComponents/Resources/list.css rename to Sources/HTMLKitComponents/Resources/css/list.css diff --git a/Sources/HTMLKitComponents/Resources/css/modal.css b/Sources/HTMLKitComponents/Resources/css/modal.css new file mode 100644 index 00000000..68c8aabe --- /dev/null +++ b/Sources/HTMLKitComponents/Resources/css/modal.css @@ -0,0 +1,18 @@ +/** + modal component + */ + +.modal { + + width: 45%; + margin: auto; + padding-top: var(--modalPaddingY); + padding-right: var(--modalPaddingX); + padding-bottom: var(--modalPaddingY); + padding-left: var(--modalPaddingX); + border-width: var(--modalBorderWidth); + border-style: solid; + border-radius: var(--modalBorderRadius); + border-color: var(--modalBorderColor); + background-color: var(--modalBackgroundColor); +} diff --git a/Sources/HTMLKitComponents/Resources/roots.css b/Sources/HTMLKitComponents/Resources/css/roots.css similarity index 84% rename from Sources/HTMLKitComponents/Resources/roots.css rename to Sources/HTMLKitComponents/Resources/css/roots.css index 79ef76ca..76b53d9c 100644 --- a/Sources/HTMLKitComponents/Resources/roots.css +++ b/Sources/HTMLKitComponents/Resources/css/roots.css @@ -108,10 +108,9 @@ --listRowPaddingY: 0px; --listRowPaddingX: 15px; --listGapSize: 15px; - - /** - link variables - */ + --listBorderColor: hsla(210, 14%, 89%, 100%); + --listBorderWidth: 1px; + --listBorderRadius: 5px; /** input variables @@ -141,10 +140,6 @@ --dividerColor: #FFFFFF; - /** - collection variables - */ - /** button variables */ @@ -157,11 +152,39 @@ --buttonFontWeight: normal; --buttonLineHeight: 1.2rem; + /** - list variables + modal variables */ - --listBorderColor: hsla(210, 14%, 89%, 100%); - --listBorderWidth: 1px; - --listBorderRadius: 5px; + --modalPaddingY: 12px; + --modalPaddingX: 16px; + --modalBorderWidth: 1px; + --modalBorderRadius: 5px; + --modalBorderColor: var(--grayColor); + --modalBackgroundColor: var(--whiteColor); + + /** + grid variables + */ + + --gridGapSize: 15px; + --gridItemPaddingY: 12px; + --gridItemPaddingX: 16px; + --gridItemBorderWidth: 1px; + --gridItemBorderColor: var(--grayColor); + --gridItemBorderRadius: 5px; + --gridItemBackgroundColor: var(--whiteColor); + + + /** + grid variables + */ + + --cardPaddingY: 12px; + --cardPaddingX: 16px; + --cardBorderWidth: 1px; + --cardBorderRadius: 15px; + --cardBorderColor: var(--grayColor); + --cardBackgroundColor: var(--whiteColor); } diff --git a/Sources/HTMLKitComponents/Resources/snippet.css b/Sources/HTMLKitComponents/Resources/css/snippet.css similarity index 100% rename from Sources/HTMLKitComponents/Resources/snippet.css rename to Sources/HTMLKitComponents/Resources/css/snippet.css diff --git a/Sources/HTMLKitComponents/Resources/stack.css b/Sources/HTMLKitComponents/Resources/css/stack.css similarity index 100% rename from Sources/HTMLKitComponents/Resources/stack.css rename to Sources/HTMLKitComponents/Resources/css/stack.css diff --git a/Sources/HTMLKitComponents/Resources/css/symbol.css b/Sources/HTMLKitComponents/Resources/css/symbol.css new file mode 100644 index 00000000..f8c32218 --- /dev/null +++ b/Sources/HTMLKitComponents/Resources/css/symbol.css @@ -0,0 +1,100 @@ +/** + symbol component + */ + +.symbol { + display: inline-block; + width: 1em; + height: 1em; +} + +.symbol.size\:small { + font-size: var(--smallFontSize); + line-height: var(--smallLineHeight); +} + +.symbol.size\:medium { + font-size: var(--mediumFontSize); + line-height: var(--mediumLineHeight); +} + +.symbol.size\:large { + font-size: var(--largeFontSize); + line-height: var(--largeLineHeight); +} + +.symbol.color\:black { + color: var(--blackColor); +} + +.symbol.color\:blue { + color: var(--blueColor); +} + +.symbol.color\:brown { + color: var(--brownColor); +} + +.symbol.color\:cyan { + color: var(--cyanColor); +} + +.symbol.color\:gray { + color: var(--grayColor); +} + +.symbol.color\:green { + color: var(--greenColor); +} + +.symbol.color\:indigo { + color: var(--indigoColor); +} + +.symbol.color\:mint { + color: var(--mintColor); +} + +.symbol.color\:orange { + color: var(--orangeColor); +} + +.symbol.color\:pink { + color: var(--pinkColor); +} + +.symbol.color\:purple { + color: var(--purpleColor); +} + +.symbol.color\:red { + color: var(--redColor); +} + +.symbol.color\:teal { + color: var(--tealColor); +} + +.symbol.color\:white { + color: var(--whiteColor); +} + +.symbol.color\:yellow { + color: var(--yellowColor); +} + +.symbol.color\:silver { + color: var(--silverColor); +} + +.symbol.color\:highlight { + color: var(--highlightColor); +} + +.symbol.color\:primary { + color: var(--primaryColor); +} + +.symbol.color\:secondary { + color: var(--secondaryColor); +} diff --git a/Sources/HTMLKitComponents/Resources/text.css b/Sources/HTMLKitComponents/Resources/css/text.css similarity index 100% rename from Sources/HTMLKitComponents/Resources/text.css rename to Sources/HTMLKitComponents/Resources/css/text.css diff --git a/Sources/HTMLKitComponents/Resources/toggle.css b/Sources/HTMLKitComponents/Resources/css/toggle.css similarity index 100% rename from Sources/HTMLKitComponents/Resources/toggle.css rename to Sources/HTMLKitComponents/Resources/css/toggle.css diff --git a/Sources/HTMLKitComponents/Resources/position.css b/Sources/HTMLKitComponents/Resources/css/utils.css similarity index 80% rename from Sources/HTMLKitComponents/Resources/position.css rename to Sources/HTMLKitComponents/Resources/css/utils.css index 44aad35f..824336e2 100644 --- a/Sources/HTMLKitComponents/Resources/position.css +++ b/Sources/HTMLKitComponents/Resources/css/utils.css @@ -1,7 +1,11 @@ /** - position component + utils classes */ +.display\:block { + display: block !important; +} + zindex\:1 { position: relative; z-index: 1; diff --git a/Sources/HTMLKitComponents/Resources/js/all.js b/Sources/HTMLKitComponents/Resources/js/all.js new file mode 100644 index 00000000..c91dae7f --- /dev/null +++ b/Sources/HTMLKitComponents/Resources/js/all.js @@ -0,0 +1,142 @@ +var $ = (function () { + + 'use strict'; + + var constructor = function (selector) { + this.elems = document.querySelectorAll(selector); + }; + + /** + * This function is for + */ + constructor.prototype.onHover = function (callback) { + + this.elems[0].addEventListener("mouseenter", callback); + }; + + /** + * This function is for + */ + constructor.prototype.onLeave = function (callback) { + + this.elems[0].addEventListener("mouseleave", callback); + }; + + /** + * This function is for + */ + constructor.prototype.onChange = function (callback) { + + this.elems[0].addEventListener("change", callback); + }; + + /** + * This function is for + */ + constructor.prototype.onClick = function (callback) { + + this.elems[0].addEventListener("click", callback); + }; + + /** + * This function is for + */ + constructor.prototype.onTapGesture = function (callback) { + + this.elems[0].addEventListener("touchend", callback); + }; + + /** + * This function is for + */ + constructor.prototype.onLongPressGesture = function (callback) { + + this.elems[0].addEventListener("touchstart", callback); + }; + + /** + * This function is for + */ + constructor.prototype.onDrag = function (callback) { + + this.elems[0].addEventListener("drag", callback); + }; + + /** + * This function is for + */ + constructor.prototype.onDrop = function (callback) { + + this.elems[0].addEventListener("drop", callback); + }; + + /** + * This function is for + */ + constructor.prototype.onFocus = function (callback) { + + this.elems[0].addEventListener("focus", callback); + }; + + /** + * This function is for + */ + constructor.prototype.onSubmit = function (callback) { + + this.elems[0].addEventListener("submit", callback); + }; + + /** + * This function is for + */ + constructor.prototype.show = function() { + + const elements = document.getElementsByClassName("display:block"); + + for (let element of elements){ + element.classList.remove("display:block") + } + + this.elems[0].classList.add("display:block") + }; + + /** + * This function is for + */ + constructor.prototype.hide = function() { + + this.elems[0].classList.remove("display:block") + }; + + /** + * This function is for + */ + constructor.prototype.animate = function({params}, speed) { + + this.elems[0].animate({params}, speed); + }; + + /** + * This function is for + */ + constructor.prototype.open = function() { + + this.elems[0].showModal() + }; + + /** + * This function is for + */ + constructor.prototype.close = function() { + + this.elems[0].close() + }; + + var instantiate = function (selector) { + return new constructor(selector); + }; + + return instantiate; + +})(); + diff --git a/Sources/HTMLKitComponents/Resources/symbols/folder.svg b/Sources/HTMLKitComponents/Resources/symbols/folder.svg new file mode 100644 index 00000000..86e9a90f --- /dev/null +++ b/Sources/HTMLKitComponents/Resources/symbols/folder.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/Sources/HTMLKitComponents/Tokens.swift b/Sources/HTMLKitComponents/Tokens.swift index 48437330..6cdfe061 100644 --- a/Sources/HTMLKitComponents/Tokens.swift +++ b/Sources/HTMLKitComponents/Tokens.swift @@ -470,13 +470,6 @@ public enum Tokens { case half = "ratio:50" } - /// A style for a collection. - public enum CollectionStyle: String { - - case grid = "style:grid" - case carousel = "style:carousel" - } - /// A style for a list. public enum ListStyle: String { diff --git a/Sources/HTMLKitVapor/Extensions/Vapor+HTMLKit.swift b/Sources/HTMLKitVapor/Extensions/Vapor+HTMLKit.swift index 0c25113a..24d6f81b 100644 --- a/Sources/HTMLKitVapor/Extensions/Vapor+HTMLKit.swift +++ b/Sources/HTMLKitVapor/Extensions/Vapor+HTMLKit.swift @@ -6,18 +6,6 @@ import HTMLKit import Vapor -extension Application.Views.Provider { - - /// Access to the view renderer - public static var htmlkit: Self { - return .init { - $0.views.use { - $0.htmlkit.renderer - } - } - } -} - extension Application { /// Access to the vapor provider @@ -28,25 +16,6 @@ extension Application { /// The vapor provider public struct HtmlKit { - internal struct CacheStorageKey: StorageKey { - - public typealias Value = ViewCache - } - - /// The view cache - public var views: ViewCache { - - if let cache = self.application.storage[CacheStorageKey.self] { - return cache - } - - let cache = ViewCache() - - self.application.storage[CacheStorageKey.self] = cache - - return cache - } - internal struct LingoStorageKey: StorageKey { public typealias Value = LingoConfiguration @@ -68,7 +37,7 @@ extension Application { /// The view renderer internal var renderer: ViewRenderer { - return .init(eventLoop: self.application.eventLoopGroup.next(), cache: self.views, lingo: lingo) + return .init(eventLoop: self.application.eventLoopGroup.next(), lingo: lingo) } /// The application dependency @@ -86,6 +55,6 @@ extension Request { /// Access to the view renderer public var htmlkit: ViewRenderer { - return .init(eventLoop: self.eventLoop, cache: self.application.htmlkit.views, lingo: self.application.htmlkit.lingo) + return .init(eventLoop: self.eventLoop, lingo: self.application.htmlkit.lingo) } } diff --git a/Sources/HTMLKitVapor/LingoConfiguration.swift b/Sources/HTMLKitVapor/LingoConfiguration.swift index 7b54a7f8..12b864b7 100644 --- a/Sources/HTMLKitVapor/LingoConfiguration.swift +++ b/Sources/HTMLKitVapor/LingoConfiguration.swift @@ -4,6 +4,7 @@ */ import Foundation +import Lingo /// The localization public class LingoConfiguration { @@ -28,6 +29,10 @@ public class LingoConfiguration { /// The locale indentifier internal var defaultLocale: String + internal var lingo: Lingo? { + return try? Lingo(rootPath: defaultDirectory, defaultLocale: defaultLocale) + } + /// Creates a configuration internal init() { diff --git a/Sources/HTMLKitVapor/ViewCache.swift b/Sources/HTMLKitVapor/ViewCache.swift deleted file mode 100644 index b50a43d8..00000000 --- a/Sources/HTMLKitVapor/ViewCache.swift +++ /dev/null @@ -1,50 +0,0 @@ -/* - Abstract: - The file contains the cache of the Vapor renderer. - */ - -import HTMLKit -import Vapor - -/// The cache -public class ViewCache { - - /// The cache storage - internal var storage: [String: HTMLKit.Formula] - - /// Creates the cache - internal init() { - self.storage = [:] - } - - /// Retrieves a formula from the storage - internal func retrieve(name: String, on loop: EventLoop) -> EventLoopFuture { - - if let cache = self.storage[name] { - return loop.makeSucceededFuture(cache) - - } else { - return loop.makeSucceededFuture(nil) - } - } - - /// Sets or updates a formula at the storage - internal func upsert(name: String, formula: HTMLKit.Formula) { - self.storage.updateValue(formula, forKey: name) - } - - /// Removes a formula from the storage - internal func remove(name: String) { - self.storage.removeValue(forKey: name) - } - - /// Adds a view to the storage - public func add(view: T) { - - let formula = HTMLKit.Formula() - - try? view.prerender(formula) - - self.storage.updateValue(formula, forKey: String(reflecting: T.self)) - } -} diff --git a/Sources/HTMLKitVapor/ViewRenderer.swift b/Sources/HTMLKitVapor/ViewRenderer.swift index 2b5e7b30..c583284d 100644 --- a/Sources/HTMLKitVapor/ViewRenderer.swift +++ b/Sources/HTMLKitVapor/ViewRenderer.swift @@ -10,76 +10,41 @@ import Lingo /// The view renderer public class ViewRenderer { - /// A enumeration of possible errors of the view renderer - public enum RendererError: Error { - - case unkownLayout(String) - - public var description: String { - - switch self { - case .unkownLayout(let name): - return "Layout with the name '\(name)' could not be found." - } - } - } - /// The event loop the view renderer is running on internal var eventLoop: EventLoop - /// The cache of the view renderer - internal var cache: ViewCache - - /// The localiatzion of the view renderer - internal var lingo: Lingo? + /// The renderer for the view renderer + internal var renderer: Renderer /// Creates the view renderer - public init(eventLoop: EventLoop, cache: ViewCache, lingo: LingoConfiguration) { + public init(eventLoop: EventLoop, lingo: LingoConfiguration) { self.eventLoop = eventLoop - self.cache = cache - self.lingo = try? Lingo(rootPath: lingo.defaultDirectory, defaultLocale: lingo.defaultLocale) + self.renderer = Renderer(lingo: lingo.lingo) } /// Renders a layout and its context - public func render(name: String, context: Encodable) -> EventLoopFuture { - - return self.cache.retrieve(name: name, on: self.eventLoop).flatMap { formula in + public func render(_ view: some HTMLKit.View) -> EventLoopFuture { - guard let formula = formula else { - return self.eventLoop.makeFailedFuture(RendererError.unkownLayout(name)) - } + do { var buffer = ByteBufferAllocator().buffer(capacity: 4096) - - let manager = HTMLKit.ContextManager(context: context, lingo: self.lingo) + buffer.writeString(try renderer.render(view: view)) - for ingredient in formula.ingredients { - - if let value = try? ingredient.render(with: manager) { - buffer.writeString(value) - } - } + return self.eventLoop.makeSucceededFuture(View(data: buffer)) - return self.eventLoop.makeSucceededFuture(buffer) + } catch(let error) { + return self.eventLoop.makeFailedFuture(error) } } -} - -extension ViewRenderer: Vapor.ViewRenderer { - public func `for`(_ request: Request) -> Vapor.ViewRenderer { - return request.htmlkit - } - - public func render(_ name: String, _ context: E) -> EventLoopFuture { - return self.render(name: name, context: context).map { buffer in - return View(data: buffer) - } + /// Renders a layout and its context + public func render(_ view: some HTMLKit.View) async throws -> Vapor.View { + return try await render(view).get() } } -extension ViewRenderer.RendererError: AbortError { +extension HTMLKit.Renderer.Errors: AbortError { @_implements(AbortError, reason) public var abortReason: String { self.description } @@ -87,8 +52,8 @@ extension ViewRenderer.RendererError: AbortError { public var status: HTTPResponseStatus { .internalServerError } } -extension ViewRenderer.RendererError: DebuggableError { +extension HTMLKit.Renderer.Errors: DebuggableError { @_implements(DebuggableError, reason) - public var debuggableReason: String { self.description } + public var debuggableReason: String { self.description } } diff --git a/Tests/HTMLKitComponentsTests/ComponentTests.swift b/Tests/HTMLKitComponentsTests/ComponentTests.swift index 8c756905..68578b5a 100644 --- a/Tests/HTMLKitComponentsTests/ComponentTests.swift +++ b/Tests/HTMLKitComponentsTests/ComponentTests.swift @@ -1,91 +1,96 @@ import XCTest import HTMLKit -@testable import HTMLKitComponents +import HTMLKitComponents final class ComponentTests: XCTestCase { - struct TestPage: Page { + struct TestView: View { - @ContentBuilder var body: AnyContent + @ContentBuilder var body: Content } let renderer = Renderer() - func testActionButton() throws { + func testLinkButton() throws { - let page = TestPage { - ActionButton(destination: "uri") { + let view = TestView { + LinkButton(destination: "uri") { "Button" } } - try renderer.add(layout: page) - - XCTAssertEqual(try renderer.render(layout: TestPage.self), + XCTAssertEqual(try renderer.render(view: view), """ Button """ ) } + func testButton() throws { + + let view = TestView { + Button(role: .button) { + "Button" + } + } + + XCTAssertEqual(try renderer.render(view: view), + """ + + """ + ) + } + func testGroup() throws { - let page = TestPage { + let view = TestView { HTMLKitComponents.Group { } } - try renderer.add(layout: page) - - XCTAssertEqual(try renderer.render(layout: TestPage.self), + XCTAssertEqual(try renderer.render(view: view), """
""" ) } - func testCollection() throws { + func testGrid() throws { - let page = TestPage { - Collection { + let view = TestView { + Grid { } } - try renderer.add(layout: page) - - XCTAssertEqual(try renderer.render(layout: TestPage.self), + XCTAssertEqual(try renderer.render(view: view), """ -
    +
      """ ) } - func testCollectionItem() throws { + func testGridItem() throws { - let page = TestPage { - CollectionItem { + let view = TestView { + GridItem { } } - try renderer.add(layout: page) - - XCTAssertEqual(try renderer.render(layout: TestPage.self), + XCTAssertEqual(try renderer.render(view: view), """ -
    • +
    • """ ) } func testFormContainer() throws { - let page = TestPage { - HTMLKitComponents.Form { + let view = TestView { + HTMLKitComponents.Form(method: .post) { } } - try renderer.add(layout: page) - - XCTAssertEqual(try renderer.render(layout: TestPage.self), + XCTAssertEqual(try renderer.render(view: view), """
      """ @@ -94,15 +99,13 @@ final class ComponentTests: XCTestCase { func testFieldLabel() throws { - let page = TestPage { + let view = TestView { FieldLabel(for: "name") { "Name" } } - try renderer.add(layout: page) - - XCTAssertEqual(try renderer.render(layout: TestPage.self), + XCTAssertEqual(try renderer.render(view: view), """ """ @@ -111,13 +114,11 @@ final class ComponentTests: XCTestCase { func testTextField() throws { - let page = TestPage { + let view = TestView { TextField(name: "name") } - try renderer.add(layout: page) - - XCTAssertEqual(try renderer.render(layout: TestPage.self), + XCTAssertEqual(try renderer.render(view: view), """ """ @@ -126,15 +127,13 @@ final class ComponentTests: XCTestCase { func testTextEditor() throws { - let page = TestPage { + let view = TestView { TextEditor(name: "name") { "value" } } - try renderer.add(layout: page) - - XCTAssertEqual(try renderer.render(layout: TestPage.self), + XCTAssertEqual(try renderer.render(view: view), """ """ @@ -143,13 +142,11 @@ final class ComponentTests: XCTestCase { func testSlider() throws { - let page = TestPage { + let view = TestView { Slider(name: "name") } - try renderer.add(layout: page) - - XCTAssertEqual(try renderer.render(layout: TestPage.self), + XCTAssertEqual(try renderer.render(view: view), """ """ @@ -158,13 +155,11 @@ final class ComponentTests: XCTestCase { func testDatePicker() throws { - let page = TestPage { + let view = TestView { DatePicker(name: "name") } - try renderer.add(layout: page) - - XCTAssertEqual(try renderer.render(layout: TestPage.self), + XCTAssertEqual(try renderer.render(view: view), """ """ @@ -173,13 +168,11 @@ final class ComponentTests: XCTestCase { func testSecureField() throws { - let page = TestPage { + let view = TestView { SecureField(name: "password") } - try renderer.add(layout: page) - - XCTAssertEqual(try renderer.render(layout: TestPage.self), + XCTAssertEqual(try renderer.render(view: view), """ """ @@ -188,13 +181,11 @@ final class ComponentTests: XCTestCase { func testCheckField() throws { - let page = TestPage { + let view = TestView { CheckField(name: "name", value: "value") } - try renderer.add(layout: page) - - XCTAssertEqual(try renderer.render(layout: TestPage.self), + XCTAssertEqual(try renderer.render(view: view), """ """ @@ -203,13 +194,11 @@ final class ComponentTests: XCTestCase { func testRadioSelect() throws { - let page = TestPage { + let view = TestView { RadioSelect(name: "name", value: "value") } - try renderer.add(layout: page) - - XCTAssertEqual(try renderer.render(layout: TestPage.self), + XCTAssertEqual(try renderer.render(view: view), """ """ @@ -218,13 +207,11 @@ final class ComponentTests: XCTestCase { func testImage() throws { - let page = TestPage { + let view = TestView { Image(source: "source") } - try renderer.add(layout: page) - - XCTAssertEqual(try renderer.render(layout: TestPage.self), + XCTAssertEqual(try renderer.render(view: view), """
      \ \ @@ -235,14 +222,12 @@ final class ComponentTests: XCTestCase { func testList() throws { - let page = TestPage { + let view = TestView { List(direction: .vertical) { } } - try renderer.add(layout: page) - - XCTAssertEqual(try renderer.render(layout: TestPage.self), + XCTAssertEqual(try renderer.render(view: view), """
        """ @@ -251,14 +236,12 @@ final class ComponentTests: XCTestCase { func testListRow() throws { - let page = TestPage { + let view = TestView { ListRow { } } - try renderer.add(layout: page) - - XCTAssertEqual(try renderer.render(layout: TestPage.self), + XCTAssertEqual(try renderer.render(view: view), """
      • """ @@ -267,15 +250,13 @@ final class ComponentTests: XCTestCase { func testLink() throws { - let page = TestPage { + let view = TestView { Link(destination: "uri") { "link" } } - try renderer.add(layout: page) - - XCTAssertEqual(try renderer.render(layout: TestPage.self), + XCTAssertEqual(try renderer.render(view: view), """ link """ @@ -284,14 +265,12 @@ final class ComponentTests: XCTestCase { func testVStack() throws { - let page = TestPage { + let view = TestView { VStack { } } - try renderer.add(layout: page) - - XCTAssertEqual(try renderer.render(layout: TestPage.self), + XCTAssertEqual(try renderer.render(view: view), """
        """ @@ -300,14 +279,12 @@ final class ComponentTests: XCTestCase { func testHStack() throws { - let page = TestPage { + let view = TestView { HStack { } } - try renderer.add(layout: page) - - XCTAssertEqual(try renderer.render(layout: TestPage.self), + XCTAssertEqual(try renderer.render(view: view), """
        """ @@ -316,14 +293,12 @@ final class ComponentTests: XCTestCase { func testZStack() throws { - let page = TestPage { + let view = TestView { ZStack { } } - try renderer.add(layout: page) - - XCTAssertEqual(try renderer.render(layout: TestPage.self), + XCTAssertEqual(try renderer.render(view: view), """
        """ @@ -333,14 +308,12 @@ final class ComponentTests: XCTestCase { func testStackColumn() throws { - let page = TestPage { + let view = TestView { StackColumn(size: .twelve) { } } - try renderer.add(layout: page) - - XCTAssertEqual(try renderer.render(layout: TestPage.self), + XCTAssertEqual(try renderer.render(view: view), """
        """ @@ -349,7 +322,7 @@ final class ComponentTests: XCTestCase { func testText() throws { - let page = TestPage { + let view = TestView { Text { } .fontSize(.large) @@ -358,34 +331,30 @@ final class ComponentTests: XCTestCase { .bold() } - try renderer.add(layout: page) - - XCTAssertEqual(try renderer.render(layout: TestPage.self), + XCTAssertEqual(try renderer.render(view: view), """

        """ ) } - func testProgressView() throws { + func testProgress() throws { - let page = TestPage { - ProgressView(name: "name") { + let view = TestView { + Progress(maximum: 100, value: 10) { } } - try renderer.add(layout: page) - - XCTAssertEqual(try renderer.render(layout: TestPage.self), + XCTAssertEqual(try renderer.render(view: view), """ - + """ ) } func testSnippet() throws { - let page = TestPage { + let view = TestView { Snippet(highlight: .html) { """
        @@ -395,9 +364,7 @@ final class ComponentTests: XCTestCase { } } - try renderer.add(layout: page) - - XCTAssertEqual(try renderer.render(layout: TestPage.self), + XCTAssertEqual(try renderer.render(view: view), """
        \
                                

        <div>

        \ @@ -410,13 +377,11 @@ final class ComponentTests: XCTestCase { func testToggle() throws { - let page = TestPage { + let view = TestView { Toggle(name: "name") } - try renderer.add(layout: page) - - XCTAssertEqual(try renderer.render(layout: TestPage.self), + XCTAssertEqual(try renderer.render(view: view), """