Skip to content

Moving DOM files to DOM Module #80

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,33 +69,6 @@ jobs:
- name: Test
run: swift test --skip-build

xcode_14_3:
runs-on: macos-13
env:
DEVELOPER_DIR: /Applications/Xcode_14.3.app/Contents/Developer
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Version
run: swift --version
- name: Build
run: swift build --build-tests
- name: Test
run: swift test --skip-build

linux_5_8:
runs-on: ubuntu-latest
container: swift:5.8
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Version
run: swift --version
- name: Build
run: swift build --build-tests
- name: Test
run: swift test --skip-build

linux_5_9:
runs-on: ubuntu-latest
container: swift:5.9
Expand Down
1 change: 0 additions & 1 deletion CommandLine/TextOutputStream+StandardError.swift

This file was deleted.

100 changes: 100 additions & 0 deletions DOM/Sources/DOM+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//
// DOM.Element.Equality.swift
// SwiftDraw
//
// Created by Simon Whitty on 31/12/16.
// Copyright 2020 Simon Whitty
//
// Distributed under the permissive zlib license
// Get the latest version from here:
//
// https://github.com/swhitty/SwiftDraw
//
// This software is provided 'as-is', without any express or implied
// warranty. In no event will the authors be held liable for any damages
// arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not be
// misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//

import Foundation

package extension DOM.Polyline {
// requires even number of elements
convenience init(_ p: DOM.Coordinate...) {

var points = [DOM.Point]()

for index in stride(from: 0, to: p.count, by: 2) {
points.append(DOM.Point(p[index], p[index + 1]))
}

self.init(points: points)
}
}

package extension DOM.Polygon {
// requires even number of elements
convenience init(_ p: DOM.Coordinate...) {

var points = [DOM.Point]()

for index in stride(from: 0, to: p.count, by: 2) {
points.append(DOM.Point(p[index], p[index + 1]))
}

self.init(points: points)
}
}

package extension XML.Element {
convenience init(_ name: String, style: String) {
self.init(name: name, attributes: ["style": style])
}

convenience init(_ name: String, id: String, style: String) {
self.init(name: name, attributes: ["id": id, "style": style])
}
}

package extension DOM.SVG {

static func parse(fileNamed name: String, in bundle: Bundle) throws -> DOM.SVG {
guard let url = bundle.url(forResource: name, withExtension: nil) else {
throw Error("missing resource: \(name) in bundle: \(bundle)")
}

let parser = XMLParser(options: [.skipInvalidElements], filename: url.lastPathComponent)
let element = try XML.SAXParser.parse(contentsOf: url)
return try parser.parseSVG(element)
}

static func parse(
xml: String,
options: XMLParser.Options = [.skipInvalidElements]
) throws -> DOM.SVG {
let element = try XML.SAXParser.parse(data: xml.data(using: .utf8)!)
let parser = XMLParser(options: options)
return try parser.parseSVG(element)
}

private struct Error: LocalizedError {
var errorDescription: String?

init(_ message: String) {
self.errorDescription = message
}
}
}
8 changes: 4 additions & 4 deletions SwiftDraw/DOM.Color.swift → DOM/Sources/DOM.Color.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
// 3. This notice may not be removed or altered from any source distribution.
//

