@guardian/interactive-component-library 0.2.0-rc1 → 0.2.0-rc3

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 (276) hide show
  1. package/dist/components/index.d.ts +3 -0
  2. package/dist/components/molecules/canvas-map/Map.d.ts +17 -0
  3. package/dist/components/molecules/canvas-map/Map.js +89 -0
  4. package/dist/components/molecules/canvas-map/context/MapContext.d.ts +19 -0
  5. package/dist/components/molecules/canvas-map/context/MapContext.js +20 -0
  6. package/dist/components/molecules/canvas-map/controls/ZoomControl.d.ts +6 -0
  7. package/dist/components/molecules/canvas-map/controls/ZoomControl.js +40 -0
  8. package/dist/components/molecules/canvas-map/controls/icons/index.d.ts +3 -0
  9. package/dist/components/molecules/canvas-map/controls/icons/minus.d.ts +1 -0
  10. package/dist/components/molecules/canvas-map/controls/icons/minus.js +25 -0
  11. package/dist/components/molecules/canvas-map/controls/icons/plus.d.ts +1 -0
  12. package/dist/components/molecules/canvas-map/controls/icons/plus.js +25 -0
  13. package/dist/components/molecules/canvas-map/controls/icons/reset.d.ts +3 -0
  14. package/dist/components/molecules/canvas-map/controls/icons/reset.js +25 -0
  15. package/dist/components/molecules/canvas-map/controls/index.d.ts +1 -0
  16. package/dist/components/molecules/canvas-map/controls/style.module.css.js +11 -0
  17. package/dist/components/molecules/canvas-map/index.d.ts +12 -0
  18. package/dist/components/molecules/canvas-map/lib/Feature.d.ts +38 -0
  19. package/dist/components/molecules/canvas-map/lib/Feature.js +104 -0
  20. package/dist/components/molecules/canvas-map/lib/FeatureCollection.d.ts +20 -0
  21. package/dist/components/molecules/canvas-map/lib/FeatureCollection.js +23 -0
  22. package/dist/components/molecules/canvas-map/lib/Map.d.ts +69 -0
  23. package/dist/components/molecules/canvas-map/lib/Map.js +254 -0
  24. package/dist/components/molecules/canvas-map/lib/View.d.ts +136 -0
  25. package/dist/components/molecules/canvas-map/lib/View.js +179 -0
  26. package/dist/components/molecules/canvas-map/lib/events/Dispatcher.d.ts +8 -0
  27. package/dist/components/molecules/canvas-map/lib/events/Dispatcher.js +35 -0
  28. package/dist/components/molecules/canvas-map/lib/events/MapEvent.d.ts +6 -0
  29. package/dist/components/molecules/canvas-map/lib/events/MapEvent.js +9 -0
  30. package/dist/components/molecules/canvas-map/lib/events/index.d.ts +2 -0
  31. package/dist/components/molecules/canvas-map/lib/formats/GeoJSON.d.ts +10 -0
  32. package/dist/components/molecules/canvas-map/lib/formats/GeoJSON.js +96 -0
  33. package/dist/components/molecules/canvas-map/lib/geometry/Geometry.d.ts +32 -0
  34. package/dist/components/molecules/canvas-map/lib/geometry/Geometry.js +41 -0
  35. package/dist/components/molecules/canvas-map/lib/geometry/LineString.d.ts +12 -0
  36. package/dist/components/molecules/canvas-map/lib/geometry/LineString.js +19 -0
  37. package/dist/components/molecules/canvas-map/lib/geometry/Point.d.ts +11 -0
  38. package/dist/components/molecules/canvas-map/lib/geometry/Point.js +16 -0
  39. package/dist/components/molecules/canvas-map/lib/geometry/Polygon.d.ts +16 -0
  40. package/dist/components/molecules/canvas-map/lib/geometry/Polygon.js +46 -0
  41. package/dist/components/molecules/canvas-map/lib/geometry/index.d.ts +4 -0
  42. package/dist/components/molecules/canvas-map/lib/interpolators/index.d.ts +2 -0
  43. package/dist/components/molecules/canvas-map/lib/interpolators/interpolateFeatures.d.ts +5 -0
  44. package/dist/components/molecules/canvas-map/lib/interpolators/interpolateFeatures.js +95 -0
  45. package/dist/components/molecules/canvas-map/lib/interpolators/interpolateStyles.d.ts +4 -0
  46. package/dist/components/molecules/canvas-map/lib/interpolators/interpolateStyles.js +65 -0
  47. package/dist/components/molecules/canvas-map/lib/layers/TextLayer.d.ts +52 -0
  48. package/dist/components/molecules/canvas-map/lib/layers/TextLayer.js +111 -0
  49. package/dist/components/molecules/canvas-map/lib/layers/VectorLayer.d.ts +53 -0
  50. package/dist/components/molecules/canvas-map/lib/layers/VectorLayer.js +132 -0
  51. package/dist/components/molecules/canvas-map/lib/layers/index.d.ts +3 -0
  52. package/dist/components/molecules/canvas-map/lib/projection/index.d.ts +22 -0
  53. package/dist/components/molecules/canvas-map/lib/projection/index.js +12 -0
  54. package/dist/components/molecules/canvas-map/lib/renderers/FeatureRenderer.d.ts +6 -0
  55. package/dist/components/molecules/canvas-map/lib/renderers/FeatureRenderer.js +46 -0
  56. package/dist/components/molecules/canvas-map/lib/renderers/MapRenderer.d.ts +6 -0
  57. package/dist/components/molecules/canvas-map/lib/renderers/MapRenderer.js +53 -0
  58. package/dist/components/molecules/canvas-map/lib/renderers/TextLayerRenderer.d.ts +17 -0
  59. package/dist/components/molecules/canvas-map/lib/renderers/TextLayerRenderer.js +119 -0
  60. package/dist/components/molecules/canvas-map/lib/renderers/VectorLayerRenderer.d.ts +10 -0
  61. package/dist/components/molecules/canvas-map/lib/renderers/VectorLayerRenderer.js +78 -0
  62. package/dist/components/molecules/canvas-map/lib/sources/VectorSource.d.ts +15 -0
  63. package/dist/components/molecules/canvas-map/lib/sources/VectorSource.js +56 -0
  64. package/dist/components/molecules/canvas-map/lib/styles/Fill.d.ts +7 -0
  65. package/dist/components/molecules/canvas-map/lib/styles/Fill.js +15 -0
  66. package/dist/components/molecules/canvas-map/lib/styles/Stroke.d.ts +8 -0
  67. package/dist/components/molecules/canvas-map/lib/styles/Stroke.js +16 -0
  68. package/dist/components/molecules/canvas-map/lib/styles/Style.d.ts +24 -0
  69. package/dist/components/molecules/canvas-map/lib/styles/Style.js +17 -0
  70. package/dist/components/molecules/canvas-map/lib/styles/Text.d.ts +10 -0
  71. package/dist/components/molecules/canvas-map/lib/styles/Text.js +14 -0
  72. package/dist/components/molecules/canvas-map/lib/styles/index.d.ts +4 -0
  73. package/dist/components/molecules/canvas-map/lib/util/array.d.ts +6 -0
  74. package/dist/components/molecules/canvas-map/lib/util/array.js +15 -0
  75. package/dist/components/molecules/canvas-map/lib/util/bboxFeature.d.ts +8 -0
  76. package/dist/components/molecules/canvas-map/lib/util/bboxFeature.js +26 -0
  77. package/dist/components/molecules/canvas-map/lib/util/debug.d.ts +11 -0
  78. package/dist/components/molecules/canvas-map/lib/util/debug.js +27 -0
  79. package/dist/components/molecules/canvas-map/lib/util/deflate.d.ts +36 -0
  80. package/dist/components/molecules/canvas-map/lib/util/distance.d.ts +1 -0
  81. package/dist/components/molecules/canvas-map/lib/util/distance.js +12 -0
  82. package/dist/components/molecules/canvas-map/lib/util/dom.d.ts +9 -0
  83. package/dist/components/molecules/canvas-map/lib/util/dom.js +28 -0
  84. package/dist/components/molecules/canvas-map/lib/util/extent.d.ts +21 -0
  85. package/dist/components/molecules/canvas-map/lib/util/extent.js +38 -0
  86. package/dist/components/molecules/canvas-map/lib/util/memoise.d.ts +10 -0
  87. package/dist/components/molecules/canvas-map/lib/util/memoise.js +20 -0
  88. package/dist/components/molecules/canvas-map/lib/util/resolution.d.ts +9 -0
  89. package/dist/components/molecules/canvas-map/lib/util/resolution.js +11 -0
  90. package/dist/components/molecules/canvas-map/lib/util/simplify.d.ts +114 -0
  91. package/dist/components/molecules/canvas-map/lib/util/size.d.ts +32 -0
  92. package/dist/components/molecules/canvas-map/lib/util/size.js +53 -0
  93. package/dist/components/molecules/canvas-map/lib/util/toRgba.d.ts +1 -0
  94. package/dist/components/molecules/canvas-map/lib/util/toRgba.js +25 -0
  95. package/dist/components/molecules/canvas-map/lib/util/uid.d.ts +5 -0
  96. package/dist/components/molecules/canvas-map/lib/util/uid.js +7 -0
  97. package/dist/components/molecules/canvas-map/lib/util/zoomLevel.d.ts +2 -0
  98. package/dist/components/molecules/canvas-map/lib/util/zoomLevel.js +14 -0
  99. package/dist/components/molecules/canvas-map/style.module.scss.js +20 -0
  100. package/dist/components/molecules/column-chart/column-chart-example.d.ts +35 -0
  101. package/dist/components/molecules/column-chart/column-chart-util.d.ts +1 -0
  102. package/dist/components/molecules/column-chart/index.d.ts +11 -0
  103. package/dist/components/molecules/column-chart/index.js +63 -0
  104. package/dist/components/molecules/column-chart/style.module.css.js +14 -0
  105. package/dist/components/molecules/control-change/index.d.ts +6 -0
  106. package/dist/components/molecules/control-change/index.js +29 -0
  107. package/dist/components/molecules/control-change/style.module.css.js +11 -0
  108. package/dist/components/molecules/dropdown/index.d.ts +11 -0
  109. package/dist/components/molecules/dropdown/index.js +191 -0
  110. package/dist/components/molecules/dropdown/style.module.css.js +50 -0
  111. package/dist/components/molecules/first-past-the-post-waffle/index.d.ts +5 -0
  112. package/dist/components/molecules/first-past-the-post-waffle/index.js +14 -0
  113. package/dist/components/molecules/first-past-the-post-waffle/style.module.css.js +14 -0
  114. package/dist/components/molecules/index.d.ts +17 -0
  115. package/dist/components/molecules/modal/index.d.ts +8 -0
  116. package/dist/components/molecules/modal/index.js +59 -0
  117. package/dist/components/molecules/modal/style.module.css.js +26 -0
  118. package/dist/components/molecules/page-section/index.d.ts +8 -0
  119. package/dist/components/molecules/page-section/index.js +52 -0
  120. package/dist/components/molecules/page-section/style.module.scss.js +20 -0
  121. package/dist/components/molecules/party-profile/index.d.ts +10 -0
  122. package/dist/components/molecules/party-profile/index.js +29 -0
  123. package/dist/components/molecules/party-profile/style.module.css.js +26 -0
  124. package/dist/components/molecules/refresh-indicator/index.d.ts +4 -0
  125. package/dist/components/molecules/refresh-indicator/index.js +18 -0
  126. package/dist/components/molecules/refresh-indicator/style.module.scss.js +17 -0
  127. package/dist/components/molecules/responsive-grid/index.d.ts +10 -0
  128. package/dist/components/molecules/responsive-grid/index.js +19 -0
  129. package/dist/components/molecules/responsive-grid/style.module.scss.js +8 -0
  130. package/dist/components/molecules/result-summary/index.d.ts +8 -0
  131. package/dist/components/molecules/result-summary/index.js +38 -0
  132. package/dist/components/molecules/result-summary/style.module.css.js +11 -0
  133. package/dist/components/molecules/search-input/icons/search.d.ts +1 -0
  134. package/dist/components/molecules/search-input/icons/search.js +24 -0
  135. package/dist/components/molecules/search-input/icons/search.module.css.js +11 -0
  136. package/dist/components/molecules/search-input/index.d.ts +11 -0
  137. package/dist/components/molecules/search-input/index.js +164 -0
  138. package/dist/components/molecules/search-input/style.module.css.js +32 -0
  139. package/dist/components/molecules/slope-chart/index.d.ts +16 -0
  140. package/dist/components/molecules/slope-chart/index.js +139 -0
  141. package/dist/components/molecules/slope-chart/style.module.css.js +35 -0
  142. package/dist/components/molecules/svg-map/context/MapContext.d.ts +1 -0
  143. package/dist/components/molecules/svg-map/context/MapContext.js +5 -0
  144. package/dist/components/molecules/svg-map/context/SVGMapProvider.d.ts +10 -0
  145. package/dist/components/molecules/svg-map/context/SVGMapProvider.js +88 -0
  146. package/dist/components/molecules/svg-map/helpers/bboxFeature.d.ts +8 -0
  147. package/dist/components/molecules/svg-map/helpers/bboxFeature.js +26 -0
  148. package/dist/components/molecules/svg-map/helpers/dynamicPropValue.d.ts +1 -0
  149. package/dist/components/molecules/svg-map/helpers/dynamicPropValue.js +9 -0
  150. package/dist/components/molecules/svg-map/helpers/geoMath.d.ts +4 -0
  151. package/dist/components/molecules/svg-map/helpers/saveSVG.d.ts +1 -0
  152. package/dist/components/molecules/svg-map/hooks/useCamera.d.ts +0 -0
  153. package/dist/components/molecules/svg-map/hooks/useThrowIfNonLayerChildren.d.ts +4 -0
  154. package/dist/components/molecules/svg-map/hooks/useThrowIfNonLayerChildren.js +19 -0
  155. package/dist/components/molecules/svg-map/index.d.ts +38 -0
  156. package/dist/components/molecules/svg-map/index.js +121 -0
  157. package/dist/components/molecules/svg-map/layers/CompositionBorders.d.ts +3 -0
  158. package/dist/components/molecules/svg-map/layers/CompositionBorders.js +14 -0
  159. package/dist/components/molecules/svg-map/layers/Line.d.ts +7 -0
  160. package/dist/components/molecules/svg-map/layers/Line.js +48 -0
  161. package/dist/components/molecules/svg-map/layers/Point.d.ts +10 -0
  162. package/dist/components/molecules/svg-map/layers/Point.js +59 -0
  163. package/dist/components/molecules/svg-map/layers/Polygon.d.ts +9 -0
  164. package/dist/components/molecules/svg-map/layers/Polygon.js +75 -0
  165. package/dist/components/molecules/svg-map/layers/Prerendered.d.ts +3 -0
  166. package/dist/components/molecules/svg-map/layers/Prerendered.js +11 -0
  167. package/dist/components/molecules/svg-map/layers/compositionBorders.module.scss.js +8 -0
  168. package/dist/components/molecules/svg-map/layers/index.d.ts +5 -0
  169. package/dist/components/molecules/svg-map/layers/index.js +12 -0
  170. package/dist/components/molecules/svg-map/renderers/SVGRenderer.d.ts +3 -0
  171. package/dist/components/molecules/svg-map/renderers/SVGRenderer.js +32 -0
  172. package/dist/components/molecules/svg-map/style.module.css.js +11 -0
  173. package/dist/components/molecules/table/index.d.ts +7 -0
  174. package/dist/components/molecules/table/index.js +90 -0
  175. package/dist/components/molecules/table/style.module.scss.js +29 -0
  176. package/dist/components/molecules/table/useTable.d.ts +8 -0
  177. package/dist/components/molecules/table/useTable.js +128 -0
  178. package/dist/components/molecules/tooltip/index.d.ts +82 -0
  179. package/dist/components/molecules/tooltip/index.js +117 -0
  180. package/dist/components/molecules/tooltip/style.module.css.js +8 -0
  181. package/dist/components/molecules/topline-result/index.d.ts +3 -0
  182. package/dist/components/molecules/topline-result/index.js +61 -0
  183. package/dist/components/molecules/topline-result/style.module.scss.js +38 -0
  184. package/dist/components/organisms/coalitions-tracker/index.d.ts +16 -0
  185. package/dist/components/organisms/coalitions-tracker/index.js +151 -0
  186. package/dist/components/organisms/coalitions-tracker/style.module.scss.js +32 -0
  187. package/dist/components/organisms/index.d.ts +2 -0
  188. package/dist/components/organisms/ticker/gradient/index.d.ts +1 -0
  189. package/dist/components/organisms/ticker/gradient/index.js +35 -0
  190. package/dist/components/organisms/ticker/gradient/style.module.scss.js +14 -0
  191. package/dist/components/organisms/ticker/index.d.ts +5 -0
  192. package/dist/components/organisms/ticker/index.js +102 -0
  193. package/dist/components/organisms/ticker/style.module.scss.js +32 -0
  194. package/dist/components/particles/ad-slot/index.d.ts +40 -0
  195. package/dist/components/particles/ad-slot/index.js +34 -0
  196. package/dist/components/particles/ad-slot/style.module.css.js +11 -0
  197. package/dist/components/particles/arrow-button/index.d.ts +6 -0
  198. package/dist/components/particles/arrow-button/index.js +32 -0
  199. package/dist/components/particles/arrow-button/style.module.css.js +11 -0
  200. package/dist/components/particles/aspect-ratio-box/index.d.ts +4 -0
  201. package/dist/components/particles/aspect-ratio-box/index.js +15 -0
  202. package/dist/components/particles/aspect-ratio-box/style.module.css.js +6 -0
  203. package/dist/components/particles/button/index.d.ts +6 -0
  204. package/dist/components/particles/button/index.js +10 -0
  205. package/dist/components/particles/button/style.module.css.js +11 -0
  206. package/dist/components/particles/change-bar/index.d.ts +8 -0
  207. package/dist/components/particles/change-bar/index.js +27 -0
  208. package/dist/components/particles/change-bar/style.module.scss.js +14 -0
  209. package/dist/components/particles/chevron/index.d.ts +6 -0
  210. package/dist/components/particles/chevron/index.js +78 -0
  211. package/dist/components/particles/chevron/style.module.css.js +20 -0
  212. package/dist/components/particles/circle-icon/index.d.ts +6 -0
  213. package/dist/components/particles/circle-icon/index.js +32 -0
  214. package/dist/components/particles/circle-icon/style.module.css.js +14 -0
  215. package/dist/components/particles/close-button/index.d.ts +5 -0
  216. package/dist/components/particles/close-button/index.js +35 -0
  217. package/dist/components/particles/close-button/style.module.css.js +17 -0
  218. package/dist/components/particles/container/index.d.ts +5 -0
  219. package/dist/components/particles/container/index.js +13 -0
  220. package/dist/components/particles/container/style.module.scss.js +11 -0
  221. package/dist/components/particles/gradient-icon/index.d.ts +1 -0
  222. package/dist/components/particles/gradient-icon/index.js +46 -0
  223. package/dist/components/particles/gradient-icon/style.module.css.js +14 -0
  224. package/dist/components/particles/index.d.ts +18 -0
  225. package/dist/components/particles/info-button/index.d.ts +3 -0
  226. package/dist/components/particles/info-button/index.js +19 -0
  227. package/dist/components/particles/info-button/style.module.css.js +11 -0
  228. package/dist/components/particles/legend-item/index.d.ts +6 -0
  229. package/dist/components/particles/legend-item/index.js +26 -0
  230. package/dist/components/particles/legend-item/style.module.css.js +17 -0
  231. package/dist/components/particles/relative-time-sentence/index.d.ts +4 -0
  232. package/dist/components/particles/relative-time-sentence/index.js +14 -0
  233. package/dist/components/particles/relative-time-sentence/style.module.css.js +8 -0
  234. package/dist/components/particles/square-cut-corner-icon/index.d.ts +6 -0
  235. package/dist/components/particles/square-cut-corner-icon/index.js +56 -0
  236. package/dist/components/particles/square-cut-corner-icon/style.module.scss.js +17 -0
  237. package/dist/components/particles/square-icon/index.d.ts +5 -0
  238. package/dist/components/particles/square-icon/index.js +28 -0
  239. package/dist/components/particles/square-icon/style.module.scss.js +11 -0
  240. package/dist/components/particles/stacked-bar/index.d.ts +23 -0
  241. package/dist/components/particles/stacked-bar/index.js +140 -0
  242. package/dist/components/particles/stacked-bar/style.module.css.js +17 -0
  243. package/dist/components/particles/stacked-grid/index.d.ts +6 -0
  244. package/dist/components/particles/stacked-grid/index.js +35 -0
  245. package/dist/components/particles/stacked-grid/style.module.css.js +20 -0
  246. package/dist/components/particles/waffle/index.d.ts +14 -0
  247. package/dist/components/particles/waffle/index.js +76 -0
  248. package/dist/components/particles/waffle/style.module.css.js +11 -0
  249. package/dist/index.d.ts +2 -0
  250. package/dist/index.js +128 -0
  251. package/dist/shared/colors/index.d.ts +2 -0
  252. package/dist/shared/helpers/createStore.d.ts +1 -0
  253. package/dist/shared/helpers/geometry.d.ts +3 -0
  254. package/dist/shared/helpers/geometry.js +16 -0
  255. package/dist/shared/helpers/geometry.test.d.ts +1 -0
  256. package/dist/shared/helpers/labelsUtil.d.ts +54 -0
  257. package/dist/shared/helpers/labelsUtil.js +58 -0
  258. package/dist/shared/helpers/labelsUtils.test.d.ts +1 -0
  259. package/dist/shared/helpers/shouldUpdate.d.ts +7 -0
  260. package/dist/shared/hooks/index.d.ts +3 -0
  261. package/dist/shared/hooks/useContainerSize.d.ts +1 -0
  262. package/dist/shared/hooks/useContainerSize.js +24 -0
  263. package/dist/shared/hooks/useTouchOrHover.d.ts +6 -0
  264. package/dist/shared/hooks/useTouchOrHover.js +95 -0
  265. package/dist/shared/hooks/useWindowSize.d.ts +4 -0
  266. package/dist/shared/hooks/useWindowSize.js +27 -0
  267. package/dist/style.css +74 -74
  268. package/dist/styles/helpers/mergeStyles.d.ts +1 -0
  269. package/dist/styles/helpers/mergeStyles.js +22 -0
  270. package/dist/styles/helpers/mergeStyles.test.d.ts +1 -0
  271. package/dist/styles/theme.config.d.ts +124 -0
  272. package/package.json +6 -9
  273. package/dist/interactive-component-library.js +0 -7993
  274. package/dist/interactive-component-library.js.map +0 -1
  275. package/dist/interactive-component-library.umd.cjs +0 -7989
  276. package/dist/interactive-component-library.umd.cjs.map +0 -1
