@momo-kits/native-kits 0.169.13-beta.2 → 0.169.13-beta.3-debug
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/build.gradle.kts +11 -0
- package/compose/build.gradle.kts +202 -0
- package/compose/compose.podspec +47 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/const/HostFont.android.kt +19 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/navigation/ScrollToTop.android.kt +6 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/BackGesture.android.kt +12 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/OsFontScale.android.kt +7 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/Platform.android.kt +154 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReduceMotion.android.kt +17 -0
- package/compose/src/androidMain/kotlin/vn/momo/kits/platform/ReservedRegions.android.kt +6 -0
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiActionsTest.kt +647 -0
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiExprTest.kt +1411 -0
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiHostTest.kt +130 -0
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiKitArgsTest.kt +524 -0
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiKitNodesTest.kt +559 -0
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiRenderPlanTest.kt +741 -0
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiRenderReuseTest.kt +221 -0
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiRendererPropsTest.kt +270 -0
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiStylePlanTest.kt +849 -0
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiStyleTest.kt +212 -0
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiTrackingTest.kt +239 -0
- package/compose/src/androidUnitTest/kotlin/vn/momo/kits/sdui/SduiViewTest.kt +252 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Context.kt +110 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/DesignSystemKits.kt +61 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/LiteScreen.kt +1067 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/Localize.kt +268 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/application/WidgetContainer.kt +56 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Avatar.kt +157 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Badge.kt +81 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeDot.kt +32 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BadgeRibbon.kt +338 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/BaselineView.kt +175 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Button.kt +354 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Carousel.kt +115 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/CheckBox.kt +89 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Chip.kt +130 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Collapse.kt +209 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/CupertinoOverscroll.kt +482 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Divider.kt +49 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Icon.kt +86 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/IconButton.kt +125 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Image.kt +224 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Information.kt +137 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Input.kt +473 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputDropDown.kt +113 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputMoney.kt +262 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputOTP.kt +237 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputPhoneNumber.kt +228 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputSearch.kt +280 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/InputTextArea.kt +183 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/LazyColumnWithBouncing.kt +342 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Loader.kt +108 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationDot.kt +56 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationNumber.kt +40 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationScroll.kt +82 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PaginationWhiteDot.kt +39 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupNotify.kt +362 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/PopupPromotion.kt +108 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/ProgressInfo.kt +304 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Radio.kt +59 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Rating.kt +87 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/ScaleSizeScope.kt +21 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Skeleton.kt +88 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Slider.kt +308 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Stepper.kt +218 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Steps.kt +456 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/SuggestAction.kt +122 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Swipe.kt +205 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Switch.kt +89 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/TabView.kt +542 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tag.kt +86 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Text.kt +175 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Title.kt +201 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Tooltip.kt +498 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/TrustBanner.kt +176 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/Uploader.kt +182 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePicker.kt +193 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerTypes.kt +29 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/DateTimePickerUtils.kt +208 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/components/datetimepicker/WheelPicker.kt +180 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Colors.kt +325 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/HostFont.kt +12 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Radius.kt +12 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Spacing.kt +16 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Theme.kt +194 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/const/Typography.kt +291 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Card.kt +54 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/HeaderLayout.kt +71 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Item.kt +50 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ModalLayout.kt +184 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/ScreenLayout.kt +315 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/layout/Section.kt +41 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/AutomationId.kt +54 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Clickable.kt +66 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Conditional.kt +11 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/DeprecatedModifier.kt +104 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Shadow.kt +48 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/modifier/Size.kt +51 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/BottomSheet.kt +397 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/HostBackGestureBridge.kt +58 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ModalScreen.kt +153 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigation.kt +118 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/NavigationContainer.kt +206 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/Navigator.kt +421 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/ScrollToTop.kt +8 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackScreen.kt +750 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/StackTransition.kt +152 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/SwipeBackHaptic.kt +35 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTab.kt +242 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/BottomTabBar.kt +398 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/CurvedContainer.kt +103 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoBarCompression.kt +93 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/DuoTabBar.kt +208 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/bottomtab/TabBarMetrics.kt +133 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/FloatingButton.kt +167 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/Header.kt +446 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderBackground.kt +105 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderJourney.kt +106 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderLocation.kt +74 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderRight.kt +400 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderTitle.kt +39 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/HeaderUser.kt +363 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SideBar.kt +197 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/component/SnackBar.kt +133 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/navigation/tracking/ScreenTracker.kt +127 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/BackGesture.kt +12 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ComposeLottieAnimation.kt +114 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/OsFontScale.kt +7 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/Platform.kt +76 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReduceMotion.kt +7 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/platform/ReservedRegions.kt +21 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiActions.kt +154 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiExpr.kt +1038 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiKitNodes.kt +848 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiLog.kt +47 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiModel.kt +39 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiPropsRenderer.kt +463 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiRenderer.kt +1146 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiStyle.kt +667 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiTracking.kt +240 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiValidate.kt +185 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiView.kt +200 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Icons.kt +1329 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Resources.kt +55 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Tracking.kt +15 -0
- package/compose/src/commonMain/kotlin/vn/momo/kits/utils/Utils.kt +117 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/const/HostFont.ios.kt +42 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/HostBackGesture.ios.kt +45 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/navigation/ScrollToTop.ios.kt +32 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/BackGesture.ios.kt +38 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/OsFontScale.ios.kt +65 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/Platform.ios.kt +217 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReduceMotion.ios.kt +48 -0
- package/compose/src/iosMain/kotlin/vn/momo/kits/platform/ReservedRegions.ios.kt +143 -0
- package/gradle/libs.versions.toml +69 -0
- package/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/gradle/wrapper/gradle-wrapper.properties +8 -0
- package/gradle.properties +24 -0
- package/gradlew +252 -0
- package/gradlew.bat +94 -0
- 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/README.md +120 -0
- package/ios-demo/Sources/MoMoUIKitsDemo/SampleDemos/BottomTabDemo.swift +3 -16
- package/package.json +1 -1
- package/scripts/sdui-visual/README.md +64 -0
- 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/settings.gradle.kts +64 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// File: compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiLog.kt
|
|
2
|
+
// Created At: 2026-10-27 19:00:00 +07:00
|
|
3
|
+
// Created By: AI
|
|
4
|
+
// AI Agent: Claude Code
|
|
5
|
+
// Model: claude-sonnet-5-5
|
|
6
|
+
|
|
7
|
+
package vn.momo.kits.sdui
|
|
8
|
+
|
|
9
|
+
import kotlin.time.Clock
|
|
10
|
+
import kotlin.time.TimeSource
|
|
11
|
+
|
|
12
|
+
// AI-GENERATED START: per-view error sink + clocks for the SDUI renderer
|
|
13
|
+
/**
|
|
14
|
+
* One view's error sink: warnings go to the device log file through the view's MaxApi (`logFile`), as `[SDUI] <label>: <message>`.
|
|
15
|
+
* Messages carry spec-level identifiers only (field names, action types, node types), never runtime values: the file stays on the device.
|
|
16
|
+
* Never throws; with no MaxApi bound a line is dropped silently. The same message is written once per instance
|
|
17
|
+
* (expressions are re-evaluated on every recomposition) and at most [MAX_LINES] distinct lines, so a bad spec cannot flood the file.
|
|
18
|
+
*/
|
|
19
|
+
internal class SduiLog(private val api: SduiMaxApi?, private val label: String = "") {
|
|
20
|
+
private val seen = HashSet<String>()
|
|
21
|
+
|
|
22
|
+
fun w(message: String) {
|
|
23
|
+
val a = api ?: return
|
|
24
|
+
runCatching {
|
|
25
|
+
if (seen.size >= MAX_LINES || !seen.add(message)) return
|
|
26
|
+
a.logFile("[SDUI] $label: $message")
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
companion object {
|
|
31
|
+
const val MAX_LINES = 50
|
|
32
|
+
|
|
33
|
+
/** No sink: every line is dropped (tests / helpers called without a view). */
|
|
34
|
+
val NONE = SduiLog(null)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
internal object SduiClock {
|
|
39
|
+
private val origin = TimeSource.Monotonic.markNow()
|
|
40
|
+
|
|
41
|
+
/** Monotonic milliseconds since process start (replaces SystemClock.elapsedRealtime()). */
|
|
42
|
+
fun nowMs(): Long = origin.elapsedNow().inWholeMilliseconds
|
|
43
|
+
|
|
44
|
+
/** Wall clock in epoch milliseconds (replaces System.currentTimeMillis()). */
|
|
45
|
+
fun epochMs(): Long = Clock.System.now().toEpochMilliseconds()
|
|
46
|
+
}
|
|
47
|
+
// AI-GENERATED END: per-view error sink + clocks for the SDUI renderer
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// File: compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiModel.kt
|
|
2
|
+
// Created At: 2026-10-27 17:00:00 +07:00
|
|
3
|
+
// Created By: AI
|
|
4
|
+
// AI Agent: Claude Code
|
|
5
|
+
// Model: claude-sonnet-5-5
|
|
6
|
+
|
|
7
|
+
package vn.momo.kits.sdui
|
|
8
|
+
|
|
9
|
+
// AI-GENERATED START: SDUI error model and constants
|
|
10
|
+
internal const val RENDER_VERSION = SduiView.RENDER_VERSION
|
|
11
|
+
/** Largest spec string SduiView accepts (UTF-8 bytes). */
|
|
12
|
+
internal const val MAX_PAYLOAD_BYTES = 256 * 1024
|
|
13
|
+
/** Deepest JSON nesting (`[` / `{`) SduiView accepts; checked before parsing so no recursive walk can overflow the stack. */
|
|
14
|
+
internal const val MAX_JSON_NESTING = 256
|
|
15
|
+
|
|
16
|
+
internal object ErrorCode {
|
|
17
|
+
/** spec `meta.minRenderVersion` is above this renderer's RENDER_VERSION (an older app met a newer spec) */
|
|
18
|
+
const val UNSUPPORTED_VERSION = "UNSUPPORTED_VERSION"
|
|
19
|
+
/** spec `meta.mode` this view does not draw (`"screen"`) */
|
|
20
|
+
const val UNSUPPORTED_MODE = "UNSUPPORTED_MODE"
|
|
21
|
+
const val PARSE = "PARSE"
|
|
22
|
+
const val PAYLOAD_TOO_LARGE = "PAYLOAD_TOO_LARGE"
|
|
23
|
+
const val SPEC_SHAPE = "SPEC_SHAPE"
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
internal data class SduiError(
|
|
27
|
+
val stage: String,
|
|
28
|
+
val code: String,
|
|
29
|
+
val retryable: Boolean,
|
|
30
|
+
val detail: String? = null,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
internal sealed interface SduiResult<out T> {
|
|
34
|
+
data class Ok<T>(val value: T) : SduiResult<T>
|
|
35
|
+
data class Err(val error: SduiError) : SduiResult<Nothing>
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
internal fun str(v: Any?, default: String): String = (v as? String)?.takeIf { it.isNotEmpty() } ?: default
|
|
39
|
+
// AI-GENERATED END: SDUI error model and constants
|
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
// File: compose/src/commonMain/kotlin/vn/momo/kits/sdui/SduiPropsRenderer.kt
|
|
2
|
+
// Created At: 2026-11-03 10:00:00 +07:00
|
|
3
|
+
// Created By: AI
|
|
4
|
+
// AI Agent: Claude Code
|
|
5
|
+
// Model: claude-sonnet-5-5
|
|
6
|
+
|
|
7
|
+
package vn.momo.kits.sdui
|
|
8
|
+
|
|
9
|
+
import androidx.compose.foundation.layout.Arrangement
|
|
10
|
+
import androidx.compose.foundation.layout.PaddingValues
|
|
11
|
+
import androidx.compose.ui.Alignment
|
|
12
|
+
import androidx.compose.ui.graphics.Color
|
|
13
|
+
import androidx.compose.ui.graphics.ColorFilter
|
|
14
|
+
import androidx.compose.ui.layout.ContentScale
|
|
15
|
+
import androidx.compose.ui.text.input.KeyboardType
|
|
16
|
+
import androidx.compose.ui.text.style.TextAlign
|
|
17
|
+
import androidx.compose.ui.text.style.TextDecoration
|
|
18
|
+
import androidx.compose.ui.text.style.TextOverflow
|
|
19
|
+
import androidx.compose.ui.unit.Dp
|
|
20
|
+
import androidx.compose.ui.unit.TextUnit
|
|
21
|
+
import androidx.compose.ui.unit.LayoutDirection
|
|
22
|
+
import androidx.compose.ui.unit.dp
|
|
23
|
+
import androidx.compose.ui.unit.sp
|
|
24
|
+
import vn.momo.kits.components.ButtonSize
|
|
25
|
+
import vn.momo.kits.components.ButtonType
|
|
26
|
+
import vn.momo.kits.components.Size
|
|
27
|
+
import vn.momo.kits.components.TitleSize
|
|
28
|
+
import vn.momo.kits.components.DotSize
|
|
29
|
+
import vn.momo.kits.components.IconAlign
|
|
30
|
+
import vn.momo.kits.components.ImageState
|
|
31
|
+
import vn.momo.kits.components.InputFontWeight
|
|
32
|
+
import vn.momo.kits.components.TabViewType
|
|
33
|
+
import vn.momo.kits.components.ChipSize
|
|
34
|
+
import vn.momo.kits.components.RibbonPosition
|
|
35
|
+
import vn.momo.kits.components.TagColor
|
|
36
|
+
import vn.momo.kits.components.TagSize
|
|
37
|
+
import vn.momo.kits.components.TabViewDirection
|
|
38
|
+
import vn.momo.kits.components.TitleType
|
|
39
|
+
|
|
40
|
+
// AI-GENERATED START: SDUI props that the kit exposes beyond the first mapping (spec prop name = kit parameter name)
|
|
41
|
+
// Pure value mappers: an absent / unknown value falls back to the kit default (or the SDUI default noted per function).
|
|
42
|
+
|
|
43
|
+
/** Enum constant -> lowercase snake_case spec value: `TopRight` -> "top_right", `LINE_THROUGH` -> "line_through". */
|
|
44
|
+
internal fun snake(v: Any?): String? = (v as? String)?.trim()?.lowercase()?.replace('-', '_')?.replace(' ', '_')?.takeIf { it.isNotEmpty() }
|
|
45
|
+
|
|
46
|
+
/** A String prop that may be absent: blank -> null (kit `String? = null`). */
|
|
47
|
+
internal fun optStr(v: Any?): String? = v?.let(::str)?.takeIf { it.isNotEmpty() }
|
|
48
|
+
|
|
49
|
+
/** Numeric props accept a number or a numeric string ("6"); anything else -> [default]. */
|
|
50
|
+
internal fun intOr(v: Any?, default: Int): Int = intOf(v) ?: default
|
|
51
|
+
internal fun floatOr(v: Any?, default: Float): Float = numOf(v)?.toFloat() ?: default
|
|
52
|
+
internal fun longOr(v: Any?, default: Long): Long = numOf(v)?.toLong() ?: default
|
|
53
|
+
|
|
54
|
+
// ---- Text -------------------------------------------------------------------------------------------------------------
|
|
55
|
+
|
|
56
|
+
/** clip | ellipsis | visible; absent / unknown = the kit default (Clip). */
|
|
57
|
+
/**
|
|
58
|
+
* Kit default is Clip, with one owner-approved exception: a Text that limits its lines (`numberOfLines`) and sets no
|
|
59
|
+
* `overflow` ends with "…", as every existing spec expects.
|
|
60
|
+
*/
|
|
61
|
+
internal fun textOverflowOf(v: Any?, linesLimited: Boolean = false): TextOverflow = when (snake(v)) {
|
|
62
|
+
"ellipsis" -> TextOverflow.Ellipsis
|
|
63
|
+
"visible" -> TextOverflow.Visible
|
|
64
|
+
"clip" -> TextOverflow.Clip
|
|
65
|
+
else -> if (linesLimited) TextOverflow.Ellipsis else TextOverflow.Clip
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** "underline", "line_through" / "line-through", or both ("underline line-through"); "none"/unknown -> null (kit default). */
|
|
69
|
+
internal fun textDecorationOf(v: Any?): TextDecoration? {
|
|
70
|
+
val s = (v as? String)?.lowercase() ?: return null
|
|
71
|
+
val under = s.contains("underline")
|
|
72
|
+
val line = s.contains("line-through") || s.contains("line_through") || s.contains("linethrough")
|
|
73
|
+
return when {
|
|
74
|
+
under && line -> TextDecoration.combine(listOf(TextDecoration.Underline, TextDecoration.LineThrough))
|
|
75
|
+
under -> TextDecoration.Underline
|
|
76
|
+
line -> TextDecoration.LineThrough
|
|
77
|
+
else -> null
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** `numberOfLines` <= 0 / absent / not numeric = no limit. */
|
|
82
|
+
internal fun maxLinesOf(v: Any?): Int = intOf(v)?.takeIf { it > 0 } ?: Int.MAX_VALUE
|
|
83
|
+
|
|
84
|
+
/** `minLines` clamped to 1..maxLines (the kit Text throws when minLines > maxLines). */
|
|
85
|
+
internal fun minLinesOf(v: Any?, maxLines: Int): Int = intOr(v, 1).coerceIn(1, maxLines)
|
|
86
|
+
|
|
87
|
+
internal fun letterSpacingOf(v: Any?): TextUnit = (v as? Number)?.toFloat()?.sp ?: TextUnit.Unspecified
|
|
88
|
+
|
|
89
|
+
// ---- Title ------------------------------------------------------------------------------------------------------------
|
|
90
|
+
|
|
91
|
+
internal fun iconAlignOf(v: Any?) = when (snake(v)) { "center" -> IconAlign.Center; "bottom" -> IconAlign.Bottom; else -> IconAlign.Top }
|
|
92
|
+
internal fun titleButtonSizeOf(v: Any?) = if (snake(v) == "large") ButtonSize.Large else ButtonSize.Small
|
|
93
|
+
|
|
94
|
+
internal fun titleSizeOf(v: Any?) = when (snake(v)) { "small" -> TitleSize.Small; "large" -> TitleSize.Large; else -> TitleSize.Medium }
|
|
95
|
+
|
|
96
|
+
// ---- Button -----------------------------------------------------------------------------------------------------------
|
|
97
|
+
|
|
98
|
+
/** The kit's default label for Badge / BadgeRibbon / Tag / Chip. */
|
|
99
|
+
internal const val KIT_LABEL = "Label"
|
|
100
|
+
|
|
101
|
+
/** Button prop -> kit args; absent = kit default (isFull = true, title "Button", type PRIMARY, size LARGE). */
|
|
102
|
+
internal data class ButtonArgs(
|
|
103
|
+
val type: ButtonType, val size: Size, val title: String, val iconLeft: String, val iconRight: String,
|
|
104
|
+
val loading: Boolean, val useTintColor: Boolean, val isFull: Boolean,
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
internal fun buttonArgsOf(p: Map<String, Any?>) = ButtonArgs(
|
|
108
|
+
type = when (snake(p["type"])) {
|
|
109
|
+
"outline" -> ButtonType.OUTLINE; "secondary" -> ButtonType.SECONDARY; "tonal" -> ButtonType.TONAL
|
|
110
|
+
"danger" -> ButtonType.DANGER; "text" -> ButtonType.TEXT; "disabled" -> ButtonType.DISABLED
|
|
111
|
+
else -> ButtonType.PRIMARY
|
|
112
|
+
},
|
|
113
|
+
size = when (snake(p["size"])) { "small" -> Size.SMALL; "medium" -> Size.MEDIUM; else -> Size.LARGE },
|
|
114
|
+
title = p["title"]?.let(::str) ?: "Button",
|
|
115
|
+
iconLeft = buttonIconOf(p["iconLeft"]),
|
|
116
|
+
iconRight = buttonIconOf(p["iconRight"]),
|
|
117
|
+
loading = p["loading"] == true,
|
|
118
|
+
useTintColor = boolOr(p["useTintColor"], true),
|
|
119
|
+
isFull = boolOr(p["full"], true),
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
// ---- Image ------------------------------------------------------------------------------------------------------------
|
|
123
|
+
|
|
124
|
+
/** top_start | top_center | top_end | center_start | center | center_end | bottom_start | bottom_center | bottom_end. */
|
|
125
|
+
internal fun alignmentOf(v: Any?, default: Alignment): Alignment = when (snake(v)) {
|
|
126
|
+
"top_start" -> Alignment.TopStart; "top_center" -> Alignment.TopCenter; "top_end" -> Alignment.TopEnd
|
|
127
|
+
"center_start" -> Alignment.CenterStart; "center" -> Alignment.Center; "center_end" -> Alignment.CenterEnd
|
|
128
|
+
"bottom_start" -> Alignment.BottomStart; "bottom_center" -> Alignment.BottomCenter; "bottom_end" -> Alignment.BottomEnd
|
|
129
|
+
else -> default
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** `colorFilter` is a colour: the image is tinted with it (SrcIn). */
|
|
133
|
+
internal fun colorFilterOf(c: Color?): ColorFilter? = c?.let { ColorFilter.tint(it) }
|
|
134
|
+
|
|
135
|
+
internal fun alphaOf(v: Any?): Float = ((v as? Number)?.toFloat() ?: 1f).coerceIn(0f, 1f)
|
|
136
|
+
|
|
137
|
+
/** What `onStateChanged` hands the action: "loading" | "success" | "error". */
|
|
138
|
+
internal fun imageStateName(s: ImageState): String = when (s) {
|
|
139
|
+
ImageState.Loading -> "loading"; ImageState.Success -> "success"; ImageState.Error -> "error"
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// ---- Section / Card ---------------------------------------------------------------------------------------------------
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* `contentPadding`: a number (all sides, dp) or {horizontal, vertical, top, bottom, start|left, end|right}. Absent / not a
|
|
146
|
+
* number or map -> null (kit default). Unlisted sides are 0; negative sides are clamped to 0 (PaddingValues throws on them).
|
|
147
|
+
*/
|
|
148
|
+
internal fun paddingValuesOf(v: Any?): PaddingValues? {
|
|
149
|
+
parseDp(v as? Number)?.let { return PaddingValues(it.coerceAtLeast(0.dp)) }
|
|
150
|
+
val m = v.asMap() ?: return null
|
|
151
|
+
fun d(vararg k: String): Dp? = k.firstNotNullOfOrNull { parseDp(m[it]) }?.coerceAtLeast(0.dp)
|
|
152
|
+
val h = d("horizontal"); val vt = d("vertical")
|
|
153
|
+
return PaddingValues(
|
|
154
|
+
start = d("start", "left") ?: h ?: 0.dp, top = d("top") ?: vt ?: 0.dp,
|
|
155
|
+
end = d("end", "right") ?: h ?: 0.dp, bottom = d("bottom") ?: vt ?: 0.dp,
|
|
156
|
+
)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// ---- Tab view ---------------------------------------------------------------------------------------------------------
|
|
160
|
+
|
|
161
|
+
internal fun tabViewTypeOf(v: Any?) = if (snake(v) == "card") TabViewType.CARD else TabViewType.DEFAULT
|
|
162
|
+
internal fun dotSizeOf(v: Any?) = if (snake(v) == "large") DotSize.Large else DotSize.Small
|
|
163
|
+
|
|
164
|
+
// ---- Pagination -------------------------------------------------------------------------------------------------------
|
|
165
|
+
|
|
166
|
+
internal enum class PaginationKind { DOT, WHITE_DOT, NUMBER, SCROLL }
|
|
167
|
+
|
|
168
|
+
internal fun paginationKindOf(v: Any?) = when (snake(v)) {
|
|
169
|
+
"white_dot" -> PaginationKind.WHITE_DOT; "number" -> PaginationKind.NUMBER; "scroll" -> PaginationKind.SCROLL
|
|
170
|
+
else -> PaginationKind.DOT
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// ---- ScrollView -------------------------------------------------------------------------------------------------------
|
|
174
|
+
|
|
175
|
+
internal fun horizontalArrangementOf(v: Any?): Arrangement.Horizontal = when (snake(v)) {
|
|
176
|
+
"end" -> Arrangement.End; "center" -> Arrangement.Center; "space_between" -> Arrangement.SpaceBetween
|
|
177
|
+
"space_around" -> Arrangement.SpaceAround; "space_evenly" -> Arrangement.SpaceEvenly
|
|
178
|
+
else -> Arrangement.Start
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
internal fun verticalArrangementOf(v: Any?): Arrangement.Vertical = when (snake(v)) {
|
|
182
|
+
"bottom" -> Arrangement.Bottom; "center" -> Arrangement.Center; "space_between" -> Arrangement.SpaceBetween
|
|
183
|
+
"space_around" -> Arrangement.SpaceAround; "space_evenly" -> Arrangement.SpaceEvenly
|
|
184
|
+
else -> Arrangement.Top
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// ---- Badge / BadgeRibbon / Tag / Chip ---------------------------------------------------------------------------------
|
|
188
|
+
|
|
189
|
+
internal data class BadgeArgs(val label: String, val backgroundColor: Color?)
|
|
190
|
+
internal fun badgeArgsOf(p: Map<String, Any?>) = BadgeArgs(p["label"]?.let(::str) ?: KIT_LABEL, parseColor(p["backgroundColor"]))
|
|
191
|
+
|
|
192
|
+
/** top_left | top_right | bottom_left | bottom_right; absent / unknown = TopRight (kit default). */
|
|
193
|
+
internal fun ribbonPositionOf(v: Any?) = when (snake(v)) {
|
|
194
|
+
"bottom_left" -> RibbonPosition.BottomLeft
|
|
195
|
+
"bottom_right" -> RibbonPosition.BottomRight
|
|
196
|
+
"top_left" -> RibbonPosition.TopLeft
|
|
197
|
+
else -> RibbonPosition.TopRight
|
|
198
|
+
}
|
|
199
|
+
internal data class RibbonArgs(val position: RibbonPosition, val label: String, val isRound: Boolean)
|
|
200
|
+
internal fun ribbonArgsOf(p: Map<String, Any?>) =
|
|
201
|
+
RibbonArgs(ribbonPositionOf(p["position"]), p["label"]?.let(::str) ?: KIT_LABEL, p["isRound"] == true)
|
|
202
|
+
|
|
203
|
+
internal data class TagArgs(val label: String, val icon: String?, val customColor: Color?, val color: TagColor, val size: TagSize)
|
|
204
|
+
internal fun tagArgsOf(p: Map<String, Any?>) = TagArgs(
|
|
205
|
+
label = p["label"]?.let(::str) ?: KIT_LABEL, icon = optStr(p["icon"]), customColor = parseColor(p["customColor"]),
|
|
206
|
+
color = tagColorOf(p["color"]), size = if (p["size"] == "medium") TagSize.Medium else TagSize.Large,
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
internal data class ChipArgs(
|
|
210
|
+
val label: String, val iconLeft: String?, val iconRight: String?, val iconLeftTint: Color?, val iconRightTint: Color?,
|
|
211
|
+
val backgroundColor: Color?, val selected: Boolean, val size: ChipSize, val accessibilityLabel: String?,
|
|
212
|
+
)
|
|
213
|
+
internal fun chipArgsOf(p: Map<String, Any?>) = ChipArgs(
|
|
214
|
+
label = p["label"]?.let(::str) ?: KIT_LABEL, iconLeft = optStr(p["iconLeft"]), iconRight = optStr(p["iconRight"]),
|
|
215
|
+
iconLeftTint = parseColor(p["iconLeftTint"]), iconRightTint = parseColor(p["iconRightTint"]),
|
|
216
|
+
backgroundColor = parseColor(p["backgroundColor"]), selected = p["selected"] == true,
|
|
217
|
+
size = if (p["size"] == "small") ChipSize.SMALL else ChipSize.LARGE, accessibilityLabel = optStr(p["accessibilityLabel"]),
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
// ---- Grid (Section / Card / Item) -------------------------------------------------------------------------------------
|
|
221
|
+
|
|
222
|
+
internal const val GRID_COLS = 12
|
|
223
|
+
internal fun gridGutter(card: Boolean): Dp = if (card) 8.dp else 12.dp
|
|
224
|
+
|
|
225
|
+
/** Item: widthSpan 1..12 (absent / non-numeric = full width), heightSpan >= 0 (0 = no fixed height). */
|
|
226
|
+
internal data class ItemArgs(val widthSpan: Int, val heightSpan: Int)
|
|
227
|
+
internal fun itemArgsOf(p: Map<String, Any?>) =
|
|
228
|
+
ItemArgs(intOr(p["widthSpan"], GRID_COLS).coerceIn(1, GRID_COLS), intOr(p["heightSpan"], 0).coerceAtLeast(0))
|
|
229
|
+
|
|
230
|
+
/** Section keeps only useMargin + backgroundImage; Card also useShadow / backgroundColor / contentPadding (default 12dp, never negative). */
|
|
231
|
+
internal data class GridArgs(
|
|
232
|
+
val useMargin: Boolean, val backgroundImage: String?, val useShadow: Boolean, val backgroundColor: Color?,
|
|
233
|
+
val contentPadding: PaddingValues,
|
|
234
|
+
)
|
|
235
|
+
internal fun gridArgsOf(p: Map<String, Any?>, card: Boolean) = GridArgs(
|
|
236
|
+
useMargin = card || p["useMargin"] != false,
|
|
237
|
+
backgroundImage = imageUrl(p["backgroundImage"]),
|
|
238
|
+
useShadow = card && p["useShadow"] == true,
|
|
239
|
+
backgroundColor = if (card) parseColor(p["backgroundColor"]) else null,
|
|
240
|
+
contentPadding = if (card) paddingValuesOf(p["contentPadding"]) ?: PaddingValues(12.dp) else PaddingValues(0.dp),
|
|
241
|
+
)
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* sizePerSpan: the width of one 12-column span. A Card's content sits inside its own contentPadding, so the
|
|
245
|
+
* actual horizontal padding ([cardHorizontalPadding]) is subtracted (not an assumed 12dp per side). Never negative.
|
|
246
|
+
*/
|
|
247
|
+
internal fun gridSizePerSpan(contentWidth: Dp, useMargin: Boolean, card: Boolean, cardHorizontalPadding: Dp): Dp {
|
|
248
|
+
val margin = if (useMargin) 12.dp else 0.dp
|
|
249
|
+
val inner = contentWidth - margin * 2 - (if (card) cardHorizontalPadding else 0.dp)
|
|
250
|
+
return ((inner - gridGutter(card) * (GRID_COLS - 1)) / GRID_COLS - (1f / GRID_COLS).dp).coerceAtLeast(0.dp)
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
internal fun PaddingValues.horizontal(): Dp =
|
|
254
|
+
calculateLeftPadding(LayoutDirection.Ltr) + calculateRightPadding(LayoutDirection.Ltr)
|
|
255
|
+
|
|
256
|
+
// ---- Carousel ---------------------------------------------------------------------------------------------------------
|
|
257
|
+
|
|
258
|
+
/** Autoplay period in ms: default 3000, never below 1000 (a tiny value would spin the pager). */
|
|
259
|
+
internal fun autoplayIntervalOf(v: Any?): Long = longOr(v, 3000L).coerceAtLeast(1000L)
|
|
260
|
+
|
|
261
|
+
// ---- InputSearch ------------------------------------------------------------------------------------------------------
|
|
262
|
+
|
|
263
|
+
/** Callbacks that mean "the user types in this field". */
|
|
264
|
+
internal val SEARCH_TYPING_CALLBACKS = listOf("onChangeText", "onFocus", "onBlur", "onPressButtonText", "onClearPress", "onRightIconPressed")
|
|
265
|
+
|
|
266
|
+
/** onPress (an action, or a prop-form action) is present; where typing callbacks also exist it fires on focus instead of an overlay. */
|
|
267
|
+
internal fun searchHasPress(node: Node) = actionsFor(node, "onPress").isNotEmpty()
|
|
268
|
+
internal fun searchHasTyping(node: Node) = SEARCH_TYPING_CALLBACKS.any { actionsFor(node, it).isNotEmpty() }
|
|
269
|
+
|
|
270
|
+
/** Tap overlay (swallows typing, fires onPress) only for a pure pressable search box: onPress and no typing callbacks. */
|
|
271
|
+
internal fun searchShowsOverlay(node: Node) = searchHasPress(node) && !searchHasTyping(node)
|
|
272
|
+
|
|
273
|
+
/** onPress AND typing callbacks: no overlay, onPress fires when the field gains focus. */
|
|
274
|
+
internal fun searchPressOnFocus(node: Node) = searchHasPress(node) && searchHasTyping(node)
|
|
275
|
+
|
|
276
|
+
// ---- Per-node argument plans (pure: the composables only read these and call the kit) ----------------------------------
|
|
277
|
+
|
|
278
|
+
/** Text: everything the kit Text is called with; [defaultColor] is the theme text colour, [screenWidth] the screen width in dp. */
|
|
279
|
+
internal data class TextArgs(
|
|
280
|
+
val text: String, val color: Color, val align: TextAlign, val typography: String?, val lineHeightSp: Float?,
|
|
281
|
+
val maxLines: Int, val overflow: TextOverflow, val decoration: TextDecoration?, val fontFamily: String?,
|
|
282
|
+
val minLines: Int, val letterSpacing: TextUnit, val softWrap: Boolean, val accessibilityId: String?,
|
|
283
|
+
)
|
|
284
|
+
internal fun textArgsOf(p: Map<String, Any?>, sty: Sty, defaultColor: Color, screenWidth: Float): TextArgs {
|
|
285
|
+
val text = ((p["children"] ?: p["text"])?.let(::str) ?: "").let {
|
|
286
|
+
if (sty.str("textTransform") == "uppercase") it.uppercase() else it
|
|
287
|
+
}
|
|
288
|
+
val align = when (sty.str("textAlign")) {
|
|
289
|
+
"center" -> TextAlign.Center
|
|
290
|
+
"right" -> TextAlign.End
|
|
291
|
+
else -> TextAlign.Start
|
|
292
|
+
}
|
|
293
|
+
val maxLines = maxLinesOf(p["numberOfLines"])
|
|
294
|
+
return TextArgs(
|
|
295
|
+
text = text,
|
|
296
|
+
color = parseColor(p["color"]) ?: defaultColor,
|
|
297
|
+
align = align,
|
|
298
|
+
typography = p["typography"] as? String,
|
|
299
|
+
// line height scaled by screenWidth/375 instead of the kit's unscaled one
|
|
300
|
+
lineHeightSp = specLineHeight(p["typography"] as? String, screenWidth),
|
|
301
|
+
maxLines = maxLines,
|
|
302
|
+
overflow = textOverflowOf(p["overflow"], linesLimited = maxLinesOf(p["numberOfLines"]) != Int.MAX_VALUE),
|
|
303
|
+
decoration = textDecorationOf(p["textDecoration"]),
|
|
304
|
+
fontFamily = optStr(p["fontFamily"]),
|
|
305
|
+
minLines = minLinesOf(p["minLines"], maxLines),
|
|
306
|
+
letterSpacing = letterSpacingOf(p["letterSpacing"]),
|
|
307
|
+
softWrap = boolOr(p["softWrap"], true),
|
|
308
|
+
accessibilityId = optStr(p["accessibilityId"]),
|
|
309
|
+
)
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
internal data class TitleArgs(
|
|
313
|
+
val title: String, val type: TitleType, val size: TitleSize, val icon: String?, val iconColor: Color?, val iconAlign: IconAlign,
|
|
314
|
+
val showRightAction: Boolean, val showTrailingAction: Boolean, val badgeLabel: String?, val buttonTitle: String?,
|
|
315
|
+
val buttonSize: ButtonSize, val textOnly: Boolean, val description: String?,
|
|
316
|
+
)
|
|
317
|
+
internal fun titleArgsOf(p: Map<String, Any?>) = TitleArgs(
|
|
318
|
+
title = p["title"]?.let(::str) ?: "",
|
|
319
|
+
type = if (p["type"] == "card") TitleType.Card else TitleType.Section,
|
|
320
|
+
size = titleSizeOf(p["size"]),
|
|
321
|
+
icon = optStr(p["icon"]),
|
|
322
|
+
iconColor = parseColor(p["iconColor"]),
|
|
323
|
+
iconAlign = iconAlignOf(p["iconAlign"]),
|
|
324
|
+
showRightAction = p["showRightAction"] == true,
|
|
325
|
+
showTrailingAction = p["showTrailingAction"] == true,
|
|
326
|
+
badgeLabel = optStr(p["badgeLabel"]),
|
|
327
|
+
buttonTitle = optStr(p["buttonTitle"]),
|
|
328
|
+
buttonSize = titleButtonSizeOf(p["buttonSize"]),
|
|
329
|
+
textOnly = p["textOnly"] == true,
|
|
330
|
+
description = optStr(p["description"]),
|
|
331
|
+
)
|
|
332
|
+
|
|
333
|
+
/** Image: a null result = no usable `source`, nothing is drawn. An absent `resizeMode` is Crop (same as an unknown one). */
|
|
334
|
+
internal data class ImageArgs(
|
|
335
|
+
val url: String, val alignment: Alignment, val contentScale: ContentScale, val colorFilter: ColorFilter?,
|
|
336
|
+
val alpha: Float, val loading: Boolean,
|
|
337
|
+
)
|
|
338
|
+
internal fun imageArgsOf(p: Map<String, Any?>): ImageArgs? {
|
|
339
|
+
val url = imageUrl(p["source"]) ?: return null
|
|
340
|
+
return ImageArgs(
|
|
341
|
+
url = url,
|
|
342
|
+
alignment = alignmentOf(p["alignment"], Alignment.TopStart),
|
|
343
|
+
contentScale = if (p["resizeMode"] == null) ContentScale.Crop else contentScale(p["resizeMode"]),
|
|
344
|
+
colorFilter = colorFilterOf(parseColor(p["colorFilter"])),
|
|
345
|
+
alpha = alphaOf(p["alpha"]),
|
|
346
|
+
loading = p["loading"] != false,
|
|
347
|
+
)
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
internal data class IconArgs(val source: String, val size: Dp, val color: Color)
|
|
351
|
+
internal fun iconArgsOf(p: Map<String, Any?>, defaultColor: Color) = IconArgs(
|
|
352
|
+
source = p["source"]?.let(::str) ?: "",
|
|
353
|
+
size = dpProp(p["size"], 24.dp),
|
|
354
|
+
color = parseColor(p["color"]) ?: defaultColor,
|
|
355
|
+
)
|
|
356
|
+
|
|
357
|
+
/** Pagination: [numberLength] is the NUMBER kind's length (default 2 when `dataLength` is absent, unlike the others' 3). */
|
|
358
|
+
internal data class PaginationArgs(val kind: PaginationKind, val active: Int, val length: Int, val numberLength: Int)
|
|
359
|
+
internal fun paginationArgsOf(p: Map<String, Any?>): PaginationArgs {
|
|
360
|
+
val active = intOr(p["activeIndex"], 0)
|
|
361
|
+
val length = intOr(p["dataLength"], 3).coerceAtMost(MAX_SPEC_COUNT)
|
|
362
|
+
return PaginationArgs(paginationKindOf(p["type"]), active, length, if (p["dataLength"] == null) 2 else length)
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
internal data class ScrollArgs(
|
|
366
|
+
val horizontal: Boolean, val enabled: Boolean, val reverse: Boolean,
|
|
367
|
+
val horizontalArrangement: Arrangement.Horizontal, val verticalArrangement: Arrangement.Vertical,
|
|
368
|
+
)
|
|
369
|
+
internal fun scrollArgsOf(p: Map<String, Any?>) = ScrollArgs(
|
|
370
|
+
horizontal = p["horizontal"] == true,
|
|
371
|
+
enabled = boolOr(p["enabled"], true),
|
|
372
|
+
reverse = p["reverseScrolling"] == true,
|
|
373
|
+
horizontalArrangement = horizontalArrangementOf(p["horizontalArrangement"]),
|
|
374
|
+
verticalArrangement = verticalArrangementOf(p["verticalArrangement"]),
|
|
375
|
+
)
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* InputSearch: [focusEvents] = the callbacks fired in order when the field gains focus (onPress joins them when the node has
|
|
379
|
+
* both onPress and typing callbacks); [overlay] = a tap overlay is drawn (pure pressable only).
|
|
380
|
+
*/
|
|
381
|
+
internal data class SearchArgs(
|
|
382
|
+
val buttonText: String, val showButtonText: Boolean, val placeholder: String, val disabled: Boolean, val icon: String,
|
|
383
|
+
val iconColor: Color, val loading: Boolean, val fontWeight: InputFontWeight, val keyboardType: KeyboardType,
|
|
384
|
+
val backgroundColor: Color, val leftPosition: Dp?, val focusEvents: List<String>, val overlay: Boolean,
|
|
385
|
+
)
|
|
386
|
+
internal fun searchArgsOf(node: Node, p: Map<String, Any?>): SearchArgs {
|
|
387
|
+
val placeholder = p["typingData"].asList()?.firstOrNull()?.let(::str) ?: p["placeholder"]?.let(::str) ?: ""
|
|
388
|
+
val pressOnFocus = searchPressOnFocus(node)
|
|
389
|
+
return SearchArgs(
|
|
390
|
+
buttonText = p["buttonText"]?.let(::str) ?: "",
|
|
391
|
+
showButtonText = p["showButtonText"] == true,
|
|
392
|
+
placeholder = placeholder,
|
|
393
|
+
disabled = p["disabled"] == true,
|
|
394
|
+
icon = p["icon"]?.let(::str) ?: "",
|
|
395
|
+
iconColor = parseColor(p["iconColor"]) ?: Color.Unspecified,
|
|
396
|
+
loading = p["loading"] == true,
|
|
397
|
+
fontWeight = inputFontWeightOf(p["fontWeight"], InputFontWeight.REGULAR),
|
|
398
|
+
keyboardType = keyboardTypeOf(p["keyboardType"]),
|
|
399
|
+
backgroundColor = parseColor(p["backgroundColor"]) ?: Color.Unspecified,
|
|
400
|
+
leftPosition = parseDp(p["leftPosition"])?.coerceAtLeast(0.dp),
|
|
401
|
+
focusEvents = if (pressOnFocus) listOf("onFocus", "onPress") else listOf("onFocus"),
|
|
402
|
+
overlay = searchShowsOverlay(node),
|
|
403
|
+
)
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/** One strip tab: [isUrl] = a CDN picture (drawn as a 24x24 untinted image), else [icon] is a glyph name. */
|
|
407
|
+
internal data class TabItemArgs(
|
|
408
|
+
val title: String, val icon: String, val isUrl: Boolean, val showDot: Boolean, val dotSize: DotSize,
|
|
409
|
+
val badge: String?, val accessibilityLabel: String?,
|
|
410
|
+
)
|
|
411
|
+
internal data class TabViewArgs(
|
|
412
|
+
val tabs: List<TabItemArgs>, val selected: Int, val type: TabViewType, val scrollable: Boolean, val fitContent: Boolean,
|
|
413
|
+
val selectedColor: Color?, val unselectedColor: Color?, val direction: TabViewDirection, val userScrollEnabled: Boolean,
|
|
414
|
+
)
|
|
415
|
+
/** null = no tabs (nothing is drawn). At most 12 tabs; `selectedIndex` is clamped into the tab range. */
|
|
416
|
+
internal fun tabViewArgsOf(p: Map<String, Any?>): TabViewArgs? {
|
|
417
|
+
val tabs = p["tabs"].asList().orEmpty().mapNotNull { it.asMap() }.take(12)
|
|
418
|
+
val selected = ((p["selectedIndex"] as? Number)?.toInt() ?: 0).coerceIn(0, (tabs.size - 1).coerceAtLeast(0))
|
|
419
|
+
if (tabs.isEmpty()) return null
|
|
420
|
+
val items = tabs.map { t ->
|
|
421
|
+
val icon = t["icon"]?.let(::str) ?: ""
|
|
422
|
+
TabItemArgs(
|
|
423
|
+
title = t["title"]?.let(::str) ?: "",
|
|
424
|
+
icon = icon,
|
|
425
|
+
isUrl = icon.startsWith("http"),
|
|
426
|
+
showDot = t["showDot"] == true,
|
|
427
|
+
dotSize = dotSizeOf(t["dotSize"]),
|
|
428
|
+
badge = optStr(t["badgeValue"]),
|
|
429
|
+
accessibilityLabel = optStr(t["accessibilityLabel"]),
|
|
430
|
+
)
|
|
431
|
+
}
|
|
432
|
+
return TabViewArgs(
|
|
433
|
+
tabs = items,
|
|
434
|
+
selected = selected,
|
|
435
|
+
type = tabViewTypeOf(p["type"]),
|
|
436
|
+
scrollable = p["scrollable"] == true,
|
|
437
|
+
fitContent = p["fitContent"] == true,
|
|
438
|
+
selectedColor = parseColor(p["selectedColor"]),
|
|
439
|
+
unselectedColor = parseColor(p["unselectedColor"]),
|
|
440
|
+
direction = if (p["direction"] == "column") TabViewDirection.COLUMN else TabViewDirection.ROW,
|
|
441
|
+
userScrollEnabled = boolOr(p["userScrollEnabled"], true),
|
|
442
|
+
)
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
internal data class CarouselArgs(
|
|
446
|
+
val target: Int, val loop: Boolean, val autoplay: Boolean, val autoplayInterval: Long, val scrollEnabled: Boolean,
|
|
447
|
+
val inactiveSlideOpacity: Float, val inactiveSlideScale: Float, val contentPadding: PaddingValues,
|
|
448
|
+
)
|
|
449
|
+
/** null = no slides (nothing is drawn). `index` is clamped into 0..slides-1. */
|
|
450
|
+
internal fun carouselArgsOf(p: Map<String, Any?>, itemCount: Int): CarouselArgs? {
|
|
451
|
+
if (itemCount == 0) return null
|
|
452
|
+
return CarouselArgs(
|
|
453
|
+
target = ((p["index"] as? Number)?.toInt() ?: 0).coerceIn(0, itemCount - 1),
|
|
454
|
+
loop = p["loop"] == true,
|
|
455
|
+
autoplay = p["autoplay"] == true,
|
|
456
|
+
autoplayInterval = autoplayIntervalOf(p["autoplayInterval"]),
|
|
457
|
+
scrollEnabled = p["scrollEnabled"] != false,
|
|
458
|
+
inactiveSlideOpacity = floatOr(p["inactiveSlideOpacity"], 1f),
|
|
459
|
+
inactiveSlideScale = floatOr(p["inactiveSlideScale"], 1f),
|
|
460
|
+
contentPadding = paddingValuesOf(p["contentPadding"]) ?: PaddingValues(0.dp),
|
|
461
|
+
)
|
|
462
|
+
}
|
|
463
|
+
// AI-GENERATED END: SDUI props that the kit exposes beyond the first mapping
|