@mapwhit/tilerenderer 0.50.0 → 0.51.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 (187) 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.txt → _prelude.fragment.glsl.js} +2 -1
  4. package/build/min/src/shaders/{_prelude.vertex.glsl.txt → _prelude.vertex.glsl.js} +2 -2
  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.txt → circle.fragment.glsl.js} +2 -2
  10. package/build/min/src/shaders/{circle.vertex.glsl.txt → circle.vertex.glsl.js} +2 -2
  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.txt → fill.fragment.glsl.js} +2 -2
  20. package/build/min/src/shaders/{fill.vertex.glsl.txt → fill.vertex.glsl.js} +2 -2
  21. package/build/min/src/shaders/fill_extrusion.fragment.glsl.js +5 -0
  22. package/build/min/src/shaders/{fill_extrusion.vertex.glsl.txt → fill_extrusion.vertex.glsl.js} +2 -2
  23. package/build/min/src/shaders/{fill_extrusion_pattern.fragment.glsl.txt → fill_extrusion_pattern.fragment.glsl.js} +2 -2
  24. package/build/min/src/shaders/{fill_extrusion_pattern.vertex.glsl.txt → fill_extrusion_pattern.vertex.glsl.js} +2 -2
  25. package/build/min/src/shaders/{fill_outline.fragment.glsl.txt → fill_outline.fragment.glsl.js} +2 -2
  26. package/build/min/src/shaders/{fill_outline.vertex.glsl.txt → fill_outline.vertex.glsl.js} +2 -2
  27. package/build/min/src/shaders/{fill_outline_pattern.fragment.glsl.txt → fill_outline_pattern.fragment.glsl.js} +2 -2
  28. package/build/min/src/shaders/{fill_outline_pattern.vertex.glsl.txt → fill_outline_pattern.vertex.glsl.js} +2 -2
  29. package/build/min/src/shaders/{fill_pattern.fragment.glsl.txt → fill_pattern.fragment.glsl.js} +2 -2
  30. package/build/min/src/shaders/{fill_pattern.vertex.glsl.txt → fill_pattern.vertex.glsl.js} +2 -2
  31. package/build/min/src/shaders/{heatmap.fragment.glsl.txt → heatmap.fragment.glsl.js} +2 -2
  32. package/build/min/src/shaders/{heatmap.vertex.glsl.txt → heatmap.vertex.glsl.js} +2 -2
  33. package/build/min/src/shaders/heatmap_texture.fragment.glsl.js +5 -0
  34. package/build/min/src/shaders/heatmap_texture.vertex.glsl.js +1 -0
  35. package/build/min/src/shaders/{hillshade.fragment.glsl.txt → hillshade.fragment.glsl.js} +2 -2
  36. package/build/min/src/shaders/hillshade.vertex.glsl.js +1 -0
  37. package/build/min/src/shaders/{hillshade_prepare.fragment.glsl.txt → hillshade_prepare.fragment.glsl.js} +2 -2
  38. package/build/min/src/shaders/hillshade_prepare.vertex.glsl.js +1 -0
  39. package/build/min/src/shaders/{line.fragment.glsl.txt → line.fragment.glsl.js} +2 -2
  40. package/build/min/src/shaders/{line.vertex.glsl.txt → line.vertex.glsl.js} +2 -2
  41. package/build/min/src/shaders/{line_gradient.fragment.glsl.txt → line_gradient.fragment.glsl.js} +2 -2
  42. package/build/min/src/shaders/{line_gradient.vertex.glsl.txt → line_gradient.vertex.glsl.js} +2 -2
  43. package/build/min/src/shaders/{line_pattern.fragment.glsl.txt → line_pattern.fragment.glsl.js} +2 -2
  44. package/build/min/src/shaders/{line_pattern.vertex.glsl.txt → line_pattern.vertex.glsl.js} +2 -2
  45. package/build/min/src/shaders/{line_sdf.fragment.glsl.txt → line_sdf.fragment.glsl.js} +2 -2
  46. package/build/min/src/shaders/{line_sdf.vertex.glsl.txt → line_sdf.vertex.glsl.js} +2 -2
  47. package/build/min/src/shaders/raster.fragment.glsl.js +5 -0
  48. package/build/min/src/shaders/raster.vertex.glsl.js +1 -0
  49. package/build/min/src/shaders/{symbol_icon.fragment.glsl.txt → symbol_icon.fragment.glsl.js} +2 -2
  50. package/build/min/src/shaders/{symbol_icon.vertex.glsl.txt → symbol_icon.vertex.glsl.js} +2 -2
  51. package/build/min/src/shaders/{symbol_sdf.fragment.glsl.txt → symbol_sdf.fragment.glsl.js} +2 -2
  52. package/build/min/src/shaders/{symbol_sdf.vertex.glsl.txt → symbol_sdf.vertex.glsl.js} +2 -2
  53. package/package.json +14 -10
  54. package/src/data/array_types.js +1 -1
  55. package/src/data/bucket/fill_bucket.js +1 -1
  56. package/src/data/bucket/fill_extrusion_bucket.js +2 -2
  57. package/src/data/bucket/line_bucket.js +1 -1
  58. package/src/data/bucket/symbol_bucket.js +3 -3
  59. package/src/data/feature_index.js +1 -1
  60. package/src/data/program_configuration.js +1 -1
  61. package/src/geo/transform.js +1 -1
  62. package/src/gl/color_mode.js +1 -1
  63. package/src/gl/value.js +1 -1
  64. package/src/index.js +2 -2
  65. package/src/render/draw_debug.js +1 -1
  66. package/src/render/draw_fill.js +1 -1
  67. package/src/render/draw_heatmap.js +1 -1
  68. package/src/render/glyph_manager.js +6 -130
  69. package/src/render/painter.js +1 -1
  70. package/src/render/uniform_binding.js +1 -1
  71. package/src/shaders/index.js +50 -50
  72. package/src/source/geojson_source.js +1 -1
  73. package/src/source/geojson_worker_source.js +4 -4
  74. package/src/source/geojson_wrapper.js +35 -27
  75. package/src/source/image_source.js +2 -2
  76. package/src/source/raster_tile_source.js +1 -1
  77. package/src/source/resources/glyphs.js +73 -0
  78. package/src/source/resources/images.js +68 -0
  79. package/src/source/resources/index.js +22 -0
  80. package/src/source/rtl_text_plugin.js +1 -1
  81. package/src/source/source_cache.js +2 -2
  82. package/src/source/tile.js +1 -1
  83. package/src/source/vector_tile_source.js +1 -1
  84. package/src/source/vector_tile_worker_source.js +5 -5
  85. package/src/source/worker.js +6 -5
  86. package/src/source/worker_tile.js +4 -4
  87. package/src/style/light.js +1 -1
  88. package/src/style/properties.js +1 -2
  89. package/src/style/query_utils.js +1 -1
  90. package/src/style/style.js +4 -4
  91. package/src/style/style_layer/circle_style_layer.js +1 -1
  92. package/src/style/style_layer/fill_extrusion_style_layer.js +1 -1
  93. package/src/style/style_layer/line_style_layer.js +1 -1
  94. package/src/style/style_layer/symbol_style_layer.js +1 -1
  95. package/src/style/style_layer.js +2 -2
  96. package/src/style-spec/feature_filter/index.js +43 -34
  97. package/src/style-spec/group_by_layout.js +10 -32
  98. package/src/symbol/anchor.js +1 -1
  99. package/src/symbol/clip_line.js +1 -1
  100. package/src/symbol/collision_feature.js +1 -1
  101. package/src/symbol/collision_index.js +1 -1
  102. package/src/symbol/mergelines.js +0 -2
  103. package/src/symbol/projection.js +1 -1
  104. package/src/symbol/quads.js +1 -1
  105. package/src/symbol/symbol_layout.js +0 -1
  106. package/src/symbol/symbol_size.js +1 -1
  107. package/src/symbol/transform_text.js +0 -1
  108. package/src/ui/camera.js +2 -2
  109. package/src/ui/map.js +11 -41
  110. package/src/util/browser.js +3 -18
  111. package/src/util/classify_rings.js +1 -1
  112. package/src/util/config.js +1 -1
  113. package/src/util/dom.js +0 -88
  114. package/src/util/find_pole_of_inaccessibility.js +3 -3
  115. package/src/util/intersection_tests.js +1 -1
  116. package/src/util/web_worker_transfer.js +4 -4
  117. package/src/worker.js +4 -0
  118. package/build/min/src/shaders/background.fragment.glsl.txt +0 -5
  119. package/build/min/src/shaders/background.vertex.glsl.txt +0 -1
  120. package/build/min/src/shaders/background_pattern.fragment.glsl.txt +0 -5
  121. package/build/min/src/shaders/background_pattern.vertex.glsl.txt +0 -1
  122. package/build/min/src/shaders/clipping_mask.fragment.glsl.txt +0 -1
  123. package/build/min/src/shaders/clipping_mask.vertex.glsl.txt +0 -1
  124. package/build/min/src/shaders/collision_box.fragment.glsl.txt +0 -1
  125. package/build/min/src/shaders/collision_box.vertex.glsl.txt +0 -1
  126. package/build/min/src/shaders/collision_circle.fragment.glsl.txt +0 -1
  127. package/build/min/src/shaders/collision_circle.vertex.glsl.txt +0 -1
  128. package/build/min/src/shaders/debug.fragment.glsl.txt +0 -1
  129. package/build/min/src/shaders/debug.vertex.glsl.txt +0 -1
  130. package/build/min/src/shaders/fill_extrusion.fragment.glsl.txt +0 -5
  131. package/build/min/src/shaders/heatmap_texture.fragment.glsl.txt +0 -5
  132. package/build/min/src/shaders/heatmap_texture.vertex.glsl.txt +0 -1
  133. package/build/min/src/shaders/hillshade.vertex.glsl.txt +0 -1
  134. package/build/min/src/shaders/hillshade_prepare.vertex.glsl.txt +0 -1
  135. package/build/min/src/shaders/raster.fragment.glsl.txt +0 -5
  136. package/build/min/src/shaders/raster.vertex.glsl.txt +0 -1
  137. package/src/style/load_glyph_range.js +0 -17
  138. package/src/style-spec/expression/compound_expression.js +0 -132
  139. package/src/style-spec/expression/definitions/assertion.js +0 -116
  140. package/src/style-spec/expression/definitions/at.js +0 -57
  141. package/src/style-spec/expression/definitions/case.js +0 -73
  142. package/src/style-spec/expression/definitions/coalesce.js +0 -66
  143. package/src/style-spec/expression/definitions/coercion.js +0 -120
  144. package/src/style-spec/expression/definitions/collator.js +0 -80
  145. package/src/style-spec/expression/definitions/comparison.js +0 -193
  146. package/src/style-spec/expression/definitions/format.js +0 -97
  147. package/src/style-spec/expression/definitions/index.js +0 -339
  148. package/src/style-spec/expression/definitions/interpolate.js +0 -245
  149. package/src/style-spec/expression/definitions/length.js +0 -54
  150. package/src/style-spec/expression/definitions/let.js +0 -60
  151. package/src/style-spec/expression/definitions/literal.js +0 -69
  152. package/src/style-spec/expression/definitions/match.js +0 -142
  153. package/src/style-spec/expression/definitions/step.js +0 -116
  154. package/src/style-spec/expression/definitions/var.js +0 -38
  155. package/src/style-spec/expression/evaluation_context.js +0 -38
  156. package/src/style-spec/expression/index.js +0 -330
  157. package/src/style-spec/expression/is_constant.js +0 -63
  158. package/src/style-spec/expression/parsing_context.js +0 -221
  159. package/src/style-spec/expression/parsing_error.js +0 -9
  160. package/src/style-spec/expression/runtime_error.js +0 -12
  161. package/src/style-spec/expression/scope.js +0 -34
  162. package/src/style-spec/expression/stops.js +0 -37
  163. package/src/style-spec/expression/types/collator.js +0 -24
  164. package/src/style-spec/expression/types/formatted.js +0 -39
  165. package/src/style-spec/expression/types.js +0 -88
  166. package/src/style-spec/expression/values.js +0 -149
  167. package/src/style-spec/function/convert.js +0 -240
  168. package/src/style-spec/function/index.js +0 -303
  169. package/src/style-spec/util/color.js +0 -73
  170. package/src/style-spec/util/color_spaces.js +0 -128
  171. package/src/style-spec/util/get_type.js +0 -18
  172. package/src/style-spec/util/interpolate.js +0 -21
  173. package/src/style-spec/util/properties.js +0 -17
  174. package/src/style-spec/util/result.js +0 -19
  175. package/src/ui/anchor.js +0 -24
  176. package/src/ui/bind_handlers.js +0 -199
  177. package/src/ui/events.js +0 -210
  178. package/src/ui/handler/box_zoom.js +0 -151
  179. package/src/ui/handler/dblclick_zoom.js +0 -91
  180. package/src/ui/handler/drag_pan.js +0 -285
  181. package/src/ui/handler/drag_rotate.js +0 -290
  182. package/src/ui/handler/frame.js +0 -28
  183. package/src/ui/handler/inertia.js +0 -45
  184. package/src/ui/handler/keyboard.js +0 -148
  185. package/src/ui/handler/scroll_zoom.js +0 -284
  186. package/src/ui/handler/touch_zoom_rotate.js +0 -263
  187. package/src/util/evented.js +0 -182
