react-native-maplibre-gl-js 1.0.3 → 1.2.0

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 (105) hide show
  1. package/README.md +89 -29
  2. package/lib/module/index.js +9 -6
  3. package/lib/module/index.js.map +1 -1
  4. package/lib/module/react-native/components/Map/Map.js +30 -1
  5. package/lib/module/react-native/components/Map/Map.js.map +1 -1
  6. package/lib/module/react-native/components/Map/Map.test.js +19 -0
  7. package/lib/module/react-native/components/Map/Map.test.js.map +1 -0
  8. package/lib/module/react-native/components/MapProvider/MapProvider.hooks.js +149 -2
  9. package/lib/module/react-native/components/MapProvider/MapProvider.hooks.js.map +1 -1
  10. package/lib/module/react-native/components/MapProvider/MapProvider.js +33 -87
  11. package/lib/module/react-native/components/MapProvider/MapProvider.js.map +1 -1
  12. package/lib/module/react-native/components/MapProvider/MapProvider.test.js +144 -0
  13. package/lib/module/react-native/components/MapProvider/MapProvider.test.js.map +1 -0
  14. package/lib/module/react-native/components/MapProvider/MapProvider.utils.js +58 -0
  15. package/lib/module/react-native/components/MapProvider/MapProvider.utils.js.map +1 -0
  16. package/lib/module/react-native/components/Marker/Marker.js +47 -1
  17. package/lib/module/react-native/components/Marker/Marker.js.map +1 -1
  18. package/lib/module/react-native/components/Marker/Marker.test.js +19 -0
  19. package/lib/module/react-native/components/Marker/Marker.test.js.map +1 -0
  20. package/lib/module/react-native/components/Popup/Popup.js +29 -1
  21. package/lib/module/react-native/components/Popup/Popup.js.map +1 -1
  22. package/lib/module/react-native/components/Popup/Popup.test.js +19 -0
  23. package/lib/module/react-native/components/Popup/Popup.test.js.map +1 -0
  24. package/lib/module/react-native/components-factory/createWebObjectAsComponent.js +3 -5
  25. package/lib/module/react-native/components-factory/createWebObjectAsComponent.js.map +1 -1
  26. package/lib/module/react-native/components-factory/createWebObjectAsComponent.test.js +28 -0
  27. package/lib/module/react-native/components-factory/createWebObjectAsComponent.test.js.map +1 -0
  28. package/lib/module/react-native/components-factory/hooks/useWebObjectMethodsProxy.mock.js +5 -0
  29. package/lib/module/react-native/components-factory/hooks/useWebObjectMethodsProxy.mock.js.map +1 -0
  30. package/lib/module/react-native/components-factory/hooks/useWebObjectMountOnLaunch.mock.js +5 -0
  31. package/lib/module/react-native/components-factory/hooks/useWebObjectMountOnLaunch.mock.js.map +1 -0
  32. package/lib/module/react-native/components-factory/hooks/useWebObjectPropertiesUpdater.js +14 -0
  33. package/lib/module/react-native/components-factory/hooks/useWebObjectPropertiesUpdater.js.map +1 -0
  34. package/lib/module/react-native/components-factory/hooks/useWebObjectPropertiesUpdater.mock.js +5 -0
  35. package/lib/module/react-native/components-factory/hooks/useWebObjectPropertiesUpdater.mock.js.map +1 -0
  36. package/lib/module/react-native/hooks/atoms/useMapAtoms.js +1 -1
  37. package/lib/module/react-native/hooks/atoms/useMapAtoms.mock.js +12 -0
  38. package/lib/module/react-native/hooks/atoms/useMapAtoms.mock.js.map +1 -0
  39. package/lib/module/react-native/logger/rn-logger.mock.js +10 -0
  40. package/lib/module/react-native/logger/rn-logger.mock.js.map +1 -0
  41. package/lib/module/typedoc.js +0 -2
  42. package/lib/module/web/generated/webview_static_html.js +3329 -3268
  43. package/lib/module/web/generated/webview_static_html.js.map +1 -1
  44. package/lib/module/web/maplibre-gl-js/MapController.js +1 -6
  45. package/lib/module/web/maplibre-gl-js/MapController.js.map +1 -1
  46. package/lib/typescript/jest.setup.d.ts +2 -0
  47. package/lib/typescript/jest.setup.d.ts.map +1 -0
  48. package/lib/typescript/src/index.d.ts +10 -14
  49. package/lib/typescript/src/index.d.ts.map +1 -1
  50. package/lib/typescript/src/react-native/components/Map/Map.d.ts +30 -1
  51. package/lib/typescript/src/react-native/components/Map/Map.d.ts.map +1 -1
  52. package/lib/typescript/src/react-native/components/Map/Map.test.d.ts +2 -0
  53. package/lib/typescript/src/react-native/components/Map/Map.test.d.ts.map +1 -0
  54. package/lib/typescript/src/react-native/components/Map/Map.types.d.ts +70 -58
  55. package/lib/typescript/src/react-native/components/Map/Map.types.d.ts.map +1 -1
  56. package/lib/typescript/src/react-native/components/MapProvider/MapProvider.d.ts +12 -2
  57. package/lib/typescript/src/react-native/components/MapProvider/MapProvider.d.ts.map +1 -1
  58. package/lib/typescript/src/react-native/components/MapProvider/MapProvider.hooks.d.ts +27 -1
  59. package/lib/typescript/src/react-native/components/MapProvider/MapProvider.hooks.d.ts.map +1 -1
  60. package/lib/typescript/src/react-native/components/MapProvider/MapProvider.test.d.ts +2 -0
  61. package/lib/typescript/src/react-native/components/MapProvider/MapProvider.test.d.ts.map +1 -0
  62. package/lib/typescript/src/react-native/components/MapProvider/MapProvider.types.d.ts +26 -1
  63. package/lib/typescript/src/react-native/components/MapProvider/MapProvider.types.d.ts.map +1 -1
  64. package/lib/typescript/src/react-native/components/MapProvider/MapProvider.utils.d.ts +14 -0
  65. package/lib/typescript/src/react-native/components/MapProvider/MapProvider.utils.d.ts.map +1 -0
  66. package/lib/typescript/src/react-native/components/Marker/Marker.d.ts +47 -1
  67. package/lib/typescript/src/react-native/components/Marker/Marker.d.ts.map +1 -1
  68. package/lib/typescript/src/react-native/components/Marker/Marker.test.d.ts +2 -0
  69. package/lib/typescript/src/react-native/components/Marker/Marker.test.d.ts.map +1 -0
  70. package/lib/typescript/src/react-native/components/Marker/Marker.types.d.ts +25 -12
  71. package/lib/typescript/src/react-native/components/Marker/Marker.types.d.ts.map +1 -1
  72. package/lib/typescript/src/react-native/components/Popup/Popup.d.ts +29 -1
  73. package/lib/typescript/src/react-native/components/Popup/Popup.d.ts.map +1 -1
  74. package/lib/typescript/src/react-native/components/Popup/Popup.test.d.ts +2 -0
  75. package/lib/typescript/src/react-native/components/Popup/Popup.test.d.ts.map +1 -0
  76. package/lib/typescript/src/react-native/components/Popup/Popup.types.d.ts +24 -11
  77. package/lib/typescript/src/react-native/components/Popup/Popup.types.d.ts.map +1 -1
  78. package/lib/typescript/src/react-native/components-factory/createWebObjectAsComponent.d.ts.map +1 -1
  79. package/lib/typescript/src/react-native/components-factory/createWebObjectAsComponent.test.d.ts +2 -0
  80. package/lib/typescript/src/react-native/components-factory/createWebObjectAsComponent.test.d.ts.map +1 -0
  81. package/lib/typescript/src/react-native/components-factory/createWebObjectAsComponent.types.d.ts +18 -16
  82. package/lib/typescript/src/react-native/components-factory/createWebObjectAsComponent.types.d.ts.map +1 -1
  83. package/lib/typescript/src/react-native/components-factory/hooks/useWebObjectMethodsProxy.mock.d.ts +3 -0
  84. package/lib/typescript/src/react-native/components-factory/hooks/useWebObjectMethodsProxy.mock.d.ts.map +1 -0
  85. package/lib/typescript/src/react-native/components-factory/hooks/useWebObjectMountOnLaunch.mock.d.ts +3 -0
  86. package/lib/typescript/src/react-native/components-factory/hooks/useWebObjectMountOnLaunch.mock.d.ts.map +1 -0
  87. package/lib/typescript/src/react-native/components-factory/hooks/useWebObjectPropertiesUpdater.d.ts +4 -0
  88. package/lib/typescript/src/react-native/components-factory/hooks/useWebObjectPropertiesUpdater.d.ts.map +1 -0
  89. package/lib/typescript/src/react-native/components-factory/hooks/useWebObjectPropertiesUpdater.mock.d.ts +3 -0
  90. package/lib/typescript/src/react-native/components-factory/hooks/useWebObjectPropertiesUpdater.mock.d.ts.map +1 -0
  91. package/lib/typescript/src/react-native/hooks/atoms/useMapAtoms.mock.d.ts +10 -0
  92. package/lib/typescript/src/react-native/hooks/atoms/useMapAtoms.mock.d.ts.map +1 -0
  93. package/lib/typescript/src/react-native/logger/rn-logger.mock.d.ts +7 -0
  94. package/lib/typescript/src/react-native/logger/rn-logger.mock.d.ts.map +1 -0
  95. package/lib/typescript/src/typedoc.d.ts +5 -2
  96. package/lib/typescript/src/typedoc.d.ts.map +1 -1
  97. package/lib/typescript/src/web/generated/webview_static_html.d.ts +1 -1
  98. package/lib/typescript/src/web/generated/webview_static_html.d.ts.map +1 -1
  99. package/lib/typescript/src/web/maplibre-gl-js/MapController.d.ts +1 -1
  100. package/lib/typescript/src/web/maplibre-gl-js/MapController.d.ts.map +1 -1
  101. package/package.json +45 -59
  102. package/lib/module/react-native/components-factory/hooks/useWebObjectOptionsUpdater.js +0 -20
  103. package/lib/module/react-native/components-factory/hooks/useWebObjectOptionsUpdater.js.map +0 -1
  104. package/lib/typescript/src/react-native/components-factory/hooks/useWebObjectOptionsUpdater.d.ts +0 -5
  105. package/lib/typescript/src/react-native/components-factory/hooks/useWebObjectOptionsUpdater.d.ts.map +0 -1
