@guardian/interactive-component-library 0.3.0 → 0.3.2-rc1

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 (284) hide show
  1. package/dist/components/index.d.ts +3 -0
  2. package/dist/components/molecules/canvas-map/Map.d.ts +8 -0
  3. package/dist/components/molecules/canvas-map/Map.js +90 -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 +44 -0
  19. package/dist/components/molecules/canvas-map/lib/Feature.js +113 -0
  20. package/dist/components/molecules/canvas-map/lib/FeatureCollection.d.ts +21 -0
  21. package/dist/components/molecules/canvas-map/lib/FeatureCollection.js +24 -0
  22. package/dist/components/molecules/canvas-map/lib/Map.d.ts +82 -0
  23. package/dist/components/molecules/canvas-map/lib/Map.js +267 -0
  24. package/dist/components/molecules/canvas-map/lib/View.d.ts +222 -0
  25. package/dist/components/molecules/canvas-map/lib/View.js +208 -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 +63 -0
  32. package/dist/components/molecules/canvas-map/lib/formats/GeoJSON.js +122 -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 +22 -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 +118 -0
  49. package/dist/components/molecules/canvas-map/lib/layers/VectorLayer.d.ts +57 -0
  50. package/dist/components/molecules/canvas-map/lib/layers/VectorLayer.js +136 -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 +27 -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 +16 -0
  55. package/dist/components/molecules/canvas-map/lib/renderers/FeatureRenderer.js +90 -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 +21 -0
  59. package/dist/components/molecules/canvas-map/lib/renderers/TextLayerRenderer.js +133 -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 +79 -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 +53 -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 +24 -0
  67. package/dist/components/molecules/canvas-map/lib/styles/Stroke.js +22 -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 +146 -0
  71. package/dist/components/molecules/canvas-map/lib/styles/Text.js +116 -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 +24 -0
  77. package/dist/components/molecules/canvas-map/lib/util/bounds.d.ts +47 -0
  78. package/dist/components/molecules/canvas-map/lib/util/bounds.js +61 -0
  79. package/dist/components/molecules/canvas-map/lib/util/coordinate.d.ts +26 -0
  80. package/dist/components/molecules/canvas-map/lib/util/coordinate.js +35 -0
  81. package/dist/components/molecules/canvas-map/lib/util/debug.d.ts +11 -0
  82. package/dist/components/molecules/canvas-map/lib/util/debug.js +27 -0
  83. package/dist/components/molecules/canvas-map/lib/util/deflate.d.ts +36 -0
  84. package/dist/components/molecules/canvas-map/lib/util/distance.d.ts +1 -0
  85. package/dist/components/molecules/canvas-map/lib/util/distance.js +12 -0
  86. package/dist/components/molecules/canvas-map/lib/util/dom.d.ts +9 -0
  87. package/dist/components/molecules/canvas-map/lib/util/dom.js +28 -0
  88. package/dist/components/molecules/canvas-map/lib/util/extent.d.ts +98 -0
  89. package/dist/components/molecules/canvas-map/lib/util/extent.js +118 -0
  90. package/dist/components/molecules/canvas-map/lib/util/index.d.ts +6 -0
  91. package/dist/components/molecules/canvas-map/lib/util/memoise.d.ts +10 -0
  92. package/dist/components/molecules/canvas-map/lib/util/memoise.js +20 -0
  93. package/dist/components/molecules/canvas-map/lib/util/resolution.d.ts +9 -0
  94. package/dist/components/molecules/canvas-map/lib/util/resolution.js +11 -0
  95. package/dist/components/molecules/canvas-map/lib/util/simplify.d.ts +114 -0
  96. package/dist/components/molecules/canvas-map/lib/util/size.d.ts +32 -0
  97. package/dist/components/molecules/canvas-map/lib/util/size.js +53 -0
  98. package/dist/components/molecules/canvas-map/lib/util/toRgba.d.ts +1 -0
  99. package/dist/components/molecules/canvas-map/lib/util/toRgba.js +25 -0
  100. package/dist/components/molecules/canvas-map/lib/util/uid.d.ts +5 -0
  101. package/dist/components/molecules/canvas-map/lib/util/uid.js +7 -0
  102. package/dist/components/molecules/canvas-map/lib/util/zoomLevel.d.ts +2 -0
  103. package/dist/components/molecules/canvas-map/lib/util/zoomLevel.js +14 -0
  104. package/dist/components/molecules/canvas-map/style.module.scss.js +20 -0
  105. package/dist/components/molecules/column-chart/column-chart-example.d.ts +35 -0
  106. package/dist/components/molecules/column-chart/column-chart-util.d.ts +1 -0
  107. package/dist/components/molecules/column-chart/index.d.ts +11 -0
  108. package/dist/components/molecules/column-chart/index.js +63 -0
  109. package/dist/components/molecules/column-chart/style.module.css.js +14 -0
  110. package/dist/components/molecules/control-change/index.d.ts +6 -0
  111. package/dist/components/molecules/control-change/index.js +29 -0
  112. package/dist/components/molecules/control-change/style.module.css.js +11 -0
  113. package/dist/components/molecules/dropdown/index.d.ts +11 -0
  114. package/dist/components/molecules/dropdown/index.js +191 -0
  115. package/dist/components/molecules/dropdown/style.module.css.js +50 -0
  116. package/dist/components/molecules/first-past-the-post-waffle/index.d.ts +5 -0
  117. package/dist/components/molecules/first-past-the-post-waffle/index.js +14 -0
  118. package/dist/components/molecules/first-past-the-post-waffle/style.module.css.js +14 -0
  119. package/dist/components/molecules/index.d.ts +18 -0
  120. package/dist/components/molecules/modal/index.d.ts +8 -0
  121. package/dist/components/molecules/modal/index.js +59 -0
  122. package/dist/components/molecules/modal/style.module.css.js +26 -0
  123. package/dist/components/molecules/option-picker/index.d.ts +26 -0
  124. package/dist/components/molecules/option-picker/index.js +94 -0
  125. package/dist/components/molecules/option-picker/style.module.css.js +35 -0
  126. package/dist/components/molecules/page-section/index.d.ts +8 -0
  127. package/dist/components/molecules/page-section/index.js +52 -0
  128. package/dist/components/molecules/page-section/style.module.scss.js +20 -0
  129. package/dist/components/molecules/party-profile/index.d.ts +10 -0
  130. package/dist/components/molecules/party-profile/index.js +29 -0
  131. package/dist/components/molecules/party-profile/style.module.css.js +26 -0
  132. package/dist/components/molecules/refresh-indicator/index.d.ts +4 -0
  133. package/dist/components/molecules/refresh-indicator/index.js +18 -0
  134. package/dist/components/molecules/refresh-indicator/style.module.scss.js +17 -0
  135. package/dist/components/molecules/responsive-grid/index.d.ts +10 -0
  136. package/dist/components/molecules/responsive-grid/index.js +19 -0
  137. package/dist/components/molecules/responsive-grid/style.module.scss.js +8 -0
  138. package/dist/components/molecules/result-summary/index.d.ts +8 -0
  139. package/dist/components/molecules/result-summary/index.js +40 -0
  140. package/dist/components/molecules/result-summary/style.module.css.js +11 -0
  141. package/dist/components/molecules/search-input/icons/search.d.ts +1 -0
  142. package/dist/components/molecules/search-input/icons/search.js +24 -0
  143. package/dist/components/molecules/search-input/icons/search.module.css.js +11 -0
  144. package/dist/components/molecules/search-input/index.d.ts +11 -0
  145. package/dist/components/molecules/search-input/index.js +165 -0
  146. package/dist/components/molecules/search-input/style.module.css.js +32 -0
  147. package/dist/components/molecules/slope-chart/index.d.ts +16 -0
  148. package/dist/components/molecules/slope-chart/index.js +139 -0
  149. package/dist/components/molecules/slope-chart/style.module.css.js +35 -0
  150. package/dist/components/molecules/svg-map/context/MapContext.d.ts +1 -0
  151. package/dist/components/molecules/svg-map/context/MapContext.js +5 -0
  152. package/dist/components/molecules/svg-map/context/SVGMapProvider.d.ts +10 -0
  153. package/dist/components/molecules/svg-map/context/SVGMapProvider.js +88 -0
  154. package/dist/components/molecules/svg-map/helpers/bboxFeature.d.ts +8 -0
  155. package/dist/components/molecules/svg-map/helpers/bboxFeature.js +26 -0
  156. package/dist/components/molecules/svg-map/helpers/dynamicPropValue.d.ts +1 -0
  157. package/dist/components/molecules/svg-map/helpers/dynamicPropValue.js +9 -0
  158. package/dist/components/molecules/svg-map/helpers/geoMath.d.ts +4 -0
  159. package/dist/components/molecules/svg-map/helpers/saveSVG.d.ts +1 -0
  160. package/dist/components/molecules/svg-map/hooks/useCamera.d.ts +0 -0
  161. package/dist/components/molecules/svg-map/hooks/useThrowIfNonLayerChildren.d.ts +4 -0
  162. package/dist/components/molecules/svg-map/hooks/useThrowIfNonLayerChildren.js +19 -0
  163. package/dist/components/molecules/svg-map/index.d.ts +38 -0
  164. package/dist/components/molecules/svg-map/index.js +121 -0
  165. package/dist/components/molecules/svg-map/layers/CompositionBorders.d.ts +3 -0
  166. package/dist/components/molecules/svg-map/layers/CompositionBorders.js +14 -0
  167. package/dist/components/molecules/svg-map/layers/Line.d.ts +7 -0
  168. package/dist/components/molecules/svg-map/layers/Line.js +48 -0
  169. package/dist/components/molecules/svg-map/layers/Point.d.ts +10 -0
  170. package/dist/components/molecules/svg-map/layers/Point.js +59 -0
  171. package/dist/components/molecules/svg-map/layers/Polygon.d.ts +9 -0
  172. package/dist/components/molecules/svg-map/layers/Polygon.js +75 -0
  173. package/dist/components/molecules/svg-map/layers/Prerendered.d.ts +3 -0
  174. package/dist/components/molecules/svg-map/layers/Prerendered.js +11 -0
  175. package/dist/components/molecules/svg-map/layers/compositionBorders.module.scss.js +8 -0
  176. package/dist/components/molecules/svg-map/layers/index.d.ts +5 -0
  177. package/dist/components/molecules/svg-map/layers/index.js +12 -0
  178. package/dist/components/molecules/svg-map/renderers/SVGRenderer.d.ts +3 -0
  179. package/dist/components/molecules/svg-map/renderers/SVGRenderer.js +32 -0
  180. package/dist/components/molecules/svg-map/style.module.css.js +11 -0
  181. package/dist/components/molecules/table/index.d.ts +7 -0
  182. package/dist/components/molecules/table/index.js +90 -0
  183. package/dist/components/molecules/table/style.module.scss.js +29 -0
  184. package/dist/components/molecules/table/useTable.d.ts +8 -0
  185. package/dist/components/molecules/table/useTable.js +128 -0
  186. package/dist/components/molecules/tooltip/index.d.ts +82 -0
  187. package/dist/components/molecules/tooltip/index.js +117 -0
  188. package/dist/components/molecules/tooltip/style.module.css.js +8 -0
  189. package/dist/components/molecules/topline-result/index.d.ts +3 -0
  190. package/dist/components/molecules/topline-result/index.js +61 -0
  191. package/dist/components/molecules/topline-result/style.module.scss.js +38 -0
  192. package/dist/components/organisms/coalitions-tracker/index.d.ts +16 -0
  193. package/dist/components/organisms/coalitions-tracker/index.js +151 -0
  194. package/dist/components/organisms/coalitions-tracker/style.module.scss.js +32 -0
  195. package/dist/components/organisms/index.d.ts +2 -0
  196. package/dist/components/organisms/ticker/gradient/index.d.ts +1 -0
  197. package/dist/components/organisms/ticker/gradient/index.js +35 -0
  198. package/dist/components/organisms/ticker/gradient/style.module.scss.js +14 -0
  199. package/dist/components/organisms/ticker/index.d.ts +5 -0
  200. package/dist/components/organisms/ticker/index.js +102 -0
  201. package/dist/components/organisms/ticker/style.module.scss.js +32 -0
  202. package/dist/components/particles/ad-slot/index.d.ts +40 -0
  203. package/dist/components/particles/ad-slot/index.js +34 -0
  204. package/dist/components/particles/ad-slot/style.module.css.js +11 -0
  205. package/dist/components/particles/arrow-button/index.d.ts +6 -0
  206. package/dist/components/particles/arrow-button/index.js +32 -0
  207. package/dist/components/particles/arrow-button/style.module.css.js +11 -0
  208. package/dist/components/particles/aspect-ratio-box/index.d.ts +4 -0
  209. package/dist/components/particles/aspect-ratio-box/index.js +15 -0
  210. package/dist/components/particles/aspect-ratio-box/style.module.css.js +6 -0
  211. package/dist/components/particles/button/index.d.ts +6 -0
  212. package/dist/components/particles/button/index.js +10 -0
  213. package/dist/components/particles/button/style.module.css.js +11 -0
  214. package/dist/components/particles/change-bar/index.d.ts +8 -0
  215. package/dist/components/particles/change-bar/index.js +27 -0
  216. package/dist/components/particles/change-bar/style.module.scss.js +14 -0
  217. package/dist/components/particles/chevron/index.d.ts +6 -0
  218. package/dist/components/particles/chevron/index.js +78 -0
  219. package/dist/components/particles/chevron/style.module.css.js +20 -0
  220. package/dist/components/particles/circle-icon/index.d.ts +6 -0
  221. package/dist/components/particles/circle-icon/index.js +32 -0
  222. package/dist/components/particles/circle-icon/style.module.css.js +14 -0
  223. package/dist/components/particles/close-button/index.d.ts +5 -0
  224. package/dist/components/particles/close-button/index.js +35 -0
  225. package/dist/components/particles/close-button/style.module.css.js +17 -0
  226. package/dist/components/particles/container/index.d.ts +5 -0
  227. package/dist/components/particles/container/index.js +13 -0
  228. package/dist/components/particles/container/style.module.scss.js +11 -0
  229. package/dist/components/particles/gradient-icon/index.d.ts +1 -0
  230. package/dist/components/particles/gradient-icon/index.js +46 -0
  231. package/dist/components/particles/gradient-icon/style.module.css.js +14 -0
  232. package/dist/components/particles/index.d.ts +18 -0
  233. package/dist/components/particles/info-button/index.d.ts +3 -0
  234. package/dist/components/particles/info-button/index.js +19 -0
  235. package/dist/components/particles/info-button/style.module.css.js +11 -0
  236. package/dist/components/particles/legend-item/index.d.ts +6 -0
  237. package/dist/components/particles/legend-item/index.js +26 -0
  238. package/dist/components/particles/legend-item/style.module.css.js +17 -0
  239. package/dist/components/particles/relative-time-sentence/index.d.ts +4 -0
  240. package/dist/components/particles/relative-time-sentence/index.js +14 -0
  241. package/dist/components/particles/relative-time-sentence/style.module.css.js +8 -0
  242. package/dist/components/particles/square-cut-corner-icon/index.d.ts +6 -0
  243. package/dist/components/particles/square-cut-corner-icon/index.js +56 -0
  244. package/dist/components/particles/square-cut-corner-icon/style.module.scss.js +17 -0
  245. package/dist/components/particles/square-icon/index.d.ts +5 -0
  246. package/dist/components/particles/square-icon/index.js +28 -0
  247. package/dist/components/particles/square-icon/style.module.scss.js +11 -0
  248. package/dist/components/particles/stacked-bar/index.d.ts +23 -0
  249. package/dist/components/particles/stacked-bar/index.js +140 -0
  250. package/dist/components/particles/stacked-bar/style.module.css.js +17 -0
  251. package/dist/components/particles/stacked-grid/index.d.ts +6 -0
  252. package/dist/components/particles/stacked-grid/index.js +35 -0
  253. package/dist/components/particles/stacked-grid/style.module.css.js +20 -0
  254. package/dist/components/particles/waffle/index.d.ts +14 -0
  255. package/dist/components/particles/waffle/index.js +76 -0
  256. package/dist/components/particles/waffle/style.module.css.js +11 -0
  257. package/dist/index.d.ts +2 -0
  258. package/dist/index.js +147 -0
  259. package/dist/shared/colors/index.d.ts +2 -0
  260. package/dist/shared/helpers/createStore.d.ts +1 -0
  261. package/dist/shared/helpers/geometry.d.ts +3 -0
  262. package/dist/shared/helpers/geometry.js +16 -0
  263. package/dist/shared/helpers/geometry.test.d.ts +1 -0
  264. package/dist/shared/helpers/labelsUtil.d.ts +54 -0
  265. package/dist/shared/helpers/labelsUtil.js +58 -0
  266. package/dist/shared/helpers/labelsUtils.test.d.ts +1 -0
  267. package/dist/shared/helpers/shouldUpdate.d.ts +7 -0
  268. package/dist/shared/hooks/index.d.ts +3 -0
  269. package/dist/shared/hooks/useContainerSize.d.ts +1 -0
  270. package/dist/shared/hooks/useContainerSize.js +24 -0
  271. package/dist/shared/hooks/useTouchOrHover.d.ts +7 -0
  272. package/dist/shared/hooks/useTouchOrHover.js +103 -0
  273. package/dist/shared/hooks/useWindowSize.d.ts +4 -0
  274. package/dist/shared/hooks/useWindowSize.js +27 -0
  275. package/dist/style.css +74 -74
  276. package/dist/styles/helpers/mergeStyles.d.ts +1 -0
  277. package/dist/styles/helpers/mergeStyles.js +22 -0
  278. package/dist/styles/helpers/mergeStyles.test.d.ts +1 -0
  279. package/dist/styles/theme.config.d.ts +124 -0
  280. package/package.json +19 -10
  281. package/dist/interactive-component-library.js +0 -8365
  282. package/dist/interactive-component-library.js.map +0 -1
  283. package/dist/interactive-component-library.umd.cjs +0 -8360
  284. package/dist/interactive-component-library.umd.cjs.map +0 -1
