mapbox-gl 1.13.2
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/.flowconfig +61 -0
- package/CHANGELOG.md +2485 -0
- package/LICENSE.txt +84 -0
- package/README.md +34 -0
- package/build/banner.js +4 -0
- package/build/check-bundle-size.js +140 -0
- package/build/diff-tarball.js +18 -0
- package/build/generate-access-token-script.js +11 -0
- package/build/generate-flow-typed-style-spec.js +188 -0
- package/build/generate-release-list.js +21 -0
- package/build/generate-struct-arrays.js +243 -0
- package/build/generate-style-code.js +159 -0
- package/build/mapbox-gl.js.flow +3 -0
- package/build/print-release-url.js +6 -0
- package/build/rollup_plugin_minify_style_spec.js +24 -0
- package/build/rollup_plugins.js +80 -0
- package/build/run-node +3 -0
- package/build/run-tap +8 -0
- package/build/test/build-tape.js +19 -0
- package/dist/mapbox-gl-csp-worker.js +2 -0
- package/dist/mapbox-gl-csp-worker.js.map +1 -0
- package/dist/mapbox-gl-csp.js +2 -0
- package/dist/mapbox-gl-csp.js.map +1 -0
- package/dist/mapbox-gl-dev.js +65889 -0
- package/dist/mapbox-gl-dev.js.flow +3 -0
- package/dist/mapbox-gl-unminified.js +42889 -0
- package/dist/mapbox-gl-unminified.js.map +1 -0
- package/dist/mapbox-gl.css +1 -0
- package/dist/mapbox-gl.js +42 -0
- package/dist/mapbox-gl.js.flow +3 -0
- package/dist/mapbox-gl.js.map +1 -0
- package/dist/style-spec/index.es.js +15032 -0
- package/dist/style-spec/index.es.js.map +1 -0
- package/dist/style-spec/index.js +15058 -0
- package/dist/style-spec/index.js.map +1 -0
- package/flow-typed/gl.js +5 -0
- package/flow-typed/jsdom.js +18 -0
- package/flow-typed/mapbox-gl-supported.js +9 -0
- package/flow-typed/mapbox-unitbezier.js +14 -0
- package/flow-typed/offscreen-canvas.js +9 -0
- package/flow-typed/pbf.js +25 -0
- package/flow-typed/point-geometry.js +44 -0
- package/flow-typed/potpack.js +12 -0
- package/flow-typed/sinon.js +28 -0
- package/flow-typed/vector-tile.js +41 -0
- package/package.json +173 -0
- package/src/css/mapbox-gl.css +812 -0
- package/src/css/svg/mapboxgl-ctrl-attrib.svg +3 -0
- package/src/css/svg/mapboxgl-ctrl-compass.svg +4 -0
- package/src/css/svg/mapboxgl-ctrl-fullscreen.svg +3 -0
- package/src/css/svg/mapboxgl-ctrl-geolocate.svg +5 -0
- package/src/css/svg/mapboxgl-ctrl-logo.svg +20 -0
- package/src/css/svg/mapboxgl-ctrl-shrink.svg +3 -0
- package/src/css/svg/mapboxgl-ctrl-zoom-in.svg +3 -0
- package/src/css/svg/mapboxgl-ctrl-zoom-out.svg +3 -0
- package/src/data/array_types.js +1135 -0
- package/src/data/bucket/circle_attributes.js +9 -0
- package/src/data/bucket/circle_bucket.js +201 -0
- package/src/data/bucket/fill_attributes.js +9 -0
- package/src/data/bucket/fill_bucket.js +229 -0
- package/src/data/bucket/fill_extrusion_attributes.js +10 -0
- package/src/data/bucket/fill_extrusion_bucket.js +283 -0
- package/src/data/bucket/heatmap_bucket.js +17 -0
- package/src/data/bucket/line_attributes.js +10 -0
- package/src/data/bucket/line_attributes_ext.js +10 -0
- package/src/data/bucket/line_bucket.js +594 -0
- package/src/data/bucket/pattern_attributes.js +12 -0
- package/src/data/bucket/pattern_bucket_features.js +60 -0
- package/src/data/bucket/symbol_attributes.js +117 -0
- package/src/data/bucket/symbol_bucket.js +937 -0
- package/src/data/bucket.js +123 -0
- package/src/data/dem_data.js +125 -0
- package/src/data/evaluation_feature.js +25 -0
- package/src/data/extent.js +18 -0
- package/src/data/feature_index.js +322 -0
- package/src/data/feature_position_map.js +131 -0
- package/src/data/index_array_type.js +16 -0
- package/src/data/load_geometry.js +46 -0
- package/src/data/pos_attributes.js +6 -0
- package/src/data/program_configuration.js +708 -0
- package/src/data/raster_bounds_attributes.js +7 -0
- package/src/data/segment.js +76 -0
- package/src/geo/edge_insets.js +102 -0
- package/src/geo/lng_lat.js +168 -0
- package/src/geo/lng_lat_bounds.js +276 -0
- package/src/geo/mercator_coordinate.js +150 -0
- package/src/geo/transform.js +834 -0
- package/src/gl/color_mode.js +34 -0
- package/src/gl/context.js +302 -0
- package/src/gl/cull_face_mode.js +26 -0
- package/src/gl/depth_mode.js +29 -0
- package/src/gl/framebuffer.js +44 -0
- package/src/gl/index_buffer.js +55 -0
- package/src/gl/stencil_mode.js +30 -0
- package/src/gl/types.js +84 -0
- package/src/gl/value.js +520 -0
- package/src/gl/vertex_buffer.js +119 -0
- package/src/index.js +230 -0
- package/src/render/draw_background.js +57 -0
- package/src/render/draw_circle.js +113 -0
- package/src/render/draw_collision_debug.js +172 -0
- package/src/render/draw_custom.js +49 -0
- package/src/render/draw_debug.js +127 -0
- package/src/render/draw_fill.js +124 -0
- package/src/render/draw_fill_extrusion.js +95 -0
- package/src/render/draw_heatmap.js +133 -0
- package/src/render/draw_hillshade.js +107 -0
- package/src/render/draw_line.js +125 -0
- package/src/render/draw_raster.js +125 -0
- package/src/render/draw_symbol.js +392 -0
- package/src/render/glyph_atlas.js +71 -0
- package/src/render/glyph_manager.js +182 -0
- package/src/render/image_atlas.js +149 -0
- package/src/render/image_manager.js +306 -0
- package/src/render/line_atlas.js +210 -0
- package/src/render/painter.js +654 -0
- package/src/render/program/background_program.js +103 -0
- package/src/render/program/circle_program.js +69 -0
- package/src/render/program/clipping_mask_program.js +20 -0
- package/src/render/program/collision_program.js +76 -0
- package/src/render/program/debug_program.js +35 -0
- package/src/render/program/fill_extrusion_program.js +122 -0
- package/src/render/program/fill_program.js +126 -0
- package/src/render/program/heatmap_program.js +83 -0
- package/src/render/program/hillshade_program.js +119 -0
- package/src/render/program/line_program.js +211 -0
- package/src/render/program/pattern.js +102 -0
- package/src/render/program/program_uniforms.js +42 -0
- package/src/render/program/raster_program.js +92 -0
- package/src/render/program/symbol_program.js +224 -0
- package/src/render/program.js +188 -0
- package/src/render/texture.js +122 -0
- package/src/render/uniform_binding.js +147 -0
- package/src/render/vertex_array_object.js +163 -0
- package/src/shaders/README.md +42 -0
- package/src/shaders/_prelude.fragment.glsl +17 -0
- package/src/shaders/_prelude.vertex.glsl +73 -0
- package/src/shaders/background.fragment.glsl +10 -0
- package/src/shaders/background.vertex.glsl +7 -0
- package/src/shaders/background_pattern.fragment.glsl +28 -0
- package/src/shaders/background_pattern.vertex.glsl +20 -0
- package/src/shaders/circle.fragment.glsl +39 -0
- package/src/shaders/circle.vertex.glsl +64 -0
- package/src/shaders/clipping_mask.fragment.glsl +3 -0
- package/src/shaders/clipping_mask.vertex.glsl +7 -0
- package/src/shaders/collision_box.fragment.glsl +21 -0
- package/src/shaders/collision_box.vertex.glsl +27 -0
- package/src/shaders/collision_circle.fragment.glsl +17 -0
- package/src/shaders/collision_circle.vertex.glsl +59 -0
- package/src/shaders/debug.fragment.glsl +9 -0
- package/src/shaders/debug.vertex.glsl +12 -0
- package/src/shaders/encode_attribute.js +17 -0
- package/src/shaders/fill.fragment.glsl +13 -0
- package/src/shaders/fill.vertex.glsl +13 -0
- package/src/shaders/fill_extrusion.fragment.glsl +9 -0
- package/src/shaders/fill_extrusion.vertex.glsl +66 -0
- package/src/shaders/fill_extrusion_pattern.fragment.glsl +45 -0
- package/src/shaders/fill_extrusion_pattern.vertex.glsl +79 -0
- package/src/shaders/fill_outline.fragment.glsl +17 -0
- package/src/shaders/fill_outline.vertex.glsl +17 -0
- package/src/shaders/fill_outline_pattern.fragment.glsl +43 -0
- package/src/shaders/fill_outline_pattern.vertex.glsl +44 -0
- package/src/shaders/fill_pattern.fragment.glsl +36 -0
- package/src/shaders/fill_pattern.vertex.glsl +39 -0
- package/src/shaders/heatmap.fragment.glsl +22 -0
- package/src/shaders/heatmap.vertex.glsl +54 -0
- package/src/shaders/heatmap_texture.fragment.glsl +14 -0
- package/src/shaders/heatmap_texture.vertex.glsl +11 -0
- package/src/shaders/hillshade.fragment.glsl +52 -0
- package/src/shaders/hillshade.vertex.glsl +11 -0
- package/src/shaders/hillshade_prepare.fragment.glsl +75 -0
- package/src/shaders/hillshade_prepare.vertex.glsl +15 -0
- package/src/shaders/index.js +20 -0
- package/src/shaders/line.fragment.glsl +30 -0
- package/src/shaders/line.vertex.glsl +85 -0
- package/src/shaders/line_gradient.fragment.glsl +34 -0
- package/src/shaders/line_gradient.vertex.glsl +88 -0
- package/src/shaders/line_pattern.fragment.glsl +74 -0
- package/src/shaders/line_pattern.vertex.glsl +99 -0
- package/src/shaders/line_sdf.fragment.glsl +45 -0
- package/src/shaders/line_sdf.vertex.glsl +98 -0
- package/src/shaders/raster.fragment.glsl +52 -0
- package/src/shaders/raster.vertex.glsl +21 -0
- package/src/shaders/shaders.js +185 -0
- package/src/shaders/symbol_icon.fragment.glsl +17 -0
- package/src/shaders/symbol_icon.vertex.glsl +94 -0
- package/src/shaders/symbol_sdf.fragment.glsl +52 -0
- package/src/shaders/symbol_sdf.vertex.glsl +115 -0
- package/src/shaders/symbol_text_and_icon.fragment.glsl +68 -0
- package/src/shaders/symbol_text_and_icon.vertex.glsl +116 -0
- package/src/source/canvas_source.js +238 -0
- package/src/source/geojson_source.js +370 -0
- package/src/source/geojson_worker_source.js +366 -0
- package/src/source/geojson_wrapper.js +94 -0
- package/src/source/image_source.js +307 -0
- package/src/source/load_tilejson.js +39 -0
- package/src/source/pixels_to_tile_units.js +21 -0
- package/src/source/query_features.js +208 -0
- package/src/source/raster_dem_tile_source.js +138 -0
- package/src/source/raster_dem_tile_worker_source.js +62 -0
- package/src/source/raster_tile_source.js +169 -0
- package/src/source/rtl_text_plugin.js +143 -0
- package/src/source/source.js +137 -0
- package/src/source/source_cache.js +953 -0
- package/src/source/source_state.js +159 -0
- package/src/source/tile.js +458 -0
- package/src/source/tile_bounds.js +38 -0
- package/src/source/tile_cache.js +212 -0
- package/src/source/tile_id.js +199 -0
- package/src/source/vector_tile_source.js +259 -0
- package/src/source/vector_tile_worker_source.js +216 -0
- package/src/source/video_source.js +203 -0
- package/src/source/worker.js +240 -0
- package/src/source/worker_source.js +107 -0
- package/src/source/worker_tile.js +224 -0
- package/src/style/create_style_layer.js +36 -0
- package/src/style/evaluation_parameters.js +62 -0
- package/src/style/format_section_override.js +56 -0
- package/src/style/light.js +130 -0
- package/src/style/load_glyph_range.js +38 -0
- package/src/style/load_sprite.js +67 -0
- package/src/style/parse_glyph_pbf.js +44 -0
- package/src/style/pauseable_placement.js +132 -0
- package/src/style/properties.js +753 -0
- package/src/style/query_utils.js +43 -0
- package/src/style/style.js +1374 -0
- package/src/style/style_glyph.js +17 -0
- package/src/style/style_image.js +137 -0
- package/src/style/style_layer/background_style_layer.js +21 -0
- package/src/style/style_layer/background_style_layer_properties.js +40 -0
- package/src/style/style_layer/circle_style_layer.js +98 -0
- package/src/style/style_layer/circle_style_layer_properties.js +63 -0
- package/src/style/style_layer/custom_style_layer.js +223 -0
- package/src/style/style_layer/fill_extrusion_style_layer.js +224 -0
- package/src/style/style_layer/fill_extrusion_style_layer_properties.js +50 -0
- package/src/style/style_layer/fill_style_layer.js +67 -0
- package/src/style/style_layer/fill_style_layer_properties.js +55 -0
- package/src/style/style_layer/heatmap_style_layer.js +73 -0
- package/src/style/style_layer/heatmap_style_layer_properties.js +44 -0
- package/src/style/style_layer/hillshade_style_layer.js +25 -0
- package/src/style/style_layer/hillshade_style_layer_properties.js +46 -0
- package/src/style/style_layer/layer_properties.js.ejs +69 -0
- package/src/style/style_layer/line_style_layer.js +150 -0
- package/src/style/style_layer/line_style_layer_properties.js +71 -0
- package/src/style/style_layer/raster_style_layer.js +21 -0
- package/src/style/style_layer/raster_style_layer_properties.js +50 -0
- package/src/style/style_layer/symbol_style_layer.js +190 -0
- package/src/style/style_layer/symbol_style_layer_properties.js +153 -0
- package/src/style/style_layer/typed_style_layer.js +17 -0
- package/src/style/style_layer.js +283 -0
- package/src/style/style_layer_index.js +80 -0
- package/src/style/validate_style.js +42 -0
- package/src/style/zoom_history.js +44 -0
- package/src/style-spec/.eslintrc +5 -0
- package/src/style-spec/CHANGELOG.md +468 -0
- package/src/style-spec/README.md +59 -0
- package/src/style-spec/bin/gl-style-composite +9 -0
- package/src/style-spec/bin/gl-style-format +22 -0
- package/src/style-spec/bin/gl-style-migrate +9 -0
- package/src/style-spec/bin/gl-style-validate +50 -0
- package/src/style-spec/composite.js +50 -0
- package/src/style-spec/declass.js +42 -0
- package/src/style-spec/deref.js +52 -0
- package/src/style-spec/diff.js +393 -0
- package/src/style-spec/dist/.gitkeep +0 -0
- package/src/style-spec/dist/index.es.js +15032 -0
- package/src/style-spec/dist/index.es.js.map +1 -0
- package/src/style-spec/dist/index.js +15058 -0
- package/src/style-spec/dist/index.js.map +1 -0
- package/src/style-spec/empty.js +29 -0
- package/src/style-spec/error/parsing_error.js +16 -0
- package/src/style-spec/error/validation_error.js +18 -0
- package/src/style-spec/expression/compound_expression.js +162 -0
- package/src/style-spec/expression/definitions/assertion.js +130 -0
- package/src/style-spec/expression/definitions/at.js +70 -0
- package/src/style-spec/expression/definitions/case.js +85 -0
- package/src/style-spec/expression/definitions/coalesce.js +93 -0
- package/src/style-spec/expression/definitions/coercion.js +133 -0
- package/src/style-spec/expression/definitions/collator.js +78 -0
- package/src/style-spec/expression/definitions/comparison.js +184 -0
- package/src/style-spec/expression/definitions/format.js +144 -0
- package/src/style-spec/expression/definitions/image.js +52 -0
- package/src/style-spec/expression/definitions/in.js +72 -0
- package/src/style-spec/expression/definitions/index.js +565 -0
- package/src/style-spec/expression/definitions/index_of.js +89 -0
- package/src/style-spec/expression/definitions/interpolate.js +267 -0
- package/src/style-spec/expression/definitions/length.js +61 -0
- package/src/style-spec/expression/definitions/let.js +72 -0
- package/src/style-spec/expression/definitions/literal.js +77 -0
- package/src/style-spec/expression/definitions/match.js +158 -0
- package/src/style-spec/expression/definitions/number_format.js +142 -0
- package/src/style-spec/expression/definitions/slice.js +86 -0
- package/src/style-spec/expression/definitions/step.js +120 -0
- package/src/style-spec/expression/definitions/var.js +46 -0
- package/src/style-spec/expression/definitions/within.js +342 -0
- package/src/style-spec/expression/evaluation_context.js +59 -0
- package/src/style-spec/expression/expression.js +27 -0
- package/src/style-spec/expression/index.js +392 -0
- package/src/style-spec/expression/is_constant.js +59 -0
- package/src/style-spec/expression/parsing_context.js +233 -0
- package/src/style-spec/expression/parsing_error.js +13 -0
- package/src/style-spec/expression/runtime_error.js +17 -0
- package/src/style-spec/expression/scope.js +36 -0
- package/src/style-spec/expression/stops.js +39 -0
- package/src/style-spec/expression/types/collator.js +61 -0
- package/src/style-spec/expression/types/formatted.js +73 -0
- package/src/style-spec/expression/types/resolved_image.js +29 -0
- package/src/style-spec/expression/types.js +126 -0
- package/src/style-spec/expression/values.js +123 -0
- package/src/style-spec/feature_filter/README.md +55 -0
- package/src/style-spec/feature_filter/convert.js +208 -0
- package/src/style-spec/feature_filter/index.js +175 -0
- package/src/style-spec/format.js +51 -0
- package/src/style-spec/function/convert.js +270 -0
- package/src/style-spec/function/index.js +262 -0
- package/src/style-spec/group_by_layout.js +75 -0
- package/src/style-spec/migrate/expressions.js +39 -0
- package/src/style-spec/migrate/v8.js +203 -0
- package/src/style-spec/migrate/v9.js +26 -0
- package/src/style-spec/migrate.js +36 -0
- package/src/style-spec/package.json +41 -0
- package/src/style-spec/read_style.js +14 -0
- package/src/style-spec/reference/latest.js +3 -0
- package/src/style-spec/reference/v8.json +5914 -0
- package/src/style-spec/rollup.config.js +65 -0
- package/src/style-spec/style-spec.js +124 -0
- package/src/style-spec/types.js +432 -0
- package/src/style-spec/util/color.js +95 -0
- package/src/style-spec/util/color_spaces.js +139 -0
- package/src/style-spec/util/deep_equal.js +28 -0
- package/src/style-spec/util/extend.js +10 -0
- package/src/style-spec/util/get_type.js +17 -0
- package/src/style-spec/util/interpolate.js +22 -0
- package/src/style-spec/util/properties.js +15 -0
- package/src/style-spec/util/ref_properties.js +2 -0
- package/src/style-spec/util/result.js +19 -0
- package/src/style-spec/util/unbundle_jsonlint.js +24 -0
- package/src/style-spec/validate/latest.js +11 -0
- package/src/style-spec/validate/validate.js +75 -0
- package/src/style-spec/validate/validate_array.js +52 -0
- package/src/style-spec/validate/validate_boolean.js +15 -0
- package/src/style-spec/validate/validate_color.js +20 -0
- package/src/style-spec/validate/validate_constants.js +13 -0
- package/src/style-spec/validate/validate_enum.js +21 -0
- package/src/style-spec/validate/validate_expression.js +43 -0
- package/src/style-spec/validate/validate_filter.js +117 -0
- package/src/style-spec/validate/validate_formatted.js +11 -0
- package/src/style-spec/validate/validate_function.js +207 -0
- package/src/style-spec/validate/validate_glyphs_url.js +21 -0
- package/src/style-spec/validate/validate_image.js +11 -0
- package/src/style-spec/validate/validate_layer.js +134 -0
- package/src/style-spec/validate/validate_layout_property.js +6 -0
- package/src/style-spec/validate/validate_light.js +47 -0
- package/src/style-spec/validate/validate_number.js +29 -0
- package/src/style-spec/validate/validate_object.js +61 -0
- package/src/style-spec/validate/validate_paint_property.js +6 -0
- package/src/style-spec/validate/validate_property.js +64 -0
- package/src/style-spec/validate/validate_source.js +111 -0
- package/src/style-spec/validate/validate_string.js +15 -0
- package/src/style-spec/validate_mapbox_api_supported.js +171 -0
- package/src/style-spec/validate_style.js +39 -0
- package/src/style-spec/validate_style.min.js +78 -0
- package/src/style-spec/visit.js +77 -0
- package/src/symbol/anchor.js +26 -0
- package/src/symbol/check_max_angle.js +81 -0
- package/src/symbol/clip_line.js +71 -0
- package/src/symbol/collision_feature.js +109 -0
- package/src/symbol/collision_index.js +373 -0
- package/src/symbol/cross_tile_symbol_index.js +301 -0
- package/src/symbol/get_anchors.js +167 -0
- package/src/symbol/grid_index.js +335 -0
- package/src/symbol/mergelines.js +82 -0
- package/src/symbol/one_em.js +4 -0
- package/src/symbol/opacity_state.js +27 -0
- package/src/symbol/path_interpolator.js +61 -0
- package/src/symbol/placement.js +1124 -0
- package/src/symbol/projection.js +451 -0
- package/src/symbol/quads.js +334 -0
- package/src/symbol/shaping.js +816 -0
- package/src/symbol/symbol_layout.js +796 -0
- package/src/symbol/symbol_size.js +113 -0
- package/src/symbol/transform_text.js +29 -0
- package/src/types/callback.js +17 -0
- package/src/types/cancelable.js +3 -0
- package/src/types/tilejson.js +17 -0
- package/src/types/transferable.js +3 -0
- package/src/types/window.js +172 -0
- package/src/ui/anchor.js +32 -0
- package/src/ui/camera.js +1277 -0
- package/src/ui/control/attribution_control.js +212 -0
- package/src/ui/control/fullscreen_control.js +147 -0
- package/src/ui/control/geolocate_control.js +707 -0
- package/src/ui/control/logo_control.js +92 -0
- package/src/ui/control/navigation_control.js +257 -0
- package/src/ui/control/scale_control.js +142 -0
- package/src/ui/default_locale.js +22 -0
- package/src/ui/events.js +1301 -0
- package/src/ui/handler/box_zoom.js +170 -0
- package/src/ui/handler/click_zoom.js +52 -0
- package/src/ui/handler/handler_util.js +12 -0
- package/src/ui/handler/keyboard.js +208 -0
- package/src/ui/handler/map_event.js +156 -0
- package/src/ui/handler/mouse.js +171 -0
- package/src/ui/handler/scroll_zoom.js +350 -0
- package/src/ui/handler/shim/dblclick_zoom.js +62 -0
- package/src/ui/handler/shim/drag_pan.js +88 -0
- package/src/ui/handler/shim/drag_rotate.js +67 -0
- package/src/ui/handler/shim/touch_zoom_rotate.js +108 -0
- package/src/ui/handler/tap_drag_zoom.js +103 -0
- package/src/ui/handler/tap_recognizer.js +133 -0
- package/src/ui/handler/tap_zoom.js +93 -0
- package/src/ui/handler/touch_pan.js +101 -0
- package/src/ui/handler/touch_zoom_rotate.js +305 -0
- package/src/ui/handler_inertia.js +158 -0
- package/src/ui/handler_manager.js +531 -0
- package/src/ui/hash.js +148 -0
- package/src/ui/map.js +2874 -0
- package/src/ui/marker.js +672 -0
- package/src/ui/popup.js +640 -0
- package/src/util/actor.js +212 -0
- package/src/util/ajax.js +388 -0
- package/src/util/browser/web_worker.js +10 -0
- package/src/util/browser/window.js +6 -0
- package/src/util/browser.js +70 -0
- package/src/util/classify_rings.js +52 -0
- package/src/util/color_ramp.js +61 -0
- package/src/util/config.js +30 -0
- package/src/util/debug.js +28 -0
- package/src/util/dictionary_coder.js +30 -0
- package/src/util/dispatcher.js +70 -0
- package/src/util/dom.js +142 -0
- package/src/util/evented.js +174 -0
- package/src/util/find_pole_of_inaccessibility.js +129 -0
- package/src/util/global_worker_pool.js +35 -0
- package/src/util/image.js +142 -0
- package/src/util/intersection_tests.js +208 -0
- package/src/util/is_char_in_unicode_block.js +311 -0
- package/src/util/mapbox.js +491 -0
- package/src/util/offscreen_canvas_supported.js +14 -0
- package/src/util/performance.js +112 -0
- package/src/util/primitives.js +145 -0
- package/src/util/resolve_tokens.js +16 -0
- package/src/util/script_detection.js +328 -0
- package/src/util/sku_token.js +42 -0
- package/src/util/smart_wrap.js +55 -0
- package/src/util/struct_array.js +243 -0
- package/src/util/struct_array.js.ejs +112 -0
- package/src/util/struct_array_layout.js.ejs +98 -0
- package/src/util/task_queue.js +68 -0
- package/src/util/throttle.js +27 -0
- package/src/util/throttled_invoker.js +46 -0
- package/src/util/tile_request_cache.js +172 -0
- package/src/util/util.js +524 -0
- package/src/util/vectortile_to_geojson.js +50 -0
- package/src/util/verticalize_punctuation.js +114 -0
- package/src/util/web_worker.js +91 -0
- package/src/util/web_worker_transfer.js +266 -0
- package/src/util/webp_supported.js +69 -0
- package/src/util/window.js +102 -0
- package/src/util/worker_pool.js +57 -0
|
@@ -0,0 +1,565 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type Type,
|
|
5
|
+
NumberType,
|
|
6
|
+
StringType,
|
|
7
|
+
BooleanType,
|
|
8
|
+
ColorType,
|
|
9
|
+
ObjectType,
|
|
10
|
+
ValueType,
|
|
11
|
+
ErrorType,
|
|
12
|
+
CollatorType,
|
|
13
|
+
array,
|
|
14
|
+
toString as typeToString
|
|
15
|
+
} from '../types';
|
|
16
|
+
|
|
17
|
+
import {typeOf, Color, validateRGBA, toString as valueToString} from '../values';
|
|
18
|
+
import CompoundExpression from '../compound_expression';
|
|
19
|
+
import RuntimeError from '../runtime_error';
|
|
20
|
+
import Let from './let';
|
|
21
|
+
import Var from './var';
|
|
22
|
+
import Literal from './literal';
|
|
23
|
+
import Assertion from './assertion';
|
|
24
|
+
import Coercion from './coercion';
|
|
25
|
+
import At from './at';
|
|
26
|
+
import In from './in';
|
|
27
|
+
import IndexOf from './index_of';
|
|
28
|
+
import Match from './match';
|
|
29
|
+
import Case from './case';
|
|
30
|
+
import Slice from './slice';
|
|
31
|
+
import Step from './step';
|
|
32
|
+
import Interpolate from './interpolate';
|
|
33
|
+
import Coalesce from './coalesce';
|
|
34
|
+
import {
|
|
35
|
+
Equals,
|
|
36
|
+
NotEquals,
|
|
37
|
+
LessThan,
|
|
38
|
+
GreaterThan,
|
|
39
|
+
LessThanOrEqual,
|
|
40
|
+
GreaterThanOrEqual
|
|
41
|
+
} from './comparison';
|
|
42
|
+
import CollatorExpression from './collator';
|
|
43
|
+
import NumberFormat from './number_format';
|
|
44
|
+
import FormatExpression from './format';
|
|
45
|
+
import ImageExpression from './image';
|
|
46
|
+
import Length from './length';
|
|
47
|
+
import Within from './within';
|
|
48
|
+
|
|
49
|
+
import type {Varargs} from '../compound_expression';
|
|
50
|
+
import type {ExpressionRegistry} from '../expression';
|
|
51
|
+
|
|
52
|
+
const expressions: ExpressionRegistry = {
|
|
53
|
+
// special forms
|
|
54
|
+
'==': Equals,
|
|
55
|
+
'!=': NotEquals,
|
|
56
|
+
'>': GreaterThan,
|
|
57
|
+
'<': LessThan,
|
|
58
|
+
'>=': GreaterThanOrEqual,
|
|
59
|
+
'<=': LessThanOrEqual,
|
|
60
|
+
'array': Assertion,
|
|
61
|
+
'at': At,
|
|
62
|
+
'boolean': Assertion,
|
|
63
|
+
'case': Case,
|
|
64
|
+
'coalesce': Coalesce,
|
|
65
|
+
'collator': CollatorExpression,
|
|
66
|
+
'format': FormatExpression,
|
|
67
|
+
'image': ImageExpression,
|
|
68
|
+
'in': In,
|
|
69
|
+
'index-of': IndexOf,
|
|
70
|
+
'interpolate': Interpolate,
|
|
71
|
+
'interpolate-hcl': Interpolate,
|
|
72
|
+
'interpolate-lab': Interpolate,
|
|
73
|
+
'length': Length,
|
|
74
|
+
'let': Let,
|
|
75
|
+
'literal': Literal,
|
|
76
|
+
'match': Match,
|
|
77
|
+
'number': Assertion,
|
|
78
|
+
'number-format': NumberFormat,
|
|
79
|
+
'object': Assertion,
|
|
80
|
+
'slice': Slice,
|
|
81
|
+
'step': Step,
|
|
82
|
+
'string': Assertion,
|
|
83
|
+
'to-boolean': Coercion,
|
|
84
|
+
'to-color': Coercion,
|
|
85
|
+
'to-number': Coercion,
|
|
86
|
+
'to-string': Coercion,
|
|
87
|
+
'var': Var,
|
|
88
|
+
'within': Within
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
function rgba(ctx, [r, g, b, a]) {
|
|
92
|
+
r = r.evaluate(ctx);
|
|
93
|
+
g = g.evaluate(ctx);
|
|
94
|
+
b = b.evaluate(ctx);
|
|
95
|
+
const alpha = a ? a.evaluate(ctx) : 1;
|
|
96
|
+
const error = validateRGBA(r, g, b, alpha);
|
|
97
|
+
if (error) throw new RuntimeError(error);
|
|
98
|
+
return new Color(r / 255 * alpha, g / 255 * alpha, b / 255 * alpha, alpha);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function has(key, obj) {
|
|
102
|
+
return key in obj;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function get(key, obj) {
|
|
106
|
+
const v = obj[key];
|
|
107
|
+
return typeof v === 'undefined' ? null : v;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function binarySearch(v, a, i, j) {
|
|
111
|
+
while (i <= j) {
|
|
112
|
+
const m = (i + j) >> 1;
|
|
113
|
+
if (a[m] === v)
|
|
114
|
+
return true;
|
|
115
|
+
if (a[m] > v)
|
|
116
|
+
j = m - 1;
|
|
117
|
+
else
|
|
118
|
+
i = m + 1;
|
|
119
|
+
}
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function varargs(type: Type): Varargs {
|
|
124
|
+
return {type};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
CompoundExpression.register(expressions, {
|
|
128
|
+
'error': [
|
|
129
|
+
ErrorType,
|
|
130
|
+
[StringType],
|
|
131
|
+
(ctx, [v]) => { throw new RuntimeError(v.evaluate(ctx)); }
|
|
132
|
+
],
|
|
133
|
+
'typeof': [
|
|
134
|
+
StringType,
|
|
135
|
+
[ValueType],
|
|
136
|
+
(ctx, [v]) => typeToString(typeOf(v.evaluate(ctx)))
|
|
137
|
+
],
|
|
138
|
+
'to-rgba': [
|
|
139
|
+
array(NumberType, 4),
|
|
140
|
+
[ColorType],
|
|
141
|
+
(ctx, [v]) => {
|
|
142
|
+
return v.evaluate(ctx).toArray();
|
|
143
|
+
}
|
|
144
|
+
],
|
|
145
|
+
'rgb': [
|
|
146
|
+
ColorType,
|
|
147
|
+
[NumberType, NumberType, NumberType],
|
|
148
|
+
rgba
|
|
149
|
+
],
|
|
150
|
+
'rgba': [
|
|
151
|
+
ColorType,
|
|
152
|
+
[NumberType, NumberType, NumberType, NumberType],
|
|
153
|
+
rgba
|
|
154
|
+
],
|
|
155
|
+
'has': {
|
|
156
|
+
type: BooleanType,
|
|
157
|
+
overloads: [
|
|
158
|
+
[
|
|
159
|
+
[StringType],
|
|
160
|
+
(ctx, [key]) => has(key.evaluate(ctx), ctx.properties())
|
|
161
|
+
], [
|
|
162
|
+
[StringType, ObjectType],
|
|
163
|
+
(ctx, [key, obj]) => has(key.evaluate(ctx), obj.evaluate(ctx))
|
|
164
|
+
]
|
|
165
|
+
]
|
|
166
|
+
},
|
|
167
|
+
'get': {
|
|
168
|
+
type: ValueType,
|
|
169
|
+
overloads: [
|
|
170
|
+
[
|
|
171
|
+
[StringType],
|
|
172
|
+
(ctx, [key]) => get(key.evaluate(ctx), ctx.properties())
|
|
173
|
+
], [
|
|
174
|
+
[StringType, ObjectType],
|
|
175
|
+
(ctx, [key, obj]) => get(key.evaluate(ctx), obj.evaluate(ctx))
|
|
176
|
+
]
|
|
177
|
+
]
|
|
178
|
+
},
|
|
179
|
+
'feature-state': [
|
|
180
|
+
ValueType,
|
|
181
|
+
[StringType],
|
|
182
|
+
(ctx, [key]) => get(key.evaluate(ctx), ctx.featureState || {})
|
|
183
|
+
],
|
|
184
|
+
'properties': [
|
|
185
|
+
ObjectType,
|
|
186
|
+
[],
|
|
187
|
+
(ctx) => ctx.properties()
|
|
188
|
+
],
|
|
189
|
+
'geometry-type': [
|
|
190
|
+
StringType,
|
|
191
|
+
[],
|
|
192
|
+
(ctx) => ctx.geometryType()
|
|
193
|
+
],
|
|
194
|
+
'id': [
|
|
195
|
+
ValueType,
|
|
196
|
+
[],
|
|
197
|
+
(ctx) => ctx.id()
|
|
198
|
+
],
|
|
199
|
+
'zoom': [
|
|
200
|
+
NumberType,
|
|
201
|
+
[],
|
|
202
|
+
(ctx) => ctx.globals.zoom
|
|
203
|
+
],
|
|
204
|
+
'heatmap-density': [
|
|
205
|
+
NumberType,
|
|
206
|
+
[],
|
|
207
|
+
(ctx) => ctx.globals.heatmapDensity || 0
|
|
208
|
+
],
|
|
209
|
+
'line-progress': [
|
|
210
|
+
NumberType,
|
|
211
|
+
[],
|
|
212
|
+
(ctx) => ctx.globals.lineProgress || 0
|
|
213
|
+
],
|
|
214
|
+
'accumulated': [
|
|
215
|
+
ValueType,
|
|
216
|
+
[],
|
|
217
|
+
(ctx) => ctx.globals.accumulated === undefined ? null : ctx.globals.accumulated
|
|
218
|
+
],
|
|
219
|
+
'+': [
|
|
220
|
+
NumberType,
|
|
221
|
+
varargs(NumberType),
|
|
222
|
+
(ctx, args) => {
|
|
223
|
+
let result = 0;
|
|
224
|
+
for (const arg of args) {
|
|
225
|
+
result += arg.evaluate(ctx);
|
|
226
|
+
}
|
|
227
|
+
return result;
|
|
228
|
+
}
|
|
229
|
+
],
|
|
230
|
+
'*': [
|
|
231
|
+
NumberType,
|
|
232
|
+
varargs(NumberType),
|
|
233
|
+
(ctx, args) => {
|
|
234
|
+
let result = 1;
|
|
235
|
+
for (const arg of args) {
|
|
236
|
+
result *= arg.evaluate(ctx);
|
|
237
|
+
}
|
|
238
|
+
return result;
|
|
239
|
+
}
|
|
240
|
+
],
|
|
241
|
+
'-': {
|
|
242
|
+
type: NumberType,
|
|
243
|
+
overloads: [
|
|
244
|
+
[
|
|
245
|
+
[NumberType, NumberType],
|
|
246
|
+
(ctx, [a, b]) => a.evaluate(ctx) - b.evaluate(ctx)
|
|
247
|
+
], [
|
|
248
|
+
[NumberType],
|
|
249
|
+
(ctx, [a]) => -a.evaluate(ctx)
|
|
250
|
+
]
|
|
251
|
+
]
|
|
252
|
+
},
|
|
253
|
+
'/': [
|
|
254
|
+
NumberType,
|
|
255
|
+
[NumberType, NumberType],
|
|
256
|
+
(ctx, [a, b]) => a.evaluate(ctx) / b.evaluate(ctx)
|
|
257
|
+
],
|
|
258
|
+
'%': [
|
|
259
|
+
NumberType,
|
|
260
|
+
[NumberType, NumberType],
|
|
261
|
+
(ctx, [a, b]) => a.evaluate(ctx) % b.evaluate(ctx)
|
|
262
|
+
],
|
|
263
|
+
'ln2': [
|
|
264
|
+
NumberType,
|
|
265
|
+
[],
|
|
266
|
+
() => Math.LN2
|
|
267
|
+
],
|
|
268
|
+
'pi': [
|
|
269
|
+
NumberType,
|
|
270
|
+
[],
|
|
271
|
+
() => Math.PI
|
|
272
|
+
],
|
|
273
|
+
'e': [
|
|
274
|
+
NumberType,
|
|
275
|
+
[],
|
|
276
|
+
() => Math.E
|
|
277
|
+
],
|
|
278
|
+
'^': [
|
|
279
|
+
NumberType,
|
|
280
|
+
[NumberType, NumberType],
|
|
281
|
+
(ctx, [b, e]) => Math.pow(b.evaluate(ctx), e.evaluate(ctx))
|
|
282
|
+
],
|
|
283
|
+
'sqrt': [
|
|
284
|
+
NumberType,
|
|
285
|
+
[NumberType],
|
|
286
|
+
(ctx, [x]) => Math.sqrt(x.evaluate(ctx))
|
|
287
|
+
],
|
|
288
|
+
'log10': [
|
|
289
|
+
NumberType,
|
|
290
|
+
[NumberType],
|
|
291
|
+
(ctx, [n]) => Math.log(n.evaluate(ctx)) / Math.LN10
|
|
292
|
+
],
|
|
293
|
+
'ln': [
|
|
294
|
+
NumberType,
|
|
295
|
+
[NumberType],
|
|
296
|
+
(ctx, [n]) => Math.log(n.evaluate(ctx))
|
|
297
|
+
],
|
|
298
|
+
'log2': [
|
|
299
|
+
NumberType,
|
|
300
|
+
[NumberType],
|
|
301
|
+
(ctx, [n]) => Math.log(n.evaluate(ctx)) / Math.LN2
|
|
302
|
+
],
|
|
303
|
+
'sin': [
|
|
304
|
+
NumberType,
|
|
305
|
+
[NumberType],
|
|
306
|
+
(ctx, [n]) => Math.sin(n.evaluate(ctx))
|
|
307
|
+
],
|
|
308
|
+
'cos': [
|
|
309
|
+
NumberType,
|
|
310
|
+
[NumberType],
|
|
311
|
+
(ctx, [n]) => Math.cos(n.evaluate(ctx))
|
|
312
|
+
],
|
|
313
|
+
'tan': [
|
|
314
|
+
NumberType,
|
|
315
|
+
[NumberType],
|
|
316
|
+
(ctx, [n]) => Math.tan(n.evaluate(ctx))
|
|
317
|
+
],
|
|
318
|
+
'asin': [
|
|
319
|
+
NumberType,
|
|
320
|
+
[NumberType],
|
|
321
|
+
(ctx, [n]) => Math.asin(n.evaluate(ctx))
|
|
322
|
+
],
|
|
323
|
+
'acos': [
|
|
324
|
+
NumberType,
|
|
325
|
+
[NumberType],
|
|
326
|
+
(ctx, [n]) => Math.acos(n.evaluate(ctx))
|
|
327
|
+
],
|
|
328
|
+
'atan': [
|
|
329
|
+
NumberType,
|
|
330
|
+
[NumberType],
|
|
331
|
+
(ctx, [n]) => Math.atan(n.evaluate(ctx))
|
|
332
|
+
],
|
|
333
|
+
'min': [
|
|
334
|
+
NumberType,
|
|
335
|
+
varargs(NumberType),
|
|
336
|
+
(ctx, args) => Math.min(...args.map(arg => arg.evaluate(ctx)))
|
|
337
|
+
],
|
|
338
|
+
'max': [
|
|
339
|
+
NumberType,
|
|
340
|
+
varargs(NumberType),
|
|
341
|
+
(ctx, args) => Math.max(...args.map(arg => arg.evaluate(ctx)))
|
|
342
|
+
],
|
|
343
|
+
'abs': [
|
|
344
|
+
NumberType,
|
|
345
|
+
[NumberType],
|
|
346
|
+
(ctx, [n]) => Math.abs(n.evaluate(ctx))
|
|
347
|
+
],
|
|
348
|
+
'round': [
|
|
349
|
+
NumberType,
|
|
350
|
+
[NumberType],
|
|
351
|
+
(ctx, [n]) => {
|
|
352
|
+
const v = n.evaluate(ctx);
|
|
353
|
+
// Javascript's Math.round() rounds towards +Infinity for halfway
|
|
354
|
+
// values, even when they're negative. It's more common to round
|
|
355
|
+
// away from 0 (e.g., this is what python and C++ do)
|
|
356
|
+
return v < 0 ? -Math.round(-v) : Math.round(v);
|
|
357
|
+
}
|
|
358
|
+
],
|
|
359
|
+
'floor': [
|
|
360
|
+
NumberType,
|
|
361
|
+
[NumberType],
|
|
362
|
+
(ctx, [n]) => Math.floor(n.evaluate(ctx))
|
|
363
|
+
],
|
|
364
|
+
'ceil': [
|
|
365
|
+
NumberType,
|
|
366
|
+
[NumberType],
|
|
367
|
+
(ctx, [n]) => Math.ceil(n.evaluate(ctx))
|
|
368
|
+
],
|
|
369
|
+
'filter-==': [
|
|
370
|
+
BooleanType,
|
|
371
|
+
[StringType, ValueType],
|
|
372
|
+
(ctx, [k, v]) => ctx.properties()[(k: any).value] === (v: any).value
|
|
373
|
+
],
|
|
374
|
+
'filter-id-==': [
|
|
375
|
+
BooleanType,
|
|
376
|
+
[ValueType],
|
|
377
|
+
(ctx, [v]) => ctx.id() === (v: any).value
|
|
378
|
+
],
|
|
379
|
+
'filter-type-==': [
|
|
380
|
+
BooleanType,
|
|
381
|
+
[StringType],
|
|
382
|
+
(ctx, [v]) => ctx.geometryType() === (v: any).value
|
|
383
|
+
],
|
|
384
|
+
'filter-<': [
|
|
385
|
+
BooleanType,
|
|
386
|
+
[StringType, ValueType],
|
|
387
|
+
(ctx, [k, v]) => {
|
|
388
|
+
const a = ctx.properties()[(k: any).value];
|
|
389
|
+
const b = (v: any).value;
|
|
390
|
+
return typeof a === typeof b && a < b;
|
|
391
|
+
}
|
|
392
|
+
],
|
|
393
|
+
'filter-id-<': [
|
|
394
|
+
BooleanType,
|
|
395
|
+
[ValueType],
|
|
396
|
+
(ctx, [v]) => {
|
|
397
|
+
const a = ctx.id();
|
|
398
|
+
const b = (v: any).value;
|
|
399
|
+
return typeof a === typeof b && a < b;
|
|
400
|
+
}
|
|
401
|
+
],
|
|
402
|
+
'filter->': [
|
|
403
|
+
BooleanType,
|
|
404
|
+
[StringType, ValueType],
|
|
405
|
+
(ctx, [k, v]) => {
|
|
406
|
+
const a = ctx.properties()[(k: any).value];
|
|
407
|
+
const b = (v: any).value;
|
|
408
|
+
return typeof a === typeof b && a > b;
|
|
409
|
+
}
|
|
410
|
+
],
|
|
411
|
+
'filter-id->': [
|
|
412
|
+
BooleanType,
|
|
413
|
+
[ValueType],
|
|
414
|
+
(ctx, [v]) => {
|
|
415
|
+
const a = ctx.id();
|
|
416
|
+
const b = (v: any).value;
|
|
417
|
+
return typeof a === typeof b && a > b;
|
|
418
|
+
}
|
|
419
|
+
],
|
|
420
|
+
'filter-<=': [
|
|
421
|
+
BooleanType,
|
|
422
|
+
[StringType, ValueType],
|
|
423
|
+
(ctx, [k, v]) => {
|
|
424
|
+
const a = ctx.properties()[(k: any).value];
|
|
425
|
+
const b = (v: any).value;
|
|
426
|
+
return typeof a === typeof b && a <= b;
|
|
427
|
+
}
|
|
428
|
+
],
|
|
429
|
+
'filter-id-<=': [
|
|
430
|
+
BooleanType,
|
|
431
|
+
[ValueType],
|
|
432
|
+
(ctx, [v]) => {
|
|
433
|
+
const a = ctx.id();
|
|
434
|
+
const b = (v: any).value;
|
|
435
|
+
return typeof a === typeof b && a <= b;
|
|
436
|
+
}
|
|
437
|
+
],
|
|
438
|
+
'filter->=': [
|
|
439
|
+
BooleanType,
|
|
440
|
+
[StringType, ValueType],
|
|
441
|
+
(ctx, [k, v]) => {
|
|
442
|
+
const a = ctx.properties()[(k: any).value];
|
|
443
|
+
const b = (v: any).value;
|
|
444
|
+
return typeof a === typeof b && a >= b;
|
|
445
|
+
}
|
|
446
|
+
],
|
|
447
|
+
'filter-id->=': [
|
|
448
|
+
BooleanType,
|
|
449
|
+
[ValueType],
|
|
450
|
+
(ctx, [v]) => {
|
|
451
|
+
const a = ctx.id();
|
|
452
|
+
const b = (v: any).value;
|
|
453
|
+
return typeof a === typeof b && a >= b;
|
|
454
|
+
}
|
|
455
|
+
],
|
|
456
|
+
'filter-has': [
|
|
457
|
+
BooleanType,
|
|
458
|
+
[ValueType],
|
|
459
|
+
(ctx, [k]) => (k: any).value in ctx.properties()
|
|
460
|
+
],
|
|
461
|
+
'filter-has-id': [
|
|
462
|
+
BooleanType,
|
|
463
|
+
[],
|
|
464
|
+
(ctx) => (ctx.id() !== null && ctx.id() !== undefined)
|
|
465
|
+
],
|
|
466
|
+
'filter-type-in': [
|
|
467
|
+
BooleanType,
|
|
468
|
+
[array(StringType)],
|
|
469
|
+
(ctx, [v]) => (v: any).value.indexOf(ctx.geometryType()) >= 0
|
|
470
|
+
],
|
|
471
|
+
'filter-id-in': [
|
|
472
|
+
BooleanType,
|
|
473
|
+
[array(ValueType)],
|
|
474
|
+
(ctx, [v]) => (v: any).value.indexOf(ctx.id()) >= 0
|
|
475
|
+
],
|
|
476
|
+
'filter-in-small': [
|
|
477
|
+
BooleanType,
|
|
478
|
+
[StringType, array(ValueType)],
|
|
479
|
+
// assumes v is an array literal
|
|
480
|
+
(ctx, [k, v]) => (v: any).value.indexOf(ctx.properties()[(k: any).value]) >= 0
|
|
481
|
+
],
|
|
482
|
+
'filter-in-large': [
|
|
483
|
+
BooleanType,
|
|
484
|
+
[StringType, array(ValueType)],
|
|
485
|
+
// assumes v is a array literal with values sorted in ascending order and of a single type
|
|
486
|
+
(ctx, [k, v]) => binarySearch(ctx.properties()[(k: any).value], (v: any).value, 0, (v: any).value.length - 1)
|
|
487
|
+
],
|
|
488
|
+
'all': {
|
|
489
|
+
type: BooleanType,
|
|
490
|
+
overloads: [
|
|
491
|
+
[
|
|
492
|
+
[BooleanType, BooleanType],
|
|
493
|
+
(ctx, [a, b]) => a.evaluate(ctx) && b.evaluate(ctx)
|
|
494
|
+
],
|
|
495
|
+
[
|
|
496
|
+
varargs(BooleanType),
|
|
497
|
+
(ctx, args) => {
|
|
498
|
+
for (const arg of args) {
|
|
499
|
+
if (!arg.evaluate(ctx))
|
|
500
|
+
return false;
|
|
501
|
+
}
|
|
502
|
+
return true;
|
|
503
|
+
}
|
|
504
|
+
]
|
|
505
|
+
]
|
|
506
|
+
},
|
|
507
|
+
'any': {
|
|
508
|
+
type: BooleanType,
|
|
509
|
+
overloads: [
|
|
510
|
+
[
|
|
511
|
+
[BooleanType, BooleanType],
|
|
512
|
+
(ctx, [a, b]) => a.evaluate(ctx) || b.evaluate(ctx)
|
|
513
|
+
],
|
|
514
|
+
[
|
|
515
|
+
varargs(BooleanType),
|
|
516
|
+
(ctx, args) => {
|
|
517
|
+
for (const arg of args) {
|
|
518
|
+
if (arg.evaluate(ctx))
|
|
519
|
+
return true;
|
|
520
|
+
}
|
|
521
|
+
return false;
|
|
522
|
+
}
|
|
523
|
+
]
|
|
524
|
+
]
|
|
525
|
+
},
|
|
526
|
+
'!': [
|
|
527
|
+
BooleanType,
|
|
528
|
+
[BooleanType],
|
|
529
|
+
(ctx, [b]) => !b.evaluate(ctx)
|
|
530
|
+
],
|
|
531
|
+
'is-supported-script': [
|
|
532
|
+
BooleanType,
|
|
533
|
+
[StringType],
|
|
534
|
+
// At parse time this will always return true, so we need to exclude this expression with isGlobalPropertyConstant
|
|
535
|
+
(ctx, [s]) => {
|
|
536
|
+
const isSupportedScript = ctx.globals && ctx.globals.isSupportedScript;
|
|
537
|
+
if (isSupportedScript) {
|
|
538
|
+
return isSupportedScript(s.evaluate(ctx));
|
|
539
|
+
}
|
|
540
|
+
return true;
|
|
541
|
+
}
|
|
542
|
+
],
|
|
543
|
+
'upcase': [
|
|
544
|
+
StringType,
|
|
545
|
+
[StringType],
|
|
546
|
+
(ctx, [s]) => s.evaluate(ctx).toUpperCase()
|
|
547
|
+
],
|
|
548
|
+
'downcase': [
|
|
549
|
+
StringType,
|
|
550
|
+
[StringType],
|
|
551
|
+
(ctx, [s]) => s.evaluate(ctx).toLowerCase()
|
|
552
|
+
],
|
|
553
|
+
'concat': [
|
|
554
|
+
StringType,
|
|
555
|
+
varargs(ValueType),
|
|
556
|
+
(ctx, args) => args.map(arg => valueToString(arg.evaluate(ctx))).join('')
|
|
557
|
+
],
|
|
558
|
+
'resolved-locale': [
|
|
559
|
+
StringType,
|
|
560
|
+
[CollatorType],
|
|
561
|
+
(ctx, [collator]) => collator.evaluate(ctx).resolvedLocale()
|
|
562
|
+
]
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
export default expressions;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import {BooleanType, StringType, ValueType, NullType, toString, NumberType, isValidType, isValidNativeType} from '../types';
|
|
4
|
+
import RuntimeError from '../runtime_error';
|
|
5
|
+
import {typeOf} from '../values';
|
|
6
|
+
|
|
7
|
+
import type {Expression} from '../expression';
|
|
8
|
+
import type ParsingContext from '../parsing_context';
|
|
9
|
+
import type EvaluationContext from '../evaluation_context';
|
|
10
|
+
import type {Type} from '../types';
|
|
11
|
+
|
|
12
|
+
class IndexOf implements Expression {
|
|
13
|
+
type: Type;
|
|
14
|
+
needle: Expression;
|
|
15
|
+
haystack: Expression;
|
|
16
|
+
fromIndex: ?Expression;
|
|
17
|
+
|
|
18
|
+
constructor(needle: Expression, haystack: Expression, fromIndex?: Expression) {
|
|
19
|
+
this.type = NumberType;
|
|
20
|
+
this.needle = needle;
|
|
21
|
+
this.haystack = haystack;
|
|
22
|
+
this.fromIndex = fromIndex;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
|
|
26
|
+
if (args.length <= 2 || args.length >= 5) {
|
|
27
|
+
return context.error(`Expected 3 or 4 arguments, but found ${args.length - 1} instead.`);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const needle = context.parse(args[1], 1, ValueType);
|
|
31
|
+
|
|
32
|
+
const haystack = context.parse(args[2], 2, ValueType);
|
|
33
|
+
|
|
34
|
+
if (!needle || !haystack) return null;
|
|
35
|
+
if (!isValidType(needle.type, [BooleanType, StringType, NumberType, NullType, ValueType])) {
|
|
36
|
+
return context.error(`Expected first argument to be of type boolean, string, number or null, but found ${toString(needle.type)} instead`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (args.length === 4) {
|
|
40
|
+
const fromIndex = context.parse(args[3], 3, NumberType);
|
|
41
|
+
if (!fromIndex) return null;
|
|
42
|
+
return new IndexOf(needle, haystack, fromIndex);
|
|
43
|
+
} else {
|
|
44
|
+
return new IndexOf(needle, haystack);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
evaluate(ctx: EvaluationContext) {
|
|
49
|
+
const needle = (this.needle.evaluate(ctx): any);
|
|
50
|
+
const haystack = (this.haystack.evaluate(ctx): any);
|
|
51
|
+
|
|
52
|
+
if (!isValidNativeType(needle, ['boolean', 'string', 'number', 'null'])) {
|
|
53
|
+
throw new RuntimeError(`Expected first argument to be of type boolean, string, number or null, but found ${toString(typeOf(needle))} instead.`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (!isValidNativeType(haystack, ['string', 'array'])) {
|
|
57
|
+
throw new RuntimeError(`Expected second argument to be of type array or string, but found ${toString(typeOf(haystack))} instead.`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (this.fromIndex) {
|
|
61
|
+
const fromIndex = (this.fromIndex.evaluate(ctx): number);
|
|
62
|
+
return haystack.indexOf(needle, fromIndex);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return haystack.indexOf(needle);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
eachChild(fn: (_: Expression) => void) {
|
|
69
|
+
fn(this.needle);
|
|
70
|
+
fn(this.haystack);
|
|
71
|
+
if (this.fromIndex) {
|
|
72
|
+
fn(this.fromIndex);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
outputDefined() {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
serialize() {
|
|
81
|
+
if (this.fromIndex != null && this.fromIndex !== undefined) {
|
|
82
|
+
const fromIndex = this.fromIndex.serialize();
|
|
83
|
+
return ["index-of", this.needle.serialize(), this.haystack.serialize(), fromIndex];
|
|
84
|
+
}
|
|
85
|
+
return ["index-of", this.needle.serialize(), this.haystack.serialize()];
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export default IndexOf;
|