@momo-kits/native-kits 0.169.13-beta.2-debug → 0.169.13-beta.3
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/CLAUDE.md +4 -1
- package/ios/Navigation/BottomTab/BottomTabBar.swift +4 -14
- package/ios/native-kits.podspec +1 -1
- package/ios-demo/MoMoUIKitsDemo.podspec +1 -1
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +3 -16
- package/package.json +1 -1
- package/scripts/sdui-visual/diff.py +65 -0
- package/scripts/sdui-visual/drive.py +234 -0
- package/scripts/sdui-visual/plan.json +713 -0
- package/scripts/sdui-visual/run.sh +92 -0
- package/build.gradle.kts +0 -11
- package/compose/build.gradle.kts +0 -198
- package/compose/compose.podspec +0 -47
- package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +0 -19
- package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +0 -6
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +0 -12
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +0 -7
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +0 -154
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +0 -17
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +0 -6
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +0 -110
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +0 -61
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +0 -1067
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +0 -268
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +0 -56
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +0 -157
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +0 -81
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +0 -32
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +0 -338
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +0 -175
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +0 -354
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +0 -115
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +0 -89
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +0 -130
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +0 -209
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +0 -482
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +0 -49
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +0 -86
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +0 -125
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +0 -224
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +0 -137
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +0 -473
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +0 -113
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +0 -262
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +0 -237
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +0 -228
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +0 -280
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +0 -183
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +0 -342
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +0 -108
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +0 -56
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +0 -40
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +0 -82
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +0 -39
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +0 -362
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +0 -108
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +0 -304
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +0 -59
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +0 -87
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +0 -21
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +0 -88
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +0 -308
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +0 -218
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +0 -456
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +0 -122
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +0 -205
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +0 -89
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +0 -542
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +0 -86
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +0 -175
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +0 -201
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +0 -498
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +0 -176
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +0 -182
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +0 -193
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +0 -29
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +0 -208
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +0 -180
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +0 -325
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +0 -12
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +0 -12
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +0 -16
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +0 -194
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +0 -291
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +0 -54
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/HeaderLayout.kt +0 -71
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +0 -50
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +0 -184
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +0 -315
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +0 -41
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +0 -54
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +0 -66
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +0 -11
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +0 -104
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +0 -48
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +0 -51
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +0 -397
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +0 -58
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +0 -153
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +0 -118
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +0 -206
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +0 -421
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +0 -8
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +0 -750
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +0 -152
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +0 -35
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +0 -242
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +0 -406
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +0 -111
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +0 -93
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +0 -208
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +0 -133
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +0 -167
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +0 -446
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +0 -105
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +0 -106
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +0 -74
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +0 -400
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +0 -39
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +0 -363
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +0 -197
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +0 -133
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +0 -127
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +0 -12
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +0 -114
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +0 -7
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +0 -76
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +0 -7
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +0 -21
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +0 -1329
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +0 -55
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +0 -15
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +0 -117
- package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +0 -42
- package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +0 -45
- package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +0 -32
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +0 -38
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +0 -65
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +0 -217
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +0 -48
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +0 -143
- package/gradle/libs.versions.toml +0 -67
- package/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/gradle/wrapper/gradle-wrapper.properties +0 -8
- package/gradle.properties +0 -24
- package/gradlew +0 -252
- package/gradlew.bat +0 -94
- package/ios-demo/README.md +0 -120
- package/settings.gradle.kts +0 -64
package/CLAUDE.md
CHANGED
|
@@ -22,15 +22,18 @@ Guidance for working in this repo. Keep it accurate — update it when structure
|
|
|
22
22
|
- `navigation/` — `NavigationContainer.kt` (**canonical entry point**), `Navigator.kt`, `Navigation.kt`, `StackScreen.kt`, `bottomtab/`, `component/`, `tracking/`.
|
|
23
23
|
- `const/` — design tokens: `Theme.kt`, `Colors.kt`, `Typography.kt`, `Spacing.kt`, `Radius.kt`.
|
|
24
24
|
- `layout/`, `modifier/`, `utils/`.
|
|
25
|
+
- `sdui/` — `SduiView(spec, modifier, onError, maxApi)`: embeddable server-driven-UI renderer (JSON spec -> kit components). No host seams: output goes only through the view's MaxApi (`maxApi`, else `LocalMaxApi`) - tracking events via `track` (Trackify), errors/warnings via `logFile` (spec-level identifiers only, deduped, capped). CornerStone / PlatformWidget are not supported: like any unknown type they draw nothing and report `sdui_node_error` (`unsupported_type`); any other child-node failure (`expr_failed`, `unknown_token`, `invalid_action`) is reported the same way, never capped. There is no click/action event: spec authors track clicks with their own `trackEvent` action. Actions use `maxApi` or `LocalMaxApi`; only typed actions exist (`type`: `startFeatureCode` | `trackEvent` | `setState`, required), an action without `type` (or with fields the runtime does not read, e.g. `code`) fails structure validation (SPEC_SHAPE); the runtime skip-and-warn guards are defence only. SduiView draws a section only: screen-level top-level keys (`header`, `footer`, `tabs`, `onMount`, `actions`, ...) fail validation. Device storage (`storage` get/set, MaxApi getItem/setItem) is not supported: such action fields fail structure validation. Expressions (`SduiExpr.kt`) follow JavaScript semantics for every supported construct, with one nullish value (null: `undefined`/missing names convert like JS null; a null optional argument counts as omitted); derived `spec.data` keys (`"{expr}"`) are re-evaluated on every read (memo only within one `evalExpr`), so they track state and repeat locals. Version: `SduiView.VERSION` (semver, set by hand, sent as `sduiVersion` on every tracking event) - bump PATCH for a renderer fix, MINOR for a new node / prop / action, MAJOR when a spec that used to work no longer does; `SduiView.RENDER_VERSION` is the feature level checked against `meta.minRenderVersion`. Tests: `compose/src/androidUnitTest/.../sdui/` (read the gallery/block specs from `sample/shared/.../composeResources/files/sdui/`).
|
|
25
26
|
- `platform/` — `Platform.kt` `expect` declarations, actualized in `androidMain` / `iosMain` (`Platform.android.kt`, `Platform.ios.kt`).
|
|
26
27
|
|
|
27
28
|
## Build & verify
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
The only unit tests are the SDUI ones (`androidUnitTest`); validate everything else by compiling the relevant target(s) and use the sample app for visual checks (the **SDUI** entry lists every bundled spec).
|
|
30
31
|
|
|
31
32
|
```bash
|
|
32
33
|
./gradlew :compose:compileCommonMainKotlinMetadata # validate commonMain (fast, do this first)
|
|
33
34
|
./gradlew :compose:compileDebugKotlinAndroid # Android target
|
|
35
|
+
./gradlew :compose:testDebugUnitTest # SDUI unit tests (537)
|
|
36
|
+
scripts/sdui-visual/run.sh baseline|check # SDUI visual regression on the emulator (see scripts/sdui-visual/README.md)
|
|
34
37
|
./gradlew :compose:linkDebugFrameworkIosSimulatorArm64 # iOS framework (slow)
|
|
35
38
|
./gradlew :sample:androidApp:installDebug # run demo on device/emulator
|
|
36
39
|
```
|
|
@@ -250,11 +250,7 @@ struct TabItemContent: View {
|
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
252
|
|
|
253
|
-
///
|
|
254
|
-
private let badgeMaxChars = 5
|
|
255
|
-
|
|
256
|
-
/// Badge value shown on a tab: nil hides it, "" is a dot, numbers cap at 99+ ("0" hides it, RN parity),
|
|
257
|
-
/// text keeps its first 5 characters.
|
|
253
|
+
/// Badge value shown on a tab: nil hides it, "" is a dot, numbers cap at 99+ ("0" hides it, RN parity).
|
|
258
254
|
func tabBadgeLabel(_ item: BottomTabItem) -> String? {
|
|
259
255
|
guard let label = item.badgeLabel else { return item.showDot ? "" : nil }
|
|
260
256
|
if label.isEmpty { return "" }
|
|
@@ -263,9 +259,7 @@ func tabBadgeLabel(_ item: BottomTabItem) -> String? {
|
|
|
263
259
|
if value == 0 { return item.showDot ? "" : nil }
|
|
264
260
|
return value > 99 ? "99+" : label
|
|
265
261
|
}
|
|
266
|
-
|
|
267
|
-
let head = String(label.prefix(badgeMaxChars))
|
|
268
|
-
return head.trimmingCharacters(in: .whitespaces) + "..."
|
|
262
|
+
return label
|
|
269
263
|
}
|
|
270
264
|
|
|
271
265
|
/// 24 icon, active and inactive tints cross-faded; badges hang off it: dot at 16/-2, label badge at
|
|
@@ -320,12 +314,8 @@ private struct TabBadge: View {
|
|
|
320
314
|
.scaleSizeMaxRate(1)
|
|
321
315
|
.padding(.horizontal, Spacing.XS)
|
|
322
316
|
.frame(minWidth: 16, maxWidth: TabBarMetrics.badgeMaxWidth, minHeight: 16, maxHeight: 16)
|
|
323
|
-
|
|
324
|
-
.background
|
|
325
|
-
Capsule()
|
|
326
|
-
.fill(isNumber ? theme.colors.error.primary : theme.colors.warning.primary)
|
|
327
|
-
.overlay(Capsule().strokeBorder(theme.colors.background.surface, lineWidth: 1))
|
|
328
|
-
)
|
|
317
|
+
.background(Capsule().fill(isNumber ? theme.colors.error.primary : theme.colors.warning.primary))
|
|
318
|
+
.overlay(Capsule().strokeBorder(theme.colors.background.surface, lineWidth: 1))
|
|
329
319
|
}
|
|
330
320
|
}
|
|
331
321
|
|
package/ios/native-kits.podspec
CHANGED
|
@@ -89,18 +89,7 @@ private func ctaLottie(_ animation: LottieAnimation?, offset: CGFloat) -> some V
|
|
|
89
89
|
}
|
|
90
90
|
private let badges: [(String, String?)] = [
|
|
91
91
|
("Không", nil), ("Dot \"\"", ""), ("\"0\"", "0"), ("\"5\"", "5"),
|
|
92
|
-
("\"1999\"", "1999"), ("\"Mới\"", "Mới"),
|
|
93
|
-
]
|
|
94
|
-
|
|
95
|
-
/// "Chữ dài" picks one of these at random on every tap.
|
|
96
|
-
private let longBadges = [
|
|
97
|
-
"Khuyến mãi lớn",
|
|
98
|
-
"Khám phá ngay",
|
|
99
|
-
"Ưu đãi cực sốc",
|
|
100
|
-
"Quà tặng hấp dẫn",
|
|
101
|
-
"Hoàn tiền mỗi ngày",
|
|
102
|
-
"Siêu sale cuối tuần",
|
|
103
|
-
"Thanh toán hóa đơn",
|
|
92
|
+
("\"1999\"", "1999"), ("\"Mới\"", "Mới"), ("Chữ dài", "Khuyến mãi lớn"),
|
|
104
93
|
]
|
|
105
94
|
|
|
106
95
|
struct BottomTabDemoContent: View {
|
|
@@ -186,12 +175,10 @@ private struct TabContent: View {
|
|
|
186
175
|
Section(title: "Tab đang mở · \(name)") {
|
|
187
176
|
IconOptions(title: "icon", icons: icons, value: tab.icon) { icon in updateTab { $0.icon = icon } }
|
|
188
177
|
Options(title: "badgeLabel",
|
|
189
|
-
hint: "\"\" là dot, \"0\" ẩn badge, số > 99 hiện 99+, chữ
|
|
178
|
+
hint: "\"\" là dot, \"0\" ẩn badge, số > 99 hiện 99+, chữ dài bị cắt ở 58",
|
|
190
179
|
options: badges.map { title, value in
|
|
191
180
|
Option(title: title, selected: tab.badgeLabel == value) { updateTab { $0.badgeLabel = value } }
|
|
192
|
-
}
|
|
193
|
-
updateTab { $0.badgeLabel = longBadges.randomElement() }
|
|
194
|
-
}])
|
|
181
|
+
})
|
|
195
182
|
Options(title: "showDot",
|
|
196
183
|
hint: "Hiện dot khi không có badgeLabel hoặc badgeLabel là \"0\"",
|
|
197
184
|
options: yesNo(tab.showDot) { value in updateTab { $0.showDot = value } })
|
package/package.json
CHANGED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# File: scripts/sdui-visual/diff.py
|
|
2
|
+
# Created At: 2026-11-10 15:30:00 +07:00
|
|
3
|
+
# Created By: AI
|
|
4
|
+
# AI Agent: Claude Code
|
|
5
|
+
# Model: claude-opus-5-5
|
|
6
|
+
"""Pixel-diff two capture folders. usage: diff.py <a> <b> <diffdir> [--noise <baseline2 dir>]
|
|
7
|
+
Status bar (top 110 px, demo-mode clock is fixed but kept out anyway) is excluded. With --noise, pixels that differed
|
|
8
|
+
between the two baseline runs of the same image are masked (inherent noise: animations, image loading)."""
|
|
9
|
+
import json, os, sys
|
|
10
|
+
from PIL import Image, ImageChops
|
|
11
|
+
|
|
12
|
+
STATUS = 110
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def load(p):
|
|
16
|
+
return Image.open(p).convert("RGB")
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def mask_of(a, b):
|
|
20
|
+
d = ImageChops.difference(a, b).convert("L").point(lambda v: 255 if v else 0)
|
|
21
|
+
return d
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def main():
|
|
25
|
+
a, b, out = sys.argv[1:4]
|
|
26
|
+
noise_dir = sys.argv[sys.argv.index("--noise") + 1] if "--noise" in sys.argv else None
|
|
27
|
+
os.makedirs(out, exist_ok=True)
|
|
28
|
+
rows = []
|
|
29
|
+
names = sorted(set(os.listdir(a)) | set(os.listdir(b)))
|
|
30
|
+
for n in names:
|
|
31
|
+
if not n.endswith(".png"):
|
|
32
|
+
continue
|
|
33
|
+
if n not in os.listdir(a) or n not in os.listdir(b):
|
|
34
|
+
rows.append((n, "MISSING", -1, -1, -1)); continue
|
|
35
|
+
ia, ib = load(f"{a}/{n}"), load(f"{b}/{n}")
|
|
36
|
+
if ia.size != ib.size:
|
|
37
|
+
rows.append((n, "SIZE", -1, -1, -1)); continue
|
|
38
|
+
w, h = ia.size
|
|
39
|
+
d = mask_of(ia, ib)
|
|
40
|
+
d.paste(0, (0, 0, w, STATUS))
|
|
41
|
+
raw = d.width * d.height - d.histogram()[0]
|
|
42
|
+
masked = raw
|
|
43
|
+
if noise_dir and os.path.exists(f"{noise_dir}/{n}"):
|
|
44
|
+
nz = mask_of(ia, load(f"{noise_dir}/{n}"))
|
|
45
|
+
keep = ImageChops.subtract(d, nz)
|
|
46
|
+
masked = keep.width * keep.height - keep.histogram()[0]
|
|
47
|
+
else:
|
|
48
|
+
keep = d
|
|
49
|
+
total = w * (h - STATUS)
|
|
50
|
+
if raw:
|
|
51
|
+
vis = ib.copy()
|
|
52
|
+
red = Image.new("RGB", ib.size, (255, 0, 0))
|
|
53
|
+
vis.paste(red, (0, 0), keep if masked else d)
|
|
54
|
+
vis.save(f"{out}/{n}")
|
|
55
|
+
rows.append((n, "OK", raw, masked, 100.0 * masked / total))
|
|
56
|
+
zero = sum(1 for r in rows if r[1] == "OK" and r[3] == 0)
|
|
57
|
+
for r in rows:
|
|
58
|
+
if r[1] != "OK" or r[2]:
|
|
59
|
+
print(f"{r[0]:40s} {r[1]:7s} raw={r[2]} beyond_noise={r[3]} ({r[4]:.4f}%)")
|
|
60
|
+
print(f"images={len(rows)} zero_beyond_noise={zero} raw_zero={sum(1 for r in rows if r[1]=='OK' and r[2]==0)}")
|
|
61
|
+
json.dump(rows, open(f"{out}/summary.json", "w"), indent=0)
|
|
62
|
+
sys.exit(0 if zero == len(rows) else 1)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
main()
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
# File: scripts/sdui-visual/drive.py
|
|
2
|
+
# Created At: 2026-11-10 15:30:00 +07:00
|
|
3
|
+
# Created By: AI
|
|
4
|
+
# AI Agent: Claude Code
|
|
5
|
+
# Model: claude-opus-5-5
|
|
6
|
+
"""Drive the sample app: open every bundled SDUI spec, capture pages + interaction states.
|
|
7
|
+
|
|
8
|
+
usage: drive.py <outdir> [--plan plan.json] [--record plan.json] [--only a,b]
|
|
9
|
+
--record: discover page counts + tap coordinates and save them (baseline run)
|
|
10
|
+
--plan: replay exactly the page counts + taps from a recorded plan
|
|
11
|
+
(a spec missing from the plan is discovered on the fly, not saved)
|
|
12
|
+
"""
|
|
13
|
+
import io, json, re, subprocess, sys, time, os
|
|
14
|
+
from PIL import Image, ImageChops
|
|
15
|
+
|
|
16
|
+
PKG = "com.myapplication.MyApplication"
|
|
17
|
+
ACT = "com.myapplication.MainActivity"
|
|
18
|
+
USAGE_KT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..",
|
|
19
|
+
"sample/shared/src/commonMain/kotlin/screens/SduiUsage.kt")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def spec_list(name):
|
|
23
|
+
"""A spec list (GALLERY / BLOCKS / SHOWCASE) exactly as the sample app shows it, read from SduiUsage.kt."""
|
|
24
|
+
src = open(USAGE_KT, encoding="utf-8").read()
|
|
25
|
+
m = re.search(r"val " + name + r" = listOf\(([^)]*)\)", src)
|
|
26
|
+
if not m:
|
|
27
|
+
raise SystemExit(f"{name} list not found in {USAGE_KT}")
|
|
28
|
+
return re.findall(r'"([^"]+)"', m.group(1))
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
# same order as the app's list screen
|
|
32
|
+
ALL = spec_list("SHOWCASE") + spec_list("BLOCKS") + spec_list("GALLERY")
|
|
33
|
+
# specs with state-changing actions (setState) that can be driven by taps (inputs need typing: skipped)
|
|
34
|
+
TAPPABLE = ["button", "carousel", "check-box", "chip", "collapse", "icon-button", "information", "popup-notify", "popup-promotion",
|
|
35
|
+
"radio", "rating", "slider", "stepper", "steps", "suggest-action", "swipe", "switch", "tab-view", "title",
|
|
36
|
+
"touchable-opacity", "uploader", "community", "paylater_benefits", "paylater_history"]
|
|
37
|
+
MAX_TAPS = 4
|
|
38
|
+
SETTLE = 3.0
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def sh(*a, capture=True):
|
|
42
|
+
return subprocess.run(["adb", *a], capture_output=capture, check=False).stdout
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def shot():
|
|
46
|
+
return Image.open(io.BytesIO(sh("exec-out", "screencap", "-p"))).convert("RGB")
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def dump():
|
|
50
|
+
for _ in range(3):
|
|
51
|
+
sh("shell", "uiautomator", "dump", "/sdcard/ui.xml")
|
|
52
|
+
x = sh("shell", "cat", "/sdcard/ui.xml").decode("utf-8", "replace")
|
|
53
|
+
if "<hierarchy" in x:
|
|
54
|
+
return x
|
|
55
|
+
time.sleep(0.5)
|
|
56
|
+
return ""
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
NODE = re.compile(r'<node [^>]*>')
|
|
60
|
+
def nodes(xml):
|
|
61
|
+
out = []
|
|
62
|
+
for m in NODE.finditer(xml):
|
|
63
|
+
s = m.group(0)
|
|
64
|
+
g = lambda k: (re.search(k + r'="([^"]*)"', s) or [None, ""])[1]
|
|
65
|
+
b = re.match(r'\[(\d+),(\d+)\]\[(\d+),(\d+)\]', g("bounds"))
|
|
66
|
+
if not b:
|
|
67
|
+
continue
|
|
68
|
+
x1, y1, x2, y2 = map(int, b.groups())
|
|
69
|
+
out.append(dict(text=g("text"), desc=g("content-desc"), clickable=g("clickable") == "true", b=(x1, y1, x2, y2)))
|
|
70
|
+
return out
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def tap(x, y):
|
|
74
|
+
sh("shell", "input", "tap", str(x), str(y))
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def swipe_up(dist=1000, dur=1200):
|
|
78
|
+
sh("shell", "input", "swipe", "540", "1900", "540", str(1900 - dist), str(dur))
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def swipe_down(dist=1000, dur=300):
|
|
82
|
+
sh("shell", "input", "swipe", "540", "700", "540", str(700 + dist), str(dur))
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def find_text(name, tries=14, up=True):
|
|
86
|
+
for _ in range(tries):
|
|
87
|
+
for n in nodes(dump()):
|
|
88
|
+
if n["text"] == name and 250 < (n["b"][1] + n["b"][3]) // 2 < 2250:
|
|
89
|
+
return n
|
|
90
|
+
if up:
|
|
91
|
+
swipe_up(700, 600)
|
|
92
|
+
else:
|
|
93
|
+
swipe_down(1500, 300)
|
|
94
|
+
time.sleep(0.6)
|
|
95
|
+
return None
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def launch_to_list():
|
|
99
|
+
sh("shell", "am", "force-stop", PKG)
|
|
100
|
+
sh("shell", "am", "start", "-n", f"{PKG}/{ACT}")
|
|
101
|
+
time.sleep(4)
|
|
102
|
+
n = find_text("SDUI", tries=25)
|
|
103
|
+
if not n:
|
|
104
|
+
raise SystemExit("SDUI entry not found")
|
|
105
|
+
x1, y1, x2, y2 = n["b"]
|
|
106
|
+
tap((x1 + x2) // 2, (y1 + y2) // 2)
|
|
107
|
+
time.sleep(2)
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def to_top():
|
|
111
|
+
for _ in range(6):
|
|
112
|
+
swipe_down(1600, 200)
|
|
113
|
+
time.sleep(0.8)
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def open_spec(name):
|
|
117
|
+
to_top()
|
|
118
|
+
n = find_text(name, tries=14)
|
|
119
|
+
if not n:
|
|
120
|
+
raise RuntimeError(f"spec {name} not found in list")
|
|
121
|
+
x1, y1, x2, y2 = n["b"]
|
|
122
|
+
tap((x1 + x2) // 2, (y1 + y2) // 2)
|
|
123
|
+
time.sleep(SETTLE)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def back():
|
|
127
|
+
sh("shell", "input", "keyevent", "4")
|
|
128
|
+
time.sleep(1.2)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
EXTRA = {
|
|
132
|
+
"carousel": [["hswipe", 900, 543, 150, 400], ["hswipe", 900, 543, 150, 400]],
|
|
133
|
+
"slider": [["hswipe", 257, 463, 500, 800]],
|
|
134
|
+
"swipe": [["hswipe", 900, 520, 300, 800], ["hswipe", 200, 770, 800, 800]],
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def act(a):
|
|
139
|
+
if a[0] == "tap":
|
|
140
|
+
tap(a[1], a[2])
|
|
141
|
+
elif a[0] == "scroll":
|
|
142
|
+
swipe_up(); time.sleep(0.3)
|
|
143
|
+
elif a[0] == "hswipe":
|
|
144
|
+
sh("shell", "input", "swipe", str(a[1]), str(a[2]), str(a[3]), str(a[2]), str(a[4]))
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def same(a, b):
|
|
148
|
+
return ImageChops.difference(a, b).getbbox() is None
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def run(outdir, plan, record_path, only):
|
|
152
|
+
os.makedirs(outdir, exist_ok=True)
|
|
153
|
+
launch_to_list()
|
|
154
|
+
new_plan = {}
|
|
155
|
+
for name in ALL:
|
|
156
|
+
if only and name not in only:
|
|
157
|
+
continue
|
|
158
|
+
entry = (plan or {}).get(name)
|
|
159
|
+
t0 = time.time()
|
|
160
|
+
# ---- pages
|
|
161
|
+
open_spec(name)
|
|
162
|
+
pages = []
|
|
163
|
+
img = shot(); img.save(f"{outdir}/{name}-p0.png"); pages.append(img)
|
|
164
|
+
if entry is not None:
|
|
165
|
+
for p in range(1, entry["pages"]):
|
|
166
|
+
swipe_up(); time.sleep(1.5)
|
|
167
|
+
img = shot(); img.save(f"{outdir}/{name}-p{p}.png")
|
|
168
|
+
else:
|
|
169
|
+
for p in range(1, 10):
|
|
170
|
+
swipe_up(); time.sleep(1.5)
|
|
171
|
+
img = shot()
|
|
172
|
+
if same(img, pages[-1]):
|
|
173
|
+
break
|
|
174
|
+
img.save(f"{outdir}/{name}-p{p}.png"); pages.append(img)
|
|
175
|
+
npages = entry["pages"] if entry is not None else len(pages)
|
|
176
|
+
back()
|
|
177
|
+
# ---- interaction states
|
|
178
|
+
taps = []
|
|
179
|
+
if name in TAPPABLE:
|
|
180
|
+
open_spec(name)
|
|
181
|
+
if entry is not None:
|
|
182
|
+
taps = entry["taps"]
|
|
183
|
+
for k, a in enumerate(taps):
|
|
184
|
+
act(a)
|
|
185
|
+
if a[0] == "scroll":
|
|
186
|
+
if k + 1 < len(taps) and taps[k + 1][0] != "scroll":
|
|
187
|
+
time.sleep(1.5)
|
|
188
|
+
continue
|
|
189
|
+
time.sleep(1.8)
|
|
190
|
+
shot().save(f"{outdir}/{name}-tap{k}.png")
|
|
191
|
+
else:
|
|
192
|
+
k = 0
|
|
193
|
+
for pg in range(npages if npages > 1 else 1):
|
|
194
|
+
if pg > 0 and pg != npages - 1:
|
|
195
|
+
continue
|
|
196
|
+
if pg > 0:
|
|
197
|
+
for _ in range(npages - 1):
|
|
198
|
+
a = ["scroll"]; act(a); taps.append(a)
|
|
199
|
+
time.sleep(1.5)
|
|
200
|
+
seen = set(); n_here = 0
|
|
201
|
+
for n in [n for n in nodes(dump()) if n["clickable"] and n["b"][1] > 300 and n["b"][3] < 2250]:
|
|
202
|
+
c = ((n["b"][0] + n["b"][2]) // 2, (n["b"][1] + n["b"][3]) // 2)
|
|
203
|
+
if c in seen:
|
|
204
|
+
continue
|
|
205
|
+
seen.add(c)
|
|
206
|
+
a = ["tap", c[0], c[1]]; act(a); taps.append(a); time.sleep(1.8)
|
|
207
|
+
shot().save(f"{outdir}/{name}-tap{len(taps) - 1}.png")
|
|
208
|
+
n_here += 1
|
|
209
|
+
if n_here >= MAX_TAPS:
|
|
210
|
+
break
|
|
211
|
+
for a in EXTRA.get(name, []):
|
|
212
|
+
act(a); taps.append(a); time.sleep(1.8)
|
|
213
|
+
shot().save(f"{outdir}/{name}-tap{len(taps) - 1}.png")
|
|
214
|
+
back()
|
|
215
|
+
# a tap may have opened a popup / modal: make sure we are back on the list
|
|
216
|
+
if not find_text(name, tries=1):
|
|
217
|
+
back()
|
|
218
|
+
new_plan[name] = {"pages": npages, "taps": taps}
|
|
219
|
+
print(f"{name}: pages={npages} taps={len(taps)} ({time.time() - t0:.1f}s)", flush=True)
|
|
220
|
+
if record_path:
|
|
221
|
+
json.dump(new_plan, open(record_path, "w"), indent=1)
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
if __name__ == "__main__":
|
|
225
|
+
args = sys.argv[1:]
|
|
226
|
+
out = args[0]
|
|
227
|
+
plan = rec = None; only = None
|
|
228
|
+
if "--plan" in args:
|
|
229
|
+
plan = json.load(open(args[args.index("--plan") + 1]))
|
|
230
|
+
if "--record" in args:
|
|
231
|
+
rec = args[args.index("--record") + 1]
|
|
232
|
+
if "--only" in args:
|
|
233
|
+
only = set(args[args.index("--only") + 1].split(","))
|
|
234
|
+
run(out, plan, rec, only)
|