@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,299 +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 { supportsInterpolation } = require('../util/properties');
7
-
8
- module.exports = {
9
- isFunction,
10
- createFunction
11
- };
12
-
13
- function isFunction(value) {
14
- return typeof value === 'object' && value !== null && !Array.isArray(value);
15
- }
16
-
17
- function identityFunction(x) {
18
- return x;
19
- }
20
-
21
- function createFunction(parameters, propertySpec) {
22
- const isColor = propertySpec.type === 'color';
23
- const zoomAndFeatureDependent = parameters.stops && typeof parameters.stops[0][0] === 'object';
24
- const featureDependent = zoomAndFeatureDependent || parameters.property !== undefined;
25
- const zoomDependent = zoomAndFeatureDependent || !featureDependent;
26
- const type = parameters.type || (supportsInterpolation(propertySpec) ? 'exponential' : 'interval');
27
-
28
- if (isColor) {
29
- parameters = { ...parameters };
30
-
31
- if (parameters.stops) {
32
- parameters.stops = parameters.stops.map(stop => {
33
- return [stop[0], Color.parse(stop[1])];
34
- });
35
- }
36
-
37
- if (parameters.default) {
38
- parameters.default = Color.parse(parameters.default);
39
- } else {
40
- parameters.default = Color.parse(propertySpec.default);
41
- }
42
- }
43
-
44
- if (parameters.colorSpace && parameters.colorSpace !== 'rgb' && !colorSpaces[parameters.colorSpace]) {
45
- throw new Error(`Unknown color space: ${parameters.colorSpace}`);
46
- }
47
-
48
- let innerFun;
49
- let hashedStops;
50
- let categoricalKeyType;
51
- if (type === 'exponential') {
52
- innerFun = evaluateExponentialFunction;
53
- } else if (type === 'interval') {
54
- innerFun = evaluateIntervalFunction;
55
- } else if (type === 'categorical') {
56
- innerFun = evaluateCategoricalFunction;
57
-
58
- // For categorical functions, generate an Object as a hashmap of the stops for fast searching
59
- hashedStops = Object.create(null);
60
- for (const stop of parameters.stops) {
61
- hashedStops[stop[0]] = stop[1];
62
- }
63
-
64
- // Infer key type based on first stop key-- used to encforce strict type checking later
65
- categoricalKeyType = typeof parameters.stops[0][0];
66
- } else if (type === 'identity') {
67
- innerFun = evaluateIdentityFunction;
68
- } else {
69
- throw new Error(`Unknown function type "${type}"`);
70
- }
71
-
72
- if (zoomAndFeatureDependent) {
73
- const featureFunctions = {};
74
- const zoomStops = [];
75
- for (let s = 0; s < parameters.stops.length; s++) {
76
- const stop = parameters.stops[s];
77
- const zoom = stop[0].zoom;
78
- if (featureFunctions[zoom] === undefined) {
79
- featureFunctions[zoom] = {
80
- zoom: zoom,
81
- type: parameters.type,
82
- property: parameters.property,
83
- default: parameters.default,
84
- stops: []
85
- };
86
- zoomStops.push(zoom);
87
- }
88
- featureFunctions[zoom].stops.push([stop[0].value, stop[1]]);
89
- }
90
-
91
- const featureFunctionStops = [];
92
- for (const z of zoomStops) {
93
- featureFunctionStops.push([featureFunctions[z].zoom, createFunction(featureFunctions[z], propertySpec)]);
94
- }
95
-
96
- return {
97
- kind: 'composite',
98
- interpolationFactor: Interpolate.interpolationFactor.bind(undefined, { name: 'linear' }),
99
- zoomStops: featureFunctionStops.map(s => s[0]),
100
- evaluate({ zoom }, properties) {
101
- return evaluateExponentialFunction(
102
- {
103
- stops: featureFunctionStops,
104
- base: parameters.base
105
- },
106
- propertySpec,
107
- zoom
108
- ).evaluate(zoom, properties);
109
- }
110
- };
111
- }
112
- if (zoomDependent) {
113
- return {
114
- kind: 'camera',
115
- interpolationFactor:
116
- type === 'exponential'
117
- ? Interpolate.interpolationFactor.bind(undefined, {
118
- name: 'exponential',
119
- base: parameters.base !== undefined ? parameters.base : 1
120
- })
121
- : () => 0,
122
- zoomStops: parameters.stops.map(s => s[0]),
123
- evaluate: ({ zoom }) => innerFun(parameters, propertySpec, zoom, hashedStops, categoricalKeyType)
124
- };
125
- }
126
- return {
127
- kind: 'source',
128
- evaluate(_, feature) {
129
- const value = feature?.properties ? feature.properties[parameters.property] : undefined;
130
- if (value === undefined) {
131
- return coalesce(parameters.default, propertySpec.default);
132
- }
133
- return innerFun(parameters, propertySpec, value, hashedStops, categoricalKeyType);
134
- }
135
- };
136
- }
137
-
138
- function coalesce(a, b, c) {
139
- if (a !== undefined) return a;
140
- if (b !== undefined) return b;
141
- if (c !== undefined) return c;
142
- }
143
-
144
- function evaluateCategoricalFunction(parameters, propertySpec, input, hashedStops, keyType) {
145
- const evaluated = typeof input === keyType ? hashedStops[input] : undefined; // Enforce strict typing on input
146
- return coalesce(evaluated, parameters.default, propertySpec.default);
147
- }
148
-
149
- function evaluateIntervalFunction(parameters, propertySpec, input) {
150
- // Edge cases
151
- if (getType(input) !== 'number') return coalesce(parameters.default, propertySpec.default);
152
- const n = parameters.stops.length;
153
- if (n === 1) return parameters.stops[0][1];
154
- if (input <= parameters.stops[0][0]) return parameters.stops[0][1];
155
- if (input >= parameters.stops[n - 1][0]) return parameters.stops[n - 1][1];
156
-
157
- const index = findStopLessThanOrEqualTo(parameters.stops, input);
158
-
159
- return parameters.stops[index][1];
160
- }
161
-
162
- function evaluateExponentialFunction(parameters, propertySpec, input) {
163
- const base = parameters.base !== undefined ? parameters.base : 1;
164
-
165
- // Edge cases
166
- if (getType(input) !== 'number') return coalesce(parameters.default, propertySpec.default);
167
- const n = parameters.stops.length;
168
- if (n === 1) return parameters.stops[0][1];
169
- if (input <= parameters.stops[0][0]) return parameters.stops[0][1];
170
- if (input >= parameters.stops[n - 1][0]) return parameters.stops[n - 1][1];
171
-
172
- const index = findStopLessThanOrEqualTo(parameters.stops, input);
173
- const t = interpolationFactor(input, base, parameters.stops[index][0], parameters.stops[index + 1][0]);
174
-
175
- const outputLower = parameters.stops[index][1];
176
- const outputUpper = parameters.stops[index + 1][1];
177
- let interp = interpolate[propertySpec.type] || identityFunction;
178
-
179
- if (parameters.colorSpace && parameters.colorSpace !== 'rgb') {
180
- const colorspace = colorSpaces[parameters.colorSpace];
181
- interp = (a, b) => colorspace.reverse(colorspace.interpolate(colorspace.forward(a), colorspace.forward(b), t));
182
- }
183
-
184
- if (typeof outputLower.evaluate === 'function') {
185
- return {
186
- evaluate(...args) {
187
- const evaluatedLower = outputLower.evaluate.apply(undefined, args);
188
- const evaluatedUpper = outputUpper.evaluate.apply(undefined, args);
189
- // Special case for fill-outline-color, which has no spec default.
190
- if (evaluatedLower === undefined || evaluatedUpper === undefined) {
191
- return undefined;
192
- }
193
- return interp(evaluatedLower, evaluatedUpper, t);
194
- }
195
- };
196
- }
197
-
198
- return interp(outputLower, outputUpper, t);
199
- }
200
-
201
- function evaluateIdentityFunction(parameters, propertySpec, input) {
202
- switch (propertySpec.type) {
203
- case 'color':
204
- input = Color.parse(input);
205
- break;
206
- case 'enum':
207
- if (!propertySpec.values.includes(input)) {
208
- input = undefined;
209
- }
210
- break;
211
- default:
212
- if (getType(input) !== propertySpec.type) {
213
- input = undefined;
214
- }
215
- }
216
- return coalesce(input, parameters.default, propertySpec.default);
217
- }
218
-
219
- /**
220
- * Returns the index of the last stop <= input, or 0 if it doesn't exist.
221
- *
222
- * @private
223
- */
224
- function findStopLessThanOrEqualTo(stops, input) {
225
- const n = stops.length;
226
- let lowerIndex = 0;
227
- let upperIndex = n - 1;
228
- let currentIndex = 0;
229
- let currentValue;
230
- let upperValue;
231
-
232
- while (lowerIndex <= upperIndex) {
233
- currentIndex = Math.floor((lowerIndex + upperIndex) / 2);
234
- currentValue = stops[currentIndex][0];
235
- upperValue = stops[currentIndex + 1][0];
236
- if (input === currentValue || (input > currentValue && input < upperValue)) {
237
- // Search complete
238
- return currentIndex;
239
- }
240
- if (currentValue < input) {
241
- lowerIndex = currentIndex + 1;
242
- } else if (currentValue > input) {
243
- upperIndex = currentIndex - 1;
244
- }
245
- }
246
-
247
- return Math.max(currentIndex - 1, 0);
248
- }
249
-
250
- /**
251
- * Returns a ratio that can be used to interpolate between exponential function
252
- * stops.
253
- *
254
- * How it works:
255
- * Two consecutive stop values define a (scaled and shifted) exponential
256
- * function `f(x) = a * base^x + b`, where `base` is the user-specified base,
257
- * and `a` and `b` are constants affording sufficient degrees of freedom to fit
258
- * the function to the given stops.
259
- *
260
- * Here's a bit of algebra that lets us compute `f(x)` directly from the stop
261
- * values without explicitly solving for `a` and `b`:
262
- *
263
- * First stop value: `f(x0) = y0 = a * base^x0 + b`
264
- * Second stop value: `f(x1) = y1 = a * base^x1 + b`
265
- * => `y1 - y0 = a(base^x1 - base^x0)`
266
- * => `a = (y1 - y0)/(base^x1 - base^x0)`
267
- *
268
- * Desired value: `f(x) = y = a * base^x + b`
269
- * => `f(x) = y0 + a * (base^x - base^x0)`
270
- *
271
- * From the above, we can replace the `a` in `a * (base^x - base^x0)` and do a
272
- * little algebra:
273
- * ```
274
- * a * (base^x - base^x0) = (y1 - y0)/(base^x1 - base^x0) * (base^x - base^x0)
275
- * = (y1 - y0) * (base^x - base^x0) / (base^x1 - base^x0)
276
- * ```
277
- *
278
- * If we let `(base^x - base^x0) / (base^x1 base^x0)`, then we have
279
- * `f(x) = y0 + (y1 - y0) * ratio`. In other words, `ratio` may be treated as
280
- * an interpolation factor between the two stops' output values.
281
- *
282
- * (Note: a slightly different form for `ratio`,
283
- * `(base^(x-x0) - 1) / (base^(x1-x0) - 1) `, is equivalent, but requires fewer
284
- * expensive `Math.pow()` operations.)
285
- *
286
- * @private
287
- */
288
- function interpolationFactor(input, base, lowerValue, upperValue) {
289
- const difference = upperValue - lowerValue;
290
- const progress = input - lowerValue;
291
-
292
- if (difference === 0) {
293
- return 0;
294
- }
295
- if (base === 1) {
296
- return progress / difference;
297
- }
298
- return (base ** progress - 1) / (base ** difference - 1);
299
- }
@@ -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
- };