@@ -0,0 +1,96 @@
1
+ import { Feature } from "../Feature.js";
2
+ import { LineString } from "../geometry/LineString.js";
3
+ import { Polygon } from "../geometry/Polygon.js";
4
+ import { Point } from "../geometry/Point.js";
5
+ import { extentForCoordinates } from "../util/extent.js";
6
+ class GeoJSON {
7
+ readFeaturesFromObject(object) {
8
+ const geoJSONObject = object;
9
+ let features = null;
10
+ if (geoJSONObject["type"] === "FeatureCollection") {
11
+ const geoJSONFeatureCollection = object;
12
+ features = [];
13
+ const geoJSONFeatures = geoJSONFeatureCollection["features"];
14
+ for (let i = 0, ii = geoJSONFeatures.length; i < ii; ++i) {
15
+ const featureObject = this.readFeatureFromObject(geoJSONFeatures[i]);
16
+ if (!featureObject) {
17
+ continue;
18
+ }
19
+ features.push(featureObject);
20
+ }
21
+ } else if (geoJSONObject["type"] === "Feature") {
22
+ features = [this.readFeatureFromObject(geoJSONObject)];
23
+ } else if (Array.isArray(geoJSONObject)) {
24
+ features = [];
25
+ for (let i = 0, ii = geoJSONObject.length; i < ii; ++i) {
26
+ const featureObject = this.readFeatureFromObject(geoJSONObject[i]);
27
+ if (!featureObject) {
28
+ continue;
29
+ }
30
+ features.push(featureObject);
31
+ }
32
+ } else {
33
+ try {
34
+ const geometries = this.readGeometriesFromObject(geoJSONObject);
35
+ const feature = new Feature({ geometries });
36
+ features = [feature];
37
+ } catch {
38
+ console.warn("Unable to interpret GeoJSON:", geoJSONObject);
39
+ return;
40
+ }
41
+ }
42
+ return features.flat();
43
+ }
44
+ readFeatureFromObject(geoJSONObject) {
45
+ const geometries = this.readGeometriesFromObject(geoJSONObject["geometry"]);
46
+ if (geometries.length > 0) {
47
+ return new Feature({
48
+ id: geoJSONObject["id"],
49
+ geometries,
50
+ properties: geoJSONObject["properties"]
51
+ });
52
+ }
53
+ return null;
54
+ }
55
+ readGeometriesFromObject(geometry) {
56
+ const geometries = [];
57
+ if (geometry.type === "Polygon") {
58
+ const polygon = this.readPolygonForCoordinates(geometry.coordinates);
59
+ geometries.push(polygon);
60
+ } else if (geometry.type === "MultiPolygon") {
61
+ for (const polygonCoordinates of geometry.coordinates) {
62
+ const polygon = this.readPolygonForCoordinates(polygonCoordinates);
63
+ geometries.push(polygon);
64
+ }
65
+ } else if (geometry.type === "LineString") {
66
+ const lineString = this.readLineStringForCoordinates(geometry.coordinates);
67
+ geometries.push(lineString);
68
+ } else if (geometry.type === "MultiLineString") {
69
+ for (const lineStringCoordinates of geometry.coordinates) {
70
+ const lineString = this.readLineStringForCoordinates(
71
+ lineStringCoordinates
72
+ );
73
+ geometries.push(lineString);
74
+ }
75
+ } else if (geometry.type === "Point") {
76
+ const point = this.readPointForCoordinates(geometry.coordinates);
77
+ geometries.push(point);
78
+ }
79
+ return geometries;
80
+ }
81
+ readPolygonForCoordinates(coordinates) {
82
+ const outerRing = coordinates[0];
83
+ const extent = extentForCoordinates(outerRing);
84
+ return new Polygon({ extent, coordinates });
85
+ }
86
+ readLineStringForCoordinates(coordinates) {
87
+ const extent = extentForCoordinates(coordinates);
88
+ return new LineString({ extent, coordinates });
89
+ }
90
+ readPointForCoordinates(coordinates) {
91
+ return new Point({ coordinates });
92
+ }
93
+ }
94
+ export {
95
+ GeoJSON
96
+ };
@@ -0,0 +1,32 @@
1
+ export class Geometry {
2
+ /**
3
+ * Represents vector geometry
4
+ * @constructor
5
+ * @param {Object} options
6
+ * @param {string} options.type - The type of geometry (e.g., 'Point', 'LineString', 'Polygon')
7
+ * @param {Array} options.extent - The extent of the geometry (e.g., [xmin, ymin, xmax, ymax])
8
+ * @param {Array} options.coordinates - The coordinates of the geometry (e.g., [[x1, y1], [x2, y2], ...])
9
+ */
10
+ constructor({ type, extent, coordinates }: {
11
+ type: string;
12
+ extent: any[];
13
+ coordinates: any[];
14
+ });
15
+ type: string;
16
+ extent: any[];
17
+ coordinates: any[];
18
+ getProjected: any;
19
+ /**
20
+ * Returns the geometry as a GeoJSON object
21
+ * @function
22
+ * @param {import("../projection").Projection} projection - The projection to use for the geometry
23
+ * @returns {Object} A GeoJSON representation of the projected geometry
24
+ * @private
25
+ */
26
+ private _getProjected;
27
+ /**
28
+ * Returns the geometry as a GeoJSON object
29
+ * @returns {Object} The GeoJSON representation of the geometry
30
+ */
31
+ getGeoJSON(): any;
32
+ }
@@ -0,0 +1,41 @@
1
+ import { memoise } from "../util/memoise.js";
2
+ class Geometry {
3
+ /**
4
+ * Represents vector geometry
5
+ * @constructor
6
+ * @param {Object} options
7
+ * @param {string} options.type - The type of geometry (e.g., 'Point', 'LineString', 'Polygon')
8
+ * @param {Array} options.extent - The extent of the geometry (e.g., [xmin, ymin, xmax, ymax])
9
+ * @param {Array} options.coordinates - The coordinates of the geometry (e.g., [[x1, y1], [x2, y2], ...])
10
+ */
11
+ constructor({ type, extent, coordinates }) {
12
+ this.type = type;
13
+ this.extent = extent;
14
+ this.coordinates = coordinates;
15
+ this.getProjected = memoise(this._getProjected).bind(this);
16
+ }
17
+ /**
18
+ * Returns the geometry as a GeoJSON object
19
+ * @function
20
+ * @param {import("../projection").Projection} projection - The projection to use for the geometry
21
+ * @returns {Object} A GeoJSON representation of the projected geometry
22
+ * @private
23
+ */
24
+ // eslint-disable-next-line no-unused-vars
25
+ _getProjected(projection) {
26
+ throw new Error("Not implemented");
27
+ }
28
+ /**
29
+ * Returns the geometry as a GeoJSON object
30
+ * @returns {Object} The GeoJSON representation of the geometry
31
+ */
32
+ getGeoJSON() {
33
+ return {
34
+ type: this.type,
35
+ coordinates: this.coordinates
36
+ };
37
+ }
38
+ }
39
+ export {
40
+ Geometry
41
+ };
@@ -0,0 +1,12 @@
1
+ import { Geometry } from './Geometry';
2
+ export class LineString extends Geometry {
3
+ constructor({ type, extent, coordinates }: {
4
+ type?: string;
5
+ extent: any;
6
+ coordinates: any;
7
+ });
8
+ _getProjected(projection: any): {
9
+ type: string;
10
+ coordinates: any[];
11
+ };
12
+ }
@@ -0,0 +1,19 @@
1
+ import { Geometry } from "./Geometry.js";
2
+ class LineString extends Geometry {
3
+ constructor({ type = "LineString", extent, coordinates }) {
4
+ super({ type, extent, coordinates });
5
+ }
6
+ _getProjected(projection) {
7
+ const projected = [];
8
+ for (const point of this.coordinates) {
9
+ projected.push(projection(point));
10
+ }
11
+ return {
12
+ type: this.type,
13
+ coordinates: projected
14
+ };
15
+ }
16
+ }
17
+ export {
18
+ LineString
19
+ };
@@ -0,0 +1,11 @@
1
+ import { Geometry } from './Geometry';
2
+ export class Point extends Geometry {
3
+ constructor({ type, coordinates }: {
4
+ type?: string;
5
+ coordinates: any;
6
+ });
7
+ _getProjected(projection: any): {
8
+ type: string;
9
+ coordinates: any;
10
+ };
11
+ }
@@ -0,0 +1,16 @@
1
+ import { Geometry } from "./Geometry.js";
2
+ class Point extends Geometry {
3
+ constructor({ type = "Point", coordinates }) {
4
+ super({ type, extent: null, coordinates });
5
+ this.extent = [...coordinates, ...coordinates];
6
+ }
7
+ _getProjected(projection) {
8
+ return {
9
+ type: this.type,
10
+ coordinates: projection(this.coordinates)
11
+ };
12
+ }
13
+ }
14
+ export {
15
+ Point
16
+ };
@@ -0,0 +1,16 @@
1
+ import { Geometry } from './Geometry';
2
+ export class Polygon extends Geometry {
3
+ constructor({ type, extent, coordinates }: {
4
+ type?: string;
5
+ extent: any;
6
+ coordinates: any;
7
+ });
8
+ _getProjected(projection: any): {
9
+ type: string;
10
+ coordinates: any[][];
11
+ };
12
+ getOuterRing(): any;
13
+ setOuterRing(coordinates: any): void;
14
+ setCoordinates(coordinates: any): void;
15
+ clone(): Polygon;
16
+ }
@@ -0,0 +1,46 @@
1
+ import { Geometry } from "./Geometry.js";
2
+ class Polygon extends Geometry {
3
+ constructor({ type = "Polygon", extent, coordinates }) {
4
+ super({ type, extent, coordinates });
5
+ }
6
+ _getProjected(projection) {
7
+ const projected = [];
8
+ const rings = this.coordinates;
9
+ for (const ring of rings) {
10
+ const projectedRing = [];
11
+ for (const point of ring) {
12
+ const projectedPoint = projection(point);
13
+ if (projectedPoint) {
14
+ projectedRing.push(projectedPoint);
15
+ } else {
16
+ break;
17
+ }
18
+ }
19
+ if (projectedRing.length > 0) {
20
+ projected.push(projectedRing);
21
+ }
22
+ }
23
+ return {
24
+ type: this.type,
25
+ coordinates: projected
26
+ };
27
+ }
28
+ getOuterRing() {
29
+ return this.coordinates[0];
30
+ }
31
+ setOuterRing(coordinates) {
32
+ this.coordinates[0] = coordinates;
33
+ }
34
+ setCoordinates(coordinates) {
35
+ this.coordinates = coordinates;
36
+ }
37
+ clone() {
38
+ return new Polygon({
39
+ extent: this.extent,
40
+ coordinates: JSON.parse(JSON.stringify(this.coordinates))
41
+ });
42
+ }
43
+ }
44
+ export {
45
+ Polygon
46
+ };
@@ -0,0 +1,4 @@
1
+ export * from './Geometry';
2
+ export * from './LineString';
3
+ export * from './Polygon';
4
+ export * from './Point';
@@ -0,0 +1,2 @@
1
+ export * from './interpolateFeatures';
2
+ export * from './interpolateStyles';
@@ -0,0 +1,5 @@
1
+ export function interpolateFeatures(currentFeatures: any, newFeatures: any, { interpolate, separate, combine }: {
2
+ interpolate: any;
3
+ separate: any;
4
+ combine: any;
5
+ }): (t: any) => any;
@@ -0,0 +1,95 @@
1
+ function interpolateFeatures(currentFeatures, newFeatures, { interpolate, separate, combine }) {
2
+ if (currentFeatures.length !== newFeatures.length) {
3
+ throw new Error(
4
+ "interpolateFeatures expects an equal number of features for start and end"
5
+ );
6
+ }
7
+ const featureInterpolators = [];
8
+ for (let i = 0; i < currentFeatures.length; i++) {
9
+ const geometryInterpolators = [];
10
+ const currentGeometries = currentFeatures[i].geometries;
11
+ const newGeometries = newFeatures[i].geometries;
12
+ if (newGeometries.length === currentGeometries.length) {
13
+ for (let e = 0; e < currentGeometries.length; e++) {
14
+ const currentGeometry = currentGeometries[e];
15
+ const newGeometry = newGeometries[e];
16
+ if (currentGeometry.type !== "Polygon" || newGeometry.type !== "Polygon") {
17
+ throw new Error("interpolateFeatures expects only Polygon geometry");
18
+ }
19
+ const shapeInterpolator = interpolate(
20
+ currentGeometries[e].getOuterRing(),
21
+ newGeometries[e].getOuterRing(),
22
+ { string: false }
23
+ );
24
+ geometryInterpolators.push({
25
+ type: "default",
26
+ interpolator: shapeInterpolator
27
+ });
28
+ }
29
+ } else if (currentGeometries.length === 1 && newGeometries.length > 1) {
30
+ const separationInterpolator = separate(
31
+ currentGeometries[0].getOuterRing(),
32
+ newGeometries.map((geometry) => geometry.getOuterRing()),
33
+ { string: false, single: true }
34
+ );
35
+ geometryInterpolators.push({
36
+ type: "separate",
37
+ interpolator: separationInterpolator
38
+ });
39
+ } else if (currentGeometries.length > 1 && newGeometries.length === 1) {
40
+ const combinationInterpolator = combine(
41
+ currentGeometries.map((geometry) => geometry.getOuterRing()),
42
+ newGeometries[0].getOuterRing(),
43
+ { string: false, single: true }
44
+ );
45
+ geometryInterpolators.push({
46
+ type: "combine",
47
+ interpolator: combinationInterpolator
48
+ });
49
+ } else {
50
+ throw new Error(
51
+ `Encountered an unexpected number of geometries: ${currentGeometries.length} and ${newGeometries.length}`
52
+ );
53
+ }
54
+ featureInterpolators.push(geometryInterpolators);
55
+ }
56
+ return (t) => {
57
+ if (t >= 1) {
58
+ return newFeatures;
59
+ }
60
+ const features = [];
61
+ for (let i = 0; i < featureInterpolators.length; i++) {
62
+ const feature = newFeatures[i].clone();
63
+ const geometries = [];
64
+ const geometryInterpolators = featureInterpolators[i];
65
+ for (const [
66
+ index,
67
+ { type, interpolator }
68
+ ] of geometryInterpolators.entries()) {
69
+ let geometry = feature.geometries[index].clone();
70
+ let interpolated;
71
+ switch (type) {
72
+ case "separate":
73
+ case "combine":
74
+ interpolated = interpolator(t);
75
+ interpolated.forEach((d) => {
76
+ const polygon = geometry.clone();
77
+ polygon.setCoordinates([d]);
78
+ geometries.push(polygon);
79
+ });
80
+ break;
81
+ default:
82
+ geometry.setOuterRing(interpolator(t));
83
+ geometries.push(geometry);
84
+ break;
85
+ }
86
+ }
87
+ feature.setGeometry(geometries);
88
+ features.push(feature);
89
+ }
90
+ return features;
91
+ };
92
+ }
93
+ export {
94
+ interpolateFeatures
95
+ };
@@ -0,0 +1,4 @@
1
+ import { Style, Fill, Stroke } from '../styles';
2
+ export function interpolateStyles(firstStyle: any, secondStyle: any, interpolateColors: any, interpolateNumbers: any): (t: any) => Style;
3
+ export function interpolateFill(fillA: any, fillB: any, interpolateColors: any, interpolateNumbers: any): (t: any) => Fill;
4
+ export function interpolateStroke(strokeA: any, strokeB: any, interpolateColors: any, interpolateNumbers: any): (t: any) => Stroke;
@@ -0,0 +1,65 @@
1
+ import { Style } from "../styles/Style.js";
2
+ import { Stroke } from "../styles/Stroke.js";
3
+ import { Fill } from "../styles/Fill.js";
4
+ function interpolateStyles(firstStyle, secondStyle, interpolateColors, interpolateNumbers) {
5
+ const fillInterpolator = interpolateFill(
6
+ firstStyle.fill,
7
+ secondStyle.fill,
8
+ interpolateColors,
9
+ interpolateNumbers
10
+ );
11
+ const strokeInterpolator = interpolateStroke(
12
+ firstStyle.stroke,
13
+ secondStyle.stroke,
14
+ interpolateColors,
15
+ interpolateNumbers
16
+ );
17
+ return (t) => {
18
+ return new Style({
19
+ fill: fillInterpolator(t),
20
+ stroke: strokeInterpolator(t)
21
+ });
22
+ };
23
+ }
24
+ function interpolateFill(fillA, fillB, interpolateColors, interpolateNumbers) {
25
+ const colorInterpolator = interpolateColors(
26
+ (fillA == null ? void 0 : fillA.color) ?? "transparent",
27
+ (fillB == null ? void 0 : fillB.color) ?? "transparent"
28
+ );
29
+ const opacityInterpolator = interpolateNumbers(
30
+ (fillA == null ? void 0 : fillA.opacity) ?? 1,
31
+ (fillB == null ? void 0 : fillB.opacity) ?? 1
32
+ );
33
+ return (t) => {
34
+ return new Fill({
35
+ color: colorInterpolator(t),
36
+ opacity: opacityInterpolator(t)
37
+ });
38
+ };
39
+ }
40
+ function interpolateStroke(strokeA, strokeB, interpolateColors, interpolateNumbers) {
41
+ const colorInterpolator = interpolateColors(
42
+ (strokeA == null ? void 0 : strokeA.color) ?? "transparent",
43
+ (strokeB == null ? void 0 : strokeB.color) ?? "transparent"
44
+ );
45
+ const opacityInterpolator = interpolateNumbers(
46
+ (strokeA == null ? void 0 : strokeA.opacity) ?? 1,
47
+ (strokeB == null ? void 0 : strokeB.opacity) ?? 1
48
+ );
49
+ const widthInterpolator = interpolateNumbers(
50
+ (strokeA == null ? void 0 : strokeA.width) ?? 1,
51
+ (strokeB == null ? void 0 : strokeB.width) ?? 1
52
+ );
53
+ return (t) => {
54
+ return new Stroke({
55
+ color: colorInterpolator(t),
56
+ opacity: opacityInterpolator(t),
57
+ width: widthInterpolator(t)
58
+ });
59
+ };
60
+ }
61
+ export {
62
+ interpolateFill,
63
+ interpolateStroke,
64
+ interpolateStyles
65
+ };
@@ -0,0 +1,52 @@
1
+ import { VectorSource } from '../sources/VectorSource';
2
+ import { Style } from '../styles';
3
+ import { TextLayerRenderer } from '../renderers/TextLayerRenderer';
4
+ import { Dispatcher } from '../events/Dispatcher';
5
+ /** @typedef {Omit<ConstructorParameters<typeof TextLayer>[0], "source">} TextLayerOptions */
6
+ /** @typedef {TextLayerOptions & { features: import("../Feature").Feature[]}} TextLayerComponentProps */
7
+ export class TextLayer {
8
+ /** @param {TextLayerComponentProps} props */
9
+ static Component({ features, style, minZoom, opacity, declutter, drawCollisionBoxes, }: TextLayerComponentProps): any;
10
+ /**
11
+ * @param {import("../Feature").Feature[]} features
12
+ * @param {TextLayerOptions} options
13
+ */
14
+ static with(features: import('../Feature').Feature[], options: TextLayerOptions): TextLayer;
15
+ /**
16
+ * @constructor
17
+ * @param {Object} params
18
+ * @param {VectorSource} params.source
19
+ * @param {Style | (() => Style)} [params.style=undefined]
20
+ * @param {number} [params.minZoom=0]
21
+ * @param {number} [params.opacity=1]
22
+ * @param {boolean} [params.declutter=true]
23
+ * @param {boolean} [params.drawCollisionBoxes=false]
24
+ */
25
+ constructor({ source, style, minZoom, opacity, declutter, drawCollisionBoxes, }: {
26
+ source: VectorSource;
27
+ style?: Style | (() => Style);
28
+ minZoom?: number;
29
+ opacity?: number;
30
+ declutter?: boolean;
31
+ drawCollisionBoxes?: boolean;
32
+ });
33
+ source: VectorSource;
34
+ _style: Style | (() => Style);
35
+ minZoom: number;
36
+ opacity: number;
37
+ declutter: boolean;
38
+ drawCollisionBoxes: boolean;
39
+ renderer: TextLayerRenderer;
40
+ dispatcher: Dispatcher;
41
+ tearDown(): void;
42
+ set style(style: Style | (() => Style));
43
+ get style(): Style | (() => Style);
44
+ getExtent(): any;
45
+ _extent: any;
46
+ getStyleFunction(): () => Style;
47
+ renderFrame(frameState: any, targetElement: any): any;
48
+ }
49
+ export type TextLayerOptions = Omit<ConstructorParameters<typeof TextLayer>[0], "source">;
50
+ export type TextLayerComponentProps = TextLayerOptions & {
51
+ features: import('../Feature').Feature[];
52
+ };
@@ -0,0 +1,111 @@
1
+ import { TextLayerRenderer } from "../renderers/TextLayerRenderer.js";
2
+ import { Style } from "../styles/Style.js";
3
+ import { Text } from "../styles/Text.js";
4
+ import { Dispatcher } from "../events/Dispatcher.js";
5
+ import { combineExtents } from "../util/extent.js";
6
+ import { MapEvent } from "../events/MapEvent.js";
7
+ import { VectorSource } from "../sources/VectorSource.js";
8
+ import { MapContext } from "../../context/MapContext.js";
9
+ import { useContext, useMemo, useEffect } from "preact/hooks";
10
+ class TextLayer {
11
+ /** @param {TextLayerComponentProps} props */
12
+ static Component({
13
+ features,
14
+ style,
15
+ minZoom,
16
+ opacity,
17
+ declutter,
18
+ drawCollisionBoxes
19
+ }) {
20
+ const { registerLayer } = useContext(MapContext);
21
+ const layer = useMemo(
22
+ () => TextLayer.with(features, {
23
+ style,
24
+ minZoom,
25
+ opacity,
26
+ declutter,
27
+ drawCollisionBoxes
28
+ }),
29
+ // eslint-disable-next-line react-hooks/exhaustive-deps
30
+ [features, minZoom, opacity, declutter, drawCollisionBoxes]
31
+ );
32
+ registerLayer(layer);
33
+ useEffect(() => {
34
+ layer.style = style;
35
+ }, [style]);
36
+ return null;
37
+ }
38
+ /**
39
+ * @param {import("../Feature").Feature[]} features
40
+ * @param {TextLayerOptions} options
41
+ */
42
+ static with(features, options) {
43
+ const source = new VectorSource({ features });
44
+ return new TextLayer({ source, ...options });
45
+ }
46
+ /**
47
+ * @constructor
48
+ * @param {Object} params
49
+ * @param {VectorSource} params.source
50
+ * @param {Style | (() => Style)} [params.style=undefined]
51
+ * @param {number} [params.minZoom=0]
52
+ * @param {number} [params.opacity=1]
53
+ * @param {boolean} [params.declutter=true]
54
+ * @param {boolean} [params.drawCollisionBoxes=false]
55
+ */
56
+ constructor({
57
+ source,
58
+ style,
59
+ minZoom = 0,
60
+ opacity = 1,
61
+ declutter = true,
62
+ drawCollisionBoxes = false
63
+ }) {
64
+ this.source = source;
65
+ this._style = style;
66
+ this.minZoom = minZoom;
67
+ this.opacity = opacity;
68
+ this.declutter = declutter;
69
+ this.drawCollisionBoxes = drawCollisionBoxes;
70
+ this.renderer = new TextLayerRenderer(this);
71
+ this.dispatcher = new Dispatcher(this);
72
+ }
73
+ tearDown() {
74
+ this.dispatcher = null;
75
+ }
76
+ get style() {
77
+ if (this._style) return this._style;
78
+ const defaultStyle = new Style({
79
+ text: new Text()
80
+ });
81
+ return defaultStyle;
82
+ }
83
+ set style(style) {
84
+ this._style = style;
85
+ this.dispatcher.dispatch(MapEvent.CHANGE);
86
+ }
87
+ getExtent() {
88
+ if (this._extent) return this._extent;
89
+ const features = this.source.getFeatures();
90
+ const extent = features.reduce((combinedExtent, feature) => {
91
+ const featureExtent = feature.getExtent();
92
+ if (!combinedExtent) return featureExtent;
93
+ return combineExtents(featureExtent, combinedExtent);
94
+ }, null);
95
+ this._extent = extent;
96
+ return extent;
97
+ }
98
+ getStyleFunction() {
99
+ const style = this.style;
100
+ if (typeof style === "function") return style;
101
+ return () => {
102
+ return style;
103
+ };
104
+ }
105
+ renderFrame(frameState, targetElement) {
106
+ return this.renderer.renderFrame(frameState, targetElement);
107
+ }
108
+ }
109
+ export {
110
+ TextLayer
111
+ };