react-native-live-widgets 1.2.0 → 1.2.1
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/CHANGELOG.md +7 -0
- package/README.md +40 -1
- package/android/src/main/java/com/reactnativeliveactivity/renderer/DynamicWidgetCanvasRenderer.kt +443 -46
- package/android/src/main/java/com/reactnativeliveactivity/storage/DynamicWidgetStateStore.kt +86 -28
- package/android/src/main/java/com/reactnativeliveactivity/widgets/DynamicHomeScreenWidgetProvider.kt +126 -56
- package/android/src/main/res/layout/rn_live_widget_hit_zone.xml +16 -0
- package/android/src/main/res/layout/rn_live_widget_host.xml +16 -87
- package/docs/GUIDE-EN.md +241 -0
- package/docs/GUIDE-VI.md +266 -0
- package/docs/index.html +1140 -259
- package/docs/llms-full.txt +26 -0
- package/docs/llms.txt +8 -0
- package/ios/Models/DynamicLayoutModels.swift +6 -1
- package/ios/Renderer/DynamicNodeView.swift +169 -14
- package/ios/Widgets/DynamicHomeScreenWidget.swift +5 -0
- package/lib/builder.d.ts.map +1 -1
- package/lib/builder.js +65 -11
- package/lib/builder.js.map +1 -1
- package/lib/dispatcher.js +16 -10
- package/lib/dispatcher.js.map +1 -1
- package/lib/hooks.js +36 -31
- package/lib/hooks.js.map +1 -1
- package/lib/index.d.ts +17 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +124 -50
- package/lib/index.js.map +1 -1
- package/lib/ir.d.ts +15 -0
- package/lib/ir.d.ts.map +1 -0
- package/lib/ir.js +379 -0
- package/lib/ir.js.map +1 -0
- package/lib/jsx.d.ts +9 -1
- package/lib/jsx.d.ts.map +1 -1
- package/lib/jsx.js +131 -84
- package/lib/jsx.js.map +1 -1
- package/lib/preview.d.ts +0 -23
- package/lib/preview.d.ts.map +1 -1
- package/lib/preview.js +373 -104
- package/lib/preview.js.map +1 -1
- package/lib/types.d.ts +204 -12
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +2 -1
- package/lib/types.js.map +1 -1
- package/package.json +2 -1
- package/src/builder.ts +57 -2
- package/src/index.ts +66 -1
- package/src/ir.ts +430 -0
- package/src/jsx.tsx +30 -0
- package/src/preview.tsx +356 -32
- package/src/react-native-env.d.ts +1 -0
- package/src/types.ts +253 -13
package/docs/llms-full.txt
CHANGED
|
@@ -130,3 +130,29 @@ export interface WidgetRemoteConfig {
|
|
|
130
130
|
iOS limits daily widget reloads (~40-70/day). Android Doze Mode batches periodic tasks. Use `Widget.setRemoteConfig` for general background polling, but use Server Push (APNs / FCM) for second-by-second updates.
|
|
131
131
|
3. **App Group Setup**:
|
|
132
132
|
The App Group string passed to `SharedStorage.setAppGroup('group.com.yourcompany.app')` must match the entitlement configured in Xcode and `app.json`.
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## 5. Architecture & Native Parity Engine (v1.2.1)
|
|
137
|
+
|
|
138
|
+
### 1. Three Core Architectural Pillars
|
|
139
|
+
- **Native Semantic Coverage**: Replaced unrealistic 100% semantics with guaranteed accessibility coverage for all critical interactive nodes and graphical fallbacks (`contentDescription` for TalkBack, accessibility traits for VoiceOver).
|
|
140
|
+
- **Native-first, Canvas-when-needed**: Native components handle interactions and chronometers directly (`android.widget.Chronometer`, `FrameLayout` hit zones); Canvas 2D is reserved for custom graphics, sparklines, and complex vector nodes.
|
|
141
|
+
- **Semantic Tree Independent from Renderer (UI IR)**: Abstract Intermediate Representation (AST) containing Visual Nodes, Semantic Nodes, and Two-Way Event Bindings (`Widget.inspectIR(layout)`, `Widget.compileIR(layout)`).
|
|
142
|
+
|
|
143
|
+
### 2. Android Exact Dynamic Hit Layer
|
|
144
|
+
- Replaced fixed grid layout with dynamic `FrameLayout` (`rn_hit_layer` + `rn_live_widget_hit_zone.xml`).
|
|
145
|
+
- Utilizes `computeCanvasMapping` to resolve `fitCenter` aspect ratio letterboxing, eliminating touch offsets and misclicks.
|
|
146
|
+
|
|
147
|
+
### 3. Native Live Countdown Chronometer
|
|
148
|
+
- Integrated native `android.widget.Chronometer` with `setChronometerCountDown(true)` and `baseMillis = SystemClock.elapsedRealtime() + remainingMillis`.
|
|
149
|
+
- Suppresses static text rendering during active countdowns to provide 1-second continuous tick updates without Canvas bitmap redrawing.
|
|
150
|
+
|
|
151
|
+
### 4. Dynamic Template Variable Interpolation
|
|
152
|
+
- Layout strings dynamically interpolate `{{id}}`, `{{title}}`, and counter values.
|
|
153
|
+
- `defaultChecked` persistence in `DynamicWidgetStateStore` enables toggling off pre-checked switches on the first tap.
|
|
154
|
+
|
|
155
|
+
### 5. Swift 6 Language Mode Compatibility (iOS Xcode)
|
|
156
|
+
- Encapsulated `Font` resolution in `renderText()` within self-invoking closures `{ ... }()`.
|
|
157
|
+
- Refactored `DynamicNodeAccessibilityModifier` procedural assignments into a dedicated `buildAccessibilityView(content:) -> AnyView` helper method.
|
|
158
|
+
- Added fallback `else { EmptyView() }` branches to `backgroundView` and `borderOverlay` in `ContainerStyleModifier`.
|
package/docs/llms.txt
CHANGED
|
@@ -72,6 +72,14 @@ const unsubscribe = Widget.onWidgetAction((actionId, payload) => {
|
|
|
72
72
|
});
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
+
### Architecture & Native Parity (v1.2.1 Updates)
|
|
76
|
+
- **Native Semantic Coverage & Accessibility**: Standard `BaseSemanticProps` (`accessible`, `accessibilityRole`, `accessibilityLabel`, `accessibilityHint`, `accessibilityValue`) with full VoiceOver and TalkBack support.
|
|
77
|
+
- **UI Intermediate Representation (IR)**: Inspect and compile layout trees with `Widget.inspectIR(layout)` and `Widget.compileIR(layout)`.
|
|
78
|
+
- **Android Exact Dynamic Hit Layer**: Dynamic `FrameLayout` overlay with `computeCanvasMapping` compensating for `fitCenter` aspect ratio letterboxing, eliminating misclicks and phantom taps.
|
|
79
|
+
- **Android Native Live Chronometer**: Realtime 1s countdowns driven by native `android.widget.Chronometer` without Canvas bitmap redraws.
|
|
80
|
+
- **Dynamic Template Variable Interpolation**: Resolves `{{id}}`, `{{title}}`, and counter values dynamically, with initial `defaultChecked` persistence in `DynamicWidgetStateStore`.
|
|
81
|
+
- **Swift 6 Compatibility**: Full compliance with Swift 6 language mode and `@ViewBuilder` closure encapsulation on iOS Xcode.
|
|
82
|
+
|
|
75
83
|
### Golden Rules for AI Agents
|
|
76
84
|
1. **Never write Swift or Kotlin files manually** when a declarative `UI.*` node exists.
|
|
77
85
|
2. **App Groups**: Both iOS app and Widget Extension MUST share the identical App Group name (e.g. `group.<bundle_id>`).
|
|
@@ -3,11 +3,13 @@ import Foundation
|
|
|
3
3
|
// MARK: - Declarative Layout Models (Shared between Live Activity & Home Screen Widgets)
|
|
4
4
|
|
|
5
5
|
public struct LayoutNodeDTO: Codable {
|
|
6
|
+
public let id: String?
|
|
6
7
|
public let type: String
|
|
7
8
|
public let props: [String: AnyCodable]?
|
|
8
9
|
public let children: [LayoutNodeDTO]?
|
|
9
10
|
|
|
10
|
-
public init(type: String, props: [String: AnyCodable]? = nil, children: [LayoutNodeDTO]? = nil) {
|
|
11
|
+
public init(id: String? = nil, type: String, props: [String: AnyCodable]? = nil, children: [LayoutNodeDTO]? = nil) {
|
|
12
|
+
self.id = id
|
|
11
13
|
self.type = type
|
|
12
14
|
self.props = props
|
|
13
15
|
self.children = children
|
|
@@ -83,6 +85,9 @@ public struct WidgetSinglePageDTO: Codable {
|
|
|
83
85
|
}
|
|
84
86
|
|
|
85
87
|
public struct WidgetMultiPagePayloadDTO: Codable {
|
|
88
|
+
public let root: LayoutNodeDTO?
|
|
89
|
+
public let version: String?
|
|
90
|
+
public let semanticSummary: String?
|
|
86
91
|
public let small: LayoutNodeDTO?
|
|
87
92
|
public let medium: LayoutNodeDTO?
|
|
88
93
|
public let large: LayoutNodeDTO?
|
|
@@ -19,6 +19,7 @@ public struct DynamicNodeView: View {
|
|
|
19
19
|
node.props?["privacySensitive"]?.boolValue == true,
|
|
20
20
|
isRedacted: node.props?["redacted"]?.boolValue == true
|
|
21
21
|
)
|
|
22
|
+
.modifier(DynamicNodeAccessibilityModifier(props: node.props))
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
@ViewBuilder
|
|
@@ -107,17 +108,49 @@ public struct DynamicNodeView: View {
|
|
|
107
108
|
let fontWeightStr = node.props?["fontWeight"]?.stringValue ?? "regular"
|
|
108
109
|
let numberOfLines = node.props?["numberOfLines"]?.doubleValue.map { Int($0) }
|
|
109
110
|
let numericAnimation = node.props?["numericAnimation"]?.boolValue ?? false
|
|
111
|
+
let fontDesignStr = node.props?["fontDesign"]?.stringValue ?? "default"
|
|
112
|
+
let design: Font.Design = fontDesignStr == "monospaced" ? .monospaced : (fontDesignStr == "rounded" ? .rounded : (fontDesignStr == "serif" ? .serif : .default))
|
|
113
|
+
|
|
114
|
+
let font: Font = {
|
|
115
|
+
if let typo = node.props?["typography"]?.stringValue {
|
|
116
|
+
switch typo {
|
|
117
|
+
case "largeTitle": return .system(.largeTitle, design: design)
|
|
118
|
+
case "title1", "title": return .system(.title, design: design)
|
|
119
|
+
case "title2": return .system(.title2, design: design)
|
|
120
|
+
case "title3": return .system(.title3, design: design)
|
|
121
|
+
case "headline": return .system(.headline, design: design)
|
|
122
|
+
case "subheadline": return .system(.subheadline, design: design)
|
|
123
|
+
case "body": return .system(.body, design: design)
|
|
124
|
+
case "callout": return .system(.callout, design: design)
|
|
125
|
+
case "footnote": return .system(.footnote, design: design)
|
|
126
|
+
case "caption1", "caption": return .system(.caption, design: design)
|
|
127
|
+
case "caption2": return .system(.caption2, design: design)
|
|
128
|
+
default: return .system(size: CGFloat(fontSize), weight: parseFontWeight(fontWeightStr), design: design)
|
|
129
|
+
}
|
|
130
|
+
} else {
|
|
131
|
+
return .system(size: CGFloat(fontSize), weight: parseFontWeight(fontWeightStr), design: design)
|
|
132
|
+
}
|
|
133
|
+
}()
|
|
110
134
|
|
|
111
135
|
let textNode = Text(text)
|
|
112
|
-
.font(
|
|
136
|
+
.font(font)
|
|
113
137
|
.foregroundColor(color)
|
|
114
138
|
.lineLimit(numberOfLines)
|
|
115
139
|
.minimumScaleFactor(0.85)
|
|
116
140
|
|
|
141
|
+
let shadowColor = Color.resolve(from: node.props?["shadowColor"], colorScheme: colorScheme)
|
|
142
|
+
let shadowRad = node.props?["shadowRadius"]?.doubleValue.map { CGFloat($0) } ?? (shadowColor != nil ? 2 : 0)
|
|
143
|
+
let shadowOffsetDict = node.props?["shadowOffset"]?.value as? [String: Any]
|
|
144
|
+
let shadowX = (shadowOffsetDict?["x"] as? Double).map { CGFloat($0) } ?? 0
|
|
145
|
+
let shadowY = (shadowOffsetDict?["y"] as? Double).map { CGFloat($0) } ?? 1
|
|
146
|
+
|
|
117
147
|
if #available(iOS 16.0, *), numericAnimation {
|
|
118
|
-
textNode
|
|
148
|
+
textNode
|
|
149
|
+
.contentTransition(.numericText())
|
|
150
|
+
.shadow(color: shadowColor ?? .clear, radius: shadowRad, x: shadowX, y: shadowY)
|
|
119
151
|
} else {
|
|
120
152
|
textNode
|
|
153
|
+
.shadow(color: shadowColor ?? .clear, radius: shadowRad, x: shadowX, y: shadowY)
|
|
121
154
|
}
|
|
122
155
|
}
|
|
123
156
|
|
|
@@ -878,7 +911,56 @@ public struct DynamicNodeView: View {
|
|
|
878
911
|
}
|
|
879
912
|
}
|
|
880
913
|
|
|
881
|
-
//
|
|
914
|
+
// ♿ Accessibility Semantics & Fallback Modifier (Phase 1)
|
|
915
|
+
struct DynamicNodeAccessibilityModifier: ViewModifier {
|
|
916
|
+
let props: [String: AnyCodable]?
|
|
917
|
+
|
|
918
|
+
func body(content: Content) -> some View {
|
|
919
|
+
buildAccessibilityView(content: content)
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
private func buildAccessibilityView(content: Content) -> AnyView {
|
|
923
|
+
let accessible = props?["accessible"]?.boolValue
|
|
924
|
+
let label = props?["accessibilityLabel"]?.stringValue
|
|
925
|
+
let hint = props?["accessibilityHint"]?.stringValue
|
|
926
|
+
let value = props?["accessibilityValue"]?.stringValue
|
|
927
|
+
let role = props?["accessibilityRole"]?.stringValue
|
|
928
|
+
|
|
929
|
+
if accessible == false {
|
|
930
|
+
return AnyView(content.accessibilityHidden(true))
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
if label == nil && hint == nil && value == nil && role == nil {
|
|
934
|
+
return AnyView(content)
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
var view = AnyView(content)
|
|
938
|
+
if let label = label {
|
|
939
|
+
view = AnyView(view.accessibilityLabel(Text(label)))
|
|
940
|
+
}
|
|
941
|
+
if let hint = hint {
|
|
942
|
+
view = AnyView(view.accessibilityHint(Text(hint)))
|
|
943
|
+
}
|
|
944
|
+
if let value = value {
|
|
945
|
+
view = AnyView(view.accessibilityValue(Text(value)))
|
|
946
|
+
}
|
|
947
|
+
if let role = role {
|
|
948
|
+
switch role {
|
|
949
|
+
case "header":
|
|
950
|
+
view = AnyView(view.accessibilityAddTraits(.isHeader))
|
|
951
|
+
case "button":
|
|
952
|
+
view = AnyView(view.accessibilityAddTraits(.isButton))
|
|
953
|
+
case "image":
|
|
954
|
+
view = AnyView(view.accessibilityAddTraits(.isImage))
|
|
955
|
+
default:
|
|
956
|
+
break
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
return view
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
// Container padding, background, gradient, border and shadow modifier
|
|
882
964
|
struct ContainerStyleModifier: ViewModifier {
|
|
883
965
|
@Environment(\.widgetFamily) var family
|
|
884
966
|
@Environment(\.colorScheme) var colorScheme
|
|
@@ -891,22 +973,95 @@ struct ContainerStyleModifier: ViewModifier {
|
|
|
891
973
|
return false
|
|
892
974
|
}
|
|
893
975
|
|
|
976
|
+
@ViewBuilder
|
|
977
|
+
private func backgroundView(cornerRadius: CGFloat) -> some View {
|
|
978
|
+
if isAccessory {
|
|
979
|
+
EmptyView()
|
|
980
|
+
} else if let gradDict = props?["gradient"]?.value as? [String: Any],
|
|
981
|
+
let colorList = gradDict["colors"] as? [Any] {
|
|
982
|
+
let colors: [Color] = colorList.compactMap {
|
|
983
|
+
if let s = $0 as? String { return Color(hex: s) }
|
|
984
|
+
if let d = $0 as? [String: Any] {
|
|
985
|
+
let key = (colorScheme == .dark) ? "dark" : "light"
|
|
986
|
+
let hex = (d[key] as? String) ?? (d["light"] as? String) ?? (d["dark"] as? String) ?? (d["tinted"] as? String)
|
|
987
|
+
return hex.flatMap { Color(hex: $0) }
|
|
988
|
+
}
|
|
989
|
+
return nil
|
|
990
|
+
}
|
|
991
|
+
if colors.count >= 2 {
|
|
992
|
+
let startX = (gradDict["startPoint"] as? [String: Any])?["x"] as? Double ?? 0.0
|
|
993
|
+
let startY = (gradDict["startPoint"] as? [String: Any])?["y"] as? Double ?? 0.0
|
|
994
|
+
let endX = (gradDict["endPoint"] as? [String: Any])?["x"] as? Double ?? 1.0
|
|
995
|
+
let endY = (gradDict["endPoint"] as? [String: Any])?["y"] as? Double ?? 1.0
|
|
996
|
+
RoundedRectangle(cornerRadius: cornerRadius)
|
|
997
|
+
.fill(LinearGradient(
|
|
998
|
+
colors: colors,
|
|
999
|
+
startPoint: UnitPoint(x: startX, y: startY),
|
|
1000
|
+
endPoint: UnitPoint(x: endX, y: endY)
|
|
1001
|
+
))
|
|
1002
|
+
} else if let firstColor = colors.first {
|
|
1003
|
+
RoundedRectangle(cornerRadius: cornerRadius).fill(firstColor)
|
|
1004
|
+
} else if let color = Color.resolve(from: props?["backgroundColor"], colorScheme: colorScheme) {
|
|
1005
|
+
RoundedRectangle(cornerRadius: cornerRadius).fill(color)
|
|
1006
|
+
} else {
|
|
1007
|
+
EmptyView()
|
|
1008
|
+
}
|
|
1009
|
+
} else if let color = Color.resolve(from: props?["backgroundColor"], colorScheme: colorScheme) {
|
|
1010
|
+
RoundedRectangle(cornerRadius: cornerRadius).fill(color)
|
|
1011
|
+
} else {
|
|
1012
|
+
EmptyView()
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
@ViewBuilder
|
|
1017
|
+
private func borderOverlay(cornerRadius: CGFloat) -> some View {
|
|
1018
|
+
let borderWidth = props?["borderWidth"]?.doubleValue.map { CGFloat($0) } ?? 0
|
|
1019
|
+
if borderWidth > 0, let borderColor = Color.resolve(from: props?["borderColor"], colorScheme: colorScheme) {
|
|
1020
|
+
let borderStyle = props?["borderStyle"]?.stringValue ?? "solid"
|
|
1021
|
+
let strokeStyle: StrokeStyle = {
|
|
1022
|
+
if borderStyle == "dashed" {
|
|
1023
|
+
return StrokeStyle(lineWidth: borderWidth, dash: [6, 4])
|
|
1024
|
+
} else if borderStyle == "dotted" {
|
|
1025
|
+
return StrokeStyle(lineWidth: borderWidth, dash: [2, 3])
|
|
1026
|
+
} else {
|
|
1027
|
+
return StrokeStyle(lineWidth: borderWidth)
|
|
1028
|
+
}
|
|
1029
|
+
}()
|
|
1030
|
+
RoundedRectangle(cornerRadius: cornerRadius)
|
|
1031
|
+
.strokeBorder(borderColor, style: strokeStyle)
|
|
1032
|
+
} else {
|
|
1033
|
+
EmptyView()
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
|
|
894
1037
|
func body(content: Content) -> some View {
|
|
895
1038
|
let rawPad = props?["padding"]?.doubleValue.map { CGFloat($0) } ?? 0
|
|
896
1039
|
let pad = isAccessory ? min(rawPad, 2) : rawPad
|
|
897
|
-
|
|
898
|
-
let bgColor = isAccessory ? nil : Color.resolve(from: props?["backgroundColor"], colorScheme: colorScheme)
|
|
899
|
-
let cornerRadius = props?["borderRadius"]?.doubleValue.map { CGFloat($0) } ?? 0
|
|
1040
|
+
let cornerRadius = props?["borderRadius"]?.doubleValue.map { CGFloat($0) } ?? (props?["cornerRadius"]?.doubleValue.map { CGFloat($0) } ?? 0)
|
|
900
1041
|
|
|
901
|
-
|
|
1042
|
+
let isRTL = (props?["isRTL"]?.boolValue == true) || (props?["direction"]?.stringValue == "rtl")
|
|
1043
|
+
let shadowColor = Color.resolve(from: props?["shadowColor"], colorScheme: colorScheme)
|
|
1044
|
+
let shadowRadius = props?["shadowRadius"]?.doubleValue.map { CGFloat($0) } ?? (shadowColor != nil ? 4 : 0)
|
|
1045
|
+
let shadowOpacity = props?["shadowOpacity"]?.doubleValue ?? 0.35
|
|
1046
|
+
let offsetDict = props?["shadowOffset"]?.value as? [String: Any]
|
|
1047
|
+
let shadowX = (offsetDict?["x"] as? Double).map { CGFloat($0) } ?? 0
|
|
1048
|
+
let shadowY = (offsetDict?["y"] as? Double).map { CGFloat($0) } ?? 2
|
|
1049
|
+
|
|
1050
|
+
let styledContent = content
|
|
902
1051
|
.padding(pad)
|
|
903
|
-
.background(
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
1052
|
+
.background(backgroundView(cornerRadius: cornerRadius))
|
|
1053
|
+
.overlay(borderOverlay(cornerRadius: cornerRadius))
|
|
1054
|
+
|
|
1055
|
+
let withShadow = Group {
|
|
1056
|
+
if let sColor = shadowColor, shadowRadius > 0 {
|
|
1057
|
+
styledContent.shadow(color: sColor.opacity(shadowOpacity), radius: shadowRadius, x: shadowX, y: shadowY)
|
|
1058
|
+
} else {
|
|
1059
|
+
styledContent
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
return withShadow
|
|
1064
|
+
.environment(\.layoutDirection, isRTL ? .rightToLeft : .leftToRight)
|
|
910
1065
|
}
|
|
911
1066
|
}
|
|
912
1067
|
|
|
@@ -241,6 +241,11 @@ public struct DynamicHomeScreenWidgetView: View {
|
|
|
241
241
|
return nil
|
|
242
242
|
}
|
|
243
243
|
|
|
244
|
+
// Hỗ trợ trực tiếp UI Intermediate Representation (IR v2.0)
|
|
245
|
+
if let root = payload.root {
|
|
246
|
+
return root
|
|
247
|
+
}
|
|
248
|
+
|
|
244
249
|
if let pages = payload.pages, !pages.isEmpty {
|
|
245
250
|
let state = DynamicWidgetStateStore.loadState()
|
|
246
251
|
let defaultOrder = payload.pageOrder ?? Array(pages.keys).sorted()
|
package/lib/builder.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,UAAU,EACV,SAAS,EACT,cAAc,EACd,UAAU,EACV,WAAW,EACX,aAAa,EACb,cAAc,EACd,SAAS,EACT,QAAQ,EACR,SAAS,EACT,UAAU,EACV,SAAS,EACT,UAAU,EACV,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,UAAU,EACV,SAAS,EACT,QAAQ,
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,UAAU,EACV,SAAS,EACT,cAAc,EACd,UAAU,EACV,WAAW,EACX,aAAa,EACb,cAAc,EACd,SAAS,EACT,QAAQ,EACR,SAAS,EACT,UAAU,EACV,SAAS,EACT,UAAU,EACV,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,UAAU,EACV,SAAS,EACT,QAAQ,EAER,SAAS,EACT,SAAS,EACT,UAAU,EACV,UAAU,EACV,UAAU,EACV,WAAW,EACZ,MAAM,SAAS,CAAC;AAKjB,wBAAgB,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,SAAS,CAiBvF;AAED,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAE9E,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI;KAC1B,CAAC,IAAI,MAAM,CAAC,GAAG,cAAc;CAC/B,CAAC;AAEF,eAAO,MAAM,UAAU;aACZ,CAAC,SAAS,WAAW,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,KAAG,CA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IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,OAAO,GAAG,UAAU,GAAG,SAAS,CAAC,KACpE,UAAU;+BAgBO,WAAW,GAAG,UAAU,GAAG,UAAU,EAAE,eAC5C,UAAU,EAAE,KACxB,UAAU;6BAUO,SAAS,GAAG,UAAU,GAAG,UAAU,EAAE,eAC1C,UAAU,EAAE,KACxB,QAAQ;wBASS,WAAW,CAAC,OAAO,CAAC,KAAG,WAAW;4BAMpC,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,YACjC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,KAC1C,SAAS;6BAiBO,MAAM,EAAE,GAAG,SAAS,CAAC,OAAO,CAAC,YACpC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,QAAQ,CAAC,KAC3C,SAAS;6BAiBM,MAAM,GAAG,UAAU,CAAC,OAAO,CAAC,YAClC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,KAC3C,UAAU;2BAkBI,MAAM,GAAG,SAAS,CAAC,OAAO,CAAC,YAChC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,KACzC,SAAS;kBAiBH,SAAS,eACH,UAAU,EAAE,KACxB,QAAQ;IAMX;;;;OAIG;4BAEc,MAAM,UACb,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,eACd,UAAU,EAAE,KACxB,UAAU;IASb;;;;OAIG;0BACmB,cAAc,KAAG,aAAa;CAYrD,CAAC"}
|
package/lib/builder.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.UI = exports.StyleSheet = void 0;
|
|
4
|
+
exports.flattenStyle = flattenStyle;
|
|
5
|
+
const dispatcher_1 = require("./dispatcher");
|
|
2
6
|
let autoActionCounter = 0;
|
|
3
|
-
|
|
7
|
+
function flattenStyle(...styles) {
|
|
4
8
|
let merged = undefined;
|
|
5
9
|
function walk(item) {
|
|
6
10
|
if (!item)
|
|
@@ -20,20 +24,70 @@ export function flattenStyle(...styles) {
|
|
|
20
24
|
}
|
|
21
25
|
return merged;
|
|
22
26
|
}
|
|
23
|
-
|
|
27
|
+
exports.StyleSheet = {
|
|
24
28
|
create: (styles) => styles,
|
|
25
29
|
flatten: flattenStyle,
|
|
26
30
|
};
|
|
27
31
|
function isLayoutNode(item) {
|
|
28
32
|
return item && typeof item === 'object' && typeof item.type === 'string';
|
|
29
33
|
}
|
|
34
|
+
const TYPOGRAPHY_DEFAULTS = {
|
|
35
|
+
largeTitle: { fontSize: 34, fontWeight: 'bold' },
|
|
36
|
+
title1: { fontSize: 28, fontWeight: 'bold' },
|
|
37
|
+
title2: { fontSize: 22, fontWeight: 'bold' },
|
|
38
|
+
title3: { fontSize: 20, fontWeight: 'semibold' },
|
|
39
|
+
headline: { fontSize: 17, fontWeight: 'semibold' },
|
|
40
|
+
body: { fontSize: 17, fontWeight: 'regular' },
|
|
41
|
+
callout: { fontSize: 16, fontWeight: 'regular' },
|
|
42
|
+
subheadline: { fontSize: 15, fontWeight: 'regular' },
|
|
43
|
+
footnote: { fontSize: 13, fontWeight: 'regular' },
|
|
44
|
+
caption1: { fontSize: 12, fontWeight: 'regular' },
|
|
45
|
+
caption2: { fontSize: 11, fontWeight: 'regular' },
|
|
46
|
+
};
|
|
30
47
|
function normalizeProps(props) {
|
|
31
48
|
if (!props)
|
|
32
49
|
return undefined;
|
|
33
50
|
const p = { ...props };
|
|
51
|
+
// Bo góc alias
|
|
34
52
|
if (p.cornerRadius !== undefined && p.borderRadius === undefined) {
|
|
35
53
|
p.borderRadius = p.cornerRadius;
|
|
36
54
|
}
|
|
55
|
+
// Spacing / Gap alias chuẩn React Native
|
|
56
|
+
if (p.gap !== undefined && p.spacing === undefined) {
|
|
57
|
+
p.spacing = p.gap;
|
|
58
|
+
}
|
|
59
|
+
// Graceful Fallback cho Gradient: nếu nền tảng/OS không hỗ trợ gradient, tự lấy màu đầu tiên làm backgroundColor
|
|
60
|
+
if (p.gradient && Array.isArray(p.gradient.colors) && p.gradient.colors.length > 0 && !p.backgroundColor) {
|
|
61
|
+
p.backgroundColor = p.gradient.colors[0];
|
|
62
|
+
}
|
|
63
|
+
// Typography scale chuẩn
|
|
64
|
+
if (p.typography && TYPOGRAPHY_DEFAULTS[p.typography]) {
|
|
65
|
+
const typo = TYPOGRAPHY_DEFAULTS[p.typography];
|
|
66
|
+
if (p.fontSize === undefined)
|
|
67
|
+
p.fontSize = typo.fontSize;
|
|
68
|
+
if (p.fontWeight === undefined)
|
|
69
|
+
p.fontWeight = typo.fontWeight;
|
|
70
|
+
}
|
|
71
|
+
// Trợ năng / Accessibility Semantics Fallback (Phase 1):
|
|
72
|
+
if (p.accessible === undefined) {
|
|
73
|
+
if (p.text !== undefined || p.title !== undefined || p.actionId !== undefined) {
|
|
74
|
+
p.accessible = true;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (p.accessibilityLabel === undefined) {
|
|
78
|
+
if (p.text !== undefined)
|
|
79
|
+
p.accessibilityLabel = String(p.text);
|
|
80
|
+
else if (p.title !== undefined)
|
|
81
|
+
p.accessibilityLabel = String(p.title);
|
|
82
|
+
}
|
|
83
|
+
if (p.accessibilityRole === undefined) {
|
|
84
|
+
if (p.title !== undefined || p.actionId !== undefined) {
|
|
85
|
+
p.accessibilityRole = 'button';
|
|
86
|
+
}
|
|
87
|
+
else if (p.typography && (p.typography.startsWith('title') || p.typography === 'largeTitle' || p.typography === 'headline')) {
|
|
88
|
+
p.accessibilityRole = 'header';
|
|
89
|
+
}
|
|
90
|
+
}
|
|
37
91
|
return p;
|
|
38
92
|
}
|
|
39
93
|
function parseContainerArgs(first, rest) {
|
|
@@ -55,8 +109,8 @@ function parseContainerArgs(first, rest) {
|
|
|
55
109
|
/**
|
|
56
110
|
* Các hàm helper tạo node cây giao diện trực quan cho TypeScript/JavaScript
|
|
57
111
|
*/
|
|
58
|
-
|
|
59
|
-
StyleSheet,
|
|
112
|
+
exports.UI = {
|
|
113
|
+
StyleSheet: exports.StyleSheet,
|
|
60
114
|
VStack: (propsOrChildren, ...children) => {
|
|
61
115
|
const { props, children: parsedChildren } = parseContainerArgs(propsOrChildren, children);
|
|
62
116
|
return {
|
|
@@ -77,10 +131,10 @@ export const UI = {
|
|
|
77
131
|
const merged = flattenStyle(...styles);
|
|
78
132
|
return {
|
|
79
133
|
type: 'Text',
|
|
80
|
-
props: {
|
|
134
|
+
props: normalizeProps({
|
|
81
135
|
text,
|
|
82
136
|
...(merged || {}),
|
|
83
|
-
},
|
|
137
|
+
}),
|
|
84
138
|
};
|
|
85
139
|
},
|
|
86
140
|
Timer: (targetTimestamp, options) => ({
|
|
@@ -137,10 +191,10 @@ export const UI = {
|
|
|
137
191
|
if (normalized.onPress && !normalized.actionId) {
|
|
138
192
|
autoActionCounter += 1;
|
|
139
193
|
normalized.actionId = `act_${Date.now()}_${autoActionCounter}`;
|
|
140
|
-
registerAction(normalized.actionId, normalized.onPress);
|
|
194
|
+
(0, dispatcher_1.registerAction)(normalized.actionId, normalized.onPress);
|
|
141
195
|
}
|
|
142
196
|
else if (normalized.onPress && normalized.actionId) {
|
|
143
|
-
registerAction(normalized.actionId, normalized.onPress);
|
|
197
|
+
(0, dispatcher_1.registerAction)(normalized.actionId, normalized.onPress);
|
|
144
198
|
}
|
|
145
199
|
return {
|
|
146
200
|
type: 'Button',
|
|
@@ -153,7 +207,7 @@ export const UI = {
|
|
|
153
207
|
autoActionCounter += 1;
|
|
154
208
|
finalActionId = `act_${Date.now()}_${autoActionCounter}`;
|
|
155
209
|
}
|
|
156
|
-
registerAction(finalActionId, options.onPress);
|
|
210
|
+
(0, dispatcher_1.registerAction)(finalActionId, options.onPress);
|
|
157
211
|
}
|
|
158
212
|
return {
|
|
159
213
|
type: 'Button',
|
|
@@ -171,7 +225,7 @@ export const UI = {
|
|
|
171
225
|
ActionButton: (title, onPress, options) => {
|
|
172
226
|
autoActionCounter += 1;
|
|
173
227
|
const actionId = `act_${Date.now()}_${autoActionCounter}`;
|
|
174
|
-
registerAction(actionId, onPress);
|
|
228
|
+
(0, dispatcher_1.registerAction)(actionId, onPress);
|
|
175
229
|
return {
|
|
176
230
|
type: 'Button',
|
|
177
231
|
props: {
|
package/lib/builder.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"builder.js","sourceRoot":"","sources":["../src/builder.ts"],"names":[],"mappings":";;;AAiCA,oCAiBC;AArBD,6CAA8C;AAE9C,IAAI,iBAAiB,GAAG,CAAC,CAAC;AAE1B,SAAgB,YAAY,CAAmB,GAAG,MAAsB;IACtE,IAAI,MAAM,GAAQ,SAAS,CAAC;IAE5B,SAAS,IAAI,CAAC,IAAS;QACrB,IAAI,CAAC,IAAI;YAAE,OAAO;QAClB,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACxB,KAAK,MAAM,GAAG,IAAI,IAAI;gBAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QACpC,CAAC;aAAM,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;YACpC,IAAI,CAAC,MAAM;gBAAE,MAAM,GAAG,EAAE,CAAC;YACzB,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAC9B,CAAC;IACH,CAAC;IAED,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE,CAAC;QACvB,IAAI,CAAC,CAAC,CAAC,CAAC;IACV,CAAC;IACD,OAAO,MAAuB,CAAC;AACjC,CAAC;AAQY,QAAA,UAAU,GAAG;IACxB,MAAM,EAAE,CAA8C,MAA4B,EAAK,EAAE,CAAC,MAAM;IAChG,OAAO,EAAE,YAAY;CACtB,CAAC;AAEF,SAAS,YAAY,CAAC,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ACD,OAAO;YACL,IAAI,EAAE,OAAO;YACb,KAAK,EAAE,cAAc,CAAC,aAAa,CAAE;SACtC,CAAC;IACJ,CAAC;IAED,IAAI,EAAE,CACJ,KAAgB,EAChB,GAAG,QAAsB,EACf,EAAE,CAAC,CAAC;QACd,IAAI,EAAE,MAAM;QACZ,KAAK;QACL,QAAQ;KACT,CAAC;IAEF;;;;OAIG;IACH,MAAM,EAAE,CACN,aAAqB,EACrB,KAA2B,EAC3B,GAAG,QAAsB,EACb,EAAE,CAAC,CAAC;QAChB,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE;YACL,GAAG,KAAK;YACR,aAAa;SACd;QACD,QAAQ,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;KACrD,CAAC;IAEF;;;;OAIG;IACH,SAAS,EAAE,CAAC,OAAwB,EAAiB,EAAE,CAAC,CAAC;QACvD,IAAI,EAAE,WAAW;QACjB,KAAK,EAAE;YACL,SAAS,EAAE,IAAI;YACf,QAAQ,EAAE,CAAC;YACX,SAAS,EAAE,SAAS;YACpB,MAAM,EAAE,EAAE;YACV,QAAQ,EAAE,CAAC;YACX,OAAO,EAAE,CAAC;YACV,GAAG,OAAO;SACX;KACF,CAAC;CACH,CAAC"}
|
package/lib/dispatcher.js
CHANGED
|
@@ -1,29 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.globalActionHandlers = exports.actionHandlers = void 0;
|
|
4
|
+
exports.registerAction = registerAction;
|
|
5
|
+
exports.registerActionHandler = registerActionHandler;
|
|
6
|
+
exports.unregisterAction = unregisterAction;
|
|
7
|
+
exports.actionHandlers = new Map();
|
|
8
|
+
exports.globalActionHandlers = new Set();
|
|
3
9
|
/**
|
|
4
10
|
* Đăng ký một hàm xử lý logic TypeScript khi người dùng bấm nút có `actionId` tương ứng ngoài Widget/Live Activity.
|
|
5
11
|
* Trả về hàm hủy đăng ký (unsubscribe).
|
|
6
12
|
*/
|
|
7
|
-
|
|
8
|
-
actionHandlers.set(actionId, handler);
|
|
13
|
+
function registerAction(actionId, handler) {
|
|
14
|
+
exports.actionHandlers.set(actionId, handler);
|
|
9
15
|
return () => {
|
|
10
|
-
actionHandlers.delete(actionId);
|
|
16
|
+
exports.actionHandlers.delete(actionId);
|
|
11
17
|
};
|
|
12
18
|
}
|
|
13
19
|
/**
|
|
14
20
|
* Đăng ký hàm lắng nghe toàn bộ các sự kiện bấm nút từ Widget hoặc Live Activity.
|
|
15
21
|
* Trả về hàm hủy đăng ký (unsubscribe).
|
|
16
22
|
*/
|
|
17
|
-
|
|
18
|
-
globalActionHandlers.add(handler);
|
|
23
|
+
function registerActionHandler(handler) {
|
|
24
|
+
exports.globalActionHandlers.add(handler);
|
|
19
25
|
return () => {
|
|
20
|
-
globalActionHandlers.delete(handler);
|
|
26
|
+
exports.globalActionHandlers.delete(handler);
|
|
21
27
|
};
|
|
22
28
|
}
|
|
23
29
|
/**
|
|
24
30
|
* Hủy đăng ký action handler.
|
|
25
31
|
*/
|
|
26
|
-
|
|
27
|
-
actionHandlers.delete(actionId);
|
|
32
|
+
function unregisterAction(actionId) {
|
|
33
|
+
exports.actionHandlers.delete(actionId);
|
|
28
34
|
}
|
|
29
35
|
//# sourceMappingURL=dispatcher.js.map
|
package/lib/dispatcher.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dispatcher.js","sourceRoot":"","sources":["../src/dispatcher.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"dispatcher.js","sourceRoot":"","sources":["../src/dispatcher.ts"],"names":[],"mappings":";;;AAkBA,wCAKC;AAMD,sDAKC;AAKD,4CAEC;AA9BY,QAAA,cAAc,GAAG,IAAI,GAAG,EAAyB,CAAC;AAClD,QAAA,oBAAoB,GAAG,IAAI,GAAG,EAAuB,CAAC;AAEnE;;;GAGG;AACH,SAAgB,cAAc,CAAC,QAAgB,EAAE,OAAsB;IACrE,sBAAc,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACtC,OAAO,GAAG,EAAE;QACV,sBAAc,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAClC,CAAC,CAAC;AACJ,CAAC;AAED;;;GAGG;AACH,SAAgB,qBAAqB,CAAC,OAA4B;IAChE,4BAAoB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IAClC,OAAO,GAAG,EAAE;QACV,4BAAoB,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,gBAAgB,CAAC,QAAgB;IAC/C,sBAAc,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAClC,CAAC"}
|