@capgo/capacitor-widget-kit 9.0.0 → 9.0.2
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 +8 -0
- package/android/src/main/java/app/capgo/widgetkit/CapgoTemplateSvgBitmapRenderer.java +96 -0
- package/ios/Sources/CapgoWidgetKitPlugin/CapgoTemplateSvgAccessibility.swift +147 -0
- package/ios/Sources/CapgoWidgetKitPlugin/CapgoTemplateSvgView.swift +3 -0
- package/ios/Sources/CapgoWidgetKitPlugin/CapgoWorkoutLiveActivityComponents.swift +57 -14
- package/ios/Sources/CapgoWidgetKitPlugin/CapgoWorkoutLiveActivityWidget.swift +8 -1
- package/ios/Tests/CapgoWidgetKitPluginTests/CapgoTemplateSvgAccessibilityTests.swift +108 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,6 +30,7 @@ We build, improve and fix our plugins with heavy use of AI, so issues usually ge
|
|
|
30
30
|
|
|
31
31
|
## Key features
|
|
32
32
|
|
|
33
|
+
- **Foldable ready**: tested on iPhone Duo. See [Foldables, tablets and split screen](#foldables-tablets-and-split-screen).
|
|
33
34
|
- **SVG template widgets**: `startTemplateWidget()` and `startTemplateActivity()` store layouts for the Home Screen, Lock Screen, Dynamic Island and Android.
|
|
34
35
|
- **Updates and actions**: `updateTemplateActivity()`, `endTemplateActivity()` and `performTemplateAction()` with declarative state patches and timers.
|
|
35
36
|
- **Interaction events**: `listTemplateEvents()` and `acknowledgeTemplateEvents()` process widget taps in your app.
|
|
@@ -83,6 +84,13 @@ Capacitor 9 needs Node.js 24+, iOS 16+ (Xcode 27) and Android minSdk 26 / compil
|
|
|
83
84
|
|
|
84
85
|
No plugin API was removed: the JavaScript API of v9 is the same as v8.
|
|
85
86
|
|
|
87
|
+
## Foldables, tablets and split screen
|
|
88
|
+
|
|
89
|
+
On iOS, widget previews and hotspots size correctly on the folded cover screen and the unfolded inner screen.
|
|
90
|
+
|
|
91
|
+
- **iPhone Duo**: tested on the iPhone Duo simulator (iOS 27.2) on the folded cover screen, the unfolded inner screen, and through a live fold and unfold.
|
|
92
|
+
- **Android foldables (Galaxy Z Fold, Pixel Fold), tablets and multi-window**: the renderer fits the bitmap to the maximum width and height the launcher reports through `AppWidgetManager` options (Android reports size ranges, not one exact current size), with the bitmap edge capped. Re-render from your `AppWidgetProvider.onAppWidgetOptionsChanged`, as the example widget does, so the bitmap is redrawn when those bounds change after a resize or fold; switching between sizes that share the same maximum bounds does not change it. Android hosts lay out their own hotspot actions.
|
|
93
|
+
|
|
86
94
|
## Install
|
|
87
95
|
|
|
88
96
|
You can use our AI-Assisted Setup to install the plugin. Add the Capgo skills to your AI tool using the following command:
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
package app.capgo.widgetkit;
|
|
2
2
|
|
|
3
|
+
import android.appwidget.AppWidgetManager;
|
|
4
|
+
import android.content.Context;
|
|
3
5
|
import android.graphics.Bitmap;
|
|
4
6
|
import android.graphics.Canvas;
|
|
7
|
+
import android.os.Bundle;
|
|
5
8
|
import com.caverock.androidsvg.SVG;
|
|
6
9
|
import org.json.JSONObject;
|
|
7
10
|
|
|
8
11
|
public final class CapgoTemplateSvgBitmapRenderer {
|
|
9
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Longest bitmap edge produced for a home screen widget. RemoteViews bitmaps count against the
|
|
15
|
+
* launcher's IPC memory budget, so a widget stretched across an unfolded inner screen must not
|
|
16
|
+
* produce a full-resolution bitmap.
|
|
17
|
+
*/
|
|
18
|
+
public static final int DEFAULT_MAX_WIDGET_BITMAP_EDGE_PX = 1024;
|
|
19
|
+
|
|
10
20
|
private CapgoTemplateSvgBitmapRenderer() {}
|
|
11
21
|
|
|
12
22
|
public static Bitmap render(final JSONObject layout, final int targetWidthPx, final int targetHeightPx) throws Exception {
|
|
@@ -22,4 +32,90 @@ public final class CapgoTemplateSvgBitmapRenderer {
|
|
|
22
32
|
svg.renderToCanvas(canvas);
|
|
23
33
|
return bitmap;
|
|
24
34
|
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Renders the template for the widget's current size. Launchers report a new size through
|
|
38
|
+
* {@code onAppWidgetOptionsChanged} when the widget is resized, the device rotates, or a foldable
|
|
39
|
+
* switches between its cover and inner screens; call this again from there so the bitmap follows
|
|
40
|
+
* the new cell size instead of a size fixed at install time.
|
|
41
|
+
*/
|
|
42
|
+
public static Bitmap renderForWidget(
|
|
43
|
+
final Context context,
|
|
44
|
+
final AppWidgetManager appWidgetManager,
|
|
45
|
+
final int appWidgetId,
|
|
46
|
+
final JSONObject layout,
|
|
47
|
+
final int fallbackWidthPx,
|
|
48
|
+
final int fallbackHeightPx
|
|
49
|
+
) throws Exception {
|
|
50
|
+
final Bundle options = appWidgetManager.getAppWidgetOptions(appWidgetId);
|
|
51
|
+
final int[] size = widgetBitmapSize(
|
|
52
|
+
options != null ? options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, 0) : 0,
|
|
53
|
+
options != null ? options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, 0) : 0,
|
|
54
|
+
options != null ? options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, 0) : 0,
|
|
55
|
+
options != null ? options.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, 0) : 0,
|
|
56
|
+
context.getResources().getDisplayMetrics().density,
|
|
57
|
+
layout.optDouble("width", 0d),
|
|
58
|
+
layout.optDouble("height", 0d),
|
|
59
|
+
fallbackWidthPx,
|
|
60
|
+
fallbackHeightPx,
|
|
61
|
+
DEFAULT_MAX_WIDGET_BITMAP_EDGE_PX
|
|
62
|
+
);
|
|
63
|
+
return render(layout, size[0], size[1]);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Computes the bitmap size for a widget from its reported option bounds (in dp).
|
|
68
|
+
*
|
|
69
|
+
* <p>The bitmap is fitted to the largest reported bounds ({@code maxWidth x maxHeight}). The
|
|
70
|
+
* min/max bounds cannot tell which size is on screen: they cover portrait and landscape, and on
|
|
71
|
+
* Android 12+ launchers they also span every display of a foldable (cover and inner), so picking
|
|
72
|
+
* one by orientation could hand the inner screen a cover-sized bitmap that the ImageView then
|
|
73
|
+
* upscales and blurs. A single bitmap sized for the largest cell is scaled down sharply on the
|
|
74
|
+
* smaller ones. When the launcher reports nothing yet, the fallback size is used. When the template reports its own size, the result takes the template's aspect
|
|
75
|
+
* ratio and is the largest such size that fits the widget, so the SVG is not letterboxed twice.
|
|
76
|
+
* The result is scaled down so that neither edge exceeds {@code maxEdgePx}.
|
|
77
|
+
*
|
|
78
|
+
* @return {@code [widthPx, heightPx]}, both at least 1.
|
|
79
|
+
*/
|
|
80
|
+
public static int[] widgetBitmapSize(
|
|
81
|
+
final int minWidthDp,
|
|
82
|
+
final int maxWidthDp,
|
|
83
|
+
final int minHeightDp,
|
|
84
|
+
final int maxHeightDp,
|
|
85
|
+
final float density,
|
|
86
|
+
final double templateWidth,
|
|
87
|
+
final double templateHeight,
|
|
88
|
+
final int fallbackWidthPx,
|
|
89
|
+
final int fallbackHeightPx,
|
|
90
|
+
final int maxEdgePx
|
|
91
|
+
) {
|
|
92
|
+
final int widthDp = Math.max(Math.max(0, minWidthDp), maxWidthDp);
|
|
93
|
+
final int heightDp = Math.max(Math.max(0, minHeightDp), maxHeightDp);
|
|
94
|
+
final float scale = density > 0f ? density : 1f;
|
|
95
|
+
|
|
96
|
+
double width = widthDp > 0 && heightDp > 0 ? widthDp * scale : fallbackWidthPx;
|
|
97
|
+
double height = widthDp > 0 && heightDp > 0 ? heightDp * scale : fallbackHeightPx;
|
|
98
|
+
width = Math.max(1d, width);
|
|
99
|
+
height = Math.max(1d, height);
|
|
100
|
+
|
|
101
|
+
if (templateWidth > 0d && templateHeight > 0d && !Double.isNaN(templateWidth) && !Double.isNaN(templateHeight)) {
|
|
102
|
+
final double templateAspect = templateWidth / templateHeight;
|
|
103
|
+
if (width / height > templateAspect) {
|
|
104
|
+
width = height * templateAspect;
|
|
105
|
+
} else {
|
|
106
|
+
height = width / templateAspect;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (maxEdgePx > 0) {
|
|
111
|
+
final double longest = Math.max(width, height);
|
|
112
|
+
if (longest > maxEdgePx) {
|
|
113
|
+
final double ratio = maxEdgePx / longest;
|
|
114
|
+
width *= ratio;
|
|
115
|
+
height *= ratio;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return new int[] { Math.max(1, (int) Math.round(width)), Math.max(1, (int) Math.round(height)) };
|
|
120
|
+
}
|
|
25
121
|
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
/// Derives a VoiceOver label for a rasterized template. The bitmap hides the SVG's text from accessibility,
|
|
4
|
+
/// so this reads the root `<title>` (a direct child of `<svg>`) when present, otherwise the text that
|
|
5
|
+
/// `CapgoTemplateSvgRenderer` actually draws, in document order. Markup that does not parse as XML gets no
|
|
6
|
+
/// label and is treated as decorative.
|
|
7
|
+
///
|
|
8
|
+
/// The text rules mirror SwiftDraw 0.29, which rasterizes the templates:
|
|
9
|
+
/// - a `<text>` is drawn only when every ancestor is `svg`, `g`, `a` or `switch`, and inside a `switch`
|
|
10
|
+
/// only its first child element is drawn (`defs`, `symbol`, `clipPath`, `mask`, `pattern`, `marker`,
|
|
11
|
+
/// `title`, `desc`, `metadata` and unknown elements never draw their text);
|
|
12
|
+
/// - a `<text>` draws its own character data, or, when that is blank, its first `<tspan>`; other tspans
|
|
13
|
+
/// are not drawn;
|
|
14
|
+
/// - `display` and `visibility` are not applied to text, so they do not hide it from the label either.
|
|
15
|
+
enum CapgoTemplateSvgAccessibility {
|
|
16
|
+
static func label(for svg: String) -> String? {
|
|
17
|
+
guard let data = svg.data(using: .utf8) else {
|
|
18
|
+
return nil
|
|
19
|
+
}
|
|
20
|
+
let collector = LabelCollector()
|
|
21
|
+
let parser = XMLParser(data: data)
|
|
22
|
+
parser.shouldResolveExternalEntities = false
|
|
23
|
+
parser.delegate = collector
|
|
24
|
+
guard parser.parse() else {
|
|
25
|
+
return nil
|
|
26
|
+
}
|
|
27
|
+
if let title = collector.rootTitle, !title.isEmpty {
|
|
28
|
+
return title
|
|
29
|
+
}
|
|
30
|
+
let texts = collector.texts.filter { !$0.isEmpty }
|
|
31
|
+
return texts.isEmpty ? nil : texts.joined(separator: ", ")
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/// SAX delegate that collects the root title and the text the renderer draws.
|
|
36
|
+
private final class LabelCollector: NSObject, XMLParserDelegate {
|
|
37
|
+
/// Containers whose children the renderer draws.
|
|
38
|
+
private static let drawingContainers: Set<String> = ["svg", "g", "a", "switch"]
|
|
39
|
+
|
|
40
|
+
private struct Frame {
|
|
41
|
+
let name: String
|
|
42
|
+
/// Whether this element's child elements are drawn.
|
|
43
|
+
let drawsChildren: Bool
|
|
44
|
+
var childElementCount = 0
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private struct TextCapture {
|
|
48
|
+
let depth: Int
|
|
49
|
+
var ownText = ""
|
|
50
|
+
/// Depth of the first tspan while it is open.
|
|
51
|
+
var firstTspanDepth: Int?
|
|
52
|
+
var firstTspanText = ""
|
|
53
|
+
var sawTspan = false
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private(set) var rootTitle: String?
|
|
57
|
+
private(set) var texts: [String] = []
|
|
58
|
+
|
|
59
|
+
private var frames: [Frame] = []
|
|
60
|
+
private var titleDepth: Int?
|
|
61
|
+
private var titleText = ""
|
|
62
|
+
private var textCapture: TextCapture?
|
|
63
|
+
|
|
64
|
+
func parser(
|
|
65
|
+
_ parser: XMLParser,
|
|
66
|
+
didStartElement elementName: String,
|
|
67
|
+
namespaceURI: String?,
|
|
68
|
+
qualifiedName qName: String?,
|
|
69
|
+
attributes attributeDict: [String: String] = [:]
|
|
70
|
+
) {
|
|
71
|
+
let name = localName(elementName)
|
|
72
|
+
let depth = frames.count
|
|
73
|
+
var drawn = true
|
|
74
|
+
if let parentIndex = frames.indices.last {
|
|
75
|
+
let parent = frames[parentIndex]
|
|
76
|
+
drawn = parent.drawsChildren && (parent.name != "switch" || parent.childElementCount == 0)
|
|
77
|
+
frames[parentIndex].childElementCount += 1
|
|
78
|
+
} else {
|
|
79
|
+
drawn = name == "svg"
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if var capture = textCapture {
|
|
83
|
+
if name == "tspan", depth == capture.depth + 1, !capture.sawTspan {
|
|
84
|
+
capture.sawTspan = true
|
|
85
|
+
capture.firstTspanDepth = depth
|
|
86
|
+
}
|
|
87
|
+
textCapture = capture
|
|
88
|
+
} else if name == "title", depth == 1, rootTitle == nil, titleDepth == nil {
|
|
89
|
+
titleDepth = depth
|
|
90
|
+
} else if name == "text", drawn {
|
|
91
|
+
textCapture = TextCapture(depth: depth)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
frames.append(Frame(name: name, drawsChildren: drawn && Self.drawingContainers.contains(name)))
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
func parser(
|
|
98
|
+
_ parser: XMLParser,
|
|
99
|
+
didEndElement elementName: String,
|
|
100
|
+
namespaceURI: String?,
|
|
101
|
+
qualifiedName qName: String?
|
|
102
|
+
) {
|
|
103
|
+
_ = frames.popLast()
|
|
104
|
+
let depth = frames.count
|
|
105
|
+
if titleDepth == depth {
|
|
106
|
+
rootTitle = collapseWhitespace(titleText)
|
|
107
|
+
titleDepth = nil
|
|
108
|
+
} else if let capture = textCapture, capture.depth == depth {
|
|
109
|
+
let own = collapseWhitespace(capture.ownText)
|
|
110
|
+
texts.append(own.isEmpty ? collapseWhitespace(capture.firstTspanText) : own)
|
|
111
|
+
textCapture = nil
|
|
112
|
+
} else if textCapture?.firstTspanDepth == depth {
|
|
113
|
+
// Later tspans open at the same depth and are not drawn.
|
|
114
|
+
textCapture?.firstTspanDepth = nil
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
func parser(_ parser: XMLParser, foundCharacters string: String) {
|
|
119
|
+
append(string)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
func parser(_ parser: XMLParser, foundCDATA CDATABlock: Data) {
|
|
123
|
+
append(String(data: CDATABlock, encoding: .utf8) ?? "")
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/// Character data belongs to the innermost open element only, as in SwiftDraw's DOM parser.
|
|
127
|
+
private func append(_ string: String) {
|
|
128
|
+
let innermost = frames.count - 1
|
|
129
|
+
if titleDepth == innermost {
|
|
130
|
+
titleText += string
|
|
131
|
+
} else if textCapture?.depth == innermost {
|
|
132
|
+
textCapture?.ownText += string
|
|
133
|
+
} else if let tspanDepth = textCapture?.firstTspanDepth, tspanDepth == innermost {
|
|
134
|
+
textCapture?.firstTspanText += string
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
private func localName(_ name: String) -> String {
|
|
139
|
+
name.split(separator: ":").last.map(String.init) ?? name
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private func collapseWhitespace(_ text: String) -> String {
|
|
143
|
+
text.components(separatedBy: .whitespacesAndNewlines)
|
|
144
|
+
.filter { !$0.isEmpty }
|
|
145
|
+
.joined(separator: " ")
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -210,9 +210,12 @@ public struct CapgoTemplateSvgView<Fallback: View>: View {
|
|
|
210
210
|
public var body: some View {
|
|
211
211
|
GeometryReader { proxy in
|
|
212
212
|
if let image = CapgoTemplateSvgRenderer.render(svg: svg, size: proxy.size, scale: displayScale) {
|
|
213
|
+
let label = CapgoTemplateSvgAccessibility.label(for: svg)
|
|
213
214
|
Image(uiImage: image)
|
|
214
215
|
.resizable()
|
|
215
216
|
.frame(width: proxy.size.width, height: proxy.size.height)
|
|
217
|
+
.accessibilityLabel(Text(label ?? ""))
|
|
218
|
+
.accessibilityHidden(label == nil)
|
|
216
219
|
} else {
|
|
217
220
|
fallback()
|
|
218
221
|
.frame(width: proxy.size.width, height: proxy.size.height)
|
|
@@ -14,6 +14,7 @@ struct WorkoutRecommendationPill: View {
|
|
|
14
14
|
HStack(spacing: 6) {
|
|
15
15
|
Image(systemName: "sparkles")
|
|
16
16
|
.font(.caption.bold())
|
|
17
|
+
.accessibilityHidden(true)
|
|
17
18
|
Text(text)
|
|
18
19
|
.font(.caption.weight(.semibold))
|
|
19
20
|
.lineLimit(1)
|
|
@@ -21,7 +22,7 @@ struct WorkoutRecommendationPill: View {
|
|
|
21
22
|
.foregroundStyle(.white)
|
|
22
23
|
.padding(.horizontal, 10)
|
|
23
24
|
.padding(.vertical, 6)
|
|
24
|
-
.background(Capsule().fill(Color.
|
|
25
|
+
.background(Capsule().fill(Color.capgoBlueInk))
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
|
|
@@ -34,11 +35,37 @@ struct WorkoutTimerLabel: View {
|
|
|
34
35
|
HStack(spacing: 6) {
|
|
35
36
|
Image(systemName: "timer")
|
|
36
37
|
.font(.subheadline.bold())
|
|
37
|
-
|
|
38
|
+
.accessibilityHidden(true)
|
|
39
|
+
WorkoutCountdownText(timer: timer, now: now)
|
|
38
40
|
.font(.system(.title3, design: .rounded).weight(.bold))
|
|
39
|
-
.monospacedDigit()
|
|
40
41
|
}
|
|
41
42
|
.foregroundStyle(Color.capgoMint)
|
|
43
|
+
// The icon is hidden, so VoiceOver reads the live countdown itself.
|
|
44
|
+
.accessibilityElement(children: .combine)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/// Live Activities are archived snapshots, so a `TimelineView` does not tick between activity updates.
|
|
49
|
+
/// `Text(timerInterval:)` is rendered live by the system, keeping the countdown accurate on the Lock Screen
|
|
50
|
+
/// and in the Dynamic Island. Digits stay tabular so the width does not jitter every second.
|
|
51
|
+
@available(iOS 16.2, *)
|
|
52
|
+
struct WorkoutCountdownText: View {
|
|
53
|
+
let timer: WorkoutActiveTimer
|
|
54
|
+
let now: Date
|
|
55
|
+
|
|
56
|
+
var body: some View {
|
|
57
|
+
let start = Date(timeIntervalSince1970: TimeInterval(timer.startedAtMs) / 1000)
|
|
58
|
+
let end = Date(timeIntervalSince1970: TimeInterval(timer.endAtMs) / 1000)
|
|
59
|
+
if end > start, end > now {
|
|
60
|
+
Text(timerInterval: start...end, countsDown: true)
|
|
61
|
+
.monospacedDigit()
|
|
62
|
+
.lineLimit(1)
|
|
63
|
+
.multilineTextAlignment(.trailing)
|
|
64
|
+
} else {
|
|
65
|
+
Text(timer.remainingText(now: now))
|
|
66
|
+
.monospacedDigit()
|
|
67
|
+
.lineLimit(1)
|
|
68
|
+
}
|
|
42
69
|
}
|
|
43
70
|
}
|
|
44
71
|
|
|
@@ -54,7 +81,8 @@ struct RestProgressBackground: View {
|
|
|
54
81
|
|
|
55
82
|
HStack(spacing: 0) {
|
|
56
83
|
Rectangle()
|
|
57
|
-
.
|
|
84
|
+
// Kept dim so white/mint text and the completion button stay legible on top of it.
|
|
85
|
+
.fill(Color.capgoMint.opacity(0.35))
|
|
58
86
|
.frame(width: remainingWidth)
|
|
59
87
|
Spacer(minLength: 0)
|
|
60
88
|
}
|
|
@@ -66,6 +94,7 @@ struct RestProgressBackground: View {
|
|
|
66
94
|
@available(iOS 16.2, *)
|
|
67
95
|
struct WorkoutCompletionButton: View {
|
|
68
96
|
let sessionId: String
|
|
97
|
+
var size = CGSize(width: 76, height: 62)
|
|
69
98
|
|
|
70
99
|
var body: some View {
|
|
71
100
|
Group {
|
|
@@ -82,17 +111,20 @@ struct WorkoutCompletionButton: View {
|
|
|
82
111
|
buttonBody
|
|
83
112
|
#endif
|
|
84
113
|
}
|
|
114
|
+
.accessibilityLabel(Text("Complete set"))
|
|
85
115
|
}
|
|
86
116
|
|
|
87
117
|
private var buttonBody: some View {
|
|
88
118
|
ZStack {
|
|
89
|
-
RoundedRectangle(cornerRadius: 18, style: .continuous)
|
|
119
|
+
RoundedRectangle(cornerRadius: min(18, size.height * 0.3), style: .continuous)
|
|
90
120
|
.fill(Color.capgoMint)
|
|
121
|
+
// A dark glyph keeps ~9.5:1 contrast on mint; white was ~1.8:1.
|
|
91
122
|
Image(systemName: "checkmark")
|
|
92
|
-
.font(.system(size: 24, weight: .bold))
|
|
93
|
-
.foregroundStyle(.
|
|
123
|
+
.font(.system(size: min(24, size.height * 0.45), weight: .bold))
|
|
124
|
+
.foregroundStyle(Color.capgoMintInk)
|
|
125
|
+
.accessibilityHidden(true)
|
|
94
126
|
}
|
|
95
|
-
.frame(width:
|
|
127
|
+
.frame(width: size.width, height: size.height)
|
|
96
128
|
}
|
|
97
129
|
}
|
|
98
130
|
|
|
@@ -123,6 +155,7 @@ struct WorkoutDynamicIslandLeadingView: View {
|
|
|
123
155
|
var body: some View {
|
|
124
156
|
Image(systemName: "figure.strengthtraining.traditional")
|
|
125
157
|
.foregroundStyle(Color.capgoMint)
|
|
158
|
+
.accessibilityHidden(true)
|
|
126
159
|
}
|
|
127
160
|
}
|
|
128
161
|
|
|
@@ -138,12 +171,12 @@ struct WorkoutDynamicIslandTrailingView: View {
|
|
|
138
171
|
var body: some View {
|
|
139
172
|
TimelineView(.periodic(from: .now, by: 1)) { timeline in
|
|
140
173
|
if let timer = session?.activeTimer(now: timeline.date) {
|
|
141
|
-
|
|
142
|
-
.monospacedDigit()
|
|
174
|
+
WorkoutCountdownText(timer: timer, now: timeline.date)
|
|
143
175
|
.foregroundStyle(Color.capgoMint)
|
|
144
176
|
} else if contentState.isComplete {
|
|
145
177
|
Image(systemName: "checkmark.circle.fill")
|
|
146
178
|
.foregroundStyle(Color.capgoMint)
|
|
179
|
+
.accessibilityLabel(Text("Session complete"))
|
|
147
180
|
}
|
|
148
181
|
}
|
|
149
182
|
}
|
|
@@ -176,8 +209,7 @@ struct WorkoutDynamicIslandBottomView: View {
|
|
|
176
209
|
.lineLimit(1)
|
|
177
210
|
Spacer(minLength: 8)
|
|
178
211
|
if !(session?.isComplete ?? contentState.isComplete) {
|
|
179
|
-
WorkoutCompletionButton(sessionId: attributes.sessionId)
|
|
180
|
-
.frame(width: 54, height: 42)
|
|
212
|
+
WorkoutCompletionButton(sessionId: attributes.sessionId, size: CGSize(width: 54, height: 44))
|
|
181
213
|
}
|
|
182
214
|
}
|
|
183
215
|
}
|
|
@@ -191,8 +223,11 @@ struct WorkoutCompactLeadingView: View {
|
|
|
191
223
|
if let activeExerciseIndex = contentState.activeExerciseIndex, let activeSetIndex = contentState.activeSetIndex {
|
|
192
224
|
Text("\(activeExerciseIndex + 1).\(activeSetIndex + 1)")
|
|
193
225
|
.font(.caption2.monospacedDigit())
|
|
226
|
+
.contentTransition(.numericText())
|
|
227
|
+
.accessibilityLabel(Text("Exercise \(activeExerciseIndex + 1), set \(activeSetIndex + 1)"))
|
|
194
228
|
} else {
|
|
195
229
|
Image(systemName: "checkmark")
|
|
230
|
+
.accessibilityLabel(Text("Session complete"))
|
|
196
231
|
}
|
|
197
232
|
}
|
|
198
233
|
}
|
|
@@ -205,6 +240,7 @@ struct WorkoutCompactTrailingView: View {
|
|
|
205
240
|
if contentState.isComplete {
|
|
206
241
|
Image(systemName: "checkmark.circle.fill")
|
|
207
242
|
.foregroundStyle(Color.capgoMint)
|
|
243
|
+
.accessibilityLabel(Text("Session complete"))
|
|
208
244
|
} else if let timerStartedAtMs = contentState.timerStartedAtMs, let timerDurationMs = contentState.timerDurationMs {
|
|
209
245
|
TimelineView(.periodic(from: .now, by: 1)) { timeline in
|
|
210
246
|
let timer = WorkoutActiveTimer(
|
|
@@ -217,8 +253,9 @@ struct WorkoutCompactTrailingView: View {
|
|
|
217
253
|
startedAtMs: timerStartedAtMs,
|
|
218
254
|
durationMs: timerDurationMs
|
|
219
255
|
)
|
|
220
|
-
|
|
221
|
-
.font(.caption2
|
|
256
|
+
WorkoutCountdownText(timer: timer, now: timeline.date)
|
|
257
|
+
.font(.caption2)
|
|
258
|
+
.frame(maxWidth: 44)
|
|
222
259
|
}
|
|
223
260
|
}
|
|
224
261
|
}
|
|
@@ -232,9 +269,11 @@ struct WorkoutMinimalView: View {
|
|
|
232
269
|
if contentState.isComplete {
|
|
233
270
|
Image(systemName: "checkmark.circle.fill")
|
|
234
271
|
.foregroundStyle(Color.capgoMint)
|
|
272
|
+
.accessibilityLabel(Text("Session complete"))
|
|
235
273
|
} else {
|
|
236
274
|
Image(systemName: "figure.strengthtraining.traditional")
|
|
237
275
|
.foregroundStyle(Color.capgoMint)
|
|
276
|
+
.accessibilityLabel(Text("Workout in progress"))
|
|
238
277
|
}
|
|
239
278
|
}
|
|
240
279
|
}
|
|
@@ -242,5 +281,9 @@ struct WorkoutMinimalView: View {
|
|
|
242
281
|
extension Color {
|
|
243
282
|
static let capgoMint = Color(red: 0.0, green: 0.85, blue: 0.62)
|
|
244
283
|
static let capgoBlue = Color(red: 0.33, green: 0.56, blue: 1.0)
|
|
284
|
+
/// Dark ink for glyphs drawn on `capgoMint` (about 9.5:1 contrast).
|
|
285
|
+
static let capgoMintInk = Color(red: 0.0, green: 0.12, blue: 0.08)
|
|
286
|
+
/// Deeper brand blue that keeps white caption text above 4.5:1 contrast.
|
|
287
|
+
static let capgoBlueInk = Color(red: 0.2, green: 0.4, blue: 0.95)
|
|
245
288
|
}
|
|
246
289
|
#endif
|
|
@@ -14,6 +14,10 @@ public struct CapgoWorkoutLiveActivityWidget: Widget {
|
|
|
14
14
|
contentState: context.state,
|
|
15
15
|
displayContext: .lockScreen
|
|
16
16
|
)
|
|
17
|
+
// The card is drawn on black in both appearances; match the system background and
|
|
18
|
+
// dismiss button tint so light mode does not show a pale rim or a dark-on-dark control.
|
|
19
|
+
.activityBackgroundTint(Color.black)
|
|
20
|
+
.activitySystemActionForegroundColor(Color.white)
|
|
17
21
|
} dynamicIsland: { context in
|
|
18
22
|
DynamicIsland {
|
|
19
23
|
DynamicIslandExpandedRegion(.leading) {
|
|
@@ -129,7 +133,7 @@ private struct WorkoutLiveActivityView: View {
|
|
|
129
133
|
if let subtitle = currentExercise?.subtitle, !subtitle.isEmpty {
|
|
130
134
|
Text(subtitle)
|
|
131
135
|
.font(.subheadline)
|
|
132
|
-
.foregroundStyle(.white.opacity(0.
|
|
136
|
+
.foregroundStyle(.white.opacity(0.7))
|
|
133
137
|
.lineLimit(1)
|
|
134
138
|
}
|
|
135
139
|
|
|
@@ -183,6 +187,7 @@ private struct CompletedWorkoutView: View {
|
|
|
183
187
|
Image(systemName: "checkmark")
|
|
184
188
|
.font(.system(size: 48, weight: .bold))
|
|
185
189
|
.foregroundStyle(Color.capgoMint)
|
|
190
|
+
.accessibilityHidden(true)
|
|
186
191
|
}
|
|
187
192
|
.padding(18)
|
|
188
193
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
@@ -252,6 +257,8 @@ private struct WorkoutExerciseThumbnail: View {
|
|
|
252
257
|
}
|
|
253
258
|
.frame(width: 56, height: 56)
|
|
254
259
|
.clipShape(RoundedRectangle(cornerRadius: 12, style: .continuous))
|
|
260
|
+
// Decorative: the exercise title next to it already names the exercise.
|
|
261
|
+
.accessibilityHidden(true)
|
|
255
262
|
}
|
|
256
263
|
}
|
|
257
264
|
#endif
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import XCTest
|
|
2
|
+
@testable import CapgoWidgetKitShared
|
|
3
|
+
#if canImport(UIKit)
|
|
4
|
+
import UIKit
|
|
5
|
+
#endif
|
|
6
|
+
|
|
7
|
+
/// The label must name exactly the text `CapgoTemplateSvgRenderer` (SwiftDraw 0.29) draws.
|
|
8
|
+
final class CapgoTemplateSvgAccessibilityTests: XCTestCase {
|
|
9
|
+
private func label(_ body: String) -> String? {
|
|
10
|
+
CapgoTemplateSvgAccessibility.label(for: #"<svg xmlns="http://www.w3.org/2000/svg">"# + body + "</svg>")
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
func testAccessibilityLabelPrefersRootTitle() {
|
|
14
|
+
XCTAssertEqual(label(#"<title>Rest timer</title><text x="0" y="10">1:30</text>"#), "Rest timer")
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
func testAccessibilityLabelJoinsTextElementsAndDecodesEntities() {
|
|
18
|
+
let body = #"<text x="0" y="10" font-weight="700">Bench press</text>"#
|
|
19
|
+
+ #"<text x="0" y="30">Set 2 & 3 — Précis</text>"#
|
|
20
|
+
|
|
21
|
+
XCTAssertEqual(label(body), "Bench press, Set 2 & 3 \u{2014} Pr\u{E9}cis")
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
func testAccessibilityLabelIgnoresNestedTitlesAndComments() {
|
|
25
|
+
XCTAssertEqual(label(#"<g><title>Icon</title></g><!-- <text>Draft</text> --><text>Ready</text>"#), "Ready")
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
func testAccessibilityLabelDecodesReferencesOnceAndKeepsCdata() {
|
|
29
|
+
XCTAssertEqual(label(#"<text>&lt; < <![CDATA[a&b]]></text>"#), "< < a&b")
|
|
30
|
+
XCTAssertEqual(label(#"<text><![CDATA[<!--Ready-->]]></text>"#), "<!--Ready-->")
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
func testAccessibilityLabelReadsOnlyTheTspanTheRendererDraws() {
|
|
34
|
+
// Own character data wins; tspans are not drawn alongside it.
|
|
35
|
+
XCTAssertEqual(label(#"<text>Re<tspan>st</tspan></text>"#), "Re")
|
|
36
|
+
// Blank own text: only the first tspan is drawn.
|
|
37
|
+
XCTAssertEqual(label(#"<text> <tspan>Rest</tspan><tspan>Ignored</tspan></text>"#), "Rest")
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
func testAccessibilityLabelSkipsTitleAndDescInsideText() {
|
|
41
|
+
XCTAssertEqual(label(#"<text>Re<title>Tooltip</title><desc>Details</desc>ady</text>"#), "Ready")
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
func testAccessibilityLabelSkipsTextTheRendererDoesNotDraw() {
|
|
45
|
+
let body = #"<defs><text id="unused">Draft</text></defs>"#
|
|
46
|
+
+ #"<symbol id="s"><text>Symbol</text></symbol>"#
|
|
47
|
+
+ #"<clipPath id="c"><text>Clip</text></clipPath>"#
|
|
48
|
+
+ #"<mask id="m"><text>Mask</text></mask>"#
|
|
49
|
+
+ #"<metadata><text>Meta</text></metadata>"#
|
|
50
|
+
+ #"<foo><text>Unknown</text></foo>"#
|
|
51
|
+
+ #"<switch><rect width="1" height="1"/><text>Second</text></switch>"#
|
|
52
|
+
+ #"<switch><text>First</text><text>Other</text></switch>"#
|
|
53
|
+
+ ##"<a href="#x"><g><text>Ready</text></g></a>"##
|
|
54
|
+
|
|
55
|
+
XCTAssertEqual(label(body), "First, Ready")
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
func testAccessibilityLabelKeepsDisplayAndVisibilityHiddenTextTheRendererStillDraws() {
|
|
59
|
+
let body = #"<g display="none"><text>Draft</text></g>"#
|
|
60
|
+
+ #"<g style="display:none"><text>Inline</text></g>"#
|
|
61
|
+
+ #"<text style="visibility:hidden">Ready</text>"#
|
|
62
|
+
|
|
63
|
+
XCTAssertEqual(label(body), "Draft, Inline, Ready")
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
func testAccessibilityLabelIsNilForMalformedMarkup() {
|
|
67
|
+
XCTAssertNil(CapgoTemplateSvgAccessibility.label(for: "<svg><text>Ready</svg>"))
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
func testAccessibilityLabelIsNilWithoutText() {
|
|
71
|
+
XCTAssertNil(label(#"<rect width="10" height="10"/>"#))
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
#if canImport(UIKit)
|
|
75
|
+
/// Guards the parity assumptions above: if SwiftDraw starts honouring these, the label rules must follow.
|
|
76
|
+
func testRendererDrawsTheTextTheLabelReads() throws {
|
|
77
|
+
let text = #"<text x="0" y="30" font-size="30">Rest</text>"#
|
|
78
|
+
let drawn = try inkCount(text)
|
|
79
|
+
XCTAssertGreaterThan(drawn, 0)
|
|
80
|
+
XCTAssertEqual(try inkCount(#"<g display="none">"# + text + "</g>"), drawn)
|
|
81
|
+
XCTAssertEqual(try inkCount(#"<g style="visibility:hidden">"# + text + "</g>"), drawn)
|
|
82
|
+
XCTAssertEqual(try inkCount(#"<text x="0" y="30" font-size="30">Re<tspan>st</tspan></text>"#),
|
|
83
|
+
try inkCount(#"<text x="0" y="30" font-size="30">Re</text>"#))
|
|
84
|
+
XCTAssertEqual(try inkCount(#"<symbol id="s">"# + text + "</symbol>"), 0)
|
|
85
|
+
XCTAssertEqual(try inkCount(#"<switch><rect width="0" height="0"/>"# + text + "</switch>"), 0)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private func inkCount(_ body: String) throws -> Int {
|
|
89
|
+
let svg = #"<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 40">"# + body + "</svg>"
|
|
90
|
+
let image = try XCTUnwrap(CapgoTemplateSvgRenderer.render(svg: svg, size: CGSize(width: 200, height: 40), scale: 1))
|
|
91
|
+
let cgImage = try XCTUnwrap(image.cgImage)
|
|
92
|
+
let width = cgImage.width
|
|
93
|
+
let height = cgImage.height
|
|
94
|
+
var pixels = [UInt8](repeating: 0, count: width * height * 4)
|
|
95
|
+
let context = try XCTUnwrap(CGContext(
|
|
96
|
+
data: &pixels,
|
|
97
|
+
width: width,
|
|
98
|
+
height: height,
|
|
99
|
+
bitsPerComponent: 8,
|
|
100
|
+
bytesPerRow: width * 4,
|
|
101
|
+
space: CGColorSpaceCreateDeviceRGB(),
|
|
102
|
+
bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue
|
|
103
|
+
))
|
|
104
|
+
context.draw(cgImage, in: CGRect(x: 0, y: 0, width: width, height: height))
|
|
105
|
+
return stride(from: 3, to: pixels.count, by: 4).filter { pixels[$0] > 0 }.count
|
|
106
|
+
}
|
|
107
|
+
#endif
|
|
108
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@capgo/capacitor-widget-kit",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Capacitor plugin for generic iOS Home Screen widgets, WidgetKit, and Live Activities using SVG templates, declarative actions, and shared App Group persistence.",
|
|
6
6
|
"main": "dist/plugin.cjs.js",
|