maplibre-gl 2.1.0 → 2.1.4

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 (308) hide show
  1. package/build/{banner.js → banner.ts} +1 -1
  2. package/build/generate-query-test-fixtures.ts +123 -0
  3. package/build/generate-shaders.ts +35 -0
  4. package/build/generate-struct-arrays.ts +7 -7
  5. package/build/generate-style-code.ts +8 -8
  6. package/build/generate-style-spec.ts +5 -4
  7. package/build/generate-typings.ts +16 -0
  8. package/build/readme.md +8 -18
  9. package/build/release-notes.js +9 -13
  10. package/build/{rollup_plugin_minify_style_spec.js → rollup_plugin_minify_style_spec.ts} +4 -3
  11. package/build/{rollup_plugins.js → rollup_plugins.ts} +12 -26
  12. package/dist/maplibre-gl-dev.js +54885 -0
  13. package/dist/maplibre-gl.css +1 -1
  14. package/dist/maplibre-gl.d.ts +1537 -1011
  15. package/dist/maplibre-gl.js +3 -3
  16. package/dist/maplibre-gl.js.map +1 -1
  17. package/package.json +83 -107
  18. package/postinstall.js +5 -0
  19. package/src/css/maplibre-gl.css +28 -28
  20. package/src/data/{array_types.ts → array_types.g.ts} +0 -0
  21. package/src/data/bucket/circle_bucket.ts +1 -1
  22. package/src/data/bucket/fill_bucket.test.ts +1 -1
  23. package/src/data/bucket/fill_bucket.ts +4 -4
  24. package/src/data/bucket/fill_extrusion_bucket.ts +1 -1
  25. package/src/data/bucket/line_bucket.test.ts +1 -1
  26. package/src/data/bucket/line_bucket.ts +6 -6
  27. package/src/data/bucket/symbol_bucket.test.ts +16 -16
  28. package/src/data/bucket/symbol_bucket.ts +53 -53
  29. package/src/data/bucket.ts +43 -43
  30. package/src/data/dem_data.ts +12 -12
  31. package/src/data/evaluation_feature.ts +10 -10
  32. package/src/data/feature_index.ts +37 -37
  33. package/src/data/feature_position_map.ts +5 -5
  34. package/src/data/index_array_type.ts +1 -1
  35. package/src/data/load_geometry.test.ts +1 -1
  36. package/src/data/program_configuration.ts +46 -46
  37. package/src/data/segment.ts +14 -14
  38. package/src/geo/edge_insets.ts +2 -2
  39. package/src/geo/lng_lat.ts +4 -4
  40. package/src/geo/lng_lat_bounds.ts +35 -35
  41. package/src/geo/mercator_coordinate.ts +5 -5
  42. package/src/geo/transform.test.ts +1 -1
  43. package/src/geo/transform.ts +14 -14
  44. package/src/gl/context.ts +3 -3
  45. package/src/gl/types.ts +19 -19
  46. package/src/gl/value.ts +6 -6
  47. package/src/gl/vertex_buffer.test.ts +1 -1
  48. package/src/index.ts +24 -9
  49. package/src/render/draw_circle.ts +8 -8
  50. package/src/render/draw_collision_debug.ts +5 -5
  51. package/src/render/draw_line.ts +4 -4
  52. package/src/render/draw_symbol.ts +21 -21
  53. package/src/render/glyph_atlas.ts +12 -12
  54. package/src/render/glyph_manager.test.ts +10 -21
  55. package/src/render/glyph_manager.ts +33 -32
  56. package/src/render/image_manager.ts +4 -4
  57. package/src/render/painter.ts +11 -11
  58. package/src/render/program/background_program.ts +29 -29
  59. package/src/render/program/circle_program.ts +10 -10
  60. package/src/render/program/clipping_mask_program.ts +1 -1
  61. package/src/render/program/collision_program.ts +9 -9
  62. package/src/render/program/debug_program.ts +4 -4
  63. package/src/render/program/fill_extrusion_program.ts +31 -31
  64. package/src/render/program/fill_program.ts +29 -29
  65. package/src/render/program/heatmap_program.ts +12 -12
  66. package/src/render/program/hillshade_program.ts +12 -12
  67. package/src/render/program/line_program.ts +38 -38
  68. package/src/render/program/pattern.ts +28 -28
  69. package/src/render/program/raster_program.ts +21 -21
  70. package/src/render/program/symbol_program.ts +96 -96
  71. package/src/render/program.ts +25 -25
  72. package/src/render/texture.ts +9 -9
  73. package/src/render/uniform_binding.ts +1 -1
  74. package/src/render/vertex_array_object.ts +13 -13
  75. package/src/shaders/_prelude.fragment.glsl.g.ts +2 -0
  76. package/src/shaders/_prelude.vertex.glsl.g.ts +2 -0
  77. package/src/shaders/background.fragment.glsl.g.ts +2 -0
  78. package/src/shaders/background.vertex.glsl.g.ts +2 -0
  79. package/src/shaders/background_pattern.fragment.glsl.g.ts +2 -0
  80. package/src/shaders/background_pattern.vertex.glsl.g.ts +2 -0
  81. package/src/shaders/circle.fragment.glsl.g.ts +2 -0
  82. package/src/shaders/circle.vertex.glsl.g.ts +2 -0
  83. package/src/shaders/clipping_mask.fragment.glsl.g.ts +2 -0
  84. package/src/shaders/clipping_mask.vertex.glsl.g.ts +2 -0
  85. package/src/shaders/collision_box.fragment.glsl.g.ts +2 -0
  86. package/src/shaders/collision_box.vertex.glsl.g.ts +2 -0
  87. package/src/shaders/collision_circle.fragment.glsl.g.ts +2 -0
  88. package/src/shaders/collision_circle.vertex.glsl.g.ts +2 -0
  89. package/src/shaders/debug.fragment.glsl.g.ts +2 -0
  90. package/src/shaders/debug.vertex.glsl.g.ts +2 -0
  91. package/src/shaders/fill.fragment.glsl.g.ts +2 -0
  92. package/src/shaders/fill.vertex.glsl.g.ts +2 -0
  93. package/src/shaders/fill_extrusion.fragment.glsl.g.ts +2 -0
  94. package/src/shaders/fill_extrusion.vertex.glsl.g.ts +2 -0
  95. package/src/shaders/fill_extrusion_pattern.fragment.glsl.g.ts +2 -0
  96. package/src/shaders/fill_extrusion_pattern.vertex.glsl.g.ts +2 -0
  97. package/src/shaders/fill_outline.fragment.glsl.g.ts +2 -0
  98. package/src/shaders/fill_outline.vertex.glsl.g.ts +2 -0
  99. package/src/shaders/fill_outline_pattern.fragment.glsl.g.ts +2 -0
  100. package/src/shaders/fill_outline_pattern.vertex.glsl.g.ts +2 -0
  101. package/src/shaders/fill_pattern.fragment.glsl.g.ts +2 -0
  102. package/src/shaders/fill_pattern.vertex.glsl.g.ts +2 -0
  103. package/src/shaders/heatmap.fragment.glsl.g.ts +2 -0
  104. package/src/shaders/heatmap.vertex.glsl.g.ts +2 -0
  105. package/src/shaders/heatmap_texture.fragment.glsl.g.ts +2 -0
  106. package/src/shaders/heatmap_texture.vertex.glsl.g.ts +2 -0
  107. package/src/shaders/hillshade.fragment.glsl.g.ts +2 -0
  108. package/src/shaders/hillshade.vertex.glsl.g.ts +2 -0
  109. package/src/shaders/hillshade_prepare.fragment.glsl.g.ts +2 -0
  110. package/src/shaders/hillshade_prepare.vertex.glsl.g.ts +2 -0
  111. package/src/shaders/line.fragment.glsl.g.ts +2 -0
  112. package/src/shaders/line.vertex.glsl.g.ts +2 -0
  113. package/src/shaders/line_gradient.fragment.glsl.g.ts +2 -0
  114. package/src/shaders/line_gradient.vertex.glsl.g.ts +2 -0
  115. package/src/shaders/line_pattern.fragment.glsl.g.ts +2 -0
  116. package/src/shaders/line_pattern.vertex.glsl.g.ts +2 -0
  117. package/src/shaders/line_sdf.fragment.glsl.g.ts +2 -0
  118. package/src/shaders/line_sdf.vertex.glsl.g.ts +2 -0
  119. package/src/shaders/raster.fragment.glsl.g.ts +2 -0
  120. package/src/shaders/raster.vertex.glsl.g.ts +2 -0
  121. package/src/shaders/shaders.ts +52 -55
  122. package/src/shaders/symbol_icon.fragment.glsl.g.ts +2 -0
  123. package/src/shaders/symbol_icon.vertex.glsl.g.ts +2 -0
  124. package/src/shaders/symbol_sdf.fragment.glsl.g.ts +2 -0
  125. package/src/shaders/symbol_sdf.vertex.glsl.g.ts +2 -0
  126. package/src/shaders/symbol_text_and_icon.fragment.glsl.g.ts +2 -0
  127. package/src/shaders/symbol_text_and_icon.vertex.glsl.g.ts +2 -0
  128. package/src/source/canvas_source.test.ts +11 -12
  129. package/src/source/canvas_source.ts +4 -4
  130. package/src/source/geojson_worker_source.ts +23 -23
  131. package/src/source/geojson_wrapper.ts +8 -8
  132. package/src/source/image_source.test.ts +2 -2
  133. package/src/source/image_source.ts +6 -6
  134. package/src/source/pixels_to_tile_units.ts +6 -6
  135. package/src/source/query_features.ts +20 -20
  136. package/src/source/raster_dem_tile_source.test.ts +2 -2
  137. package/src/source/raster_tile_source.test.ts +2 -2
  138. package/src/source/rtl_text_plugin.ts +10 -10
  139. package/src/source/source.ts +29 -29
  140. package/src/source/source_cache.test.ts +32 -0
  141. package/src/source/source_cache.ts +7 -5
  142. package/src/source/source_state.ts +1 -1
  143. package/src/source/tile.test.ts +3 -3
  144. package/src/source/tile.ts +15 -15
  145. package/src/source/tile_cache.test.ts +6 -4
  146. package/src/source/tile_cache.ts +6 -6
  147. package/src/source/tile_id.test.ts +0 -1
  148. package/src/source/vector_tile_source.test.ts +16 -5
  149. package/src/source/vector_tile_source.ts +2 -3
  150. package/src/source/vector_tile_worker_source.test.ts +4 -4
  151. package/src/source/vector_tile_worker_source.ts +5 -5
  152. package/src/source/worker.test.ts +1 -1
  153. package/src/source/worker.ts +22 -22
  154. package/src/source/worker_source.ts +56 -56
  155. package/src/source/worker_tile.ts +4 -4
  156. package/src/style/evaluation_parameters.ts +3 -3
  157. package/src/style/format_section_override.test.ts +1 -1
  158. package/src/style/light.ts +10 -10
  159. package/src/style/load_glyph_range.test.ts +3 -5
  160. package/src/style/load_glyph_range.ts +6 -6
  161. package/src/style/load_sprite.ts +4 -4
  162. package/src/style/pauseable_placement.ts +1 -1
  163. package/src/style/properties.ts +69 -69
  164. package/src/style/query_utils.ts +7 -7
  165. package/src/style/style.test.ts +22 -15
  166. package/src/style/style.ts +29 -29
  167. package/src/style/style_glyph.ts +8 -8
  168. package/src/style/style_image.ts +58 -58
  169. package/src/style/style_layer/background_style_layer.ts +2 -2
  170. package/src/style/style_layer/{background_style_layer_properties.ts → background_style_layer_properties.g.ts} +0 -0
  171. package/src/style/style_layer/circle_style_layer.ts +10 -10
  172. package/src/style/style_layer/{circle_style_layer_properties.ts → circle_style_layer_properties.g.ts} +0 -0
  173. package/src/style/style_layer/custom_style_layer.ts +17 -17
  174. package/src/style/style_layer/fill_extrusion_style_layer.ts +10 -10
  175. package/src/style/style_layer/{fill_extrusion_style_layer_properties.ts → fill_extrusion_style_layer_properties.g.ts} +0 -0
  176. package/src/style/style_layer/fill_style_layer.ts +9 -9
  177. package/src/style/style_layer/{fill_style_layer_properties.ts → fill_style_layer_properties.g.ts} +0 -0
  178. package/src/style/style_layer/heatmap_style_layer.ts +2 -2
  179. package/src/style/style_layer/{heatmap_style_layer_properties.ts → heatmap_style_layer_properties.g.ts} +0 -0
  180. package/src/style/style_layer/hillshade_style_layer.ts +2 -2
  181. package/src/style/style_layer/{hillshade_style_layer_properties.ts → hillshade_style_layer_properties.g.ts} +0 -0
  182. package/src/style/style_layer/line_style_layer.ts +9 -9
  183. package/src/style/style_layer/{line_style_layer_properties.ts → line_style_layer_properties.g.ts} +0 -0
  184. package/src/style/style_layer/raster_style_layer.ts +2 -2
  185. package/src/style/style_layer/{raster_style_layer_properties.ts → raster_style_layer_properties.g.ts} +0 -0
  186. package/src/style/style_layer/symbol_style_layer.ts +7 -7
  187. package/src/style/style_layer/{symbol_style_layer_properties.ts → symbol_style_layer_properties.g.ts} +0 -0
  188. package/src/style/style_layer.ts +10 -10
  189. package/src/style/style_layer_index.ts +3 -3
  190. package/src/style/validate_style.ts +15 -15
  191. package/src/style-spec/error/validation_error.ts +1 -1
  192. package/src/style-spec/expression/compound_expression.ts +3 -3
  193. package/src/style-spec/expression/definitions/format.ts +11 -11
  194. package/src/style-spec/expression/definitions/interpolate.ts +5 -5
  195. package/src/style-spec/expression/definitions/match.ts +2 -2
  196. package/src/style-spec/expression/definitions/number_format.ts +11 -11
  197. package/src/style-spec/expression/expression.ts +8 -8
  198. package/src/style-spec/expression/index.ts +97 -97
  199. package/src/style-spec/expression/parsing_context.ts +11 -11
  200. package/src/style-spec/expression/types/collator.ts +9 -9
  201. package/src/style-spec/expression/types/resolved_image.ts +2 -2
  202. package/src/style-spec/expression/types.ts +14 -14
  203. package/src/style-spec/expression/values.ts +1 -1
  204. package/src/style-spec/feature_filter/index.ts +66 -66
  205. package/src/style-spec/function/convert.ts +3 -3
  206. package/src/style-spec/style-spec.ts +44 -44
  207. package/src/style-spec/util/color_spaces.ts +8 -8
  208. package/src/style-spec/util/result.ts +4 -4
  209. package/src/style-spec/validate/validate_filter.ts +58 -58
  210. package/src/style-spec/validate/validate_source.ts +63 -63
  211. package/src/style-spec/visit.ts +11 -11
  212. package/src/symbol/collision_feature.test.ts +1 -1
  213. package/src/symbol/collision_feature.ts +10 -10
  214. package/src/symbol/collision_index.ts +26 -26
  215. package/src/symbol/cross_tile_symbol_index.ts +17 -17
  216. package/src/symbol/get_anchors.ts +16 -16
  217. package/src/symbol/grid_index.ts +7 -7
  218. package/src/symbol/placement.ts +72 -72
  219. package/src/symbol/projection.ts +30 -30
  220. package/src/symbol/quads.ts +30 -30
  221. package/src/symbol/shaping.ts +160 -160
  222. package/src/symbol/symbol_layout.ts +119 -119
  223. package/src/symbol/symbol_size.ts +29 -29
  224. package/src/symbol/symbol_style_layer.test.ts +1 -1
  225. package/src/types/cancelable.ts +1 -1
  226. package/src/types/tilejson.ts +13 -13
  227. package/src/ui/anchor.ts +1 -1
  228. package/src/ui/camera.test.ts +9 -9
  229. package/src/ui/camera.ts +18 -18
  230. package/src/ui/control/attribution_control.test.ts +51 -16
  231. package/src/ui/control/attribution_control.ts +35 -16
  232. package/src/ui/control/control.ts +40 -40
  233. package/src/ui/control/fullscreen_control.ts +1 -1
  234. package/src/ui/control/geolocate_control.test.ts +1 -1
  235. package/src/ui/control/geolocate_control.ts +102 -102
  236. package/src/ui/control/logo_control.test.ts +5 -4
  237. package/src/ui/control/navigation_control.ts +3 -3
  238. package/src/ui/control/scale_control.test.ts +2 -2
  239. package/src/ui/control/scale_control.ts +5 -5
  240. package/src/ui/events.ts +289 -200
  241. package/src/ui/handler/box_zoom.test.ts +1 -1
  242. package/src/ui/handler/box_zoom.ts +1 -1
  243. package/src/ui/handler/dblclick_zoom.test.ts +1 -1
  244. package/src/ui/handler/drag_pan.test.ts +1 -1
  245. package/src/ui/handler/drag_rotate.test.ts +1 -1
  246. package/src/ui/handler/keyboard.test.ts +1 -1
  247. package/src/ui/handler/keyboard.ts +51 -51
  248. package/src/ui/handler/map_event.test.ts +1 -1
  249. package/src/ui/handler/map_event.ts +1 -1
  250. package/src/ui/handler/mouse.ts +1 -1
  251. package/src/ui/handler/mouse_rotate.test.ts +1 -1
  252. package/src/ui/handler/scroll_zoom.test.ts +3 -2
  253. package/src/ui/handler/scroll_zoom.ts +9 -9
  254. package/src/ui/handler/shim/drag_pan.ts +4 -4
  255. package/src/ui/handler/shim/drag_rotate.ts +1 -1
  256. package/src/ui/handler/shim/touch_zoom_rotate.ts +1 -1
  257. package/src/ui/handler/tap_recognizer.ts +4 -4
  258. package/src/ui/handler/touch_pan.ts +2 -2
  259. package/src/ui/handler/touch_zoom_rotate.test.ts +1 -1
  260. package/src/ui/handler/touch_zoom_rotate.ts +1 -1
  261. package/src/ui/handler_inertia.ts +6 -6
  262. package/src/ui/handler_manager.ts +44 -44
  263. package/src/ui/map/isMoving.test.ts +1 -1
  264. package/src/ui/map/isRotating.test.ts +1 -1
  265. package/src/ui/map/isZooming.test.ts +1 -1
  266. package/src/ui/map.test.ts +26 -14
  267. package/src/ui/map.ts +107 -102
  268. package/src/ui/map_events.test.ts +1 -1
  269. package/src/ui/marker.test.ts +12 -12
  270. package/src/ui/marker.ts +37 -37
  271. package/src/ui/popup.test.ts +7 -7
  272. package/src/ui/popup.ts +9 -9
  273. package/src/util/actor.test.ts +41 -10
  274. package/src/util/actor.ts +8 -8
  275. package/src/util/ajax.test.ts +29 -21
  276. package/src/util/ajax.ts +51 -30
  277. package/src/util/browser.ts +1 -1
  278. package/src/util/classify_rings.test.ts +1 -1
  279. package/src/util/color_ramp.ts +5 -5
  280. package/src/util/config.ts +2 -2
  281. package/src/util/dispatcher.ts +1 -1
  282. package/src/util/dom.ts +2 -2
  283. package/src/util/evented.ts +1 -1
  284. package/src/util/find_pole_of_inaccessibility.ts +3 -3
  285. package/src/util/image.ts +5 -5
  286. package/src/util/performance.ts +7 -7
  287. package/src/util/request_manager.ts +4 -4
  288. package/src/util/resolve_tokens.ts +4 -4
  289. package/src/util/struct_array.test.ts +1 -1
  290. package/src/util/struct_array.ts +15 -15
  291. package/src/util/task_queue.ts +3 -3
  292. package/src/util/tile_request_cache.ts +3 -3
  293. package/src/util/transferable_grid_index.ts +4 -4
  294. package/src/util/util.ts +8 -8
  295. package/src/util/web_worker.ts +4 -68
  296. package/src/util/web_worker_transfer.test.ts +3 -0
  297. package/src/util/web_worker_transfer.ts +21 -17
  298. package/src/util/worker_pool.ts +1 -1
  299. package/build/.eslintrc +0 -21
  300. package/build/glsl_to_js.js +0 -12
  301. package/build/post-ts-build.js +0 -43
  302. package/build/release-notes.md.ejs +0 -8
  303. package/build/test/build-tape.js +0 -17
  304. package/build/web_worker_replacement.js +0 -5
  305. package/dist/package.json +0 -1
  306. package/src/style-spec/validate_spec.test.ts +0 -29
  307. package/src/symbol/shaping.test.ts +0 -392
  308. package/src/types/glsl.d.ts +0 -4
