Skip to content

Commit 041a209

Browse files
committed
Add webcodecs IDL spec and generated code
1 parent efffa34 commit 041a209

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2004
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// This file was auto-generated by WebIDLToSwift. DO NOT EDIT!
2+
3+
import JavaScriptEventLoop
4+
import JavaScriptKit
5+
6+
public enum AlphaOption: JSString, JSValueCompatible {
7+
case keep = "keep"
8+
case discard = "discard"
9+
10+
@inlinable public static func construct(from jsValue: JSValue) -> Self? {
11+
if let string = jsValue.jsString {
12+
return Self(rawValue: string)
13+
}
14+
return nil
15+
}
16+
17+
@inlinable public init?(string: String) {
18+
self.init(rawValue: JSString(string))
19+
}
20+
21+
@inlinable public var jsValue: JSValue { rawValue.jsValue }
22+
}

Sources/DOMKit/WebIDL/AudioData.swift

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// This file was auto-generated by WebIDLToSwift. DO NOT EDIT!
2+
3+
import JavaScriptEventLoop
4+
import JavaScriptKit
5+
6+
public class AudioData: JSBridgedClass {
7+
@inlinable public class var constructor: JSFunction { JSObject.global[Strings.AudioData].function! }
8+
9+
public let jsObject: JSObject
10+
11+
public required init(unsafelyWrapping jsObject: JSObject) {
12+
_format = ReadonlyAttribute(jsObject: jsObject, name: Strings.format)
13+
_sampleRate = ReadonlyAttribute(jsObject: jsObject, name: Strings.sampleRate)
14+
_numberOfFrames = ReadonlyAttribute(jsObject: jsObject, name: Strings.numberOfFrames)
15+
_numberOfChannels = ReadonlyAttribute(jsObject: jsObject, name: Strings.numberOfChannels)
16+
_duration = ReadonlyAttribute(jsObject: jsObject, name: Strings.duration)
17+
_timestamp = ReadonlyAttribute(jsObject: jsObject, name: Strings.timestamp)
18+
self.jsObject = jsObject
19+
}
20+
21+
@inlinable public convenience init(init: AudioDataInit) {
22+
self.init(unsafelyWrapping: Self.constructor.new(arguments: [`init`.jsValue]))
23+
}
24+
25+
@ReadonlyAttribute
26+
public var format: AudioSampleFormat?
27+
28+
@ReadonlyAttribute
29+
public var sampleRate: Float
30+
31+
@ReadonlyAttribute
32+
public var numberOfFrames: UInt32
33+
34+
@ReadonlyAttribute
35+
public var numberOfChannels: UInt32
36+
37+
@ReadonlyAttribute
38+
public var duration: UInt64
39+
40+
@ReadonlyAttribute
41+
public var timestamp: Int64
42+
43+
@inlinable public func allocationSize(options: AudioDataCopyToOptions) -> UInt32 {
44+
let this = jsObject
45+
return this[Strings.allocationSize].function!(this: this, arguments: [options.jsValue]).fromJSValue()!
46+
}
47+
48+
@inlinable public func copyTo(destination: BufferSource, options: AudioDataCopyToOptions) {
49+
let this = jsObject
50+
_ = this[Strings.copyTo].function!(this: this, arguments: [destination.jsValue, options.jsValue])
51+
}
52+
53+
@inlinable public func clone() -> Self {
54+
let this = jsObject
55+
return this[Strings.clone].function!(this: this, arguments: []).fromJSValue()!
56+
}
57+
58+
@inlinable public func close() {
59+
let this = jsObject
60+
_ = this[Strings.close].function!(this: this, arguments: [])
61+
}
62+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// This file was auto-generated by WebIDLToSwift. DO NOT EDIT!
2+
3+
import JavaScriptEventLoop
4+
import JavaScriptKit
5+
6+
public class AudioDataCopyToOptions: BridgedDictionary {
7+
public convenience init(planeIndex: UInt32, frameOffset: UInt32, frameCount: UInt32, format: AudioSampleFormat) {
8+
let object = JSObject.global[Strings.Object].function!.new()
9+
object[Strings.planeIndex] = planeIndex.jsValue
10+
object[Strings.frameOffset] = frameOffset.jsValue
11+
object[Strings.frameCount] = frameCount.jsValue
12+
object[Strings.format] = format.jsValue
13+
self.init(unsafelyWrapping: object)
14+
}
15+
16+
public required init(unsafelyWrapping object: JSObject) {
17+
_planeIndex = ReadWriteAttribute(jsObject: object, name: Strings.planeIndex)
18+
_frameOffset = ReadWriteAttribute(jsObject: object, name: Strings.frameOffset)
19+
_frameCount = ReadWriteAttribute(jsObject: object, name: Strings.frameCount)
20+
_format = ReadWriteAttribute(jsObject: object, name: Strings.format)
21+
super.init(unsafelyWrapping: object)
22+
}
23+
24+
@ReadWriteAttribute
25+
public var planeIndex: UInt32
26+
27+
@ReadWriteAttribute
28+
public var frameOffset: UInt32
29+
30+
@ReadWriteAttribute
31+
public var frameCount: UInt32
32+
33+
@ReadWriteAttribute
34+
public var format: AudioSampleFormat
35+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// This file was auto-generated by WebIDLToSwift. DO NOT EDIT!
2+
3+
import JavaScriptEventLoop
4+
import JavaScriptKit
5+
6+
public class AudioDataInit: BridgedDictionary {
7+
public convenience init(format: AudioSampleFormat, sampleRate: Float, numberOfFrames: UInt32, numberOfChannels: UInt32, timestamp: Int64, data: BufferSource) {
8+
let object = JSObject.global[Strings.Object].function!.new()
9+
object[Strings.format] = format.jsValue
10+
object[Strings.sampleRate] = sampleRate.jsValue
11+
object[Strings.numberOfFrames] = numberOfFrames.jsValue
12+
object[Strings.numberOfChannels] = numberOfChannels.jsValue
13+
object[Strings.timestamp] = timestamp.jsValue
14+
object[Strings.data] = data.jsValue
15+
self.init(unsafelyWrapping: object)
16+
}
17+
18+
public required init(unsafelyWrapping object: JSObject) {
19+
_format = ReadWriteAttribute(jsObject: object, name: Strings.format)
20+
_sampleRate = ReadWriteAttribute(jsObject: object, name: Strings.sampleRate)
21+
_numberOfFrames = ReadWriteAttribute(jsObject: object, name: Strings.numberOfFrames)
22+
_numberOfChannels = ReadWriteAttribute(jsObject: object, name: Strings.numberOfChannels)
23+
_timestamp = ReadWriteAttribute(jsObject: object, name: Strings.timestamp)
24+
_data = ReadWriteAttribute(jsObject: object, name: Strings.data)
25+
super.init(unsafelyWrapping: object)
26+
}
27+
28+
@ReadWriteAttribute
29+
public var format: AudioSampleFormat
30+
31+
@ReadWriteAttribute
32+
public var sampleRate: Float
33+
34+
@ReadWriteAttribute
35+
public var numberOfFrames: UInt32
36+
37+
@ReadWriteAttribute
38+
public var numberOfChannels: UInt32
39+
40+
@ReadWriteAttribute
41+
public var timestamp: Int64
42+
43+
@ReadWriteAttribute
44+
public var data: BufferSource
45+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// This file was auto-generated by WebIDLToSwift. DO NOT EDIT!
2+
3+
import JavaScriptEventLoop
4+
import JavaScriptKit
5+
6+
public class AudioDecoder: JSBridgedClass {
7+
@inlinable public class var constructor: JSFunction { JSObject.global[Strings.AudioDecoder].function! }
8+
9+
public let jsObject: JSObject
10+
11+
public required init(unsafelyWrapping jsObject: JSObject) {
12+
_state = ReadonlyAttribute(jsObject: jsObject, name: Strings.state)
13+
_decodeQueueSize = ReadonlyAttribute(jsObject: jsObject, name: Strings.decodeQueueSize)
14+
self.jsObject = jsObject
15+
}
16+
17+
@inlinable public convenience init(init: AudioDecoderInit) {
18+
self.init(unsafelyWrapping: Self.constructor.new(arguments: [`init`.jsValue]))
19+
}
20+
21+
@ReadonlyAttribute
22+
public var state: CodecState
23+
24+
@ReadonlyAttribute
25+
public var decodeQueueSize: UInt32
26+
27+
@inlinable public func configure(config: AudioDecoderConfig) {
28+
let this = jsObject
29+
_ = this[Strings.configure].function!(this: this, arguments: [config.jsValue])
30+
}
31+
32+
@inlinable public func decode(chunk: EncodedAudioChunk) {
33+
let this = jsObject
34+
_ = this[Strings.decode].function!(this: this, arguments: [chunk.jsValue])
35+
}
36+
37+
@inlinable public func flush() -> JSPromise {
38+
let this = jsObject
39+
return this[Strings.flush].function!(this: this, arguments: []).fromJSValue()!
40+
}
41+
42+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
43+
@inlinable public func flush() async throws {
44+
let this = jsObject
45+
let _promise: JSPromise = this[Strings.flush].function!(this: this, arguments: []).fromJSValue()!
46+
_ = try await _promise.value
47+
}
48+
49+
@inlinable public func reset() {
50+
let this = jsObject
51+
_ = this[Strings.reset].function!(this: this, arguments: [])
52+
}
53+
54+
@inlinable public func close() {
55+
let this = jsObject
56+
_ = this[Strings.close].function!(this: this, arguments: [])
57+
}
58+
59+
@inlinable public static func isConfigSupported(config: AudioDecoderConfig) -> JSPromise {
60+
let this = constructor
61+
return this[Strings.isConfigSupported].function!(this: this, arguments: [config.jsValue]).fromJSValue()!
62+
}
63+
64+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
65+
@inlinable public static func isConfigSupported(config: AudioDecoderConfig) async throws -> AudioDecoderSupport {
66+
let this = constructor
67+
let _promise: JSPromise = this[Strings.isConfigSupported].function!(this: this, arguments: [config.jsValue]).fromJSValue()!
68+
return try await _promise.value.fromJSValue()!
69+
}
70+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// This file was auto-generated by WebIDLToSwift. DO NOT EDIT!
2+
3+
import JavaScriptEventLoop
4+
import JavaScriptKit
5+
6+
public class AudioDecoderConfig: BridgedDictionary {
7+
public convenience init(codec: String, sampleRate: UInt32, numberOfChannels: UInt32, description: BufferSource) {
8+
let object = JSObject.global[Strings.Object].function!.new()
9+
object[Strings.codec] = codec.jsValue
10+
object[Strings.sampleRate] = sampleRate.jsValue
11+
object[Strings.numberOfChannels] = numberOfChannels.jsValue
12+
object[Strings.description] = description.jsValue
13+
self.init(unsafelyWrapping: object)
14+
}
15+
16+
public required init(unsafelyWrapping object: JSObject) {
17+
_codec = ReadWriteAttribute(jsObject: object, name: Strings.codec)
18+
_sampleRate = ReadWriteAttribute(jsObject: object, name: Strings.sampleRate)
19+
_numberOfChannels = ReadWriteAttribute(jsObject: object, name: Strings.numberOfChannels)
20+
_description = ReadWriteAttribute(jsObject: object, name: Strings.description)
21+
super.init(unsafelyWrapping: object)
22+
}
23+
24+
@ReadWriteAttribute
25+
public var codec: String
26+
27+
@ReadWriteAttribute
28+
public var sampleRate: UInt32
29+
30+
@ReadWriteAttribute
31+
public var numberOfChannels: UInt32
32+
33+
@ReadWriteAttribute
34+
public var description: BufferSource
35+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// This file was auto-generated by WebIDLToSwift. DO NOT EDIT!
2+
3+
import JavaScriptEventLoop
4+
import JavaScriptKit
5+
6+
public class AudioDecoderInit: BridgedDictionary {
7+
public convenience init(output: @escaping AudioDataOutputCallback, error: @escaping WebCodecsErrorCallback) {
8+
let object = JSObject.global[Strings.Object].function!.new()
9+
ClosureAttribute1Void[Strings.output, in: object] = output
10+
ClosureAttribute1Void[Strings.error, in: object] = error
11+
self.init(unsafelyWrapping: object)
12+
}
13+
14+
public required init(unsafelyWrapping object: JSObject) {
15+
_output = ClosureAttribute1Void(jsObject: object, name: Strings.output)
16+
_error = ClosureAttribute1Void(jsObject: object, name: Strings.error)
17+
super.init(unsafelyWrapping: object)
18+
}
19+
20+
@ClosureAttribute1Void
21+
public var output: AudioDataOutputCallback
22+
23+
@ClosureAttribute1Void
24+
public var error: WebCodecsErrorCallback
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// This file was auto-generated by WebIDLToSwift. DO NOT EDIT!
2+
3+
import JavaScriptEventLoop
4+
import JavaScriptKit
5+
6+
public class AudioDecoderSupport: BridgedDictionary {
7+
public convenience init(supported: Bool, config: AudioDecoderConfig) {
8+
let object = JSObject.global[Strings.Object].function!.new()
9+
object[Strings.supported] = supported.jsValue
10+
object[Strings.config] = config.jsValue
11+
self.init(unsafelyWrapping: object)
12+
}
13+
14+
public required init(unsafelyWrapping object: JSObject) {
15+
_supported = ReadWriteAttribute(jsObject: object, name: Strings.supported)
16+
_config = ReadWriteAttribute(jsObject: object, name: Strings.config)
17+
super.init(unsafelyWrapping: object)
18+
}
19+
20+
@ReadWriteAttribute
21+
public var supported: Bool
22+
23+
@ReadWriteAttribute
24+
public var config: AudioDecoderConfig
25+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// This file was auto-generated by WebIDLToSwift. DO NOT EDIT!
2+
3+
import JavaScriptEventLoop
4+
import JavaScriptKit
5+
6+
public class AudioEncoder: JSBridgedClass {
7+
@inlinable public class var constructor: JSFunction { JSObject.global[Strings.AudioEncoder].function! }
8+
9+
public let jsObject: JSObject
10+
11+
public required init(unsafelyWrapping jsObject: JSObject) {
12+
_state = ReadonlyAttribute(jsObject: jsObject, name: Strings.state)
13+
_encodeQueueSize = ReadonlyAttribute(jsObject: jsObject, name: Strings.encodeQueueSize)
14+
self.jsObject = jsObject
15+
}
16+
17+
@inlinable public convenience init(init: AudioEncoderInit) {
18+
self.init(unsafelyWrapping: Self.constructor.new(arguments: [`init`.jsValue]))
19+
}
20+
21+
@ReadonlyAttribute
22+
public var state: CodecState
23+
24+
@ReadonlyAttribute
25+
public var encodeQueueSize: UInt32
26+
27+
@inlinable public func configure(config: AudioEncoderConfig) {
28+
let this = jsObject
29+
_ = this[Strings.configure].function!(this: this, arguments: [config.jsValue])
30+
}
31+
32+
@inlinable public func encode(data: AudioData) {
33+
let this = jsObject
34+
_ = this[Strings.encode].function!(this: this, arguments: [data.jsValue])
35+
}
36+
37+
@inlinable public func flush() -> JSPromise {
38+
let this = jsObject
39+
return this[Strings.flush].function!(this: this, arguments: []).fromJSValue()!
40+
}
41+
42+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
43+
@inlinable public func flush() async throws {
44+
let this = jsObject
45+
let _promise: JSPromise = this[Strings.flush].function!(this: this, arguments: []).fromJSValue()!
46+
_ = try await _promise.value
47+
}
48+
49+
@inlinable public func reset() {
50+
let this = jsObject
51+
_ = this[Strings.reset].function!(this: this, arguments: [])
52+
}
53+
54+
@inlinable public func close() {
55+
let this = jsObject
56+
_ = this[Strings.close].function!(this: this, arguments: [])
57+
}
58+
59+
@inlinable public static func isConfigSupported(config: AudioEncoderConfig) -> JSPromise {
60+
let this = constructor
61+
return this[Strings.isConfigSupported].function!(this: this, arguments: [config.jsValue]).fromJSValue()!
62+
}
63+
64+
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
65+
@inlinable public static func isConfigSupported(config: AudioEncoderConfig) async throws -> AudioEncoderSupport {
66+
let this = constructor
67+
let _promise: JSPromise = this[Strings.isConfigSupported].function!(this: this, arguments: [config.jsValue]).fromJSValue()!
68+
return try await _promise.value.fromJSValue()!
69+
}
70+
}

0 commit comments

Comments
 (0)