@mapwhit/tilerenderer 0.47.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (356) hide show
  1. package/LICENSE.txt +87 -0
  2. package/README.md +25 -0
  3. package/build/min/.dir +0 -0
  4. package/build/min/package.json +3 -0
  5. package/build/min/src/shaders/_prelude.fragment.glsl.txt +13 -0
  6. package/build/min/src/shaders/_prelude.vertex.glsl.txt +14 -0
  7. package/build/min/src/shaders/background.fragment.glsl.txt +5 -0
  8. package/build/min/src/shaders/background.vertex.glsl.txt +1 -0
  9. package/build/min/src/shaders/background_pattern.fragment.glsl.txt +5 -0
  10. package/build/min/src/shaders/background_pattern.vertex.glsl.txt +1 -0
  11. package/build/min/src/shaders/circle.fragment.glsl.txt +20 -0
  12. package/build/min/src/shaders/circle.vertex.glsl.txt +17 -0
  13. package/build/min/src/shaders/clipping_mask.fragment.glsl.txt +1 -0
  14. package/build/min/src/shaders/clipping_mask.vertex.glsl.txt +1 -0
  15. package/build/min/src/shaders/collision_box.fragment.glsl.txt +1 -0
  16. package/build/min/src/shaders/collision_box.vertex.glsl.txt +1 -0
  17. package/build/min/src/shaders/collision_circle.fragment.glsl.txt +1 -0
  18. package/build/min/src/shaders/collision_circle.vertex.glsl.txt +1 -0
  19. package/build/min/src/shaders/debug.fragment.glsl.txt +1 -0
  20. package/build/min/src/shaders/debug.vertex.glsl.txt +1 -0
  21. package/build/min/src/shaders/fill.fragment.glsl.txt +10 -0
  22. package/build/min/src/shaders/fill.vertex.glsl.txt +7 -0
  23. package/build/min/src/shaders/fill_extrusion.fragment.glsl.txt +13 -0
  24. package/build/min/src/shaders/fill_extrusion.vertex.glsl.txt +9 -0
  25. package/build/min/src/shaders/fill_extrusion_pattern.fragment.glsl.txt +15 -0
  26. package/build/min/src/shaders/fill_extrusion_pattern.vertex.glsl.txt +11 -0
  27. package/build/min/src/shaders/fill_outline.fragment.glsl.txt +10 -0
  28. package/build/min/src/shaders/fill_outline.vertex.glsl.txt +7 -0
  29. package/build/min/src/shaders/fill_outline_pattern.fragment.glsl.txt +13 -0
  30. package/build/min/src/shaders/fill_outline_pattern.vertex.glsl.txt +9 -0
  31. package/build/min/src/shaders/fill_pattern.fragment.glsl.txt +13 -0
  32. package/build/min/src/shaders/fill_pattern.vertex.glsl.txt +9 -0
  33. package/build/min/src/shaders/heatmap.fragment.glsl.txt +10 -0
  34. package/build/min/src/shaders/heatmap.vertex.glsl.txt +8 -0
  35. package/build/min/src/shaders/heatmap_texture.fragment.glsl.txt +5 -0
  36. package/build/min/src/shaders/heatmap_texture.vertex.glsl.txt +1 -0
  37. package/build/min/src/shaders/hillshade.fragment.glsl.txt +7 -0
  38. package/build/min/src/shaders/hillshade.vertex.glsl.txt +1 -0
  39. package/build/min/src/shaders/hillshade_prepare.fragment.glsl.txt +8 -0
  40. package/build/min/src/shaders/hillshade_prepare.vertex.glsl.txt +1 -0
  41. package/build/min/src/shaders/line.fragment.glsl.txt +12 -0
  42. package/build/min/src/shaders/line.vertex.glsl.txt +17 -0
  43. package/build/min/src/shaders/line_gradient.fragment.glsl.txt +10 -0
  44. package/build/min/src/shaders/line_gradient.vertex.glsl.txt +16 -0
  45. package/build/min/src/shaders/line_pattern.fragment.glsl.txt +15 -0
  46. package/build/min/src/shaders/line_pattern.vertex.glsl.txt +20 -0
  47. package/build/min/src/shaders/line_sdf.fragment.glsl.txt +17 -0
  48. package/build/min/src/shaders/line_sdf.vertex.glsl.txt +20 -0
  49. package/build/min/src/shaders/raster.fragment.glsl.txt +5 -0
  50. package/build/min/src/shaders/raster.vertex.glsl.txt +1 -0
  51. package/build/min/src/shaders/symbol_icon.fragment.glsl.txt +9 -0
  52. package/build/min/src/shaders/symbol_icon.vertex.glsl.txt +5 -0
  53. package/build/min/src/shaders/symbol_sdf.fragment.glsl.txt +19 -0
  54. package/build/min/src/shaders/symbol_sdf.vertex.glsl.txt +13 -0
  55. package/package.json +44 -0
  56. package/src/css/mapbox-gl.css +506 -0
  57. package/src/css/svg/mapboxgl-ctrl-attrib.svg +3 -0
  58. package/src/css/svg/mapboxgl-ctrl-compass.svg +4 -0
  59. package/src/css/svg/mapboxgl-ctrl-fullscreen.svg +3 -0
  60. package/src/css/svg/mapboxgl-ctrl-geolocate-background.svg +3 -0
  61. package/src/css/svg/mapboxgl-ctrl-geolocate.svg +3 -0
  62. package/src/css/svg/mapboxgl-ctrl-logo-compact.svg +2 -0
  63. package/src/css/svg/mapboxgl-ctrl-logo.svg +1 -0
  64. package/src/css/svg/mapboxgl-ctrl-shrink.svg +3 -0
  65. package/src/css/svg/mapboxgl-ctrl-zoom-in.svg +3 -0
  66. package/src/css/svg/mapboxgl-ctrl-zoom-out.svg +3 -0
  67. package/src/data/array_types.js +1138 -0
  68. package/src/data/bucket/circle_attributes.js +5 -0
  69. package/src/data/bucket/circle_bucket.js +118 -0
  70. package/src/data/bucket/fill_attributes.js +5 -0
  71. package/src/data/bucket/fill_bucket.js +166 -0
  72. package/src/data/bucket/fill_extrusion_attributes.js +11 -0
  73. package/src/data/bucket/fill_extrusion_bucket.js +247 -0
  74. package/src/data/bucket/heatmap_bucket.js +12 -0
  75. package/src/data/bucket/line_attributes.js +11 -0
  76. package/src/data/bucket/line_bucket.js +625 -0
  77. package/src/data/bucket/pattern_attributes.js +9 -0
  78. package/src/data/bucket/pattern_bucket_features.js +44 -0
  79. package/src/data/bucket/symbol_attributes.js +95 -0
  80. package/src/data/bucket/symbol_bucket.js +697 -0
  81. package/src/data/bucket.js +53 -0
  82. package/src/data/dem_data.js +126 -0
  83. package/src/data/extent.js +17 -0
  84. package/src/data/feature_index.js +254 -0
  85. package/src/data/index_array_type.js +14 -0
  86. package/src/data/load_geometry.js +42 -0
  87. package/src/data/pos_attributes.js +3 -0
  88. package/src/data/program_configuration.js +782 -0
  89. package/src/data/raster_bounds_attributes.js +6 -0
  90. package/src/data/segment.js +63 -0
  91. package/src/geo/coordinate.js +78 -0
  92. package/src/geo/lng_lat.js +129 -0
  93. package/src/geo/lng_lat_bounds.js +253 -0
  94. package/src/geo/transform.js +605 -0
  95. package/src/gl/color_mode.js +21 -0
  96. package/src/gl/context.js +193 -0
  97. package/src/gl/cull_face_mode.js +22 -0
  98. package/src/gl/depth_mode.js +18 -0
  99. package/src/gl/framebuffer.js +28 -0
  100. package/src/gl/index_buffer.js +52 -0
  101. package/src/gl/stencil_mode.js +17 -0
  102. package/src/gl/types.js +0 -0
  103. package/src/gl/value.js +676 -0
  104. package/src/gl/vertex_buffer.js +101 -0
  105. package/src/index.js +50 -0
  106. package/src/render/draw_background.js +60 -0
  107. package/src/render/draw_circle.js +55 -0
  108. package/src/render/draw_collision_debug.js +45 -0
  109. package/src/render/draw_debug.js +429 -0
  110. package/src/render/draw_fill.js +143 -0
  111. package/src/render/draw_fill_extrusion.js +101 -0
  112. package/src/render/draw_heatmap.js +159 -0
  113. package/src/render/draw_hillshade.js +144 -0
  114. package/src/render/draw_line.js +99 -0
  115. package/src/render/draw_raster.js +151 -0
  116. package/src/render/draw_symbol.js +231 -0
  117. package/src/render/glyph_atlas.js +55 -0
  118. package/src/render/glyph_manager.js +145 -0
  119. package/src/render/image_atlas.js +97 -0
  120. package/src/render/image_manager.js +183 -0
  121. package/src/render/line_atlas.js +139 -0
  122. package/src/render/painter.js +483 -0
  123. package/src/render/program/background_program.js +46 -0
  124. package/src/render/program/circle_program.js +40 -0
  125. package/src/render/program/clipping_mask_program.js +11 -0
  126. package/src/render/program/collision_program.js +28 -0
  127. package/src/render/program/debug_program.js +13 -0
  128. package/src/render/program/fill_extrusion_program.js +76 -0
  129. package/src/render/program/fill_program.js +60 -0
  130. package/src/render/program/heatmap_program.js +46 -0
  131. package/src/render/program/hillshade_program.js +77 -0
  132. package/src/render/program/line_program.js +119 -0
  133. package/src/render/program/pattern.js +57 -0
  134. package/src/render/program/program_uniforms.js +46 -0
  135. package/src/render/program/raster_program.js +50 -0
  136. package/src/render/program/symbol_program.js +112 -0
  137. package/src/render/program.js +133 -0
  138. package/src/render/texture.js +88 -0
  139. package/src/render/tile_mask.js +108 -0
  140. package/src/render/uniform_binding.js +129 -0
  141. package/src/render/vertex_array_object.js +155 -0
  142. package/src/shaders/README.md +42 -0
  143. package/src/shaders/_prelude.fragment.glsl +17 -0
  144. package/src/shaders/_prelude.vertex.glsl +73 -0
  145. package/src/shaders/background.fragment.glsl +10 -0
  146. package/src/shaders/background.vertex.glsl +7 -0
  147. package/src/shaders/background_pattern.fragment.glsl +28 -0
  148. package/src/shaders/background_pattern.vertex.glsl +20 -0
  149. package/src/shaders/circle.fragment.glsl +39 -0
  150. package/src/shaders/circle.vertex.glsl +63 -0
  151. package/src/shaders/clipping_mask.fragment.glsl +3 -0
  152. package/src/shaders/clipping_mask.vertex.glsl +7 -0
  153. package/src/shaders/collision_box.fragment.glsl +21 -0
  154. package/src/shaders/collision_box.vertex.glsl +26 -0
  155. package/src/shaders/collision_circle.fragment.glsl +34 -0
  156. package/src/shaders/collision_circle.vertex.glsl +36 -0
  157. package/src/shaders/debug.fragment.glsl +5 -0
  158. package/src/shaders/debug.vertex.glsl +7 -0
  159. package/src/shaders/encode_attribute.js +19 -0
  160. package/src/shaders/fill.fragment.glsl +13 -0
  161. package/src/shaders/fill.vertex.glsl +13 -0
  162. package/src/shaders/fill_extrusion.fragment.glsl +16 -0
  163. package/src/shaders/fill_extrusion.vertex.glsl +66 -0
  164. package/src/shaders/fill_extrusion_pattern.fragment.glsl +41 -0
  165. package/src/shaders/fill_extrusion_pattern.vertex.glsl +76 -0
  166. package/src/shaders/fill_outline.fragment.glsl +17 -0
  167. package/src/shaders/fill_outline.vertex.glsl +17 -0
  168. package/src/shaders/fill_outline_pattern.fragment.glsl +43 -0
  169. package/src/shaders/fill_outline_pattern.vertex.glsl +41 -0
  170. package/src/shaders/fill_pattern.fragment.glsl +36 -0
  171. package/src/shaders/fill_pattern.vertex.glsl +36 -0
  172. package/src/shaders/heatmap.fragment.glsl +21 -0
  173. package/src/shaders/heatmap.vertex.glsl +53 -0
  174. package/src/shaders/heatmap_texture.fragment.glsl +14 -0
  175. package/src/shaders/heatmap_texture.vertex.glsl +11 -0
  176. package/src/shaders/hillshade.fragment.glsl +52 -0
  177. package/src/shaders/hillshade.vertex.glsl +11 -0
  178. package/src/shaders/hillshade_prepare.fragment.glsl +72 -0
  179. package/src/shaders/hillshade_prepare.vertex.glsl +15 -0
  180. package/src/shaders/index.js +194 -0
  181. package/src/shaders/line.fragment.glsl +28 -0
  182. package/src/shaders/line.vertex.glsl +84 -0
  183. package/src/shaders/line_gradient.fragment.glsl +34 -0
  184. package/src/shaders/line_gradient.vertex.glsl +84 -0
  185. package/src/shaders/line_pattern.fragment.glsl +69 -0
  186. package/src/shaders/line_pattern.vertex.glsl +88 -0
  187. package/src/shaders/line_sdf.fragment.glsl +44 -0
  188. package/src/shaders/line_sdf.vertex.glsl +95 -0
  189. package/src/shaders/raster.fragment.glsl +52 -0
  190. package/src/shaders/raster.vertex.glsl +21 -0
  191. package/src/shaders/symbol_icon.fragment.glsl +17 -0
  192. package/src/shaders/symbol_icon.vertex.glsl +91 -0
  193. package/src/shaders/symbol_sdf.fragment.glsl +50 -0
  194. package/src/shaders/symbol_sdf.vertex.glsl +117 -0
  195. package/src/source/geojson_source.js +267 -0
  196. package/src/source/geojson_worker_source.js +210 -0
  197. package/src/source/geojson_wrapper.js +67 -0
  198. package/src/source/image_source.js +213 -0
  199. package/src/source/load_tilejson.js +40 -0
  200. package/src/source/pixels_to_tile_units.js +17 -0
  201. package/src/source/query_features.js +198 -0
  202. package/src/source/raster_dem_tile_source.js +140 -0
  203. package/src/source/raster_dem_tile_worker_source.js +26 -0
  204. package/src/source/raster_tile_source.js +126 -0
  205. package/src/source/rtl_text_plugin.js +63 -0
  206. package/src/source/source.js +75 -0
  207. package/src/source/source_cache.js +794 -0
  208. package/src/source/source_state.js +55 -0
  209. package/src/source/tile.js +332 -0
  210. package/src/source/tile_bounds.js +40 -0
  211. package/src/source/tile_cache.js +122 -0
  212. package/src/source/tile_id.js +150 -0
  213. package/src/source/vector_tile_source.js +144 -0
  214. package/src/source/vector_tile_worker_source.js +126 -0
  215. package/src/source/worker.js +175 -0
  216. package/src/source/worker_source.js +14 -0
  217. package/src/source/worker_tile.js +199 -0
  218. package/src/style/create_style_layer.js +25 -0
  219. package/src/style/evaluation_parameters.js +45 -0
  220. package/src/style/light.js +112 -0
  221. package/src/style/load_glyph_range.js +17 -0
  222. package/src/style/load_sprite.js +26 -0
  223. package/src/style/parse_glyph_pbf.js +45 -0
  224. package/src/style/pauseable_placement.js +88 -0
  225. package/src/style/properties.js +691 -0
  226. package/src/style/query_utils.js +39 -0
  227. package/src/style/style.js +955 -0
  228. package/src/style/style_layer/background_style_layer.js +11 -0
  229. package/src/style/style_layer/background_style_layer_properties.js +25 -0
  230. package/src/style/style_layer/circle_style_layer.js +93 -0
  231. package/src/style/style_layer/circle_style_layer_properties.js +76 -0
  232. package/src/style/style_layer/fill_extrusion_style_layer.js +194 -0
  233. package/src/style/style_layer/fill_extrusion_style_layer_properties.js +56 -0
  234. package/src/style/style_layer/fill_style_layer.js +46 -0
  235. package/src/style/style_layer/fill_style_layer_properties.js +45 -0
  236. package/src/style/style_layer/heatmap_style_layer.js +51 -0
  237. package/src/style/style_layer/heatmap_style_layer_properties.js +52 -0
  238. package/src/style/style_layer/hillshade_style_layer.js +15 -0
  239. package/src/style/style_layer/hillshade_style_layer_properties.js +43 -0
  240. package/src/style/style_layer/line_style_layer.js +129 -0
  241. package/src/style/style_layer/line_style_layer_properties.js +104 -0
  242. package/src/style/style_layer/raster_style_layer.js +11 -0
  243. package/src/style/style_layer/raster_style_layer_properties.js +55 -0
  244. package/src/style/style_layer/symbol_style_layer.js +66 -0
  245. package/src/style/style_layer/symbol_style_layer_properties.js +288 -0
  246. package/src/style/style_layer.js +183 -0
  247. package/src/style/style_layer_index.js +61 -0
  248. package/src/style/zoom_history.js +36 -0
  249. package/src/style-spec/deref.js +51 -0
  250. package/src/style-spec/error/parsing_error.js +8 -0
  251. package/src/style-spec/error/validation_error.js +10 -0
  252. package/src/style-spec/expression/compound_expression.js +118 -0
  253. package/src/style-spec/expression/definitions/array.js +82 -0
  254. package/src/style-spec/expression/definitions/assertion.js +69 -0
  255. package/src/style-spec/expression/definitions/at.js +57 -0
  256. package/src/style-spec/expression/definitions/case.js +73 -0
  257. package/src/style-spec/expression/definitions/coalesce.js +68 -0
  258. package/src/style-spec/expression/definitions/coercion.js +96 -0
  259. package/src/style-spec/expression/definitions/collator.js +102 -0
  260. package/src/style-spec/expression/definitions/equals.js +93 -0
  261. package/src/style-spec/expression/definitions/index.js +407 -0
  262. package/src/style-spec/expression/definitions/interpolate.js +235 -0
  263. package/src/style-spec/expression/definitions/length.js +54 -0
  264. package/src/style-spec/expression/definitions/let.js +60 -0
  265. package/src/style-spec/expression/definitions/literal.js +64 -0
  266. package/src/style-spec/expression/definitions/match.js +142 -0
  267. package/src/style-spec/expression/definitions/step.js +116 -0
  268. package/src/style-spec/expression/definitions/var.js +38 -0
  269. package/src/style-spec/expression/evaluation_context.js +35 -0
  270. package/src/style-spec/expression/index.js +329 -0
  271. package/src/style-spec/expression/is_constant.js +63 -0
  272. package/src/style-spec/expression/parsing_context.js +213 -0
  273. package/src/style-spec/expression/parsing_error.js +9 -0
  274. package/src/style-spec/expression/runtime_error.js +12 -0
  275. package/src/style-spec/expression/scope.js +34 -0
  276. package/src/style-spec/expression/stops.js +37 -0
  277. package/src/style-spec/expression/types.js +77 -0
  278. package/src/style-spec/expression/values.js +126 -0
  279. package/src/style-spec/feature_filter/README.md +55 -0
  280. package/src/style-spec/feature_filter/index.js +158 -0
  281. package/src/style-spec/function/convert.js +256 -0
  282. package/src/style-spec/function/index.js +299 -0
  283. package/src/style-spec/group_by_layout.js +68 -0
  284. package/src/style-spec/reference/v8.json +5356 -0
  285. package/src/style-spec/util/color.js +73 -0
  286. package/src/style-spec/util/color_spaces.js +128 -0
  287. package/src/style-spec/util/eval_support.js +8 -0
  288. package/src/style-spec/util/get_type.js +18 -0
  289. package/src/style-spec/util/interpolate.js +21 -0
  290. package/src/style-spec/util/properties.js +17 -0
  291. package/src/style-spec/util/ref_properties.js +1 -0
  292. package/src/style-spec/util/result.js +19 -0
  293. package/src/symbol/anchor.js +21 -0
  294. package/src/symbol/check_max_angle.js +75 -0
  295. package/src/symbol/clip_line.js +73 -0
  296. package/src/symbol/collision_feature.js +230 -0
  297. package/src/symbol/collision_index.js +379 -0
  298. package/src/symbol/cross_tile_symbol_index.js +270 -0
  299. package/src/symbol/get_anchors.js +177 -0
  300. package/src/symbol/grid_index.js +318 -0
  301. package/src/symbol/mergelines.js +75 -0
  302. package/src/symbol/opacity_state.js +21 -0
  303. package/src/symbol/placement.js +563 -0
  304. package/src/symbol/projection.js +601 -0
  305. package/src/symbol/quads.js +173 -0
  306. package/src/symbol/shaping.js +347 -0
  307. package/src/symbol/symbol_layout.js +519 -0
  308. package/src/symbol/symbol_size.js +110 -0
  309. package/src/symbol/transform_text.js +16 -0
  310. package/src/ui/anchor.js +24 -0
  311. package/src/ui/bind_handlers.js +199 -0
  312. package/src/ui/camera.js +954 -0
  313. package/src/ui/events.js +210 -0
  314. package/src/ui/handler/box_zoom.js +151 -0
  315. package/src/ui/handler/dblclick_zoom.js +91 -0
  316. package/src/ui/handler/drag_pan.js +285 -0
  317. package/src/ui/handler/drag_rotate.js +290 -0
  318. package/src/ui/handler/frame.js +28 -0
  319. package/src/ui/handler/inertia.js +45 -0
  320. package/src/ui/handler/keyboard.js +148 -0
  321. package/src/ui/handler/scroll_zoom.js +284 -0
  322. package/src/ui/handler/touch_zoom_rotate.js +263 -0
  323. package/src/ui/map.js +1645 -0
  324. package/src/util/actor.js +104 -0
  325. package/src/util/async.js +23 -0
  326. package/src/util/browser.js +61 -0
  327. package/src/util/callback.js +26 -0
  328. package/src/util/classify_rings.js +43 -0
  329. package/src/util/color_ramp.js +24 -0
  330. package/src/util/config.js +24 -0
  331. package/src/util/dictionary_coder.js +25 -0
  332. package/src/util/dispatcher.js +68 -0
  333. package/src/util/dom.js +102 -0
  334. package/src/util/evented.js +182 -0
  335. package/src/util/find_pole_of_inaccessibility.js +129 -0
  336. package/src/util/global_worker_pool.js +15 -0
  337. package/src/util/image.js +124 -0
  338. package/src/util/interpolate.js +5 -0
  339. package/src/util/intersection_tests.js +207 -0
  340. package/src/util/is_char_in_unicode_block.js +287 -0
  341. package/src/util/loader/image.js +32 -0
  342. package/src/util/object.js +178 -0
  343. package/src/util/script_detection.js +337 -0
  344. package/src/util/struct_array.js +197 -0
  345. package/src/util/task_queue.js +57 -0
  346. package/src/util/throttle.js +26 -0
  347. package/src/util/tile_cover.js +114 -0
  348. package/src/util/token.js +13 -0
  349. package/src/util/unique_id.js +12 -0
  350. package/src/util/util.js +192 -0
  351. package/src/util/vectortile_to_geojson.js +44 -0
  352. package/src/util/verticalize_punctuation.js +112 -0
  353. package/src/util/warn.js +21 -0
  354. package/src/util/web_worker.js +5 -0
  355. package/src/util/web_worker_transfer.js +228 -0
  356. package/src/util/worker_pool.js +41 -0