@@ -1,303 +0,0 @@
1
- const colorSpaces = require('../util/color_spaces');
2
- const Color = require('../util/color');
3
- const getType = require('../util/get_type');
4
- const interpolate = require('../util/interpolate');
5
- const Interpolate = require('../expression/definitions/interpolate');
6
- const { Formatted } = require('../expression/types/formatted');
7
- const { supportsInterpolation } = require('../util/properties');
8
-
9
- module.exports = {
10
- isFunction,
11
- createFunction
12
- };
13
-
14
- function isFunction(value) {
15
- return typeof value === 'object' && value !== null && !Array.isArray(value);
16
- }
17
-
18
- function identityFunction(x) {
19
- return x;
20
- }
21
-
22
- function createFunction(parameters, propertySpec) {
23
- const isColor = propertySpec.type === 'color';
24
- const zoomAndFeatureDependent = parameters.stops && typeof parameters.stops[0][0] === 'object';
25
- const featureDependent = zoomAndFeatureDependent || parameters.property !== undefined;
26
- const zoomDependent = zoomAndFeatureDependent || !featureDependent;
27
- const type = parameters.type || (supportsInterpolation(propertySpec) ? 'exponential' : 'interval');
28
-
29
- if (isColor) {
30
- parameters = { ...parameters };
31
-
32
- if (parameters.stops) {
33
- parameters.stops = parameters.stops.map(stop => {
34
- return [stop[0], Color.parse(stop[1])];
35
- });
36
- }
37
-
38
- if (parameters.default) {
39
- parameters.default = Color.parse(parameters.default);
40
- } else {
41
- parameters.default = Color.parse(propertySpec.default);
42
- }
43
- }
44
-
45
- if (parameters.colorSpace && parameters.colorSpace !== 'rgb' && !colorSpaces[parameters.colorSpace]) {
46
- throw new Error(`Unknown color space: ${parameters.colorSpace}`);
47
- }
48
-
49
- let innerFun;
50
- let hashedStops;
51
- let categoricalKeyType;
52
- if (type === 'exponential') {
53
- innerFun = evaluateExponentialFunction;
54
- } else if (type === 'interval') {
55
- innerFun = evaluateIntervalFunction;
56
- } else if (type === 'categorical') {
57
- innerFun = evaluateCategoricalFunction;
58
-
59
- // For categorical functions, generate an Object as a hashmap of the stops for fast searching
60
- hashedStops = Object.create(null);
61
- for (const stop of parameters.stops) {
62
- hashedStops[stop[0]] = stop[1];
63
- }
64
-
65
- // Infer key type based on first stop key-- used to encforce strict type checking later
66
- categoricalKeyType = typeof parameters.stops[0][0];
67
- } else if (type === 'identity') {
68
- innerFun = evaluateIdentityFunction;
69
- } else {
70
- throw new Error(`Unknown function type "${type}"`);
71
- }
72
-
73
- if (zoomAndFeatureDependent) {
74
- const featureFunctions = {};
75
- const zoomStops = [];
76
- for (let s = 0; s < parameters.stops.length; s++) {
77
- const stop = parameters.stops[s];
78
- const zoom = stop[0].zoom;
79
- if (featureFunctions[zoom] === undefined) {
80
- featureFunctions[zoom] = {
81
- zoom: zoom,
82
- type: parameters.type,
83
- property: parameters.property,
84
- default: parameters.default,
85
- stops: []
86
- };
87
- zoomStops.push(zoom);
88
- }
89
- featureFunctions[zoom].stops.push([stop[0].value, stop[1]]);
90
- }
91
-
92
- const featureFunctionStops = [];
93
- for (const z of zoomStops) {
94
- featureFunctionStops.push([featureFunctions[z].zoom, createFunction(featureFunctions[z], propertySpec)]);
95
- }
96
-
97
- return {
98
- kind: 'composite',
99
- interpolationFactor: Interpolate.interpolationFactor.bind(undefined, { name: 'linear' }),
100
- zoomStops: featureFunctionStops.map(s => s[0]),
101
- evaluate({ zoom }, properties) {
102
- return evaluateExponentialFunction(
103
- {
104
- stops: featureFunctionStops,
105
- base: parameters.base
106
- },
107
- propertySpec,
108
- zoom
109
- ).evaluate(zoom, properties);
110
- }
111
- };
112
- }
113
- if (zoomDependent) {
114
- return {
115
- kind: 'camera',
116
- interpolationFactor:
117
- type === 'exponential'
118
- ? Interpolate.interpolationFactor.bind(undefined, {
119
- name: 'exponential',
120
- base: parameters.base !== undefined ? parameters.base : 1
121
- })
122
- : () => 0,
123
- zoomStops: parameters.stops.map(s => s[0]),
124
- evaluate: ({ zoom }) => innerFun(parameters, propertySpec, zoom, hashedStops, categoricalKeyType)
125
- };
126
- }
127
- return {
128
- kind: 'source',
129
- evaluate(_, feature) {
130
- const value = feature?.properties ? feature.properties[parameters.property] : undefined;
131
- if (value === undefined) {
132
- return coalesce(parameters.default, propertySpec.default);
133
- }
134
- return innerFun(parameters, propertySpec, value, hashedStops, categoricalKeyType);
135
- }
136
- };
137
- }
138
-
139
- function coalesce(a, b, c) {
140
- if (a !== undefined) return a;
141
- if (b !== undefined) return b;
142
- if (c !== undefined) return c;
143
- }
144
-
145
- function evaluateCategoricalFunction(parameters, propertySpec, input, hashedStops, keyType) {
146
- const evaluated = typeof input === keyType ? hashedStops[input] : undefined; // Enforce strict typing on input
147
- return coalesce(evaluated, parameters.default, propertySpec.default);
148
- }
149
-
150
- function evaluateIntervalFunction(parameters, propertySpec, input) {
151
- // Edge cases
152
- if (getType(input) !== 'number') return coalesce(parameters.default, propertySpec.default);
153
- const n = parameters.stops.length;
154
- if (n === 1) return parameters.stops[0][1];
155
- if (input <= parameters.stops[0][0]) return parameters.stops[0][1];
156
- if (input >= parameters.stops[n - 1][0]) return parameters.stops[n - 1][1];
157
-
158
- const index = findStopLessThanOrEqualTo(parameters.stops, input);
159
-
160
- return parameters.stops[index][1];
161
- }
162
-
163
- function evaluateExponentialFunction(parameters, propertySpec, input) {
164
- const base = parameters.base !== undefined ? parameters.base : 1;
165
-
166
- // Edge cases
167
- if (getType(input) !== 'number') return coalesce(parameters.default, propertySpec.default);
168
- const n = parameters.stops.length;
169
- if (n === 1) return parameters.stops[0][1];
170
- if (input <= parameters.stops[0][0]) return parameters.stops[0][1];
171
- if (input >= parameters.stops[n - 1][0]) return parameters.stops[n - 1][1];
172
-
173
- const index = findStopLessThanOrEqualTo(parameters.stops, input);
174
- const t = interpolationFactor(input, base, parameters.stops[index][0], parameters.stops[index + 1][0]);
175
-
176
- const outputLower = parameters.stops[index][1];
177
- const outputUpper = parameters.stops[index + 1][1];
178
- let interp = interpolate[propertySpec.type] || identityFunction;
179
-
180
- if (parameters.colorSpace && parameters.colorSpace !== 'rgb') {
181
- const colorspace = colorSpaces[parameters.colorSpace];
182
- interp = (a, b) => colorspace.reverse(colorspace.interpolate(colorspace.forward(a), colorspace.forward(b), t));
183
- }
184
-
185
- if (typeof outputLower.evaluate === 'function') {
186
- return {
187
- evaluate(...args) {
188
- const evaluatedLower = outputLower.evaluate.apply(undefined, args);
189
- const evaluatedUpper = outputUpper.evaluate.apply(undefined, args);
190
- // Special case for fill-outline-color, which has no spec default.
191
- if (evaluatedLower === undefined || evaluatedUpper === undefined) {
192
- return undefined;
193
- }
194
- return interp(evaluatedLower, evaluatedUpper, t);
195
- }
196
- };
197
- }
198
-
199
- return interp(outputLower, outputUpper, t);
200
- }
201
-
202
- function evaluateIdentityFunction(parameters, propertySpec, input) {
203
- switch (propertySpec.type) {
204
- case 'color':
205
- input = Color.parse(input);
206
- break;
207
- case 'formatted':
208
- input = Formatted.fromString(input.toString());
209
- break;
210
- case 'enum':
211
- if (!propertySpec.values.includes(input)) {
212
- input = undefined;
213
- }
214
- break;
215
- default:
216
- if (getType(input) !== propertySpec.type) {
217
- input = undefined;
218
- }
219
- }
220
- return coalesce(input, parameters.default, propertySpec.default);
221
- }
222
-
223
- /**
224
- * Returns the index of the last stop <= input, or 0 if it doesn't exist.
225
- *
226
- * @private
227
- */
228
- function findStopLessThanOrEqualTo(stops, input) {
229
- const n = stops.length;
230
- let lowerIndex = 0;
231
- let upperIndex = n - 1;
232
- let currentIndex = 0;
233
- let currentValue;
234
- let upperValue;
235
-
236
- while (lowerIndex <= upperIndex) {
237
- currentIndex = Math.floor((lowerIndex + upperIndex) / 2);
238
- currentValue = stops[currentIndex][0];
239
- upperValue = stops[currentIndex + 1][0];
240
- if (input === currentValue || (input > currentValue && input < upperValue)) {
241
- // Search complete
242
- return currentIndex;
243
- }
244
- if (currentValue < input) {
245
- lowerIndex = currentIndex + 1;
246
- } else if (currentValue > input) {
247
- upperIndex = currentIndex - 1;
248
- }
249
- }
250
-
251
- return Math.max(currentIndex - 1, 0);
252
- }
253
-
254
- /**
255
- * Returns a ratio that can be used to interpolate between exponential function
256
- * stops.
257
- *
258
- * How it works:
259
- * Two consecutive stop values define a (scaled and shifted) exponential
260
- * function `f(x) = a * base^x + b`, where `base` is the user-specified base,
261
- * and `a` and `b` are constants affording sufficient degrees of freedom to fit
262
- * the function to the given stops.
263
- *
264
- * Here's a bit of algebra that lets us compute `f(x)` directly from the stop
265
- * values without explicitly solving for `a` and `b`:
266
- *
267
- * First stop value: `f(x0) = y0 = a * base^x0 + b`
268
- * Second stop value: `f(x1) = y1 = a * base^x1 + b`
269
- * => `y1 - y0 = a(base^x1 - base^x0)`
270
- * => `a = (y1 - y0)/(base^x1 - base^x0)`
271
- *
272
- * Desired value: `f(x) = y = a * base^x + b`
273
- * => `f(x) = y0 + a * (base^x - base^x0)`
274
- *
275
- * From the above, we can replace the `a` in `a * (base^x - base^x0)` and do a
276
- * little algebra:
277
- * ```
278
- * a * (base^x - base^x0) = (y1 - y0)/(base^x1 - base^x0) * (base^x - base^x0)
279
- * = (y1 - y0) * (base^x - base^x0) / (base^x1 - base^x0)
280
- * ```
281
- *
282
- * If we let `(base^x - base^x0) / (base^x1 base^x0)`, then we have
283
- * `f(x) = y0 + (y1 - y0) * ratio`. In other words, `ratio` may be treated as
284
- * an interpolation factor between the two stops' output values.
285
- *
286
- * (Note: a slightly different form for `ratio`,
287
- * `(base^(x-x0) - 1) / (base^(x1-x0) - 1) `, is equivalent, but requires fewer
288
- * expensive `Math.pow()` operations.)
289
- *
290
- * @private
291
- */
292
- function interpolationFactor(input, base, lowerValue, upperValue) {
293
- const difference = upperValue - lowerValue;
294
- const progress = input - lowerValue;
295
-
296
- if (difference === 0) {
297
- return 0;
298
- }
299
- if (base === 1) {
300
- return progress / difference;
301
- }
302
- return (base ** progress - 1) / (base ** difference - 1);
303
- }
@@ -1,73 +0,0 @@
1
- const { parseCSSColor } = require('csscolorparser');
2
-
3
- /**
4
- * An RGBA color value. Create instances from color strings using the static
5
- * method `Color.parse`. The constructor accepts RGB channel values in the range
6
- * `[0, 1]`, premultiplied by A.
7
- *
8
- * @param {number} r The red channel.
9
- * @param {number} g The green channel.
10
- * @param {number} b The blue channel.
11
- * @param {number} a The alpha channel.
12
- * @private
13
- */
14
- class Color {
15
- constructor(r, g, b, a = 1) {
16
- this.r = r;
17
- this.g = g;
18
- this.b = b;
19
- this.a = a;
20
- }
21
-
22
- /**
23
- * Parses valid CSS color strings and returns a `Color` instance.
24
- * @returns A `Color` instance, or `undefined` if the input is not a valid color string.
25
- */
26
- static parse(input) {
27
- if (!input) {
28
- return undefined;
29
- }
30
-
31
- if (input instanceof Color) {
32
- return input;
33
- }
34
-
35
- if (typeof input !== 'string') {
36
- return undefined;
37
- }
38
-
39
- const rgba = parseCSSColor(input);
40
- if (!rgba) {
41
- return undefined;
42
- }
43
-
44
- return new Color((rgba[0] / 255) * rgba[3], (rgba[1] / 255) * rgba[3], (rgba[2] / 255) * rgba[3], rgba[3]);
45
- }
46
-
47
- /**
48
- * Returns an RGBA string representing the color value.
49
- *
50
- * @returns An RGBA string.
51
- * @example
52
- * var purple = new Color.parse('purple');
53
- * purple.toString; // = "rgba(128,0,128,1)"
54
- * var translucentGreen = new Color.parse('rgba(26, 207, 26, .73)');
55
- * translucentGreen.toString(); // = "rgba(26,207,26,0.73)"
56
- */
57
- toString() {
58
- const [r, g, b, a] = this.toArray();
59
- return `rgba(${Math.round(r)},${Math.round(g)},${Math.round(b)},${a})`;
60
- }
61
-
62
- toArray() {
63
- const { r, g, b, a } = this;
64
- return a === 0 ? [0, 0, 0, 0] : [(r * 255) / a, (g * 255) / a, (b * 255) / a, a];
65
- }
66
- }
67
-
68
- Color.black = new Color(0, 0, 0, 1);
69
- Color.white = new Color(1, 1, 1, 1);
70
- Color.transparent = new Color(0, 0, 0, 0);
71
- Color.red = new Color(1, 0, 0, 1);
72
-
73
- module.exports = Color;
@@ -1,128 +0,0 @@
1
- const Color = require('./color');
2
-
3
- const { number: interpolateNumber } = require('./interpolate');
4
-
5
- // Constants
6
- const Xn = 0.95047; // D65 standard referent
7
- const Yn = 1;
8
- const Zn = 1.08883;
9
- const t0 = 4 / 29;
10
- const t1 = 6 / 29;
11
- const t2 = 3 * t1 * t1;
12
- const t3 = t1 * t1 * t1;
13
- const deg2rad = Math.PI / 180;
14
- const rad2deg = 180 / Math.PI;
15
-
16
- // Utilities
17
- function xyz2lab(t) {
18
- return t > t3 ? t ** (1 / 3) : t / t2 + t0;
19
- }
20
-
21
- function lab2xyz(t) {
22
- return t > t1 ? t * t * t : t2 * (t - t0);
23
- }
24
-
25
- function xyz2rgb(x) {
26
- return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * x ** (1 / 2.4) - 0.055);
27
- }
28
-
29
- function rgb2xyz(x) {
30
- x /= 255;
31
- return x <= 0.04045 ? x / 12.92 : ((x + 0.055) / 1.055) ** 2.4;
32
- }
33
-
34
- // LAB
35
- function rgbToLab(rgbColor) {
36
- const b = rgb2xyz(rgbColor.r);
37
- const a = rgb2xyz(rgbColor.g);
38
- const l = rgb2xyz(rgbColor.b);
39
- const x = xyz2lab((0.4124564 * b + 0.3575761 * a + 0.1804375 * l) / Xn);
40
- const y = xyz2lab((0.2126729 * b + 0.7151522 * a + 0.072175 * l) / Yn);
41
- const z = xyz2lab((0.0193339 * b + 0.119192 * a + 0.9503041 * l) / Zn);
42
-
43
- return {
44
- l: 116 * y - 16,
45
- a: 500 * (x - y),
46
- b: 200 * (y - z),
47
- alpha: rgbColor.a
48
- };
49
- }
50
-
51
- function labToRgb(labColor) {
52
- let y = (labColor.l + 16) / 116;
53
- let x = isNaN(labColor.a) ? y : y + labColor.a / 500;
54
- let z = isNaN(labColor.b) ? y : y - labColor.b / 200;
55
- y = Yn * lab2xyz(y);
56
- x = Xn * lab2xyz(x);
57
- z = Zn * lab2xyz(z);
58
- return new Color(
59
- xyz2rgb(3.2404542 * x - 1.5371385 * y - 0.4985314 * z), // D65 -> sRGB
60
- xyz2rgb(-0.969266 * x + 1.8760108 * y + 0.041556 * z),
61
- xyz2rgb(0.0556434 * x - 0.2040259 * y + 1.0572252 * z),
62
- labColor.alpha
63
- );
64
- }
65
-
66
- function interpolateLab(from, to, t) {
67
- return {
68
- l: interpolateNumber(from.l, to.l, t),
69
- a: interpolateNumber(from.a, to.a, t),
70
- b: interpolateNumber(from.b, to.b, t),
71
- alpha: interpolateNumber(from.alpha, to.alpha, t)
72
- };
73
- }
74
-
75
- // HCL
76
- function rgbToHcl(rgbColor) {
77
- const { l, a, b } = rgbToLab(rgbColor);
78
- const h = Math.atan2(b, a) * rad2deg;
79
- return {
80
- h: h < 0 ? h + 360 : h,
81
- c: Math.sqrt(a * a + b * b),
82
- l: l,
83
- alpha: rgbColor.a
84
- };
85
- }
86
-
87
- function hclToRgb(hclColor) {
88
- const h = hclColor.h * deg2rad;
89
- const c = hclColor.c;
90
- const l = hclColor.l;
91
- return labToRgb({
92
- l: l,
93
- a: Math.cos(h) * c,
94
- b: Math.sin(h) * c,
95
- alpha: hclColor.alpha
96
- });
97
- }
98
-
99
- function interpolateHue(a, b, t) {
100
- const d = b - a;
101
- return a + t * (d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d);
102
- }
103
-
104
- function interpolateHcl(from, to, t) {
105
- return {
106
- h: interpolateHue(from.h, to.h, t),
107
- c: interpolateNumber(from.c, to.c, t),
108
- l: interpolateNumber(from.l, to.l, t),
109
- alpha: interpolateNumber(from.alpha, to.alpha, t)
110
- };
111
- }
112
-
113
- const lab = {
114
- forward: rgbToLab,
115
- reverse: labToRgb,
116
- interpolate: interpolateLab
117
- };
118
-
119
- const hcl = {
120
- forward: rgbToHcl,
121
- reverse: hclToRgb,
122
- interpolate: interpolateHcl
123
- };
124
-
125
- module.exports = {
126
- lab,
127
- hcl
128
- };
@@ -1,18 +0,0 @@
1
- module.exports = function getType(val) {
2
- if (val instanceof Number) {
3
- return 'number';
4
- }
5
- if (val instanceof String) {
6
- return 'string';
7
- }
8
- if (val instanceof Boolean) {
9
- return 'boolean';
10
- }
11
- if (Array.isArray(val)) {
12
- return 'array';
13
- }
14
- if (val === null) {
15
- return 'null';
16
- }
17
- return typeof val;
18
- };
@@ -1,21 +0,0 @@
1
- const Color = require('./color');
2
-
3
- function number(a, b, t) {
4
- return a * (1 - t) + b * t;
5
- }
6
-
7
- function color(from, to, t) {
8
- return new Color(number(from.r, to.r, t), number(from.g, to.g, t), number(from.b, to.b, t), number(from.a, to.a, t));
9
- }
10
-
11
- function array(from, to, t) {
12
- return from.map((d, i) => {
13
- return number(d, to[i], t);
14
- });
15
- }
16
-
17
- module.exports = {
18
- number,
19
- color,
20
- array
21
- };
@@ -1,17 +0,0 @@
1
- function supportsPropertyExpression({ ['property-type']: propertyType }) {
2
- return propertyType === 'data-driven' || propertyType === 'cross-faded-data-driven';
3
- }
4
-
5
- function supportsZoomExpression(spec) {
6
- return !!spec.expression?.parameters.includes('zoom');
7
- }
8
-
9
- function supportsInterpolation(spec) {
10
- return !!spec.expression?.interpolated;
11
- }
12
-
13
- module.exports = {
14
- supportsPropertyExpression,
15
- supportsZoomExpression,
16
- supportsInterpolation
17
- };
@@ -1,19 +0,0 @@
1
- /**
2
- * A type used for returning and propagating errors. The first element of the union
3
- * represents success and contains a value, and the second represents an error and
4
- * contains an error value.
5
- * @private
6
- */
7
-
8
- function success(value) {
9
- return { result: 'success', value };
10
- }
11
-
12
- function error(value) {
13
- return { result: 'error', value };
14
- }
15
-
16
- module.exports = {
17
- success,
18
- error
19
- };
package/src/ui/anchor.js DELETED
@@ -1,24 +0,0 @@
1
- const anchorTranslate = {
2
- center: 'translate(-50%,-50%)',
3
- top: 'translate(-50%,0)',
4
- 'top-left': 'translate(0,0)',
5
- 'top-right': 'translate(-100%,0)',
6
- bottom: 'translate(-50%,-100%)',
7
- 'bottom-left': 'translate(0,-100%)',
8
- 'bottom-right': 'translate(-100%,-100%)',
9
- left: 'translate(0,-50%)',
10
- right: 'translate(-100%,-50%)'
11
- };
12
-
13
- function applyAnchorClass(element, anchor, prefix) {
14
- const classList = element.classList;
15
- for (const key in anchorTranslate) {
16
- classList.remove(`mapboxgl-${prefix}-anchor-${key}`);
17
- }
18
- classList.add(`mapboxgl-${prefix}-anchor-${anchor}`);
19
- }
20
-
21
- module.exports = {
22
- anchorTranslate,
23
- applyAnchorClass
24
- };