@mapwhit/tilerenderer 0.49.0 → 0.51.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.
Files changed (147) hide show
  1. package/build/min/package.json +1 -1
  2. package/build/min/src/shaders/.dir +0 -0
  3. package/build/min/src/shaders/_prelude.fragment.glsl.js +14 -0
  4. package/build/min/src/shaders/_prelude.vertex.glsl.js +14 -0
  5. package/build/min/src/shaders/background.fragment.glsl.js +5 -0
  6. package/build/min/src/shaders/background.vertex.glsl.js +1 -0
  7. package/build/min/src/shaders/background_pattern.fragment.glsl.js +5 -0
  8. package/build/min/src/shaders/background_pattern.vertex.glsl.js +1 -0
  9. package/build/min/src/shaders/circle.fragment.glsl.js +20 -0
  10. package/build/min/src/shaders/circle.vertex.glsl.js +17 -0
  11. package/build/min/src/shaders/clipping_mask.fragment.glsl.js +1 -0
  12. package/build/min/src/shaders/clipping_mask.vertex.glsl.js +1 -0
  13. package/build/min/src/shaders/collision_box.fragment.glsl.js +1 -0
  14. package/build/min/src/shaders/collision_box.vertex.glsl.js +1 -0
  15. package/build/min/src/shaders/collision_circle.fragment.glsl.js +1 -0
  16. package/build/min/src/shaders/collision_circle.vertex.glsl.js +1 -0
  17. package/build/min/src/shaders/debug.fragment.glsl.js +1 -0
  18. package/build/min/src/shaders/debug.vertex.glsl.js +1 -0
  19. package/build/min/src/shaders/fill.fragment.glsl.js +10 -0
  20. package/build/min/src/shaders/fill.vertex.glsl.js +7 -0
  21. package/build/min/src/shaders/fill_extrusion.fragment.glsl.js +5 -0
  22. package/build/min/src/shaders/fill_extrusion.fragment.glsl.txt +1 -9
  23. package/build/min/src/shaders/fill_extrusion.vertex.glsl.js +9 -0
  24. package/build/min/src/shaders/fill_extrusion.vertex.glsl.txt +4 -4
  25. package/build/min/src/shaders/fill_extrusion_pattern.fragment.glsl.js +15 -0
  26. package/build/min/src/shaders/fill_extrusion_pattern.vertex.glsl.js +11 -0
  27. package/build/min/src/shaders/fill_outline.fragment.glsl.js +10 -0
  28. package/build/min/src/shaders/fill_outline.vertex.glsl.js +7 -0
  29. package/build/min/src/shaders/fill_outline_pattern.fragment.glsl.js +13 -0
  30. package/build/min/src/shaders/fill_outline_pattern.vertex.glsl.js +9 -0
  31. package/build/min/src/shaders/fill_pattern.fragment.glsl.js +13 -0
  32. package/build/min/src/shaders/fill_pattern.vertex.glsl.js +9 -0
  33. package/build/min/src/shaders/heatmap.fragment.glsl.js +10 -0
  34. package/build/min/src/shaders/heatmap.vertex.glsl.js +8 -0
  35. package/build/min/src/shaders/heatmap_texture.fragment.glsl.js +5 -0
  36. package/build/min/src/shaders/heatmap_texture.vertex.glsl.js +1 -0
  37. package/build/min/src/shaders/hillshade.fragment.glsl.js +7 -0
  38. package/build/min/src/shaders/hillshade.vertex.glsl.js +1 -0
  39. package/build/min/src/shaders/hillshade_prepare.fragment.glsl.js +8 -0
  40. package/build/min/src/shaders/hillshade_prepare.vertex.glsl.js +1 -0
  41. package/build/min/src/shaders/line.fragment.glsl.js +12 -0
  42. package/build/min/src/shaders/line.vertex.glsl.js +17 -0
  43. package/build/min/src/shaders/line_gradient.fragment.glsl.js +10 -0
  44. package/build/min/src/shaders/line_gradient.vertex.glsl.js +16 -0
  45. package/build/min/src/shaders/line_pattern.fragment.glsl.js +15 -0
  46. package/build/min/src/shaders/line_pattern.vertex.glsl.js +20 -0
  47. package/build/min/src/shaders/line_sdf.fragment.glsl.js +17 -0
  48. package/build/min/src/shaders/line_sdf.vertex.glsl.js +20 -0
  49. package/build/min/src/shaders/raster.fragment.glsl.js +5 -0
  50. package/build/min/src/shaders/raster.vertex.glsl.js +1 -0
  51. package/build/min/src/shaders/symbol_icon.fragment.glsl.js +9 -0
  52. package/build/min/src/shaders/symbol_icon.vertex.glsl.js +5 -0
  53. package/build/min/src/shaders/symbol_sdf.fragment.glsl.js +19 -0
  54. package/build/min/src/shaders/symbol_sdf.vertex.glsl.js +13 -0
  55. package/package.json +7 -7
  56. package/src/data/bucket/fill_bucket.js +1 -1
  57. package/src/data/bucket/fill_extrusion_bucket.js +2 -2
  58. package/src/data/bucket/line_bucket.js +1 -1
  59. package/src/data/bucket/symbol_bucket.js +16 -15
  60. package/src/data/feature_index.js +1 -1
  61. package/src/data/program_configuration.js +1 -1
  62. package/src/gl/color_mode.js +1 -1
  63. package/src/gl/value.js +1 -1
  64. package/src/render/draw_debug.js +1 -1
  65. package/src/render/draw_fill.js +1 -1
  66. package/src/render/draw_heatmap.js +1 -1
  67. package/src/render/glyph_manager.js +6 -130
  68. package/src/render/painter.js +1 -1
  69. package/src/render/uniform_binding.js +1 -1
  70. package/src/shaders/fill_extrusion.fragment.glsl +0 -7
  71. package/src/shaders/fill_extrusion.vertex.glsl +4 -4
  72. package/src/shaders/index.js +50 -50
  73. package/src/source/geojson_worker_source.js +4 -4
  74. package/src/source/geojson_wrapper.js +34 -26
  75. package/src/source/resources/glyphs.js +73 -0
  76. package/src/source/resources/images.js +68 -0
  77. package/src/source/resources/index.js +22 -0
  78. package/src/source/vector_tile_worker_source.js +5 -5
  79. package/src/source/worker.js +6 -5
  80. package/src/source/worker_tile.js +4 -4
  81. package/src/style/properties.js +1 -2
  82. package/src/style/style.js +3 -3
  83. package/src/style/style_layer/symbol_style_layer.js +1 -1
  84. package/src/style/style_layer.js +1 -1
  85. package/src/style-spec/feature_filter/index.js +43 -34
  86. package/src/style-spec/group_by_layout.js +10 -32
  87. package/src/style-spec/reference/v8.json +1 -1
  88. package/src/symbol/mergelines.js +1 -3
  89. package/src/symbol/placement.js +21 -2
  90. package/src/symbol/shaping.js +9 -18
  91. package/src/symbol/symbol_layout.js +1 -2
  92. package/src/symbol/symbol_size.js +1 -1
  93. package/src/symbol/transform_text.js +4 -8
  94. package/src/ui/map.js +11 -39
  95. package/src/util/browser.js +3 -18
  96. package/src/util/classify_rings.js +1 -1
  97. package/src/util/dom.js +0 -88
  98. package/src/util/find_pole_of_inaccessibility.js +2 -2
  99. package/src/util/web_worker_transfer.js +4 -4
  100. package/src/style/load_glyph_range.js +0 -17
  101. package/src/style-spec/expression/compound_expression.js +0 -132
  102. package/src/style-spec/expression/definitions/assertion.js +0 -116
  103. package/src/style-spec/expression/definitions/at.js +0 -57
  104. package/src/style-spec/expression/definitions/case.js +0 -73
  105. package/src/style-spec/expression/definitions/coalesce.js +0 -68
  106. package/src/style-spec/expression/definitions/coercion.js +0 -109
  107. package/src/style-spec/expression/definitions/collator.js +0 -102
  108. package/src/style-spec/expression/definitions/comparison.js +0 -193
  109. package/src/style-spec/expression/definitions/formatted.js +0 -123
  110. package/src/style-spec/expression/definitions/index.js +0 -356
  111. package/src/style-spec/expression/definitions/interpolate.js +0 -245
  112. package/src/style-spec/expression/definitions/length.js +0 -54
  113. package/src/style-spec/expression/definitions/let.js +0 -60
  114. package/src/style-spec/expression/definitions/literal.js +0 -69
  115. package/src/style-spec/expression/definitions/match.js +0 -142
  116. package/src/style-spec/expression/definitions/step.js +0 -116
  117. package/src/style-spec/expression/definitions/var.js +0 -38
  118. package/src/style-spec/expression/evaluation_context.js +0 -35
  119. package/src/style-spec/expression/index.js +0 -329
  120. package/src/style-spec/expression/is_constant.js +0 -63
  121. package/src/style-spec/expression/parsing_context.js +0 -212
  122. package/src/style-spec/expression/parsing_error.js +0 -9
  123. package/src/style-spec/expression/runtime_error.js +0 -12
  124. package/src/style-spec/expression/scope.js +0 -34
  125. package/src/style-spec/expression/stops.js +0 -37
  126. package/src/style-spec/expression/types.js +0 -88
  127. package/src/style-spec/expression/values.js +0 -126
  128. package/src/style-spec/function/convert.js +0 -234
  129. package/src/style-spec/function/index.js +0 -299
  130. package/src/style-spec/util/color.js +0 -73
  131. package/src/style-spec/util/color_spaces.js +0 -128
  132. package/src/style-spec/util/get_type.js +0 -18
  133. package/src/style-spec/util/interpolate.js +0 -21
  134. package/src/style-spec/util/properties.js +0 -17
  135. package/src/style-spec/util/result.js +0 -19
  136. package/src/ui/anchor.js +0 -24
  137. package/src/ui/bind_handlers.js +0 -199
  138. package/src/ui/events.js +0 -210
  139. package/src/ui/handler/box_zoom.js +0 -151
  140. package/src/ui/handler/dblclick_zoom.js +0 -91
  141. package/src/ui/handler/drag_pan.js +0 -285
  142. package/src/ui/handler/drag_rotate.js +0 -290
  143. package/src/ui/handler/frame.js +0 -28
  144. package/src/ui/handler/inertia.js +0 -45
  145. package/src/ui/handler/keyboard.js +0 -148
  146. package/src/ui/handler/scroll_zoom.js +0 -284
  147. package/src/ui/handler/touch_zoom_rotate.js +0 -263