extension DOM {
package extension DOM {

enum Color: Equatable {
case none
case currentColor
Expand All @@ -41,7 +41,7 @@ extension DOM {
case hex(UInt8, UInt8, UInt8)

// see: https://www.w3.org/TR/SVG11/types.html#ColorKeywords
enum Keyword: String {
package enum Keyword: String {
case aliceblue
case antiquewhite
case aqua
Expand Down Expand Up @@ -193,7 +193,7 @@ extension DOM {
}
}

extension DOM.Color.Keyword {
package extension DOM.Color.Keyword {

// each color keyword maps to an rgbi
var rgbi: (UInt8, UInt8, UInt8) {
Expand Down
84 changes: 42 additions & 42 deletions SwiftDraw/DOM.Element.swift → DOM/Sources/DOM.Element.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,34 @@

import Foundation

protocol ContainerElement {
package protocol ContainerElement {
var childElements: [DOM.GraphicsElement] { get set }
}

protocol ElementAttributes {
package protocol ElementAttributes {
var id: String? { get set }
var `class`: String? { get set }
}

extension DOM {
package extension DOM {

class Element {}

class GraphicsElement: Element, ElementAttributes, @unchecked Sendable {
var id: String?
var `class`: String?
var attributes = PresentationAttributes()
var style = PresentationAttributes()
package var id: String?
package var `class`: String?

package var attributes = PresentationAttributes()
package var style = PresentationAttributes()
}

final class Line: GraphicsElement, @unchecked Sendable {
var x1: Coordinate
var y1: Coordinate
var x2: Coordinate
var y2: Coordinate
init(x1: Coordinate, y1: Coordinate, x2: Coordinate, y2: Coordinate) {
package var x1: Coordinate
package var y1: Coordinate
package var x2: Coordinate
package var y2: Coordinate

package init(x1: Coordinate, y1: Coordinate, x2: Coordinate, y2: Coordinate) {
self.x1 = x1
self.y1 = y1
self.x2 = x2
Expand All @@ -68,11 +68,11 @@ extension DOM {
}

final class Circle: GraphicsElement, @unchecked Sendable {
var cx: Coordinate?
var cy: Coordinate?
var r: Coordinate
init(cx: Coordinate?, cy: Coordinate?, r: Coordinate) {
package var cx: Coordinate?
package var cy: Coordinate?
package var r: Coordinate

package init(cx: Coordinate?, cy: Coordinate?, r: Coordinate) {
self.cx = cx
self.cy = cy
self.r = r
Expand All @@ -81,12 +81,12 @@ extension DOM {
}

final class Ellipse: GraphicsElement, @unchecked Sendable {
var cx: Coordinate?
var cy: Coordinate?
var rx: Coordinate
var ry: Coordinate
init(cx: Coordinate?, cy: Coordinate?, rx: Coordinate, ry: Coordinate) {
package var cx: Coordinate?
package var cy: Coordinate?
package var rx: Coordinate
package var ry: Coordinate

package init(cx: Coordinate?, cy: Coordinate?, rx: Coordinate, ry: Coordinate) {
self.cx = cx
self.cy = cy
self.rx = rx
Expand All @@ -96,15 +96,15 @@ extension DOM {
}

final class Rect: GraphicsElement, @unchecked Sendable {
var x: Coordinate?
var y: Coordinate?
var width: Coordinate
var height: Coordinate
var rx: Coordinate?
var ry: Coordinate?
init(x: Coordinate? = nil, y: Coordinate? = nil, width: Coordinate, height: Coordinate) {
package var x: Coordinate?
package var y: Coordinate?
package var width: Coordinate
package var height: Coordinate

package var rx: Coordinate?
package var ry: Coordinate?

package init(x: Coordinate? = nil, y: Coordinate? = nil, width: Coordinate, height: Coordinate) {
self.x = x
self.y = y
self.width = width
Expand All @@ -114,24 +114,24 @@ extension DOM {
}

final class Polyline: GraphicsElement, @unchecked Sendable {
var points: [Point]
init(points: [Point]) {
package var points: [Point]

package init(points: [Point]) {
self.points = points
super.init()
}
}

final class Polygon: GraphicsElement, @unchecked Sendable {
var points: [Point]
init(points: [Point]) {
package var points: [Point]

package init(points: [Point]) {
self.points = points
super.init()
}
}

final class Group: GraphicsElement, ContainerElement, @unchecked Sendable {
var childElements = [GraphicsElement]()
package var childElements = [GraphicsElement]()
}
}
16 changes: 8 additions & 8 deletions SwiftDraw/DOM.Filter.swift → DOM/Sources/DOM.Filter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@
// 3. This notice may not be removed or altered from any source distribution.
//

extension DOM {
package extension DOM {

final class Filter: Element {
var id: String
var effects: [Effect]
init(id: String) {
package var id: String

package var effects: [Effect]

package init(id: String) {
self.id = id
self.effects = []
}

enum Effect: Hashable {
package enum Effect: Hashable {
case gaussianBlur(stdDeviation: DOM.Float)
}
}
Expand Down
16 changes: 8 additions & 8 deletions SwiftDraw/DOM.Image.swift → DOM/Sources/DOM.Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@
//
// 3. This notice may not be removed or altered from any source distribution.
//
extension DOM {
package extension DOM {
final class Image: GraphicsElement, @unchecked Sendable {
var href: URL
var width: Coordinate?
var height: Coordinate?
package var href: URL
package var width: Coordinate?
package var height: Coordinate?

var x: Coordinate?
var y: Coordinate?
init(href: URL) {
package var x: Coordinate?
package var y: Coordinate?

package init(href: URL) {
self.href = href
super.init()
}
Expand Down
Loading