package/README.md CHANGED
@@ -1,11 +1,18 @@
1
+
1
2
  <div align="center">
2
3
  <h1>react-native-maplibre-gl-js</h1>
3
- </div>
4
- <div align="center">
5
- <img src="https://img.shields.io/github/license/emilienaufauvre/react-native-maplibre-gl-js?style=for-the-badge&labelColor=black" />
6
- <img src="https://img.shields.io/github/actions/workflow/status/emilienaufauvre/react-native-maplibre-gl-js/ci.yml?branch=main&style=for-the-badge&label=CI&labelColor=black" />
7
- <img src="https://img.shields.io/github/actions/workflow/status/emilienaufauvre/react-native-maplibre-gl-js/cd.yml?branch=main&style=for-the-badge&label=CD&labelColor=black" />
8
- <img src="https://img.shields.io/npm/v/react-native-maplibre-gl-js.svg?style=for-the-badge&label=NPM&labelColor=black" />
4
+ <a href="https://github.com/emilienaufauvre/react-native-maplibre-gl-js/actions/workflows/validation.yml">
5
+ <img src="https://img.shields.io/github/actions/workflow/status/emilienaufauvre/react-native-maplibre-gl-js/validation.yml?branch=main&style=for-the-badge&label=Validation&labelColor=black" />
6
+ </a>
7
+ <a href="https://codecov.io/github/emilienaufauvre/react-native-maplibre-gl-js">
8
+ <img src="https://img.shields.io/codecov/c/github/emilienaufauvre/react-native-maplibre-gl-js/main?style=for-the-badge&labelColor=black&label=Test%20coverage" />
9
+ </a>
10
+ <a href="https://github.com/emilienaufauvre/react-native-maplibre-gl-js/actions/workflows/delivery.yml">
11
+ <img src="https://img.shields.io/github/actions/workflow/status/emilienaufauvre/react-native-maplibre-gl-js/delivery.yml?branch=main&style=for-the-badge&label=Delivery&labelColor=black" />
12
+ </a>
13
+ <a href="https://www.npmjs.com/package/react-native-maplibre-gl-js">
14
+ <img src="https://img.shields.io/npm/v/react-native-maplibre-gl-js.svg?style=for-the-badge&label=NPM&labelColor=black" />
15
+ </a>
9
16
  </div>
10
17
 
11
18
  <div align="center">
@@ -39,32 +46,85 @@
39
46
  > This project **is not** affiliated with, endorsed by, or sponsored by MapLibre.
40
47
 
41
48
 
42
- ## Supported platforms
49
+ ## Table of contents
43
50
 