@@ -1,4 +1,4 @@
1
1
  import fs from 'fs';
2
2
 
3
- const version = JSON.parse(fs.readFileSync('package.json')).version;
3
+ const version = JSON.parse(fs.readFileSync('package.json').toString()).version;
4
4
  export default `/* MapLibre GL JS is licensed under the 3-Clause BSD License. Full text of license: https://github.com/maplibre/maplibre-gl-js/blob/v${version}/LICENSE.txt */`;
@@ -0,0 +1,123 @@
1
+ import path from 'path';
2
+ import fs from 'fs';
3
+ import glob from 'glob';
4
+ import localizeURLs from '../test/integration/lib/localize-urls';
5
+
6
+ const OUTPUT_FILE = 'fixtures.json';
7
+ const rootFixturePath = 'test/integration/query/';
8
+ const suitePath = 'tests';
9
+
10
+ /**
11
+ * Analyzes the contents of the specified `path.join(rootDirectory, suiteDirectory)`, and inlines
12
+ * the contents into a single json file which can then be imported and built into a bundle
13
+ * to be shipped to the browser.
14
+ * @param rootDirectory - The root directory
15
+ * @param suiteDirectory - The suite directory
16
+ * @param outputDirectory - The output directory
17
+ * @param includeImages - Flag to include images
18
+ */
19
+ function generateFixtureJson(rootDirectory: string, suiteDirectory: string, outputDirectory: string = 'test/integration/query/dist', includeImages:boolean = false) {
20
+ const globs = getAllFixtureGlobs(rootDirectory, suiteDirectory);
21
+ const jsonPaths = globs[0];
22
+ const imagePaths = globs[1];
23
+ //Extract the filedata into a flat dictionary
24
+ const allFiles = {};
25
+ let allPaths = glob.sync(jsonPaths);
26
+ if (includeImages) {
27
+ allPaths = allPaths.concat(glob.sync(imagePaths));
28
+ }
29
+
30
+ //A Set that stores test names that are malformed so they can be removed later
31
+ const malformedTests = {};
32
+
33
+ for (const fixturePath of allPaths) {
34
+ const testName = path.dirname(fixturePath);
35
+ const fileName = path.basename(fixturePath);
36
+ const extension = path.extname(fixturePath);
37
+ try {
38
+ if (extension === '.json') {
39
+ let json = parseJsonFromFile(fixturePath);
40
+
41
+ //Special case for style json which needs some preprocessing
42
+ if (fileName === 'style.json') {
43
+ json = processStyle(testName, json);
44
+ }
45
+
46
+ allFiles[fixturePath] = json;
47
+ } else if (extension === '.png') {
48
+ allFiles[fixturePath] = pngToBase64Str(fixturePath);
49
+ } else {
50
+ throw new Error(`${extension} is incompatible , file path ${fixturePath}`);
51
+ }
52
+ } catch (e) {
53
+ console.log(`Error parsing file: ${fixturePath}`);
54
+ malformedTests[testName] = true;
55
+ }
56
+ }
57
+
58
+ // Re-nest by directory path, each directory path defines a testcase.
59
+ const result = {};
60
+ for (const fullPath in allFiles) {
61
+ const testName = path.dirname(fullPath).replace(rootDirectory, '');
62
+ //Skip if test is malformed
63
+ if (malformedTests[testName]) { continue; }
64
+
65
+ //Lazily initaialize an object to store each file wihin a particular testName
66
+ if (result[testName] == null) {
67
+ result[testName] = {};
68
+ }
69
+ //Trim extension from filename
70
+ const fileName = path.basename(fullPath, path.extname(fullPath));
71
+ result[testName][fileName] = allFiles[fullPath];
72
+ }
73
+
74
+ const outputStr = JSON.stringify(result, null, 4);
75
+ const outputPath = path.join(outputDirectory, OUTPUT_FILE);
76
+
77
+ return new Promise<void>((resolve, reject) => {
78
+ fs.writeFile(outputPath, outputStr, {encoding: 'utf8'}, (err) => {
79
+ if (err) { reject(err); }
80
+
81
+ resolve();
82
+ });
83
+ });
84
+ }
85
+
86
+ function getAllFixtureGlobs(rootDirectory, suiteDirectory) {
87
+ const basePath = path.join(rootDirectory, suiteDirectory);
88
+ const jsonPaths = path.join(basePath, '/**/*.json');
89
+ const imagePaths = path.join(basePath, '/**/*.png');
90
+
91
+ return [jsonPaths, imagePaths];
92
+ }
93
+
94
+ function parseJsonFromFile(filePath) {
95
+ return JSON.parse(fs.readFileSync(filePath, {encoding: 'utf8'}));
96
+ }
97
+
98
+ function pngToBase64Str(filePath) {
99
+ return fs.readFileSync(filePath).toString('base64');
100
+ }
101
+
102
+ function processStyle(testName, style) {
103
+ const clone = JSON.parse(JSON.stringify(style));
104
+
105
+ localizeURLs(clone, 7357);
106
+
107
+ clone.metadata = clone.metadata || {};
108
+
109
+ // eslint-disable-next-line no-restricted-properties
110
+ clone.metadata.test = Object.assign({
111
+ testName,
112
+ width: 512,
113
+ height: 512,
114
+ pixelRatio: 1,
115
+ recycleMap: false,
116
+ allowed: 0.00015
117
+ }, clone.metadata.test);
118
+
119
+ return clone;
120
+ }
121
+
122
+ // @ts-ignore
123
+ await generateFixtureJson(rootFixturePath, suitePath);
@@ -0,0 +1,35 @@
1
+ import fs from 'fs';
2
+ import glob from 'glob';
3
+
4
+ console.log('Generating shaders');
5
+
6
+ /**
7
+ * This script is intended to copy the glsl file to the compilation output folder,
8
+ * change their extension to .js and export the shaders as strings in javascript.
9
+ * It will also minify them a bit if needed and change the extension to .js
10
+ * After that it will create a combined typescript definition file and manipulate it a bit
11
+ * It will also create a simple package.json file to allow importing this package in webpack
12
+ */
13
+
14
+ glob('./src/shaders/*.glsl', null, (_err, files) => {
15
+ for (const file of files) {
16
+ const code = fs.readFileSync(file, 'utf8');
17
+ const content = glslToTs(code);
18
+ const fileName = `./src/shaders/${file.split('/').splice(-1)}.g.ts`;
19
+ fs.writeFileSync(fileName, content);
20
+ }
21
+ console.log(`Finished converting ${files.length} glsl files`);
22
+ });
23
+
24
+ function glslToTs(code: string): string {
25
+ code = code
26
+ .trim() // strip whitespace at the start/end
27
+ .replace(/\s*\/\/[^\n]*\n/g, '\n') // strip double-slash comments
28
+ .replace(/\n+/g, '\n') // collapse multi line breaks
29
+ .replace(/\n\s+/g, '\n') // strip identation
30
+ .replace(/\s?([+-\/*=,])\s?/g, '$1') // strip whitespace around operators
31
+ .replace(/([;\(\),\{\}])\n(?=[^#])/g, '$1'); // strip more line breaks
32
+
33
+ return `// This file is generated. Edit build/generate-shaders.ts, then run \`npm run codegen\`.
34
+ export default ${JSON.stringify(code).replaceAll('"', '\'')};\n`;
35
+ }
@@ -166,26 +166,26 @@ createStructArrayType('symbol_line_vertex', lineVertex, true);
166
166
  // feature index array
167
167
  createStructArrayType('feature_index', createLayout([
168
168
  // the index of the feature in the original vectortile
169
- { type: 'Uint32', name: 'featureIndex' },
169
+ {type: 'Uint32', name: 'featureIndex'},
170
170
  // the source layer the feature appears in
171
- { type: 'Uint16', name: 'sourceLayerIndex' },
171
+ {type: 'Uint16', name: 'sourceLayerIndex'},
172
172
  // the bucket the feature appears in
173
- { type: 'Uint16', name: 'bucketIndex' }
173
+ {type: 'Uint16', name: 'bucketIndex'}
174
174
  ]), true);
175
175
 
176
176
  // triangle index array
177
177
  createStructArrayType('triangle_index', createLayout([
178
- { type: 'Uint16', name: 'vertices', components: 3 }
178
+ {type: 'Uint16', name: 'vertices', components: 3}
179
179
  ]));
180
180
 
181
181
  // line index array
182
182
  createStructArrayType('line_index', createLayout([
183
- { type: 'Uint16', name: 'vertices', components: 2 }
183
+ {type: 'Uint16', name: 'vertices', components: 2}
184
184
  ]));
185
185
 
186
186
  // line strip index array
187
187
  createStructArrayType('line_strip_index', createLayout([
188
- { type: 'Uint16', name: 'vertices', components: 1 }
188
+ {type: 'Uint16', name: 'vertices', components: 1}
189
189
  ]));
190
190
 
191
191
  // paint vertex arrays
@@ -422,7 +422,7 @@ register('${structArrayClass}', ${structArrayClass});
422
422
  return output.join('\n');
423
423
  }
424
424
 
425
- fs.writeFileSync('src/data/array_types.ts',
425
+ fs.writeFileSync('src/data/array_types.g.ts',
426
426
  `// This file is generated. Edit build/generate-struct-arrays.ts, then run \`npm run codegen\`.
427
427
 
428
428
  import assert from 'assert';
@@ -5,13 +5,13 @@ import * as fs from 'fs';
5
5
  import spec from '../src/style-spec/reference/v8.json';
6
6
 
7
7
  function camelCase(str: string): string {
8
- return str.replace(/-(.)/g, function (_, x) {
9
- return x.toUpperCase();
8
+ return str.replace(/-(.)/g, (_, x) => {
9
+ return x.toUpperCase();
10
10
  });
11
11
  }
12
12
 
13
13
  function pascalCase(str: string): string {
14
- let almostCamelized = camelCase(str);
14
+ const almostCamelized = camelCase(str);
15
15
  return almostCamelized[0].toUpperCase() + almostCamelized.slice(1);
16
16
  }
17
17
 
@@ -37,7 +37,7 @@ function nativeType(property) {
37
37
  } else {
38
38
  return `Array<${nativeType({type: property.value, values: property.values})}>`;
39
39
  }
40
- default: throw new Error(`unknown type for ${property.name}`)
40
+ default: throw new Error(`unknown type for ${property.name}`);
41
41
  }
42
42
  }
43
43
 
@@ -97,7 +97,7 @@ function runtimeType(property) {
97
97
  } else {
98
98
  return `array(${runtimeType({type: property.value})})`;
99
99
  }
100
- default: throw new Error(`unknown type for ${property.name}`)
100
+ default: throw new Error(`unknown type for ${property.name}`);
101
101
  }
102
102
  }
103
103
 
@@ -146,7 +146,7 @@ const layers = Object.keys(spec.layer.type.values).map((type) => {
146
146
  return memo;
147
147
  }, []);
148
148
 
149
- return { type, layoutProperties, paintProperties };
149
+ return {type, layoutProperties, paintProperties};
150
150
  });
151
151
 
152
152
  function emitlayerProperties(locals) {
@@ -264,12 +264,12 @@ const paint: Properties<${layerType}PaintProps> = new Properties({`);
264
264
  `});
265
265
 
266
266
  export default ({ paint${layoutProperties.length ? ', layout' : ''} } as {
267
- paint: Properties<${layerType}PaintProps>${layoutProperties.length ? ',\n layout: Properties<' + layerType + 'LayoutProps>' : ''}
267
+ paint: Properties<${layerType}PaintProps>${layoutProperties.length ? `,\n layout: Properties<${layerType}LayoutProps>` : ''}
268
268
  });`);
269
269
 
270
270
  return output.join('\n');
271
271
  }
272
272
 
273
273
  for (const layer of layers) {
274
- fs.writeFileSync(`src/style/style_layer/${layer.type.replace('-', '_')}_style_layer_properties.ts`, emitlayerProperties(layer))
274
+ fs.writeFileSync(`src/style/style_layer/${layer.type.replace('-', '_')}_style_layer_properties.g.ts`, emitlayerProperties(layer));
275
275
  }
@@ -24,13 +24,14 @@ function propertyType(property) {
24
24
  return property.type;
25
25
  case 'enum':
26
26
  return unionType(property.values);
27
- case 'array':
28
- const elementType = propertyType(typeof property.value === 'string' ? {type: property.value, values: property.values} : property.value)
27
+ case 'array': {
28
+ const elementType = propertyType(typeof property.value === 'string' ? {type: property.value, values: property.values} : property.value);
29
29
  if (property.length) {
30
30
  return `[${Array(property.length).fill(elementType).join(', ')}]`;
31
31
  } else {
32
32
  return `Array<${elementType}>`;
33
33
  }
34
+ }
34
35
  case 'light':
35
36
  return 'LightSpecification';
36
37
  case 'sources':
@@ -67,7 +68,7 @@ ${Object.keys(properties)
67
68
  .filter(k => k !== '*')
68
69
  .map(k => ` ${indent}${propertyDeclaration(k, properties[k])}`)
69
70
  .join(',\n')}
70
- ${indent}}`
71
+ ${indent}}`;
71
72
  }
72
73
 
73
74
  function sourceTypeName(key) {
@@ -114,7 +115,7 @@ function layerType(key) {
114
115
  const layerTypes = Object.keys(spec.layer.type.values);
115
116
 
116
117
  fs.writeFileSync('src/style-spec/types.ts',
117
- `// Generated code; do not edit. Edit build/generate-style-spec.ts instead.
118
+ `// Generated code; do not edit. Edit build/generate-style-spec.ts instead.
118
119
  /* eslint-disable */
119
120
 
120
121
  export type ColorSpecification = string;
@@ -0,0 +1,16 @@
1
+
2
+ import fs from 'fs';
3
+ import childProcess from 'child_process';
4
+
5
+ if (!fs.existsSync('dist')) {
6
+ fs.mkdirSync('dist');
7
+ }
8
+
9
+ console.log('Starting bundling types');
10
+ const outputFile = './dist/maplibre-gl.d.ts';
11
+ childProcess.execSync(`dts-bundle-generator --no-check --umd-module-name=maplibregl -o ${outputFile} ./src/index.ts`);
12
+ let types = fs.readFileSync(outputFile, 'utf8');
13
+ // Classes are not exported but should be since this is exported as UMD - fixing...
14
+ types = types.replace(/declare class/g, 'export declare class');
15
+ fs.writeFileSync(outputFile, types);
16
+ console.log('Finished bundling types');
package/build/readme.md CHANGED
@@ -1,38 +1,31 @@
1
1
  # Build Scripts
2
2
  This folder holds common build scripts accessed via the various `npm run` commands.
3
-
3
+ Codegen is executed when calling `npm install` in order to generate all artifacts needed for the build to pass
4
4
  ## Bundeling all the code
5
5
 
6
6
  The bundeling process can be split into several steps:
7
7
 
8
- `npx run tsc`
9
- This command will transpile all the typescript files into javascript files and place them in the `rollup/build` folder.
10
-
11
- `npm run build-glsl`
12
- This command will copy all the shader files to the build output and convert the shaders into strings that can be imported to javascript.
13
-
14
8
  `npm run build-css`
15
9
  This command will compile the css code and create the css file.
16
10
 
17
11
  `npm run build-prod` or `npm run build-prod-min` or `npm run build-dev`
18
12
  These commands will use rollup to bundle the code. This is where the magic happens and uses some files in this folder.
19
13
 
20
- `banner.js` is used to create a banner at the beginning of the output file
14
+ `banner.ts` is used to create a banner at the beginning of the output file
21
15
 
22
- `rollup_plugins.js` is used to define common plugins for rollup configurations
16
+ `rollup_plugins.ts` is used to define common plugins for rollup configurations
23
17
 
24
- `rollup_plugin_minify_style_spec.js` is used to specify the plugin used in style spec bundeling
18
+ `rollup_plugin_minify_style_spec.ts` is used to specify the plugin used in style spec bundeling
25
19
 
26
20
  In the `rollup` folder there are some files that are used as linking files as they link to other files for rollup to pick when bundling.
27
- Rollup also has a configuration in the `package.json` file to signal which files it needs to replace when bundling for the browser, this is where `web_worker_replacement.js` is used - as it replaces the node mocking of web worker that is present in the source code.
28
21
 
29
22
  Rollup is generating 3 files throughout the process of bundling:
30
23
 
31
- `index.js` a file containing all the code that will run in the main thread.
24
+ `index.ts` a file containing all the code that will run in the main thread.
32
25
 
33
- `shared.js` a file containing all the code shared between the main and worker code.
26
+ `shared.ts` a file containing all the code shared between the main and worker code.
34
27
 
35
- `worker.js` a file containing all the code the will run in the worker threads.
28
+ `worker.ts` a file containing all the code the will run in the worker threads.
36
29
 
37
30
  These 3 files are then referenced and used by the `bundle_prelude.js` file. It allows loading the web wroker code automatically in web workers without any extra effort from someone who would like to use the library, i.e. it simply works.
38
31
 
@@ -55,8 +48,5 @@ Generates `style-spec/types.ts` based on the content of `v8.json`. This provides
55
48
  <hr>
56
49
 
57
50
  ### Generate Release Nodes
58
- The following files are being used to generate release notes:
59
-
60
- `release-notes.js` Used to generate release notes when releasing a new version
61
51
 
62
- `release-notes.md.ejs` Used for the generation as a template file
52
+ `release-notes.js` Used to generate release notes when releasing a new version
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import * as fs from 'fs';
4
- import * as ejs from 'ejs';
5
4
  import semver from 'semver';
6
5
 
7
6
  const changelogPath = 'CHANGELOG.md';
@@ -32,18 +31,15 @@ while (match = regex.exec(changelog)) {
32
31
  const latest = releaseNotes[0];
33
32
  const previous = releaseNotes[1];
34
33
 
35
- /*
36
- Fill and print the release notes template.
37
- */
38
- let templatedReleaseNotes;
39
34
 
40
- templatedReleaseNotes = ejs.render(fs.readFileSync('build/release-notes.md.ejs', 'utf8'), {
41
- 'CURRENTVERSION': latest.version,
42
- 'PREVIOUSVERSION': previous.version,
43
- 'CHANGELOG': latest.changelog,
44
- 'isPrerelease': semver.prerelease(latest.version)
45
- });
46
- templatedReleaseNotes = templatedReleaseNotes.trimEnd();
35
+ // Print the release notes template.
36
+
37
+ const templatedReleaseNotes = `https://github.com/maplibre/maplibre-gl-js
38
+ [Changes](https://github.com/maplibre/maplibre-gl-js/compare/v${previous.version}...v${latest.version}) since [MapLibre GL JS v${previous.version}](https://github.com/maplibre/releases/tag/v${previous.version}):
39
+
40
+ ${latest.changelog}
41
+
42
+ ${semver.prerelease(latest.version) ? 'Pre-release version' : ''}`;
47
43
 
48
44
  // eslint-disable-next-line eol-last
49
- process.stdout.write(templatedReleaseNotes);
45
+ process.stdout.write(templatedReleaseNotes.trimEnd());
@@ -1,9 +1,10 @@
1
+ import {Plugin} from 'rollup';
1
2
 
2
- function replacer(k, v) {
3
- return (k === 'doc' || k === 'example' || k === 'sdk-support') ? undefined : v;
3
+ function replacer(key: string, value: any) {
4
+ return (key === 'doc' || key === 'example' || key === 'sdk-support') ? undefined : value;
4
5
  }
5
6
 
6
- export default function minifyStyleSpec() {
7
+ export default function minifyStyleSpec(): Plugin {
7
8
  return {
8
9
  name: 'minify-style-spec',
9
10
  transform: (source, id) => {
@@ -6,19 +6,23 @@ import commonjs from '@rollup/plugin-commonjs';
6
6
  import unassert from 'rollup-plugin-unassert';
7
7
  import json from '@rollup/plugin-json';
8
8
  import {terser} from 'rollup-plugin-terser';
9
- import minifyStyleSpec from './rollup_plugin_minify_style_spec.js';
10
- import {createFilter} from 'rollup-pluginutils';
9
+ import minifyStyleSpec from './rollup_plugin_minify_style_spec';
11
10
  import strip from '@rollup/plugin-strip';
12
- import glsl_to_js from './glsl_to_js.js';
13
-
11
+ import {Plugin} from 'rollup';
14
12
  // Common set of plugins/transformations shared across different rollup
15
13
  // builds (main maplibre bundle, style-spec package, benchmarks bundle)
16
14
 
17
- export const plugins = (minified, production, watch) => [
15
+ export const nodeResolve = resolve({
16
+ browser: true,
17
+ preferBuiltins: false
18
+ });
19
+
20
+ export const plugins = (minified: boolean, production: boolean): Plugin[] => [
18
21
  minifyStyleSpec(),
19
22
  json(),
20
23
  // https://github.com/zaach/jison/issues/351
21
24
  replace({
25
+ preventAssignment: true,
22
26
  include: /\/jsonlint-lines-primitives\/lib\/jsonlint.js/,
23
27
  delimiters: ['', ''],
24
28
  values: {
@@ -29,9 +33,9 @@ export const plugins = (minified, production, watch) => [
29
33
  sourceMap: true,
30
34
  functions: ['PerformanceUtils.*', 'Debug.*']
31
35
  }) : false,
32
- glsl('**/*.glsl', production),
33
36
  minified ? terser({
34
37
  compress: {
38
+ // eslint-disable-next-line camelcase
35
39
  pure_getters: true,
36
40
  passes: 3
37
41
  }
@@ -39,29 +43,11 @@ export const plugins = (minified, production, watch) => [
39
43
  production ? unassert({
40
44
  include: ['**/*'], // by default, unassert only includes .js files
41
45
  }) : false,
42
- resolve({
43
- browser: true,
44
- preferBuiltins: false
45
- }),
46
- watch ? typescript() : false,
46
+ nodeResolve,
47
+ typescript(),
47
48
  commonjs({
48
49
  // global keyword handling causes Webpack compatibility issues, so we disabled it:
49
50
  // https://github.com/mapbox/mapbox-gl-js/pull/6956
50
51
  ignoreGlobal: true
51
52
  })
52
53
  ].filter(Boolean);
53
-
54
- // Using this instead of rollup-plugin-string to add minification
55
- function glsl(include, minify) {
56
- const filter = createFilter(include);
57
- return {
58
- name: 'glsl',
59
- transform(code, id) {
60
- if (!filter(id)) return;
61
- return {
62
- code: glsl_to_js(code, minify),
63
- map: {mappings: ''}
64
- };
65
- }
66
- };
67
- }