@@ -1,7 +1,6 @@
1
1
  const { charHasUprightVerticalOrientation, charAllowsIdeographicBreaking } = require('../util/script_detection');
2
2
  const verticalizePunctuation = require('../util/verticalize_punctuation');
3
3
  const { plugin: rtlTextPlugin } = require('../source/rtl_text_plugin');
4
- const { Formatted } = require('../style-spec/expression/definitions/formatted');
5
4
 
6
5
  const WritingMode = {
7
6
  horizontal: 1,
@@ -24,23 +23,15 @@ class TaggedString {
24
23
 
25
24
  static fromFeature(text, defaultFontStack) {
26
25
  const result = new TaggedString();
27
- if (text instanceof Formatted) {
28
- for (let i = 0; i < text.sections.length; i++) {
29
- const section = text.sections[i];
30
- result.sections.push({
31
- scale: section.scale || 1,
32
- fontStack: section.fontStack || defaultFontStack
33
- });
34
- result.text += section.text;
35
- for (let j = 0; j < section.text.length; j++) {
36
- result.sectionIndex.push(i);
37
- }
38
- }
39
- } else {
40
- result.text = text;
41
- result.sections.push({ scale: 1, fontStack: defaultFontStack });
42
- for (let i = 0; i < text.length; i++) {
43
- result.sectionIndex.push(0);
26
+ for (let i = 0; i < text.sections.length; i++) {
27
+ const section = text.sections[i];
28
+ result.sections.push({
29
+ scale: section.scale || 1,
30
+ fontStack: section.fontStack || defaultFontStack
31
+ });
32
+ result.text += section.text;
33
+ for (let j = 0; j < section.text.length; j++) {
34
+ result.sectionIndex.push(i);
44
35
  }
45
36
  }
46
37
  return result;
@@ -12,7 +12,6 @@ const classifyRings = require('../util/classify_rings');
12
12
  const EXTENT = require('../data/extent');
13
13
  const SymbolBucket = require('../data/bucket/symbol_bucket');
14
14
  const EvaluationParameters = require('../style/evaluation_parameters');
15
- const { Formatted } = require('../style-spec/expression/definitions/formatted');
16
15
  const murmur3 = require('murmurhash-js');
17
16
 
18
17
  // The symbol layout process needs `text-size` evaluated at up to five different zoom levels, and
@@ -79,7 +78,7 @@ function performSymbolLayout(bucket, glyphMap, glyphPositions, imageMap, imagePo
79
78
  const shapedTextOrientations = {};
80
79
  const text = feature.text;
81
80
  if (text) {
82
- const unformattedText = text instanceof Formatted ? text.toString() : text;
81
+ const unformattedText = text.toString();
83
82
  const textOffset = layout
84
83
  .get('text-offset')
85
84
  .evaluate(feature, {})
@@ -1,4 +1,4 @@
1
- const { normalizePropertyExpression } = require('../style-spec/expression');
1
+ const { normalizePropertyExpression } = require('@mapwhit/style-expressions');
2
2
 
3
3
  const interpolate = require('../util/interpolate');
4
4
  const { clamp } = require('../util/util');
@@ -1,5 +1,4 @@
1
1
  const { plugin: rtlTextPlugin } = require('../source/rtl_text_plugin');
2
- const { Formatted } = require('../style-spec/expression/definitions/formatted');
3
2
 
4
3
  function transformText(text, layer, feature) {
5
4
  const transform = layer.layout.get('text-transform').evaluate(feature, {});
@@ -17,11 +16,8 @@ function transformText(text, layer, feature) {
17
16
  }
18
17
 
19
18
  module.exports = function (text, layer, feature) {
20
- if (text instanceof Formatted) {
21
- text.sections.forEach(section => {
22
- section.text = transformText(section.text, layer, feature);
23
- });
24
- return text;
25
- }
26
- return transformText(text, layer, feature);
19
+ text.sections.forEach(section => {
20
+ section.text = transformText(section.text, layer, feature);
21
+ });
22
+ return text;
27
23
  };
package/src/ui/map.js CHANGED
@@ -9,7 +9,6 @@ const Style = require('../style/style');
9
9
  const EvaluationParameters = require('../style/evaluation_parameters');
10
10
  const Painter = require('../render/painter');
11
11
  const Transform = require('../geo/transform');
12
- const bindHandlers = require('./bind_handlers');
13
12
  const Camera = require('./camera');
14
13
  const LngLat = require('../geo/lng_lat');
15
14
  const LngLatBounds = require('../geo/lng_lat_bounds');
@@ -31,18 +30,8 @@ const defaultOptions = {
31
30
 
32
31
  interactive: true,
33
32
 
34
- scrollZoom: true,
35
- boxZoom: true,
36
- dragRotate: true,
37
- dragPan: true,
38
- keyboard: true,
39
- doubleClickZoom: true,
40
- touchZoomRotate: true,
41
-
42
33
  bearingSnap: 7,
43
34
 
44
- clickTolerance: 3,
45
-
46
35
  attributionControl: true,
47
36
 
48
37
  failIfMajorPerformanceCaveat: false,
@@ -98,19 +87,11 @@ const defaultOptions = {
98
87
  * bearing will snap to north. For example, with a `bearingSnap` of 7, if the user rotates
99
88
  * the map within 7 degrees of north, the map will automatically snap to exact north.
100
89
  * @param {boolean} [options.pitchWithRotate=true] If `false`, the map's pitch (tilt) control with "drag to rotate" interaction will be disabled.
101
- * @param {number} [options.clickTolerance=3] The max number of pixels a user can shift the mouse pointer during a click for it to be considered a valid click (as opposed to a mouse drag).
102
90
  * @param {string} [options.logoPosition='bottom-left'] A string representing the position of the Mapbox wordmark on the map. Valid options are `top-left`,`top-right`, `bottom-left`, `bottom-right`.
103
91
  * @param {boolean} [options.failIfMajorPerformanceCaveat=false] If `true`, map creation will fail if the performance of Mapbox
104
92
  * GL JS would be dramatically worse than expected (i.e. a software renderer would be used).
105
93
  * @param {boolean} [options.preserveDrawingBuffer=false] If `true`, the map's canvas can be exported to a PNG using `map.getCanvas().toDataURL()`. This is `false` by default as a performance optimization.
106
94
  * @param {LngLatBoundsLike} [options.maxBounds] If set, the map will be constrained to the given bounds.
107
- * @param {boolean|Object} [options.scrollZoom=true] If `true`, the "scroll to zoom" interaction is enabled. An `Object` value is passed as options to {@link ScrollZoomHandler#enable}.
108
- * @param {boolean} [options.boxZoom=true] If `true`, the "box zoom" interaction is enabled (see {@link BoxZoomHandler}).
109
- * @param {boolean} [options.dragRotate=true] If `true`, the "drag to rotate" interaction is enabled (see {@link DragRotateHandler}).
110
- * @param {boolean} [options.dragPan=true] If `true`, the "drag to pan" interaction is enabled (see {@link DragPanHandler}).
111
- * @param {boolean} [options.keyboard=true] If `true`, keyboard shortcuts are enabled (see {@link KeyboardHandler}).
112
- * @param {boolean} [options.doubleClickZoom=true] If `true`, the "double click to zoom" interaction is enabled (see {@link DoubleClickZoomHandler}).
113
- * @param {boolean|Object} [options.touchZoomRotate=true] If `true`, the "pinch to rotate and zoom" interaction is enabled. An `Object` value is passed as options to {@link TouchZoomRotateHandler#enable}.
114
95
  * @param {boolean} [options.trackResize=true] If `true`, the map will automatically resize when the browser window resizes.
115
96
  * @param {LngLatLike} [options.center=[0, 0]] The inital geographical centerpoint of the map. If `center` is not specified in the constructor options, Mapbox GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `[0, 0]` Note: Mapbox GL uses longitude, latitude coordinate order (as opposed to latitude, longitude) to match GeoJSON.
116
97
  * @param {number} [options.zoom=0] The initial zoom level of the map. If `zoom` is not specified in the constructor options, Mapbox GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `0`.
@@ -118,10 +99,6 @@ const defaultOptions = {
118
99
  * @param {number} [options.pitch=0] The initial pitch (tilt) of the map, measured in degrees away from the plane of the screen (0-60). If `pitch` is not specified in the constructor options, Mapbox GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `0`.
119
100
  * @param {boolean} [options.renderWorldCopies=true] If `true`, multiple copies of the world will be rendered, when zoomed out.
120
101
  * @param {number} [options.maxTileCacheSize=null] The maximum number of tiles stored in the tile cache for a given source. If omitted, the cache will be dynamically sized based on the current viewport.
121
- * @param {string} [options.localIdeographFontFamily=null] If specified, defines a CSS font-family
122
- * for locally overriding generation of glyphs in the 'CJK Unified Ideographs' and 'Hangul Syllables' ranges.
123
- * In these ranges, font settings from the map's style will be ignored, except for font-weight keywords (light/regular/medium/bold).
124
- * The purpose of this option is to avoid bandwidth-intensive glyph server requests. (see [Use locally generated ideographs](https://www.mapbox.com/mapbox-gl-js/example/local-ideographs))
125
102
  * @param {number} [options.fadeDuration=300] Controls the duration of the fade-in/fade-out animation for label collisions, in milliseconds. This setting affects all symbol layers. This setting does not affect the duration of runtime styling transitions or raster tile cross-fading.
126
103
  * @param {boolean} [options.crossSourceCollisions=true] If `true`, symbols from multiple sources can collide with each other during collision detection. If `false`, collision detection is run separately for the symbols in each source.
127
104
  * @example
@@ -134,6 +111,8 @@ const defaultOptions = {
134
111
  * @see [Display a map](https://www.mapbox.com/mapbox-gl-js/examples/)
135
112
  */
136
113
  class Map extends Camera {
114
+ #mapGestures;
115
+
137
116
  constructor(options) {
138
117
  options = Object.assign({}, defaultOptions, options);
139
118
 
@@ -203,8 +182,6 @@ class Map extends Camera {
203
182
  window.addEventListener('resize', this._onWindowResize, false);
204
183
  }
205
184
 
206
- bindHandlers(this, options);
207
-
208
185
  this.jumpTo({
209
186
  center: options.center,
210
187
  zoom: options.zoom,
@@ -214,7 +191,7 @@ class Map extends Camera {
214
191
 
215
192
  this.resize();
216
193
 
217
- if (options.style) this.setStyle(options.style, { localIdeographFontFamily: options.localIdeographFontFamily });
194
+ if (options.style) this.setStyle(options.style);
218
195
 
219
196
  this.on('style.load', function () {
220
197
  if (this.transform.unmodified) {
@@ -465,27 +442,21 @@ class Map extends Camera {
465
442
  * Returns true if the map is panning, zooming, rotating, or pitching due to a camera animation or user gesture.
466
443
  */
467
444
  isMoving() {
468
- return (
469
- this._moving ||
470
- this.dragPan.isActive() ||
471
- this.dragRotate.isActive() ||
472
- this.touchZoomRotate.isActive() ||
473
- this.scrollZoom.isActive()
474
- );
445
+ return !!(this._moving || this._mapGestures?.isMoving());
475
446
  }
476
447
 
477
448
  /**
478
449
  * Returns true if the map is zooming due to a camera animation or user gesture.
479
450
  */
480
451
  isZooming() {
481
- return this._zooming || this.touchZoomRotate.isActive() || this.scrollZoom.isZooming();
452
+ return !!(this._zooming || this._mapGestures?.isZooming());
482
453
  }
483
454
 
484
455
  /**
485
456
  * Returns true if the map is rotating due to a camera animation or user gesture.
486
457
  */
487
458
  isRotating() {
488
- return this._rotating || this.touchZoomRotate.isActive() || this.dragRotate.isActive();
459
+ return !!(this._rotating || this._mapGestures?.isRotating());
489
460
  }
490
461
 
491
462
  /**
@@ -666,9 +637,6 @@ class Map extends Camera {
666
637
  * @param {Object} [options]
667
638
  * @param {boolean} [options.diff=true] If false, force a 'full' update, removing the current style
668
639
  * and adding building the given one instead of attempting a diff-based update.
669
- * @param {string} [options.localIdeographFontFamily=null] If non-null, defines a css font-family
670
- * for locally overriding generation of glyphs in the 'CJK Unified Ideographs' and 'Hangul Syllables'
671
- * ranges. Forces a full update.
672
640
  * @returns {Map} `this`
673
641
  * @see [Change a map's style](https://www.mapbox.com/mapbox-gl-js/example/setstyle/)
674
642
  */
@@ -823,7 +791,11 @@ class Map extends Camera {
823
791
  );
824
792
  } else {
825
793
  const { width, height, data } = image;
826
- this.style.addImage(id, { data: new RGBAImage({ width, height }, new Uint8Array(data)), pixelRatio, sdf });
794
+ this.style.addImage(id, {
795
+ data: new RGBAImage({ width, height }, new Uint8Array(data)),
796
+ pixelRatio,
797
+ sdf
798
+ });
827
799
  }
828
800
  }
829
801
 
@@ -1,25 +1,10 @@
1
1
  // TODO move code that assumes that `window` may not be set to relevant tests
2
2
 
3
- const now =
4
- typeof window === 'object' && window.performance?.now
5
- ? window.performance.now.bind(window.performance)
6
- : Date.now.bind(Date);
3
+ const now = () => performance.now();
7
4
 
8
- const raf =
9
- typeof window === 'object'
10
- ? window.requestAnimationFrame ||
11
- window.mozRequestAnimationFrame ||
12
- window.webkitRequestAnimationFrame ||
13
- window.msRequestAnimationFrame
14
- : fn => setTimeout(fn, 0);
5
+ const raf = typeof window === 'object' ? window.requestAnimationFrame : fn => setTimeout(fn, 0);
15
6
 
16
- const cancel =
17
- typeof window === 'object'
18
- ? window.cancelAnimationFrame ||
19
- window.mozCancelAnimationFrame ||
20
- window.webkitCancelAnimationFrame ||
21
- window.msCancelAnimationFrame
22
- : id => clearTimeout(id);
7
+ const cancel = typeof window === 'object' ? window.cancelAnimationFrame : id => clearTimeout(id);
23
8
 
24
9
  /**
25
10
  * @private
@@ -1,4 +1,4 @@
1
- const quickselect = require('quickselect');
1
+ const { default: quickselect } = require('quickselect');
2
2
 
3
3
  const { calculateSignedArea } = require('./util');
4
4
 
package/src/util/dom.js CHANGED
@@ -1,7 +1,3 @@
1
- const Point = require('@mapbox/point-geometry');
2
-
3
- const assert = require('assert');
4
-
5
1
  const DOM = {};
6
2
  module.exports = DOM;
7
3
 
@@ -16,87 +12,3 @@ DOM.createNS = function (namespaceURI, tagName) {
16
12
  const el = window.document.createElementNS(namespaceURI, tagName);
17
13
  return el;
18
14
  };
19
-
20
- let docStyle;
21
- let selectProp;
22
-
23
- DOM.initEnableDisableDrag = function () {
24
- docStyle = window.document ? window.document.documentElement.style : null;
25
-
26
- function testProp(props) {
27
- if (!docStyle) return null;
28
- for (let i = 0; i < props.length; i++) {
29
- if (props[i] in docStyle) {
30
- return props[i];
31
- }
32
- }
33
- return props[0];
34
- }
35
-
36
- selectProp = testProp(['userSelect', 'MozUserSelect', 'WebkitUserSelect', 'msUserSelect']);
37
- };
38
-
39
- let userSelect;
40
-
41
- DOM.disableDrag = function () {
42
- if (docStyle && selectProp) {
43
- userSelect = docStyle[selectProp];
44
- docStyle[selectProp] = 'none';
45
- }
46
- };
47
-
48
- DOM.enableDrag = function () {
49
- if (docStyle && selectProp) {
50
- docStyle[selectProp] = userSelect;
51
- }
52
- };
53
-
54
- // Suppress the next click, but only if it's immediate.
55
- const suppressClick = function (e) {
56
- e.preventDefault();
57
- e.stopPropagation();
58
- window.removeEventListener('click', suppressClick, true);
59
- };
60
-
61
- DOM.suppressClick = function () {
62
- window.addEventListener('click', suppressClick, true);
63
- window.setTimeout(() => {
64
- if (typeof window === 'object' && window) {
65
- window.removeEventListener('click', suppressClick, true);
66
- }
67
- }, 0);
68
- };
69
-
70
- DOM.mousePos = function (el, e) {
71
- const rect = el.getBoundingClientRect();
72
- e = e.touches ? e.touches[0] : e;
73
- return new Point(e.clientX - rect.left - el.clientLeft, e.clientY - rect.top - el.clientTop);
74
- };
75
-
76
- DOM.touchPos = function (el, e) {
77
- const rect = el.getBoundingClientRect();
78
- const points = [];
79
- const touches = e.type === 'touchend' ? e.changedTouches : e.touches;
80
- for (let i = 0; i < touches.length; i++) {
81
- points.push(
82
- new Point(touches[i].clientX - rect.left - el.clientLeft, touches[i].clientY - rect.top - el.clientTop)
83
- );
84
- }
85
- return points;
86
- };
87
-
88
- DOM.mouseButton = function (e) {
89
- assert(e.type === 'mousedown' || e.type === 'mouseup');
90
- if (
91
- typeof window.InstallTrigger !== 'undefined' &&
92
- e.button === 2 &&
93
- e.ctrlKey &&
94
- window.navigator.platform.toUpperCase().indexOf('MAC') >= 0
95
- ) {
96
- // Fix for https://github.com/mapbox/mapbox-gl-js/issues/3131:
97
- // Firefox (detected by InstallTrigger) on Mac determines e.button = 2 when
98
- // using Control + left click
99
- return 0;
100
- }
101
- return e.button;
102
- };
@@ -1,4 +1,4 @@
1
- const Queue = require('tinyqueue');
1
+ const { default: Queue } = require('tinyqueue');
2
2
 
3
3
  const Point = require('@mapbox/point-geometry');
4
4
  const { distToSegmentSquared } = require('./intersection_tests');
@@ -34,7 +34,7 @@ module.exports = function (polygonRings, precision = 1, debug = false) {
34
34
  let h = cellSize / 2;
35
35
 
36
36
  // a priority queue of cells in order of their "potential" (max distance to polygon)
37
- const cellQueue = new Queue(null, compareMax);
37
+ const cellQueue = new Queue(undefined, compareMax);
38
38
 
39
39
  if (cellSize === 0) return new Point(minX, minY);
40
40
 
@@ -1,13 +1,13 @@
1
1
  const Grid = require('grid-index');
2
- const Color = require('../style-spec/util/color');
2
+ const { Color } = require('@mapwhit/style-expressions');
3
3
  const {
4
+ CompoundExpression,
5
+ definitions: expressions,
4
6
  StylePropertyFunction,
5
7
  StyleExpression,
6
8
  ZoomDependentExpression,
7
9
  ZoomConstantExpression
8
- } = require('../style-spec/expression');
9
- const CompoundExpression = require('../style-spec/expression/compound_expression');
10
- const expressions = require('../style-spec/expression/definitions');
10
+ } = require('@mapwhit/style-expressions');
11
11
 
12
12
  const { register, serialize, deserialize } = require('./transfer_registry');
13
13
  module.exports = {
@@ -1,17 +0,0 @@
1
- const parseGlyphPBF = require('./parse_glyph_pbf');
2
- const { callback } = require('../util/callback');
3
-
4
- module.exports = loadGlyphRange;
5
-
6
- function loadGlyphRange(fontstack, range, load, fn) {
7
- return callback(fn, perform());
8
-
9
- async function perform() {
10
- const data = await load(fontstack, range);
11
- const glyphs = {};
12
- for (const glyph of parseGlyphPBF(data)) {
13
- glyphs[glyph.id] = glyph;
14
- }
15
- return glyphs;
16
- }
17
- }
@@ -1,132 +0,0 @@
1
- const { toString } = require('./types');
2
-
3
- const assert = require('assert');
4
-
5
- class CompoundExpression {
6
- constructor(name, type, evaluate, args) {
7
- this.name = name;
8
- this.type = type;
9
- this._evaluate = evaluate;
10
- this.args = args;
11
- }
12
-
13
- evaluate(ctx) {
14
- return this._evaluate(ctx, this.args);
15
- }
16
-
17
- eachChild(fn) {
18
- this.args.forEach(fn);
19
- }
20
-
21
- possibleOutputs() {
22
- return [undefined];
23
- }
24
-
25
- serialize() {
26
- return [this.name].concat(this.args.map(arg => arg.serialize()));
27
- }
28
-
29
- static parse(args, context) {
30
- const ParsingContext = require('./parsing_context');
31
-
32
- const op = args[0];
33
- const definition = CompoundExpression.definitions[op];
34
- if (!definition) {
35
- return context.error(`Unknown expression "${op}". If you wanted a literal array, use ["literal", [...]].`, 0);
36
- }
37
-
38
- // Now check argument types against each signature
39
- const type = Array.isArray(definition) ? definition[0] : definition.type;
40
-
41
- const availableOverloads = Array.isArray(definition) ? [[definition[1], definition[2]]] : definition.overloads;
42
-
43
- const overloads = availableOverloads.filter(
44
- ([signature]) =>
45
- !Array.isArray(signature) || // varags
46
- signature.length === args.length - 1 // correct param count
47
- );
48
-
49
- let signatureContext = null;
50
-
51
- for (const [params, evaluate] of overloads) {
52
- // Use a fresh context for each attempted signature so that, if
53
- // we eventually succeed, we haven't polluted `context.errors`.
54
- signatureContext = new ParsingContext(context.registry, context.path, null, context.scope);
55
-
56
- // First parse all the args, potentially coercing to the
57
- // types expected by this overload.
58
- const parsedArgs = [];
59
- let argParseFailed = false;
60
- for (let i = 1; i < args.length; i++) {
61
- const arg = args[i];
62
- const expectedType = Array.isArray(params) ? params[i - 1] : params.type;
63
-
64
- const parsed = signatureContext.parse(arg, 1 + parsedArgs.length, expectedType);
65
- if (!parsed) {
66
- argParseFailed = true;
67
- break;
68
- }
69
- parsedArgs.push(parsed);
70
- }
71
- if (argParseFailed) {
72
- // Couldn't coerce args of this overload to expected type, move
73
- // on to next one.
74
- continue;
75
- }
76
-
77
- if (Array.isArray(params)) {
78
- if (params.length !== parsedArgs.length) {
79
- signatureContext.error(`Expected ${params.length} arguments, but found ${parsedArgs.length} instead.`);
80
- continue;
81
- }
82
- }
83
-
84
- for (let i = 0; i < parsedArgs.length; i++) {
85
- const expected = Array.isArray(params) ? params[i] : params.type;
86
- const arg = parsedArgs[i];
87
- signatureContext.concat(i + 1).checkSubtype(expected, arg.type);
88
- }
89
-
90
- if (signatureContext.errors.length === 0) {
91
- return new CompoundExpression(op, type, evaluate, parsedArgs);
92
- }
93
- }
94
-
95
- assert(!signatureContext || signatureContext.errors.length > 0);
96
-
97
- if (overloads.length === 1) {
98
- context.errors.push.apply(context.errors, signatureContext.errors);
99
- } else {
100
- const expected = overloads.length ? overloads : availableOverloads;
101
- const signatures = expected.map(([params]) => stringifySignature(params)).join(' | ');
102
- const actualTypes = [];
103
- // For error message, re-parse arguments without trying to
104
- // apply any coercions
105
- for (let i = 1; i < args.length; i++) {
106
- const parsed = context.parse(args[i], 1 + actualTypes.length);
107
- if (!parsed) return null;
108
- actualTypes.push(toString(parsed.type));
109
- }
110
- context.error(`Expected arguments of type ${signatures}, but found (${actualTypes.join(', ')}) instead.`);
111
- }
112
-
113
- return null;
114
- }
115
-
116
- static register(registry, definitions) {
117
- assert(!CompoundExpression.definitions);
118
- CompoundExpression.definitions = definitions;
119
- for (const name in definitions) {
120
- registry[name] = CompoundExpression;
121
- }
122
- }
123
- }
124
-
125
- function stringifySignature(signature) {
126
- if (Array.isArray(signature)) {
127
- return `(${signature.map(toString).join(', ')})`;
128
- }
129
- return `(${toString(signature.type)}...)`;
130
- }
131
-
132
- module.exports = CompoundExpression;
@@ -1,116 +0,0 @@
1
- const assert = require('assert');
2
-
3
- const {
4
- ObjectType,
5
- ValueType,
6
- StringType,
7
- NumberType,
8
- BooleanType,
9
- checkSubtype,
10
- toString,
11
- array
12
- } = require('../types');
13
- const RuntimeError = require('../runtime_error');
14
- const { typeOf } = require('../values');
15
-
16
- const types = {
17
- string: StringType,
18
- number: NumberType,
19
- boolean: BooleanType,
20
- object: ObjectType
21
- };
22
-
23
- class Assertion {
24
- constructor(type, args) {
25
- this.type = type;
26
- this.args = args;
27
- }
28
-
29
- static parse(args, context) {
30
- if (args.length < 2) return context.error('Expected at least one argument.');
31
-
32
- let i = 1;
33
- let type;
34
-
35
- const name = args[0];
36
- if (name === 'array') {
37
- let itemType;
38
- if (args.length > 2) {
39
- const type = args[1];
40
- if (typeof type !== 'string' || !(type in types) || type === 'object')
41
- return context.error('The item type argument of "array" must be one of string, number, boolean', 1);
42
- itemType = types[type];
43
- i++;
44
- } else {
45
- itemType = ValueType;
46
- }
47
-
48
- let N;
49
- if (args.length > 3) {
50
- if (args[2] !== null && (typeof args[2] !== 'number' || args[2] < 0 || args[2] !== Math.floor(args[2]))) {
51
- return context.error('The length argument to "array" must be a positive integer literal', 2);
52
- }
53
- N = args[2];
54
- i++;
55
- }
56
-
57
- type = array(itemType, N);
58
- } else {
59
- assert(types[name], name);
60
- type = types[name];
61
- }
62
-
63
- const parsed = [];
64
- for (; i < args.length; i++) {
65
- const input = context.parse(args[i], i, ValueType);
66
- if (!input) return null;
67
- parsed.push(input);
68
- }
69
-
70
- return new Assertion(type, parsed);
71
- }
72
-
73
- evaluate(ctx) {
74
- for (let i = 0; i < this.args.length; i++) {
75
- const value = this.args[i].evaluate(ctx);
76
- const error = checkSubtype(this.type, typeOf(value));
77
- if (!error) {
78
- return value;
79
- }
80
- if (i === this.args.length - 1) {
81
- throw new RuntimeError(
82
- `Expected value to be of type ${toString(this.type)}, but found ${toString(typeOf(value))} instead.`
83
- );
84
- }
85
- }
86
-
87
- assert(false);
88
- return null;
89
- }
90
-
91
- eachChild(fn) {
92
- this.args.forEach(fn);
93
- }
94
-
95
- possibleOutputs() {
96
- return [].concat(...this.args.map(arg => arg.possibleOutputs()));
97
- }
98
-
99
- serialize() {
100
- const type = this.type;
101
- const serialized = [type.kind];
102
- if (type.kind === 'array') {
103
- const itemType = type.itemType;
104
- if (itemType.kind === 'string' || itemType.kind === 'number' || itemType.kind === 'boolean') {
105
- serialized.push(itemType.kind);
106
- const N = type.N;
107
- if (typeof N === 'number' || this.args.length > 1) {
108
- serialized.push(N);
109
- }
110
- }
111
- }
112
- return serialized.concat(this.args.map(arg => arg.serialize()));
113
- }
114
- }
115
-
116
- module.exports = Assertion;