@iternio/react-native-auto-play 0.6.0 → 0.6.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.
Files changed (82) hide show
  1. package/README.md +56 -7
  2. package/android/src/main/java/com/margelo/nitro/swe/iternio/reactnativeautoplay/template/Parser.kt +49 -14
  3. package/jest.js +2 -0
  4. package/lib/index.web.d.ts +73 -0
  5. package/lib/index.web.js +72 -1
  6. package/lib/types/Image.d.ts +6 -1
  7. package/lib/utils/NitroColor.d.ts +1 -0
  8. package/lib/utils/NitroColor.js +8 -0
  9. package/lib/utils/NitroImage.js +1 -1
  10. package/lib/utils/NitroManeuver.js +1 -3
  11. package/lib-cjs/AutoPlayHeadlessJsTask.js +16 -0
  12. package/lib-cjs/Constants.js +9 -0
  13. package/lib-cjs/components/MapTemplateContext.js +10 -0
  14. package/lib-cjs/components/SafeAreaInsetsContext.js +21 -0
  15. package/lib-cjs/components/SafeAreaView.js +22 -0
  16. package/lib-cjs/components/WindowInformationWrapper.js +20 -0
  17. package/lib-cjs/hooks/useAndroidAutoTelemetry.js +115 -0
  18. package/lib-cjs/hooks/useFocusedEffect.js +35 -0
  19. package/lib-cjs/hooks/useMapTemplate.js +13 -0
  20. package/lib-cjs/hooks/useSafeAreaInsets.js +9 -0
  21. package/lib-cjs/hooks/useVoiceInput.js +42 -0
  22. package/lib-cjs/hybrid/HybridAndroidAutoTelemetry.js +4 -0
  23. package/lib-cjs/hybrid/HybridAndroidWindowInformation.js +4 -0
  24. package/lib-cjs/hybrid/HybridAutoPlay.js +5 -0
  25. package/lib-cjs/hybrid/HybridVoice.js +61 -0
  26. package/lib-cjs/index.js +76 -0
  27. package/lib-cjs/index.web.js +98 -0
  28. package/lib-cjs/scenes/AutoPlayCluster.js +140 -0
  29. package/lib-cjs/scenes/CarPlayDashboardScene.js +100 -0
  30. package/lib-cjs/specs/AndroidAutoTelemetry.nitro.js +2 -0
  31. package/lib-cjs/specs/AndroidAutomotive.nitro.js +16 -0
  32. package/lib-cjs/specs/AndroidWindowInformation.nitro.js +2 -0
  33. package/lib-cjs/specs/AutoPlay.nitro.js +2 -0
  34. package/lib-cjs/specs/CarPlayDashboard.nitro.js +2 -0
  35. package/lib-cjs/specs/Cluster.nitro.js +2 -0
  36. package/lib-cjs/specs/GridTemplate.nitro.js +2 -0
  37. package/lib-cjs/specs/InformationTemplate.nitro.js +2 -0
  38. package/lib-cjs/specs/ListTemplate.nitro.js +2 -0
  39. package/lib-cjs/specs/MapTemplate.nitro.js +2 -0
  40. package/lib-cjs/specs/MessageTemplate.nitro.js +2 -0
  41. package/lib-cjs/specs/SearchTemplate.nitro.js +2 -0
  42. package/lib-cjs/specs/SignInTemplate.nitro.js +2 -0
  43. package/lib-cjs/specs/Voice.nitro.js +2 -0
  44. package/lib-cjs/templates/GridTemplate.js +41 -0
  45. package/lib-cjs/templates/InformationTemplate.js +49 -0
  46. package/lib-cjs/templates/ListTemplate.js +33 -0
  47. package/lib-cjs/templates/MapTemplate.js +168 -0
  48. package/lib-cjs/templates/MessageTemplate.js +50 -0
  49. package/lib-cjs/templates/SearchTemplate.js +32 -0
  50. package/lib-cjs/templates/SignInTemplate.js +55 -0
  51. package/lib-cjs/templates/Template.js +40 -0
  52. package/lib-cjs/types/Button.js +12 -0
  53. package/lib-cjs/types/Event.js +2 -0
  54. package/lib-cjs/types/Image.js +2 -0
  55. package/lib-cjs/types/Maneuver.js +77 -0
  56. package/lib-cjs/types/RootComponent.js +2 -0
  57. package/lib-cjs/types/SignInMethod.js +22 -0
  58. package/lib-cjs/types/Telemetry.js +24 -0
  59. package/lib-cjs/types/Text.js +8 -0
  60. package/lib-cjs/types/Trip.js +2 -0
  61. package/lib-cjs/types/Voice.js +2 -0
  62. package/lib-cjs/utils/ErrorUtil.js +34 -0
  63. package/lib-cjs/utils/NitroAction.js +129 -0
  64. package/lib-cjs/utils/NitroAlert.js +19 -0
  65. package/lib-cjs/utils/NitroAttributedString.js +14 -0
  66. package/lib-cjs/utils/NitroColor.js +32 -0
  67. package/lib-cjs/utils/NitroGrid.js +12 -0
  68. package/lib-cjs/utils/NitroImage.js +97 -0
  69. package/lib-cjs/utils/NitroManeuver.js +79 -0
  70. package/lib-cjs/utils/NitroMapButton.js +33 -0
  71. package/lib-cjs/utils/NitroOptionsPanel.js +66 -0
  72. package/lib-cjs/utils/NitroSection.js +112 -0
  73. package/nitrogen/generated/android/c++/JNitroColor.hpp +8 -4
  74. package/nitrogen/generated/android/kotlin/com/margelo/nitro/swe/iternio/reactnativeautoplay/NitroColor.kt +9 -4
  75. package/nitrogen/generated/ios/swift/NitroColor.swift +20 -2
  76. package/nitrogen/generated/shared/c++/NitroColor.hpp +7 -3
  77. package/package.json +7 -3
  78. package/src/index.web.ts +166 -0
  79. package/src/types/Image.ts +6 -1
  80. package/src/utils/NitroColor.ts +10 -1
  81. package/src/utils/NitroImage.ts +1 -5
  82. package/src/utils/NitroManeuver.ts +1 -4
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Flag = void 0;
4
+ /**
5
+ * @namespace Android
6
+ */
7
+ var Flag;
8
+ (function (Flag) {
9
+ Flag[Flag["Primary"] = 1] = "Primary";
10
+ Flag[Flag["Persistent"] = 2] = "Persistent";
11
+ Flag[Flag["Default"] = 4] = "Default";
12
+ })(Flag || (exports.Flag = Flag = {}));
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ManeuverState = exports.KeepType = exports.ForkType = exports.OnRampType = exports.OffRampType = exports.TurnType = exports.TrafficSide = exports.ManeuverType = void 0;
4
+ var ManeuverType;
5
+ (function (ManeuverType) {
6
+ ManeuverType[ManeuverType["Depart"] = 0] = "Depart";
7
+ ManeuverType[ManeuverType["Arrive"] = 10] = "Arrive";
8
+ ManeuverType[ManeuverType["ArriveLeft"] = 11] = "ArriveLeft";
9
+ ManeuverType[ManeuverType["ArriveRight"] = 12] = "ArriveRight";
10
+ ManeuverType[ManeuverType["Straight"] = 20] = "Straight";
11
+ ManeuverType[ManeuverType["Turn"] = 30] = "Turn";
12
+ ManeuverType[ManeuverType["Roundabout"] = 40] = "Roundabout";
13
+ ManeuverType[ManeuverType["OffRamp"] = 50] = "OffRamp";
14
+ ManeuverType[ManeuverType["OnRamp"] = 60] = "OnRamp";
15
+ ManeuverType[ManeuverType["Fork"] = 70] = "Fork";
16
+ ManeuverType[ManeuverType["EnterFerry"] = 80] = "EnterFerry";
17
+ ManeuverType[ManeuverType["Keep"] = 90] = "Keep";
18
+ })(ManeuverType || (exports.ManeuverType = ManeuverType = {}));
19
+ var TrafficSide;
20
+ (function (TrafficSide) {
21
+ TrafficSide[TrafficSide["Right"] = 0] = "Right";
22
+ TrafficSide[TrafficSide["Left"] = 1] = "Left";
23
+ })(TrafficSide || (exports.TrafficSide = TrafficSide = {}));
24
+ var TurnType;
25
+ (function (TurnType) {
26
+ TurnType[TurnType["NoTurn"] = 0] = "NoTurn";
27
+ TurnType[TurnType["SlightLeft"] = 1] = "SlightLeft";
28
+ TurnType[TurnType["SlightRight"] = 2] = "SlightRight";
29
+ TurnType[TurnType["NormalLeft"] = 3] = "NormalLeft";
30
+ TurnType[TurnType["NormalRight"] = 4] = "NormalRight";
31
+ TurnType[TurnType["SharpLeft"] = 5] = "SharpLeft";
32
+ TurnType[TurnType["SharpRight"] = 6] = "SharpRight";
33
+ TurnType[TurnType["UTurnLeft"] = 7] = "UTurnLeft";
34
+ TurnType[TurnType["UTurnRight"] = 8] = "UTurnRight";
35
+ })(TurnType || (exports.TurnType = TurnType = {}));
36
+ var OffRampType;
37
+ (function (OffRampType) {
38
+ OffRampType[OffRampType["SlightLeft"] = 0] = "SlightLeft";
39
+ OffRampType[OffRampType["SlightRight"] = 1] = "SlightRight";
40
+ OffRampType[OffRampType["NormalLeft"] = 2] = "NormalLeft";
41
+ OffRampType[OffRampType["NormalRight"] = 3] = "NormalRight";
42
+ })(OffRampType || (exports.OffRampType = OffRampType = {}));
43
+ var OnRampType;
44
+ (function (OnRampType) {
45
+ OnRampType[OnRampType["SlightLeft"] = 0] = "SlightLeft";
46
+ OnRampType[OnRampType["SlightRight"] = 1] = "SlightRight";
47
+ OnRampType[OnRampType["NormalLeft"] = 2] = "NormalLeft";
48
+ OnRampType[OnRampType["NormalRight"] = 3] = "NormalRight";
49
+ OnRampType[OnRampType["SharpLeft"] = 4] = "SharpLeft";
50
+ OnRampType[OnRampType["SharpRight"] = 5] = "SharpRight";
51
+ OnRampType[OnRampType["UTurnLeft"] = 6] = "UTurnLeft";
52
+ OnRampType[OnRampType["UTurnRight"] = 7] = "UTurnRight";
53
+ })(OnRampType || (exports.OnRampType = OnRampType = {}));
54
+ var ForkType;
55
+ (function (ForkType) {
56
+ ForkType[ForkType["Left"] = 0] = "Left";
57
+ ForkType[ForkType["Right"] = 1] = "Right";
58
+ })(ForkType || (exports.ForkType = ForkType = {}));
59
+ var KeepType;
60
+ (function (KeepType) {
61
+ KeepType[KeepType["Left"] = 0] = "Left";
62
+ KeepType[KeepType["Right"] = 1] = "Right";
63
+ KeepType[KeepType["FollowRoad"] = 2] = "FollowRoad";
64
+ })(KeepType || (exports.KeepType = KeepType = {}));
65
+ /**
66
+ * Describes the progress within a maneuver.
67
+ * Transition through: Continue → Initial → Prepare → Execute → Continue
68
+ * @namespace iOS sets CPManeuverState on the CPNavigationSession
69
+ * @namespace Android no-op, Android Auto does not have an equivalent API
70
+ */
71
+ var ManeuverState;
72
+ (function (ManeuverState) {
73
+ ManeuverState[ManeuverState["Continue"] = 0] = "Continue";
74
+ ManeuverState[ManeuverState["Initial"] = 1] = "Initial";
75
+ ManeuverState[ManeuverState["Prepare"] = 2] = "Prepare";
76
+ ManeuverState[ManeuverState["Execute"] = 3] = "Execute";
77
+ })(ManeuverState || (exports.ManeuverState = ManeuverState = {}));
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TextInputType = exports.KeyboardType = exports.SignInMethods = void 0;
4
+ var SignInMethods;
5
+ (function (SignInMethods) {
6
+ SignInMethods[SignInMethods["QR"] = 0] = "QR";
7
+ SignInMethods[SignInMethods["GOOGLE"] = 1] = "GOOGLE";
8
+ SignInMethods[SignInMethods["PIN"] = 2] = "PIN";
9
+ SignInMethods[SignInMethods["INPUT"] = 3] = "INPUT";
10
+ })(SignInMethods || (exports.SignInMethods = SignInMethods = {}));
11
+ var KeyboardType;
12
+ (function (KeyboardType) {
13
+ KeyboardType[KeyboardType["DEFAULT"] = 0] = "DEFAULT";
14
+ KeyboardType[KeyboardType["EMAIL"] = 1] = "EMAIL";
15
+ KeyboardType[KeyboardType["PHONE"] = 2] = "PHONE";
16
+ KeyboardType[KeyboardType["NUMBER"] = 3] = "NUMBER";
17
+ })(KeyboardType || (exports.KeyboardType = KeyboardType = {}));
18
+ var TextInputType;
19
+ (function (TextInputType) {
20
+ TextInputType[TextInputType["PASSWORD"] = 0] = "PASSWORD";
21
+ TextInputType[TextInputType["DEFAULT"] = 1] = "DEFAULT";
22
+ })(TextInputType || (exports.TextInputType = TextInputType = {}));
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VehicleGear = exports.AndroidAutomotiveTelemetryPermissions = exports.AndroidAutoTelemetryPermissions = void 0;
4
+ var AndroidAutoTelemetryPermissions;
5
+ (function (AndroidAutoTelemetryPermissions) {
6
+ AndroidAutoTelemetryPermissions["Speed"] = "com.google.android.gms.permission.CAR_SPEED";
7
+ AndroidAutoTelemetryPermissions["Energy"] = "com.google.android.gms.permission.CAR_FUEL";
8
+ AndroidAutoTelemetryPermissions["Odometer"] = "com.google.android.gms.permission.CAR_MILEAGE";
9
+ })(AndroidAutoTelemetryPermissions || (exports.AndroidAutoTelemetryPermissions = AndroidAutoTelemetryPermissions = {}));
10
+ var AndroidAutomotiveTelemetryPermissions;
11
+ (function (AndroidAutomotiveTelemetryPermissions) {
12
+ AndroidAutomotiveTelemetryPermissions["Info"] = "android.car.permission.CAR_INFO";
13
+ AndroidAutomotiveTelemetryPermissions["Speed"] = "android.car.permission.CAR_SPEED";
14
+ AndroidAutomotiveTelemetryPermissions["Energy"] = "android.car.permission.CAR_ENERGY";
15
+ AndroidAutomotiveTelemetryPermissions["ExteriorEnvironment"] = "android.car.permission.CAR_EXTERIOR_ENVIRONMENT";
16
+ AndroidAutomotiveTelemetryPermissions["EnergyPorts"] = "android.car.permission.CAR_ENERGY_PORTS";
17
+ })(AndroidAutomotiveTelemetryPermissions || (exports.AndroidAutomotiveTelemetryPermissions = AndroidAutomotiveTelemetryPermissions = {}));
18
+ var VehicleGear;
19
+ (function (VehicleGear) {
20
+ VehicleGear[VehicleGear["Neutral"] = 1] = "Neutral";
21
+ VehicleGear[VehicleGear["Reverse"] = 2] = "Reverse";
22
+ VehicleGear[VehicleGear["Park"] = 4] = "Park";
23
+ VehicleGear[VehicleGear["Drive"] = 8] = "Drive";
24
+ })(VehicleGear || (exports.VehicleGear = VehicleGear = {}));
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TextPlaceholders = void 0;
4
+ var TextPlaceholders;
5
+ (function (TextPlaceholders) {
6
+ TextPlaceholders["Distance"] = "{distance}";
7
+ TextPlaceholders["Duration"] = "{duration}";
8
+ })(TextPlaceholders || (exports.TextPlaceholders = TextPlaceholders = {}));
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ErrorUtil = void 0;
4
+ const isError = (error) => {
5
+ if (error == null) {
6
+ return false;
7
+ }
8
+ if (typeof error !== 'object') {
9
+ return false;
10
+ }
11
+ if (!('message' in error && 'name' in error)) {
12
+ return false;
13
+ }
14
+ if (error.name !== 'Error') {
15
+ return false;
16
+ }
17
+ if (typeof error.message !== 'string') {
18
+ return false;
19
+ }
20
+ return true;
21
+ };
22
+ const isTemplateNotFoundError = (error) => {
23
+ if (isError(error)) {
24
+ return error.message.startsWith('templateNotFound');
25
+ }
26
+ return false;
27
+ };
28
+ const isVoiceInputCanceledError = (error) => {
29
+ if (isError(error)) {
30
+ return error.message.startsWith('voiceInputCancelled');
31
+ }
32
+ return false;
33
+ };
34
+ exports.ErrorUtil = { isTemplateNotFoundError, isVoiceInputCanceledError };
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NitroActionUtil = void 0;
4
+ const react_native_1 = require("react-native");
5
+ const NitroImage_1 = require("./NitroImage");
6
+ const getImage = (action) => {
7
+ if (action.type === 'text') {
8
+ return undefined;
9
+ }
10
+ if (action.image.type === 'glyph' && action.image.fontScale == null) {
11
+ action.image.fontScale = react_native_1.Platform.OS === 'android' ? 1.0 : 0.8;
12
+ }
13
+ return NitroImage_1.NitroImageUtil.convert(action.image);
14
+ };
15
+ const getTitle = (action) => {
16
+ if (action.type === 'image') {
17
+ return undefined;
18
+ }
19
+ return action.title;
20
+ };
21
+ // appIcon can not be pressed but we wanna have a non-optional onPress on native side
22
+ const getAppIconAction = (alignment) => ({
23
+ type: 'appIcon',
24
+ onPress: () => null,
25
+ alignment,
26
+ });
27
+ const convertToNitro = (template, action, alignment) => {
28
+ const { type } = action;
29
+ if (type === 'appIcon') {
30
+ return getAppIconAction(alignment);
31
+ }
32
+ const { onPress } = action;
33
+ if (type === 'back') {
34
+ return { type, onPress: () => onPress(template), alignment };
35
+ }
36
+ const { enabled, flags, style } = action;
37
+ const title = getTitle(action);
38
+ const image = getImage(action);
39
+ return {
40
+ onPress: () => onPress(template),
41
+ type: 'custom',
42
+ enabled,
43
+ flags,
44
+ image,
45
+ title,
46
+ alignment,
47
+ style,
48
+ };
49
+ };
50
+ const convertActionButtons = (template, actions) => {
51
+ return actions?.map((action) => convertToNitro(template, action, undefined));
52
+ };
53
+ function convertIos(template, actions) {
54
+ if (actions == null) {
55
+ return undefined;
56
+ }
57
+ const nitroActions = [];
58
+ if (actions.backButton != null) {
59
+ nitroActions.push({
60
+ type: 'back',
61
+ onPress: () => actions.backButton?.onPress(template),
62
+ alignment: undefined,
63
+ });
64
+ }
65
+ if (actions.leadingNavigationBarButtons != null) {
66
+ for (const button of actions.leadingNavigationBarButtons) {
67
+ const { onPress, enabled } = button;
68
+ const image = getImage(button);
69
+ const title = getTitle(button);
70
+ nitroActions.push({
71
+ type: 'custom',
72
+ enabled,
73
+ image,
74
+ onPress: () => onPress(template),
75
+ title,
76
+ alignment: 'leading',
77
+ });
78
+ }
79
+ }
80
+ if (actions.trailingNavigationBarButtons) {
81
+ for (const button of actions.trailingNavigationBarButtons) {
82
+ const { onPress, enabled } = button;
83
+ const image = getImage(button);
84
+ const title = getTitle(button);
85
+ nitroActions.push({
86
+ type: 'custom',
87
+ enabled,
88
+ image,
89
+ onPress: () => onPress(template),
90
+ title,
91
+ alignment: 'trailing',
92
+ });
93
+ }
94
+ }
95
+ return nitroActions;
96
+ }
97
+ function convertAndroid(template, actions) {
98
+ if (actions == null) {
99
+ return undefined;
100
+ }
101
+ if (Array.isArray(actions)) {
102
+ return convertActionButtons(template, actions);
103
+ }
104
+ const nitroActions = [];
105
+ const { startHeaderAction, endHeaderActions = [] } = actions;
106
+ if (startHeaderAction != null) {
107
+ const action = startHeaderAction.type === 'appIcon'
108
+ ? getAppIconAction('leading')
109
+ : {
110
+ ...startHeaderAction,
111
+ alignment: 'leading',
112
+ onPress: () => startHeaderAction.onPress(template),
113
+ };
114
+ nitroActions.push(action);
115
+ }
116
+ for (const action of endHeaderActions) {
117
+ nitroActions.push(convertToNitro(template, action, 'trailing'));
118
+ }
119
+ return nitroActions;
120
+ }
121
+ function convert(template, actions) {
122
+ if (Array.isArray(actions)) {
123
+ return convertActionButtons(template, actions);
124
+ }
125
+ return react_native_1.Platform.OS === 'android'
126
+ ? convertAndroid(template, actions?.android)
127
+ : convertIos(template, actions?.ios);
128
+ }
129
+ exports.NitroActionUtil = { convert };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NitroAlertUtil = void 0;
4
+ const NitroImage_1 = require("./NitroImage");
5
+ var AlertPriorityEnum;
6
+ (function (AlertPriorityEnum) {
7
+ AlertPriorityEnum[AlertPriorityEnum["low"] = 0] = "low";
8
+ AlertPriorityEnum[AlertPriorityEnum["medium"] = 1] = "medium";
9
+ AlertPriorityEnum[AlertPriorityEnum["high"] = 2] = "high";
10
+ })(AlertPriorityEnum || (AlertPriorityEnum = {}));
11
+ const convert = (alert) => {
12
+ const { image, priority, ...rest } = alert;
13
+ return {
14
+ ...rest,
15
+ image: NitroImage_1.NitroImageUtil.convert(image),
16
+ priority: AlertPriorityEnum[priority],
17
+ };
18
+ };
19
+ exports.NitroAlertUtil = { convert };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NitroAttributedStringUtil = void 0;
4
+ const NitroImage_1 = require("./NitroImage");
5
+ function convert(attributedStrings) {
6
+ return attributedStrings.map((attributedString) => ({
7
+ ...attributedString,
8
+ images: attributedString.images?.map((image) => ({
9
+ ...image,
10
+ image: NitroImage_1.NitroImageUtil.convert(image.image),
11
+ })),
12
+ }));
13
+ }
14
+ exports.NitroAttributedStringUtil = { convert };
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NitroColorUtil = void 0;
4
+ const react_native_1 = require("react-native");
5
+ const DefaultNitroColor = {
6
+ darkColor: convertColor('white'),
7
+ lightColor: convertColor('black'),
8
+ isDefault: true,
9
+ };
10
+ function convertColor(color) {
11
+ // since we accept only string it can return a number only
12
+ return (0, react_native_1.processColor)(color);
13
+ }
14
+ function convert(color) {
15
+ if (color == null) {
16
+ return undefined;
17
+ }
18
+ if (typeof color === 'string') {
19
+ if (color === 'default') {
20
+ return DefaultNitroColor;
21
+ }
22
+ const convertedColor = convertColor(color);
23
+ return { darkColor: convertedColor, lightColor: convertedColor };
24
+ }
25
+ const darkColor = convertColor(color.darkColor);
26
+ const lightColor = convertColor(color.lightColor);
27
+ return {
28
+ darkColor,
29
+ lightColor,
30
+ };
31
+ }
32
+ exports.NitroColorUtil = { convert };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NitroGridUtil = void 0;
4
+ const NitroImage_1 = require("./NitroImage");
5
+ const convert = (template, buttons) => {
6
+ return buttons.map((button) => ({
7
+ title: button.title,
8
+ image: NitroImage_1.NitroImageUtil.convert(button.image),
9
+ onPress: () => button.onPress(template),
10
+ }));
11
+ };
12
+ exports.NitroGridUtil = { convert };
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NitroImageUtil = void 0;
4
+ exports.setIconFont = setIconFont;
5
+ const react_native_1 = require("react-native");
6
+ const NitroColor_1 = require("./NitroColor");
7
+ let _iconFont;
8
+ let _glyphMap;
9
+ /**
10
+ * Register the icon font and (optionally) a glyph map for name-based lookups.
11
+ * Must be called **once** before creating any templates. Subsequent calls are ignored.
12
+ *
13
+ * The font name maps directly to a native font asset:
14
+ * - **Android** — `res/font/<name>.ttf` (must be lowercase)
15
+ * - **iOS** — `<name>.ttf` in the app bundle (registered via CoreText automatically)
16
+ *
17
+ * For cross-platform compatibility use lowercase with underscores only.
18
+ *
19
+ * @param name Native font asset name (without extension).
20
+ * @param glyphMap Optional map of glyph names to Unicode code points.
21
+ * When provided, glyphs can use `{ type: 'glyph', name: 'icon_name' }`.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * import { glyphMap } from './assets/Glyphmap';
26
+ * setIconFont('material_symbols', glyphMap);
27
+ * ```
28
+ */
29
+ function setIconFont(name, glyphMap) {
30
+ if (_iconFont != null) {
31
+ return;
32
+ }
33
+ _iconFont = name;
34
+ _glyphMap = glyphMap;
35
+ }
36
+ function getIconFont() {
37
+ if (_iconFont == null) {
38
+ throw new Error('No icon font configured. Call setIconFont("your_font_name") before using glyph images.');
39
+ }
40
+ return _iconFont;
41
+ }
42
+ function resolveGlyph(image) {
43
+ if ('name' in image && image.name !== undefined) {
44
+ if (image.codepoint !== undefined) {
45
+ return image.codepoint;
46
+ }
47
+ if (_glyphMap == null) {
48
+ throw new Error(`Glyph name "${image.name}" used but no glyph map was provided to setIconFont().`);
49
+ }
50
+ const cp = _glyphMap[image.name];
51
+ if (cp === undefined) {
52
+ throw new Error(`Glyph name "${image.name}" not found in the glyph map.`);
53
+ }
54
+ return cp;
55
+ }
56
+ if (image.codepoint !== undefined) {
57
+ return image.codepoint;
58
+ }
59
+ throw new Error('Glyph image must provide either `name` or `codepoint`.');
60
+ }
61
+ function convert(image) {
62
+ if (image == null) {
63
+ return undefined;
64
+ }
65
+ if (image.type === 'glyph') {
66
+ const { color = 'default', fontScale, backgroundColor = 'transparent' } = image;
67
+ return {
68
+ glyph: resolveGlyph(image),
69
+ fontName: getIconFont(),
70
+ color: NitroColor_1.NitroColorUtil.convert(color),
71
+ backgroundColor: NitroColor_1.NitroColorUtil.convert(backgroundColor),
72
+ fontScale,
73
+ };
74
+ }
75
+ if (image.type === 'remote') {
76
+ return {
77
+ uri: image.uri,
78
+ color: NitroColor_1.NitroColorUtil.convert(image.color),
79
+ timeoutMs: image.timeoutMs,
80
+ };
81
+ }
82
+ // Image.resolveAssetSource is pretty terrible, it will simply return whatever object you pass it is not a number [require(...)]
83
+ // so the input allows all optional parameters which are returned as is even though
84
+ // the return type claims to not have any optional parameters...
85
+ // we specify some default values to not crash because of proper typing required by nitro-modules
86
+ const { height = 0, scale = 0, uri, width = 0, ...rest } = react_native_1.Image.resolveAssetSource(image.image);
87
+ const assetImage = {
88
+ height,
89
+ scale,
90
+ uri,
91
+ width,
92
+ packager_asset: '__packager_asset' in rest ? Boolean(rest.__packager_asset) : false,
93
+ color: NitroColor_1.NitroColorUtil.convert(image.color),
94
+ };
95
+ return assetImage;
96
+ }
97
+ exports.NitroImageUtil = { convert };
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NitroManeuverUtil = void 0;
4
+ const Maneuver_1 = require("../types/Maneuver");
5
+ const NitroColor_1 = require("./NitroColor");
6
+ const NitroImage_1 = require("./NitroImage");
7
+ function convertManeuverImage(image) {
8
+ if (image == null) {
9
+ return undefined;
10
+ }
11
+ if (image.type === 'glyph') {
12
+ const color = typeof image.color === 'string' ? image.color : (image.color ?? 'default');
13
+ return NitroImage_1.NitroImageUtil.convert({
14
+ ...image,
15
+ color: color,
16
+ });
17
+ }
18
+ return NitroImage_1.NitroImageUtil.convert(image);
19
+ }
20
+ function convert(autoManeuver) {
21
+ if (autoManeuver.type === 'message') {
22
+ const { title, image, text } = autoManeuver;
23
+ return {
24
+ title,
25
+ text,
26
+ image: convertManeuverImage(image),
27
+ cardBackgroundColor: NitroColor_1.NitroColorUtil.convert(autoManeuver.cardBackgroundColor),
28
+ };
29
+ }
30
+ const { symbolImage, junctionImage, attributedInstructionVariants, id, maneuverType, trafficSide, travelEstimates, highwayExitLabel, linkedLaneGuidance, roadName, cardBackgroundColor, } = autoManeuver;
31
+ const elementAngles = maneuverType === Maneuver_1.ManeuverType.Turn || maneuverType === Maneuver_1.ManeuverType.Roundabout
32
+ ? autoManeuver.elementAngles
33
+ : undefined;
34
+ const angle = maneuverType === Maneuver_1.ManeuverType.Turn || maneuverType === Maneuver_1.ManeuverType.Roundabout
35
+ ? autoManeuver.angle
36
+ : undefined;
37
+ const turnType = maneuverType === Maneuver_1.ManeuverType.Turn ? autoManeuver.turnType : undefined;
38
+ const exitNumber = maneuverType === Maneuver_1.ManeuverType.Roundabout ? autoManeuver.exitNumber : undefined;
39
+ const offRampType = maneuverType === Maneuver_1.ManeuverType.OffRamp ? autoManeuver.offRampType : undefined;
40
+ const onRampType = maneuverType === Maneuver_1.ManeuverType.OnRamp ? autoManeuver.onRampType : undefined;
41
+ const forkType = maneuverType === Maneuver_1.ManeuverType.Fork ? autoManeuver.forkType : undefined;
42
+ const keepType = maneuverType === Maneuver_1.ManeuverType.Keep ? autoManeuver.keepType : undefined;
43
+ return {
44
+ id,
45
+ maneuverType,
46
+ trafficSide,
47
+ travelEstimates,
48
+ linkedLaneGuidance: linkedLaneGuidance
49
+ ? {
50
+ ...linkedLaneGuidance,
51
+ lanes: linkedLaneGuidance.lanes.map((lane) => ({
52
+ ...lane,
53
+ image: convertManeuverImage(lane.image),
54
+ })),
55
+ }
56
+ : undefined,
57
+ highwayExitLabel,
58
+ roadName,
59
+ attributedInstructionVariants: attributedInstructionVariants.map((variant) => ({
60
+ text: variant.text,
61
+ images: variant.images?.map(({ image, position }) => ({
62
+ image: convertManeuverImage(image),
63
+ position,
64
+ })),
65
+ })),
66
+ junctionImage: convertManeuverImage(junctionImage),
67
+ symbolImage: convertManeuverImage(symbolImage),
68
+ elementAngles,
69
+ angle,
70
+ turnType,
71
+ exitNumber,
72
+ offRampType,
73
+ onRampType,
74
+ forkType,
75
+ keepType,
76
+ cardBackgroundColor: NitroColor_1.NitroColorUtil.convert(cardBackgroundColor),
77
+ };
78
+ }
79
+ exports.NitroManeuverUtil = { convert };
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NitroMapButton = void 0;
4
+ const react_native_1 = require("react-native");
5
+ const NitroImage_1 = require("./NitroImage");
6
+ const convert = (template, mapButtons) => {
7
+ if (mapButtons == null) {
8
+ return undefined;
9
+ }
10
+ return mapButtons?.map((button) => {
11
+ const { type } = button;
12
+ const onPress = button.type === 'custom' ? () => button.onPress(template) : undefined;
13
+ if (button.image.type === 'glyph') {
14
+ const backgroundColor = react_native_1.Platform.OS === 'android'
15
+ ? 'transparent'
16
+ : 'backgroundColor' in button.image
17
+ ? button.image.backgroundColor
18
+ : 'transparent';
19
+ const fontScale = button.image.fontScale ?? (react_native_1.Platform.OS === 'android' ? 1.0 : 0.65);
20
+ return {
21
+ type,
22
+ onPress,
23
+ image: NitroImage_1.NitroImageUtil.convert({ ...button.image, backgroundColor, fontScale }),
24
+ };
25
+ }
26
+ return {
27
+ type,
28
+ onPress,
29
+ image: NitroImage_1.NitroImageUtil.convert(button.image),
30
+ };
31
+ });
32
+ };
33
+ exports.NitroMapButton = { convert };