44
- | Platform | Status |
45
- |--------|--------|
46
- | iOS | ✅ |
47
- | Android | ✅ |
48
- | Web | ❌ |
51
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
52
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
49
53
 
50
- ## Documentation
54
+ - [Supported platforms](#supported-platforms)
55
+ - [Installation](#installation)
56
+ - [📚 Documentation](#-documentation)
57
+ - [🧪 Examples](#-examples)
58
+ - [1. Map](#1-map)
59
+ - [2. Marker](#2-marker)
60
+ - [3. Popup](#3-popup)
61
+ - [🏁 Getting started](#-getting-started)
62
+ - [📝 Design rationale](#-design-rationale)
63
+ - [Existing React Native map solutions](#existing-react-native-map-solutions)
64
+ - [Architectural approach](#architectural-approach)
65
+ - [Contributing](#contributing)
66
+ - [Credits](#credits)
67
+ - [License](#license)
51
68
 
52
- 📘 [**API Reference** Complete TypeScript API documentation.](./docs/api/index.md)
69
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
53
70
 
54
- 🧪 [**Examples** – Real-world examples showcasing common use cases.](./docs/examples/index.md)
55
71
 
56
- 📚 [**For library developers** – Internal architecture, glossary and design decisions.](./docs/developer/index.md)
72
+ ## Supported platforms
57
73
 
74
+ | Platform | Status |
75
+ |----------|--------|
76
+ | iOS | ✅ |
77
+ | Android | ✅ |
78
+ | Web | ❌ |
58
79
 
59
- ## Installation
60
80
 
61
- ** TODO not available on npm yet **
81
+ ## Installation
62
82
 
63
83
  ```sh
64
84
  npm install react-native-maplibre-gl-js
65
85
  ```
66
86
 
67
- ## Getting started
87
+ ## 📚 Documentation
88
+
89
+ [**API Reference** – Complete TypeScript API documentation.](./docs/api/index.md)
90
+
91
+ [**For library developers** – Internal architecture, glossary and design decisions.](./docs/developer/index.md)
92
+
93
+
94
+ ## 🧪 Examples
95
+
96
+ Several real-world usage scenarios are available, you can explore them in two ways:
97
+
98
+ - [**Run the examples as an Expo app**](./CONTRIBUTING.md#scripts) to interact
99
+ with them directly.
100
+ - [**Browse the source code**](./example/src/app) to understand how each feature
101
+ is implemented (see below the example list).
102
+
103
+ <!-- EXAMPLES-LIST:START -->
104
+
105
+ ### 1. Map
106
+
107
+ - [`1.1. Component basis`](./example/src/app/1.-Map/1.1.-Component-basis.tsx)
108
+ - [`1.2. Create a camera animation`](./example/src/app/1.-Map/1.2.-Create-a-camera-animation.tsx)
109
+ - [`1.3. Use the globe projection`](./example/src/app/1.-Map/1.3.-Use-the-globe-projection.tsx)
110
+ - [`1.4. Add a raster tile source directly on map`](./example/src/app/1.-Map/1.4.-Add-a-raster-tile-source-directly-on-map.tsx)
111
+
112
+ ### 2. Marker
113
+
114
+ - [`2.1. Component basis`](./example/src/app/2.-Marker/2.1.-Component-basis.tsx)
115
+ - [`2.2. Animate the coordinate`](./example/src/app/2.-Marker/2.2.-Animate-the-coordinate.tsx)
116
+ - [`2.3. Use an detached popup`](./example/src/app/2.-Marker/2.3.-Use-an-detached-popup.tsx)
117
+ - [`2.4. Use an attached popup`](./example/src/app/2.-Marker/2.4.-Use-an-attached-popup.tsx)
118
+ - [`2.5. Propagates the events to a parent component`](./example/src/app/2.-Marker/2.5.-Propagates-the-events-to-a-parent-component.tsx)
119
+
120
+ ### 3. Popup
121
+
122
+ - [`3.1. Component basis`](./example/src/app/3.-Popup/3.1.-Component-basis.tsx)
123
+
124
+ <!-- EXAMPLES-LIST:END -->
125
+
126
+
127
+ ## 🏁 Getting started
68
128
 
69
129
  The minimal setup to render a MapLibre map in React Native.
70
130
 
@@ -89,7 +149,7 @@ export default App
89
149
  ```
90
150
 
91
151
 
92
- ## Design rationale
152
+ ## 📝 Design rationale
93
153
 
94
154
  Explain why I decided to build a new React Native map library instead of using
95
155
  an existing one.
@@ -101,11 +161,11 @@ that can be used in React Native. Each has its strengths, and credit goes to
101
161
  their contributors. Still, I have highlighted what I consider to be their main
102
162
  drawbacks.
103
163
 
104
- | Library | Notes | Main Drawbacks |
105
- |-----------------------------|------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
106
- | `react-native-maps` / `expo-maps` | Overlay custom tiles on Apple Maps (iOS) or Google Maps (iOS/Android). | - On tile loading, the map below (Google Maps or Apple Maps) is visible.<br/>- If the map provider is Google Maps (mandatory on the Android platform), an API key is needed to use Google Maps SDK, and therefore its use is billed. |
107
- | `@rnmapbox/maps` | - | - Dependence on Mapbox choices.<br>- On the latest versions, an API key is required (at least on the Android side that drops the MapLibre SDK support), and therefore its use is billed.<br>- To render animated markers or markers with dynamic content and developed visual styles, the use of native views is necessary, and this greatly slows down the application. |
108
- | `maplibre-react-native` | Open source fork of MapBox. | - Being an open source fork of MapBox, the library is years behind (1000+ commits to date) and lacks many features and bug fixes.<br>- The same performance issue with native views as `@rnmapbox` is also present. |
164
+ | Library | Notes | Main Drawbacks |
165
+ |-----------------------------------|------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
166
+ | `react-native-maps` / `expo-maps` | Overlay custom tiles on Apple Maps (iOS) or Google Maps (iOS/Android). | - On tile loading, the map below (Google Maps or Apple Maps) is visible.<br/>- If the map provider is Google Maps (mandatory on the Android platform), an API key is needed to use Google Maps SDK, and therefore its use is billed. |
167
+ | `@rnmapbox/maps` | - | - Dependence on Mapbox choices.<br>- On the latest versions, an API key is required (at least on the Android side that drops the MapLibre SDK support), and therefore its use is billed.<br>- To render animated markers or markers with dynamic content and developed visual styles, the use of native views is necessary, and this greatly slows down the application. |
168
+ | `maplibre-react-native` | Open source fork of MapBox. | - Being an open source fork of MapBox, the library is years behind (1000+ commits to date) and lacks many features and bug fixes.<br>- The same performance issue with native views as `@rnmapbox` is also present. |
109
169
 
110
170
  ### Architectural approach
111
171
 
@@ -122,10 +182,10 @@ libraries, while enabling more features.
122
182
  I outline two solutions in this category below, along with the issues they still
123
183
  carry. This library implements the second approach.
124
184
 
125
- | Approach | Description | Main Drawbacks |
126
- |-----------------------------------------------|-----------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
127
- | Remote WebView-based map | Host a map on a web page and access it through a WebView. | - Requires additional infrastructure.<br>- Very sensitive to network latency, and in general, a degraded user experience.<br>- Offline usage is not possible. |
128
- | Embedded WebView with bundled MapLibre GL JS | Bundle JS code that runs MapLibre GL JS, enabling two-way communication with React Native, and inject it into a WebView for execution. | - Any interaction between the WebView content and the React Native world is made through message-passing, which can make certain interactions more indirect.<br>- Some objects cannot be serialized and sent between the WebView code and React Native (e.g., HTMLElement).<br>- Some GitHub repositories are implementing this solution, however, no one is actively maintained, and the underlying web libraries are missing key features — good examples being `react-native-leaflet-view` and `@neukolabs/react-native-maplibre-js`. |
185
+ | Approach | Description | Main Drawbacks <br/> |
186
+ |----------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
187
+ | Remote WebView-based map | Host a map on a web page and access it through a WebView. | - Requires additional infrastructure.<br>- Very sensitive to network latency, and in general, a degraded user experience.<br>- Offline usage is not possible. |
188
+ | Embedded WebView with bundled `MapLibre GL JS` | Bundle JS code that runs `MapLibre GL JS`, enabling two-way communication with React Native, and inject it into a WebView for execution. | - Any interaction between the WebView content and the React Native world is made through message-passing, which can make certain interactions more indirect.<br>- Some objects cannot be serialized and sent between the WebView code and React Native (e.g., HTMLElement).<br>- Some GitHub repositories are implementing this solution, however, no one is actively maintained, and the underlying web libraries are missing key features — good examples being `react-native-leaflet-view` and `@neukolabs/react-native-maplibre-js`. |
129
189
 
130
190
 
131
191
  ## Contributing
@@ -1,14 +1,17 @@
1
1
  "use strict";
2
2
 
3
3
  /**
4
- * Public API of react-native-maplibre-gl-js.
4
+ * Public API of `react-native-maplibre-gl-js`.
5
5
  * @module Public API
6
6
  * @packageDocumentation
7
+ * @sortStrategy sort-order
7
8
  */
8
9
 
9
- import MapProvider from "./react-native/components/MapProvider/MapProvider.js";
10
- import Map from "./react-native/components/Map/Map.js";
11
- import Marker from "./react-native/components/Marker/Marker.js";
12
- import Popup from "./react-native/components/Popup/Popup.js";
13
- export { MapProvider, Map, Marker, Popup };
10
+ // @group Types
11
+
12
+ // @group Components
13
+ export { default as MapProvider } from "./react-native/components/MapProvider/MapProvider.js";
14
+ export { default as Map } from "./react-native/components/Map/Map.js";
15
+ export { default as Marker } from "./react-native/components/Marker/Marker.js";
16
+ export { default as Popup } from "./react-native/components/Popup/Popup.js";
14
17
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["MapProvider","Map","Marker","Popup"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;;AAkBA,OAAOA,WAAW,MAAM,sDAAmD;AAC3E,OAAOC,GAAG,MAAM,sCAAmC;AACnD,OAAOC,MAAM,MAAM,4CAAyC;AAC5D,OAAOC,KAAK,MAAM,0CAAuC;AAEzD,SAASH,WAAW,EAAEC,GAAG,EAAEC,MAAM,EAAEC,KAAK","ignoreList":[]}
1
+ {"version":3,"names":["default","MapProvider","Map","Marker","Popup"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAYA;AACA,SAASA,OAAO,IAAIC,WAAW,QAAQ,sDAAmD;AAC1F,SAASD,OAAO,IAAIE,GAAG,QAAQ,sCAAmC;AAClE,SAASF,OAAO,IAAIG,MAAM,QAAQ,4CAAyC;AAC3E,SAASH,OAAO,IAAII,KAAK,QAAQ,0CAAuC","ignoreList":[]}
@@ -3,7 +3,36 @@
3
3
  import createWebObjectAsComponent from "../../components-factory/createWebObjectAsComponent.js";
4
4
  /**
5
5
  * MapLibre Map view.
6
- * @see {@link https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/ MapLibre GL JS docs}
6
+ * @props {@link MapProps}
7
+ * @ref {@link MapRef}
8
+ * @see {@link https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/ `MapLibre GL JS` docs}
9
+ * @example
10
+ * ```tsx
11
+ * <Map
12
+ * options={{
13
+ * style: 'https://tiles.openfreemap.org/styles/liberty',
14
+ * center: [2.32, 48.86],
15
+ * zoom: 12,
16
+ * }}
17
+ * listeners={{
18
+ * mount: {
19
+ * rnListener: () => console.log('Map mounted'),
20
+ * },
21
+ * unmount: {
22
+ * rnListener: () => console.log('Map unmounted'),
23
+ * },
24
+ * click: {
25
+ * objectListener: (event: MapMouseEvent) =>
26
+ * console.log('Map clicked', event),
27
+ * },
28
+ * rotatestart: {
29
+ * objectListener: (
30
+ * event: MapLibreEvent<MouseEvent | TouchEvent | undefined>,
31
+ * ) => console.log('Map rotation started', event),
32
+ * },
33
+ * }}
34
+ * />
35
+ * ```
7
36
  * @group Components
8
37
  */
9
38
  const Map = createWebObjectAsComponent('map');
@@ -1 +1 @@
1
- {"version":3,"names":["createWebObjectAsComponent","Map"],"sourceRoot":"../../../../../src","sources":["react-native/components/Map/Map.tsx"],"mappings":";;AAAA,OAAOA,0BAA0B,MAAM,wDAAqD;AAG5F;AACA;AACA;AACA;AACA;AACA,MAAMC,GAAG,GAAGD,0BAA0B,CAAmB,KAAK,CAAC;AAE/D,eAAeC,GAAG","ignoreList":[]}
1
+ {"version":3,"names":["createWebObjectAsComponent","Map"],"sourceRoot":"../../../../../src","sources":["react-native/components/Map/Map.tsx"],"mappings":";;AAAA,OAAOA,0BAA0B,MAAM,wDAAqD;AAG5F;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,GAAG,GAAGD,0BAA0B,CAAmB,KAAK,CAAC;AAE/D,eAAeC,GAAG","ignoreList":[]}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ import { render } from '@testing-library/react-native';
4
+ import Map from "./Map.js";
5
+ import { jsx as _jsx } from "react/jsx-runtime";
6
+ describe('Map', () => {
7
+ beforeEach(() => {
8
+ jest.clearAllMocks();
9
+ });
10
+ describe('Given the component is rendered', () => {
11
+ beforeEach(() => {
12
+ render(/*#__PURE__*/_jsx(Map, {}));
13
+ });
14
+ describe('When nothing', () => {
15
+ test('Then it does not crash', () => {});
16
+ });
17
+ });
18
+ });
19
+ //# sourceMappingURL=Map.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["render","Map","jsx","_jsx","describe","beforeEach","jest","clearAllMocks","test"],"sourceRoot":"../../../../../src","sources":["react-native/components/Map/Map.test.tsx"],"mappings":";;AAAA,SAASA,MAAM,QAAQ,+BAA+B;AACtD,OAAOC,GAAG,MAAM,UAAO;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAEvBC,QAAQ,CAAC,KAAK,EAAE,MAAM;EACpBC,UAAU,CAAC,MAAM;IACfC,IAAI,CAACC,aAAa,CAAC,CAAC;EACtB,CAAC,CAAC;EAEFH,QAAQ,CAAC,iCAAiC,EAAE,MAAM;IAChDC,UAAU,CAAC,MAAM;MACfL,MAAM,cAACG,IAAA,CAACF,GAAG,IAAE,CAAC,CAAC;IACjB,CAAC,CAAC;IAEFG,QAAQ,CAAC,cAAc,EAAE,MAAM;MAC7BI,IAAI,CAAC,wBAAwB,EAAE,MAAM,CAAC,CAAC,CAAC;IAC1C,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
 
3
3
  import { StyleSheet } from 'react-native';
4
- import { useMemo } from 'react';
4
+ import { useCallback, useEffect, useMemo, useRef } from 'react';
5
+ import RNLogger from "../../logger/rn-logger.js";
6
+ import { isWebObjectListenerOnHTMLElement, isWebObjectListenerOnMapLayer, isWebObjectListenerOnObject, isWebObjectListenerOnRN } from "../../../communication/messages.utils.js";
7
+ import useMapAtoms from "../../hooks/atoms/useMapAtoms.js";
8
+ import { buildCssInjectionScript, normalizeCss } from "./MapProvider.utils.js";
5
9
  export const useStyles = () => {
6
10
  return useMemo(() => StyleSheet.create({
7
11
  container: {
@@ -9,10 +13,153 @@ export const useStyles = () => {
9
13
  height: '100%',
10
14
  overflow: 'hidden'
11
15
  },
12
- webview: {
16
+ webView: {
13
17
  flex: 1,
14
18
  backgroundColor: 'transparent'
15
19
  }
16
20
  }), []);
17
21
  };
22
+
23
+ /**
24
+ * On start, the map must be mounted before any other map element. When the
25
+ * mount message of the map is ready, we flush all the pending messages to
26
+ * the web world.
27
+ */
28
+ export const useFlushMessagesOnMapMounted = () => {
29
+ // States.
30
+ // - Global.
31
+ const {
32
+ isMapMountMessageReady,
33
+ flushMessages
34
+ } = useMapAtoms();
35
+ useEffect(() => {
36
+ if (isMapMountMessageReady) {
37
+ flushMessages();
38
+ }
39
+ }, [flushMessages, isMapMountMessageReady]);
40
+ };
41
+
42
+ /**
43
+ * @returns - The handler that will receive the messages from the web world.
44
+ */
45
+ export const useWebMessageHandler = () => {
46
+ // States.
47
+ // - Global.
48
+ const {
49
+ setIsWebWorldReady,
50
+ getWebObjectListeners,
51
+ resolveWebObjectPendingMethodResponse
52
+ } = useMapAtoms();
53
+ const createWebViewMessageHandler = useCallback(handlers => {
54
+ // Not an anonymous function => get the function name for logger.
55
+ return function handleMessage(event) {
56
+ try {
57
+ RNLogger.debug('RN', handleMessage.name, event?.nativeEvent?.data);
58
+ const message = JSON.parse(event.nativeEvent.data);
59
+ const handler = handlers[message.type];
60
+ return handler?.(message);
61
+ } catch (error) {
62
+ RNLogger.error('RN', handleMessage.name, error.message);
63
+ }
64
+ };
65
+ }, []);
66
+
67
+ // Handle the messages from the web world by dispatching the message to the
68
+ // corresponding handler.
69
+ const handler = useMemo(() => {
70
+ return createWebViewMessageHandler({
71
+ console: ({
72
+ payload: {
73
+ args,
74
+ level
75
+ }
76
+ }) => {
77
+ RNLogger[level]('Web', args[0], ...args.slice(1));
78
+ },
79
+ ready: () => {
80
+ setIsWebWorldReady(true);
81
+ },
82
+ webObjectListenerEvent: ({
83
+ payload: {
84
+ eventName,
85
+ event,
86
+ objectId
87
+ }
88
+ }) => {
89
+ // Retrieve the corresponding object listener.
90
+ const listener = getWebObjectListeners({
91
+ objectId
92
+ })?.[eventName];
93
+ // Then, call it.
94
+ if (isWebObjectListenerOnRN(listener)) {
95
+ ;
96
+ listener.rnListener(event);
97
+ }
98
+ if (isWebObjectListenerOnObject(listener)) {
99
+ ;
100
+ listener.objectListener(event);
101
+ }
102
+ if (isWebObjectListenerOnMapLayer(listener)) {
103
+ ;
104
+ listener.layerListener(event);
105
+ }
106
+ if (isWebObjectListenerOnHTMLElement(listener)) {
107
+ ;
108
+ listener.elementListener(event);
109
+ }
110
+ },
111
+ webObjectMethodResponse: ({
112
+ payload: {
113
+ requestId,
114
+ result
115
+ }
116
+ }) => {
117
+ resolveWebObjectPendingMethodResponse({
118
+ requestId,
119
+ result
120
+ });
121
+ }
122
+ });
123
+ }, [createWebViewMessageHandler, setIsWebWorldReady, getWebObjectListeners, resolveWebObjectPendingMethodResponse]);
124
+ return {
125
+ handler
126
+ };
127
+ };
128
+
129
+ /**
130
+ * @param injectedCss - The CSS to be injected.
131
+ * @returns - The given CSS in a format that can be injected into the WebView.
132
+ */
133
+ export const useCssInjectionScript = injectedCss => {
134
+ const cssInjectionScript = useMemo(() => {
135
+ const normalizedCss = normalizeCss(injectedCss);
136
+ return normalizedCss ? buildCssInjectionScript(normalizedCss) : undefined;
137
+ }, [injectedCss]);
138
+ return {
139
+ cssInjectionScript
140
+ };
141
+ };
142
+
143
+ /**
144
+ * Inject the given script into the WebView if it changed.
145
+ * @param cssInjectionScript - A script that injects CSS once executed within
146
+ * the WebView.
147
+ */
148
+ export const useInjectJavaScriptIfInjectedCssChanged = cssInjectionScript => {
149
+ // Refs.
150
+ const lastInjectedScriptRef = useRef(undefined);
151
+ // States.
152
+ // - Global.
153
+ const {
154
+ webView,
155
+ isWebWorldReady
156
+ } = useMapAtoms();
157
+ useEffect(() => {
158
+ if (!cssInjectionScript || !isWebWorldReady || !webView || lastInjectedScriptRef.current === cssInjectionScript) {
159
+ return;
160
+ }
161
+ webView?.injectJavaScript(cssInjectionScript);
162
+ lastInjectedScriptRef.current = cssInjectionScript;
163
+ }, [cssInjectionScript, isWebWorldReady, webView]);
164
+ };
18
165
  //# sourceMappingURL=MapProvider.hooks.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["StyleSheet","useMemo","useStyles","create","container","width","height","overflow","webview","flex","backgroundColor"],"sourceRoot":"../../../../../src","sources":["react-native/components/MapProvider/MapProvider.hooks.ts"],"mappings":";;AAAA,SAASA,UAAU,QAAQ,cAAc;AACzC,SAASC,OAAO,QAAQ,OAAO;AAE/B,OAAO,MAAMC,SAAS,GAAGA,CAAA,KAAM;EAC7B,OAAOD,OAAO,CACZ,MACED,UAAU,CAACG,MAAM,CAAC;IAChBC,SAAS,EAAE;MAAEC,KAAK,EAAE,MAAM;MAAEC,MAAM,EAAE,MAAM;MAAEC,QAAQ,EAAE;IAAS,CAAC;IAChEC,OAAO,EAAE;MAAEC,IAAI,EAAE,CAAC;MAAEC,eAAe,EAAE;IAAc;EACrD,CAAC,CAAC,EACJ,EACF,CAAC;AACH,CAAC","ignoreList":[]}
1
+ {"version":3,"names":["StyleSheet","useCallback","useEffect","useMemo","useRef","RNLogger","isWebObjectListenerOnHTMLElement","isWebObjectListenerOnMapLayer","isWebObjectListenerOnObject","isWebObjectListenerOnRN","useMapAtoms","buildCssInjectionScript","normalizeCss","useStyles","create","container","width","height","overflow","webView","flex","backgroundColor","useFlushMessagesOnMapMounted","isMapMountMessageReady","flushMessages","useWebMessageHandler","setIsWebWorldReady","getWebObjectListeners","resolveWebObjectPendingMethodResponse","createWebViewMessageHandler","handlers","handleMessage","event","debug","name","nativeEvent","data","message","JSON","parse","handler","type","error","console","payload","args","level","slice","ready","webObjectListenerEvent","eventName","objectId","listener","rnListener","objectListener","layerListener","elementListener","webObjectMethodResponse","requestId","result","useCssInjectionScript","injectedCss","cssInjectionScript","normalizedCss","undefined","useInjectJavaScriptIfInjectedCssChanged","lastInjectedScriptRef","isWebWorldReady","current","injectJavaScript"],"sourceRoot":"../../../../../src","sources":["react-native/components/MapProvider/MapProvider.hooks.ts"],"mappings":";;AAAA,SAASA,UAAU,QAAQ,cAAc;AACzC,SAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,QAAQ,OAAO;AAG/D,OAAOC,QAAQ,MAAM,2BAAwB;AAE7C,SACEC,gCAAgC,EAChCC,6BAA6B,EAC7BC,2BAA2B,EAC3BC,uBAAuB,QAClB,0CAAuC;AAC9C,OAAOC,WAAW,MAAM,kCAA+B;AAOvD,SAASC,uBAAuB,EAAEC,YAAY,QAAQ,wBAAqB;AAE3E,OAAO,MAAMC,SAAS,GAAGA,CAAA,KAAM;EAC7B,OAAOV,OAAO,CACZ,MACEH,UAAU,CAACc,MAAM,CAAC;IAChBC,SAAS,EAAE;MAAEC,KAAK,EAAE,MAAM;MAAEC,MAAM,EAAE,MAAM;MAAEC,QAAQ,EAAE;IAAS,CAAC;IAChEC,OAAO,EAAE;MAAEC,IAAI,EAAE,CAAC;MAAEC,eAAe,EAAE;IAAc;EACrD,CAAC,CAAC,EACJ,EACF,CAAC;AACH,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA,O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B,IAAK;EACxE,MAAMC,kBAAkB,GAAG3D,OAAO,CAAC,MAAM;IACvC,MAAM4D,aAAa,GAAGnD,YAAY,CAACiD,WAAW,CAAC;IAC/C,OAAOE,aAAa,GAAGpD,uBAAuB,CAACoD,aAAa,CAAC,GAAGC,SAAS;EAC3E,CAAC,EAAE,CAACH,WAAW,CAAC,CAAC;EACjB,OAAO;IAAEC;EAAmB,CAAC;AAC/B,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMG,uCAAuC,GAClDH,kBAA2B,IACxB;EACH;EACA,MAAMI,qBAAqB,GAAG9D,MAAM,CAAS4D,SAAS,CAAC;EACvD;EACA;EACA,MAAM;IAAE7C,OAAO;IAAEgD;EAAgB,CAAC,GAAGzD,WAAW,CAAC,CAAC;EAElDR,SAAS,CAAC,MAAM;IACd,IACE,CAAC4D,kBAAkB,IACnB,CAACK,eAAe,IAChB,CAAChD,OAAO,IACR+C,qBAAqB,CAACE,OAAO,KAAKN,kBAAkB,EACpD;MACA;IACF;IACA3C,OAAO,EAAEkD,gBAAgB,CAACP,kBAAkB,CAAC;IAC7CI,qBAAqB,CAACE,OAAO,GAAGN,kBAAkB;EACpD,CAAC,EAAE,CAACA,kBAAkB,EAAEK,eAAe,EAAEhD,OAAO,CAAC,CAAC;AACpD,CAAC","ignoreList":[]}
@@ -3,114 +3,60 @@
3
3
  import { View } from 'react-native';
4
4
  import { WebView } from 'react-native-webview';
5
5
  import { WEBVIEW_STATIC_HTML } from "../../../web/generated/webview_static_html.js";
6
- import RNLogger from "../../logger/rn-logger.js";
7
6
  import useMapAtoms from "../../hooks/atoms/useMapAtoms.js";
8
- import { isWebObjectListenerOnHTMLElement, isWebObjectListenerOnMapLayer, isWebObjectListenerOnObject, isWebObjectListenerOnRN } from "../../../communication/messages.utils.js";
9
- import { useStyles } from "./MapProvider.hooks.js";
10
- import { useCallback, useEffect } from 'react';
7
+ import { useFlushMessagesOnMapMounted, useCssInjectionScript, useInjectJavaScriptIfInjectedCssChanged, useStyles, useWebMessageHandler } from "./MapProvider.hooks.js";
11
8
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
12
9
  /**
13
- * Provide the main
10
+ * Must be used as a parent component to allow instantiation of map elements.
11
+ * Every child must be a direct component.
12
+ * This is the bridge to the web world / the `MapLibre GL JS` library.
14
13
  * @param props -
15
14
  * @group Components
15
+ * @example
16
+ * ```tsx
17
+ * <MapProvider>
18
+ * <Map/>
19
+ * <Marker/>
20
+ * ...
21
+ * </MapProvider>
22
+ * ```
16
23
  */
17
24
  const MapProvider = ({
18
- children
25
+ style,
26
+ webViewStyle,
27
+ children,
28
+ injectedCss
19
29
  }) => {
20
30
  // States.
21
31
  // - Global.
22
32
  const {
23
- setWebView,
24
- setIsWebWorldReady,
25
- isMapMountMessageReady,
26
- flushMessages,
27
- getWebObjectListeners,
28
- resolveWebObjectPendingMethodResponse
33
+ setWebView
29
34
  } = useMapAtoms();
30
35
  // Theme.
31
36
  const styles = useStyles();
32
-
33
- // On start, the map must be mounted before any other map element. When the
34
- // mount message of the map is ready, we flush all the pending messages to
35
- // the web world.
36
- useEffect(() => {
37
- if (isMapMountMessageReady) {
38
- flushMessages();
39
- }
40
- }, [flushMessages, isMapMountMessageReady]);
41
-
42
- // Handler of messages from the web world.
43
- const onMessage = useCallback(
44
- // Not an anonymous function => get the function name for logger.
45
- function handleMessage(event) {
46
- try {
47
- RNLogger.debug('RN', handleMessage.name, event?.nativeEvent?.data);
48
- const message = JSON.parse(event.nativeEvent.data);
49
- switch (message.type) {
50
- case 'console':
51
- {
52
- RNLogger[message.payload.level]('Web', message.payload.args[0], ...message.payload.args.slice(1));
53
- break;
54
- }
55
- case 'ready':
56
- {
57
- setIsWebWorldReady(true);
58
- break;
59
- }
60
- case 'webObjectListenerEvent':
61
- {
62
- // Retrieve the corresponding object listener.
63
- const listener = getWebObjectListeners({
64
- objectId: message.payload.objectId
65
- })?.[message.payload.eventName];
66
- // Then, call it.
67
- if (isWebObjectListenerOnRN(listener)) {
68
- ;
69
- listener.rnListener(message.payload.event);
70
- }
71
- if (isWebObjectListenerOnObject(listener)) {
72
- ;
73
- listener.objectListener(message.payload.event);
74
- }
75
- if (isWebObjectListenerOnMapLayer(listener)) {
76
- ;
77
- listener.layerListener(message.payload.event);
78
- }
79
- if (isWebObjectListenerOnHTMLElement(listener)) {
80
- ;
81
- listener.elementListener(message.payload.event);
82
- }
83
- break;
84
- }
85
- case 'webObjectMethodResponse':
86
- {
87
- resolveWebObjectPendingMethodResponse({
88
- requestId: message.payload.requestId,
89
- result: message.payload.result
90
- });
91
- break;
92
- }
93
- }
94
- } catch (error) {
95
- RNLogger.error('RN', handleMessage.name, error.message);
96
- }
97
- }, [setIsWebWorldReady, getWebObjectListeners, resolveWebObjectPendingMethodResponse]);
37
+ // Behaviors.
38
+ useFlushMessagesOnMapMounted();
39
+ const {
40
+ handler
41
+ } = useWebMessageHandler();
42
+ const {
43
+ cssInjectionScript
44
+ } = useCssInjectionScript(injectedCss);
45
+ useInjectJavaScriptIfInjectedCssChanged(cssInjectionScript);
98
46
  return /*#__PURE__*/_jsxs(View, {
99
- style: styles.container,
47
+ style: [styles.container, style],
100
48
  children: [/*#__PURE__*/_jsx(WebView, {
49
+ testID: 'map-provider-webview',
101
50
  ref: setWebView,
102
- style: styles.webview,
103
- originWhitelist: ['*'],
51
+ style: [styles.webView, webViewStyle],
52
+ scrollEnabled: false,
104
53
  javaScriptEnabled: true,
105
- allowFileAccess: true,
106
54
  domStorageEnabled: true,
107
- scrollEnabled: false,
108
- allowUniversalAccessFromFileURLs: true,
109
- mixedContentMode: 'always',
110
- onMessage: onMessage,
55
+ onMessage: handler,
111
56
  source: {
112
57
  html: WEBVIEW_STATIC_HTML
113
- }
58
+ },
59
+ injectedJavaScriptBeforeContentLoaded: cssInjectionScript
114
60
  }), children]
115
61
  });
116
62
  };
@@ -1 +1 @@
1
- {"version":3,"names":["View","WebView","WEBVIEW_STATIC_HTML","RNLogger","useMapAtoms","isWebObjectListenerOnHTMLElement","isWebObjectListenerOnMapLayer","isWebObjectListenerOnObject","isWebObjectListenerOnRN","useStyles","useCallback","useEffect","jsx","_jsx","jsxs","_jsxs","MapProvider","children","setWebView","setIsWebWorldReady","isMapMountMessageReady","flushMessages","getWebObjectListeners","resolveWebObjectPendingMethodResponse","styles","onMessage","handleMessage","event","debug","name","nativeEvent","data","message","JSON","parse","type","payload","level","args","slice","listener","objectId","eventName","rnListener","objectListener","layerListener","elementListener","requestId","result","error","style","container","ref","webview","originWhitelist","javaScriptEnabled","allowFileAccess","domStorageEnabled","scrollEnabled","allowUniversalAccessFromFileURLs","mixedContentMode","source","html"],"sourceRoot":"../../../../../src","sources":["react-native/components/MapProvider/MapProvider.tsx"],"mappings":";;AAAA,SAASA,IAAI,QAAQ,cAAc;AACnC,SAASC,OAAO,QAAkC,sBAAsB;AACxE,SAASC,mBAAmB,QAAQ,+CAA4C;AAEhF,OAAOC,QAAQ,MAAM,2BAAwB;AAC7C,OAAOC,WAAW,MAAM,kCAA+B;AACvD,SACEC,gCAAgC,EAChCC,6BAA6B,EAC7BC,2BAA2B,EAC3BC,uBAAuB,QAClB,0CAAuC;AAC9C,SAASC,SAAS,QAAQ,wBAAqB;AAC/C,SAASC,WAAW,EAAEC,SAAS,QAAQ,OAAO;AAAA,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAS9C;AACA;AACA;AACA;AACA;AACA,MAAMC,WAAW,GAAGA,CAAC;EAAEC;AAA2B,CAAC,KAAK;EACtD;EACA;EACA,MAAM;IACJC,UAAU;IACVC,kBAAkB;IAClBC,sBAAsB;IACtBC,aAAa;IACbC,qBAAqB;IACrBC;EACF,CAAC,GAAGnB,WAAW,CAAC,CAAC;EACjB;EACA,MAAMoB,MAAM,GAAGf,SAAS,CAAC,CAAC;;EAE1B;EACA;EACA;EACAE,SAAS,CAAC,MAAM;IACd,IAAIS,sBAAsB,EAAE;MAC1BC,aAAa,CAAC,CAAC;IACj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CAC3Db,OAAO,CAACI,OAAO,CAACT,KAClB,CAAC;YACH;YACA,IAAItB,gCAAgC,CAACmC,QAAQ,CAAC,EAAE;cAC9C;cACEA,QAAQ,CACRM,eAAe,CAACd,OAAO,CAACI,OAAO,CAACT,KAAK,CAAC;YAC1C;YACA;UACF;QACA,KAAK,yBAAyB;UAAE;YAC9BJ,qCAAqC,CAAC;cACpCwB,SAAS,EAAEf,OAAO,CAACI,OAAO,CAACW,SAAS;cACpCC,MAAM,EAAEhB,OAAO,CAACI,OAAO,CAACY;YAC1B,CAAC,CAAC;YACF;UACF;MACF;IACF,CAAC,CAAC,OAAOC,KAAU,EAAE;MACnB9C,QAAQ,CAAC8C,KAAK,CAAC,IAAI,EAAEvB,aAAa,CAACG,IAAI,EAAEoB,KAAK,CAACjB,OAAO,CAAC;IACzD;EACF,CAAC,EACD,CACEb,kBAAkB,EAClBG,qBAAqB,EACrBC,qCAAqC,CAEzC,CAAC;EAED,oBACER,KAAA,CAACf,IAAI;IAACkD,KAAK,EAAE1B,MAAM,CAAC2B,SAAU;IAAAlC,QAAA,gBAC5BJ,IAAA,CAACZ,OAAO;MACNmD,GAAG,EAAElC,UAAW;MAChBgC,KAAK,EAAE1B,MAAM,CAAC6B,OAAQ;MACtBC,eAAe,EAAE,CAAC,GAAG,CAAE;MACvBC,iBAAiB,EAAE,IAAK;MACxBC,eAAe,EAAE,IAAK;MACtBC,iBAAiB,EAAE,IAAK;MACxBC,aAAa,EAAE,KAAM;MACrBC,gCAAgC,EAAE,IAAK;MACvCC,gBAAgB,EAAE,QAAS;MAC3BnC,SAAS,EAAEA,SAAU;MACrBoC,MAAM,EAAE;QAAEC,IAAI,EAAE5D;MAAoB;IAAE,CACvC,CAAC,EACDe,QAAQ;EAAA,CACL,CAAC;AAEX,CAAC;AAED,eAAeD,WAAW","ignoreList":[]}
1
+ {"version":3,"names":["View","WebView","WEBVIEW_STATIC_HTML","useMapAtoms","useFlushMessagesOnMapMounted","useCssInjectionScript","useInjectJavaScriptIfInjectedCssChanged","useStyles","useWebMessageHandler","jsx","_jsx","jsxs","_jsxs","MapProvider","style","webViewStyle","children","injectedCss","setWebView","styles","handler","cssInjectionScript","container","testID","ref","webView","scrollEnabled","javaScriptEnabled","domStorageEnabled","onMessage","source","html","injectedJavaScriptBeforeContentLoaded"],"sourceRoot":"../../../../../src","sources":["react-native/components/MapProvider/MapProvider.tsx"],"mappings":";;AAAA,SAASA,IAAI,QAAQ,cAAc;AACnC,SAASC,OAAO,QAAQ,sBAAsB;AAC9C,SAASC,mBAAmB,QAAQ,+CAA4C;AAChF,OAAOC,WAAW,MAAM,kCAA+B;AACvD,SACEC,4BAA4B,EAC5BC,qBAAqB,EACrBC,uCAAuC,EACvCC,SAAS,EACTC,oBAAoB,QACf,wBAAqB;AAAA,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAG5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,WAAW,GAAGA,CAAC;EACnBC,KAAK;EACLC,YAAY;EACZC,QAAQ;EACRC;AACgB,CAAC,KAAK;EACtB;EACA;EACA,MAAM;IAAEC;EAAW,CAAC,GAAGf,WAAW,CAAC,CAAC;EACpC;EACA,MAAMgB,MAAM,GAAGZ,SAAS,CAAC,CAAC;EAC1B;EACAH,4BAA4B,CAAC,CAAC;EAC9B,MAAM;IAAEgB;EAAQ,CAAC,GAAGZ,oBAAoB,CAAC,CAAC;EAC1C,MAAM;IAAEa;EAAmB,CAAC,GAAGhB,qBAAqB,CAACY,WAAW,CAAC;EACjEX,uCAAuC,CAACe,kBAAkB,CAAC;EAE3D,oBACET,KAAA,CAACZ,IAAI;IAACc,KAAK,EAAE,CAACK,MAAM,CAACG,SAAS,EAAER,KAAK,CAAE;IAAAE,QAAA,gBACrCN,IAAA,CAACT,OAAO;MACNsB,MAAM,EAAE,sBAAuB;MAC/BC,GAAG,EAAEN,UAAW;MAChBJ,KA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