@swiftbrowser/native 0.19.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -11
- package/dist/blob.d.ts +85 -11
- package/dist/blob.d.ts.map +1 -1
- package/dist/blob.js +184 -34
- package/dist/blob.js.map +1 -1
- package/dist/bridge.d.ts +33 -2
- package/dist/bridge.d.ts.map +1 -1
- package/dist/bridge.js.map +1 -1
- package/dist/fetch.d.ts +19 -11
- package/dist/fetch.d.ts.map +1 -1
- package/dist/fetch.js +105 -41
- package/dist/fetch.js.map +1 -1
- package/dist/hostRequests.d.ts +3 -1
- package/dist/hostRequests.d.ts.map +1 -1
- package/dist/hostRequests.js +47 -6
- package/dist/hostRequests.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/runtime.js +1 -1
- package/dist/runtime.js.map +1 -1
- package/dist/webSocket.d.ts.map +1 -1
- package/dist/webSocket.js +13 -1
- package/dist/webSocket.js.map +1 -1
- package/package.json +3 -3
- package/src/blob.ts +215 -34
- package/src/bridge.ts +27 -2
- package/src/fetch.ts +99 -41
- package/src/hostRequests.ts +62 -8
- package/src/index.ts +1 -2
- package/src/runtime.ts +1 -1
- package/src/webSocket.ts +10 -1
- package/swift/Packages/SwiftBrowserDSP/Sources/SwiftBrowserDSP/ProgramNode.swift +122 -19
- package/swift/Packages/SwiftBrowserDSP/Sources/SwiftBrowserDSP/ScopeView.swift +79 -0
- package/swift/Packages/SwiftBrowserDSP/Sources/SwiftBrowserDSPCore/Machine.swift +1247 -209
- package/swift/Packages/SwiftBrowserDSP/Sources/SwiftBrowserDSPCore/Program.swift +314 -19
- package/swift/Packages/SwiftBrowserShader/Package.swift +31 -0
- package/swift/Packages/SwiftBrowserShader/README.md +45 -0
- package/swift/Packages/SwiftBrowserShader/Sources/SwiftBrowserShader/ShaderRenderer.swift +103 -0
- package/swift/Packages/SwiftBrowserShader/Sources/SwiftBrowserShader/ShaderView.swift +168 -0
- package/swift/Packages/SwiftBrowserShader/Sources/SwiftBrowserShaderCore/ShaderProps.swift +120 -0
- package/swift/Sources/SwiftBrowserNative/Host/BodyStream.swift +166 -0
- package/swift/Sources/SwiftBrowserNative/Host/FilesBridge.swift +141 -7
- package/swift/Sources/SwiftBrowserNative/Host/HostBridge.swift +47 -1
- package/swift/Sources/SwiftBrowserNative/Host/HostRequestBridge.swift +98 -29
- package/swift/Sources/SwiftBrowserNative/Runtime/NativeFunctions.swift +1 -1
- package/swift/Sources/SwiftBrowserNative/Runtime/ViewRegistry.swift +57 -0
- package/swift/Sources/SwiftBrowserNative/Views/ElementView.swift +11 -7
- package/swift/Sources/SwiftBrowserNative/Views/Kinds/Drawing.swift +378 -0
- package/swift/Sources/SwiftBrowserNative/Views/Kinds/Navigation.swift +15 -10
- package/swift/Sources/SwiftBrowserNative/Views/Kinds/PopTap.swift +31 -28
- package/swift/Sources/SwiftBrowserNative/Views/StyleModifier.swift +142 -0
- package/swift/Sources/SwiftBrowserProtocol/Drawing.swift +306 -0
- package/swift/Sources/SwiftBrowserProtocol/Props.swift +5 -2
- package/swift/Sources/SwiftBrowserProtocol/RendererEvent.swift +24 -3
- package/swift/Sources/SwiftBrowserProtocol/Style.swift +87 -0
- package/wasm/SwiftBrowserNative.wasm +2 -2
- package/dist/native.d.ts +0 -19
- package/dist/native.d.ts.map +0 -1
- package/dist/native.js +0 -17
- package/dist/native.js.map +0 -1
- package/src/native.ts +0 -35
- package/swift/Sources/SwiftBrowserNative/Runtime/NativeRegistry.swift +0 -53
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
[diffend] Oversized file quarantined before diffing.
|
|
2
2
|
name: package/wasm/SwiftBrowserNative.wasm
|
|
3
|
-
size:
|
|
4
|
-
sha256:
|
|
3
|
+
size: 50264748 bytes
|
|
4
|
+
sha256: 7712613a6aed40822224c0e4042dab20c7de0e5708ff6ad8ce79f52013b76472
|
package/dist/native.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `<Native name props onEvent>`: the escape hatch (docs/native.md). The
|
|
3
|
-
* element kind `native`, which only this producer emits, names a SwiftUI view
|
|
4
|
-
* the app registered with `NativeRegistry.register(name)`; `props` reach it
|
|
5
|
-
* as JSON, its children as SwiftUI views, and what it sends back arrives at
|
|
6
|
-
* `onEvent`.
|
|
7
|
-
*/
|
|
8
|
-
import { type ReactElement, type ReactNode } from 'react';
|
|
9
|
-
export interface NativeProps {
|
|
10
|
-
/** The name registered on the Swift side. */
|
|
11
|
-
name: string;
|
|
12
|
-
/** JSON-serializable props for the view. */
|
|
13
|
-
props?: Record<string, unknown>;
|
|
14
|
-
/** A value the native view sent (`context.send(value)`). */
|
|
15
|
-
onEvent?: (value: unknown) => void;
|
|
16
|
-
children?: ReactNode;
|
|
17
|
-
}
|
|
18
|
-
export declare function Native({ name, props, onEvent, children }: NativeProps): ReactElement;
|
|
19
|
-
//# sourceMappingURL=native.d.ts.map
|
package/dist/native.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"native.d.ts","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAiB,KAAK,YAAY,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEzE,MAAM,WAAW,WAAW;IAC1B,6CAA6C;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb,4CAA4C;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,4DAA4D;IAC5D,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACnC,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAUD,wBAAgB,MAAM,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,EAAE,WAAW,GAAG,YAAY,CAMpF"}
|
package/dist/native.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `<Native name props onEvent>`: the escape hatch (docs/native.md). The
|
|
3
|
-
* element kind `native`, which only this producer emits, names a SwiftUI view
|
|
4
|
-
* the app registered with `NativeRegistry.register(name)`; `props` reach it
|
|
5
|
-
* as JSON, its children as SwiftUI views, and what it sends back arrives at
|
|
6
|
-
* `onEvent`.
|
|
7
|
-
*/
|
|
8
|
-
import { createElement } from 'react';
|
|
9
|
-
export function Native({ name, props, onEvent, children }) {
|
|
10
|
-
// The host element of @swiftbrowser/react: `sb` with the protocol kind and
|
|
11
|
-
// props, and the handlers by event type (packages/react/src/host/instance.ts).
|
|
12
|
-
const hostProps = { kind: 'native', props: { name, props: props ?? {} } };
|
|
13
|
-
if (onEvent)
|
|
14
|
-
hostProps['on'] = { native: (event) => onEvent(event.value) };
|
|
15
|
-
return children === undefined ? createElement('sb', hostProps) : createElement('sb', hostProps, children);
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=native.js.map
|
package/dist/native.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"native.js","sourceRoot":"","sources":["../src/native.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,aAAa,EAAqC,MAAM,OAAO,CAAC;AAoBzE,MAAM,UAAU,MAAM,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAe;IACpE,2EAA2E;IAC3E,+EAA+E;IAC/E,MAAM,SAAS,GAA4B,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,IAAI,EAAE,EAAE,EAAE,CAAC;IACnG,IAAI,OAAO;QAAE,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,CAAC,KAAkB,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;IACxF,OAAO,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;AAC5G,CAAC"}
|
package/src/native.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `<Native name props onEvent>`: the escape hatch (docs/native.md). The
|
|
3
|
-
* element kind `native`, which only this producer emits, names a SwiftUI view
|
|
4
|
-
* the app registered with `NativeRegistry.register(name)`; `props` reach it
|
|
5
|
-
* as JSON, its children as SwiftUI views, and what it sends back arrives at
|
|
6
|
-
* `onEvent`.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { createElement, type ReactElement, type ReactNode } from 'react';
|
|
10
|
-
|
|
11
|
-
export interface NativeProps {
|
|
12
|
-
/** The name registered on the Swift side. */
|
|
13
|
-
name: string;
|
|
14
|
-
/** JSON-serializable props for the view. */
|
|
15
|
-
props?: Record<string, unknown>;
|
|
16
|
-
/** A value the native view sent (`context.send(value)`). */
|
|
17
|
-
onEvent?: (value: unknown) => void;
|
|
18
|
-
children?: ReactNode;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** The shape of a `native` event (`RendererEvent` has no such member). */
|
|
22
|
-
interface NativeEvent {
|
|
23
|
-
type: 'native';
|
|
24
|
-
id: number;
|
|
25
|
-
name: string;
|
|
26
|
-
value: unknown;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function Native({ name, props, onEvent, children }: NativeProps): ReactElement {
|
|
30
|
-
// The host element of @swiftbrowser/react: `sb` with the protocol kind and
|
|
31
|
-
// props, and the handlers by event type (packages/react/src/host/instance.ts).
|
|
32
|
-
const hostProps: Record<string, unknown> = { kind: 'native', props: { name, props: props ?? {} } };
|
|
33
|
-
if (onEvent) hostProps['on'] = { native: (event: NativeEvent) => onEvent(event.value) };
|
|
34
|
-
return children === undefined ? createElement('sb', hostProps) : createElement('sb', hostProps, children);
|
|
35
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
#if canImport(SwiftUI)
|
|
2
|
-
import Foundation
|
|
3
|
-
import SwiftBrowserProtocol
|
|
4
|
-
import SwiftBrowserTree
|
|
5
|
-
import SwiftUI
|
|
6
|
-
|
|
7
|
-
/// What a registered native view gets: the element's `props` as the app
|
|
8
|
-
/// wrote them, its children (SwiftUI views the app put inside it) and a way
|
|
9
|
-
/// to send a value back, which reaches the element's `onEvent` in JavaScript.
|
|
10
|
-
public struct NativeViewContext {
|
|
11
|
-
public let id: Int
|
|
12
|
-
public let props: JSONValue
|
|
13
|
-
public let children: [ElementNode]
|
|
14
|
-
public let send: (JSONValue) -> Void
|
|
15
|
-
|
|
16
|
-
/// The children as a view (built on the main actor, as views are).
|
|
17
|
-
@MainActor public var content: some View {
|
|
18
|
-
ForEach(children) { ElementView(node: $0) }
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/// The escape hatch (docs/native.md): the `native` element kind, which only
|
|
23
|
-
/// a JavaScript producer emits, names a view the Swift app registered.
|
|
24
|
-
///
|
|
25
|
-
/// ```swift
|
|
26
|
-
/// NativeRegistry.register("MapView") { context in
|
|
27
|
-
/// MapView(region: context.props["region"]) { context.send(["tapped": true]) }
|
|
28
|
-
/// }
|
|
29
|
-
/// ```
|
|
30
|
-
///
|
|
31
|
-
/// ```tsx
|
|
32
|
-
/// <Native name="MapView" props={{ region }} onEvent={(value) => …} />
|
|
33
|
-
/// ```
|
|
34
|
-
@MainActor
|
|
35
|
-
public enum NativeRegistry {
|
|
36
|
-
public typealias Builder = (NativeViewContext) -> AnyView
|
|
37
|
-
private static var builders: [String: Builder] = [:]
|
|
38
|
-
|
|
39
|
-
public static func register<V: View>(_ name: String, @ViewBuilder _ builder: @escaping (NativeViewContext) -> V) {
|
|
40
|
-
builders[name] = { AnyView(builder($0)) }
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public static func unregister(_ name: String) {
|
|
44
|
-
builders[name] = nil
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
public static func isRegistered(_ name: String) -> Bool { builders[name] != nil }
|
|
48
|
-
|
|
49
|
-
static func view(name: String, context: NativeViewContext) -> AnyView? {
|
|
50
|
-
builders[name]?(context)
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
#endif
|