@scoova/mgl 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +116 -0
- package/README.md +174 -0
- package/build/banner.ts +12 -0
- package/build/bump-version-changelog.js +26 -0
- package/build/check-bundle-size.js +77 -0
- package/build/generate-dist-package.js +26 -0
- package/build/generate-doc-images.ts +78 -0
- package/build/generate-docs.ts +190 -0
- package/build/generate-shaders.ts +68 -0
- package/build/generate-struct-arrays.ts +438 -0
- package/build/generate-style-code.ts +283 -0
- package/build/readme.md +56 -0
- package/build/release-notes.js +45 -0
- package/build/rollup/bundle_prelude.js +29 -0
- package/build/rollup/maplibregl.js +22 -0
- package/build/rollup_plugins.ts +58 -0
- package/dist/LICENSE.txt +116 -0
- package/dist/maplibre-gl.css +1 -0
- package/dist/maplibre-gl.d.ts +13304 -0
- package/dist/maplibre-gl.js +59 -0
- package/dist/maplibre-gl.js.map +1 -0
- package/dist/package.json +1 -0
- package/package.json +192 -0
- package/src/css/maplibre-gl.css +854 -0
- package/src/css/svg/maplibregl-ctrl-attrib.svg +3 -0
- package/src/css/svg/maplibregl-ctrl-compass.svg +4 -0
- package/src/css/svg/maplibregl-ctrl-fullscreen.svg +3 -0
- package/src/css/svg/maplibregl-ctrl-geolocate.svg +5 -0
- package/src/css/svg/maplibregl-ctrl-logo.svg +11 -0
- package/src/css/svg/maplibregl-ctrl-shrink.svg +3 -0
- package/src/css/svg/maplibregl-ctrl-terrain.svg +3 -0
- package/src/css/svg/maplibregl-ctrl-zoom-in.svg +3 -0
- package/src/css/svg/maplibregl-ctrl-zoom-out.svg +3 -0
- package/src/data/array_types.g.ts +1130 -0
- package/src/data/bucket/circle_attributes.ts +8 -0
- package/src/data/bucket/circle_bucket.ts +197 -0
- package/src/data/bucket/fill_attributes.ts +8 -0
- package/src/data/bucket/fill_bucket.test.ts +95 -0
- package/src/data/bucket/fill_bucket.ts +228 -0
- package/src/data/bucket/fill_extrusion_attributes.ts +13 -0
- package/src/data/bucket/fill_extrusion_bucket.ts +305 -0
- package/src/data/bucket/heatmap_bucket.ts +12 -0
- package/src/data/bucket/line_attributes.ts +8 -0
- package/src/data/bucket/line_attributes_ext.ts +8 -0
- package/src/data/bucket/line_bucket.test.ts +142 -0
- package/src/data/bucket/line_bucket.ts +592 -0
- package/src/data/bucket/pattern_attributes.ts +9 -0
- package/src/data/bucket/pattern_bucket_features.ts +57 -0
- package/src/data/bucket/symbol_attributes.ts +122 -0
- package/src/data/bucket/symbol_bucket.test.ts +243 -0
- package/src/data/bucket/symbol_bucket.ts +975 -0
- package/src/data/bucket.ts +123 -0
- package/src/data/dem_data.test.ts +237 -0
- package/src/data/dem_data.ts +171 -0
- package/src/data/evaluation_feature.ts +18 -0
- package/src/data/extent.ts +13 -0
- package/src/data/feature_index.ts +337 -0
- package/src/data/feature_position_map.test.ts +33 -0
- package/src/data/feature_position_map.ts +126 -0
- package/src/data/index_array_type.ts +9 -0
- package/src/data/load_geometry.test.ts +49 -0
- package/src/data/load_geometry.ts +44 -0
- package/src/data/pos3d_attributes.ts +5 -0
- package/src/data/pos_attributes.ts +5 -0
- package/src/data/program_configuration.ts +735 -0
- package/src/data/raster_bounds_attributes.ts +6 -0
- package/src/data/segment.ts +89 -0
- package/src/geo/edge_insets.test.ts +83 -0
- package/src/geo/edge_insets.ts +146 -0
- package/src/geo/lng_lat.test.ts +65 -0
- package/src/geo/lng_lat.ts +169 -0
- package/src/geo/lng_lat_bounds.test.ts +357 -0
- package/src/geo/lng_lat_bounds.ts +356 -0
- package/src/geo/mercator_coordinate.test.ts +34 -0
- package/src/geo/mercator_coordinate.ts +157 -0
- package/src/geo/projection/projection.ts +72 -0
- package/src/geo/transform.test.ts +509 -0
- package/src/geo/transform.ts +1072 -0
- package/src/gl/color_mode.ts +31 -0
- package/src/gl/context.ts +321 -0
- package/src/gl/cull_face_mode.ts +22 -0
- package/src/gl/depth_mode.ts +26 -0
- package/src/gl/framebuffer.ts +48 -0
- package/src/gl/index_buffer.ts +55 -0
- package/src/gl/render_pool.test.ts +69 -0
- package/src/gl/render_pool.ts +93 -0
- package/src/gl/state.test.ts +125 -0
- package/src/gl/stencil_mode.ts +27 -0
- package/src/gl/types.ts +59 -0
- package/src/gl/value.ts +534 -0
- package/src/gl/vertex_buffer.test.ts +57 -0
- package/src/gl/vertex_buffer.ts +111 -0
- package/src/gl/webgl2.ts +12 -0
- package/src/index.test.ts +121 -0
- package/src/index.ts +250 -0
- package/src/render/draw_background.ts +53 -0
- package/src/render/draw_circle.ts +113 -0
- package/src/render/draw_collision_debug.ts +168 -0
- package/src/render/draw_custom.test.ts +73 -0
- package/src/render/draw_custom.ts +45 -0
- package/src/render/draw_debug.test.ts +122 -0
- package/src/render/draw_debug.ts +148 -0
- package/src/render/draw_fill.test.ts +137 -0
- package/src/render/draw_fill.ts +128 -0
- package/src/render/draw_fill_extrusion.ts +97 -0
- package/src/render/draw_heatmap.ts +228 -0
- package/src/render/draw_hillshade.ts +119 -0
- package/src/render/draw_line.ts +125 -0
- package/src/render/draw_raster.ts +133 -0
- package/src/render/draw_sky.ts +44 -0
- package/src/render/draw_symbol.test.ts +223 -0
- package/src/render/draw_symbol.ts +499 -0
- package/src/render/draw_terrain.ts +99 -0
- package/src/render/glyph_atlas.ts +83 -0
- package/src/render/glyph_manager.test.ts +147 -0
- package/src/render/glyph_manager.ts +198 -0
- package/src/render/image_atlas.ts +159 -0
- package/src/render/image_manager.ts +337 -0
- package/src/render/line_atlas.test.ts +38 -0
- package/src/render/line_atlas.ts +214 -0
- package/src/render/mesh.ts +25 -0
- package/src/render/painter.test.ts +51 -0
- package/src/render/painter.ts +666 -0
- package/src/render/program/background_program.ts +100 -0
- package/src/render/program/circle_program.ts +61 -0
- package/src/render/program/clipping_mask_program.ts +19 -0
- package/src/render/program/collision_program.ts +47 -0
- package/src/render/program/debug_program.ts +29 -0
- package/src/render/program/fill_extrusion_program.ts +120 -0
- package/src/render/program/fill_program.ts +121 -0
- package/src/render/program/heatmap_program.ts +76 -0
- package/src/render/program/hillshade_program.ts +116 -0
- package/src/render/program/line_program.ts +207 -0
- package/src/render/program/pattern.ts +102 -0
- package/src/render/program/program_uniforms.ts +46 -0
- package/src/render/program/raster_program.ts +88 -0
- package/src/render/program/sky_program.ts +28 -0
- package/src/render/program/symbol_program.ts +266 -0
- package/src/render/program/terrain_program.ts +116 -0
- package/src/render/program.ts +233 -0
- package/src/render/render_to_texture.test.ts +151 -0
- package/src/render/render_to_texture.ts +197 -0
- package/src/render/terrain.test.ts +322 -0
- package/src/render/terrain.ts +464 -0
- package/src/render/texture.ts +114 -0
- package/src/render/uniform_binding.test.ts +122 -0
- package/src/render/uniform_binding.ts +157 -0
- package/src/render/update_pattern_positions_in_program.test.ts +74 -0
- package/src/render/update_pattern_positions_in_program.ts +50 -0
- package/src/render/vertex_array_object.ts +163 -0
- package/src/shaders/README.md +42 -0
- package/src/shaders/_prelude.fragment.glsl +19 -0
- package/src/shaders/_prelude.fragment.glsl.g.ts +2 -0
- package/src/shaders/_prelude.vertex.glsl +148 -0
- package/src/shaders/_prelude.vertex.glsl.g.ts +2 -0
- package/src/shaders/background.fragment.glsl +10 -0
- package/src/shaders/background.fragment.glsl.g.ts +2 -0
- package/src/shaders/background.vertex.glsl +7 -0
- package/src/shaders/background.vertex.glsl.g.ts +2 -0
- package/src/shaders/background_pattern.fragment.glsl +28 -0
- package/src/shaders/background_pattern.fragment.glsl.g.ts +2 -0
- package/src/shaders/background_pattern.vertex.glsl +19 -0
- package/src/shaders/background_pattern.vertex.glsl.g.ts +2 -0
- package/src/shaders/circle.fragment.glsl +34 -0
- package/src/shaders/circle.fragment.glsl.g.ts +2 -0
- package/src/shaders/circle.vertex.glsl +68 -0
- package/src/shaders/circle.vertex.glsl.g.ts +2 -0
- package/src/shaders/clipping_mask.fragment.glsl +3 -0
- package/src/shaders/clipping_mask.fragment.glsl.g.ts +2 -0
- package/src/shaders/clipping_mask.vertex.glsl +7 -0
- package/src/shaders/clipping_mask.vertex.glsl.g.ts +2 -0
- package/src/shaders/collision_box.fragment.glsl +20 -0
- package/src/shaders/collision_box.fragment.glsl.g.ts +2 -0
- package/src/shaders/collision_box.vertex.glsl +27 -0
- package/src/shaders/collision_box.vertex.glsl.g.ts +2 -0
- package/src/shaders/collision_circle.fragment.glsl +17 -0
- package/src/shaders/collision_circle.fragment.glsl.g.ts +2 -0
- package/src/shaders/collision_circle.vertex.glsl +59 -0
- package/src/shaders/collision_circle.vertex.glsl.g.ts +2 -0
- package/src/shaders/debug.fragment.glsl +9 -0
- package/src/shaders/debug.fragment.glsl.g.ts +2 -0
- package/src/shaders/debug.vertex.glsl +12 -0
- package/src/shaders/debug.vertex.glsl.g.ts +2 -0
- package/src/shaders/encode_attribute.test.ts +11 -0
- package/src/shaders/encode_attribute.ts +13 -0
- package/src/shaders/fill.fragment.glsl +13 -0
- package/src/shaders/fill.fragment.glsl.g.ts +2 -0
- package/src/shaders/fill.vertex.glsl +13 -0
- package/src/shaders/fill.vertex.glsl.g.ts +2 -0
- package/src/shaders/fill_extrusion.fragment.glsl +9 -0
- package/src/shaders/fill_extrusion.fragment.glsl.g.ts +2 -0
- package/src/shaders/fill_extrusion.vertex.glsl +84 -0
- package/src/shaders/fill_extrusion.vertex.glsl.g.ts +2 -0
- package/src/shaders/fill_extrusion_pattern.fragment.glsl +47 -0
- package/src/shaders/fill_extrusion_pattern.fragment.glsl.g.ts +2 -0
- package/src/shaders/fill_extrusion_pattern.vertex.glsl +96 -0
- package/src/shaders/fill_extrusion_pattern.vertex.glsl.g.ts +2 -0
- package/src/shaders/fill_outline.fragment.glsl +17 -0
- package/src/shaders/fill_outline.fragment.glsl.g.ts +2 -0
- package/src/shaders/fill_outline.vertex.glsl +17 -0
- package/src/shaders/fill_outline.vertex.glsl.g.ts +2 -0
- package/src/shaders/fill_outline_pattern.fragment.glsl +43 -0
- package/src/shaders/fill_outline_pattern.fragment.glsl.g.ts +2 -0
- package/src/shaders/fill_outline_pattern.vertex.glsl +44 -0
- package/src/shaders/fill_outline_pattern.vertex.glsl.g.ts +2 -0
- package/src/shaders/fill_pattern.fragment.glsl +39 -0
- package/src/shaders/fill_pattern.fragment.glsl.g.ts +2 -0
- package/src/shaders/fill_pattern.vertex.glsl +39 -0
- package/src/shaders/fill_pattern.vertex.glsl.g.ts +2 -0
- package/src/shaders/heatmap.fragment.glsl +22 -0
- package/src/shaders/heatmap.fragment.glsl.g.ts +2 -0
- package/src/shaders/heatmap.vertex.glsl +54 -0
- package/src/shaders/heatmap.vertex.glsl.g.ts +2 -0
- package/src/shaders/heatmap_texture.fragment.glsl +15 -0
- package/src/shaders/heatmap_texture.fragment.glsl.g.ts +2 -0
- package/src/shaders/heatmap_texture.vertex.glsl +11 -0
- package/src/shaders/heatmap_texture.vertex.glsl.g.ts +2 -0
- package/src/shaders/hillshade.fragment.glsl +52 -0
- package/src/shaders/hillshade.fragment.glsl.g.ts +2 -0
- package/src/shaders/hillshade.vertex.glsl +11 -0
- package/src/shaders/hillshade.vertex.glsl.g.ts +2 -0
- package/src/shaders/hillshade_prepare.fragment.glsl +77 -0
- package/src/shaders/hillshade_prepare.fragment.glsl.g.ts +2 -0
- package/src/shaders/hillshade_prepare.vertex.glsl +15 -0
- package/src/shaders/hillshade_prepare.vertex.glsl.g.ts +2 -0
- package/src/shaders/line.fragment.glsl +30 -0
- package/src/shaders/line.fragment.glsl.g.ts +2 -0
- package/src/shaders/line.vertex.glsl +89 -0
- package/src/shaders/line.vertex.glsl.g.ts +2 -0
- package/src/shaders/line_gradient.fragment.glsl +34 -0
- package/src/shaders/line_gradient.fragment.glsl.g.ts +2 -0
- package/src/shaders/line_gradient.vertex.glsl +92 -0
- package/src/shaders/line_gradient.vertex.glsl.g.ts +2 -0
- package/src/shaders/line_pattern.fragment.glsl +77 -0
- package/src/shaders/line_pattern.fragment.glsl.g.ts +2 -0
- package/src/shaders/line_pattern.vertex.glsl +103 -0
- package/src/shaders/line_pattern.vertex.glsl.g.ts +2 -0
- package/src/shaders/line_sdf.fragment.glsl +45 -0
- package/src/shaders/line_sdf.fragment.glsl.g.ts +2 -0
- package/src/shaders/line_sdf.vertex.glsl +101 -0
- package/src/shaders/line_sdf.vertex.glsl.g.ts +2 -0
- package/src/shaders/raster.fragment.glsl +53 -0
- package/src/shaders/raster.fragment.glsl.g.ts +2 -0
- package/src/shaders/raster.vertex.glsl +21 -0
- package/src/shaders/raster.vertex.glsl.g.ts +2 -0
- package/src/shaders/shaders.ts +197 -0
- package/src/shaders/sky.fragment.glsl +17 -0
- package/src/shaders/sky.fragment.glsl.g.ts +2 -0
- package/src/shaders/sky.vertex.glsl +5 -0
- package/src/shaders/sky.vertex.glsl.g.ts +2 -0
- package/src/shaders/symbol_icon.fragment.glsl +17 -0
- package/src/shaders/symbol_icon.fragment.glsl.g.ts +2 -0
- package/src/shaders/symbol_icon.vertex.glsl +117 -0
- package/src/shaders/symbol_icon.vertex.glsl.g.ts +2 -0
- package/src/shaders/symbol_sdf.fragment.glsl +58 -0
- package/src/shaders/symbol_sdf.fragment.glsl.g.ts +2 -0
- package/src/shaders/symbol_sdf.vertex.glsl +142 -0
- package/src/shaders/symbol_sdf.vertex.glsl.g.ts +2 -0
- package/src/shaders/symbol_text_and_icon.fragment.glsl +68 -0
- package/src/shaders/symbol_text_and_icon.fragment.glsl.g.ts +2 -0
- package/src/shaders/symbol_text_and_icon.vertex.glsl +140 -0
- package/src/shaders/symbol_text_and_icon.vertex.glsl.g.ts +2 -0
- package/src/shaders/terrain.fragment.glsl +32 -0
- package/src/shaders/terrain.fragment.glsl.g.ts +2 -0
- package/src/shaders/terrain.vertex.glsl +17 -0
- package/src/shaders/terrain.vertex.glsl.g.ts +2 -0
- package/src/shaders/terrain_coords.fragment.glsl +11 -0
- package/src/shaders/terrain_coords.fragment.glsl.g.ts +2 -0
- package/src/shaders/terrain_coords.vertex.glsl +13 -0
- package/src/shaders/terrain_coords.vertex.glsl.g.ts +2 -0
- package/src/shaders/terrain_depth.fragment.glsl +15 -0
- package/src/shaders/terrain_depth.fragment.glsl.g.ts +2 -0
- package/src/shaders/terrain_depth.vertex.glsl +13 -0
- package/src/shaders/terrain_depth.vertex.glsl.g.ts +2 -0
- package/src/source/canvas_source.test.ts +210 -0
- package/src/source/canvas_source.ts +227 -0
- package/src/source/geojson_source.test.ts +492 -0
- package/src/source/geojson_source.ts +431 -0
- package/src/source/geojson_source_diff.test.ts +364 -0
- package/src/source/geojson_source_diff.ts +172 -0
- package/src/source/geojson_worker_source.test.ts +399 -0
- package/src/source/geojson_worker_source.ts +303 -0
- package/src/source/geojson_wrapper.test.ts +32 -0
- package/src/source/geojson_wrapper.ts +81 -0
- package/src/source/image_source.test.ts +235 -0
- package/src/source/image_source.ts +338 -0
- package/src/source/load_tilejson.ts +47 -0
- package/src/source/pixels_to_tile_units.ts +25 -0
- package/src/source/protocol_crud.ts +48 -0
- package/src/source/query_features.test.ts +31 -0
- package/src/source/query_features.ts +252 -0
- package/src/source/raster_dem_tile_source.test.ts +158 -0
- package/src/source/raster_dem_tile_source.ts +166 -0
- package/src/source/raster_dem_tile_worker_source.test.ts +36 -0
- package/src/source/raster_dem_tile_worker_source.ts +38 -0
- package/src/source/raster_tile_source.test.ts +206 -0
- package/src/source/raster_tile_source.ts +227 -0
- package/src/source/rtl_text_plugin_main_thread.test.ts +170 -0
- package/src/source/rtl_text_plugin_main_thread.ts +89 -0
- package/src/source/rtl_text_plugin_status.ts +33 -0
- package/src/source/rtl_text_plugin_worker.ts +49 -0
- package/src/source/source.test.ts +41 -0
- package/src/source/source.ts +186 -0
- package/src/source/source_cache.test.ts +2069 -0
- package/src/source/source_cache.ts +1102 -0
- package/src/source/source_state.ts +157 -0
- package/src/source/terrain_source_cache.test.ts +105 -0
- package/src/source/terrain_source_cache.ts +204 -0
- package/src/source/tile.test.ts +290 -0
- package/src/source/tile.ts +478 -0
- package/src/source/tile_bounds.ts +34 -0
- package/src/source/tile_cache.test.ts +130 -0
- package/src/source/tile_cache.ts +208 -0
- package/src/source/tile_id.test.ts +112 -0
- package/src/source/tile_id.ts +221 -0
- package/src/source/vector_tile_source.test.ts +401 -0
- package/src/source/vector_tile_source.ts +283 -0
- package/src/source/vector_tile_worker_source.test.ts +396 -0
- package/src/source/vector_tile_worker_source.ts +199 -0
- package/src/source/video_source.test.ts +124 -0
- package/src/source/video_source.ts +204 -0
- package/src/source/worker.test.ts +233 -0
- package/src/source/worker.ts +301 -0
- package/src/source/worker_source.ts +117 -0
- package/src/source/worker_tile.test.ts +226 -0
- package/src/source/worker_tile.ts +208 -0
- package/src/style/create_style_layer.ts +39 -0
- package/src/style/evaluation_parameters.ts +62 -0
- package/src/style/format_section_override.test.ts +62 -0
- package/src/style/format_section_override.ts +50 -0
- package/src/style/light.test.ts +86 -0
- package/src/style/light.ts +135 -0
- package/src/style/load_glyph_range.test.ts +40 -0
- package/src/style/load_glyph_range.ts +32 -0
- package/src/style/load_sprite.test.ts +227 -0
- package/src/style/load_sprite.ts +71 -0
- package/src/style/parse_glyph_pbf.ts +42 -0
- package/src/style/pauseable_placement.ts +138 -0
- package/src/style/properties.ts +726 -0
- package/src/style/query_utils.test.ts +107 -0
- package/src/style/query_utils.ts +70 -0
- package/src/style/sky.ts +127 -0
- package/src/style/style.test.ts +2654 -0
- package/src/style/style.ts +1814 -0
- package/src/style/style_glyph.ts +25 -0
- package/src/style/style_image.ts +188 -0
- package/src/style/style_layer/background_style_layer.ts +17 -0
- package/src/style/style_layer/background_style_layer_properties.g.ts +40 -0
- package/src/style/style_layer/circle_style_layer.ts +98 -0
- package/src/style/style_layer/circle_style_layer_properties.g.ts +76 -0
- package/src/style/style_layer/custom_style_layer.ts +233 -0
- package/src/style/style_layer/fill_extrusion_style_layer.ts +224 -0
- package/src/style/style_layer/fill_extrusion_style_layer_properties.g.ts +55 -0
- package/src/style/style_layer/fill_style_layer.test.ts +37 -0
- package/src/style/style_layer/fill_style_layer.ts +65 -0
- package/src/style/style_layer/fill_style_layer_properties.g.ts +64 -0
- package/src/style/style_layer/heatmap_style_layer.ts +74 -0
- package/src/style/style_layer/heatmap_style_layer_properties.g.ts +46 -0
- package/src/style/style_layer/hillshade_style_layer.ts +21 -0
- package/src/style/style_layer/hillshade_style_layer_properties.g.ts +49 -0
- package/src/style/style_layer/line_style_layer.test.ts +50 -0
- package/src/style/style_layer/line_style_layer.ts +131 -0
- package/src/style/style_layer/line_style_layer_properties.g.ts +88 -0
- package/src/style/style_layer/overlap_mode.test.ts +57 -0
- package/src/style/style_layer/overlap_mode.ts +25 -0
- package/src/style/style_layer/raster_style_layer.ts +17 -0
- package/src/style/style_layer/raster_style_layer_properties.g.ts +55 -0
- package/src/style/style_layer/symbol_style_layer.ts +195 -0
- package/src/style/style_layer/symbol_style_layer_properties.g.ts +218 -0
- package/src/style/style_layer/typed_style_layer.ts +9 -0
- package/src/style/style_layer/variable_text_anchor.test.ts +117 -0
- package/src/style/style_layer/variable_text_anchor.ts +163 -0
- package/src/style/style_layer.test.ts +372 -0
- package/src/style/style_layer.ts +287 -0
- package/src/style/style_layer_index.test.ts +99 -0
- package/src/style/style_layer_index.ts +78 -0
- package/src/style/validate_style.ts +53 -0
- package/src/style/zoom_history.ts +40 -0
- package/src/symbol/anchor.test.ts +14 -0
- package/src/symbol/anchor.ts +22 -0
- package/src/symbol/check_max_angle.test.ts +54 -0
- package/src/symbol/check_max_angle.ts +76 -0
- package/src/symbol/clip_line.test.ts +154 -0
- package/src/symbol/clip_line.ts +66 -0
- package/src/symbol/collision_feature.test.ts +98 -0
- package/src/symbol/collision_feature.ts +114 -0
- package/src/symbol/collision_index.test.ts +19 -0
- package/src/symbol/collision_index.ts +618 -0
- package/src/symbol/cross_tile_symbol_index.test.ts +260 -0
- package/src/symbol/cross_tile_symbol_index.ts +367 -0
- package/src/symbol/get_anchors.test.ts +113 -0
- package/src/symbol/get_anchors.ts +167 -0
- package/src/symbol/grid_index.test.ts +75 -0
- package/src/symbol/grid_index.ts +414 -0
- package/src/symbol/merge_lines.test.ts +30 -0
- package/src/symbol/merge_lines.ts +80 -0
- package/src/symbol/one_em.ts +3 -0
- package/src/symbol/opacity_state.ts +23 -0
- package/src/symbol/path_interpolator.test.ts +134 -0
- package/src/symbol/path_interpolator.ts +55 -0
- package/src/symbol/placement.ts +1371 -0
- package/src/symbol/projection.test.ts +171 -0
- package/src/symbol/projection.ts +833 -0
- package/src/symbol/quads.test.ts +157 -0
- package/src/symbol/quads.ts +349 -0
- package/src/symbol/shaping.test.ts +360 -0
- package/src/symbol/shaping.ts +911 -0
- package/src/symbol/symbol_layout.ts +739 -0
- package/src/symbol/symbol_size.ts +129 -0
- package/src/symbol/symbol_style_layer.test.ts +103 -0
- package/src/symbol/transform_text.ts +27 -0
- package/src/ui/anchor.ts +27 -0
- package/src/ui/camera.test.ts +2301 -0
- package/src/ui/camera.ts +1520 -0
- package/src/ui/control/attribution_control.test.ts +543 -0
- package/src/ui/control/attribution_control.ts +209 -0
- package/src/ui/control/control.ts +67 -0
- package/src/ui/control/fullscreen_control.test.ts +114 -0
- package/src/ui/control/fullscreen_control.ts +189 -0
- package/src/ui/control/geolocate_control.test.ts +619 -0
- package/src/ui/control/geolocate_control.ts +725 -0
- package/src/ui/control/logo_control.test.ts +88 -0
- package/src/ui/control/logo_control.ts +86 -0
- package/src/ui/control/navigation_control.test.ts +238 -0
- package/src/ui/control/navigation_control.ts +294 -0
- package/src/ui/control/scale_control.test.ts +52 -0
- package/src/ui/control/scale_control.ts +152 -0
- package/src/ui/control/terrain_control.test.ts +58 -0
- package/src/ui/control/terrain_control.ts +74 -0
- package/src/ui/default_locale.ts +25 -0
- package/src/ui/events.ts +758 -0
- package/src/ui/handler/box_zoom.test.ts +163 -0
- package/src/ui/handler/box_zoom.ts +171 -0
- package/src/ui/handler/click_zoom.ts +55 -0
- package/src/ui/handler/cooperative_gestures.test.ts +338 -0
- package/src/ui/handler/cooperative_gestures.ts +111 -0
- package/src/ui/handler/dblclick_zoom.test.ts +151 -0
- package/src/ui/handler/drag_handler.ts +174 -0
- package/src/ui/handler/drag_move_state_manager.ts +115 -0
- package/src/ui/handler/drag_pan.test.ts +487 -0
- package/src/ui/handler/drag_rotate.test.ts +859 -0
- package/src/ui/handler/handler_util.ts +10 -0
- package/src/ui/handler/keyboard.test.ts +235 -0
- package/src/ui/handler/keyboard.ts +212 -0
- package/src/ui/handler/map_event.test.ts +158 -0
- package/src/ui/handler/map_event.ts +161 -0
- package/src/ui/handler/mouse.ts +92 -0
- package/src/ui/handler/mouse_handler_interface.test.ts +111 -0
- package/src/ui/handler/mouse_rotate.test.ts +62 -0
- package/src/ui/handler/one_finger_touch_drag.ts +45 -0
- package/src/ui/handler/one_finger_touch_drag_handler_interface.test.ts +77 -0
- package/src/ui/handler/scroll_zoom.test.ts +382 -0
- package/src/ui/handler/scroll_zoom.ts +379 -0
- package/src/ui/handler/shim/dblclick_zoom.ts +64 -0
- package/src/ui/handler/shim/drag_pan.ts +104 -0
- package/src/ui/handler/shim/drag_rotate.ts +76 -0
- package/src/ui/handler/shim/two_fingers_touch.ts +112 -0
- package/src/ui/handler/tap_drag_zoom.test.ts +113 -0
- package/src/ui/handler/tap_drag_zoom.ts +112 -0
- package/src/ui/handler/tap_recognizer.ts +138 -0
- package/src/ui/handler/tap_zoom.ts +98 -0
- package/src/ui/handler/touch_pan.ts +115 -0
- package/src/ui/handler/transform-provider.ts +44 -0
- package/src/ui/handler/two_fingers_touch.test.ts +283 -0
- package/src/ui/handler/two_fingers_touch.ts +336 -0
- package/src/ui/handler_inertia.ts +157 -0
- package/src/ui/handler_manager.ts +637 -0
- package/src/ui/hash.test.ts +404 -0
- package/src/ui/hash.ts +153 -0
- package/src/ui/map.ts +3393 -0
- package/src/ui/map_tests/map_animation.test.ts +61 -0
- package/src/ui/map_tests/map_basic.test.ts +223 -0
- package/src/ui/map_tests/map_bounds.test.ts +123 -0
- package/src/ui/map_tests/map_calculate_camera_options.test.ts +113 -0
- package/src/ui/map_tests/map_canvas.test.ts +59 -0
- package/src/ui/map_tests/map_control.test.ts +61 -0
- package/src/ui/map_tests/map_disable_handlers.test.ts +38 -0
- package/src/ui/map_tests/map_events.test.ts +1001 -0
- package/src/ui/map_tests/map_feature_state.test.ts +421 -0
- package/src/ui/map_tests/map_images.test.ts +175 -0
- package/src/ui/map_tests/map_is_moving.test.ts +164 -0
- package/src/ui/map_tests/map_is_rotating.test.ts +62 -0
- package/src/ui/map_tests/map_is_zooming.test.ts +86 -0
- package/src/ui/map_tests/map_layer.test.ts +457 -0
- package/src/ui/map_tests/map_options.test.ts +64 -0
- package/src/ui/map_tests/map_pitch.test.ts +90 -0
- package/src/ui/map_tests/map_pixel_ratio.test.ts +75 -0
- package/src/ui/map_tests/map_query_rendered_features.test.ts +93 -0
- package/src/ui/map_tests/map_render.test.ts +90 -0
- package/src/ui/map_tests/map_request_render_frame.test.ts +51 -0
- package/src/ui/map_tests/map_resize.test.ts +120 -0
- package/src/ui/map_tests/map_style.test.ts +541 -0
- package/src/ui/map_tests/map_terrian.test.ts +104 -0
- package/src/ui/map_tests/map_webgl.test.ts +72 -0
- package/src/ui/map_tests/map_world_copies.test.ts +103 -0
- package/src/ui/map_tests/map_zoom.test.ts +95 -0
- package/src/ui/marker.test.ts +1149 -0
- package/src/ui/marker.ts +880 -0
- package/src/ui/popup.test.ts +827 -0
- package/src/ui/popup.ts +717 -0
- package/src/util/abort_error.ts +21 -0
- package/src/util/actor.test.ts +218 -0
- package/src/util/actor.ts +241 -0
- package/src/util/actor_messages.ts +149 -0
- package/src/util/ajax.test.ts +237 -0
- package/src/util/ajax.ts +297 -0
- package/src/util/browser.test.ts +23 -0
- package/src/util/browser.ts +63 -0
- package/src/util/color_ramp.test.ts +105 -0
- package/src/util/color_ramp.ts +56 -0
- package/src/util/config.ts +29 -0
- package/src/util/dictionary_coder.ts +23 -0
- package/src/util/dispatcher.test.ts +76 -0
- package/src/util/dispatcher.ts +78 -0
- package/src/util/dom.ts +135 -0
- package/src/util/evented.test.ts +231 -0
- package/src/util/evented.ts +178 -0
- package/src/util/find_pole_of_inaccessibility.test.ts +21 -0
- package/src/util/find_pole_of_inaccessibility.ts +130 -0
- package/src/util/geolocation_support.test.ts +43 -0
- package/src/util/geolocation_support.ts +23 -0
- package/src/util/global_worker_pool.ts +65 -0
- package/src/util/image.ts +150 -0
- package/src/util/image_request.test.ts +408 -0
- package/src/util/image_request.ts +246 -0
- package/src/util/intersection_tests.ts +206 -0
- package/src/util/is_char_in_unicode_block.test.ts +15 -0
- package/src/util/is_char_in_unicode_block.ts +345 -0
- package/src/util/offscreen_canvas_distorted.test.ts +13 -0
- package/src/util/offscreen_canvas_distorted.ts +39 -0
- package/src/util/offscreen_canvas_supported.ts +11 -0
- package/src/util/performance.ts +117 -0
- package/src/util/primitives.test.ts +140 -0
- package/src/util/primitives.ts +143 -0
- package/src/util/request_manager.ts +42 -0
- package/src/util/resolve_tokens.test.ts +45 -0
- package/src/util/resolve_tokens.ts +17 -0
- package/src/util/script_detection.test.ts +138 -0
- package/src/util/script_detection.ts +376 -0
- package/src/util/smart_wrap.test.ts +97 -0
- package/src/util/smart_wrap.ts +58 -0
- package/src/util/struct_array.test.ts +101 -0
- package/src/util/struct_array.ts +246 -0
- package/src/util/style.test.ts +34 -0
- package/src/util/style.ts +28 -0
- package/src/util/task_queue.test.ts +114 -0
- package/src/util/task_queue.ts +64 -0
- package/src/util/test/util.ts +185 -0
- package/src/util/throttle.test.ts +42 -0
- package/src/util/throttle.ts +28 -0
- package/src/util/throttled_invoker.ts +41 -0
- package/src/util/transferable_grid_index.test.ts +56 -0
- package/src/util/transferable_grid_index.ts +214 -0
- package/src/util/util.test.ts +414 -0
- package/src/util/util.ts +724 -0
- package/src/util/vectortile_to_geojson.ts +72 -0
- package/src/util/verticalize_punctuation.ts +110 -0
- package/src/util/web_worker.ts +16 -0
- package/src/util/web_worker_transfer.test.ts +153 -0
- package/src/util/web_worker_transfer.ts +254 -0
- package/src/util/webp_supported.ts +63 -0
- package/src/util/worker_pool.test.ts +43 -0
- package/src/util/worker_pool.ts +58 -0
- package/src/util/world_bounds.test.ts +59 -0
- package/src/util/world_bounds.ts +46 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import typedocConfig from '../typedoc.json' with {type: 'json'};
|
|
4
|
+
import packageJson from '../package.json' with {type: 'json'};
|
|
5
|
+
import {get} from 'https';
|
|
6
|
+
|
|
7
|
+
type HtmlDoc = {
|
|
8
|
+
title: string;
|
|
9
|
+
description: string;
|
|
10
|
+
mdFileName: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function generateAPIIntroMarkdown(lines: string[]): string {
|
|
14
|
+
let intro = `# Intro
|
|
15
|
+
|
|
16
|
+
This file is intended as a reference for the important and public classes of this API.
|
|
17
|
+
We recommend looking at the [examples](../examples/index.md) as they will help you the most to start with MapLibre.
|
|
18
|
+
|
|
19
|
+
Most of the classes written here have an "Options" object for initialization, it is recommended to check which options exist.
|
|
20
|
+
|
|
21
|
+
It is recommended to import what you need and the use it. Some examples for classes assume you did that.
|
|
22
|
+
For example, import the \`Map\` class like this:
|
|
23
|
+
\`\`\`ts
|
|
24
|
+
import {Map} from 'maplibre-gl';
|
|
25
|
+
const map = new Map(...)
|
|
26
|
+
\`\`\`
|
|
27
|
+
|
|
28
|
+
Import declarations are omitted from the examples for brevity.
|
|
29
|
+
|
|
30
|
+
`;
|
|
31
|
+
intro += lines.map(l => l.replace('../', './')).join('\n');
|
|
32
|
+
return intro;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function generateMarkdownForExample(title: string, description: string, file: string, htmlContent: string): string {
|
|
36
|
+
return `
|
|
37
|
+
# ${title}
|
|
38
|
+
|
|
39
|
+
${description}
|
|
40
|
+
|
|
41
|
+
<iframe src="../${file}" width="100%" style="border:none; height:400px"></iframe>
|
|
42
|
+
|
|
43
|
+
\`\`\`html
|
|
44
|
+
${htmlContent}
|
|
45
|
+
\`\`\`
|
|
46
|
+
`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function generateMarkdownIndexFileOfAllExamples(indexArray: HtmlDoc[]): string {
|
|
50
|
+
let indexMarkdown = '# Overview \n\n';
|
|
51
|
+
for (const indexArrayItem of indexArray) {
|
|
52
|
+
indexMarkdown += `
|
|
53
|
+
## [${indexArrayItem.title}](./${indexArrayItem.mdFileName})
|
|
54
|
+
|
|
55
|
+
}){ loading=lazy }
|
|
56
|
+
|
|
57
|
+
${indexArrayItem.description}
|
|
58
|
+
`;
|
|
59
|
+
}
|
|
60
|
+
return indexMarkdown;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Builds the README.md file by parsing the modules.md file generated by typedoc.
|
|
65
|
+
*/
|
|
66
|
+
function generateReadme() {
|
|
67
|
+
const globalsFile = path.join(typedocConfig.out, 'globals.md');
|
|
68
|
+
const content = fs.readFileSync(globalsFile, 'utf-8');
|
|
69
|
+
let lines = content.split('\n');
|
|
70
|
+
const classesLineIndex = lines.indexOf(lines.find(l => l.endsWith('Classes')) as string);
|
|
71
|
+
lines = lines.splice(2, classesLineIndex - 2);
|
|
72
|
+
const contentString = generateAPIIntroMarkdown(lines);
|
|
73
|
+
fs.writeFileSync(path.join(typedocConfig.out, 'README.md'), contentString);
|
|
74
|
+
fs.rmSync(globalsFile);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* This takes the examples folder with all the html files and generates a markdown file for each of them.
|
|
79
|
+
* It also create an index file with all the examples and their images.
|
|
80
|
+
*/
|
|
81
|
+
function generateExamplesFolder() {
|
|
82
|
+
const examplesDocsFolder = path.join('docs', 'examples');
|
|
83
|
+
if (fs.existsSync(examplesDocsFolder)) {
|
|
84
|
+
fs.rmSync(examplesDocsFolder, {recursive: true, force: true});
|
|
85
|
+
}
|
|
86
|
+
fs.mkdirSync(examplesDocsFolder);
|
|
87
|
+
const examplesFolder = path.join('test', 'examples');
|
|
88
|
+
const files = fs.readdirSync(examplesFolder).filter(f => f.endsWith('html'));
|
|
89
|
+
const maplibreUnpkg = `https://unpkg.com/maplibre-gl@${packageJson.version}/`;
|
|
90
|
+
const indexArray = [] as HtmlDoc[];
|
|
91
|
+
for (const file of files) {
|
|
92
|
+
const htmlFile = path.join(examplesFolder, file);
|
|
93
|
+
let htmlContent = fs.readFileSync(htmlFile, 'utf-8');
|
|
94
|
+
htmlContent = htmlContent.replace(/\.\.\/\.\.\//g, maplibreUnpkg);
|
|
95
|
+
htmlContent = htmlContent.replace(/-dev.js/g, '.js');
|
|
96
|
+
const htmlContentLines = htmlContent.split('\n');
|
|
97
|
+
const title = htmlContentLines.find(l => l.includes('<title'))?.replace('<title>', '').replace('</title>', '').trim()!;
|
|
98
|
+
const description = htmlContentLines.find(l => l.includes('og:description'))?.replace(/.*content=\"(.*)\".*/, '$1')!;
|
|
99
|
+
fs.writeFileSync(path.join(examplesDocsFolder, file), htmlContent);
|
|
100
|
+
const mdFileName = file.replace('.html', '.md');
|
|
101
|
+
indexArray.push({
|
|
102
|
+
title,
|
|
103
|
+
description,
|
|
104
|
+
mdFileName
|
|
105
|
+
});
|
|
106
|
+
const exampleMarkdown = generateMarkdownForExample(title, description, file, htmlContent);
|
|
107
|
+
fs.writeFileSync(path.join(examplesDocsFolder, mdFileName), exampleMarkdown);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const indexMarkdown = generateMarkdownIndexFileOfAllExamples(indexArray);
|
|
111
|
+
fs.writeFileSync(path.join(examplesDocsFolder, 'index.md'), indexMarkdown);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function fetchUrlContent(url: string) {
|
|
115
|
+
return new Promise<string>((resolve, reject) => {
|
|
116
|
+
get(url, (res) => {
|
|
117
|
+
let data = '';
|
|
118
|
+
if (res.statusCode && (res.statusCode < 200 || res.statusCode >= 300)) {
|
|
119
|
+
reject(new Error(res.statusMessage));
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
res.on('data', (chunk) => {
|
|
124
|
+
data += chunk;
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
res.on('end', () => {
|
|
128
|
+
resolve(data);
|
|
129
|
+
});
|
|
130
|
+
}).on('error', reject);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async function generatePluginsPage() {
|
|
135
|
+
/**
|
|
136
|
+
* It extract some sections from Awesome MapLibre README.md so we can integrate it into our plugins page
|
|
137
|
+
*
|
|
138
|
+
* ```
|
|
139
|
+
* header
|
|
140
|
+
* <!-- [SOME-ID]:BEGIN -->
|
|
141
|
+
* CONTENT-TO-EXTRACT
|
|
142
|
+
* <!-- [SOME-ID]:END -->
|
|
143
|
+
* footer
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
const awesomeReadmeUrl = 'https://raw.githubusercontent.com/maplibre/awesome-maplibre/main/README.md';
|
|
147
|
+
const awesomeReadme = await fetchUrlContent(awesomeReadmeUrl);
|
|
148
|
+
|
|
149
|
+
const contentGroupsRE = /<!--\s*\[([-a-zA-Z]+)\]:BEGIN\s*-->([\s\S]*?)<!--\s*\[\1\]:END\s*-->/g;
|
|
150
|
+
|
|
151
|
+
const matches = awesomeReadme.matchAll(contentGroupsRE);
|
|
152
|
+
const groups = Object.fromEntries(
|
|
153
|
+
Array.from(matches).map(([, key, content]) => [key, content])
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
const pluginsContent = `# Plugins
|
|
157
|
+
|
|
158
|
+
${groups['JAVASCRIPT-PLUGINS']}
|
|
159
|
+
|
|
160
|
+
## Framework Integrations
|
|
161
|
+
|
|
162
|
+
${groups['JAVASCRIPT-BINDINGS']}
|
|
163
|
+
`;
|
|
164
|
+
|
|
165
|
+
fs.writeFileSync('docs/plugins.md', pluginsContent, {encoding: 'utf-8'});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function updateMapLibreVersionForUNPKG() {
|
|
169
|
+
|
|
170
|
+
// Read index.md
|
|
171
|
+
const indexPath = 'docs/index.md';
|
|
172
|
+
let indexContent = fs.readFileSync(indexPath, 'utf-8');
|
|
173
|
+
|
|
174
|
+
// Replace the version number
|
|
175
|
+
indexContent = indexContent.replace(/unpkg\.com\/maplibre-gl@\^(\d+\.\d+\.\d+)/g, `unpkg.com/maplibre-gl@^${packageJson.version}`);
|
|
176
|
+
|
|
177
|
+
// Save index.md
|
|
178
|
+
fs.writeFileSync(indexPath, indexContent);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// !!Main flow start here!!
|
|
182
|
+
if (!fs.existsSync(typedocConfig.out)) {
|
|
183
|
+
throw new Error('Please run typedoc generation first!');
|
|
184
|
+
}
|
|
185
|
+
fs.rmSync(path.join(typedocConfig.out, 'README.md'));
|
|
186
|
+
generateReadme();
|
|
187
|
+
generateExamplesFolder();
|
|
188
|
+
await generatePluginsPage();
|
|
189
|
+
updateMapLibreVersionForUNPKG();
|
|
190
|
+
console.log('Docs generation completed, to see it in action run\n npm run start-docs');
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import {globSync} from 'glob';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
|
|
5
|
+
console.log('Generating shaders');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* This script is intended to copy the glsl file to the compilation output folder,
|
|
9
|
+
* change their extension to .js and export the shaders as strings in javascript.
|
|
10
|
+
* It will also minify them a bit if needed and change the extension to .js
|
|
11
|
+
* After that it will create a combined typescript definition file and manipulate it a bit
|
|
12
|
+
* It will also create a simple package.json file to allow importing this package in webpack
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const vertex = globSync('./src/shaders/*.vertex.glsl');
|
|
16
|
+
for (const file of vertex) {
|
|
17
|
+
const code = fs.readFileSync(file, 'utf8');
|
|
18
|
+
const content = glslToTs(code, 'vertex');
|
|
19
|
+
const fileName = path.join('.', 'src', 'shaders', `${file.split(path.sep).splice(-1)}.g.ts`);
|
|
20
|
+
fs.writeFileSync(fileName, content);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
console.log(`Finished converting ${vertex.length} vertex shaders`);
|
|
24
|
+
|
|
25
|
+
const fragment = globSync('./src/shaders/*.fragment.glsl');
|
|
26
|
+
for (const file of fragment) {
|
|
27
|
+
const code = fs.readFileSync(file, 'utf8');
|
|
28
|
+
const content = glslToTs(code, 'fragment');
|
|
29
|
+
const fileName = path.join('.', 'src', 'shaders', `${file.split(path.sep).splice(-1)}.g.ts`);
|
|
30
|
+
fs.writeFileSync(fileName, content);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
console.log(`Finished converting ${fragment.length} fragment shaders`);
|
|
34
|
+
|
|
35
|
+
function glslToTs(code: string, type: 'fragment'|'vertex'): string {
|
|
36
|
+
code = code
|
|
37
|
+
.trim(); // strip whitespace at the start/end
|
|
38
|
+
|
|
39
|
+
// WebGL1 Compat -- Start
|
|
40
|
+
|
|
41
|
+
if (type === 'fragment') {
|
|
42
|
+
code = code
|
|
43
|
+
.replace(/\bin\s/g, 'varying ') // For fragment shaders, replace "in " with "varying "
|
|
44
|
+
.replace('out highp vec4 fragColor;', '');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (type === 'vertex') {
|
|
48
|
+
code = code
|
|
49
|
+
.replace(/\bin\s/g, 'attribute ') // For vertex shaders, replace "in " with "attribute "
|
|
50
|
+
.replace(/\bout\s/g, 'varying '); // For vertex shaders, replace "out " with "varying "
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
code = code
|
|
54
|
+
.replace(/fragColor/g, 'gl_FragColor')
|
|
55
|
+
.replace(/texture\(/g, 'texture2D(');
|
|
56
|
+
|
|
57
|
+
// WebGL1 Compat -- End
|
|
58
|
+
|
|
59
|
+
code = code
|
|
60
|
+
.replace(/\s*\/\/[^\n]*\n/g, '\n') // strip double-slash comments
|
|
61
|
+
.replace(/\n+/g, '\n') // collapse multi line breaks
|
|
62
|
+
.replace(/\n\s+/g, '\n') // strip indentation
|
|
63
|
+
.replace(/\s?([+-\/*=,])\s?/g, '$1') // strip whitespace around operators
|
|
64
|
+
.replace(/([;\(\),\{\}])\n(?=[^#])/g, '$1'); // strip more line breaks
|
|
65
|
+
|
|
66
|
+
return `// This file is generated. Edit build/generate-shaders.ts, then run \`npm run codegen\`.
|
|
67
|
+
export default ${JSON.stringify(code).replaceAll('"', '\'')};\n`;
|
|
68
|
+
}
|
|
@@ -0,0 +1,438 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Generates the following:
|
|
3
|
+
* - data/array_types.js, which consists of:
|
|
4
|
+
* - StructArrayLayout_* subclasses, one for each underlying memory layout we need
|
|
5
|
+
* - Named exports mapping each conceptual array type (e.g., CircleLayoutArray) to its corresponding StructArrayLayout class
|
|
6
|
+
* - Particular, named StructArray subclasses, when fancy struct accessors are needed (e.g. CollisionBoxArray)
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
'use strict';
|
|
10
|
+
|
|
11
|
+
import * as fs from 'fs';
|
|
12
|
+
import * as util from '../src/util/util';
|
|
13
|
+
import {createLayout, viewTypes} from '../src/util/struct_array';
|
|
14
|
+
import type {ViewType, StructArrayLayout} from '../src/util/struct_array';
|
|
15
|
+
|
|
16
|
+
import posAttributes from '../src/data/pos_attributes';
|
|
17
|
+
import pos3dAttributes from '../src/data/pos3d_attributes';
|
|
18
|
+
import rasterBoundsAttributes from '../src/data/raster_bounds_attributes';
|
|
19
|
+
import circleAttributes from '../src/data/bucket/circle_attributes';
|
|
20
|
+
import fillAttributes from '../src/data/bucket/fill_attributes';
|
|
21
|
+
import fillExtrusionAttributes from '../src/data/bucket/fill_extrusion_attributes';
|
|
22
|
+
import {lineLayoutAttributes} from '../src/data/bucket/line_attributes';
|
|
23
|
+
import {lineLayoutAttributesExt} from '../src/data/bucket/line_attributes_ext';
|
|
24
|
+
import {patternAttributes} from '../src/data/bucket/pattern_attributes';
|
|
25
|
+
// symbol layer specific arrays
|
|
26
|
+
import {
|
|
27
|
+
symbolLayoutAttributes,
|
|
28
|
+
dynamicLayoutAttributes,
|
|
29
|
+
placementOpacityAttributes,
|
|
30
|
+
collisionBox,
|
|
31
|
+
collisionBoxLayout,
|
|
32
|
+
collisionCircleLayout,
|
|
33
|
+
collisionVertexAttributes,
|
|
34
|
+
quadTriangle,
|
|
35
|
+
placement,
|
|
36
|
+
symbolInstance,
|
|
37
|
+
glyphOffset,
|
|
38
|
+
lineVertex,
|
|
39
|
+
textAnchorOffset
|
|
40
|
+
} from '../src/data/bucket/symbol_attributes';
|
|
41
|
+
|
|
42
|
+
const typeAbbreviations = {
|
|
43
|
+
'Int8': 'b',
|
|
44
|
+
'Uint8': 'ub',
|
|
45
|
+
'Int16': 'i',
|
|
46
|
+
'Uint16': 'ui',
|
|
47
|
+
'Int32': 'l',
|
|
48
|
+
'Uint32': 'ul',
|
|
49
|
+
'Float32': 'f'
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const arraysWithStructAccessors = [];
|
|
53
|
+
const arrayTypeEntries = new Set();
|
|
54
|
+
const layoutCache = {};
|
|
55
|
+
|
|
56
|
+
function normalizeMembers(members, usedTypes) {
|
|
57
|
+
return members.map((member) => {
|
|
58
|
+
if (usedTypes && !usedTypes.has(member.type)) {
|
|
59
|
+
usedTypes.add(member.type);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return util.extend(member, {
|
|
63
|
+
size: sizeOf(member.type),
|
|
64
|
+
view: member.type.toLowerCase()
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// - If necessary, write the StructArrayLayout_* class for the given layout
|
|
70
|
+
// - If `includeStructAccessors`, write the fancy subclass
|
|
71
|
+
// - Add an entry for `name` in the array type registry
|
|
72
|
+
function createStructArrayType(name: string, layout: StructArrayLayout, includeStructAccessors: boolean = false) {
|
|
73
|
+
const hasAnchorPoint = layout.members.some(m => m.name === 'anchorPointX');
|
|
74
|
+
|
|
75
|
+
// create the underlying StructArrayLayout class exists
|
|
76
|
+
const layoutClass = createStructArrayLayoutType(layout);
|
|
77
|
+
const arrayClass = `${camelize(name)}Array`;
|
|
78
|
+
|
|
79
|
+
if (includeStructAccessors) {
|
|
80
|
+
const usedTypes = new Set(['Uint8']);
|
|
81
|
+
const members = normalizeMembers(layout.members, usedTypes);
|
|
82
|
+
arraysWithStructAccessors.push({
|
|
83
|
+
arrayClass,
|
|
84
|
+
members,
|
|
85
|
+
size: layout.size,
|
|
86
|
+
usedTypes,
|
|
87
|
+
hasAnchorPoint,
|
|
88
|
+
layoutClass,
|
|
89
|
+
includeStructAccessors
|
|
90
|
+
});
|
|
91
|
+
} else {
|
|
92
|
+
arrayTypeEntries.add(`export class ${arrayClass} extends ${layoutClass} {}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function createStructArrayLayoutType({members, size, alignment}) {
|
|
97
|
+
const usedTypes = new Set(['Uint8']);
|
|
98
|
+
members = normalizeMembers(members, usedTypes);
|
|
99
|
+
|
|
100
|
+
// combine consecutive 'members' with same underlying type, summing their
|
|
101
|
+
// component counts
|
|
102
|
+
if (!alignment || alignment === 1) members = members.reduce((memo, member) => {
|
|
103
|
+
if (memo.length > 0 && memo[memo.length - 1].type === member.type) {
|
|
104
|
+
const last = memo[memo.length - 1];
|
|
105
|
+
return memo.slice(0, -1).concat(util.extend({}, last, {
|
|
106
|
+
components: last.components + member.components,
|
|
107
|
+
}));
|
|
108
|
+
}
|
|
109
|
+
return memo.concat(member);
|
|
110
|
+
}, []);
|
|
111
|
+
|
|
112
|
+
const key = `${members.map(m => `${m.components}${typeAbbreviations[m.type]}`).join('')}${size}`;
|
|
113
|
+
const className = `StructArrayLayout${key}`;
|
|
114
|
+
|
|
115
|
+
if (!layoutCache[key]) {
|
|
116
|
+
layoutCache[key] = {
|
|
117
|
+
className,
|
|
118
|
+
members,
|
|
119
|
+
size,
|
|
120
|
+
usedTypes
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return className;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function sizeOf(type: ViewType): number {
|
|
128
|
+
return viewTypes[type].BYTES_PER_ELEMENT;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function camelize (str) {
|
|
132
|
+
return str.replace(/(?:^|[-_])(.)/g, (_, x) => {
|
|
133
|
+
return /^[0-9]$/.test(x) ? _ : x.toUpperCase();
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
createStructArrayType('pos', posAttributes);
|
|
138
|
+
createStructArrayType('pos3d', pos3dAttributes);
|
|
139
|
+
createStructArrayType('raster_bounds', rasterBoundsAttributes);
|
|
140
|
+
|
|
141
|
+
// layout vertex arrays
|
|
142
|
+
const layoutAttributes = {
|
|
143
|
+
circle: circleAttributes,
|
|
144
|
+
fill: fillAttributes,
|
|
145
|
+
'fill-extrusion': fillExtrusionAttributes,
|
|
146
|
+
heatmap: circleAttributes,
|
|
147
|
+
line: lineLayoutAttributes,
|
|
148
|
+
lineExt: lineLayoutAttributesExt,
|
|
149
|
+
pattern: patternAttributes
|
|
150
|
+
};
|
|
151
|
+
for (const name in layoutAttributes) {
|
|
152
|
+
createStructArrayType(`${name.replace(/-/g, '_')}_layout`, layoutAttributes[name]);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
createStructArrayType('symbol_layout', symbolLayoutAttributes);
|
|
156
|
+
createStructArrayType('symbol_dynamic_layout', dynamicLayoutAttributes);
|
|
157
|
+
createStructArrayType('symbol_opacity', placementOpacityAttributes);
|
|
158
|
+
createStructArrayType('collision_box', collisionBox, true);
|
|
159
|
+
createStructArrayType('collision_box_layout', collisionBoxLayout);
|
|
160
|
+
createStructArrayType('collision_circle_layout', collisionCircleLayout);
|
|
161
|
+
createStructArrayType('collision_vertex', collisionVertexAttributes);
|
|
162
|
+
createStructArrayType('quad_triangle', quadTriangle);
|
|
163
|
+
createStructArrayType('placed_symbol', placement, true);
|
|
164
|
+
createStructArrayType('symbol_instance', symbolInstance, true);
|
|
165
|
+
createStructArrayType('glyph_offset', glyphOffset, true);
|
|
166
|
+
createStructArrayType('symbol_line_vertex', lineVertex, true);
|
|
167
|
+
createStructArrayType('text_anchor_offset', textAnchorOffset, true);
|
|
168
|
+
|
|
169
|
+
// feature index array
|
|
170
|
+
createStructArrayType('feature_index', createLayout([
|
|
171
|
+
// the index of the feature in the original vectortile
|
|
172
|
+
{type: 'Uint32', name: 'featureIndex'},
|
|
173
|
+
// the source layer the feature appears in
|
|
174
|
+
{type: 'Uint16', name: 'sourceLayerIndex'},
|
|
175
|
+
// the bucket the feature appears in
|
|
176
|
+
{type: 'Uint16', name: 'bucketIndex'}
|
|
177
|
+
]), true);
|
|
178
|
+
|
|
179
|
+
// triangle index array
|
|
180
|
+
createStructArrayType('triangle_index', createLayout([
|
|
181
|
+
{type: 'Uint16', name: 'vertices', components: 3}
|
|
182
|
+
]));
|
|
183
|
+
|
|
184
|
+
// line index array
|
|
185
|
+
createStructArrayType('line_index', createLayout([
|
|
186
|
+
{type: 'Uint16', name: 'vertices', components: 2}
|
|
187
|
+
]));
|
|
188
|
+
|
|
189
|
+
// line strip index array
|
|
190
|
+
createStructArrayType('line_strip_index', createLayout([
|
|
191
|
+
{type: 'Uint16', name: 'vertices', components: 1}
|
|
192
|
+
]));
|
|
193
|
+
|
|
194
|
+
// paint vertex arrays
|
|
195
|
+
|
|
196
|
+
// used by SourceBinder for float properties
|
|
197
|
+
createStructArrayLayoutType(createLayout([{
|
|
198
|
+
name: 'dummy name (unused for StructArrayLayout)',
|
|
199
|
+
type: 'Float32',
|
|
200
|
+
components: 1
|
|
201
|
+
}], 4));
|
|
202
|
+
|
|
203
|
+
// used by SourceBinder for color properties and CompositeBinder for float properties
|
|
204
|
+
createStructArrayLayoutType(createLayout([{
|
|
205
|
+
name: 'dummy name (unused for StructArrayLayout)',
|
|
206
|
+
type: 'Float32',
|
|
207
|
+
components: 2
|
|
208
|
+
}], 4));
|
|
209
|
+
|
|
210
|
+
// used by CompositeBinder for color properties
|
|
211
|
+
createStructArrayLayoutType(createLayout([{
|
|
212
|
+
name: 'dummy name (unused for StructArrayLayout)',
|
|
213
|
+
type: 'Float32',
|
|
214
|
+
components: 4
|
|
215
|
+
}], 4));
|
|
216
|
+
|
|
217
|
+
const layouts = Object.keys(layoutCache).map(k => layoutCache[k]);
|
|
218
|
+
|
|
219
|
+
function emitStructArrayLayout(locals) {
|
|
220
|
+
const output = [];
|
|
221
|
+
const {
|
|
222
|
+
className,
|
|
223
|
+
members,
|
|
224
|
+
size,
|
|
225
|
+
usedTypes
|
|
226
|
+
} = locals;
|
|
227
|
+
const structArrayLayoutClass = className;
|
|
228
|
+
|
|
229
|
+
output.push(
|
|
230
|
+
`/**
|
|
231
|
+
* @internal
|
|
232
|
+
* Implementation of the StructArray layout:`);
|
|
233
|
+
|
|
234
|
+
for (const member of members) {
|
|
235
|
+
output.push(
|
|
236
|
+
` * [${member.offset}] - ${member.type}[${member.components}]`);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
output.push(
|
|
240
|
+
` *
|
|
241
|
+
*/
|
|
242
|
+
class ${structArrayLayoutClass} extends StructArray {`);
|
|
243
|
+
|
|
244
|
+
for (const type of usedTypes) {
|
|
245
|
+
output.push(
|
|
246
|
+
` ${type.toLowerCase()}: ${type}Array;`);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
output.push(`
|
|
250
|
+
_refreshViews() {`);
|
|
251
|
+
|
|
252
|
+
for (const type of usedTypes) {
|
|
253
|
+
output.push(
|
|
254
|
+
` this.${type.toLowerCase()} = new ${type}Array(this.arrayBuffer);`);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
output.push(
|
|
258
|
+
' }');
|
|
259
|
+
|
|
260
|
+
// prep for emplaceBack: collect type sizes and count the number of arguments
|
|
261
|
+
// we'll need
|
|
262
|
+
const bytesPerElement = size;
|
|
263
|
+
const usedTypeSizes = [];
|
|
264
|
+
const argNames = [];
|
|
265
|
+
const argNamesTyped = [];
|
|
266
|
+
|
|
267
|
+
for (const member of members) {
|
|
268
|
+
if (usedTypeSizes.indexOf(member.size) < 0) {
|
|
269
|
+
usedTypeSizes.push(member.size);
|
|
270
|
+
}
|
|
271
|
+
for (let c = 0; c < member.components; c++) {
|
|
272
|
+
// arguments v0, v1, v2, ... are, in order, the components of
|
|
273
|
+
// member 0, then the components of member 1, etc.
|
|
274
|
+
const name = `v${argNames.length}`;
|
|
275
|
+
argNames.push(name);
|
|
276
|
+
argNamesTyped.push(`${name}: number`);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
output.push(
|
|
281
|
+
`
|
|
282
|
+
public emplaceBack(${argNamesTyped.join(', ')}) {
|
|
283
|
+
const i = this.length;
|
|
284
|
+
this.resize(i + 1);
|
|
285
|
+
return this.emplace(i, ${argNames.join(', ')});
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
public emplace(i: number, ${argNamesTyped.join(', ')}) {`);
|
|
289
|
+
|
|
290
|
+
for (const size of usedTypeSizes) {
|
|
291
|
+
output.push(
|
|
292
|
+
` const o${size.toFixed(0)} = i * ${(bytesPerElement / size).toFixed(0)};`);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
let argIndex = 0;
|
|
296
|
+
for (const member of members) {
|
|
297
|
+
for (let c = 0; c < member.components; c++) {
|
|
298
|
+
// The index for `member` component `c` into the appropriate type array is:
|
|
299
|
+
// this.{TYPE}[o{SIZE} + MEMBER_OFFSET + {c}] = v{X}
|
|
300
|
+
// where MEMBER_OFFSET = ROUND(member.offset / size) is the per-element
|
|
301
|
+
// offset of this member into the array
|
|
302
|
+
const index = `o${member.size.toFixed(0)} + ${(member.offset / member.size + c).toFixed(0)}`;
|
|
303
|
+
|
|
304
|
+
output.push(
|
|
305
|
+
` this.${member.view}[${index}] = v${argIndex++};`);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
output.push(
|
|
310
|
+
` return i;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
${structArrayLayoutClass}.prototype.bytesPerElement = ${size};
|
|
315
|
+
register('${structArrayLayoutClass}', ${structArrayLayoutClass});
|
|
316
|
+
`);
|
|
317
|
+
|
|
318
|
+
return output.join('\n');
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
function emitStructArray(locals) {
|
|
322
|
+
const output = [];
|
|
323
|
+
const {
|
|
324
|
+
arrayClass,
|
|
325
|
+
members,
|
|
326
|
+
size,
|
|
327
|
+
hasAnchorPoint,
|
|
328
|
+
layoutClass,
|
|
329
|
+
includeStructAccessors
|
|
330
|
+
} = locals;
|
|
331
|
+
|
|
332
|
+
const structTypeClass = arrayClass.replace('Array', 'Struct');
|
|
333
|
+
const structArrayClass = arrayClass;
|
|
334
|
+
const structArrayLayoutClass = layoutClass;
|
|
335
|
+
|
|
336
|
+
// collect components
|
|
337
|
+
const components = [];
|
|
338
|
+
for (const member of members) {
|
|
339
|
+
for (let c = 0; c < member.components; c++) {
|
|
340
|
+
let name = member.name;
|
|
341
|
+
if (member.components > 1) {
|
|
342
|
+
name += c;
|
|
343
|
+
}
|
|
344
|
+
components.push({name, member, component: c});
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// exceptions for which we generate accessors on the array rather than a separate struct for performance
|
|
349
|
+
const useComponentGetters = structArrayClass === 'GlyphOffsetArray' || structArrayClass === 'SymbolLineVertexArray';
|
|
350
|
+
|
|
351
|
+
if (includeStructAccessors && !useComponentGetters) {
|
|
352
|
+
output.push(
|
|
353
|
+
`/** @internal */
|
|
354
|
+
class ${structTypeClass} extends Struct {
|
|
355
|
+
_structArray: ${structArrayClass};`);
|
|
356
|
+
|
|
357
|
+
for (const {name, member, component} of components) {
|
|
358
|
+
const elementOffset = `this._pos${member.size.toFixed(0)}`;
|
|
359
|
+
const componentOffset = (member.offset / member.size + component).toFixed(0);
|
|
360
|
+
const index = `${elementOffset} + ${componentOffset}`;
|
|
361
|
+
const componentAccess = `this._structArray.${member.view}[${index}]`;
|
|
362
|
+
|
|
363
|
+
output.push(
|
|
364
|
+
` get ${name}() { return ${componentAccess}; }`);
|
|
365
|
+
|
|
366
|
+
// generate setters for properties that are updated during runtime symbol placement; others are read-only
|
|
367
|
+
if (name === 'crossTileID' || name === 'placedOrientation' || name === 'hidden') {
|
|
368
|
+
output.push(
|
|
369
|
+
` set ${name}(x: number) { ${componentAccess} = x; }`);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
// Special case used for the CollisionBoxArray type
|
|
374
|
+
if (hasAnchorPoint) {
|
|
375
|
+
output.push(
|
|
376
|
+
' get anchorPoint() { return new Point(this.anchorPointX, this.anchorPointY); }');
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
output.push(
|
|
380
|
+
`}
|
|
381
|
+
|
|
382
|
+
${structTypeClass}.prototype.size = ${size};
|
|
383
|
+
|
|
384
|
+
export type ${structTypeClass.replace('Struct', '')} = ${structTypeClass};
|
|
385
|
+
`);
|
|
386
|
+
} // end 'if (includeStructAccessors)'
|
|
387
|
+
|
|
388
|
+
output.push(
|
|
389
|
+
`/** @internal */
|
|
390
|
+
export class ${structArrayClass} extends ${structArrayLayoutClass} {`);
|
|
391
|
+
|
|
392
|
+
if (useComponentGetters) {
|
|
393
|
+
for (const member of members) {
|
|
394
|
+
for (let c = 0; c < member.components; c++) {
|
|
395
|
+
if (!includeStructAccessors) continue;
|
|
396
|
+
let name = `get${member.name}`;
|
|
397
|
+
if (member.components > 1) {
|
|
398
|
+
name += c;
|
|
399
|
+
}
|
|
400
|
+
const componentOffset = (member.offset / member.size + c).toFixed(0);
|
|
401
|
+
const componentStride = size / member.size;
|
|
402
|
+
output.push(
|
|
403
|
+
` ${name}(index: number) { return this.${member.view}[index * ${componentStride} + ${componentOffset}]; }`);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
} else if (includeStructAccessors) { // get(i)
|
|
407
|
+
output.push(
|
|
408
|
+
` /**
|
|
409
|
+
* Return the ${structTypeClass} at the given location in the array.
|
|
410
|
+
* @param index The index of the element.
|
|
411
|
+
*/
|
|
412
|
+
get(index: number): ${structTypeClass} {
|
|
413
|
+
return new ${structTypeClass}(this, index);
|
|
414
|
+
}`);
|
|
415
|
+
}
|
|
416
|
+
output.push(
|
|
417
|
+
`}
|
|
418
|
+
|
|
419
|
+
register('${structArrayClass}', ${structArrayClass});
|
|
420
|
+
`);
|
|
421
|
+
|
|
422
|
+
return output.join('\n');
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
fs.writeFileSync('src/data/array_types.g.ts',
|
|
426
|
+
`// This file is generated. Edit build/generate-struct-arrays.ts, then run \`npm run codegen\`.
|
|
427
|
+
|
|
428
|
+
import {Struct, StructArray} from '../util/struct_array';
|
|
429
|
+
import {register} from '../util/web_worker_transfer';
|
|
430
|
+
import Point from '@mapbox/point-geometry';
|
|
431
|
+
|
|
432
|
+
${layouts.map(emitStructArrayLayout).join('\n')}
|
|
433
|
+
${arraysWithStructAccessors.map(emitStructArray).join('\n')}
|
|
434
|
+
${[...arrayTypeEntries].join('\n')}
|
|
435
|
+
export {
|
|
436
|
+
${layouts.map(layout => layout.className).join(',\n ')}
|
|
437
|
+
};
|
|
438
|
+
`);
|