@@ -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[] | import("../FeatureCollection").FeatureCollection }} TextLayerComponentProps */
7
+ export class TextLayer {
8
+ /** @param {TextLayerComponentProps} props */
9
+ static Component({ features: featureCollection, 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[] | import('../FeatureCollection').FeatureCollection;
52
+ };
@@ -0,0 +1,118 @@
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
+ import { FeatureCollection } from "../FeatureCollection.js";
11
+ class TextLayer {
12
+ /** @param {TextLayerComponentProps} props */
13
+ static Component({
14
+ features: featureCollection,
15
+ style,
16
+ minZoom,
17
+ opacity,
18
+ declutter,
19
+ drawCollisionBoxes
20
+ }) {
21
+ const { registerLayer } = useContext(MapContext);
22
+ const layer = useMemo(
23
+ () => {
24
+ const features = featureCollection instanceof FeatureCollection ? featureCollection.features : (
25
+ /** @type {import("../Feature").Feature[]} */
26
+ featureCollection
27
+ );
28
+ return TextLayer.with(features, {
29
+ style,
30
+ minZoom,
31
+ opacity,
32
+ declutter,
33
+ drawCollisionBoxes
34
+ });
35
+ },
36
+ // eslint-disable-next-line react-hooks/exhaustive-deps
37
+ [featureCollection, minZoom, opacity, declutter, drawCollisionBoxes]
38
+ );
39
+ registerLayer(layer);
40
+ useEffect(() => {
41
+ layer.style = style;
42
+ }, [style]);
43
+ return null;
44
+ }
45
+ /**
46
+ * @param {import("../Feature").Feature[]} features
47
+ * @param {TextLayerOptions} options
48
+ */
49
+ static with(features, options) {
50
+ const source = new VectorSource({ features });
51
+ return new TextLayer({ source, ...options });
52
+ }
53
+ /**
54
+ * @constructor
55
+ * @param {Object} params
56
+ * @param {VectorSource} params.source
57
+ * @param {Style | (() => Style)} [params.style=undefined]
58
+ * @param {number} [params.minZoom=0]
59
+ * @param {number} [params.opacity=1]
60
+ * @param {boolean} [params.declutter=true]
61
+ * @param {boolean} [params.drawCollisionBoxes=false]
62
+ */
63
+ constructor({
64
+ source,
65
+ style,
66
+ minZoom = 0,
67
+ opacity = 1,
68
+ declutter = true,
69
+ drawCollisionBoxes = false
70
+ }) {
71
+ this.source = source;
72
+ this._style = style;
73
+ this.minZoom = minZoom;
74
+ this.opacity = opacity;
75
+ this.declutter = declutter;
76
+ this.drawCollisionBoxes = drawCollisionBoxes;
77
+ this.renderer = new TextLayerRenderer(this);
78
+ this.dispatcher = new Dispatcher(this);
79
+ }
80
+ tearDown() {
81
+ this.dispatcher = null;
82
+ }
83
+ get style() {
84
+ if (this._style) return this._style;
85
+ const defaultStyle = new Style({
86
+ text: new Text()
87
+ });
88
+ return defaultStyle;
89
+ }
90
+ set style(style) {
91
+ this._style = style;
92
+ this.dispatcher.dispatch(MapEvent.CHANGE);
93
+ }
94
+ getExtent() {
95
+ if (this._extent) return this._extent;
96
+ const features = this.source.getFeatures();
97
+ const extent = features.reduce((combinedExtent, feature) => {
98
+ const featureExtent = feature.getExtent();
99
+ if (!combinedExtent) return featureExtent;
100
+ return combineExtents(featureExtent, combinedExtent);
101
+ }, null);
102
+ this._extent = extent;
103
+ return extent;
104
+ }
105
+ getStyleFunction() {
106
+ const style = this.style;
107
+ if (typeof style === "function") return style;
108
+ return () => {
109
+ return style;
110
+ };
111
+ }
112
+ renderFrame(frameState, targetElement) {
113
+ return this.renderer.renderFrame(frameState, targetElement);
114
+ }
115
+ }
116
+ export {
117
+ TextLayer
118
+ };
@@ -0,0 +1,57 @@
1
+ import { Dispatcher } from '../events';
2
+ import { VectorLayerRenderer } from '../renderers/VectorLayerRenderer';
3
+ import { Style } from '../styles';
4
+ import { VectorSource } from '../sources/VectorSource';
5
+ /** @typedef {Omit<ConstructorParameters<typeof VectorLayer>[0], "source">} VectorLayerOptions */
6
+ /** @typedef {VectorLayerOptions & { features: import("../Feature").Feature[] | import("../FeatureCollection").FeatureCollection }} VectorLayerComponentProps */
7
+ export class VectorLayer {
8
+ /** @param {VectorLayerComponentProps} props */
9
+ static Component({ features: featureCollection, style, minZoom, opacity, hitDetectionEnabled, }: VectorLayerComponentProps): any;
10
+ /**
11
+ * @param {import("../Feature").Feature[]} features
12
+ * @param {VectorLayerOptions} options
13
+ */
14
+ static with(features: import('../Feature').Feature[], options: VectorLayerOptions): VectorLayer;
15
+ /**
16
+ * @param {Object} params
17
+ * @param {VectorSource} params.source
18
+ * @param {Style | (() => Style)} [params.style=undefined]
19
+ * @param {number} [params.minZoom=0]
20
+ * @param {number} [params.opacity=1]
21
+ * @param {boolean} [params.hitDetectionEnabled=true]
22
+ */
23
+ constructor({ source, style, minZoom, opacity, hitDetectionEnabled, }: {
24
+ source: VectorSource;
25
+ style?: Style | (() => Style);
26
+ minZoom?: number;
27
+ opacity?: number;
28
+ hitDetectionEnabled?: boolean;
29
+ });
30
+ dispatcher: Dispatcher;
31
+ renderer: VectorLayerRenderer;
32
+ set source(source: any);
33
+ get source(): any;
34
+ _style: Style | (() => Style);
35
+ minZoom: number;
36
+ opacity: number;
37
+ hitDetectionEnabled: boolean;
38
+ _source: any;
39
+ _extent: any;
40
+ setRawProjection(projection: any): void;
41
+ projection: any;
42
+ tearDown(): void;
43
+ set style(style: Style | (() => Style));
44
+ get style(): Style | (() => Style);
45
+ getStyleFunction(): () => Style;
46
+ /**
47
+ * Get the extent of the features in the layer.
48
+ * @returns {import("../util").Extent | null} The extent of the features in the layer, or null if the layer is empty.
49
+ */
50
+ getExtent(): import('../util').Extent | null;
51
+ findFeatures(coordinate: any): any;
52
+ renderFrame(frameState: any, targetElement: any): any;
53
+ }
54
+ export type VectorLayerOptions = Omit<ConstructorParameters<typeof VectorLayer>[0], "source">;
55
+ export type VectorLayerComponentProps = VectorLayerOptions & {
56
+ features: import('../Feature').Feature[] | import('../FeatureCollection').FeatureCollection;
57
+ };
@@ -0,0 +1,136 @@
1
+ import { VectorLayerRenderer } from "../renderers/VectorLayerRenderer.js";
2
+ import { Style } from "../styles/Style.js";
3
+ import { Stroke } from "../styles/Stroke.js";
4
+ import { combineExtents } from "../util/extent.js";
5
+ import { Dispatcher } from "../events/Dispatcher.js";
6
+ import { MapEvent } from "../events/MapEvent.js";
7
+ import { VectorSource } from "../sources/VectorSource.js";
8
+ import { useContext, useMemo, useEffect } from "preact/hooks";
9
+ import { MapContext } from "../../context/MapContext.js";
10
+ import { FeatureCollection } from "../FeatureCollection.js";
11
+ class VectorLayer {
12
+ /** @param {VectorLayerComponentProps} props */
13
+ static Component({
14
+ features: featureCollection,
15
+ style,
16
+ minZoom,
17
+ opacity,
18
+ hitDetectionEnabled = true
19
+ }) {
20
+ const { registerLayer } = useContext(MapContext);
21
+ const layer = useMemo(
22
+ () => {
23
+ const features = featureCollection instanceof FeatureCollection ? featureCollection.features : (
24
+ /** @type {import("../Feature").Feature[]} */
25
+ featureCollection
26
+ );
27
+ return VectorLayer.with(features, {
28
+ style,
29
+ minZoom,
30
+ opacity,
31
+ hitDetectionEnabled
32
+ });
33
+ },
34
+ // eslint-disable-next-line react-hooks/exhaustive-deps
35
+ [featureCollection, minZoom, opacity, hitDetectionEnabled]
36
+ );
37
+ registerLayer(layer);
38
+ useEffect(() => {
39
+ layer.style = style;
40
+ }, [style]);
41
+ return null;
42
+ }
43
+ /**
44
+ * @param {import("../Feature").Feature[]} features
45
+ * @param {VectorLayerOptions} options
46
+ */
47
+ static with(features, options) {
48
+ const source = new VectorSource({ features });
49
+ return new VectorLayer({ source, ...options });
50
+ }
51
+ /**
52
+ * @param {Object} params
53
+ * @param {VectorSource} params.source
54
+ * @param {Style | (() => Style)} [params.style=undefined]
55
+ * @param {number} [params.minZoom=0]
56
+ * @param {number} [params.opacity=1]
57
+ * @param {boolean} [params.hitDetectionEnabled=true]
58
+ */
59
+ constructor({
60
+ source,
61
+ style,
62
+ minZoom = 0,
63
+ opacity = 1,
64
+ hitDetectionEnabled = true
65
+ }) {
66
+ this.dispatcher = new Dispatcher(this);
67
+ this.renderer = new VectorLayerRenderer(this);
68
+ this.source = source;
69
+ this._style = style;
70
+ this.minZoom = minZoom;
71
+ this.opacity = opacity;
72
+ this.hitDetectionEnabled = hitDetectionEnabled;
73
+ }
74
+ get source() {
75
+ return this._source;
76
+ }
77
+ set source(source) {
78
+ if (this._source && source !== this._source) {
79
+ this._source.tearDown();
80
+ }
81
+ this._source = source;
82
+ source.on(MapEvent.CHANGE, () => {
83
+ this._extent = null;
84
+ this.dispatcher.dispatch(MapEvent.CHANGE);
85
+ });
86
+ }
87
+ setRawProjection(projection) {
88
+ this.projection = projection;
89
+ }
90
+ tearDown() {
91
+ this.dispatcher = null;
92
+ }
93
+ get style() {
94
+ if (this._style) return this._style;
95
+ const defaultStyle = new Style({
96
+ stroke: new Stroke()
97
+ });
98
+ return defaultStyle;
99
+ }
100
+ set style(style) {
101
+ this._style = style;
102
+ this.dispatcher.dispatch(MapEvent.CHANGE);
103
+ }
104
+ getStyleFunction() {
105
+ const style = this.style;
106
+ if (typeof style === "function") return style;
107
+ return () => {
108
+ return style;
109
+ };
110
+ }
111
+ /**
112
+ * Get the extent of the features in the layer.
113
+ * @returns {import("../util").Extent | null} The extent of the features in the layer, or null if the layer is empty.
114
+ */
115
+ getExtent() {
116
+ if (this._extent) return this._extent;
117
+ const features = this.source.getFeatures();
118
+ const extent = features.reduce((combinedExtent, feature) => {
119
+ const featureExtent = feature.getExtent();
120
+ if (!combinedExtent) return featureExtent;
121
+ return combineExtents(featureExtent, combinedExtent);
122
+ }, null);
123
+ this._extent = extent;
124
+ return extent;
125
+ }
126
+ findFeatures(coordinate) {
127
+ if (!this.hitDetectionEnabled) return;
128
+ return this.source.getFeaturesAtCoordinate(coordinate);
129
+ }
130
+ renderFrame(frameState, targetElement) {
131
+ return this.renderer.renderFrame(frameState, targetElement);
132
+ }
133
+ }
134
+ export {
135
+ VectorLayer
136
+ };
@@ -0,0 +1,3 @@
1
+ export * from './TextLayer';
2
+ export * from './VectorLayer';
3
+ export type Layer = import('./TextLayer').TextLayer | import('./VectorLayer').VectorLayer;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Projection functions for different map projections.
3
+ */
4
+ export type Projection = ProjectionFunction;
5
+ export namespace Projection {
6
+ let geoIdentity: {
7
+ (p: any): number[];
8
+ invert(p: any): number[];
9
+ stream(stream: any): any;
10
+ postclip(_: any, ...args: any[]): any;
11
+ clipExtent(_: any, ...args: any[]): any[][] | any;
12
+ scale(_: any, ...args: any[]): number | any;
13
+ translate(_: any, ...args: any[]): number[] | any;
14
+ angle(_: any, ...args: any[]): number | any;
15
+ reflectX(_: any, ...args: any[]): boolean | any;
16
+ reflectY(_: any, ...args: any[]): boolean | any;
17
+ fitExtent(extent: any, object: any): any;
18
+ fitSize(size: any, object: any): any;
19
+ fitWidth(width: any, object: any): any;
20
+ fitHeight(height: any, object: any): any;
21
+ };
22
+ let geoMercator: any;
23
+ let geoAlbersUS: any;
24
+ let geoAlbersUKComposite: any;
25
+ let geoAlbersEngland: any;
26
+ }
27
+ export type ProjectionFunction = (point: [number, number]) => [number, number] | null;
@@ -0,0 +1,12 @@
1
+ import { geoIdentity, geoMercator, geoAlbersUsa, geoAlbers } from "d3-geo";
2
+ import { geoAlbersUk } from "d3-composite-projections";
3
+ const Projection = {
4
+ geoIdentity: geoIdentity(),
5
+ geoMercator: geoMercator(),
6
+ geoAlbersUS: geoAlbersUsa().scale(1070).translate([487.5, 305]),
7
+ geoAlbersUKComposite: geoAlbersUk(),
8
+ geoAlbersEngland: geoAlbers().center([0, 52.7]).rotate([1.1743, 0]).parallels([50, 54])
9
+ };
10
+ export {
11
+ Projection
12
+ };
@@ -0,0 +1,16 @@
1
+ export class FeatureRenderer {
2
+ drawingFunction: any;
3
+ setStyle(style: any): void;
4
+ style: any;
5
+ setFeature(feature: any): void;
6
+ feature: any;
7
+ render(frameState: any, context: any): void;
8
+ drawPath(geometries: any, context: any, clipPath?: boolean): void;
9
+ drawStroke(frameState: any, context: any, { style, width: strokeWidth, position }: {
10
+ style: any;
11
+ width: any;
12
+ position: any;
13
+ }): void;
14
+ createCanvas(width: any, height: any): HTMLCanvasElement;
15
+ getProjectedExtent(projection: any): any;
16
+ }
@@ -0,0 +1,90 @@
1
+ import { geoPath } from "d3-geo";
2
+ import { validateGeometries, generateDebugUrl } from "../util/debug.js";
3
+ import { StrokePosition } from "../styles/Stroke.js";
4
+ import { combineExtents } from "../util/extent.js";
5
+ class FeatureRenderer {
6
+ constructor() {
7
+ this.drawingFunction = geoPath();
8
+ }
9
+ setStyle(style) {
10
+ this.style = style;
11
+ }
12
+ setFeature(feature) {
13
+ this.feature = feature;
14
+ }
15
+ render(frameState, context) {
16
+ if (!this.style) {
17
+ return;
18
+ }
19
+ const feature = this.feature;
20
+ const { projection, transform, pixelRatio } = frameState.viewState;
21
+ const { stroke, fill } = this.style;
22
+ const geometries = feature.getProjectedGeometries(projection);
23
+ if (frameState.debug) {
24
+ try {
25
+ validateGeometries(geometries);
26
+ } catch {
27
+ console.error(
28
+ `Invalid geometry. Feature skipped during rendering. Click here to inspect geometry: ${generateDebugUrl(feature)}
29
+ `,
30
+ feature
31
+ );
32
+ }
33
+ }
34
+ this.drawPath(geometries, context);
35
+ if (fill) {
36
+ context.fillStyle = fill.getRgba();
37
+ context.fill();
38
+ }
39
+ if (stroke) {
40
+ context.save();
41
+ this.drawStroke(frameState, context, {
42
+ style: stroke.getRgba(),
43
+ width: stroke.width / transform.k * pixelRatio,
44
+ position: stroke.position
45
+ });
46
+ context.restore();
47
+ }
48
+ }
49
+ drawPath(geometries, context, clipPath = false) {
50
+ this.drawingFunction.context(context);
51
+ context.beginPath();
52
+ for (const geometry of geometries) {
53
+ this.drawingFunction(geometry);
54
+ }
55
+ if (clipPath) {
56
+ context.clip();
57
+ } else {
58
+ context.closePath();
59
+ }
60
+ }
61
+ drawStroke(frameState, context, { style, width: strokeWidth, position }) {
62
+ const { projection } = frameState.viewState;
63
+ context.lineWidth = strokeWidth;
64
+ context.strokeStyle = style;
65
+ if (position === StrokePosition.INSIDE) {
66
+ context.lineWidth = strokeWidth * 2;
67
+ const geometries = this.feature.getProjectedGeometries(projection);
68
+ this.drawPath(geometries, context, true);
69
+ }
70
+ context.stroke();
71
+ }
72
+ createCanvas(width, height) {
73
+ const canvas = document.createElement("canvas");
74
+ canvas.width = width;
75
+ canvas.height = height;
76
+ return canvas;
77
+ }
78
+ getProjectedExtent(projection) {
79
+ const geometries = this.feature.getProjectedGeometries(projection);
80
+ const extent = geometries.reduce((combinedExtent, geometry) => {
81
+ const bounds = this.drawingFunction.bounds(geometry);
82
+ if (!combinedExtent) return bounds;
83
+ return combineExtents(bounds, combinedExtent);
84
+ }, null);
85
+ return extent;
86
+ }
87
+ }
88
+ export {
89
+ FeatureRenderer
90
+ };
@@ -0,0 +1,6 @@
1
+ export class MapRenderer {
2
+ constructor(map: any);
3
+ map: any;
4
+ _element: HTMLDivElement;
5
+ renderFrame(frameState: any): void;
6
+ }
@@ -0,0 +1,53 @@
1
+ import { replaceChildren } from "../util/dom.js";
2
+ import RBush from "rbush";
3
+ class MapRenderer {
4
+ constructor(map) {
5
+ this.map = map;
6
+ this._element = document.createElement("div");
7
+ this._element.className = "gv-layer-container";
8
+ const style = this._element.style;
9
+ style.position = "absolute";
10
+ style.width = "100%";
11
+ style.height = "100%";
12
+ style.zIndex = "0";
13
+ const container = map.viewPort;
14
+ container.insertBefore(this._element, container.firstChild || null);
15
+ }
16
+ renderFrame(frameState) {
17
+ const { zoomLevel, projection } = frameState.viewState;
18
+ const layers = this.map.layers;
19
+ const mapElements = [];
20
+ let previousElement = null;
21
+ const visibleLayers = layers.filter((layer) => {
22
+ return zoomLevel > (layer.minZoom || 0);
23
+ });
24
+ const renderLayer = (layer, declutterTree2) => {
25
+ const viewState = frameState.viewState;
26
+ if (layer.projection) {
27
+ viewState.projection = layer.projection;
28
+ }
29
+ const element = layer.renderFrame(
30
+ { ...frameState, viewState, declutterTree: declutterTree2 },
31
+ previousElement
32
+ );
33
+ if (element !== previousElement) {
34
+ mapElements.push(element);
35
+ previousElement = element;
36
+ }
37
+ viewState.projection = projection;
38
+ };
39
+ const baseLayers = visibleLayers.filter((layer) => !layer.declutter);
40
+ for (const layer of baseLayers) {
41
+ renderLayer(layer);
42
+ }
43
+ const declutterTree = new RBush();
44
+ const layersToDeclutter = [...visibleLayers].filter((layer) => !!layer.declutter).reverse();
45
+ for (const layer of layersToDeclutter) {
46
+ renderLayer(layer, declutterTree);
47
+ }
48
+ replaceChildren(this._element, mapElements);
49
+ }
50
+ }
51
+ export {
52
+ MapRenderer
53
+ };
@@ -0,0 +1,21 @@
1
+ import { FeatureRenderer } from './FeatureRenderer';
2
+ export class TextLayerRenderer {
3
+ constructor(layer: any);
4
+ layer: any;
5
+ featureRenderer: FeatureRenderer;
6
+ _element: HTMLDivElement;
7
+ renderFrame(frameState: any, targetElement: any): any;
8
+ getTextElementWithID(id: any): Element;
9
+ styleTextElement(element: any, textStyle: any, position: any): void;
10
+ getElementSize(element: any): {
11
+ width: any;
12
+ height: any;
13
+ };
14
+ getElementBBox(element: any, textStyle: any, position: any): {
15
+ minX: number;
16
+ minY: number;
17
+ maxX: number;
18
+ maxY: number;
19
+ };
20
+ getCollisionBoxElement(bbox: any): HTMLDivElement;
21
+ }