@swiftbrowser/native 0.11.0 → 0.13.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 +38 -1
- package/bin/swiftbrowser-native.mjs +27 -8
- package/dist/bridge.d.ts +7 -0
- package/dist/bridge.d.ts.map +1 -1
- package/dist/bridge.js.map +1 -1
- package/dist/build.d.ts +22 -2
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +25 -8
- package/dist/build.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/runtime.d.ts +7 -3
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +16 -3
- package/dist/runtime.js.map +1 -1
- package/dist/site.d.ts +8 -0
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +24 -5
- package/dist/site.js.map +1 -1
- package/dist/worker.d.ts +87 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/worker.js +213 -0
- package/dist/worker.js.map +1 -0
- package/package.json +3 -3
- package/src/bridge.ts +12 -0
- package/src/build.ts +40 -8
- package/src/index.ts +1 -0
- package/src/runtime.ts +16 -3
- package/src/site.ts +31 -5
- package/src/worker.ts +236 -0
- package/swift/Package.swift +1 -0
- package/swift/Sources/SwiftBrowserNative/Host/HostBridge.swift +46 -2
- package/swift/Sources/SwiftBrowserNative/Host/JavaScriptCoreHost.swift +2 -1
- package/swift/Sources/SwiftBrowserNative/Host/WorkerHost.swift +279 -0
- package/swift/Sources/SwiftBrowserNative/Views/ElementView.swift +8 -1
- package/swift/Sources/SwiftBrowserNative/Views/Kinds/Charts.swift +340 -0
- package/swift/Sources/SwiftBrowserNative/Views/Kinds/Inspector.swift +29 -0
- package/swift/Sources/SwiftBrowserNative/Views/Kinds/Navigation.swift +8 -1
- package/swift/Sources/SwiftBrowserNative/Views/Kinds/Stacks.swift +58 -6
- package/swift/Sources/SwiftBrowserNative/Views/StyleModifier.swift +25 -7
- package/swift/Sources/SwiftBrowserProtocol/Props.swift +170 -0
- package/swift/Sources/SwiftBrowserProtocol/RendererEvent.swift +2 -0
- package/swift/Sources/SwiftBrowserProtocol/Style.swift +41 -0
- package/wasm/SwiftBrowserNative.wasm +2 -2
|
@@ -54,9 +54,13 @@ public struct StackProps: Equatable, Sendable {
|
|
|
54
54
|
/// A `VStack`'s horizontal alignment, an `HStack`'s vertical one, a `ZStack`'s frame alignment.
|
|
55
55
|
public var alignment: String
|
|
56
56
|
|
|
57
|
+
/// `.scrollTargetLayout()`: the stack's children are the snap points of the scroll view around it.
|
|
58
|
+
public var scrollTarget: Bool
|
|
59
|
+
|
|
57
60
|
public init(props: JSONObject) {
|
|
58
61
|
spacing = props.double("spacing")
|
|
59
62
|
alignment = props.string("alignment") ?? "center"
|
|
63
|
+
scrollTarget = props.bool("scrollTarget") ?? false
|
|
60
64
|
}
|
|
61
65
|
}
|
|
62
66
|
|
|
@@ -111,13 +115,27 @@ public struct ScrollViewProps: Equatable, Sendable {
|
|
|
111
115
|
public var axes: String
|
|
112
116
|
public var showsIndicators: Bool
|
|
113
117
|
public var refreshable: Bool
|
|
118
|
+
/// `.scrollTargetBehavior`: `viewAligned` or `paging`.
|
|
119
|
+
public var snap: String?
|
|
120
|
+
/// `.scrollPosition(id:)`: the view reports the marked element at its anchor as it settles.
|
|
121
|
+
public var reportsPosition: Bool
|
|
122
|
+
public var positionAnchor: UnitPointSpec?
|
|
114
123
|
public init(props: JSONObject) {
|
|
115
124
|
axes = props.string("axes") ?? "vertical"
|
|
116
125
|
showsIndicators = props.bool("showsIndicators") ?? true
|
|
117
126
|
refreshable = props.bool("refreshable") ?? false
|
|
127
|
+
snap = props.string("snap")
|
|
128
|
+
reportsPosition = props.bool("reportsPosition") ?? false
|
|
129
|
+
positionAnchor = UnitPointSpec(json: props.value("positionAnchor"))
|
|
118
130
|
}
|
|
119
131
|
}
|
|
120
132
|
|
|
133
|
+
/// `inspector`: the modified view's elements, then an `inspectorpanel`.
|
|
134
|
+
public struct InspectorProps: Equatable, Sendable {
|
|
135
|
+
public var presented: Bool
|
|
136
|
+
public init(props: JSONObject) { presented = props.bool("presented") ?? false }
|
|
137
|
+
}
|
|
138
|
+
|
|
121
139
|
public struct ListProps: Equatable, Sendable {
|
|
122
140
|
/// `insetGrouped` (the default), `grouped`, `plain`, `sidebar`.
|
|
123
141
|
public var style: String
|
|
@@ -473,3 +491,155 @@ public struct SizeReportProps: Equatable, Sendable {
|
|
|
473
491
|
reader = props.int("reader")
|
|
474
492
|
}
|
|
475
493
|
}
|
|
494
|
+
|
|
495
|
+
// MARK: - Charts
|
|
496
|
+
|
|
497
|
+
/// `chart`: the marks in unit coordinates of the plot (x 0…1 left to right,
|
|
498
|
+
/// y 0…1 top to bottom), the axes with their grid lines, ticks and labels
|
|
499
|
+
/// already placed and formatted, and the legend (docs/ops-protocol.md,
|
|
500
|
+
/// "Phase 7"). A renderer measures the labels, lays the plot out and draws.
|
|
501
|
+
public struct ChartProps: Equatable, Sendable {
|
|
502
|
+
public var marks: [ChartMarkSpec]
|
|
503
|
+
public var xAxis: ChartAxisSpec?
|
|
504
|
+
public var yAxis: ChartAxisSpec?
|
|
505
|
+
public var legend: ChartLegendSpec?
|
|
506
|
+
public init(props: JSONObject) {
|
|
507
|
+
marks = (props.array("marks") ?? []).compactMap(ChartMarkSpec.init(json:))
|
|
508
|
+
xAxis = ChartAxisSpec(json: props.value("xAxis"))
|
|
509
|
+
yAxis = ChartAxisSpec(json: props.value("yAxis"))
|
|
510
|
+
legend = ChartLegendSpec(json: props.value("legend"))
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
/// A point of a line (`y`) or an area (`y0 ≤ y1`) mark.
|
|
515
|
+
public struct ChartPointSpec: Equatable, Sendable {
|
|
516
|
+
public var x: Double
|
|
517
|
+
public var y: Double
|
|
518
|
+
public var y0: Double
|
|
519
|
+
public var y1: Double
|
|
520
|
+
init?(json: JSONValue) {
|
|
521
|
+
guard let x = json["x"].double else { return nil }
|
|
522
|
+
self.x = x
|
|
523
|
+
y = json["y"].double ?? json["y0"].double ?? 0
|
|
524
|
+
y0 = json["y0"].double ?? y
|
|
525
|
+
y1 = json["y1"].double ?? y
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/// One mark: `rect` (bars), `line`, `area`, `point` or `rule`.
|
|
530
|
+
public struct ChartMarkSpec: Equatable, Sendable {
|
|
531
|
+
public var kind: String
|
|
532
|
+
public var style: ShapeStyleSpec?
|
|
533
|
+
public var opacity: Double
|
|
534
|
+
/// `rect` and `rule`: the unit rect (a rule's two ends); `point`: `x0`/`y0`.
|
|
535
|
+
public var x0: Double
|
|
536
|
+
public var x1: Double
|
|
537
|
+
public var y0: Double
|
|
538
|
+
public var y1: Double
|
|
539
|
+
public var cornerRadius: Double
|
|
540
|
+
/// A rect this wide in points, centered on the unit rect, instead of the unit rect's width.
|
|
541
|
+
public var fixedWidth: Double?
|
|
542
|
+
/// `line` and `area`.
|
|
543
|
+
public var points: [ChartPointSpec]
|
|
544
|
+
public var lineWidth: Double
|
|
545
|
+
public var interpolation: String
|
|
546
|
+
/// `circle`, `square`, `triangle`, `diamond`, `cross`, `plus`, `asterisk`; nil for none.
|
|
547
|
+
public var symbol: String?
|
|
548
|
+
public var symbolSize: Double
|
|
549
|
+
public init?(json: JSONValue) {
|
|
550
|
+
guard let kind = json["kind"].string else { return nil }
|
|
551
|
+
self.kind = kind
|
|
552
|
+
style = ShapeStyleSpec(json: json["style"])
|
|
553
|
+
opacity = json["opacity"].double ?? 1
|
|
554
|
+
x0 = json["x0"].double ?? json["x"].double ?? 0
|
|
555
|
+
x1 = json["x1"].double ?? x0
|
|
556
|
+
y0 = json["y0"].double ?? json["y"].double ?? 0
|
|
557
|
+
y1 = json["y1"].double ?? y0
|
|
558
|
+
cornerRadius = json["cornerRadius"].double ?? 0
|
|
559
|
+
fixedWidth = json["fixedWidth"].double
|
|
560
|
+
points = (json["points"].array ?? []).compactMap(ChartPointSpec.init(json:))
|
|
561
|
+
lineWidth = json["lineWidth"].double ?? (kind == "rule" ? 1 : 2)
|
|
562
|
+
interpolation = json["interpolation"].string ?? "linear"
|
|
563
|
+
symbol = json["symbol"].string ?? (kind == "point" ? "circle" : nil)
|
|
564
|
+
symbolSize = json["symbolSize"].double ?? 8
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
public struct ChartAxisLabelSpec: Equatable, Sendable {
|
|
569
|
+
/// Unit position along the axis (y: 0 is the top).
|
|
570
|
+
public var at: Double
|
|
571
|
+
public var text: String
|
|
572
|
+
/// `leading`: an x label that starts at its tick instead of centering on it.
|
|
573
|
+
public var anchor: String?
|
|
574
|
+
init?(json: JSONValue) {
|
|
575
|
+
guard let at = json["at"].double else { return nil }
|
|
576
|
+
self.at = at
|
|
577
|
+
text = json["text"].string ?? ""
|
|
578
|
+
anchor = json["anchor"].string
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
public struct ChartAxisSpec: Equatable, Sendable {
|
|
583
|
+
/// x: `bottom` or `top`; y: `trailing` or `leading`.
|
|
584
|
+
public var position: String
|
|
585
|
+
public var gridLines: [Double]
|
|
586
|
+
public var dashed: Bool
|
|
587
|
+
public var ticks: [Double]
|
|
588
|
+
public var labels: [ChartAxisLabelSpec]
|
|
589
|
+
public init?(json: JSONValue) {
|
|
590
|
+
guard let fields = json.object else { return nil }
|
|
591
|
+
position = fields.string("position") ?? "bottom"
|
|
592
|
+
gridLines = (fields.array("gridLines") ?? []).compactMap(\.double)
|
|
593
|
+
dashed = fields.bool("dashed") ?? false
|
|
594
|
+
ticks = (fields.array("ticks") ?? []).compactMap(\.double)
|
|
595
|
+
labels = (fields.array("labels") ?? []).compactMap(ChartAxisLabelSpec.init(json:))
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
public struct ChartLegendItemSpec: Equatable, Sendable {
|
|
600
|
+
public var label: String
|
|
601
|
+
public var style: ShapeStyleSpec?
|
|
602
|
+
/// Nil: a short line instead of a symbol.
|
|
603
|
+
public var symbol: String?
|
|
604
|
+
init(json: JSONValue) {
|
|
605
|
+
label = json["label"].string ?? ""
|
|
606
|
+
style = ShapeStyleSpec(json: json["style"])
|
|
607
|
+
symbol = json["symbol"].string
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
public struct ChartLegendSpec: Equatable, Sendable {
|
|
612
|
+
/// `top`, `bottom`, `leading` or `trailing`.
|
|
613
|
+
public var position: String
|
|
614
|
+
public var items: [ChartLegendItemSpec]
|
|
615
|
+
public init?(json: JSONValue) {
|
|
616
|
+
guard let fields = json.object else { return nil }
|
|
617
|
+
position = fields.string("position") ?? "bottom"
|
|
618
|
+
items = (fields.array("items") ?? []).map(ChartLegendItemSpec.init(json:))
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
/// `chartitem`: an annotation against its mark's unit rect, or an axis label
|
|
623
|
+
/// view at its tick (`x0 == x1` for an x label, `y0 == y1` for a y label).
|
|
624
|
+
public struct ChartItemProps: Equatable, Sendable {
|
|
625
|
+
/// `annotation`, `xLabel` or `yLabel`.
|
|
626
|
+
public var role: String
|
|
627
|
+
public var x0: Double
|
|
628
|
+
public var x1: Double
|
|
629
|
+
public var y0: Double
|
|
630
|
+
public var y1: Double
|
|
631
|
+
/// `top`, `bottom`, `leading`, `trailing` or `overlay`.
|
|
632
|
+
public var position: String
|
|
633
|
+
public var alignment: String
|
|
634
|
+
public var spacing: Double
|
|
635
|
+
public init(props: JSONObject) {
|
|
636
|
+
role = props.string("role") ?? "annotation"
|
|
637
|
+
x0 = props.double("x0") ?? 0
|
|
638
|
+
x1 = props.double("x1") ?? x0
|
|
639
|
+
y0 = props.double("y0") ?? 0
|
|
640
|
+
y1 = props.double("y1") ?? y0
|
|
641
|
+
position = props.string("position") ?? "overlay"
|
|
642
|
+
alignment = props.string("alignment") ?? "center"
|
|
643
|
+
spacing = props.double("spacing") ?? 0
|
|
644
|
+
}
|
|
645
|
+
}
|
|
@@ -88,6 +88,8 @@ public struct RendererEvent: Equatable, Sendable {
|
|
|
88
88
|
public static func longPress(_ id: Int) -> RendererEvent { with("longpress", id: id) }
|
|
89
89
|
/// A `list` or `scrollview` with `refreshable` was pulled.
|
|
90
90
|
public static func refresh(_ id: Int) -> RendererEvent { with("refresh", id: id) }
|
|
91
|
+
/// `.scrollPosition(id:)`: the marked element at the scroll view's anchor once it settled.
|
|
92
|
+
public static func scrollPosition(_ id: Int) -> RendererEvent { with("scrollposition", id: id) }
|
|
91
93
|
/// A `menu` opened or closed (lazy menus build their items on `open`).
|
|
92
94
|
public static func menu(_ id: Int, open: Bool) -> RendererEvent { with("menu", id: id, ["open": .bool(open)]) }
|
|
93
95
|
/// The host's answer to a `native` element's own event (docs/native.md, the escape hatch).
|
|
@@ -67,6 +67,12 @@ public struct Style: Equatable, Sendable {
|
|
|
67
67
|
public var help: String?
|
|
68
68
|
public var matchedGeometry: String?
|
|
69
69
|
public var contentTransition: String?
|
|
70
|
+
/// `.containerRelativeFrame`: the length along each named axis is `a × container + b`.
|
|
71
|
+
public var containerRelativeFrame: ContainerRelativeFrameSpec?
|
|
72
|
+
/// `.id(x)` inside a `ScrollViewReader`: the element a `scrollTo` or a scroll position names.
|
|
73
|
+
public var scrollID: Bool
|
|
74
|
+
/// `proxy.scrollTo(x)`: the request (its serial is new each time) on the element it names.
|
|
75
|
+
public var scrollTo: ScrollToSpec?
|
|
70
76
|
|
|
71
77
|
public init(json: JSONValue) {
|
|
72
78
|
let fields = json.object ?? [:]
|
|
@@ -137,6 +143,9 @@ public struct Style: Equatable, Sendable {
|
|
|
137
143
|
help = fields.string("help")
|
|
138
144
|
matchedGeometry = fields.string("matchedGeometry")
|
|
139
145
|
contentTransition = fields.object("contentTransition")?.string("kind")
|
|
146
|
+
containerRelativeFrame = ContainerRelativeFrameSpec(json: fields.value("containerRelativeFrame"))
|
|
147
|
+
scrollID = fields.bool("scrollID") ?? false
|
|
148
|
+
scrollTo = ScrollToSpec(json: fields.value("scrollTo"))
|
|
140
149
|
}
|
|
141
150
|
|
|
142
151
|
public init() {
|
|
@@ -146,3 +155,35 @@ public struct Style: Equatable, Sendable {
|
|
|
146
155
|
/// The style's field names, for the unsupported-field diagnostics and tests.
|
|
147
156
|
public var fieldNames: [String] { raw.keys.sorted() }
|
|
148
157
|
}
|
|
158
|
+
|
|
159
|
+
/// `.containerRelativeFrame(axes)` as the style hint carries it: `length = a × container + b`.
|
|
160
|
+
public struct ContainerRelativeFrameSpec: Equatable, Sendable {
|
|
161
|
+
public var horizontal: Bool
|
|
162
|
+
public var vertical: Bool
|
|
163
|
+
public var a: Double
|
|
164
|
+
public var b: Double
|
|
165
|
+
public var alignment: String
|
|
166
|
+
public init?(json: JSONValue) {
|
|
167
|
+
guard let fields = json.object else { return nil }
|
|
168
|
+
horizontal = fields.bool("horizontal") ?? false
|
|
169
|
+
vertical = fields.bool("vertical") ?? false
|
|
170
|
+
a = fields.double("a") ?? 1
|
|
171
|
+
b = fields.double("b") ?? 0
|
|
172
|
+
alignment = fields.string("alignment") ?? "center"
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/// A `ScrollViewReader` proxy's `scrollTo` on the element it names.
|
|
177
|
+
public struct ScrollToSpec: Equatable, Sendable {
|
|
178
|
+
/// Increases with every request, across all readers.
|
|
179
|
+
public var serial: Double
|
|
180
|
+
public var anchor: UnitPointSpec?
|
|
181
|
+
/// `horizontal`, `vertical` or `both` (the default).
|
|
182
|
+
public var axes: String
|
|
183
|
+
public init?(json: JSONValue) {
|
|
184
|
+
guard let fields = json.object, let serial = fields.double("serial") else { return nil }
|
|
185
|
+
self.serial = serial
|
|
186
|
+
anchor = UnitPointSpec(json: fields.value("anchor"))
|
|
187
|
+
axes = fields.string("axes") ?? "both"
|
|
188
|
+
}
|
|
189
|
+
}
|
|
@@ -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: 49299538 bytes
|
|
4
|
+
sha256: 4d0446e4f7414a5c80780f1206c3d3b1d8577840d60b07efbb1e925b00caea88
|