@@ -0,0 +1,329 @@
1
+ const assert = require('assert');
2
+
3
+ const ParsingError = require('./parsing_error');
4
+ const ParsingContext = require('./parsing_context');
5
+ const EvaluationContext = require('./evaluation_context');
6
+ const CompoundExpression = require('./compound_expression');
7
+ const Step = require('./definitions/step');
8
+ const Interpolate = require('./definitions/interpolate');
9
+ const Coalesce = require('./definitions/coalesce');
10
+ const Let = require('./definitions/let');
11
+ const definitions = require('./definitions');
12
+ const isConstant = require('./is_constant');
13
+ const RuntimeError = require('./runtime_error');
14
+ const { success, error } = require('../util/result');
15
+ const { supportsPropertyExpression, supportsZoomExpression, supportsInterpolation } = require('../util/properties');
16
+
17
+ class StyleExpression {
18
+ constructor(expression, propertySpec) {
19
+ this.expression = expression;
20
+ this._warningHistory = {};
21
+ this._defaultValue = getDefaultValue(propertySpec);
22
+ if (propertySpec.type === 'enum') {
23
+ this._enumValues = propertySpec.values;
24
+ }
25
+ }
26
+
27
+ evaluateWithoutErrorHandling(globals, feature, featureState) {
28
+ if (!this._evaluator) {
29
+ this._evaluator = new EvaluationContext();
30
+ }
31
+
32
+ this._evaluator.globals = globals;
33
+ this._evaluator.feature = feature;
34
+ this._evaluator.featureState = featureState;
35
+
36
+ return this.expression.evaluate(this._evaluator);
37
+ }
38
+
39
+ evaluate(globals, feature, featureState) {
40
+ if (!this._evaluator) {
41
+ this._evaluator = new EvaluationContext();
42
+ }
43
+
44
+ this._evaluator.globals = globals;
45
+ this._evaluator.feature = feature;
46
+ this._evaluator.featureState = featureState;
47
+
48
+ try {
49
+ const val = this.expression.evaluate(this._evaluator);
50
+ if (val === null || val === undefined) {
51
+ return this._defaultValue;
52
+ }
53
+ if (this._enumValues && !this._enumValues.includes(val)) {
54
+ throw new RuntimeError(
55
+ `Expected value to be one of ${this._enumValues
56
+ .map(v => JSON.stringify(v))
57
+ .join(', ')}, but found ${JSON.stringify(val)} instead.`
58
+ );
59
+ }
60
+ return val;
61
+ } catch (e) {
62
+ if (!this._warningHistory[e.message]) {
63
+ this._warningHistory[e.message] = true;
64
+ if (typeof console !== 'undefined') {
65
+ console.warn(e.message);
66
+ }
67
+ }
68
+ return this._defaultValue;
69
+ }
70
+ }
71
+ }
72
+
73
+ function isExpression(expression) {
74
+ return (
75
+ Array.isArray(expression) &&
76
+ expression.length > 0 &&
77
+ typeof expression[0] === 'string' &&
78
+ expression[0] in definitions
79
+ );
80
+ }
81
+
82
+ /**
83
+ * Parse and typecheck the given style spec JSON expression. If
84
+ * options.defaultValue is provided, then the resulting StyleExpression's
85
+ * `evaluate()` method will handle errors by logging a warning (once per
86
+ * message) and returning the default value. Otherwise, it will throw
87
+ * evaluation errors.
88
+ *
89
+ * @private
90
+ */
91
+ function createExpression(expression, propertySpec) {
92
+ const parser = new ParsingContext(definitions, [], getExpectedType(propertySpec));
93
+ const parsed = parser.parse(expression);
94
+ if (!parsed) {
95
+ assert(parser.errors.length > 0);
96
+ return error(parser.errors);
97
+ }
98
+
99
+ return success(new StyleExpression(parsed, propertySpec));
100
+ }
101
+
102
+ class ZoomConstantExpression {
103
+ constructor(kind, expression) {
104
+ this.kind = kind;
105
+ this._styleExpression = expression;
106
+ this.isStateDependent = kind !== 'constant' && !isConstant.isStateConstant(expression.expression);
107
+ }
108
+
109
+ evaluateWithoutErrorHandling(globals, feature, featureState) {
110
+ return this._styleExpression.evaluateWithoutErrorHandling(globals, feature, featureState);
111
+ }
112
+
113
+ evaluate(globals, feature, featureState) {
114
+ return this._styleExpression.evaluate(globals, feature, featureState);
115
+ }
116
+ }
117
+
118
+ class ZoomDependentExpression {
119
+ constructor(kind, expression, zoomCurve) {
120
+ this.kind = kind;
121
+ this.zoomStops = zoomCurve.labels;
122
+ this._styleExpression = expression;
123
+ this.isStateDependent = kind !== 'camera' && !isConstant.isStateConstant(expression.expression);
124
+ if (zoomCurve instanceof Interpolate) {
125
+ this._interpolationType = zoomCurve.interpolation;
126
+ }
127
+ }
128
+
129
+ evaluateWithoutErrorHandling(globals, feature, featureState) {
130
+ return this._styleExpression.evaluateWithoutErrorHandling(globals, feature, featureState);
131
+ }
132
+
133
+ evaluate(globals, feature, featureState) {
134
+ return this._styleExpression.evaluate(globals, feature, featureState);
135
+ }
136
+
137
+ interpolationFactor(input, lower, upper) {
138
+ if (this._interpolationType) {
139
+ return Interpolate.interpolationFactor(this._interpolationType, input, lower, upper);
140
+ }
141
+ return 0;
142
+ }
143
+ }
144
+
145
+ function createPropertyExpression(expression, propertySpec) {
146
+ expression = createExpression(expression, propertySpec);
147
+ if (expression.result === 'error') {
148
+ return expression;
149
+ }
150
+
151
+ const parsed = expression.value.expression;
152
+
153
+ const isFeatureConstant = isConstant.isFeatureConstant(parsed);
154
+ if (!isFeatureConstant && !supportsPropertyExpression(propertySpec)) {
155
+ return error([new ParsingError('', 'data expressions not supported')]);
156
+ }
157
+
158
+ const isZoomConstant = isConstant.isGlobalPropertyConstant(parsed, ['zoom']);
159
+ if (!isZoomConstant && !supportsZoomExpression(propertySpec)) {
160
+ return error([new ParsingError('', 'zoom expressions not supported')]);
161
+ }
162
+
163
+ const zoomCurve = findZoomCurve(parsed);
164
+ if (!zoomCurve && !isZoomConstant) {
165
+ return error([
166
+ new ParsingError(
167
+ '',
168
+ '"zoom" expression may only be used as input to a top-level "step" or "interpolate" expression.'
169
+ )
170
+ ]);
171
+ }
172
+ if (zoomCurve instanceof ParsingError) {
173
+ return error([zoomCurve]);
174
+ }
175
+ if (zoomCurve instanceof Interpolate && !supportsInterpolation(propertySpec)) {
176
+ return error([new ParsingError('', '"interpolate" expressions cannot be used with this property')]);
177
+ }
178
+
179
+ if (!zoomCurve) {
180
+ return success(
181
+ isFeatureConstant
182
+ ? new ZoomConstantExpression('constant', expression.value)
183
+ : new ZoomConstantExpression('source', expression.value)
184
+ );
185
+ }
186
+
187
+ return success(
188
+ isFeatureConstant
189
+ ? new ZoomDependentExpression('camera', expression.value, zoomCurve)
190
+ : new ZoomDependentExpression('composite', expression.value, zoomCurve)
191
+ );
192
+ }
193
+
194
+ const { isFunction, createFunction } = require('../function');
195
+ const { Color } = require('./values');
196
+
197
+ // serialization wrapper for old-style stop functions normalized to the
198
+ // expression interface
199
+ class StylePropertyFunction {
200
+ constructor(parameters, specification) {
201
+ this._parameters = parameters;
202
+ this._specification = specification;
203
+ Object.assign(this, createFunction(this._parameters, this._specification));
204
+ }
205
+
206
+ static deserialize(serialized) {
207
+ return new StylePropertyFunction(serialized._parameters, serialized._specification);
208
+ }
209
+
210
+ static serialize(input) {
211
+ return {
212
+ _parameters: input._parameters,
213
+ _specification: input._specification
214
+ };
215
+ }
216
+ }
217
+
218
+ function normalizePropertyExpression(value, specification) {
219
+ if (isFunction(value)) {
220
+ return new StylePropertyFunction(value, specification);
221
+ }
222
+ if (isExpression(value)) {
223
+ const expression = createPropertyExpression(value, specification);
224
+ if (expression.result === 'error') {
225
+ // this should have been caught in validation
226
+ throw new Error(expression.value.map(err => `${err.key}: ${err.message}`).join(', '));
227
+ }
228
+ return expression.value;
229
+ }
230
+ let constant = value;
231
+ if (typeof value === 'string' && specification.type === 'color') {
232
+ constant = Color.parse(value);
233
+ }
234
+ return {
235
+ kind: 'constant',
236
+ evaluate: () => constant
237
+ };
238
+ }
239
+
240
+ // Zoom-dependent expressions may only use ["zoom"] as the input to a top-level "step" or "interpolate"
241
+ // expression (collectively referred to as a "curve"). The curve may be wrapped in one or more "let" or
242
+ // "coalesce" expressions.
243
+ function findZoomCurve(expression) {
244
+ let result = null;
245
+ if (expression instanceof Let) {
246
+ result = findZoomCurve(expression.result);
247
+ } else if (expression instanceof Coalesce) {
248
+ for (const arg of expression.args) {
249
+ result = findZoomCurve(arg);
250
+ if (result) {
251
+ break;
252
+ }
253
+ }
254
+ } else if (
255
+ (expression instanceof Step || expression instanceof Interpolate) &&
256
+ expression.input instanceof CompoundExpression &&
257
+ expression.input.name === 'zoom'
258
+ ) {
259
+ result = expression;
260
+ }
261
+
262
+ if (result instanceof ParsingError) {
263
+ return result;
264
+ }
265
+
266
+ expression.eachChild(child => {
267
+ const childResult = findZoomCurve(child);
268
+ if (childResult instanceof ParsingError) {
269
+ result = childResult;
270
+ } else if (!result && childResult) {
271
+ result = new ParsingError(
272
+ '',
273
+ '"zoom" expression may only be used as input to a top-level "step" or "interpolate" expression.'
274
+ );
275
+ } else if (result && childResult && result !== childResult) {
276
+ result = new ParsingError(
277
+ '',
278
+ 'Only one zoom-based "step" or "interpolate" subexpression may be used in an expression.'
279
+ );
280
+ }
281
+ });
282
+
283
+ return result;
284
+ }
285
+
286
+ const { ColorType, StringType, NumberType, BooleanType, ValueType, array } = require('./types');
287
+
288
+ function getExpectedType(spec) {
289
+ const types = {
290
+ color: ColorType,
291
+ string: StringType,
292
+ number: NumberType,
293
+ enum: StringType,
294
+ boolean: BooleanType
295
+ };
296
+
297
+ if (spec.type === 'array') {
298
+ return array(types[spec.value] || ValueType, spec.length);
299
+ }
300
+
301
+ return types[spec.type] || null;
302
+ }
303
+
304
+ function getDefaultValue(spec) {
305
+ if (spec.type === 'color' && isFunction(spec.default)) {
306
+ // Special case for heatmap-color: it uses the 'default:' to define a
307
+ // default color ramp, but createExpression expects a simple value to fall
308
+ // back to in case of runtime errors
309
+ return new Color(0, 0, 0, 0);
310
+ }
311
+ if (spec.type === 'color') {
312
+ return Color.parse(spec.default) || null;
313
+ }
314
+ if (spec.default === undefined) {
315
+ return null;
316
+ }
317
+ return spec.default;
318
+ }
319
+
320
+ module.exports = {
321
+ StyleExpression,
322
+ isExpression,
323
+ createExpression,
324
+ ZoomConstantExpression,
325
+ ZoomDependentExpression,
326
+ createPropertyExpression,
327
+ StylePropertyFunction,
328
+ normalizePropertyExpression
329
+ };
@@ -0,0 +1,63 @@
1
+ const CompoundExpression = require('./compound_expression');
2
+
3
+ function isFeatureConstant(e) {
4
+ if (e instanceof CompoundExpression) {
5
+ if (e.name === 'get' && e.args.length === 1) {
6
+ return false;
7
+ }
8
+ if (e.name === 'feature-state') {
9
+ return false;
10
+ }
11
+ if (e.name === 'has' && e.args.length === 1) {
12
+ return false;
13
+ }
14
+ if (e.name === 'properties' || e.name === 'geometry-type' || e.name === 'id') {
15
+ return false;
16
+ }
17
+ if (/^filter-/.test(e.name)) {
18
+ return false;
19
+ }
20
+ }
21
+
22
+ let result = true;
23
+ e.eachChild(arg => {
24
+ if (result && !isFeatureConstant(arg)) {
25
+ result = false;
26
+ }
27
+ });
28
+ return result;
29
+ }
30
+
31
+ function isStateConstant(e) {
32
+ if (e instanceof CompoundExpression) {
33
+ if (e.name === 'feature-state') {
34
+ return false;
35
+ }
36
+ }
37
+ let result = true;
38
+ e.eachChild(arg => {
39
+ if (result && !isStateConstant(arg)) {
40
+ result = false;
41
+ }
42
+ });
43
+ return result;
44
+ }
45
+
46
+ function isGlobalPropertyConstant(e, properties) {
47
+ if (e instanceof CompoundExpression && properties.indexOf(e.name) >= 0) {
48
+ return false;
49
+ }
50
+ let result = true;
51
+ e.eachChild(arg => {
52
+ if (result && !isGlobalPropertyConstant(arg, properties)) {
53
+ result = false;
54
+ }
55
+ });
56
+ return result;
57
+ }
58
+
59
+ module.exports = {
60
+ isFeatureConstant,
61
+ isGlobalPropertyConstant,
62
+ isStateConstant
63
+ };
@@ -0,0 +1,213 @@
1
+ const Scope = require('./scope');
2
+
3
+ const { checkSubtype } = require('./types');
4
+ const ParsingError = require('./parsing_error');
5
+ const Literal = require('./definitions/literal');
6
+ const Assertion = require('./definitions/assertion');
7
+ const ArrayAssertion = require('./definitions/array');
8
+ const Coercion = require('./definitions/coercion');
9
+ const EvaluationContext = require('./evaluation_context');
10
+ const { CollatorExpression } = require('./definitions/collator');
11
+ const { isGlobalPropertyConstant, isFeatureConstant } = require('./is_constant');
12
+ const Var = require('./definitions/var');
13
+
14
+ /**
15
+ * State associated parsing at a given point in an expression tree.
16
+ * @private
17
+ */
18
+ class ParsingContext {
19
+ // The expected type of this expression. Provided only to allow Expression
20
+ // implementations to infer argument types: Expression#parse() need not
21
+ // check that the output type of the parsed expression matches
22
+ // `expectedType`.
23
+
24
+ constructor(registry, path = [], expectedType, scope = new Scope(), errors = []) {
25
+ this.registry = registry;
26
+ this.path = path;
27
+ this.key = path.map(part => `[${part}]`).join('');
28
+ this.scope = scope;
29
+ this.errors = errors;
30
+ this.expectedType = expectedType;
31
+ }
32
+
33
+ /**
34
+ * @param expr the JSON expression to parse
35
+ * @param index the optional argument index if this expression is an argument of a parent expression that's being parsed
36
+ * @param options
37
+ * @param options.omitTypeAnnotations set true to omit inferred type annotations. Caller beware: with this option set, the parsed expression's type will NOT satisfy `expectedType` if it would normally be wrapped in an inferred annotation.
38
+ * @private
39
+ */
40
+ parse(expr, index, expectedType, bindings, options = {}) {
41
+ if (index) {
42
+ return this.concat(index, expectedType, bindings)._parse(expr, options);
43
+ }
44
+ return this._parse(expr, options);
45
+ }
46
+
47
+ _parse(expr, options) {
48
+ if (expr === null || typeof expr === 'string' || typeof expr === 'boolean' || typeof expr === 'number') {
49
+ expr = ['literal', expr];
50
+ }
51
+
52
+ if (Array.isArray(expr)) {
53
+ if (expr.length === 0) {
54
+ return this.error(
55
+ `Expected an array with at least one element. If you wanted a literal array, use ["literal", []].`
56
+ );
57
+ }
58
+
59
+ const op = expr[0];
60
+ if (typeof op !== 'string') {
61
+ this.error(
62
+ `Expression name must be a string, but found ${typeof op} instead. If you wanted a literal array, use ["literal", [...]].`,
63
+ 0
64
+ );
65
+ return null;
66
+ }
67
+
68
+ const Expr = this.registry[op];
69
+ if (Expr) {
70
+ let parsed = Expr.parse(expr, this);
71
+ if (!parsed) return null;
72
+
73
+ if (this.expectedType) {
74
+ const expected = this.expectedType;
75
+ const actual = parsed.type;
76
+
77
+ // When we expect a number, string, boolean, or array but
78
+ // have a Value, we can wrap it in a refining assertion.
79
+ // When we expect a Color but have a String or Value, we
80
+ // can wrap it in "to-color" coercion.
81
+ // Otherwise, we do static type-checking.
82
+ if (
83
+ (expected.kind === 'string' ||
84
+ expected.kind === 'number' ||
85
+ expected.kind === 'boolean' ||
86
+ expected.kind === 'object') &&
87
+ actual.kind === 'value'
88
+ ) {
89
+ if (!options.omitTypeAnnotations) {
90
+ parsed = new Assertion(expected, [parsed]);
91
+ }
92
+ } else if (expected.kind === 'array' && actual.kind === 'value') {
93
+ if (!options.omitTypeAnnotations) {
94
+ parsed = new ArrayAssertion(expected, parsed);
95
+ }
96
+ } else if (expected.kind === 'color' && (actual.kind === 'value' || actual.kind === 'string')) {
97
+ if (!options.omitTypeAnnotations) {
98
+ parsed = new Coercion(expected, [parsed]);
99
+ }
100
+ } else if (this.checkSubtype(this.expectedType, parsed.type)) {
101
+ return null;
102
+ }
103
+ }
104
+
105
+ // If an expression's arguments are all literals, we can evaluate
106
+ // it immediately and replace it with a literal value in the
107
+ // parsed/compiled result.
108
+ if (!(parsed instanceof Literal) && isConstant(parsed)) {
109
+ const ec = new EvaluationContext();
110
+ try {
111
+ parsed = new Literal(parsed.type, parsed.evaluate(ec));
112
+ } catch (e) {
113
+ this.error(e.message);
114
+ return null;
115
+ }
116
+ }
117
+
118
+ return parsed;
119
+ }
120
+
121
+ return this.error(`Unknown expression "${op}". If you wanted a literal array, use ["literal", [...]].`, 0);
122
+ }
123
+ if (typeof expr === 'undefined') {
124
+ return this.error(`'undefined' value invalid. Use null instead.`);
125
+ }
126
+ if (typeof expr === 'object') {
127
+ return this.error(`Bare objects invalid. Use ["literal", {...}] instead.`);
128
+ }
129
+ return this.error(`Expected an array, but found ${typeof expr} instead.`);
130
+ }
131
+
132
+ /**
133
+ * Returns a copy of this context suitable for parsing the subexpression at
134
+ * index `index`, optionally appending to 'let' binding map.
135
+ *
136
+ * Note that `errors` property, intended for collecting errors while
137
+ * parsing, is copied by reference rather than cloned.
138
+ * @private
139
+ */
140
+ concat(index, expectedType, bindings) {
141
+ const path = typeof index === 'number' ? this.path.concat(index) : this.path;
142
+ const scope = bindings ? this.scope.concat(bindings) : this.scope;
143
+ return new ParsingContext(this.registry, path, expectedType || null, scope, this.errors);
144
+ }
145
+
146
+ /**
147
+ * Push a parsing (or type checking) error into the `this.errors`
148
+ * @param error The message
149
+ * @param keys Optionally specify the source of the error at a child
150
+ * of the current expression at `this.key`.
151
+ * @private
152
+ */
153
+ error(error, ...keys) {
154
+ const key = `${this.key}${keys.map(k => `[${k}]`).join('')}`;
155
+ this.errors.push(new ParsingError(key, error));
156
+ }
157
+
158
+ /**
159
+ * Returns null if `t` is a subtype of `expected`; otherwise returns an
160
+ * error message and also pushes it to `this.errors`.
161
+ */
162
+ checkSubtype(expected, t) {
163
+ const error = checkSubtype(expected, t);
164
+ if (error) this.error(error);
165
+ return error;
166
+ }
167
+ }
168
+
169
+ module.exports = ParsingContext;
170
+
171
+ function isConstant(expression) {
172
+ const CompoundExpression = require('./compound_expression');
173
+
174
+ if (expression instanceof Var) {
175
+ return isConstant(expression.boundExpression);
176
+ }
177
+ if (expression instanceof CompoundExpression && expression.name === 'error') {
178
+ return false;
179
+ }
180
+ if (expression instanceof CollatorExpression) {
181
+ // Although the results of a Collator expression with fixed arguments
182
+ // generally shouldn't change between executions, we can't serialize them
183
+ // as constant expressions because results change based on environment.
184
+ return false;
185
+ }
186
+
187
+ const isTypeAnnotation =
188
+ expression instanceof Coercion || expression instanceof Assertion || expression instanceof ArrayAssertion;
189
+
190
+ let childrenConstant = true;
191
+ expression.eachChild(child => {
192
+ // We can _almost_ assume that if `expressions` children are constant,
193
+ // they would already have been evaluated to Literal values when they
194
+ // were parsed. Type annotations are the exception, because they might
195
+ // have been inferred and added after a child was parsed.
196
+
197
+ // So we recurse into isConstant() for the children of type annotations,
198
+ // but otherwise simply check whether they are Literals.
199
+ if (isTypeAnnotation) {
200
+ childrenConstant = childrenConstant && isConstant(child);
201
+ } else {
202
+ childrenConstant = childrenConstant && child instanceof Literal;
203
+ }
204
+ });
205
+ if (!childrenConstant) {
206
+ return false;
207
+ }
208
+
209
+ return (
210
+ isFeatureConstant(expression) &&
211
+ isGlobalPropertyConstant(expression, ['zoom', 'heatmap-density', 'line-progress', 'is-supported-script'])
212
+ );
213
+ }
@@ -0,0 +1,9 @@
1
+ class ParsingError extends Error {
2
+ constructor(key, message) {
3
+ super(message);
4
+ this.message = message;
5
+ this.key = key;
6
+ }
7
+ }
8
+
9
+ module.exports = ParsingError;
@@ -0,0 +1,12 @@
1
+ class RuntimeError {
2
+ constructor(message) {
3
+ this.name = 'ExpressionEvaluationError';
4
+ this.message = message;
5
+ }
6
+
7
+ toJSON() {
8
+ return this.message;
9
+ }
10
+ }
11
+
12
+ module.exports = RuntimeError;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Tracks `let` bindings during expression parsing.
3
+ * @private
4
+ */
5
+ class Scope {
6
+ constructor(parent, bindings = []) {
7
+ this.parent = parent;
8
+ this.bindings = {};
9
+ for (const [name, expression] of bindings) {
10
+ this.bindings[name] = expression;
11
+ }
12
+ }
13
+
14
+ concat(bindings) {
15
+ return new Scope(this, bindings);
16
+ }
17
+
18
+ get(name) {
19
+ if (this.bindings[name]) {
20
+ return this.bindings[name];
21
+ }
22
+ if (this.parent) {
23
+ return this.parent.get(name);
24
+ }
25
+ throw new Error(`${name} not found in scope.`);
26
+ }
27
+
28
+ has(name) {
29
+ if (this.bindings[name]) return true;
30
+ return this.parent ? this.parent.has(name) : false;
31
+ }
32
+ }
33
+
34
+ module.exports = Scope;
@@ -0,0 +1,37 @@
1
+ const RuntimeError = require('./runtime_error');
2
+
3
+ /**
4
+ * Returns the index of the last stop <= input, or 0 if it doesn't exist.
5
+ * @private
6
+ */
7
+ function findStopLessThanOrEqualTo(stops, input) {
8
+ const n = stops.length;
9
+ let lowerIndex = 0;
10
+ let upperIndex = n - 1;
11
+ let currentIndex = 0;
12
+ let currentValue;
13
+ let upperValue;
14
+
15
+ while (lowerIndex <= upperIndex) {
16
+ currentIndex = Math.floor((lowerIndex + upperIndex) / 2);
17
+ currentValue = stops[currentIndex];
18
+ upperValue = stops[currentIndex + 1];
19
+ if (input === currentValue || (input > currentValue && input < upperValue)) {
20
+ // Search complete
21
+ return currentIndex;
22
+ }
23
+ if (currentValue < input) {
24
+ lowerIndex = currentIndex + 1;
25
+ } else if (currentValue > input) {
26
+ upperIndex = currentIndex - 1;
27
+ } else {
28
+ throw new RuntimeError('Input is not a number.');
29
+ }
30
+ }
31
+
32
+ return Math.max(currentIndex - 1, 0);
33
+ }
34
+
35
+ module.exports = {
36
+ findStopLessThanOrEqualTo
37
+ };