Leon4gr45 commited on
Commit
b593f0b
·
verified ·
1 Parent(s): e7b2eb4

Upload folder using huggingface_hub (part 9)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +2 -0
  2. node_modules/@plotly/mapbox-gl/src/style-spec/.eslintrc +5 -0
  3. node_modules/@plotly/mapbox-gl/src/style-spec/CHANGELOG.md +468 -0
  4. node_modules/@plotly/mapbox-gl/src/style-spec/README.md +59 -0
  5. node_modules/@plotly/mapbox-gl/src/style-spec/bin/gl-style-composite +9 -0
  6. node_modules/@plotly/mapbox-gl/src/style-spec/bin/gl-style-format +22 -0
  7. node_modules/@plotly/mapbox-gl/src/style-spec/bin/gl-style-migrate +9 -0
  8. node_modules/@plotly/mapbox-gl/src/style-spec/bin/gl-style-validate +50 -0
  9. node_modules/@plotly/mapbox-gl/src/style-spec/composite.js +50 -0
  10. node_modules/@plotly/mapbox-gl/src/style-spec/declass.js +42 -0
  11. node_modules/@plotly/mapbox-gl/src/style-spec/deref.js +52 -0
  12. node_modules/@plotly/mapbox-gl/src/style-spec/diff.js +393 -0
  13. node_modules/@plotly/mapbox-gl/src/style-spec/dist/.gitkeep +0 -0
  14. node_modules/@plotly/mapbox-gl/src/style-spec/empty.js +29 -0
  15. node_modules/@plotly/mapbox-gl/src/style-spec/error/parsing_error.js +16 -0
  16. node_modules/@plotly/mapbox-gl/src/style-spec/error/validation_error.js +18 -0
  17. node_modules/@plotly/mapbox-gl/src/style-spec/expression/compound_expression.js +162 -0
  18. node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/assertion.js +130 -0
  19. node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/at.js +70 -0
  20. node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/case.js +85 -0
  21. node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/coalesce.js +93 -0
  22. node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/coercion.js +133 -0
  23. node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/collator.js +78 -0
  24. node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/comparison.js +184 -0
  25. node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/format.js +144 -0
  26. node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/image.js +52 -0
  27. node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/in.js +72 -0
  28. node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/index.js +565 -0
  29. node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/index_of.js +89 -0
  30. node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/interpolate.js +267 -0
  31. node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/length.js +61 -0
  32. node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/let.js +72 -0
  33. node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/literal.js +77 -0
  34. node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/match.js +158 -0
  35. node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/number_format.js +142 -0
  36. node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/slice.js +86 -0
  37. node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/step.js +120 -0
  38. node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/var.js +46 -0
  39. node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/within.js +342 -0
  40. node_modules/@plotly/mapbox-gl/src/style-spec/expression/evaluation_context.js +59 -0
  41. node_modules/@plotly/mapbox-gl/src/style-spec/expression/expression.js +27 -0
  42. node_modules/@plotly/mapbox-gl/src/style-spec/expression/index.js +392 -0
  43. node_modules/@plotly/mapbox-gl/src/style-spec/expression/is_constant.js +59 -0
  44. node_modules/@plotly/mapbox-gl/src/style-spec/expression/parsing_context.js +233 -0
  45. node_modules/@plotly/mapbox-gl/src/style-spec/expression/parsing_error.js +13 -0
  46. node_modules/@plotly/mapbox-gl/src/style-spec/expression/runtime_error.js +17 -0
  47. node_modules/@plotly/mapbox-gl/src/style-spec/expression/scope.js +36 -0
  48. node_modules/@plotly/mapbox-gl/src/style-spec/expression/stops.js +39 -0
  49. node_modules/@plotly/mapbox-gl/src/style-spec/expression/types.js +126 -0
  50. node_modules/@plotly/mapbox-gl/src/style-spec/expression/types/collator.js +61 -0
.gitattributes CHANGED
@@ -40,3 +40,5 @@ node_modules/@plotly/d3-sankey/img/align-center.png filter=lfs diff=lfs merge=lf
40
  node_modules/@plotly/d3-sankey/img/align-left.png filter=lfs diff=lfs merge=lfs -text
41
  node_modules/@plotly/d3-sankey/img/align-right.png filter=lfs diff=lfs merge=lfs -text
42
  node_modules/@plotly/d3-sankey/img/energy.png filter=lfs diff=lfs merge=lfs -text
 
 
 
40
  node_modules/@plotly/d3-sankey/img/align-left.png filter=lfs diff=lfs merge=lfs -text
41
  node_modules/@plotly/d3-sankey/img/align-right.png filter=lfs diff=lfs merge=lfs -text
42
  node_modules/@plotly/d3-sankey/img/energy.png filter=lfs diff=lfs merge=lfs -text
43
+ node_modules/@rollup/rollup-linux-x64-gnu/rollup.linux-x64-gnu.node filter=lfs diff=lfs merge=lfs -text
44
+ node_modules/@rollup/rollup-linux-x64-musl/rollup.linux-x64-musl.node filter=lfs diff=lfs merge=lfs -text
node_modules/@plotly/mapbox-gl/src/style-spec/.eslintrc ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "rules": {
3
+ "flowtype/require-valid-file-annotation": [0]
4
+ }
5
+ }
node_modules/@plotly/mapbox-gl/src/style-spec/CHANGELOG.md ADDED
@@ -0,0 +1,468 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## 13.17.0
2
+
3
+ ### ✨ Features and improvements
4
+ * Add a `filter` option for GeoJSON sources to filter out features prior to processing (e.g. before clustering). [#9864](https://github.com/mapbox/mapbox-gl-js/pull/9864)
5
+
6
+ ## 13.16.0
7
+
8
+ ### ✨ Features and improvements
9
+ * Added `volatile` source property to control storing the tiles in local storage. ([9702](https://github.com/mapbox/mapbox-gl-js/pull/9702))
10
+
11
+ * Added `clusterMinPoints` option for clustered GeoJSON sources that defines the minimum number of points to form a cluster. ([#9748](https://github.com/mapbox/mapbox-gl-js/pull/9748))
12
+
13
+ ## 13.15.0
14
+
15
+ ### ✨ Features and improvements
16
+ * Add `distance` expression to `style-spec`. This expression returns the shortest distance between a feature and an input geometry ([#9655](https://github.com/mapbox/mapbox-gl-js/pull/9655))
17
+
18
+ ## 13.14.0
19
+
20
+ ### ✨ Features and improvements
21
+ * Add `index-of` and `slice` expressions to search arrays and strings for the first occurrence of a specified value and return a section of the original array or string ([#9450](https://github.com/mapbox/mapbox-gl-js/pull/9450)) (h/t [lbutler](https://github.com/lbutler))
22
+
23
+ ## 13.13.1
24
+
25
+ ### ✨ Features and improvements
26
+ * Expose `expression.isExpressionFilter(..)` from the bundle. ([#9530](https://github.com/mapbox/mapbox-gl-js/pull/9530))
27
+
28
+ ### 🐛 Bug fixes
29
+ * Fix a broken module import where the `style-spec` package was importing files from `mapbox-gl-js`, it's parent repo, causing downstream build systems to break. ([#9522](https://github.com/mapbox/mapbox-gl-js/pull/9522))
30
+
31
+ ## 13.13.0
32
+
33
+ ### ✨ Features and improvements
34
+ * Add `within` expression for testing whether an evaluated feature lies within a given GeoJSON object ([#9352](https://github.com/mapbox/mapbox-gl-js/pull/9352)). For example:<br>
35
+ `"icon-opacity": ["case", ["==", ["within", "some-polygon"], true], 1,
36
+ ["==", ["within", "some-polygon"], false], 0]`
37
+ * Improve scaling of patterns used in `line-pattern` on all device resolutions and pixel ratios ([#9266](https://github.com/mapbox/mapbox-gl-js/pull/9266))
38
+
39
+ ### 🐛 Bug fixes
40
+ * Allow needle argument to `in` expression to be false ([#9295](https://github.com/mapbox/mapbox-gl-js/pull/9295))
41
+ * Fix a bug where `icon-image` expression that evaluates to an empty string (`''`) produced a warning ([#9380](https://github.com/mapbox/mapbox-gl-js/pull/9380))
42
+ * Prevent exception resulting from `line-dash-array` of empty length ([#9385](https://github.com/mapbox/mapbox-gl-js/pull/9385))
43
+
44
+ ## 13.12.0
45
+
46
+ * Update `image` expression SDK support table ([#9228](https://github.com/mapbox/mapbox-gl-js/pull/9228))
47
+ * Fix `promoteId` for line layers ([#9210](https://github.com/mapbox/mapbox-gl-js/pull/9210), [#9212](https://github.com/mapbox/mapbox-gl-js/pull/9212))
48
+
49
+ ## 13.11.0
50
+
51
+ ### ✨ Features and improvements
52
+ * Add `promoteId` option to use a feature property as ID for feature state ([#8987](https://github.com/mapbox/mapbox-gl-js/pull/8987))
53
+ * Update `symbol-avoid-edges` documentation regarding global collision detection ([#9157](https://github.com/mapbox/mapbox-gl-js/pull/9157))
54
+ * Remove reference to `in` function which has been replaced by the `in` expression ([#9102](https://github.com/mapbox/mapbox-gl-js/pull/9102))
55
+
56
+ ### 🐛 Bug fixes
57
+ * Fix bug where `symbol-sort-key` was not used for collisions that crossed tile boundaries ([#9054](https://github.com/mapbox/mapbox-gl-js/pull/9054))
58
+
59
+ ## 13.10.2
60
+
61
+ ### 🐛 Bug fixes
62
+ * Fix style validation error messages not being displayed ([#9073](https://github.com/mapbox/mapbox-gl-js/pull/9073))
63
+
64
+ ## 13.10.0
65
+
66
+ ### ✨ Features and improvements
67
+ * Add ability to insert images into text labels using an `image` expression within a `format` expression: `"text-field": ["format", "Some text", ["image", "my-image"], "some more text"]` ([#8904](https://github.com/mapbox/mapbox-gl-js/pull/8904))
68
+ * Add `in` expression. It can check if a value is in an array (`["in", value, array]`) or a substring is in a string (`["in", substring, string]`) ([#8876](https://github.com/mapbox/mapbox-gl-js/pull/8876))
69
+ * Add support for stretchable images (aka nine-part or nine-patch images). Stretchable images can be used with `icon-text-fit` to draw resized images with unstretched corners and borders. ([#8997](https://github.com/mapbox/mapbox-gl-js/pull/8997))
70
+ * Add an es modules build of for mapbox-gl-style-spec in dist/ ([#8247](https://github.com/mapbox/mapbox-gl-js/pull/8247)) (h/t [ahocevar](https://github.com/ahocevar))
71
+
72
+ ## 13.9.1
73
+
74
+ ### ✨ Improvement
75
+ * Rename `Image` type to `ResolvedImage`, to better represent the result of an `image` expression evaluation. ([#8901](https://github.com/mapbox/mapbox-gl-js/pull/8901))
76
+
77
+ ## 13.9.0
78
+
79
+ * Add `image` expression operator to determine image availability ([#8684](https://github.com/mapbox/mapbox-gl-js/pull/8684))
80
+ * Add a style-spec function to validate that styles are compatible with the Mapbox API ([#8663](https://github.com/mapbox/mapbox-gl-js/pull/8663))
81
+
82
+ ## 13.8.0
83
+
84
+ - Introduce `text-writing-mode` symbol layer property to allow placing point labels vertically. [#8399](https://github.com/mapbox/mapbox-gl-js/pull/8399)
85
+ - Allow `text-color` to be used in formatted expressions to be able to draw different parts of a label in different colors. [#8068](https://github.com/mapbox/mapbox-gl-js/pull/8068)
86
+ - Improve conversion of legacy filters with duplicate values. [#8542](https://github.com/mapbox/mapbox-gl-js/pull/8542)
87
+
88
+ ## 13.7.2
89
+
90
+ ### 🐛 Bug fixes
91
+ * Fix SDK support spec section for variable label placement ([#8384](https://github.com/mapbox/mapbox-gl-js/pull/8384)) (h/t [@pozdnyakov](https://github.com/pozdnyakov))
92
+
93
+ ### ✨ Features and improvements
94
+ * Add SDK support spec section for text-radial-offset ([#8401](https://github.com/mapbox/mapbox-gl-js/pull/8401))
95
+ * Add `*-sort-key` layout property for circle, fill, line ([#8467](https://github.com/mapbox/mapbox-gl-js/pull/8467))
96
+ * Expose convertFilter API in the style specification ([#8493](https://github.com/mapbox/mapbox-gl-js/pull/8493))
97
+
98
+ ## 13.7.1
99
+
100
+ ### 🐛 Bug fixes
101
+ * Fix format expression options validation ([#8339](https://github.com/mapbox/mapbox-gl-js/pull/8339))
102
+ * Fix SDK support information for style properties added in v13.7.0: ([#8384](https://github.com/mapbox/mapbox-gl-js/pull/8384))
103
+ * Add missing SDK support section for `text-radial-offset` property
104
+ * Assign SDK versions for `text-variable-anchor` and `text-justify: auto`
105
+
106
+ ## 13.7.0
107
+
108
+ ### ✨ Features and improvements
109
+ * Add `text-radial-offset` style property ([#7596](https://github.com/mapbox/mapbox-gl-js/pull/7596))
110
+ * Add `text-variable-anchor` style property ([#7596](https://github.com/mapbox/mapbox-gl-js/pull/7596))
111
+ * Add `auto` value to `text-justify` style property ([#7596](https://github.com/mapbox/mapbox-gl-js/pull/7596))
112
+
113
+ ## 13.6.0
114
+
115
+ ### ✨ Features and improvements
116
+ * Add `clusterProperties` option for aggregated cluster properties ([#2412](https://github.com/mapbox/mapbox-gl-js/issues/2412), fixed by [#7584](https://github.com/mapbox/mapbox-gl-js/pull/7584))
117
+ * Add `number-format` expression ([#7626](https://github.com/mapbox/mapbox-gl-js/pull/7626))
118
+ * Add `symbol-sort-key` style property ([#7678](https://github.com/mapbox/mapbox-gl-js/pull/7678))
119
+
120
+ ## 13.5.0
121
+
122
+ ### Features and improvements
123
+ * Flattens `all` expressions in converted filters ([#7679](https://github.com/mapbox/mapbox-gl-js/pull/7679))
124
+ * Compatibility tables are updated ([#7574](https://github.com/mapbox/mapbox-gl-js/pull/7574))
125
+
126
+ ## 13.4.0
127
+
128
+ ### ✨ Features and improvements
129
+ * **Tighten style validation**
130
+ * Disallow expressions as stop values ([#7396](https://github.com/mapbox/mapbox-gl-js/pull/7396))
131
+ * Disallow `feature-state` expressions in filters ([#7366](https://github.com/mapbox/mapbox-gl-js/pull/7366))
132
+
133
+ ## 13.3.0
134
+
135
+ ### 🐛 Bug fixes
136
+ * **Expressions**
137
+ * Fix `let` expression stripping expected type during parsing ([#7300](https://github.com/mapbox/mapbox-gl-js/issues/7300), fixed by [#7301](https://github.com/mapbox/mapbox-gl-js/pull/7301))
138
+ * Fix superfluous wrapping of literals in `literal` expression ([#7336](https://github.com/mapbox/mapbox-gl-js/issues/7336), fixed by [#7337](https://github.com/mapbox/mapbox-gl-js/pull/7337))
139
+ * Allow calling `to-color` on values that are already of type `Color` ([#7260](https://github.com/mapbox/mapbox-gl-js/pull/7260))
140
+ * Fix `to-array` for empty arrays (([#7261](https://github.com/mapbox/mapbox-gl-js/pull/7261)))
141
+ * Fix identity functions for `text-field` when using formatted text ([#7351](https://github.com/mapbox/mapbox-gl-js/pull/7351))
142
+ * Fix coercion of `null` to `0` in `to-number` expression ([#7083](https://github.com/mapbox/mapbox-gl-js/issues/7083), fixed by [#7274](https://github.com/mapbox/mapbox-gl-js/pull/7274))
143
+
144
+ ### ✨ Features and improvements
145
+ * Add `fill-extrusion-vertical-gradient` property for controlling shading of fill extrusions ([#5768](https://github.com/mapbox/mapbox-gl-js/issues/5768), fixed by [#6841](https://github.com/mapbox/mapbox-gl-js/pull/6841))
146
+
147
+ ## 13.2.0
148
+
149
+ ### 🐛 Bug fixes
150
+ * Update the style-spec's old `gl-style-migrate` script to include conversion of legacy functions and filters to their expression equivalents ([#6927](https://github.com/mapbox/mapbox-gl-js/issues/6927), fixed by [#7095](https://github.com/mapbox/mapbox-gl-js/pull/7095))
151
+
152
+ ### ✨ Features and improvements
153
+ * Add `symbol-z-order` symbol layout property to style spec ([#7219](https://github.com/mapbox/mapbox-gl-js/pull/7219))
154
+ * Implement data-driven styling support for `*-pattern properties` ([#6289](https://github.com/mapbox/mapbox-gl-js/pull/6289))
155
+
156
+ ## 13.1.1
157
+
158
+ ### 🐛 Bug fixes
159
+ * Fix broken module import in mapboxgl-style-spec (v13.0.1) ([#6984](https://github.com/mapbox/mapbox-gl-js/issues/6984), fixed by [#6997](https://api.github.com/repos/mapbox/mapbox-gl-js/pulls/6997))
160
+
161
+ ### ✨ Features and improvements
162
+ * Improve formatting for style output ([#7029](https://github.com/mapbox/mapbox-gl-js/pull/7029))
163
+
164
+ ## 13.1.0
165
+
166
+ ### ✨ Features and improvements
167
+ * Add `raster-resampling` raster paint property ([#6411](https://github.com/mapbox/mapbox-gl-js/pull/6411)) (h/t [andrewharvey](https://github.com/andrewharvey))
168
+ * Add `symbol-placement: line-center` ([#6821](https://github.com/mapbox/mapbox-gl-js/pull/6821))
169
+
170
+ ## 13.0.1
171
+
172
+ ### ⚠️ Breaking changes
173
+ * Align implicit type behavior of `match` expressions with with `case/==` ([#6684](https://github.com/mapbox/mapbox-gl-js/pull/6684))
174
+ * Update spec so that documentation can automatically capture which functions and expressions can be used with which properties ([#6521](https://github.com/mapbox/mapbox-gl-js/pull/6521))
175
+
176
+ ### ✨ Features and improvements
177
+ * Add `feature-state` [#6263](https://github.com/mapbox/mapbox-gl-js/pull/6263)
178
+ * Add support for GeoJSON attribution ([#6364](https://github.com/mapbox/mapbox-gl-js/pull/6364)) (h/t [andrewharvey](https://github.com/andrewharvey))
179
+ * Upgrade to Flow 0.69 ([#6594](https://github.com/mapbox/mapbox-gl-js/pull/6594))
180
+
181
+ ### 🐛 Bug fixes
182
+ * Use named exports for style-spec entrypoint module ([#6601](https://github.com/mapbox/mapbox-gl-js/issues/6601)
183
+
184
+ ## 13.0.0
185
+ Malformed package published to NPM.
186
+
187
+ ## 12.0.0
188
+
189
+ ### ⚠️ Breaking changes
190
+ * The `"to-string"` expression operator now converts null to an empty string rather than to `"null"`. [#6534](https://github.com/mapbox/mapbox-gl-js/pull/6534)
191
+
192
+ ### ✨ Features and improvements
193
+ * 🌈 Add line-gradient property [#6303](https://github.com/mapbox/mapbox-gl-js/pull/6303)
194
+ * Add collator expression for controlling case and diacritic sensitivity in string comparisons [#6270](https://github.com/mapbox/mapbox-gl-js/pull/6270)
195
+ * Add `is-supported-script` expression for determining if a script is supported. [#6260](https://github.com/mapbox/mapbox-gl-js/pull/6260)
196
+ * Add `collator` expression for controlling case and diacritic sensitivity in string comparisons [#6270](https://github.com/mapbox/mapbox-gl-js/pull/6270)
197
+ * Add `abs`, `round`, `floor`, and `ceil` expression operators [#6496](https://github.com/mapbox/mapbox-gl-js/pull/6496)
198
+ * Add support for Mapzen Terrarium tiles in raster-dem sources [#6110](https://github.com/mapbox/mapbox-gl-js/pull/6110)
199
+
200
+ ### 🐛 Bug fixes
201
+ - Fix Rollup build [6575](https://github.com/mapbox/mapbox-gl-js/pull/6575)
202
+
203
+ ## 11.1.1
204
+
205
+ ### 🐛 Bug fixes
206
+
207
+ * Update SDK support information for `text-font`, and `heatmap-color`, and `hillshade` layer properties.
208
+
209
+ ## 11.1.0
210
+
211
+ ### ✨ Features and improvements
212
+
213
+ * Avoid use of `new Function` for filters by converting old-style filters to expressions [#5665](https://github.com/mapbox/mapbox-gl-js/pull/5665).
214
+
215
+ ## 11.0.0
216
+
217
+ ### ⚠️ Breaking changes
218
+
219
+ * Remove constants validating code [#5885](https://github.com/mapbox/mapbox-gl-js/pull/5885)
220
+ * `"colorSpace": "hcl"` now uses shortest-path interpolation for hue [#5811](https://github.com/mapbox/mapbox-gl-js/issues/5811)
221
+
222
+ ### ✨ Features and improvements
223
+
224
+ * Introduce client-side hillshading with `raster-dem` source type and `hillshade` layer type [#5286](https://github.com/mapbox/mapbox-gl-js/pull/5286)
225
+ * Add Color#toString and expose Color publicly [#5866](https://github.com/mapbox/mapbox-gl-js/pull/5866)
226
+ * Improve typing for `==` and `!=` expressions [#5840](https://github.com/mapbox/mapbox-gl-js/pull/5840)
227
+ * Made `coalesce` expressions more useful [#5755](https://github.com/mapbox/mapbox-gl-js/issues/5755)
228
+ * Enable implicit type assertions for array types [#5738](https://github.com/mapbox/mapbox-gl-js/pull/5738)
229
+
230
+ ### 🐛 Bug fixes
231
+
232
+ * Fix standalone browser build [#5736](https://github.com/mapbox/mapbox-gl-js/pull/5736), [#5906](https://github.com/mapbox/mapbox-gl-js/pull/5906)
233
+ * Handle NaN as input to step and interpolate expressions [#5757](https://github.com/mapbox/mapbox-gl-js/pull/5757)
234
+ * Fix style diffing for changes to GeoJSON sources [#5745](https://github.com/mapbox/mapbox-gl-js/pull/5745)
235
+ * Mark layer "type" property as required [#5849](https://github.com/mapbox/mapbox-gl-js/pull/5849)
236
+
237
+ ## 10.1.0
238
+
239
+ * Remove support for validating and migrating v6 styles [#5604](https://github.com/mapbox/mapbox-gl-js/pull/5604)
240
+ * Remove support for validating v7 styles [#5604](https://github.com/mapbox/mapbox-gl-js/pull/5604)
241
+ * Remove spaces after commas in `to-string` representation of colors [#5480](https://github.com/mapbox/mapbox-gl-js/pull/5480)
242
+ * Fix bugs preventing `mapbox-gl-style-spec` package on NPM from being used externally [#5502](https://github.com/mapbox/mapbox-gl-js/pull/5502)
243
+ * Fix flow-typed interface generator [#5478](https://github.com/mapbox/mapbox-gl-js/pull/5478)
244
+ * Export `function` [#5584](https://github.com/mapbox/mapbox-gl-js/pull/5584)
245
+ * Export `StylePropertySpecification` type [#5593](https://github.com/mapbox/mapbox-gl-js/pull/5593)
246
+ * Split the `source_tile` entry in the JSON schema into `source_vector` and `source_raster` [#5604](https://github.com/mapbox/mapbox-gl-js/pull/5604)
247
+
248
+ ### Validation Changes
249
+
250
+ * Require that `heatmap-color` use expressions instead of stop functions [#5624](https://github.com/mapbox/mapbox-gl-js/issues/5624)
251
+ * Remove support for including `{tokens}` in expressions for `text-field` and `icon-image` [#5599](https://github.com/mapbox/mapbox-gl-js/issues/5599)
252
+ * Disallow interpolation in expressions for `line-dasharray` [#5519](https://github.com/mapbox/mapbox-gl-js/pull/5519)
253
+ * Validate that zoom expressions only appear at the top level of an expression [#5609](https://github.com/mapbox/mapbox-gl-js/issues/5609)
254
+ * Validate that `step` and `interpolate` expressions don't have any duplicate stops [#5605](https://github.com/mapbox/mapbox-gl-js/issues/5605)
255
+ * Split `curve` expression into `step` and `interpolate` expressions [#5542](https://github.com/mapbox/mapbox-gl-js/pull/5542)
256
+ * Validate expression values for enum-typed properties [#5589](https://github.com/mapbox/mapbox-gl-js/pull/5589)
257
+ * Improve validation to catch uses of deprecated function syntax [#5667](https://github.com/mapbox/mapbox-gl-js/pull/5667)
258
+
259
+ ## 10.0.1
260
+
261
+ * Fix bug preventing @mapbox/mapbox-gl-style-spec package from being usable outside of mapbox-gl-js (#5502)
262
+
263
+ ## 10.0.0
264
+
265
+ * Add expression and heatmap layer support. See Mapbox GL JS v0.40.1 changelog entry for details.
266
+
267
+ ## 9.0.1
268
+
269
+ * Remove `fast-stable-stringify` dependency (#5152)
270
+
271
+ ## 9.0.0
272
+
273
+ * Fix validation error on categorical zoom-and-property functions (#4220)
274
+ * Relax requirement that styles using "icon-image" must have a "sprite"
275
+ * Prevent infinite loop in binarySearchForIndex when duplicate stops are present. (#4503)
276
+ * Ensure generated composite function stops are in the correct order (#4509)
277
+ * Update SDK support matrices to be current as of GL JS v0.35.1, iOS SDK v3.5.0, Android SDK 5.0.0
278
+ * Remove support for implicitly-categorical functions
279
+ * BREAKING CHANGE: the API for the `function` module has changed. The `interpolated` and `piecewise-constant` exports
280
+ were replaced with a single unnamed export, a function which accepts an object conforming to the style spec "function"
281
+ definition, and an object defining a style spec property. It handles color parsing and validation of feature values
282
+ internally.
283
+ * Functions now support a "default" property.
284
+ * `parseColor` was promoted from gl-js.
285
+
286
+ ## 8.11.0
287
+
288
+ * Merge `feature-filter` repository into this repository #639
289
+
290
+ ## 8.10.0
291
+
292
+ v8.0.0 styles are fully compatible with v8.10.0.
293
+
294
+ ### Style Specification Changes
295
+
296
+ * Added `colorSpace` option to functions
297
+ * Added `fill-extrusion` layer type
298
+ * Add top-level `light` property
299
+ * Remove increase maximum `maxzoom` to 24
300
+ * Deprecate paint classes :warning:
301
+ * Increase strictness of function validation
302
+
303
+ ### Reference JSON & API Changes
304
+
305
+ * Added `deref` utility
306
+ * Added `group_by_layout` utility
307
+ * Merge `mapbox-gl-function` repository into this repository
308
+
309
+ ## 8.9.0
310
+
311
+ v8.0.0 styles are fully compatible with v8.9.0.
312
+
313
+ * Added identity functions
314
+ * Added `auto` value which represents the calculated default value
315
+
316
+ ## 8.8.1
317
+
318
+ v8.0.0 styles are fully compatible with v8.8.1.
319
+
320
+ * Fixed style validation for layers with invalid types
321
+
322
+ ## 8.8.0
323
+
324
+ v8.0.0 styles are fully compatible with v8.8.0.
325
+
326
+ * Clarified documentation around fill-opacity.
327
+ * Update function documentation and validation for property functions.
328
+ * Add text-pitch-alignment property.
329
+ * Add icon-text-fit, icon-text-fit-padding properties.
330
+
331
+ ## 8.7.0
332
+
333
+ v8.0.0 styles are fully compatible with v8.7.0.
334
+
335
+ * Add support for has / !has operators.
336
+
337
+ ## 8.6.0
338
+
339
+ v8.0.0 styles are fully compatible with v8.6.0.
340
+
341
+ * Added support for zoom and feature driven functions.
342
+
343
+ ## 8.4.2
344
+
345
+ v8.0.0 styles are fully compatible with v8.4.2.
346
+
347
+ * Refactored style validator to expose more granular validation methods
348
+
349
+ ## 8.4.1
350
+
351
+ v8.0.0 styles are fully compatible with v8.4.1.
352
+
353
+ * Revert ramp validation checks that broke some styles.
354
+
355
+ ## 8.4.0
356
+
357
+ v8.0.0 styles are fully compatible with v8.4.0.
358
+
359
+ * Added `cluster`, `clusterRadius`, `clusterMaxZoom` GeoJSON source properties.
360
+
361
+ ## 8.3.0
362
+
363
+ v8.0.0 styles are fully compatible with v8.3.0.
364
+
365
+ * Added `line-offset` style property
366
+
367
+ ## 8.2.1
368
+
369
+ v8.0.0 styles are fully compatible with v8.2.1.
370
+
371
+ * Enforce that all layers that use a vector source specify a "source-layer"
372
+
373
+ ## 8.2.0
374
+
375
+ v8.0.0 styles are fully compatible with v8.2.0.
376
+
377
+ * Add inline `example` property.
378
+ * Enforce that all style properties must have documentation in `doc` property.
379
+ * Create minified style specs with `doc` and `example` properties removed.
380
+ * `validate` now validates against minified style spec.
381
+ * `format` now accepts `space` option to use with `JSON.stringify`.
382
+ * Remove `gl-style-spritify`. Mapbox GL sprites are now created automatically by
383
+ the Mapbox style APIs, or for hand-crafted styles, by [spritezero-cli](https://github.com/mapbox/spritezero-cli).
384
+
385
+ ## 8.1.0
386
+
387
+ v8.0.0 styles are fully compatible with v8.1.0.
388
+
389
+ * [BREAKING] Simplified layout/paint layer property types to more closely align
390
+ with v7 types.
391
+ * Fixed migration script compatibility with newer versions of Node.js and io.js
392
+ * Removed `constants` from schema, they were deprecated in v8
393
+ * Added style diff utility to generate semantic deltas between two stylesheets
394
+ * Added `visibility` property to `circle` layer type
395
+ * Added `pitch` property to stylesheet
396
+
397
+ ## 8.0.0
398
+
399
+ Introduction of Mapbox GL style specification v8. To migrate a v7 style to v8,
400
+ use the `gl-style-migrate` script as described in the README.
401
+
402
+ * [BREAKING] The value of the `text-font` property is now an array of
403
+ strings, rather than a single comma separated string.
404
+ * [BREAKING] Renamed `symbol-min-distance` to `symbol-spacing`.
405
+ * [BREAKING] Renamed `background-image` to `background-pattern`.
406
+ * [BREAKING] Renamed `line-image` to `line-pattern`.
407
+ * [BREAKING] Renamed `fill-image` to `fill-pattern`.
408
+ * [BREAKING] Renamed the `url` property of the video source type to `urls`.
409
+ * [BREAKING] Coordinates in video sources are now specified in [lon, lat] order.
410
+ * [BREAKING] Removed `text-max-size` and `icon-max-size` properties; these
411
+ are now calculated automatically.
412
+ * [BREAKING] `text-size` and `icon-size` are now layout properties instead of paint properties.
413
+ * [BREAKING] Constants are no longer supported. If you are editing styles by
414
+ hand and want to use constants, you can use a preprocessing step with a tool
415
+ like [ScreeSS](https://github.com/screee/screess).
416
+ * [BREAKING] The format for `mapbox://` glyphs URLs has changed; you should
417
+ now use `mapbox://fonts/mapbox/{fontstack}/{range}.pbf`.
418
+ * [BREAKING] Reversed the priority of layers for calculating label placement:
419
+ labels for layers that appear later in the style now have priority over earlier
420
+ layers.
421
+ * Added a new `image` source type.
422
+ * Added a new `circle` layer type.
423
+ * Default map center location can now be set in the style.
424
+ * Added `mapbox://` sprite URLs `mapbox://sprite/{user | "mapbox"}/{id}`
425
+
426
+ ## 7.5.0
427
+
428
+ * Added gl-style-composite script, for auto-compositing sources in a style.
429
+
430
+ ## 7.4.1
431
+
432
+ * Use JSON.stringify for formatting instead of js-beautify
433
+
434
+ ## 7.0.0
435
+
436
+ Introduction of Mapbox GL style specification v7.
437
+
438
+ * [BREAKING] Improve dashed lines (#234)
439
+ * [BREAKING] Remove prerendered layers (#232)
440
+ * Explicit visibility property (#212)
441
+ * Functions for all properties (#237)
442
+
443
+ ## 6.0.0 (Style spec v6)
444
+
445
+ Introduction of Mapbox GL style specification v6.
446
+
447
+ * [BREAKING] New filter syntax (#178)
448
+ * [BREAKING] Line gap property (#131)
449
+ * [BREAKING] Remove dashes from min/max-zoom (#175)
450
+ * [BREAKING] New layout/paint terminology (#166)
451
+ * [BREAKING] Single text positioning property (#197)
452
+ * Added requirements (#200)
453
+ * Added minimum, maximum, and period values (#198)
454
+
455
+ ## 0.0.5 (in progress)
456
+
457
+ * [BREAKING] Switch to suffix for transition properties (`transition-*` -> `*-transition`).
458
+ * Added support for remote, non-Mapbox TileJSON sources.
459
+ * [BREAKING] Source `minZoom` and `maxZoom` renamed to `minzoom` and `maxzoom to match TileJSON.
460
+ * Added support for `mapbox://` glyph URLs.
461
+ * [BREAKING] Renamed `raster-fade` to `raster-fade-duration`.
462
+ * Added background-opacity property.
463
+ * Added "tokens" property to string values that can autocomplete fields from layers
464
+ * Added "units" property to describe value types
465
+
466
+ ## 0.0.4 (Aug 8 2014)
467
+
468
+ * Initial public release
node_modules/@plotly/mapbox-gl/src/style-spec/README.md ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Mapbox GL style specification & utilities
2
+
3
+ This directory contains code and reference files that define the Mapbox GL style specification and provides some utilities for working with Mapbox styles.
4
+
5
+ ## npm package
6
+
7
+ The Mapbox GL style specification and utilities are published as a seperate npm
8
+ package so that they can be installed without the bulk of GL JS.
9
+
10
+ npm install @mapbox/mapbox-gl-style-spec
11
+
12
+ ## CLI Tools
13
+
14
+ If you install this package globally, you will have access to several CLI tools.
15
+
16
+ npm install @mapbox/mapbox-gl-style-spec --global
17
+
18
+
19
+ ### `gl-style-composite`
20
+ ```bash
21
+ $ gl-style-composite style.json
22
+ ```
23
+
24
+ Will take a non-composited style and produce a [composite style](https://www.mapbox.com/blog/better-label-placement-in-mapbox-studio/).
25
+
26
+ ### `gl-style-migrate`
27
+
28
+ This repo contains scripts for migrating GL styles of any version to the latest version
29
+ (currently v8). Migrate a style like this:
30
+
31
+ ```bash
32
+ $ gl-style-migrate bright-v7.json > bright-v8.json
33
+ ```
34
+
35
+ To migrate a file in place, you can use the `sponge` utility from the `moreutils` package:
36
+
37
+ ```bash
38
+ $ brew install moreutils
39
+ $ gl-style-migrate bright.json | sponge bright.json
40
+ ```
41
+
42
+ ### `gl-style-format`
43
+
44
+ ```bash
45
+ $ gl-style-format style.json
46
+ ```
47
+
48
+ Will format the given style JSON to use standard indentation and sorted object keys.
49
+
50
+ ### `gl-style-validate`
51
+
52
+ ```bash
53
+ $ gl-style-validate style.json
54
+ ```
55
+
56
+ Will validate the given style JSON and print errors to stdout. Provide a
57
+ `--json` flag to get JSON output.
58
+
59
+ To validate that a style can be uploaded to the Mapbox Styles API, use the `--mapbox-api-supported` flag.
node_modules/@plotly/mapbox-gl/src/style-spec/bin/gl-style-composite ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env node
2
+
3
+
4
+ var fs = require('fs'),
5
+ argv = require('minimist')(process.argv.slice(2)),
6
+ format = require('../').format,
7
+ composite = require('../').composite;
8
+
9
+ console.log(format(composite(JSON.parse(fs.readFileSync(argv._[0])))));
node_modules/@plotly/mapbox-gl/src/style-spec/bin/gl-style-format ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env node
2
+
3
+
4
+ var fs = require('fs'),
5
+ argv = require('minimist')(process.argv.slice(2)),
6
+ format = require('../').format;
7
+
8
+ if (argv.help || argv.h || (!argv._.length && process.stdin.isTTY)) {
9
+ return help();
10
+ }
11
+
12
+ console.log(format(JSON.parse(fs.readFileSync(argv._[0])), argv.space));
13
+
14
+ function help() {
15
+ console.log('usage:');
16
+ console.log(' gl-style-format source.json > destination.json');
17
+ console.log('');
18
+ console.log('options:');
19
+ console.log(' --space <num>');
20
+ console.log(' Number of spaces in output (default "2")');
21
+ console.log(' Pass "0" for minified output.');
22
+ }
node_modules/@plotly/mapbox-gl/src/style-spec/bin/gl-style-migrate ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env node
2
+
3
+
4
+ var fs = require('fs'),
5
+ argv = require('minimist')(process.argv.slice(2)),
6
+ format = require('../').format,
7
+ migrate = require('../').migrate;
8
+
9
+ console.log(format(migrate(JSON.parse(fs.readFileSync(argv._[0])))));
node_modules/@plotly/mapbox-gl/src/style-spec/bin/gl-style-validate ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env node
2
+
3
+
4
+ var argv = require('minimist')(process.argv.slice(2), {
5
+ boolean: 'json',
6
+ boolean: 'mapbox-api-supported'
7
+ }),
8
+ validate = require('../').validate,
9
+ validateMapboxApiSupported = require('../').validateMapboxApiSupported
10
+ rw = require('rw'),
11
+ status = 0;
12
+
13
+ if (argv.help || argv.h || (!argv._.length && process.stdin.isTTY)) {
14
+ return help();
15
+ }
16
+
17
+ if (!argv._.length) {
18
+ argv._.push('/dev/stdin');
19
+ }
20
+
21
+ argv._.forEach(function(file) {
22
+ var errors;
23
+ if (argv['mapbox-api-supported']) {
24
+ errors = validateMapboxApiSupported(rw.readFileSync(file, 'utf8'));
25
+ } else {
26
+ errors = validate(rw.readFileSync(file, 'utf8'));
27
+ }
28
+ if (errors.length) {
29
+ if (argv.json) {
30
+ process.stdout.write(JSON.stringify(errors, null, 2));
31
+ } else {
32
+ errors.forEach(function (e) {
33
+ console.log('%s:%d: %s', file, e.line, e.message);
34
+ });
35
+ }
36
+ status = 1;
37
+ }
38
+ });
39
+
40
+ process.exit(status);
41
+
42
+ function help() {
43
+ console.log('usage:');
44
+ console.log(' gl-style-validate file.json');
45
+ console.log(' gl-style-validate < file.json');
46
+ console.log('');
47
+ console.log('options:');
48
+ console.log('--json output errors as json');
49
+ console.log('--mapbox-api-supported validate compatibility with Mapbox Styles API');
50
+ }
node_modules/@plotly/mapbox-gl/src/style-spec/composite.js ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ export default function (style) {
3
+ const styleIDs = [];
4
+ const sourceIDs = [];
5
+ const compositedSourceLayers = [];
6
+
7
+ for (const id in style.sources) {
8
+ const source = style.sources[id];
9
+
10
+ if (source.type !== "vector")
11
+ continue;
12
+
13
+ const match = /^mapbox:\/\/(.*)/.exec(source.url);
14
+ if (!match)
15
+ continue;
16
+
17
+ styleIDs.push(id);
18
+ sourceIDs.push(match[1]);
19
+ }
20
+
21
+ if (styleIDs.length < 2)
22
+ return style;
23
+
24
+ styleIDs.forEach((id) => {
25
+ delete style.sources[id];
26
+ });
27
+
28
+ const compositeID = sourceIDs.join(",");
29
+
30
+ style.sources[compositeID] = {
31
+ "type": "vector",
32
+ "url": `mapbox://${compositeID}`
33
+ };
34
+
35
+ style.layers.forEach((layer) => {
36
+ if (styleIDs.indexOf(layer.source) >= 0) {
37
+ layer.source = compositeID;
38
+
39
+ if ('source-layer' in layer) {
40
+ if (compositedSourceLayers.indexOf(layer['source-layer']) >= 0) {
41
+ throw new Error('Conflicting source layer names');
42
+ } else {
43
+ compositedSourceLayers.push(layer['source-layer']);
44
+ }
45
+ }
46
+ }
47
+ });
48
+
49
+ return style;
50
+ }
node_modules/@plotly/mapbox-gl/src/style-spec/declass.js ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import extend from './util/extend';
3
+
4
+ export default declassStyle;
5
+
6
+ /**
7
+ * Returns a new style with the given 'paint classes' merged into each layer's
8
+ * main `paint` definiton, and with all `paint.*` properties removed.
9
+ *
10
+ * @private
11
+ * @param {Object} style A style JSON object.
12
+ * @param {Array<string>} classes An array of paint classes to apply, in order.
13
+ *
14
+ * @example
15
+ * var declass = require('mapbox-gl-style-spec/lib/declass')
16
+ * var baseStyle = { ... style with a 'paint.night' property in some layers ... }
17
+ * var nightStyle = declass(baseStyle, ['night'])
18
+ * // nightStyle now has each layer's `paint.night` properties merged in to the
19
+ * // main `paint` property.
20
+ */
21
+ function declassStyle(style, classes) {
22
+ return extend({}, style, {
23
+ layers: style.layers.map((layer) => {
24
+ const result = classes.reduce(declassLayer, layer);
25
+
26
+ // strip away all `paint.CLASS` definitions
27
+ for (const key in result) {
28
+ if (/paint\..*/.test(key)) {
29
+ delete result[key];
30
+ }
31
+ }
32
+
33
+ return result;
34
+ })
35
+ });
36
+ }
37
+
38
+ function declassLayer(layer, klass) {
39
+ return extend({}, layer, {
40
+ paint: extend({}, layer.paint, layer[`paint.${klass}`])
41
+ });
42
+ }
node_modules/@plotly/mapbox-gl/src/style-spec/deref.js ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import refProperties from './util/ref_properties';
3
+
4
+ function deref(layer, parent) {
5
+ const result = {};
6
+
7
+ for (const k in layer) {
8
+ if (k !== 'ref') {
9
+ result[k] = layer[k];
10
+ }
11
+ }
12
+
13
+ refProperties.forEach((k) => {
14
+ if (k in parent) {
15
+ result[k] = parent[k];
16
+ }
17
+ });
18
+
19
+ return result;
20
+ }
21
+
22
+ export default derefLayers;
23
+
24
+ /**
25
+ * Given an array of layers, some of which may contain `ref` properties
26
+ * whose value is the `id` of another property, return a new array where
27
+ * such layers have been augmented with the 'type', 'source', etc. properties
28
+ * from the parent layer, and the `ref` property has been removed.
29
+ *
30
+ * The input is not modified. The output may contain references to portions
31
+ * of the input.
32
+ *
33
+ * @private
34
+ * @param {Array<Layer>} layers
35
+ * @returns {Array<Layer>}
36
+ */
37
+ function derefLayers(layers) {
38
+ layers = layers.slice();
39
+
40
+ const map = Object.create(null);
41
+ for (let i = 0; i < layers.length; i++) {
42
+ map[layers[i].id] = layers[i];
43
+ }
44
+
45
+ for (let i = 0; i < layers.length; i++) {
46
+ if ('ref' in layers[i]) {
47
+ layers[i] = deref(layers[i], map[layers[i].ref]);
48
+ }
49
+ }
50
+
51
+ return layers;
52
+ }
node_modules/@plotly/mapbox-gl/src/style-spec/diff.js ADDED
@@ -0,0 +1,393 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import isEqual from './util/deep_equal';
3
+
4
+ const operations = {
5
+
6
+ /*
7
+ * { command: 'setStyle', args: [stylesheet] }
8
+ */
9
+ setStyle: 'setStyle',
10
+
11
+ /*
12
+ * { command: 'addLayer', args: [layer, 'beforeLayerId'] }
13
+ */
14
+ addLayer: 'addLayer',
15
+
16
+ /*
17
+ * { command: 'removeLayer', args: ['layerId'] }
18
+ */
19
+ removeLayer: 'removeLayer',
20
+
21
+ /*
22
+ * { command: 'setPaintProperty', args: ['layerId', 'prop', value] }
23
+ */
24
+ setPaintProperty: 'setPaintProperty',
25
+
26
+ /*
27
+ * { command: 'setLayoutProperty', args: ['layerId', 'prop', value] }
28
+ */
29
+ setLayoutProperty: 'setLayoutProperty',
30
+
31
+ /*
32
+ * { command: 'setFilter', args: ['layerId', filter] }
33
+ */
34
+ setFilter: 'setFilter',
35
+
36
+ /*
37
+ * { command: 'addSource', args: ['sourceId', source] }
38
+ */
39
+ addSource: 'addSource',
40
+
41
+ /*
42
+ * { command: 'removeSource', args: ['sourceId'] }
43
+ */
44
+ removeSource: 'removeSource',
45
+
46
+ /*
47
+ * { command: 'setGeoJSONSourceData', args: ['sourceId', data] }
48
+ */
49
+ setGeoJSONSourceData: 'setGeoJSONSourceData',
50
+
51
+ /*
52
+ * { command: 'setLayerZoomRange', args: ['layerId', 0, 22] }
53
+ */
54
+ setLayerZoomRange: 'setLayerZoomRange',
55
+
56
+ /*
57
+ * { command: 'setLayerProperty', args: ['layerId', 'prop', value] }
58
+ */
59
+ setLayerProperty: 'setLayerProperty',
60
+
61
+ /*
62
+ * { command: 'setCenter', args: [[lon, lat]] }
63
+ */
64
+ setCenter: 'setCenter',
65
+
66
+ /*
67
+ * { command: 'setZoom', args: [zoom] }
68
+ */
69
+ setZoom: 'setZoom',
70
+
71
+ /*
72
+ * { command: 'setBearing', args: [bearing] }
73
+ */
74
+ setBearing: 'setBearing',
75
+
76
+ /*
77
+ * { command: 'setPitch', args: [pitch] }
78
+ */
79
+ setPitch: 'setPitch',
80
+
81
+ /*
82
+ * { command: 'setSprite', args: ['spriteUrl'] }
83
+ */
84
+ setSprite: 'setSprite',
85
+
86
+ /*
87
+ * { command: 'setGlyphs', args: ['glyphsUrl'] }
88
+ */
89
+ setGlyphs: 'setGlyphs',
90
+
91
+ /*
92
+ * { command: 'setTransition', args: [transition] }
93
+ */
94
+ setTransition: 'setTransition',
95
+
96
+ /*
97
+ * { command: 'setLighting', args: [lightProperties] }
98
+ */
99
+ setLight: 'setLight'
100
+
101
+ };
102
+
103
+ function addSource(sourceId, after, commands) {
104
+ commands.push({command: operations.addSource, args: [sourceId, after[sourceId]]});
105
+ }
106
+
107
+ function removeSource(sourceId, commands, sourcesRemoved) {
108
+ commands.push({command: operations.removeSource, args: [sourceId]});
109
+ sourcesRemoved[sourceId] = true;
110
+ }
111
+
112
+ function updateSource(sourceId, after, commands, sourcesRemoved) {
113
+ removeSource(sourceId, commands, sourcesRemoved);
114
+ addSource(sourceId, after, commands);
115
+ }
116
+
117
+ function canUpdateGeoJSON(before, after, sourceId) {
118
+ let prop;
119
+ for (prop in before[sourceId]) {
120
+ if (!before[sourceId].hasOwnProperty(prop)) continue;
121
+ if (prop !== 'data' && !isEqual(before[sourceId][prop], after[sourceId][prop])) {
122
+ return false;
123
+ }
124
+ }
125
+ for (prop in after[sourceId]) {
126
+ if (!after[sourceId].hasOwnProperty(prop)) continue;
127
+ if (prop !== 'data' && !isEqual(before[sourceId][prop], after[sourceId][prop])) {
128
+ return false;
129
+ }
130
+ }
131
+ return true;
132
+ }
133
+
134
+ function diffSources(before, after, commands, sourcesRemoved) {
135
+ before = before || {};
136
+ after = after || {};
137
+
138
+ let sourceId;
139
+
140
+ // look for sources to remove
141
+ for (sourceId in before) {
142
+ if (!before.hasOwnProperty(sourceId)) continue;
143
+ if (!after.hasOwnProperty(sourceId)) {
144
+ removeSource(sourceId, commands, sourcesRemoved);
145
+ }
146
+ }
147
+
148
+ // look for sources to add/update
149
+ for (sourceId in after) {
150
+ if (!after.hasOwnProperty(sourceId)) continue;
151
+ if (!before.hasOwnProperty(sourceId)) {
152
+ addSource(sourceId, after, commands);
153
+ } else if (!isEqual(before[sourceId], after[sourceId])) {
154
+ if (before[sourceId].type === 'geojson' && after[sourceId].type === 'geojson' && canUpdateGeoJSON(before, after, sourceId)) {
155
+ commands.push({command: operations.setGeoJSONSourceData, args: [sourceId, after[sourceId].data]});
156
+ } else {
157
+ // no update command, must remove then add
158
+ updateSource(sourceId, after, commands, sourcesRemoved);
159
+ }
160
+ }
161
+ }
162
+ }
163
+
164
+ function diffLayerPropertyChanges(before, after, commands, layerId, klass, command) {
165
+ before = before || {};
166
+ after = after || {};
167
+
168
+ let prop;
169
+
170
+ for (prop in before) {
171
+ if (!before.hasOwnProperty(prop)) continue;
172
+ if (!isEqual(before[prop], after[prop])) {
173
+ commands.push({command, args: [layerId, prop, after[prop], klass]});
174
+ }
175
+ }
176
+ for (prop in after) {
177
+ if (!after.hasOwnProperty(prop) || before.hasOwnProperty(prop)) continue;
178
+ if (!isEqual(before[prop], after[prop])) {
179
+ commands.push({command, args: [layerId, prop, after[prop], klass]});
180
+ }
181
+ }
182
+ }
183
+
184
+ function pluckId(layer) {
185
+ return layer.id;
186
+ }
187
+ function indexById(group, layer) {
188
+ group[layer.id] = layer;
189
+ return group;
190
+ }
191
+
192
+ function diffLayers(before, after, commands) {
193
+ before = before || [];
194
+ after = after || [];
195
+
196
+ // order of layers by id
197
+ const beforeOrder = before.map(pluckId);
198
+ const afterOrder = after.map(pluckId);
199
+
200
+ // index of layer by id
201
+ const beforeIndex = before.reduce(indexById, {});
202
+ const afterIndex = after.reduce(indexById, {});
203
+
204
+ // track order of layers as if they have been mutated
205
+ const tracker = beforeOrder.slice();
206
+
207
+ // layers that have been added do not need to be diffed
208
+ const clean = Object.create(null);
209
+
210
+ let i, d, layerId, beforeLayer, afterLayer, insertBeforeLayerId, prop;
211
+
212
+ // remove layers
213
+ for (i = 0, d = 0; i < beforeOrder.length; i++) {
214
+ layerId = beforeOrder[i];
215
+ if (!afterIndex.hasOwnProperty(layerId)) {
216
+ commands.push({command: operations.removeLayer, args: [layerId]});
217
+ tracker.splice(tracker.indexOf(layerId, d), 1);
218
+ } else {
219
+ // limit where in tracker we need to look for a match
220
+ d++;
221
+ }
222
+ }
223
+
224
+ // add/reorder layers
225
+ for (i = 0, d = 0; i < afterOrder.length; i++) {
226
+ // work backwards as insert is before an existing layer
227
+ layerId = afterOrder[afterOrder.length - 1 - i];
228
+
229
+ if (tracker[tracker.length - 1 - i] === layerId) continue;
230
+
231
+ if (beforeIndex.hasOwnProperty(layerId)) {
232
+ // remove the layer before we insert at the correct position
233
+ commands.push({command: operations.removeLayer, args: [layerId]});
234
+ tracker.splice(tracker.lastIndexOf(layerId, tracker.length - d), 1);
235
+ } else {
236
+ // limit where in tracker we need to look for a match
237
+ d++;
238
+ }
239
+
240
+ // add layer at correct position
241
+ insertBeforeLayerId = tracker[tracker.length - i];
242
+ commands.push({command: operations.addLayer, args: [afterIndex[layerId], insertBeforeLayerId]});
243
+ tracker.splice(tracker.length - i, 0, layerId);
244
+ clean[layerId] = true;
245
+ }
246
+
247
+ // update layers
248
+ for (i = 0; i < afterOrder.length; i++) {
249
+ layerId = afterOrder[i];
250
+ beforeLayer = beforeIndex[layerId];
251
+ afterLayer = afterIndex[layerId];
252
+
253
+ // no need to update if previously added (new or moved)
254
+ if (clean[layerId] || isEqual(beforeLayer, afterLayer)) continue;
255
+
256
+ // If source, source-layer, or type have changes, then remove the layer
257
+ // and add it back 'from scratch'.
258
+ if (!isEqual(beforeLayer.source, afterLayer.source) || !isEqual(beforeLayer['source-layer'], afterLayer['source-layer']) || !isEqual(beforeLayer.type, afterLayer.type)) {
259
+ commands.push({command: operations.removeLayer, args: [layerId]});
260
+ // we add the layer back at the same position it was already in, so
261
+ // there's no need to update the `tracker`
262
+ insertBeforeLayerId = tracker[tracker.lastIndexOf(layerId) + 1];
263
+ commands.push({command: operations.addLayer, args: [afterLayer, insertBeforeLayerId]});
264
+ continue;
265
+ }
266
+
267
+ // layout, paint, filter, minzoom, maxzoom
268
+ diffLayerPropertyChanges(beforeLayer.layout, afterLayer.layout, commands, layerId, null, operations.setLayoutProperty);
269
+ diffLayerPropertyChanges(beforeLayer.paint, afterLayer.paint, commands, layerId, null, operations.setPaintProperty);
270
+ if (!isEqual(beforeLayer.filter, afterLayer.filter)) {
271
+ commands.push({command: operations.setFilter, args: [layerId, afterLayer.filter]});
272
+ }
273
+ if (!isEqual(beforeLayer.minzoom, afterLayer.minzoom) || !isEqual(beforeLayer.maxzoom, afterLayer.maxzoom)) {
274
+ commands.push({command: operations.setLayerZoomRange, args: [layerId, afterLayer.minzoom, afterLayer.maxzoom]});
275
+ }
276
+
277
+ // handle all other layer props, including paint.*
278
+ for (prop in beforeLayer) {
279
+ if (!beforeLayer.hasOwnProperty(prop)) continue;
280
+ if (prop === 'layout' || prop === 'paint' || prop === 'filter' ||
281
+ prop === 'metadata' || prop === 'minzoom' || prop === 'maxzoom') continue;
282
+ if (prop.indexOf('paint.') === 0) {
283
+ diffLayerPropertyChanges(beforeLayer[prop], afterLayer[prop], commands, layerId, prop.slice(6), operations.setPaintProperty);
284
+ } else if (!isEqual(beforeLayer[prop], afterLayer[prop])) {
285
+ commands.push({command: operations.setLayerProperty, args: [layerId, prop, afterLayer[prop]]});
286
+ }
287
+ }
288
+ for (prop in afterLayer) {
289
+ if (!afterLayer.hasOwnProperty(prop) || beforeLayer.hasOwnProperty(prop)) continue;
290
+ if (prop === 'layout' || prop === 'paint' || prop === 'filter' ||
291
+ prop === 'metadata' || prop === 'minzoom' || prop === 'maxzoom') continue;
292
+ if (prop.indexOf('paint.') === 0) {
293
+ diffLayerPropertyChanges(beforeLayer[prop], afterLayer[prop], commands, layerId, prop.slice(6), operations.setPaintProperty);
294
+ } else if (!isEqual(beforeLayer[prop], afterLayer[prop])) {
295
+ commands.push({command: operations.setLayerProperty, args: [layerId, prop, afterLayer[prop]]});
296
+ }
297
+ }
298
+ }
299
+ }
300
+
301
+ /**
302
+ * Diff two stylesheet
303
+ *
304
+ * Creates semanticly aware diffs that can easily be applied at runtime.
305
+ * Operations produced by the diff closely resemble the mapbox-gl-js API. Any
306
+ * error creating the diff will fall back to the 'setStyle' operation.
307
+ *
308
+ * Example diff:
309
+ * [
310
+ * { command: 'setConstant', args: ['@water', '#0000FF'] },
311
+ * { command: 'setPaintProperty', args: ['background', 'background-color', 'black'] }
312
+ * ]
313
+ *
314
+ * @private
315
+ * @param {*} [before] stylesheet to compare from
316
+ * @param {*} after stylesheet to compare to
317
+ * @returns Array list of changes
318
+ */
319
+ function diffStyles(before, after) {
320
+ if (!before) return [{command: operations.setStyle, args: [after]}];
321
+
322
+ let commands = [];
323
+
324
+ try {
325
+ // Handle changes to top-level properties
326
+ if (!isEqual(before.version, after.version)) {
327
+ return [{command: operations.setStyle, args: [after]}];
328
+ }
329
+ if (!isEqual(before.center, after.center)) {
330
+ commands.push({command: operations.setCenter, args: [after.center]});
331
+ }
332
+ if (!isEqual(before.zoom, after.zoom)) {
333
+ commands.push({command: operations.setZoom, args: [after.zoom]});
334
+ }
335
+ if (!isEqual(before.bearing, after.bearing)) {
336
+ commands.push({command: operations.setBearing, args: [after.bearing]});
337
+ }
338
+ if (!isEqual(before.pitch, after.pitch)) {
339
+ commands.push({command: operations.setPitch, args: [after.pitch]});
340
+ }
341
+ if (!isEqual(before.sprite, after.sprite)) {
342
+ commands.push({command: operations.setSprite, args: [after.sprite]});
343
+ }
344
+ if (!isEqual(before.glyphs, after.glyphs)) {
345
+ commands.push({command: operations.setGlyphs, args: [after.glyphs]});
346
+ }
347
+ if (!isEqual(before.transition, after.transition)) {
348
+ commands.push({command: operations.setTransition, args: [after.transition]});
349
+ }
350
+ if (!isEqual(before.light, after.light)) {
351
+ commands.push({command: operations.setLight, args: [after.light]});
352
+ }
353
+
354
+ // Handle changes to `sources`
355
+ // If a source is to be removed, we also--before the removeSource
356
+ // command--need to remove all the style layers that depend on it.
357
+ const sourcesRemoved = {};
358
+
359
+ // First collect the {add,remove}Source commands
360
+ const removeOrAddSourceCommands = [];
361
+ diffSources(before.sources, after.sources, removeOrAddSourceCommands, sourcesRemoved);
362
+
363
+ // Push a removeLayer command for each style layer that depends on a
364
+ // source that's being removed.
365
+ // Also, exclude any such layers them from the input to `diffLayers`
366
+ // below, so that diffLayers produces the appropriate `addLayers`
367
+ // command
368
+ const beforeLayers = [];
369
+ if (before.layers) {
370
+ before.layers.forEach((layer) => {
371
+ if (sourcesRemoved[layer.source]) {
372
+ commands.push({command: operations.removeLayer, args: [layer.id]});
373
+ } else {
374
+ beforeLayers.push(layer);
375
+ }
376
+ });
377
+ }
378
+ commands = commands.concat(removeOrAddSourceCommands);
379
+
380
+ // Handle changes to `layers`
381
+ diffLayers(beforeLayers, after.layers, commands);
382
+
383
+ } catch (e) {
384
+ // fall back to setStyle
385
+ console.warn('Unable to compute style diff:', e);
386
+ commands = [{command: operations.setStyle, args: [after]}];
387
+ }
388
+
389
+ return commands;
390
+ }
391
+
392
+ export default diffStyles;
393
+ export {operations};
node_modules/@plotly/mapbox-gl/src/style-spec/dist/.gitkeep ADDED
File without changes
node_modules/@plotly/mapbox-gl/src/style-spec/empty.js ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import latest from './reference/latest';
2
+
3
+ export default function emptyStyle() {
4
+ const style = {};
5
+
6
+ const version = latest['$version'];
7
+ for (const styleKey in latest['$root']) {
8
+ const spec = latest['$root'][styleKey];
9
+
10
+ if (spec.required) {
11
+ let value = null;
12
+ if (styleKey === 'version') {
13
+ value = version;
14
+ } else {
15
+ if (spec.type === 'array') {
16
+ value = [];
17
+ } else {
18
+ value = {};
19
+ }
20
+ }
21
+
22
+ if (value != null) {
23
+ style[styleKey] = value;
24
+ }
25
+ }
26
+ }
27
+
28
+ return style;
29
+ }
node_modules/@plotly/mapbox-gl/src/style-spec/error/parsing_error.js ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ // Note: Do not inherit from Error. It breaks when transpiling to ES5.
4
+
5
+ export default class ParsingError {
6
+ message: string;
7
+ error: Error;
8
+ line: number;
9
+
10
+ constructor(error: Error) {
11
+ this.error = error;
12
+ this.message = error.message;
13
+ const match = error.message.match(/line (\d+)/);
14
+ this.line = match ? parseInt(match[1], 10) : 0;
15
+ }
16
+ }
node_modules/@plotly/mapbox-gl/src/style-spec/error/validation_error.js ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ // Note: Do not inherit from Error. It breaks when transpiling to ES5.
4
+
5
+ export default class ValidationError {
6
+ message: string;
7
+ identifier: ?string;
8
+ line: ?number;
9
+
10
+ constructor(key: ?string, value: ?{ __line__: number }, message: string, identifier: ?string) {
11
+ this.message = (key ? `${key}: ` : '') + message;
12
+ if (identifier) this.identifier = identifier;
13
+
14
+ if (value !== null && value !== undefined && value.__line__) {
15
+ this.line = value.__line__;
16
+ }
17
+ }
18
+ }
node_modules/@plotly/mapbox-gl/src/style-spec/expression/compound_expression.js ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ import {toString} from './types';
4
+
5
+ import ParsingContext from './parsing_context';
6
+ import EvaluationContext from './evaluation_context';
7
+ import assert from 'assert';
8
+
9
+ import type {Expression, ExpressionRegistry} from './expression';
10
+ import type {Type} from './types';
11
+ import type {Value} from './values';
12
+
13
+ export type Varargs = {| type: Type |};
14
+ type Signature = Array<Type> | Varargs;
15
+ type Evaluate = (EvaluationContext, Array<Expression>) => Value;
16
+ type Definition = [Type, Signature, Evaluate] |
17
+ {|type: Type, overloads: Array<[Signature, Evaluate]>|};
18
+
19
+ class CompoundExpression implements Expression {
20
+ name: string;
21
+ type: Type;
22
+ _evaluate: Evaluate;
23
+ args: Array<Expression>;
24
+
25
+ static definitions: {[_: string]: Definition };
26
+
27
+ constructor(name: string, type: Type, evaluate: Evaluate, args: Array<Expression>) {
28
+ this.name = name;
29
+ this.type = type;
30
+ this._evaluate = evaluate;
31
+ this.args = args;
32
+ }
33
+
34
+ evaluate(ctx: EvaluationContext) {
35
+ return this._evaluate(ctx, this.args);
36
+ }
37
+
38
+ eachChild(fn: (_: Expression) => void) {
39
+ this.args.forEach(fn);
40
+ }
41
+
42
+ outputDefined() {
43
+ return false;
44
+ }
45
+
46
+ serialize(): Array<mixed> {
47
+ return [this.name].concat(this.args.map(arg => arg.serialize()));
48
+ }
49
+
50
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext): ?Expression {
51
+ const op: string = (args[0]: any);
52
+ const definition = CompoundExpression.definitions[op];
53
+ if (!definition) {
54
+ return context.error(`Unknown expression "${op}". If you wanted a literal array, use ["literal", [...]].`, 0);
55
+ }
56
+
57
+ // Now check argument types against each signature
58
+ const type = Array.isArray(definition) ?
59
+ definition[0] : definition.type;
60
+
61
+ const availableOverloads = Array.isArray(definition) ?
62
+ [[definition[1], definition[2]]] :
63
+ definition.overloads;
64
+
65
+ const overloads = availableOverloads.filter(([signature]) => (
66
+ !Array.isArray(signature) || // varags
67
+ signature.length === args.length - 1 // correct param count
68
+ ));
69
+
70
+ let signatureContext: ParsingContext = (null: any);
71
+
72
+ for (const [params, evaluate] of overloads) {
73
+ // Use a fresh context for each attempted signature so that, if
74
+ // we eventually succeed, we haven't polluted `context.errors`.
75
+ signatureContext = new ParsingContext(context.registry, context.path, null, context.scope);
76
+
77
+ // First parse all the args, potentially coercing to the
78
+ // types expected by this overload.
79
+ const parsedArgs: Array<Expression> = [];
80
+ let argParseFailed = false;
81
+ for (let i = 1; i < args.length; i++) {
82
+ const arg = args[i];
83
+ const expectedType = Array.isArray(params) ?
84
+ params[i - 1] :
85
+ params.type;
86
+
87
+ const parsed = signatureContext.parse(arg, 1 + parsedArgs.length, expectedType);
88
+ if (!parsed) {
89
+ argParseFailed = true;
90
+ break;
91
+ }
92
+ parsedArgs.push(parsed);
93
+ }
94
+ if (argParseFailed) {
95
+ // Couldn't coerce args of this overload to expected type, move
96
+ // on to next one.
97
+ continue;
98
+ }
99
+
100
+ if (Array.isArray(params)) {
101
+ if (params.length !== parsedArgs.length) {
102
+ signatureContext.error(`Expected ${params.length} arguments, but found ${parsedArgs.length} instead.`);
103
+ continue;
104
+ }
105
+ }
106
+
107
+ for (let i = 0; i < parsedArgs.length; i++) {
108
+ const expected = Array.isArray(params) ? params[i] : params.type;
109
+ const arg = parsedArgs[i];
110
+ signatureContext.concat(i + 1).checkSubtype(expected, arg.type);
111
+ }
112
+
113
+ if (signatureContext.errors.length === 0) {
114
+ return new CompoundExpression(op, type, evaluate, parsedArgs);
115
+ }
116
+ }
117
+
118
+ assert(!signatureContext || signatureContext.errors.length > 0);
119
+
120
+ if (overloads.length === 1) {
121
+ context.errors.push(...signatureContext.errors);
122
+ } else {
123
+ const expected = overloads.length ? overloads : availableOverloads;
124
+ const signatures = expected
125
+ .map(([params]) => stringifySignature(params))
126
+ .join(' | ');
127
+
128
+ const actualTypes = [];
129
+ // For error message, re-parse arguments without trying to
130
+ // apply any coercions
131
+ for (let i = 1; i < args.length; i++) {
132
+ const parsed = context.parse(args[i], 1 + actualTypes.length);
133
+ if (!parsed) return null;
134
+ actualTypes.push(toString(parsed.type));
135
+ }
136
+ context.error(`Expected arguments of type ${signatures}, but found (${actualTypes.join(', ')}) instead.`);
137
+ }
138
+
139
+ return null;
140
+ }
141
+
142
+ static register(
143
+ registry: ExpressionRegistry,
144
+ definitions: {[_: string]: Definition }
145
+ ) {
146
+ assert(!CompoundExpression.definitions);
147
+ CompoundExpression.definitions = definitions;
148
+ for (const name in definitions) {
149
+ registry[name] = CompoundExpression;
150
+ }
151
+ }
152
+ }
153
+
154
+ function stringifySignature(signature: Signature): string {
155
+ if (Array.isArray(signature)) {
156
+ return `(${signature.map(toString).join(', ')})`;
157
+ } else {
158
+ return `(${toString(signature.type)}...)`;
159
+ }
160
+ }
161
+
162
+ export default CompoundExpression;
node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/assertion.js ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ import assert from 'assert';
4
+
5
+ import {
6
+ ObjectType,
7
+ ValueType,
8
+ StringType,
9
+ NumberType,
10
+ BooleanType,
11
+ checkSubtype,
12
+ toString,
13
+ array
14
+ } from '../types';
15
+ import RuntimeError from '../runtime_error';
16
+ import {typeOf} from '../values';
17
+
18
+ import type {Expression} from '../expression';
19
+ import type ParsingContext from '../parsing_context';
20
+ import type EvaluationContext from '../evaluation_context';
21
+ import type {Type} from '../types';
22
+
23
+ const types = {
24
+ string: StringType,
25
+ number: NumberType,
26
+ boolean: BooleanType,
27
+ object: ObjectType
28
+ };
29
+
30
+ class Assertion implements Expression {
31
+ type: Type;
32
+ args: Array<Expression>;
33
+
34
+ constructor(type: Type, args: Array<Expression>) {
35
+ this.type = type;
36
+ this.args = args;
37
+ }
38
+
39
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext): ?Expression {
40
+ if (args.length < 2)
41
+ return context.error(`Expected at least one argument.`);
42
+
43
+ let i = 1;
44
+ let type;
45
+
46
+ const name: string = (args[0]: any);
47
+ if (name === 'array') {
48
+ let itemType;
49
+ if (args.length > 2) {
50
+ const type = args[1];
51
+ if (typeof type !== 'string' || !(type in types) || type === 'object')
52
+ return context.error('The item type argument of "array" must be one of string, number, boolean', 1);
53
+ itemType = types[type];
54
+ i++;
55
+ } else {
56
+ itemType = ValueType;
57
+ }
58
+
59
+ let N;
60
+ if (args.length > 3) {
61
+ if (args[2] !== null &&
62
+ (typeof args[2] !== 'number' ||
63
+ args[2] < 0 ||
64
+ args[2] !== Math.floor(args[2]))
65
+ ) {
66
+ return context.error('The length argument to "array" must be a positive integer literal', 2);
67
+ }
68
+ N = args[2];
69
+ i++;
70
+ }
71
+
72
+ type = array(itemType, N);
73
+ } else {
74
+ assert(types[name], name);
75
+ type = types[name];
76
+ }
77
+
78
+ const parsed = [];
79
+ for (; i < args.length; i++) {
80
+ const input = context.parse(args[i], i, ValueType);
81
+ if (!input) return null;
82
+ parsed.push(input);
83
+ }
84
+
85
+ return new Assertion(type, parsed);
86
+ }
87
+
88
+ evaluate(ctx: EvaluationContext) {
89
+ for (let i = 0; i < this.args.length; i++) {
90
+ const value = this.args[i].evaluate(ctx);
91
+ const error = checkSubtype(this.type, typeOf(value));
92
+ if (!error) {
93
+ return value;
94
+ } else if (i === this.args.length - 1) {
95
+ throw new RuntimeError(`Expected value to be of type ${toString(this.type)}, but found ${toString(typeOf(value))} instead.`);
96
+ }
97
+ }
98
+
99
+ assert(false);
100
+ return null;
101
+ }
102
+
103
+ eachChild(fn: (_: Expression) => void) {
104
+ this.args.forEach(fn);
105
+ }
106
+
107
+ outputDefined(): boolean {
108
+ return this.args.every(arg => arg.outputDefined());
109
+ }
110
+
111
+ serialize(): Array<mixed> {
112
+ const type = this.type;
113
+ const serialized = [type.kind];
114
+ if (type.kind === 'array') {
115
+ const itemType = type.itemType;
116
+ if (itemType.kind === 'string' ||
117
+ itemType.kind === 'number' ||
118
+ itemType.kind === 'boolean') {
119
+ serialized.push(itemType.kind);
120
+ const N = type.N;
121
+ if (typeof N === 'number' || this.args.length > 1) {
122
+ serialized.push(N);
123
+ }
124
+ }
125
+ }
126
+ return serialized.concat(this.args.map(arg => arg.serialize()));
127
+ }
128
+ }
129
+
130
+ export default Assertion;
node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/at.js ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ import {array, ValueType, NumberType} from '../types';
4
+
5
+ import RuntimeError from '../runtime_error';
6
+
7
+ import type {Expression} from '../expression';
8
+ import type ParsingContext from '../parsing_context';
9
+ import type EvaluationContext from '../evaluation_context';
10
+ import type {Type, ArrayType} from '../types';
11
+ import type {Value} from '../values';
12
+
13
+ class At implements Expression {
14
+ type: Type;
15
+ index: Expression;
16
+ input: Expression;
17
+
18
+ constructor(type: Type, index: Expression, input: Expression) {
19
+ this.type = type;
20
+ this.index = index;
21
+ this.input = input;
22
+ }
23
+
24
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
25
+ if (args.length !== 3)
26
+ return context.error(`Expected 2 arguments, but found ${args.length - 1} instead.`);
27
+
28
+ const index = context.parse(args[1], 1, NumberType);
29
+ const input = context.parse(args[2], 2, array(context.expectedType || ValueType));
30
+
31
+ if (!index || !input) return null;
32
+
33
+ const t: ArrayType = (input.type: any);
34
+ return new At(t.itemType, index, input);
35
+ }
36
+
37
+ evaluate(ctx: EvaluationContext) {
38
+ const index = ((this.index.evaluate(ctx): any): number);
39
+ const array = ((this.input.evaluate(ctx): any): Array<Value>);
40
+
41
+ if (index < 0) {
42
+ throw new RuntimeError(`Array index out of bounds: ${index} < 0.`);
43
+ }
44
+
45
+ if (index >= array.length) {
46
+ throw new RuntimeError(`Array index out of bounds: ${index} > ${array.length - 1}.`);
47
+ }
48
+
49
+ if (index !== Math.floor(index)) {
50
+ throw new RuntimeError(`Array index must be an integer, but found ${index} instead.`);
51
+ }
52
+
53
+ return array[index];
54
+ }
55
+
56
+ eachChild(fn: (_: Expression) => void) {
57
+ fn(this.index);
58
+ fn(this.input);
59
+ }
60
+
61
+ outputDefined() {
62
+ return false;
63
+ }
64
+
65
+ serialize() {
66
+ return ["at", this.index.serialize(), this.input.serialize()];
67
+ }
68
+ }
69
+
70
+ export default At;
node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/case.js ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ import assert from 'assert';
4
+
5
+ import {BooleanType} from '../types';
6
+
7
+ import type {Expression} from '../expression';
8
+ import type ParsingContext from '../parsing_context';
9
+ import type EvaluationContext from '../evaluation_context';
10
+ import type {Type} from '../types';
11
+
12
+ type Branches = Array<[Expression, Expression]>;
13
+
14
+ class Case implements Expression {
15
+ type: Type;
16
+
17
+ branches: Branches;
18
+ otherwise: Expression;
19
+
20
+ constructor(type: Type, branches: Branches, otherwise: Expression) {
21
+ this.type = type;
22
+ this.branches = branches;
23
+ this.otherwise = otherwise;
24
+ }
25
+
26
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
27
+ if (args.length < 4)
28
+ return context.error(`Expected at least 3 arguments, but found only ${args.length - 1}.`);
29
+ if (args.length % 2 !== 0)
30
+ return context.error(`Expected an odd number of arguments.`);
31
+
32
+ let outputType: ?Type;
33
+ if (context.expectedType && context.expectedType.kind !== 'value') {
34
+ outputType = context.expectedType;
35
+ }
36
+
37
+ const branches = [];
38
+ for (let i = 1; i < args.length - 1; i += 2) {
39
+ const test = context.parse(args[i], i, BooleanType);
40
+ if (!test) return null;
41
+
42
+ const result = context.parse(args[i + 1], i + 1, outputType);
43
+ if (!result) return null;
44
+
45
+ branches.push([test, result]);
46
+
47
+ outputType = outputType || result.type;
48
+ }
49
+
50
+ const otherwise = context.parse(args[args.length - 1], args.length - 1, outputType);
51
+ if (!otherwise) return null;
52
+
53
+ assert(outputType);
54
+ return new Case((outputType: any), branches, otherwise);
55
+ }
56
+
57
+ evaluate(ctx: EvaluationContext) {
58
+ for (const [test, expression] of this.branches) {
59
+ if (test.evaluate(ctx)) {
60
+ return expression.evaluate(ctx);
61
+ }
62
+ }
63
+ return this.otherwise.evaluate(ctx);
64
+ }
65
+
66
+ eachChild(fn: (_: Expression) => void) {
67
+ for (const [test, expression] of this.branches) {
68
+ fn(test);
69
+ fn(expression);
70
+ }
71
+ fn(this.otherwise);
72
+ }
73
+
74
+ outputDefined(): boolean {
75
+ return this.branches.every(([_, out]) => out.outputDefined()) && this.otherwise.outputDefined();
76
+ }
77
+
78
+ serialize() {
79
+ const serialized = ["case"];
80
+ this.eachChild(child => { serialized.push(child.serialize()); });
81
+ return serialized;
82
+ }
83
+ }
84
+
85
+ export default Case;
node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/coalesce.js ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ import assert from 'assert';
4
+
5
+ import {checkSubtype, ValueType} from '../types';
6
+ import ResolvedImage from '../types/resolved_image';
7
+
8
+ import type {Expression} from '../expression';
9
+ import type ParsingContext from '../parsing_context';
10
+ import type EvaluationContext from '../evaluation_context';
11
+ import type {Type} from '../types';
12
+
13
+ class Coalesce implements Expression {
14
+ type: Type;
15
+ args: Array<Expression>;
16
+
17
+ constructor(type: Type, args: Array<Expression>) {
18
+ this.type = type;
19
+ this.args = args;
20
+ }
21
+
22
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
23
+ if (args.length < 2) {
24
+ return context.error("Expectected at least one argument.");
25
+ }
26
+ let outputType: Type = (null: any);
27
+ const expectedType = context.expectedType;
28
+ if (expectedType && expectedType.kind !== 'value') {
29
+ outputType = expectedType;
30
+ }
31
+ const parsedArgs = [];
32
+
33
+ for (const arg of args.slice(1)) {
34
+ const parsed = context.parse(arg, 1 + parsedArgs.length, outputType, undefined, {typeAnnotation: 'omit'});
35
+ if (!parsed) return null;
36
+ outputType = outputType || parsed.type;
37
+ parsedArgs.push(parsed);
38
+ }
39
+ assert(outputType);
40
+
41
+ // Above, we parse arguments without inferred type annotation so that
42
+ // they don't produce a runtime error for `null` input, which would
43
+ // preempt the desired null-coalescing behavior.
44
+ // Thus, if any of our arguments would have needed an annotation, we
45
+ // need to wrap the enclosing coalesce expression with it instead.
46
+ const needsAnnotation = expectedType &&
47
+ parsedArgs.some(arg => checkSubtype(expectedType, arg.type));
48
+
49
+ return needsAnnotation ?
50
+ new Coalesce(ValueType, parsedArgs) :
51
+ new Coalesce((outputType: any), parsedArgs);
52
+ }
53
+
54
+ evaluate(ctx: EvaluationContext) {
55
+ let result = null;
56
+ let argCount = 0;
57
+ let requestedImageName;
58
+ for (const arg of this.args) {
59
+ argCount++;
60
+ result = arg.evaluate(ctx);
61
+ // we need to keep track of the first requested image in a coalesce statement
62
+ // if coalesce can't find a valid image, we return the first image name so styleimagemissing can fire
63
+ if (result && result instanceof ResolvedImage && !result.available) {
64
+ if (!requestedImageName) {
65
+ requestedImageName = result.name;
66
+ }
67
+ result = null;
68
+ if (argCount === this.args.length) {
69
+ result = requestedImageName;
70
+ }
71
+ }
72
+
73
+ if (result !== null) break;
74
+ }
75
+ return result;
76
+ }
77
+
78
+ eachChild(fn: (_: Expression) => void) {
79
+ this.args.forEach(fn);
80
+ }
81
+
82
+ outputDefined(): boolean {
83
+ return this.args.every(arg => arg.outputDefined());
84
+ }
85
+
86
+ serialize() {
87
+ const serialized = ["coalesce"];
88
+ this.eachChild(child => { serialized.push(child.serialize()); });
89
+ return serialized;
90
+ }
91
+ }
92
+
93
+ export default Coalesce;
node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/coercion.js ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ import assert from 'assert';
4
+
5
+ import {BooleanType, ColorType, NumberType, StringType, ValueType} from '../types';
6
+ import {Color, toString as valueToString, validateRGBA} from '../values';
7
+ import RuntimeError from '../runtime_error';
8
+ import Formatted from '../types/formatted';
9
+ import FormatExpression from '../definitions/format';
10
+ import ImageExpression from '../definitions/image';
11
+ import ResolvedImage from '../types/resolved_image';
12
+
13
+ import type {Expression} from '../expression';
14
+ import type ParsingContext from '../parsing_context';
15
+ import type EvaluationContext from '../evaluation_context';
16
+ import type {Type} from '../types';
17
+
18
+ const types = {
19
+ 'to-boolean': BooleanType,
20
+ 'to-color': ColorType,
21
+ 'to-number': NumberType,
22
+ 'to-string': StringType
23
+ };
24
+
25
+ /**
26
+ * Special form for error-coalescing coercion expressions "to-number",
27
+ * "to-color". Since these coercions can fail at runtime, they accept multiple
28
+ * arguments, only evaluating one at a time until one succeeds.
29
+ *
30
+ * @private
31
+ */
32
+ class Coercion implements Expression {
33
+ type: Type;
34
+ args: Array<Expression>;
35
+
36
+ constructor(type: Type, args: Array<Expression>) {
37
+ this.type = type;
38
+ this.args = args;
39
+ }
40
+
41
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext): ?Expression {
42
+ if (args.length < 2)
43
+ return context.error(`Expected at least one argument.`);
44
+
45
+ const name: string = (args[0]: any);
46
+ assert(types[name], name);
47
+
48
+ if ((name === 'to-boolean' || name === 'to-string') && args.length !== 2)
49
+ return context.error(`Expected one argument.`);
50
+
51
+ const type = types[name];
52
+
53
+ const parsed = [];
54
+ for (let i = 1; i < args.length; i++) {
55
+ const input = context.parse(args[i], i, ValueType);
56
+ if (!input) return null;
57
+ parsed.push(input);
58
+ }
59
+
60
+ return new Coercion(type, parsed);
61
+ }
62
+
63
+ evaluate(ctx: EvaluationContext) {
64
+ if (this.type.kind === 'boolean') {
65
+ return Boolean(this.args[0].evaluate(ctx));
66
+ } else if (this.type.kind === 'color') {
67
+ let input;
68
+ let error;
69
+ for (const arg of this.args) {
70
+ input = arg.evaluate(ctx);
71
+ error = null;
72
+ if (input instanceof Color) {
73
+ return input;
74
+ } else if (typeof input === 'string') {
75
+ const c = ctx.parseColor(input);
76
+ if (c) return c;
77
+ } else if (Array.isArray(input)) {
78
+ if (input.length < 3 || input.length > 4) {
79
+ error = `Invalid rbga value ${JSON.stringify(input)}: expected an array containing either three or four numeric values.`;
80
+ } else {
81
+ error = validateRGBA(input[0], input[1], input[2], input[3]);
82
+ }
83
+ if (!error) {
84
+ return new Color((input[0]: any) / 255, (input[1]: any) / 255, (input[2]: any) / 255, (input[3]: any));
85
+ }
86
+ }
87
+ }
88
+ throw new RuntimeError(error || `Could not parse color from value '${typeof input === 'string' ? input : String(JSON.stringify(input))}'`);
89
+ } else if (this.type.kind === 'number') {
90
+ let value = null;
91
+ for (const arg of this.args) {
92
+ value = arg.evaluate(ctx);
93
+ if (value === null) return 0;
94
+ const num = Number(value);
95
+ if (isNaN(num)) continue;
96
+ return num;
97
+ }
98
+ throw new RuntimeError(`Could not convert ${JSON.stringify(value)} to number.`);
99
+ } else if (this.type.kind === 'formatted') {
100
+ // There is no explicit 'to-formatted' but this coercion can be implicitly
101
+ // created by properties that expect the 'formatted' type.
102
+ return Formatted.fromString(valueToString(this.args[0].evaluate(ctx)));
103
+ } else if (this.type.kind === 'resolvedImage') {
104
+ return ResolvedImage.fromString(valueToString(this.args[0].evaluate(ctx)));
105
+ } else {
106
+ return valueToString(this.args[0].evaluate(ctx));
107
+ }
108
+ }
109
+
110
+ eachChild(fn: (_: Expression) => void) {
111
+ this.args.forEach(fn);
112
+ }
113
+
114
+ outputDefined(): boolean {
115
+ return this.args.every(arg => arg.outputDefined());
116
+ }
117
+
118
+ serialize() {
119
+ if (this.type.kind === 'formatted') {
120
+ return new FormatExpression([{content: this.args[0], scale: null, font: null, textColor: null}]).serialize();
121
+ }
122
+
123
+ if (this.type.kind === 'resolvedImage') {
124
+ return new ImageExpression(this.args[0]).serialize();
125
+ }
126
+
127
+ const serialized = [`to-${this.type.kind}`];
128
+ this.eachChild(child => { serialized.push(child.serialize()); });
129
+ return serialized;
130
+ }
131
+ }
132
+
133
+ export default Coercion;
node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/collator.js ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ import {StringType, BooleanType, CollatorType} from '../types';
4
+ import Collator from '../types/collator';
5
+
6
+ import type {Expression} from '../expression';
7
+ import type EvaluationContext from '../evaluation_context';
8
+ import type ParsingContext from '../parsing_context';
9
+ import type {Type} from '../types';
10
+
11
+ export default class CollatorExpression implements Expression {
12
+ type: Type;
13
+ caseSensitive: Expression;
14
+ diacriticSensitive: Expression;
15
+ locale: Expression | null;
16
+
17
+ constructor(caseSensitive: Expression, diacriticSensitive: Expression, locale: Expression | null) {
18
+ this.type = CollatorType;
19
+ this.locale = locale;
20
+ this.caseSensitive = caseSensitive;
21
+ this.diacriticSensitive = diacriticSensitive;
22
+ }
23
+
24
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext): ?Expression {
25
+ if (args.length !== 2)
26
+ return context.error(`Expected one argument.`);
27
+
28
+ const options = (args[1]: any);
29
+ if (typeof options !== "object" || Array.isArray(options))
30
+ return context.error(`Collator options argument must be an object.`);
31
+
32
+ const caseSensitive = context.parse(
33
+ options['case-sensitive'] === undefined ? false : options['case-sensitive'], 1, BooleanType);
34
+ if (!caseSensitive) return null;
35
+
36
+ const diacriticSensitive = context.parse(
37
+ options['diacritic-sensitive'] === undefined ? false : options['diacritic-sensitive'], 1, BooleanType);
38
+ if (!diacriticSensitive) return null;
39
+
40
+ let locale = null;
41
+ if (options['locale']) {
42
+ locale = context.parse(options['locale'], 1, StringType);
43
+ if (!locale) return null;
44
+ }
45
+
46
+ return new CollatorExpression(caseSensitive, diacriticSensitive, locale);
47
+ }
48
+
49
+ evaluate(ctx: EvaluationContext) {
50
+ return new Collator(this.caseSensitive.evaluate(ctx), this.diacriticSensitive.evaluate(ctx), this.locale ? this.locale.evaluate(ctx) : null);
51
+ }
52
+
53
+ eachChild(fn: (_: Expression) => void) {
54
+ fn(this.caseSensitive);
55
+ fn(this.diacriticSensitive);
56
+ if (this.locale) {
57
+ fn(this.locale);
58
+ }
59
+ }
60
+
61
+ outputDefined() {
62
+ // Technically the set of possible outputs is the combinatoric set of Collators produced
63
+ // by all possible outputs of locale/caseSensitive/diacriticSensitive
64
+ // But for the primary use of Collators in comparison operators, we ignore the Collator's
65
+ // possible outputs anyway, so we can get away with leaving this false for now.
66
+ return false;
67
+ }
68
+
69
+ serialize() {
70
+ const options = {};
71
+ options['case-sensitive'] = this.caseSensitive.serialize();
72
+ options['diacritic-sensitive'] = this.diacriticSensitive.serialize();
73
+ if (this.locale) {
74
+ options['locale'] = this.locale.serialize();
75
+ }
76
+ return ["collator", options];
77
+ }
78
+ }
node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/comparison.js ADDED
@@ -0,0 +1,184 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ import {toString, ValueType, BooleanType, CollatorType} from '../types';
4
+ import Assertion from './assertion';
5
+ import {typeOf} from '../values';
6
+ import RuntimeError from '../runtime_error';
7
+
8
+ import type {Expression} from '../expression';
9
+ import type EvaluationContext from '../evaluation_context';
10
+ import type ParsingContext from '../parsing_context';
11
+ import type {Type} from '../types';
12
+
13
+ type ComparisonOperator = '==' | '!=' | '<' | '>' | '<=' | '>=' ;
14
+
15
+ function isComparableType(op: ComparisonOperator, type: Type) {
16
+ if (op === '==' || op === '!=') {
17
+ // equality operator
18
+ return type.kind === 'boolean' ||
19
+ type.kind === 'string' ||
20
+ type.kind === 'number' ||
21
+ type.kind === 'null' ||
22
+ type.kind === 'value';
23
+ } else {
24
+ // ordering operator
25
+ return type.kind === 'string' ||
26
+ type.kind === 'number' ||
27
+ type.kind === 'value';
28
+ }
29
+ }
30
+
31
+ function eq(ctx, a, b) { return a === b; }
32
+ function neq(ctx, a, b) { return a !== b; }
33
+ function lt(ctx, a, b) { return a < b; }
34
+ function gt(ctx, a, b) { return a > b; }
35
+ function lteq(ctx, a, b) { return a <= b; }
36
+ function gteq(ctx, a, b) { return a >= b; }
37
+
38
+ function eqCollate(ctx, a, b, c) { return c.compare(a, b) === 0; }
39
+ function neqCollate(ctx, a, b, c) { return !eqCollate(ctx, a, b, c); }
40
+ function ltCollate(ctx, a, b, c) { return c.compare(a, b) < 0; }
41
+ function gtCollate(ctx, a, b, c) { return c.compare(a, b) > 0; }
42
+ function lteqCollate(ctx, a, b, c) { return c.compare(a, b) <= 0; }
43
+ function gteqCollate(ctx, a, b, c) { return c.compare(a, b) >= 0; }
44
+
45
+ /**
46
+ * Special form for comparison operators, implementing the signatures:
47
+ * - (T, T, ?Collator) => boolean
48
+ * - (T, value, ?Collator) => boolean
49
+ * - (value, T, ?Collator) => boolean
50
+ *
51
+ * For inequalities, T must be either value, string, or number. For ==/!=, it
52
+ * can also be boolean or null.
53
+ *
54
+ * Equality semantics are equivalent to Javascript's strict equality (===/!==)
55
+ * -- i.e., when the arguments' types don't match, == evaluates to false, != to
56
+ * true.
57
+ *
58
+ * When types don't match in an ordering comparison, a runtime error is thrown.
59
+ *
60
+ * @private
61
+ */
62
+ function makeComparison(op: ComparisonOperator, compareBasic, compareWithCollator) {
63
+ const isOrderComparison = op !== '==' && op !== '!=';
64
+
65
+ return class Comparison implements Expression {
66
+ type: Type;
67
+ lhs: Expression;
68
+ rhs: Expression;
69
+ collator: ?Expression;
70
+ hasUntypedArgument: boolean;
71
+
72
+ constructor(lhs: Expression, rhs: Expression, collator: ?Expression) {
73
+ this.type = BooleanType;
74
+ this.lhs = lhs;
75
+ this.rhs = rhs;
76
+ this.collator = collator;
77
+ this.hasUntypedArgument = lhs.type.kind === 'value' || rhs.type.kind === 'value';
78
+ }
79
+
80
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext): ?Expression {
81
+ if (args.length !== 3 && args.length !== 4)
82
+ return context.error(`Expected two or three arguments.`);
83
+
84
+ const op: ComparisonOperator = (args[0]: any);
85
+
86
+ let lhs = context.parse(args[1], 1, ValueType);
87
+ if (!lhs) return null;
88
+ if (!isComparableType(op, lhs.type)) {
89
+ return context.concat(1).error(`"${op}" comparisons are not supported for type '${toString(lhs.type)}'.`);
90
+ }
91
+ let rhs = context.parse(args[2], 2, ValueType);
92
+ if (!rhs) return null;
93
+ if (!isComparableType(op, rhs.type)) {
94
+ return context.concat(2).error(`"${op}" comparisons are not supported for type '${toString(rhs.type)}'.`);
95
+ }
96
+
97
+ if (
98
+ lhs.type.kind !== rhs.type.kind &&
99
+ lhs.type.kind !== 'value' &&
100
+ rhs.type.kind !== 'value'
101
+ ) {
102
+ return context.error(`Cannot compare types '${toString(lhs.type)}' and '${toString(rhs.type)}'.`);
103
+ }
104
+
105
+ if (isOrderComparison) {
106
+ // typing rules specific to less/greater than operators
107
+ if (lhs.type.kind === 'value' && rhs.type.kind !== 'value') {
108
+ // (value, T)
109
+ lhs = new Assertion(rhs.type, [lhs]);
110
+ } else if (lhs.type.kind !== 'value' && rhs.type.kind === 'value') {
111
+ // (T, value)
112
+ rhs = new Assertion(lhs.type, [rhs]);
113
+ }
114
+ }
115
+
116
+ let collator = null;
117
+ if (args.length === 4) {
118
+ if (
119
+ lhs.type.kind !== 'string' &&
120
+ rhs.type.kind !== 'string' &&
121
+ lhs.type.kind !== 'value' &&
122
+ rhs.type.kind !== 'value'
123
+ ) {
124
+ return context.error(`Cannot use collator to compare non-string types.`);
125
+ }
126
+ collator = context.parse(args[3], 3, CollatorType);
127
+ if (!collator) return null;
128
+ }
129
+
130
+ return new Comparison(lhs, rhs, collator);
131
+ }
132
+
133
+ evaluate(ctx: EvaluationContext) {
134
+ const lhs = this.lhs.evaluate(ctx);
135
+ const rhs = this.rhs.evaluate(ctx);
136
+
137
+ if (isOrderComparison && this.hasUntypedArgument) {
138
+ const lt = typeOf(lhs);
139
+ const rt = typeOf(rhs);
140
+ // check that type is string or number, and equal
141
+ if (lt.kind !== rt.kind || !(lt.kind === 'string' || lt.kind === 'number')) {
142
+ throw new RuntimeError(`Expected arguments for "${op}" to be (string, string) or (number, number), but found (${lt.kind}, ${rt.kind}) instead.`);
143
+ }
144
+ }
145
+
146
+ if (this.collator && !isOrderComparison && this.hasUntypedArgument) {
147
+ const lt = typeOf(lhs);
148
+ const rt = typeOf(rhs);
149
+ if (lt.kind !== 'string' || rt.kind !== 'string') {
150
+ return compareBasic(ctx, lhs, rhs);
151
+ }
152
+ }
153
+
154
+ return this.collator ?
155
+ compareWithCollator(ctx, lhs, rhs, this.collator.evaluate(ctx)) :
156
+ compareBasic(ctx, lhs, rhs);
157
+ }
158
+
159
+ eachChild(fn: (_: Expression) => void) {
160
+ fn(this.lhs);
161
+ fn(this.rhs);
162
+ if (this.collator) {
163
+ fn(this.collator);
164
+ }
165
+ }
166
+
167
+ outputDefined(): boolean {
168
+ return true;
169
+ }
170
+
171
+ serialize() {
172
+ const serialized = [op];
173
+ this.eachChild(child => { serialized.push(child.serialize()); });
174
+ return serialized;
175
+ }
176
+ };
177
+ }
178
+
179
+ export const Equals = makeComparison('==', eq, eqCollate);
180
+ export const NotEquals = makeComparison('!=', neq, neqCollate);
181
+ export const LessThan = makeComparison('<', lt, ltCollate);
182
+ export const GreaterThan = makeComparison('>', gt, gtCollate);
183
+ export const LessThanOrEqual = makeComparison('<=', lteq, lteqCollate);
184
+ export const GreaterThanOrEqual = makeComparison('>=', gteq, gteqCollate);
node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/format.js ADDED
@@ -0,0 +1,144 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ import {NumberType, ValueType, FormattedType, array, StringType, ColorType, ResolvedImageType} from '../types';
4
+ import Formatted, {FormattedSection} from '../types/formatted';
5
+ import {toString, typeOf} from '../values';
6
+
7
+ import type {Expression} from '../expression';
8
+ import type EvaluationContext from '../evaluation_context';
9
+ import type ParsingContext from '../parsing_context';
10
+ import type {Type} from '../types';
11
+
12
+ type FormattedSectionExpression = {
13
+ // Content of a section may be Image expression or other
14
+ // type of expression that is coercable to 'string'.
15
+ content: Expression,
16
+ scale: Expression | null;
17
+ font: Expression | null;
18
+ textColor: Expression | null;
19
+ }
20
+
21
+ export default class FormatExpression implements Expression {
22
+ type: Type;
23
+ sections: Array<FormattedSectionExpression>;
24
+
25
+ constructor(sections: Array<FormattedSectionExpression>) {
26
+ this.type = FormattedType;
27
+ this.sections = sections;
28
+ }
29
+
30
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext): ?Expression {
31
+ if (args.length < 2) {
32
+ return context.error(`Expected at least one argument.`);
33
+ }
34
+
35
+ const firstArg = args[1];
36
+ if (!Array.isArray(firstArg) && typeof firstArg === 'object') {
37
+ return context.error(`First argument must be an image or text section.`);
38
+ }
39
+
40
+ const sections: Array<FormattedSectionExpression> = [];
41
+ let nextTokenMayBeObject = false;
42
+ for (let i = 1; i <= args.length - 1; ++i) {
43
+ const arg = (args[i]: any);
44
+
45
+ if (nextTokenMayBeObject && typeof arg === "object" && !Array.isArray(arg)) {
46
+ nextTokenMayBeObject = false;
47
+
48
+ let scale = null;
49
+ if (arg['font-scale']) {
50
+ scale = context.parse(arg['font-scale'], 1, NumberType);
51
+ if (!scale) return null;
52
+ }
53
+
54
+ let font = null;
55
+ if (arg['text-font']) {
56
+ font = context.parse(arg['text-font'], 1, array(StringType));
57
+ if (!font) return null;
58
+ }
59
+
60
+ let textColor = null;
61
+ if (arg['text-color']) {
62
+ textColor = context.parse(arg['text-color'], 1, ColorType);
63
+ if (!textColor) return null;
64
+ }
65
+
66
+ const lastExpression = sections[sections.length - 1];
67
+ lastExpression.scale = scale;
68
+ lastExpression.font = font;
69
+ lastExpression.textColor = textColor;
70
+ } else {
71
+ const content = context.parse(args[i], 1, ValueType);
72
+ if (!content) return null;
73
+
74
+ const kind = content.type.kind;
75
+ if (kind !== 'string' && kind !== 'value' && kind !== 'null' && kind !== 'resolvedImage')
76
+ return context.error(`Formatted text type must be 'string', 'value', 'image' or 'null'.`);
77
+
78
+ nextTokenMayBeObject = true;
79
+ sections.push({content, scale: null, font: null, textColor: null});
80
+ }
81
+ }
82
+
83
+ return new FormatExpression(sections);
84
+ }
85
+
86
+ evaluate(ctx: EvaluationContext) {
87
+ const evaluateSection = section => {
88
+ const evaluatedContent = section.content.evaluate(ctx);
89
+ if (typeOf(evaluatedContent) === ResolvedImageType) {
90
+ return new FormattedSection('', evaluatedContent, null, null, null);
91
+ }
92
+
93
+ return new FormattedSection(
94
+ toString(evaluatedContent),
95
+ null,
96
+ section.scale ? section.scale.evaluate(ctx) : null,
97
+ section.font ? section.font.evaluate(ctx).join(',') : null,
98
+ section.textColor ? section.textColor.evaluate(ctx) : null
99
+ );
100
+ };
101
+
102
+ return new Formatted(this.sections.map(evaluateSection));
103
+ }
104
+
105
+ eachChild(fn: (_: Expression) => void) {
106
+ for (const section of this.sections) {
107
+ fn(section.content);
108
+ if (section.scale) {
109
+ fn(section.scale);
110
+ }
111
+ if (section.font) {
112
+ fn(section.font);
113
+ }
114
+ if (section.textColor) {
115
+ fn(section.textColor);
116
+ }
117
+ }
118
+ }
119
+
120
+ outputDefined() {
121
+ // Technically the combinatoric set of all children
122
+ // Usually, this.text will be undefined anyway
123
+ return false;
124
+ }
125
+
126
+ serialize() {
127
+ const serialized = ["format"];
128
+ for (const section of this.sections) {
129
+ serialized.push(section.content.serialize());
130
+ const options = {};
131
+ if (section.scale) {
132
+ options['font-scale'] = section.scale.serialize();
133
+ }
134
+ if (section.font) {
135
+ options['text-font'] = section.font.serialize();
136
+ }
137
+ if (section.textColor) {
138
+ options['text-color'] = section.textColor.serialize();
139
+ }
140
+ serialized.push(options);
141
+ }
142
+ return serialized;
143
+ }
144
+ }
node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/image.js ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ import {ResolvedImageType, StringType} from '../types';
4
+ import ResolvedImage from '../types/resolved_image';
5
+
6
+ import type {Expression} from '../expression';
7
+ import type EvaluationContext from '../evaluation_context';
8
+ import type ParsingContext from '../parsing_context';
9
+ import type {Type} from '../types';
10
+
11
+ export default class ImageExpression implements Expression {
12
+ type: Type;
13
+ input: Expression;
14
+
15
+ constructor(input: Expression) {
16
+ this.type = ResolvedImageType;
17
+ this.input = input;
18
+ }
19
+
20
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext): ?Expression {
21
+ if (args.length !== 2) {
22
+ return context.error(`Expected two arguments.`);
23
+ }
24
+
25
+ const name = context.parse(args[1], 1, StringType);
26
+ if (!name) return context.error(`No image name provided.`);
27
+
28
+ return new ImageExpression(name);
29
+ }
30
+
31
+ evaluate(ctx: EvaluationContext) {
32
+ const evaluatedImageName = this.input.evaluate(ctx);
33
+
34
+ const value = ResolvedImage.fromString(evaluatedImageName);
35
+ if (value && ctx.availableImages) value.available = ctx.availableImages.indexOf(evaluatedImageName) > -1;
36
+
37
+ return value;
38
+ }
39
+
40
+ eachChild(fn: (_: Expression) => void) {
41
+ fn(this.input);
42
+ }
43
+
44
+ outputDefined() {
45
+ // The output of image is determined by the list of available images in the evaluation context
46
+ return false;
47
+ }
48
+
49
+ serialize() {
50
+ return ["image", this.input.serialize()];
51
+ }
52
+ }
node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/in.js ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ import {BooleanType, StringType, ValueType, NullType, toString, NumberType, isValidType, isValidNativeType} from '../types';
4
+ import RuntimeError from '../runtime_error';
5
+ import {typeOf} from '../values';
6
+
7
+ import type {Expression} from '../expression';
8
+ import type ParsingContext from '../parsing_context';
9
+ import type EvaluationContext from '../evaluation_context';
10
+ import type {Type} from '../types';
11
+
12
+ class In implements Expression {
13
+ type: Type;
14
+ needle: Expression;
15
+ haystack: Expression;
16
+
17
+ constructor(needle: Expression, haystack: Expression) {
18
+ this.type = BooleanType;
19
+ this.needle = needle;
20
+ this.haystack = haystack;
21
+ }
22
+
23
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
24
+ if (args.length !== 3) {
25
+ return context.error(`Expected 2 arguments, but found ${args.length - 1} instead.`);
26
+ }
27
+
28
+ const needle = context.parse(args[1], 1, ValueType);
29
+
30
+ const haystack = context.parse(args[2], 2, ValueType);
31
+
32
+ if (!needle || !haystack) return null;
33
+
34
+ if (!isValidType(needle.type, [BooleanType, StringType, NumberType, NullType, ValueType])) {
35
+ return context.error(`Expected first argument to be of type boolean, string, number or null, but found ${toString(needle.type)} instead`);
36
+ }
37
+
38
+ return new In(needle, haystack);
39
+ }
40
+
41
+ evaluate(ctx: EvaluationContext) {
42
+ const needle = (this.needle.evaluate(ctx): any);
43
+ const haystack = (this.haystack.evaluate(ctx): any);
44
+
45
+ if (!haystack) return false;
46
+
47
+ if (!isValidNativeType(needle, ['boolean', 'string', 'number', 'null'])) {
48
+ throw new RuntimeError(`Expected first argument to be of type boolean, string, number or null, but found ${toString(typeOf(needle))} instead.`);
49
+ }
50
+
51
+ if (!isValidNativeType(haystack, ['string', 'array'])) {
52
+ throw new RuntimeError(`Expected second argument to be of type array or string, but found ${toString(typeOf(haystack))} instead.`);
53
+ }
54
+
55
+ return haystack.indexOf(needle) >= 0;
56
+ }
57
+
58
+ eachChild(fn: (_: Expression) => void) {
59
+ fn(this.needle);
60
+ fn(this.haystack);
61
+ }
62
+
63
+ outputDefined() {
64
+ return true;
65
+ }
66
+
67
+ serialize() {
68
+ return ["in", this.needle.serialize(), this.haystack.serialize()];
69
+ }
70
+ }
71
+
72
+ export default In;
node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/index.js ADDED
@@ -0,0 +1,565 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ import {
4
+ type Type,
5
+ NumberType,
6
+ StringType,
7
+ BooleanType,
8
+ ColorType,
9
+ ObjectType,
10
+ ValueType,
11
+ ErrorType,
12
+ CollatorType,
13
+ array,
14
+ toString as typeToString
15
+ } from '../types';
16
+
17
+ import {typeOf, Color, validateRGBA, toString as valueToString} from '../values';
18
+ import CompoundExpression from '../compound_expression';
19
+ import RuntimeError from '../runtime_error';
20
+ import Let from './let';
21
+ import Var from './var';
22
+ import Literal from './literal';
23
+ import Assertion from './assertion';
24
+ import Coercion from './coercion';
25
+ import At from './at';
26
+ import In from './in';
27
+ import IndexOf from './index_of';
28
+ import Match from './match';
29
+ import Case from './case';
30
+ import Slice from './slice';
31
+ import Step from './step';
32
+ import Interpolate from './interpolate';
33
+ import Coalesce from './coalesce';
34
+ import {
35
+ Equals,
36
+ NotEquals,
37
+ LessThan,
38
+ GreaterThan,
39
+ LessThanOrEqual,
40
+ GreaterThanOrEqual
41
+ } from './comparison';
42
+ import CollatorExpression from './collator';
43
+ import NumberFormat from './number_format';
44
+ import FormatExpression from './format';
45
+ import ImageExpression from './image';
46
+ import Length from './length';
47
+ import Within from './within';
48
+
49
+ import type {Varargs} from '../compound_expression';
50
+ import type {ExpressionRegistry} from '../expression';
51
+
52
+ const expressions: ExpressionRegistry = {
53
+ // special forms
54
+ '==': Equals,
55
+ '!=': NotEquals,
56
+ '>': GreaterThan,
57
+ '<': LessThan,
58
+ '>=': GreaterThanOrEqual,
59
+ '<=': LessThanOrEqual,
60
+ 'array': Assertion,
61
+ 'at': At,
62
+ 'boolean': Assertion,
63
+ 'case': Case,
64
+ 'coalesce': Coalesce,
65
+ 'collator': CollatorExpression,
66
+ 'format': FormatExpression,
67
+ 'image': ImageExpression,
68
+ 'in': In,
69
+ 'index-of': IndexOf,
70
+ 'interpolate': Interpolate,
71
+ 'interpolate-hcl': Interpolate,
72
+ 'interpolate-lab': Interpolate,
73
+ 'length': Length,
74
+ 'let': Let,
75
+ 'literal': Literal,
76
+ 'match': Match,
77
+ 'number': Assertion,
78
+ 'number-format': NumberFormat,
79
+ 'object': Assertion,
80
+ 'slice': Slice,
81
+ 'step': Step,
82
+ 'string': Assertion,
83
+ 'to-boolean': Coercion,
84
+ 'to-color': Coercion,
85
+ 'to-number': Coercion,
86
+ 'to-string': Coercion,
87
+ 'var': Var,
88
+ 'within': Within
89
+ };
90
+
91
+ function rgba(ctx, [r, g, b, a]) {
92
+ r = r.evaluate(ctx);
93
+ g = g.evaluate(ctx);
94
+ b = b.evaluate(ctx);
95
+ const alpha = a ? a.evaluate(ctx) : 1;
96
+ const error = validateRGBA(r, g, b, alpha);
97
+ if (error) throw new RuntimeError(error);
98
+ return new Color(r / 255 * alpha, g / 255 * alpha, b / 255 * alpha, alpha);
99
+ }
100
+
101
+ function has(key, obj) {
102
+ return key in obj;
103
+ }
104
+
105
+ function get(key, obj) {
106
+ const v = obj[key];
107
+ return typeof v === 'undefined' ? null : v;
108
+ }
109
+
110
+ function binarySearch(v, a, i, j) {
111
+ while (i <= j) {
112
+ const m = (i + j) >> 1;
113
+ if (a[m] === v)
114
+ return true;
115
+ if (a[m] > v)
116
+ j = m - 1;
117
+ else
118
+ i = m + 1;
119
+ }
120
+ return false;
121
+ }
122
+
123
+ function varargs(type: Type): Varargs {
124
+ return {type};
125
+ }
126
+
127
+ CompoundExpression.register(expressions, {
128
+ 'error': [
129
+ ErrorType,
130
+ [StringType],
131
+ (ctx, [v]) => { throw new RuntimeError(v.evaluate(ctx)); }
132
+ ],
133
+ 'typeof': [
134
+ StringType,
135
+ [ValueType],
136
+ (ctx, [v]) => typeToString(typeOf(v.evaluate(ctx)))
137
+ ],
138
+ 'to-rgba': [
139
+ array(NumberType, 4),
140
+ [ColorType],
141
+ (ctx, [v]) => {
142
+ return v.evaluate(ctx).toArray();
143
+ }
144
+ ],
145
+ 'rgb': [
146
+ ColorType,
147
+ [NumberType, NumberType, NumberType],
148
+ rgba
149
+ ],
150
+ 'rgba': [
151
+ ColorType,
152
+ [NumberType, NumberType, NumberType, NumberType],
153
+ rgba
154
+ ],
155
+ 'has': {
156
+ type: BooleanType,
157
+ overloads: [
158
+ [
159
+ [StringType],
160
+ (ctx, [key]) => has(key.evaluate(ctx), ctx.properties())
161
+ ], [
162
+ [StringType, ObjectType],
163
+ (ctx, [key, obj]) => has(key.evaluate(ctx), obj.evaluate(ctx))
164
+ ]
165
+ ]
166
+ },
167
+ 'get': {
168
+ type: ValueType,
169
+ overloads: [
170
+ [
171
+ [StringType],
172
+ (ctx, [key]) => get(key.evaluate(ctx), ctx.properties())
173
+ ], [
174
+ [StringType, ObjectType],
175
+ (ctx, [key, obj]) => get(key.evaluate(ctx), obj.evaluate(ctx))
176
+ ]
177
+ ]
178
+ },
179
+ 'feature-state': [
180
+ ValueType,
181
+ [StringType],
182
+ (ctx, [key]) => get(key.evaluate(ctx), ctx.featureState || {})
183
+ ],
184
+ 'properties': [
185
+ ObjectType,
186
+ [],
187
+ (ctx) => ctx.properties()
188
+ ],
189
+ 'geometry-type': [
190
+ StringType,
191
+ [],
192
+ (ctx) => ctx.geometryType()
193
+ ],
194
+ 'id': [
195
+ ValueType,
196
+ [],
197
+ (ctx) => ctx.id()
198
+ ],
199
+ 'zoom': [
200
+ NumberType,
201
+ [],
202
+ (ctx) => ctx.globals.zoom
203
+ ],
204
+ 'heatmap-density': [
205
+ NumberType,
206
+ [],
207
+ (ctx) => ctx.globals.heatmapDensity || 0
208
+ ],
209
+ 'line-progress': [
210
+ NumberType,
211
+ [],
212
+ (ctx) => ctx.globals.lineProgress || 0
213
+ ],
214
+ 'accumulated': [
215
+ ValueType,
216
+ [],
217
+ (ctx) => ctx.globals.accumulated === undefined ? null : ctx.globals.accumulated
218
+ ],
219
+ '+': [
220
+ NumberType,
221
+ varargs(NumberType),
222
+ (ctx, args) => {
223
+ let result = 0;
224
+ for (const arg of args) {
225
+ result += arg.evaluate(ctx);
226
+ }
227
+ return result;
228
+ }
229
+ ],
230
+ '*': [
231
+ NumberType,
232
+ varargs(NumberType),
233
+ (ctx, args) => {
234
+ let result = 1;
235
+ for (const arg of args) {
236
+ result *= arg.evaluate(ctx);
237
+ }
238
+ return result;
239
+ }
240
+ ],
241
+ '-': {
242
+ type: NumberType,
243
+ overloads: [
244
+ [
245
+ [NumberType, NumberType],
246
+ (ctx, [a, b]) => a.evaluate(ctx) - b.evaluate(ctx)
247
+ ], [
248
+ [NumberType],
249
+ (ctx, [a]) => -a.evaluate(ctx)
250
+ ]
251
+ ]
252
+ },
253
+ '/': [
254
+ NumberType,
255
+ [NumberType, NumberType],
256
+ (ctx, [a, b]) => a.evaluate(ctx) / b.evaluate(ctx)
257
+ ],
258
+ '%': [
259
+ NumberType,
260
+ [NumberType, NumberType],
261
+ (ctx, [a, b]) => a.evaluate(ctx) % b.evaluate(ctx)
262
+ ],
263
+ 'ln2': [
264
+ NumberType,
265
+ [],
266
+ () => Math.LN2
267
+ ],
268
+ 'pi': [
269
+ NumberType,
270
+ [],
271
+ () => Math.PI
272
+ ],
273
+ 'e': [
274
+ NumberType,
275
+ [],
276
+ () => Math.E
277
+ ],
278
+ '^': [
279
+ NumberType,
280
+ [NumberType, NumberType],
281
+ (ctx, [b, e]) => Math.pow(b.evaluate(ctx), e.evaluate(ctx))
282
+ ],
283
+ 'sqrt': [
284
+ NumberType,
285
+ [NumberType],
286
+ (ctx, [x]) => Math.sqrt(x.evaluate(ctx))
287
+ ],
288
+ 'log10': [
289
+ NumberType,
290
+ [NumberType],
291
+ (ctx, [n]) => Math.log(n.evaluate(ctx)) / Math.LN10
292
+ ],
293
+ 'ln': [
294
+ NumberType,
295
+ [NumberType],
296
+ (ctx, [n]) => Math.log(n.evaluate(ctx))
297
+ ],
298
+ 'log2': [
299
+ NumberType,
300
+ [NumberType],
301
+ (ctx, [n]) => Math.log(n.evaluate(ctx)) / Math.LN2
302
+ ],
303
+ 'sin': [
304
+ NumberType,
305
+ [NumberType],
306
+ (ctx, [n]) => Math.sin(n.evaluate(ctx))
307
+ ],
308
+ 'cos': [
309
+ NumberType,
310
+ [NumberType],
311
+ (ctx, [n]) => Math.cos(n.evaluate(ctx))
312
+ ],
313
+ 'tan': [
314
+ NumberType,
315
+ [NumberType],
316
+ (ctx, [n]) => Math.tan(n.evaluate(ctx))
317
+ ],
318
+ 'asin': [
319
+ NumberType,
320
+ [NumberType],
321
+ (ctx, [n]) => Math.asin(n.evaluate(ctx))
322
+ ],
323
+ 'acos': [
324
+ NumberType,
325
+ [NumberType],
326
+ (ctx, [n]) => Math.acos(n.evaluate(ctx))
327
+ ],
328
+ 'atan': [
329
+ NumberType,
330
+ [NumberType],
331
+ (ctx, [n]) => Math.atan(n.evaluate(ctx))
332
+ ],
333
+ 'min': [
334
+ NumberType,
335
+ varargs(NumberType),
336
+ (ctx, args) => Math.min(...args.map(arg => arg.evaluate(ctx)))
337
+ ],
338
+ 'max': [
339
+ NumberType,
340
+ varargs(NumberType),
341
+ (ctx, args) => Math.max(...args.map(arg => arg.evaluate(ctx)))
342
+ ],
343
+ 'abs': [
344
+ NumberType,
345
+ [NumberType],
346
+ (ctx, [n]) => Math.abs(n.evaluate(ctx))
347
+ ],
348
+ 'round': [
349
+ NumberType,
350
+ [NumberType],
351
+ (ctx, [n]) => {
352
+ const v = n.evaluate(ctx);
353
+ // Javascript's Math.round() rounds towards +Infinity for halfway
354
+ // values, even when they're negative. It's more common to round
355
+ // away from 0 (e.g., this is what python and C++ do)
356
+ return v < 0 ? -Math.round(-v) : Math.round(v);
357
+ }
358
+ ],
359
+ 'floor': [
360
+ NumberType,
361
+ [NumberType],
362
+ (ctx, [n]) => Math.floor(n.evaluate(ctx))
363
+ ],
364
+ 'ceil': [
365
+ NumberType,
366
+ [NumberType],
367
+ (ctx, [n]) => Math.ceil(n.evaluate(ctx))
368
+ ],
369
+ 'filter-==': [
370
+ BooleanType,
371
+ [StringType, ValueType],
372
+ (ctx, [k, v]) => ctx.properties()[(k: any).value] === (v: any).value
373
+ ],
374
+ 'filter-id-==': [
375
+ BooleanType,
376
+ [ValueType],
377
+ (ctx, [v]) => ctx.id() === (v: any).value
378
+ ],
379
+ 'filter-type-==': [
380
+ BooleanType,
381
+ [StringType],
382
+ (ctx, [v]) => ctx.geometryType() === (v: any).value
383
+ ],
384
+ 'filter-<': [
385
+ BooleanType,
386
+ [StringType, ValueType],
387
+ (ctx, [k, v]) => {
388
+ const a = ctx.properties()[(k: any).value];
389
+ const b = (v: any).value;
390
+ return typeof a === typeof b && a < b;
391
+ }
392
+ ],
393
+ 'filter-id-<': [
394
+ BooleanType,
395
+ [ValueType],
396
+ (ctx, [v]) => {
397
+ const a = ctx.id();
398
+ const b = (v: any).value;
399
+ return typeof a === typeof b && a < b;
400
+ }
401
+ ],
402
+ 'filter->': [
403
+ BooleanType,
404
+ [StringType, ValueType],
405
+ (ctx, [k, v]) => {
406
+ const a = ctx.properties()[(k: any).value];
407
+ const b = (v: any).value;
408
+ return typeof a === typeof b && a > b;
409
+ }
410
+ ],
411
+ 'filter-id->': [
412
+ BooleanType,
413
+ [ValueType],
414
+ (ctx, [v]) => {
415
+ const a = ctx.id();
416
+ const b = (v: any).value;
417
+ return typeof a === typeof b && a > b;
418
+ }
419
+ ],
420
+ 'filter-<=': [
421
+ BooleanType,
422
+ [StringType, ValueType],
423
+ (ctx, [k, v]) => {
424
+ const a = ctx.properties()[(k: any).value];
425
+ const b = (v: any).value;
426
+ return typeof a === typeof b && a <= b;
427
+ }
428
+ ],
429
+ 'filter-id-<=': [
430
+ BooleanType,
431
+ [ValueType],
432
+ (ctx, [v]) => {
433
+ const a = ctx.id();
434
+ const b = (v: any).value;
435
+ return typeof a === typeof b && a <= b;
436
+ }
437
+ ],
438
+ 'filter->=': [
439
+ BooleanType,
440
+ [StringType, ValueType],
441
+ (ctx, [k, v]) => {
442
+ const a = ctx.properties()[(k: any).value];
443
+ const b = (v: any).value;
444
+ return typeof a === typeof b && a >= b;
445
+ }
446
+ ],
447
+ 'filter-id->=': [
448
+ BooleanType,
449
+ [ValueType],
450
+ (ctx, [v]) => {
451
+ const a = ctx.id();
452
+ const b = (v: any).value;
453
+ return typeof a === typeof b && a >= b;
454
+ }
455
+ ],
456
+ 'filter-has': [
457
+ BooleanType,
458
+ [ValueType],
459
+ (ctx, [k]) => (k: any).value in ctx.properties()
460
+ ],
461
+ 'filter-has-id': [
462
+ BooleanType,
463
+ [],
464
+ (ctx) => (ctx.id() !== null && ctx.id() !== undefined)
465
+ ],
466
+ 'filter-type-in': [
467
+ BooleanType,
468
+ [array(StringType)],
469
+ (ctx, [v]) => (v: any).value.indexOf(ctx.geometryType()) >= 0
470
+ ],
471
+ 'filter-id-in': [
472
+ BooleanType,
473
+ [array(ValueType)],
474
+ (ctx, [v]) => (v: any).value.indexOf(ctx.id()) >= 0
475
+ ],
476
+ 'filter-in-small': [
477
+ BooleanType,
478
+ [StringType, array(ValueType)],
479
+ // assumes v is an array literal
480
+ (ctx, [k, v]) => (v: any).value.indexOf(ctx.properties()[(k: any).value]) >= 0
481
+ ],
482
+ 'filter-in-large': [
483
+ BooleanType,
484
+ [StringType, array(ValueType)],
485
+ // assumes v is a array literal with values sorted in ascending order and of a single type
486
+ (ctx, [k, v]) => binarySearch(ctx.properties()[(k: any).value], (v: any).value, 0, (v: any).value.length - 1)
487
+ ],
488
+ 'all': {
489
+ type: BooleanType,
490
+ overloads: [
491
+ [
492
+ [BooleanType, BooleanType],
493
+ (ctx, [a, b]) => a.evaluate(ctx) && b.evaluate(ctx)
494
+ ],
495
+ [
496
+ varargs(BooleanType),
497
+ (ctx, args) => {
498
+ for (const arg of args) {
499
+ if (!arg.evaluate(ctx))
500
+ return false;
501
+ }
502
+ return true;
503
+ }
504
+ ]
505
+ ]
506
+ },
507
+ 'any': {
508
+ type: BooleanType,
509
+ overloads: [
510
+ [
511
+ [BooleanType, BooleanType],
512
+ (ctx, [a, b]) => a.evaluate(ctx) || b.evaluate(ctx)
513
+ ],
514
+ [
515
+ varargs(BooleanType),
516
+ (ctx, args) => {
517
+ for (const arg of args) {
518
+ if (arg.evaluate(ctx))
519
+ return true;
520
+ }
521
+ return false;
522
+ }
523
+ ]
524
+ ]
525
+ },
526
+ '!': [
527
+ BooleanType,
528
+ [BooleanType],
529
+ (ctx, [b]) => !b.evaluate(ctx)
530
+ ],
531
+ 'is-supported-script': [
532
+ BooleanType,
533
+ [StringType],
534
+ // At parse time this will always return true, so we need to exclude this expression with isGlobalPropertyConstant
535
+ (ctx, [s]) => {
536
+ const isSupportedScript = ctx.globals && ctx.globals.isSupportedScript;
537
+ if (isSupportedScript) {
538
+ return isSupportedScript(s.evaluate(ctx));
539
+ }
540
+ return true;
541
+ }
542
+ ],
543
+ 'upcase': [
544
+ StringType,
545
+ [StringType],
546
+ (ctx, [s]) => s.evaluate(ctx).toUpperCase()
547
+ ],
548
+ 'downcase': [
549
+ StringType,
550
+ [StringType],
551
+ (ctx, [s]) => s.evaluate(ctx).toLowerCase()
552
+ ],
553
+ 'concat': [
554
+ StringType,
555
+ varargs(ValueType),
556
+ (ctx, args) => args.map(arg => valueToString(arg.evaluate(ctx))).join('')
557
+ ],
558
+ 'resolved-locale': [
559
+ StringType,
560
+ [CollatorType],
561
+ (ctx, [collator]) => collator.evaluate(ctx).resolvedLocale()
562
+ ]
563
+ });
564
+
565
+ export default expressions;
node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/index_of.js ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ import {BooleanType, StringType, ValueType, NullType, toString, NumberType, isValidType, isValidNativeType} from '../types';
4
+ import RuntimeError from '../runtime_error';
5
+ import {typeOf} from '../values';
6
+
7
+ import type {Expression} from '../expression';
8
+ import type ParsingContext from '../parsing_context';
9
+ import type EvaluationContext from '../evaluation_context';
10
+ import type {Type} from '../types';
11
+
12
+ class IndexOf implements Expression {
13
+ type: Type;
14
+ needle: Expression;
15
+ haystack: Expression;
16
+ fromIndex: ?Expression;
17
+
18
+ constructor(needle: Expression, haystack: Expression, fromIndex?: Expression) {
19
+ this.type = NumberType;
20
+ this.needle = needle;
21
+ this.haystack = haystack;
22
+ this.fromIndex = fromIndex;
23
+ }
24
+
25
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
26
+ if (args.length <= 2 || args.length >= 5) {
27
+ return context.error(`Expected 3 or 4 arguments, but found ${args.length - 1} instead.`);
28
+ }
29
+
30
+ const needle = context.parse(args[1], 1, ValueType);
31
+
32
+ const haystack = context.parse(args[2], 2, ValueType);
33
+
34
+ if (!needle || !haystack) return null;
35
+ if (!isValidType(needle.type, [BooleanType, StringType, NumberType, NullType, ValueType])) {
36
+ return context.error(`Expected first argument to be of type boolean, string, number or null, but found ${toString(needle.type)} instead`);
37
+ }
38
+
39
+ if (args.length === 4) {
40
+ const fromIndex = context.parse(args[3], 3, NumberType);
41
+ if (!fromIndex) return null;
42
+ return new IndexOf(needle, haystack, fromIndex);
43
+ } else {
44
+ return new IndexOf(needle, haystack);
45
+ }
46
+ }
47
+
48
+ evaluate(ctx: EvaluationContext) {
49
+ const needle = (this.needle.evaluate(ctx): any);
50
+ const haystack = (this.haystack.evaluate(ctx): any);
51
+
52
+ if (!isValidNativeType(needle, ['boolean', 'string', 'number', 'null'])) {
53
+ throw new RuntimeError(`Expected first argument to be of type boolean, string, number or null, but found ${toString(typeOf(needle))} instead.`);
54
+ }
55
+
56
+ if (!isValidNativeType(haystack, ['string', 'array'])) {
57
+ throw new RuntimeError(`Expected second argument to be of type array or string, but found ${toString(typeOf(haystack))} instead.`);
58
+ }
59
+
60
+ if (this.fromIndex) {
61
+ const fromIndex = (this.fromIndex.evaluate(ctx): number);
62
+ return haystack.indexOf(needle, fromIndex);
63
+ }
64
+
65
+ return haystack.indexOf(needle);
66
+ }
67
+
68
+ eachChild(fn: (_: Expression) => void) {
69
+ fn(this.needle);
70
+ fn(this.haystack);
71
+ if (this.fromIndex) {
72
+ fn(this.fromIndex);
73
+ }
74
+ }
75
+
76
+ outputDefined() {
77
+ return false;
78
+ }
79
+
80
+ serialize() {
81
+ if (this.fromIndex != null && this.fromIndex !== undefined) {
82
+ const fromIndex = this.fromIndex.serialize();
83
+ return ["index-of", this.needle.serialize(), this.haystack.serialize(), fromIndex];
84
+ }
85
+ return ["index-of", this.needle.serialize(), this.haystack.serialize()];
86
+ }
87
+ }
88
+
89
+ export default IndexOf;
node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/interpolate.js ADDED
@@ -0,0 +1,267 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ import UnitBezier from '@mapbox/unitbezier';
4
+
5
+ import * as interpolate from '../../util/interpolate';
6
+ import {toString, NumberType, ColorType} from '../types';
7
+ import {findStopLessThanOrEqualTo} from '../stops';
8
+ import {hcl, lab} from '../../util/color_spaces';
9
+
10
+ import type {Stops} from '../stops';
11
+ import type {Expression} from '../expression';
12
+ import type ParsingContext from '../parsing_context';
13
+ import type EvaluationContext from '../evaluation_context';
14
+ import type {Type} from '../types';
15
+
16
+ export type InterpolationType =
17
+ { name: 'linear' } |
18
+ { name: 'exponential', base: number } |
19
+ { name: 'cubic-bezier', controlPoints: [number, number, number, number] };
20
+
21
+ class Interpolate implements Expression {
22
+ type: Type;
23
+
24
+ operator: 'interpolate' | 'interpolate-hcl' | 'interpolate-lab';
25
+ interpolation: InterpolationType;
26
+ input: Expression;
27
+ labels: Array<number>;
28
+ outputs: Array<Expression>;
29
+
30
+ constructor(type: Type, operator: 'interpolate' | 'interpolate-hcl' | 'interpolate-lab', interpolation: InterpolationType, input: Expression, stops: Stops) {
31
+ this.type = type;
32
+ this.operator = operator;
33
+ this.interpolation = interpolation;
34
+ this.input = input;
35
+
36
+ this.labels = [];
37
+ this.outputs = [];
38
+ for (const [label, expression] of stops) {
39
+ this.labels.push(label);
40
+ this.outputs.push(expression);
41
+ }
42
+ }
43
+
44
+ static interpolationFactor(interpolation: InterpolationType, input: number, lower: number, upper: number) {
45
+ let t = 0;
46
+ if (interpolation.name === 'exponential') {
47
+ t = exponentialInterpolation(input, interpolation.base, lower, upper);
48
+ } else if (interpolation.name === 'linear') {
49
+ t = exponentialInterpolation(input, 1, lower, upper);
50
+ } else if (interpolation.name === 'cubic-bezier') {
51
+ const c = interpolation.controlPoints;
52
+ const ub = new UnitBezier(c[0], c[1], c[2], c[3]);
53
+ t = ub.solve(exponentialInterpolation(input, 1, lower, upper));
54
+ }
55
+ return t;
56
+ }
57
+
58
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
59
+ let [operator, interpolation, input, ...rest] = args;
60
+
61
+ if (!Array.isArray(interpolation) || interpolation.length === 0) {
62
+ return context.error(`Expected an interpolation type expression.`, 1);
63
+ }
64
+
65
+ if (interpolation[0] === 'linear') {
66
+ interpolation = {name: 'linear'};
67
+ } else if (interpolation[0] === 'exponential') {
68
+ const base = interpolation[1];
69
+ if (typeof base !== 'number')
70
+ return context.error(`Exponential interpolation requires a numeric base.`, 1, 1);
71
+ interpolation = {
72
+ name: 'exponential',
73
+ base
74
+ };
75
+ } else if (interpolation[0] === 'cubic-bezier') {
76
+ const controlPoints = interpolation.slice(1);
77
+ if (
78
+ controlPoints.length !== 4 ||
79
+ controlPoints.some(t => typeof t !== 'number' || t < 0 || t > 1)
80
+ ) {
81
+ return context.error('Cubic bezier interpolation requires four numeric arguments with values between 0 and 1.', 1);
82
+ }
83
+
84
+ interpolation = {
85
+ name: 'cubic-bezier',
86
+ controlPoints: (controlPoints: any)
87
+ };
88
+ } else {
89
+ return context.error(`Unknown interpolation type ${String(interpolation[0])}`, 1, 0);
90
+ }
91
+
92
+ if (args.length - 1 < 4) {
93
+ return context.error(`Expected at least 4 arguments, but found only ${args.length - 1}.`);
94
+ }
95
+
96
+ if ((args.length - 1) % 2 !== 0) {
97
+ return context.error(`Expected an even number of arguments.`);
98
+ }
99
+
100
+ input = context.parse(input, 2, NumberType);
101
+ if (!input) return null;
102
+
103
+ const stops: Stops = [];
104
+
105
+ let outputType: Type = (null: any);
106
+ if (operator === 'interpolate-hcl' || operator === 'interpolate-lab') {
107
+ outputType = ColorType;
108
+ } else if (context.expectedType && context.expectedType.kind !== 'value') {
109
+ outputType = context.expectedType;
110
+ }
111
+
112
+ for (let i = 0; i < rest.length; i += 2) {
113
+ const label = rest[i];
114
+ const value = rest[i + 1];
115
+
116
+ const labelKey = i + 3;
117
+ const valueKey = i + 4;
118
+
119
+ if (typeof label !== 'number') {
120
+ return context.error('Input/output pairs for "interpolate" expressions must be defined using literal numeric values (not computed expressions) for the input values.', labelKey);
121
+ }
122
+
123
+ if (stops.length && stops[stops.length - 1][0] >= label) {
124
+ return context.error('Input/output pairs for "interpolate" expressions must be arranged with input values in strictly ascending order.', labelKey);
125
+ }
126
+
127
+ const parsed = context.parse(value, valueKey, outputType);
128
+ if (!parsed) return null;
129
+ outputType = outputType || parsed.type;
130
+ stops.push([label, parsed]);
131
+ }
132
+
133
+ if (outputType.kind !== 'number' &&
134
+ outputType.kind !== 'color' &&
135
+ !(
136
+ outputType.kind === 'array' &&
137
+ outputType.itemType.kind === 'number' &&
138
+ typeof outputType.N === 'number'
139
+ )
140
+ ) {
141
+ return context.error(`Type ${toString(outputType)} is not interpolatable.`);
142
+ }
143
+
144
+ return new Interpolate(outputType, (operator: any), interpolation, input, stops);
145
+ }
146
+
147
+ evaluate(ctx: EvaluationContext) {
148
+ const labels = this.labels;
149
+ const outputs = this.outputs;
150
+
151
+ if (labels.length === 1) {
152
+ return outputs[0].evaluate(ctx);
153
+ }
154
+
155
+ const value = ((this.input.evaluate(ctx): any): number);
156
+ if (value <= labels[0]) {
157
+ return outputs[0].evaluate(ctx);
158
+ }
159
+
160
+ const stopCount = labels.length;
161
+ if (value >= labels[stopCount - 1]) {
162
+ return outputs[stopCount - 1].evaluate(ctx);
163
+ }
164
+
165
+ const index = findStopLessThanOrEqualTo(labels, value);
166
+ const lower = labels[index];
167
+ const upper = labels[index + 1];
168
+ const t = Interpolate.interpolationFactor(this.interpolation, value, lower, upper);
169
+
170
+ const outputLower = outputs[index].evaluate(ctx);
171
+ const outputUpper = outputs[index + 1].evaluate(ctx);
172
+
173
+ if (this.operator === 'interpolate') {
174
+ return (interpolate[this.type.kind.toLowerCase()]: any)(outputLower, outputUpper, t); // eslint-disable-line import/namespace
175
+ } else if (this.operator === 'interpolate-hcl') {
176
+ return hcl.reverse(hcl.interpolate(hcl.forward(outputLower), hcl.forward(outputUpper), t));
177
+ } else {
178
+ return lab.reverse(lab.interpolate(lab.forward(outputLower), lab.forward(outputUpper), t));
179
+ }
180
+ }
181
+
182
+ eachChild(fn: (_: Expression) => void) {
183
+ fn(this.input);
184
+ for (const expression of this.outputs) {
185
+ fn(expression);
186
+ }
187
+ }
188
+
189
+ outputDefined(): boolean {
190
+ return this.outputs.every(out => out.outputDefined());
191
+ }
192
+
193
+ serialize(): Array<mixed> {
194
+ let interpolation;
195
+ if (this.interpolation.name === 'linear') {
196
+ interpolation = ["linear"];
197
+ } else if (this.interpolation.name === 'exponential') {
198
+ if (this.interpolation.base === 1) {
199
+ interpolation = ["linear"];
200
+ } else {
201
+ interpolation = ["exponential", this.interpolation.base];
202
+ }
203
+ } else {
204
+ interpolation = ["cubic-bezier" ].concat(this.interpolation.controlPoints);
205
+ }
206
+
207
+ const serialized = [this.operator, interpolation, this.input.serialize()];
208
+
209
+ for (let i = 0; i < this.labels.length; i++) {
210
+ serialized.push(
211
+ this.labels[i],
212
+ this.outputs[i].serialize()
213
+ );
214
+ }
215
+ return serialized;
216
+ }
217
+ }
218
+
219
+ /**
220
+ * Returns a ratio that can be used to interpolate between exponential function
221
+ * stops.
222
+ * How it works: Two consecutive stop values define a (scaled and shifted) exponential function `f(x) = a * base^x + b`, where `base` is the user-specified base,
223
+ * and `a` and `b` are constants affording sufficient degrees of freedom to fit
224
+ * the function to the given stops.
225
+ *
226
+ * Here's a bit of algebra that lets us compute `f(x)` directly from the stop
227
+ * values without explicitly solving for `a` and `b`:
228
+ *
229
+ * First stop value: `f(x0) = y0 = a * base^x0 + b`
230
+ * Second stop value: `f(x1) = y1 = a * base^x1 + b`
231
+ * => `y1 - y0 = a(base^x1 - base^x0)`
232
+ * => `a = (y1 - y0)/(base^x1 - base^x0)`
233
+ *
234
+ * Desired value: `f(x) = y = a * base^x + b`
235
+ * => `f(x) = y0 + a * (base^x - base^x0)`
236
+ *
237
+ * From the above, we can replace the `a` in `a * (base^x - base^x0)` and do a
238
+ * little algebra:
239
+ * ```
240
+ * a * (base^x - base^x0) = (y1 - y0)/(base^x1 - base^x0) * (base^x - base^x0)
241
+ * = (y1 - y0) * (base^x - base^x0) / (base^x1 - base^x0)
242
+ * ```
243
+ *
244
+ * If we let `(base^x - base^x0) / (base^x1 base^x0)`, then we have
245
+ * `f(x) = y0 + (y1 - y0) * ratio`. In other words, `ratio` may be treated as
246
+ * an interpolation factor between the two stops' output values.
247
+ *
248
+ * (Note: a slightly different form for `ratio`,
249
+ * `(base^(x-x0) - 1) / (base^(x1-x0) - 1) `, is equivalent, but requires fewer
250
+ * expensive `Math.pow()` operations.)
251
+ *
252
+ * @private
253
+ */
254
+ function exponentialInterpolation(input, base, lowerValue, upperValue) {
255
+ const difference = upperValue - lowerValue;
256
+ const progress = input - lowerValue;
257
+
258
+ if (difference === 0) {
259
+ return 0;
260
+ } else if (base === 1) {
261
+ return progress / difference;
262
+ } else {
263
+ return (Math.pow(base, progress) - 1) / (Math.pow(base, difference) - 1);
264
+ }
265
+ }
266
+
267
+ export default Interpolate;
node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/length.js ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ import {NumberType, toString} from '../types';
4
+
5
+ import {typeOf} from '../values';
6
+ import RuntimeError from '../runtime_error';
7
+
8
+ import type {Expression} from '../expression';
9
+ import type ParsingContext from '../parsing_context';
10
+ import type EvaluationContext from '../evaluation_context';
11
+ import type {Type} from '../types';
12
+
13
+ class Length implements Expression {
14
+ type: Type;
15
+ input: Expression;
16
+
17
+ constructor(input: Expression) {
18
+ this.type = NumberType;
19
+ this.input = input;
20
+ }
21
+
22
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
23
+ if (args.length !== 2)
24
+ return context.error(`Expected 1 argument, but found ${args.length - 1} instead.`);
25
+
26
+ const input = context.parse(args[1], 1);
27
+ if (!input) return null;
28
+
29
+ if (input.type.kind !== 'array' && input.type.kind !== 'string' && input.type.kind !== 'value')
30
+ return context.error(`Expected argument of type string or array, but found ${toString(input.type)} instead.`);
31
+
32
+ return new Length(input);
33
+ }
34
+
35
+ evaluate(ctx: EvaluationContext) {
36
+ const input = this.input.evaluate(ctx);
37
+ if (typeof input === 'string') {
38
+ return input.length;
39
+ } else if (Array.isArray(input)) {
40
+ return input.length;
41
+ } else {
42
+ throw new RuntimeError(`Expected value to be of type string or array, but found ${toString(typeOf(input))} instead.`);
43
+ }
44
+ }
45
+
46
+ eachChild(fn: (_: Expression) => void) {
47
+ fn(this.input);
48
+ }
49
+
50
+ outputDefined() {
51
+ return false;
52
+ }
53
+
54
+ serialize() {
55
+ const serialized = ["length"];
56
+ this.eachChild(child => { serialized.push(child.serialize()); });
57
+ return serialized;
58
+ }
59
+ }
60
+
61
+ export default Length;
node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/let.js ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ import type {Type} from '../types';
4
+ import type {Expression} from '../expression';
5
+ import type ParsingContext from '../parsing_context';
6
+ import type EvaluationContext from '../evaluation_context';
7
+
8
+ class Let implements Expression {
9
+ type: Type;
10
+ bindings: Array<[string, Expression]>;
11
+ result: Expression;
12
+
13
+ constructor(bindings: Array<[string, Expression]>, result: Expression) {
14
+ this.type = result.type;
15
+ this.bindings = [].concat(bindings);
16
+ this.result = result;
17
+ }
18
+
19
+ evaluate(ctx: EvaluationContext) {
20
+ return this.result.evaluate(ctx);
21
+ }
22
+
23
+ eachChild(fn: (_: Expression) => void) {
24
+ for (const binding of this.bindings) {
25
+ fn(binding[1]);
26
+ }
27
+ fn(this.result);
28
+ }
29
+
30
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
31
+ if (args.length < 4)
32
+ return context.error(`Expected at least 3 arguments, but found ${args.length - 1} instead.`);
33
+
34
+ const bindings: Array<[string, Expression]> = [];
35
+ for (let i = 1; i < args.length - 1; i += 2) {
36
+ const name = args[i];
37
+
38
+ if (typeof name !== 'string') {
39
+ return context.error(`Expected string, but found ${typeof name} instead.`, i);
40
+ }
41
+
42
+ if (/[^a-zA-Z0-9_]/.test(name)) {
43
+ return context.error(`Variable names must contain only alphanumeric characters or '_'.`, i);
44
+ }
45
+
46
+ const value = context.parse(args[i + 1], i + 1);
47
+ if (!value) return null;
48
+
49
+ bindings.push([name, value]);
50
+ }
51
+
52
+ const result = context.parse(args[args.length - 1], args.length - 1, context.expectedType, bindings);
53
+ if (!result) return null;
54
+
55
+ return new Let(bindings, result);
56
+ }
57
+
58
+ outputDefined() {
59
+ return this.result.outputDefined();
60
+ }
61
+
62
+ serialize() {
63
+ const serialized = ["let"];
64
+ for (const [name, expr] of this.bindings) {
65
+ serialized.push(name, expr.serialize());
66
+ }
67
+ serialized.push(this.result.serialize());
68
+ return serialized;
69
+ }
70
+ }
71
+
72
+ export default Let;
node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/literal.js ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ import assert from 'assert';
4
+ import {isValue, typeOf, Color} from '../values';
5
+ import Formatted from '../types/formatted';
6
+
7
+ import type {Type} from '../types';
8
+ import type {Value} from '../values';
9
+ import type {Expression} from '../expression';
10
+ import type ParsingContext from '../parsing_context';
11
+
12
+ class Literal implements Expression {
13
+ type: Type;
14
+ value: Value;
15
+
16
+ constructor(type: Type, value: Value) {
17
+ this.type = type;
18
+ this.value = value;
19
+ }
20
+
21
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
22
+ if (args.length !== 2)
23
+ return context.error(`'literal' expression requires exactly one argument, but found ${args.length - 1} instead.`);
24
+
25
+ if (!isValue(args[1]))
26
+ return context.error(`invalid value`);
27
+
28
+ const value = (args[1]: any);
29
+ let type = typeOf(value);
30
+
31
+ // special case: infer the item type if possible for zero-length arrays
32
+ const expected = context.expectedType;
33
+ if (
34
+ type.kind === 'array' &&
35
+ type.N === 0 &&
36
+ expected &&
37
+ expected.kind === 'array' &&
38
+ (typeof expected.N !== 'number' || expected.N === 0)
39
+ ) {
40
+ type = expected;
41
+ }
42
+
43
+ return new Literal(type, value);
44
+ }
45
+
46
+ evaluate() {
47
+ return this.value;
48
+ }
49
+
50
+ eachChild() {}
51
+
52
+ outputDefined() {
53
+ return true;
54
+ }
55
+
56
+ serialize(): Array<mixed> {
57
+ if (this.type.kind === 'array' || this.type.kind === 'object') {
58
+ return ["literal", this.value];
59
+ } else if (this.value instanceof Color) {
60
+ // Constant-folding can generate Literal expressions that you
61
+ // couldn't actually generate with a "literal" expression,
62
+ // so we have to implement an equivalent serialization here
63
+ return ["rgba"].concat(this.value.toArray());
64
+ } else if (this.value instanceof Formatted) {
65
+ // Same as Color
66
+ return this.value.serialize();
67
+ } else {
68
+ assert(this.value === null ||
69
+ typeof this.value === 'string' ||
70
+ typeof this.value === 'number' ||
71
+ typeof this.value === 'boolean');
72
+ return (this.value: any);
73
+ }
74
+ }
75
+ }
76
+
77
+ export default Literal;
node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/match.js ADDED
@@ -0,0 +1,158 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ import assert from 'assert';
4
+
5
+ import {typeOf} from '../values';
6
+ import {ValueType, type Type} from '../types';
7
+
8
+ import type {Expression} from '../expression';
9
+ import type ParsingContext from '../parsing_context';
10
+ import type EvaluationContext from '../evaluation_context';
11
+
12
+ // Map input label values to output expression index
13
+ type Cases = {[number | string]: number};
14
+
15
+ class Match implements Expression {
16
+ type: Type;
17
+ inputType: Type;
18
+
19
+ input: Expression;
20
+ cases: Cases;
21
+ outputs: Array<Expression>;
22
+ otherwise: Expression;
23
+
24
+ constructor(inputType: Type, outputType: Type, input: Expression, cases: Cases, outputs: Array<Expression>, otherwise: Expression) {
25
+ this.inputType = inputType;
26
+ this.type = outputType;
27
+ this.input = input;
28
+ this.cases = cases;
29
+ this.outputs = outputs;
30
+ this.otherwise = otherwise;
31
+ }
32
+
33
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
34
+ if (args.length < 5)
35
+ return context.error(`Expected at least 4 arguments, but found only ${args.length - 1}.`);
36
+ if (args.length % 2 !== 1)
37
+ return context.error(`Expected an even number of arguments.`);
38
+
39
+ let inputType;
40
+ let outputType;
41
+ if (context.expectedType && context.expectedType.kind !== 'value') {
42
+ outputType = context.expectedType;
43
+ }
44
+ const cases = {};
45
+ const outputs = [];
46
+ for (let i = 2; i < args.length - 1; i += 2) {
47
+ let labels = args[i];
48
+ const value = args[i + 1];
49
+
50
+ if (!Array.isArray(labels)) {
51
+ labels = [labels];
52
+ }
53
+
54
+ const labelContext = context.concat(i);
55
+ if (labels.length === 0) {
56
+ return labelContext.error('Expected at least one branch label.');
57
+ }
58
+
59
+ for (const label of labels) {
60
+ if (typeof label !== 'number' && typeof label !== 'string') {
61
+ return labelContext.error(`Branch labels must be numbers or strings.`);
62
+ } else if (typeof label === 'number' && Math.abs(label) > Number.MAX_SAFE_INTEGER) {
63
+ return labelContext.error(`Branch labels must be integers no larger than ${Number.MAX_SAFE_INTEGER}.`);
64
+
65
+ } else if (typeof label === 'number' && Math.floor(label) !== label) {
66
+ return labelContext.error(`Numeric branch labels must be integer values.`);
67
+
68
+ } else if (!inputType) {
69
+ inputType = typeOf(label);
70
+ } else if (labelContext.checkSubtype(inputType, typeOf(label))) {
71
+ return null;
72
+ }
73
+
74
+ if (typeof cases[String(label)] !== 'undefined') {
75
+ return labelContext.error('Branch labels must be unique.');
76
+ }
77
+
78
+ cases[String(label)] = outputs.length;
79
+ }
80
+
81
+ const result = context.parse(value, i, outputType);
82
+ if (!result) return null;
83
+ outputType = outputType || result.type;
84
+ outputs.push(result);
85
+ }
86
+
87
+ const input = context.parse(args[1], 1, ValueType);
88
+ if (!input) return null;
89
+
90
+ const otherwise = context.parse(args[args.length - 1], args.length - 1, outputType);
91
+ if (!otherwise) return null;
92
+
93
+ assert(inputType && outputType);
94
+
95
+ if (input.type.kind !== 'value' && context.concat(1).checkSubtype((inputType: any), input.type)) {
96
+ return null;
97
+ }
98
+
99
+ return new Match((inputType: any), (outputType: any), input, cases, outputs, otherwise);
100
+ }
101
+
102
+ evaluate(ctx: EvaluationContext) {
103
+ const input = (this.input.evaluate(ctx): any);
104
+ const output = (typeOf(input) === this.inputType && this.outputs[this.cases[input]]) || this.otherwise;
105
+ return output.evaluate(ctx);
106
+ }
107
+
108
+ eachChild(fn: (_: Expression) => void) {
109
+ fn(this.input);
110
+ this.outputs.forEach(fn);
111
+ fn(this.otherwise);
112
+ }
113
+
114
+ outputDefined(): boolean {
115
+ return this.outputs.every(out => out.outputDefined()) && this.otherwise.outputDefined();
116
+ }
117
+
118
+ serialize(): Array<mixed> {
119
+ const serialized = ["match", this.input.serialize()];
120
+
121
+ // Sort so serialization has an arbitrary defined order, even though
122
+ // branch order doesn't affect evaluation
123
+ const sortedLabels = Object.keys(this.cases).sort();
124
+
125
+ // Group branches by unique match expression to support condensed
126
+ // serializations of the form [case1, case2, ...] -> matchExpression
127
+ const groupedByOutput: Array<[number, Array<number | string>]> = [];
128
+ const outputLookup: {[index: number]: number} = {}; // lookup index into groupedByOutput for a given output expression
129
+ for (const label of sortedLabels) {
130
+ const outputIndex = outputLookup[this.cases[label]];
131
+ if (outputIndex === undefined) {
132
+ // First time seeing this output, add it to the end of the grouped list
133
+ outputLookup[this.cases[label]] = groupedByOutput.length;
134
+ groupedByOutput.push([this.cases[label], [label]]);
135
+ } else {
136
+ // We've seen this expression before, add the label to that output's group
137
+ groupedByOutput[outputIndex][1].push(label);
138
+ }
139
+ }
140
+
141
+ const coerceLabel = (label) => this.inputType.kind === 'number' ? Number(label) : label;
142
+
143
+ for (const [outputIndex, labels] of groupedByOutput) {
144
+ if (labels.length === 1) {
145
+ // Only a single label matches this output expression
146
+ serialized.push(coerceLabel(labels[0]));
147
+ } else {
148
+ // Array of literal labels pointing to this output expression
149
+ serialized.push(labels.map(coerceLabel));
150
+ }
151
+ serialized.push(this.outputs[outputIndex].serialize());
152
+ }
153
+ serialized.push(this.otherwise.serialize());
154
+ return serialized;
155
+ }
156
+ }
157
+
158
+ export default Match;
node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/number_format.js ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ import {StringType, NumberType} from '../types';
4
+
5
+ import type {Expression} from '../expression';
6
+ import type EvaluationContext from '../evaluation_context';
7
+ import type ParsingContext from '../parsing_context';
8
+ import type {Type} from '../types';
9
+
10
+ declare var Intl: {
11
+ NumberFormat: Class<Intl$NumberFormat>
12
+ };
13
+
14
+ declare class Intl$NumberFormat {
15
+ constructor (
16
+ locales?: string | string[],
17
+ options?: NumberFormatOptions
18
+ ): Intl$NumberFormat;
19
+
20
+ static (
21
+ locales?: string | string[],
22
+ options?: NumberFormatOptions
23
+ ): Intl$NumberFormat;
24
+
25
+ format(a: number): string;
26
+
27
+ resolvedOptions(): any;
28
+ }
29
+
30
+ type NumberFormatOptions = {
31
+ style?: 'decimal' | 'currency' | 'percent';
32
+ currency?: null | string;
33
+ minimumFractionDigits?: null | string;
34
+ maximumFractionDigits?: null | string;
35
+ };
36
+
37
+ export default class NumberFormat implements Expression {
38
+ type: Type;
39
+ number: Expression;
40
+ locale: Expression | null; // BCP 47 language tag
41
+ currency: Expression | null; // ISO 4217 currency code, required if style=currency
42
+ minFractionDigits: Expression | null; // Default 0
43
+ maxFractionDigits: Expression | null; // Default 3
44
+
45
+ constructor(number: Expression,
46
+ locale: Expression | null,
47
+ currency: Expression | null,
48
+ minFractionDigits: Expression | null,
49
+ maxFractionDigits: Expression | null) {
50
+ this.type = StringType;
51
+ this.number = number;
52
+ this.locale = locale;
53
+ this.currency = currency;
54
+ this.minFractionDigits = minFractionDigits;
55
+ this.maxFractionDigits = maxFractionDigits;
56
+ }
57
+
58
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext): ?Expression {
59
+ if (args.length !== 3)
60
+ return context.error(`Expected two arguments.`);
61
+
62
+ const number = context.parse(args[1], 1, NumberType);
63
+ if (!number) return null;
64
+
65
+ const options = (args[2]: any);
66
+ if (typeof options !== "object" || Array.isArray(options))
67
+ return context.error(`NumberFormat options argument must be an object.`);
68
+
69
+ let locale = null;
70
+ if (options['locale']) {
71
+ locale = context.parse(options['locale'], 1, StringType);
72
+ if (!locale) return null;
73
+ }
74
+
75
+ let currency = null;
76
+ if (options['currency']) {
77
+ currency = context.parse(options['currency'], 1, StringType);
78
+ if (!currency) return null;
79
+ }
80
+
81
+ let minFractionDigits = null;
82
+ if (options['min-fraction-digits']) {
83
+ minFractionDigits = context.parse(options['min-fraction-digits'], 1, NumberType);
84
+ if (!minFractionDigits) return null;
85
+ }
86
+
87
+ let maxFractionDigits = null;
88
+ if (options['max-fraction-digits']) {
89
+ maxFractionDigits = context.parse(options['max-fraction-digits'], 1, NumberType);
90
+ if (!maxFractionDigits) return null;
91
+ }
92
+
93
+ return new NumberFormat(number, locale, currency, minFractionDigits, maxFractionDigits);
94
+ }
95
+
96
+ evaluate(ctx: EvaluationContext) {
97
+ return new Intl.NumberFormat(this.locale ? this.locale.evaluate(ctx) : [],
98
+ {
99
+ style: this.currency ? "currency" : "decimal",
100
+ currency: this.currency ? this.currency.evaluate(ctx) : undefined,
101
+ minimumFractionDigits: this.minFractionDigits ? this.minFractionDigits.evaluate(ctx) : undefined,
102
+ maximumFractionDigits: this.maxFractionDigits ? this.maxFractionDigits.evaluate(ctx) : undefined,
103
+ }).format(this.number.evaluate(ctx));
104
+ }
105
+
106
+ eachChild(fn: (_: Expression) => void) {
107
+ fn(this.number);
108
+ if (this.locale) {
109
+ fn(this.locale);
110
+ }
111
+ if (this.currency) {
112
+ fn(this.currency);
113
+ }
114
+ if (this.minFractionDigits) {
115
+ fn(this.minFractionDigits);
116
+ }
117
+ if (this.maxFractionDigits) {
118
+ fn(this.maxFractionDigits);
119
+ }
120
+ }
121
+
122
+ outputDefined() {
123
+ return false;
124
+ }
125
+
126
+ serialize() {
127
+ const options = {};
128
+ if (this.locale) {
129
+ options['locale'] = this.locale.serialize();
130
+ }
131
+ if (this.currency) {
132
+ options['currency'] = this.currency.serialize();
133
+ }
134
+ if (this.minFractionDigits) {
135
+ options['min-fraction-digits'] = this.minFractionDigits.serialize();
136
+ }
137
+ if (this.maxFractionDigits) {
138
+ options['max-fraction-digits'] = this.maxFractionDigits.serialize();
139
+ }
140
+ return ["number-format", this.number.serialize(), options];
141
+ }
142
+ }
node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/slice.js ADDED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ import {ValueType, NumberType, StringType, array, toString, isValidType, isValidNativeType} from '../types';
4
+ import RuntimeError from '../runtime_error';
5
+ import {typeOf} from '../values';
6
+
7
+ import type {Expression} from '../expression';
8
+ import type ParsingContext from '../parsing_context';
9
+ import type EvaluationContext from '../evaluation_context';
10
+ import type {Type} from '../types';
11
+
12
+ class Slice implements Expression {
13
+ type: Type;
14
+ input: Expression;
15
+ beginIndex: Expression;
16
+ endIndex: ?Expression;
17
+
18
+ constructor(type: Type, input: Expression, beginIndex: Expression, endIndex?: Expression) {
19
+ this.type = type;
20
+ this.input = input;
21
+ this.beginIndex = beginIndex;
22
+ this.endIndex = endIndex;
23
+
24
+ }
25
+
26
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
27
+ if (args.length <= 2 || args.length >= 5) {
28
+ return context.error(`Expected 3 or 4 arguments, but found ${args.length - 1} instead.`);
29
+ }
30
+
31
+ const input = context.parse(args[1], 1, ValueType);
32
+ const beginIndex = context.parse(args[2], 2, NumberType);
33
+
34
+ if (!input || !beginIndex) return null;
35
+
36
+ if (!isValidType(input.type, [array(ValueType), StringType, ValueType])) {
37
+ return context.error(`Expected first argument to be of type array or string, but found ${toString(input.type)} instead`);
38
+ }
39
+
40
+ if (args.length === 4) {
41
+ const endIndex = context.parse(args[3], 3, NumberType);
42
+ if (!endIndex) return null;
43
+ return new Slice(input.type, input, beginIndex, endIndex);
44
+ } else {
45
+ return new Slice(input.type, input, beginIndex);
46
+ }
47
+ }
48
+
49
+ evaluate(ctx: EvaluationContext) {
50
+ const input = (this.input.evaluate(ctx): any);
51
+ const beginIndex = (this.beginIndex.evaluate(ctx): number);
52
+
53
+ if (!isValidNativeType(input, ['string', 'array'])) {
54
+ throw new RuntimeError(`Expected first argument to be of type array or string, but found ${toString(typeOf(input))} instead.`);
55
+ }
56
+
57
+ if (this.endIndex) {
58
+ const endIndex = (this.endIndex.evaluate(ctx): number);
59
+ return input.slice(beginIndex, endIndex);
60
+ }
61
+
62
+ return input.slice(beginIndex);
63
+ }
64
+
65
+ eachChild(fn: (_: Expression) => void) {
66
+ fn(this.input);
67
+ fn(this.beginIndex);
68
+ if (this.endIndex) {
69
+ fn(this.endIndex);
70
+ }
71
+ }
72
+
73
+ outputDefined() {
74
+ return false;
75
+ }
76
+
77
+ serialize() {
78
+ if (this.endIndex != null && this.endIndex !== undefined) {
79
+ const endIndex = this.endIndex.serialize();
80
+ return ["slice", this.input.serialize(), this.beginIndex.serialize(), endIndex];
81
+ }
82
+ return ["slice", this.input.serialize(), this.beginIndex.serialize()];
83
+ }
84
+ }
85
+
86
+ export default Slice;
node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/step.js ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ import {NumberType} from '../types';
4
+
5
+ import {findStopLessThanOrEqualTo} from '../stops';
6
+
7
+ import type {Stops} from '../stops';
8
+ import type {Expression} from '../expression';
9
+ import type ParsingContext from '../parsing_context';
10
+ import type EvaluationContext from '../evaluation_context';
11
+ import type {Type} from '../types';
12
+
13
+ class Step implements Expression {
14
+ type: Type;
15
+
16
+ input: Expression;
17
+ labels: Array<number>;
18
+ outputs: Array<Expression>;
19
+
20
+ constructor(type: Type, input: Expression, stops: Stops) {
21
+ this.type = type;
22
+ this.input = input;
23
+
24
+ this.labels = [];
25
+ this.outputs = [];
26
+ for (const [label, expression] of stops) {
27
+ this.labels.push(label);
28
+ this.outputs.push(expression);
29
+ }
30
+ }
31
+
32
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
33
+ if (args.length - 1 < 4) {
34
+ return context.error(`Expected at least 4 arguments, but found only ${args.length - 1}.`);
35
+ }
36
+
37
+ if ((args.length - 1) % 2 !== 0) {
38
+ return context.error(`Expected an even number of arguments.`);
39
+ }
40
+
41
+ const input = context.parse(args[1], 1, NumberType);
42
+ if (!input) return null;
43
+
44
+ const stops: Stops = [];
45
+
46
+ let outputType: Type = (null: any);
47
+ if (context.expectedType && context.expectedType.kind !== 'value') {
48
+ outputType = context.expectedType;
49
+ }
50
+
51
+ for (let i = 1; i < args.length; i += 2) {
52
+ const label = i === 1 ? -Infinity : args[i];
53
+ const value = args[i + 1];
54
+
55
+ const labelKey = i;
56
+ const valueKey = i + 1;
57
+
58
+ if (typeof label !== 'number') {
59
+ return context.error('Input/output pairs for "step" expressions must be defined using literal numeric values (not computed expressions) for the input values.', labelKey);
60
+ }
61
+
62
+ if (stops.length && stops[stops.length - 1][0] >= label) {
63
+ return context.error('Input/output pairs for "step" expressions must be arranged with input values in strictly ascending order.', labelKey);
64
+ }
65
+
66
+ const parsed = context.parse(value, valueKey, outputType);
67
+ if (!parsed) return null;
68
+ outputType = outputType || parsed.type;
69
+ stops.push([label, parsed]);
70
+ }
71
+
72
+ return new Step(outputType, input, stops);
73
+ }
74
+
75
+ evaluate(ctx: EvaluationContext) {
76
+ const labels = this.labels;
77
+ const outputs = this.outputs;
78
+
79
+ if (labels.length === 1) {
80
+ return outputs[0].evaluate(ctx);
81
+ }
82
+
83
+ const value = ((this.input.evaluate(ctx): any): number);
84
+ if (value <= labels[0]) {
85
+ return outputs[0].evaluate(ctx);
86
+ }
87
+
88
+ const stopCount = labels.length;
89
+ if (value >= labels[stopCount - 1]) {
90
+ return outputs[stopCount - 1].evaluate(ctx);
91
+ }
92
+
93
+ const index = findStopLessThanOrEqualTo(labels, value);
94
+ return outputs[index].evaluate(ctx);
95
+ }
96
+
97
+ eachChild(fn: (_: Expression) => void) {
98
+ fn(this.input);
99
+ for (const expression of this.outputs) {
100
+ fn(expression);
101
+ }
102
+ }
103
+
104
+ outputDefined(): boolean {
105
+ return this.outputs.every(out => out.outputDefined());
106
+ }
107
+
108
+ serialize() {
109
+ const serialized = ["step", this.input.serialize()];
110
+ for (let i = 0; i < this.labels.length; i++) {
111
+ if (i > 0) {
112
+ serialized.push(this.labels[i]);
113
+ }
114
+ serialized.push(this.outputs[i].serialize());
115
+ }
116
+ return serialized;
117
+ }
118
+ }
119
+
120
+ export default Step;
node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/var.js ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ import type {Type} from '../types';
4
+ import type {Expression} from '../expression';
5
+ import type ParsingContext from '../parsing_context';
6
+ import type EvaluationContext from '../evaluation_context';
7
+
8
+ class Var implements Expression {
9
+ type: Type;
10
+ name: string;
11
+ boundExpression: Expression;
12
+
13
+ constructor(name: string, boundExpression: Expression) {
14
+ this.type = boundExpression.type;
15
+ this.name = name;
16
+ this.boundExpression = boundExpression;
17
+ }
18
+
19
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
20
+ if (args.length !== 2 || typeof args[1] !== 'string')
21
+ return context.error(`'var' expression requires exactly one string literal argument.`);
22
+
23
+ const name = args[1];
24
+ if (!context.scope.has(name)) {
25
+ return context.error(`Unknown variable "${name}". Make sure "${name}" has been bound in an enclosing "let" expression before using it.`, 1);
26
+ }
27
+
28
+ return new Var(name, context.scope.get(name));
29
+ }
30
+
31
+ evaluate(ctx: EvaluationContext) {
32
+ return this.boundExpression.evaluate(ctx);
33
+ }
34
+
35
+ eachChild() {}
36
+
37
+ outputDefined() {
38
+ return false;
39
+ }
40
+
41
+ serialize() {
42
+ return ["var", this.name];
43
+ }
44
+ }
45
+
46
+ export default Var;
node_modules/@plotly/mapbox-gl/src/style-spec/expression/definitions/within.js ADDED
@@ -0,0 +1,342 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ import {isValue} from '../values';
4
+ import type {Type} from '../types';
5
+ import {BooleanType} from '../types';
6
+ import type {Expression} from '../expression';
7
+ import type ParsingContext from '../parsing_context';
8
+ import type EvaluationContext from '../evaluation_context';
9
+ import type {GeoJSON, GeoJSONPolygon, GeoJSONMultiPolygon} from '@mapbox/geojson-types';
10
+ import Point from '@mapbox/point-geometry';
11
+ import type {CanonicalTileID} from '../../../source/tile_id';
12
+
13
+ type GeoJSONPolygons =| GeoJSONPolygon | GeoJSONMultiPolygon;
14
+
15
+ // minX, minY, maxX, maxY
16
+ type BBox = [number, number, number, number];
17
+ const EXTENT = 8192;
18
+
19
+ function updateBBox(bbox: BBox, coord: Point) {
20
+ bbox[0] = Math.min(bbox[0], coord[0]);
21
+ bbox[1] = Math.min(bbox[1], coord[1]);
22
+ bbox[2] = Math.max(bbox[2], coord[0]);
23
+ bbox[3] = Math.max(bbox[3], coord[1]);
24
+ }
25
+
26
+ function mercatorXfromLng(lng: number) {
27
+ return (180 + lng) / 360;
28
+ }
29
+
30
+ function mercatorYfromLat(lat: number) {
31
+ return (180 - (180 / Math.PI * Math.log(Math.tan(Math.PI / 4 + lat * Math.PI / 360)))) / 360;
32
+ }
33
+
34
+ function boxWithinBox(bbox1: BBox, bbox2: BBox) {
35
+ if (bbox1[0] <= bbox2[0]) return false;
36
+ if (bbox1[2] >= bbox2[2]) return false;
37
+ if (bbox1[1] <= bbox2[1]) return false;
38
+ if (bbox1[3] >= bbox2[3]) return false;
39
+ return true;
40
+ }
41
+
42
+ function getTileCoordinates(p, canonical: CanonicalTileID) {
43
+ const x = mercatorXfromLng(p[0]);
44
+ const y = mercatorYfromLat(p[1]);
45
+ const tilesAtZoom = Math.pow(2, canonical.z);
46
+ return [Math.round(x * tilesAtZoom * EXTENT), Math.round(y * tilesAtZoom * EXTENT)];
47
+ }
48
+
49
+ function onBoundary(p, p1, p2) {
50
+ const x1 = p[0] - p1[0];
51
+ const y1 = p[1] - p1[1];
52
+ const x2 = p[0] - p2[0];
53
+ const y2 = p[1] - p2[1];
54
+ return (x1 * y2 - x2 * y1 === 0) && (x1 * x2 <= 0) && (y1 * y2 <= 0);
55
+ }
56
+
57
+ function rayIntersect(p, p1, p2) {
58
+ return ((p1[1] > p[1]) !== (p2[1] > p[1])) && (p[0] < (p2[0] - p1[0]) * (p[1] - p1[1]) / (p2[1] - p1[1]) + p1[0]);
59
+ }
60
+
61
+ // ray casting algorithm for detecting if point is in polygon
62
+ function pointWithinPolygon(point, rings) {
63
+ let inside = false;
64
+ for (let i = 0, len = rings.length; i < len; i++) {
65
+ const ring = rings[i];
66
+ for (let j = 0, len2 = ring.length; j < len2 - 1; j++) {
67
+ if (onBoundary(point, ring[j], ring[j + 1])) return false;
68
+ if (rayIntersect(point, ring[j], ring[j + 1])) inside = !inside;
69
+ }
70
+ }
71
+ return inside;
72
+ }
73
+
74
+ function pointWithinPolygons(point, polygons) {
75
+ for (let i = 0; i < polygons.length; i++) {
76
+ if (pointWithinPolygon(point, polygons[i])) return true;
77
+ }
78
+ return false;
79
+ }
80
+
81
+ function perp(v1, v2) {
82
+ return (v1[0] * v2[1] - v1[1] * v2[0]);
83
+ }
84
+
85
+ // check if p1 and p2 are in different sides of line segment q1->q2
86
+ function twoSided(p1, p2, q1, q2) {
87
+ // q1->p1 (x1, y1), q1->p2 (x2, y2), q1->q2 (x3, y3)
88
+ const x1 = p1[0] - q1[0];
89
+ const y1 = p1[1] - q1[1];
90
+ const x2 = p2[0] - q1[0];
91
+ const y2 = p2[1] - q1[1];
92
+ const x3 = q2[0] - q1[0];
93
+ const y3 = q2[1] - q1[1];
94
+ const det1 = (x1 * y3 - x3 * y1);
95
+ const det2 = (x2 * y3 - x3 * y2);
96
+ if ((det1 > 0 && det2 < 0) || (det1 < 0 && det2 > 0)) return true;
97
+ return false;
98
+ }
99
+ // a, b are end points for line segment1, c and d are end points for line segment2
100
+ function lineIntersectLine(a, b, c, d) {
101
+ // check if two segments are parallel or not
102
+ // precondition is end point a, b is inside polygon, if line a->b is
103
+ // parallel to polygon edge c->d, then a->b won't intersect with c->d
104
+ const vectorP = [b[0] - a[0], b[1] - a[1]];
105
+ const vectorQ = [d[0] - c[0], d[1] - c[1]];
106
+ if (perp(vectorQ, vectorP) === 0) return false;
107
+
108
+ // If lines are intersecting with each other, the relative location should be:
109
+ // a and b lie in different sides of segment c->d
110
+ // c and d lie in different sides of segment a->b
111
+ if (twoSided(a, b, c, d) && twoSided(c, d, a, b)) return true;
112
+ return false;
113
+ }
114
+
115
+ function lineIntersectPolygon(p1, p2, polygon) {
116
+ for (const ring of polygon) {
117
+ // loop through every edge of the ring
118
+ for (let j = 0; j < ring.length - 1; ++j) {
119
+ if (lineIntersectLine(p1, p2, ring[j], ring[j + 1])) {
120
+ return true;
121
+ }
122
+ }
123
+ }
124
+ return false;
125
+ }
126
+
127
+ function lineStringWithinPolygon(line, polygon) {
128
+ // First, check if geometry points of line segments are all inside polygon
129
+ for (let i = 0; i < line.length; ++i) {
130
+ if (!pointWithinPolygon(line[i], polygon)) {
131
+ return false;
132
+ }
133
+ }
134
+
135
+ // Second, check if there is line segment intersecting polygon edge
136
+ for (let i = 0; i < line.length - 1; ++i) {
137
+ if (lineIntersectPolygon(line[i], line[i + 1], polygon)) {
138
+ return false;
139
+ }
140
+ }
141
+ return true;
142
+ }
143
+
144
+ function lineStringWithinPolygons(line, polygons) {
145
+ for (let i = 0; i < polygons.length; i++) {
146
+ if (lineStringWithinPolygon(line, polygons[i])) return true;
147
+ }
148
+ return false;
149
+ }
150
+
151
+ function getTilePolygon(coordinates, bbox, canonical) {
152
+ const polygon = [];
153
+ for (let i = 0; i < coordinates.length; i++) {
154
+ const ring = [];
155
+ for (let j = 0; j < coordinates[i].length; j++) {
156
+ const coord = getTileCoordinates(coordinates[i][j], canonical);
157
+ updateBBox(bbox, coord);
158
+ ring.push(coord);
159
+ }
160
+ polygon.push(ring);
161
+ }
162
+ return polygon;
163
+ }
164
+
165
+ function getTilePolygons(coordinates, bbox, canonical) {
166
+ const polygons = [];
167
+ for (let i = 0; i < coordinates.length; i++) {
168
+ const polygon = getTilePolygon(coordinates[i], bbox, canonical);
169
+ polygons.push(polygon);
170
+ }
171
+ return polygons;
172
+ }
173
+
174
+ function updatePoint(p, bbox, polyBBox, worldSize) {
175
+ if (p[0] < polyBBox[0] || p[0] > polyBBox[2]) {
176
+ const halfWorldSize = worldSize * 0.5;
177
+ let shift = (p[0] - polyBBox[0] > halfWorldSize) ? -worldSize : (polyBBox[0] - p[0] > halfWorldSize) ? worldSize : 0;
178
+ if (shift === 0) {
179
+ shift = (p[0] - polyBBox[2] > halfWorldSize) ? -worldSize : (polyBBox[2] - p[0] > halfWorldSize) ? worldSize : 0;
180
+ }
181
+ p[0] += shift;
182
+ }
183
+ updateBBox(bbox, p);
184
+ }
185
+
186
+ function resetBBox(bbox) {
187
+ bbox[0] = bbox[1] = Infinity;
188
+ bbox[2] = bbox[3] = -Infinity;
189
+ }
190
+
191
+ function getTilePoints(geometry, pointBBox, polyBBox, canonical) {
192
+ const worldSize = Math.pow(2, canonical.z) * EXTENT;
193
+ const shifts = [canonical.x * EXTENT, canonical.y * EXTENT];
194
+ const tilePoints = [];
195
+ for (const points of geometry) {
196
+ for (const point of points) {
197
+ const p = [point.x + shifts[0], point.y + shifts[1]];
198
+ updatePoint(p, pointBBox, polyBBox, worldSize);
199
+ tilePoints.push(p);
200
+ }
201
+ }
202
+ return tilePoints;
203
+ }
204
+
205
+ function getTileLines(geometry, lineBBox, polyBBox, canonical) {
206
+ const worldSize = Math.pow(2, canonical.z) * EXTENT;
207
+ const shifts = [canonical.x * EXTENT, canonical.y * EXTENT];
208
+ const tileLines = [];
209
+ for (const line of geometry) {
210
+ const tileLine = [];
211
+ for (const point of line) {
212
+ const p = [point.x + shifts[0], point.y + shifts[1]];
213
+ updateBBox(lineBBox, p);
214
+ tileLine.push(p);
215
+ }
216
+ tileLines.push(tileLine);
217
+ }
218
+ if (lineBBox[2] - lineBBox[0] <= worldSize / 2) {
219
+ resetBBox(lineBBox);
220
+ for (const line of tileLines) {
221
+ for (const p of line) {
222
+ updatePoint(p, lineBBox, polyBBox, worldSize);
223
+ }
224
+ }
225
+ }
226
+ return tileLines;
227
+ }
228
+
229
+ function pointsWithinPolygons(ctx: EvaluationContext, polygonGeometry: GeoJSONPolygons) {
230
+ const pointBBox = [Infinity, Infinity, -Infinity, -Infinity];
231
+ const polyBBox = [Infinity, Infinity, -Infinity, -Infinity];
232
+
233
+ const canonical = ctx.canonicalID();
234
+
235
+ if (polygonGeometry.type === 'Polygon') {
236
+ const tilePolygon = getTilePolygon(polygonGeometry.coordinates, polyBBox, canonical);
237
+ const tilePoints = getTilePoints(ctx.geometry(), pointBBox, polyBBox, canonical);
238
+ if (!boxWithinBox(pointBBox, polyBBox)) return false;
239
+
240
+ for (const point of tilePoints) {
241
+ if (!pointWithinPolygon(point, tilePolygon)) return false;
242
+ }
243
+ }
244
+ if (polygonGeometry.type === 'MultiPolygon') {
245
+ const tilePolygons = getTilePolygons(polygonGeometry.coordinates, polyBBox, canonical);
246
+ const tilePoints = getTilePoints(ctx.geometry(), pointBBox, polyBBox, canonical);
247
+ if (!boxWithinBox(pointBBox, polyBBox)) return false;
248
+
249
+ for (const point of tilePoints) {
250
+ if (!pointWithinPolygons(point, tilePolygons)) return false;
251
+ }
252
+ }
253
+
254
+ return true;
255
+ }
256
+
257
+ function linesWithinPolygons(ctx: EvaluationContext, polygonGeometry: GeoJSONPolygons) {
258
+ const lineBBox = [Infinity, Infinity, -Infinity, -Infinity];
259
+ const polyBBox = [Infinity, Infinity, -Infinity, -Infinity];
260
+
261
+ const canonical = ctx.canonicalID();
262
+
263
+ if (polygonGeometry.type === 'Polygon') {
264
+ const tilePolygon = getTilePolygon(polygonGeometry.coordinates, polyBBox, canonical);
265
+ const tileLines = getTileLines(ctx.geometry(), lineBBox, polyBBox, canonical);
266
+ if (!boxWithinBox(lineBBox, polyBBox)) return false;
267
+
268
+ for (const line of tileLines) {
269
+ if (!lineStringWithinPolygon(line, tilePolygon)) return false;
270
+ }
271
+ }
272
+ if (polygonGeometry.type === 'MultiPolygon') {
273
+ const tilePolygons = getTilePolygons(polygonGeometry.coordinates, polyBBox, canonical);
274
+ const tileLines = getTileLines(ctx.geometry(), lineBBox, polyBBox, canonical);
275
+ if (!boxWithinBox(lineBBox, polyBBox)) return false;
276
+
277
+ for (const line of tileLines) {
278
+ if (!lineStringWithinPolygons(line, tilePolygons)) return false;
279
+ }
280
+ }
281
+ return true;
282
+ }
283
+
284
+ class Within implements Expression {
285
+ type: Type;
286
+ geojson: GeoJSON
287
+ geometries: GeoJSONPolygons;
288
+
289
+ constructor(geojson: GeoJSON, geometries: GeoJSONPolygons) {
290
+ this.type = BooleanType;
291
+ this.geojson = geojson;
292
+ this.geometries = geometries;
293
+ }
294
+
295
+ static parse(args: $ReadOnlyArray<mixed>, context: ParsingContext) {
296
+ if (args.length !== 2)
297
+ return context.error(`'within' expression requires exactly one argument, but found ${args.length - 1} instead.`);
298
+ if (isValue(args[1])) {
299
+ const geojson = (args[1]: Object);
300
+ if (geojson.type === 'FeatureCollection') {
301
+ for (let i = 0; i < geojson.features.length; ++i) {
302
+ const type = geojson.features[i].geometry.type;
303
+ if (type === 'Polygon' || type === 'MultiPolygon') {
304
+ return new Within(geojson, geojson.features[i].geometry);
305
+ }
306
+ }
307
+ } else if (geojson.type === 'Feature') {
308
+ const type = geojson.geometry.type;
309
+ if (type === 'Polygon' || type === 'MultiPolygon') {
310
+ return new Within(geojson, geojson.geometry);
311
+ }
312
+ } else if (geojson.type === 'Polygon' || geojson.type === 'MultiPolygon') {
313
+ return new Within(geojson, geojson);
314
+ }
315
+ }
316
+ return context.error(`'within' expression requires valid geojson object that contains polygon geometry type.`);
317
+ }
318
+
319
+ evaluate(ctx: EvaluationContext) {
320
+ if (ctx.geometry() != null && ctx.canonicalID() != null) {
321
+ if (ctx.geometryType() === 'Point') {
322
+ return pointsWithinPolygons(ctx, this.geometries);
323
+ } else if (ctx.geometryType() === 'LineString') {
324
+ return linesWithinPolygons(ctx, this.geometries);
325
+ }
326
+ }
327
+ return false;
328
+ }
329
+
330
+ eachChild() {}
331
+
332
+ outputDefined(): boolean {
333
+ return true;
334
+ }
335
+
336
+ serialize(): Array<mixed> {
337
+ return ["within", this.geojson];
338
+ }
339
+
340
+ }
341
+
342
+ export default Within;
node_modules/@plotly/mapbox-gl/src/style-spec/expression/evaluation_context.js ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ import {Color} from './values';
4
+ import type {FormattedSection} from './types/formatted';
5
+ import type {GlobalProperties, Feature, FeatureState} from './index';
6
+ import type {CanonicalTileID} from '../../source/tile_id';
7
+
8
+ const geometryTypes = ['Unknown', 'Point', 'LineString', 'Polygon'];
9
+
10
+ class EvaluationContext {
11
+ globals: GlobalProperties;
12
+ feature: ?Feature;
13
+ featureState: ?FeatureState;
14
+ formattedSection: ?FormattedSection;
15
+ availableImages: ?Array<string>;
16
+ canonical: ?CanonicalTileID;
17
+
18
+ _parseColorCache: {[_: string]: ?Color};
19
+
20
+ constructor() {
21
+ this.globals = (null: any);
22
+ this.feature = null;
23
+ this.featureState = null;
24
+ this.formattedSection = null;
25
+ this._parseColorCache = {};
26
+ this.availableImages = null;
27
+ this.canonical = null;
28
+ }
29
+
30
+ id() {
31
+ return this.feature && 'id' in this.feature ? this.feature.id : null;
32
+ }
33
+
34
+ geometryType() {
35
+ return this.feature ? typeof this.feature.type === 'number' ? geometryTypes[this.feature.type] : this.feature.type : null;
36
+ }
37
+
38
+ geometry() {
39
+ return this.feature && 'geometry' in this.feature ? this.feature.geometry : null;
40
+ }
41
+
42
+ canonicalID() {
43
+ return this.canonical;
44
+ }
45
+
46
+ properties() {
47
+ return this.feature && this.feature.properties || {};
48
+ }
49
+
50
+ parseColor(input: string): ?Color {
51
+ let cached = this._parseColorCache[input];
52
+ if (!cached) {
53
+ cached = this._parseColorCache[input] = Color.parse(input);
54
+ }
55
+ return cached;
56
+ }
57
+ }
58
+
59
+ export default EvaluationContext;
node_modules/@plotly/mapbox-gl/src/style-spec/expression/expression.js ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ import type {Type} from './types';
4
+ import type ParsingContext from './parsing_context';
5
+ import type EvaluationContext from './evaluation_context';
6
+
7
+ type SerializedExpression = Array<mixed> | string | number | boolean | null;
8
+
9
+ export interface Expression {
10
+ +type: Type;
11
+
12
+ evaluate(ctx: EvaluationContext): any;
13
+
14
+ eachChild(fn: Expression => void): void;
15
+
16
+ /**
17
+ * Statically analyze the expression, attempting to enumerate possible outputs. Returns
18
+ * false if the complete set of outputs is statically undecidable, otherwise true.
19
+ */
20
+ outputDefined(): boolean;
21
+
22
+ serialize(): SerializedExpression;
23
+ }
24
+
25
+ export type ExpressionParser = (args: $ReadOnlyArray<mixed>, context: ParsingContext) => ?Expression;
26
+ export type ExpressionRegistration = Class<Expression> & { +parse: ExpressionParser };
27
+ export type ExpressionRegistry = {[_: string]: ExpressionRegistration};
node_modules/@plotly/mapbox-gl/src/style-spec/expression/index.js ADDED
@@ -0,0 +1,392 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ import assert from 'assert';
4
+
5
+ import extend from '../util/extend';
6
+ import ParsingError from './parsing_error';
7
+ import ParsingContext from './parsing_context';
8
+ import EvaluationContext from './evaluation_context';
9
+ import CompoundExpression from './compound_expression';
10
+ import Step from './definitions/step';
11
+ import Interpolate from './definitions/interpolate';
12
+ import Coalesce from './definitions/coalesce';
13
+ import Let from './definitions/let';
14
+ import definitions from './definitions';
15
+ import * as isConstant from './is_constant';
16
+ import RuntimeError from './runtime_error';
17
+ import {success, error} from '../util/result';
18
+ import {supportsPropertyExpression, supportsZoomExpression, supportsInterpolation} from '../util/properties';
19
+
20
+ import type {Type, EvaluationKind} from './types';
21
+ import type {Value} from './values';
22
+ import type {Expression} from './expression';
23
+ import type {StylePropertySpecification} from '../style-spec';
24
+ import type {Result} from '../util/result';
25
+ import type {InterpolationType} from './definitions/interpolate';
26
+ import type {PropertyValueSpecification} from '../types';
27
+ import type {FormattedSection} from './types/formatted';
28
+ import type Point from '@mapbox/point-geometry';
29
+ import type {CanonicalTileID} from '../../source/tile_id';
30
+
31
+ export type Feature = {
32
+ +type: 1 | 2 | 3 | 'Unknown' | 'Point' | 'MultiPoint' | 'LineString' | 'MultiLineString' | 'Polygon' | 'MultiPolygon',
33
+ +id?: any,
34
+ +properties: {[_: string]: any},
35
+ +patterns?: {[_: string]: {"min": string, "mid": string, "max": string}},
36
+ +geometry?: Array<Array<Point>>
37
+ };
38
+
39
+ export type FeatureState = {[_: string]: any};
40
+
41
+ export type GlobalProperties = $ReadOnly<{
42
+ zoom: number,
43
+ heatmapDensity?: number,
44
+ lineProgress?: number,
45
+ isSupportedScript?: (_: string) => boolean,
46
+ accumulated?: Value
47
+ }>;
48
+
49
+ export class StyleExpression {
50
+ expression: Expression;
51
+
52
+ _evaluator: EvaluationContext;
53
+ _defaultValue: Value;
54
+ _warningHistory: {[key: string]: boolean};
55
+ _enumValues: ?{[_: string]: any};
56
+
57
+ constructor(expression: Expression, propertySpec: ?StylePropertySpecification) {
58
+ this.expression = expression;
59
+ this._warningHistory = {};
60
+ this._evaluator = new EvaluationContext();
61
+ this._defaultValue = propertySpec ? getDefaultValue(propertySpec) : null;
62
+ this._enumValues = propertySpec && propertySpec.type === 'enum' ? propertySpec.values : null;
63
+ }
64
+
65
+ evaluateWithoutErrorHandling(globals: GlobalProperties, feature?: Feature, featureState?: FeatureState, canonical?: CanonicalTileID, availableImages?: Array<string>, formattedSection?: FormattedSection): any {
66
+ this._evaluator.globals = globals;
67
+ this._evaluator.feature = feature;
68
+ this._evaluator.featureState = featureState;
69
+ this._evaluator.canonical = canonical;
70
+ this._evaluator.availableImages = availableImages || null;
71
+ this._evaluator.formattedSection = formattedSection;
72
+
73
+ return this.expression.evaluate(this._evaluator);
74
+ }
75
+
76
+ evaluate(globals: GlobalProperties, feature?: Feature, featureState?: FeatureState, canonical?: CanonicalTileID, availableImages?: Array<string>, formattedSection?: FormattedSection): any {
77
+ this._evaluator.globals = globals;
78
+ this._evaluator.feature = feature || null;
79
+ this._evaluator.featureState = featureState || null;
80
+ this._evaluator.canonical = canonical;
81
+ this._evaluator.availableImages = availableImages || null;
82
+ this._evaluator.formattedSection = formattedSection || null;
83
+
84
+ try {
85
+ const val = this.expression.evaluate(this._evaluator);
86
+ // eslint-disable-next-line no-self-compare
87
+ if (val === null || val === undefined || (typeof val === 'number' && val !== val)) {
88
+ return this._defaultValue;
89
+ }
90
+ if (this._enumValues && !(val in this._enumValues)) {
91
+ throw new RuntimeError(`Expected value to be one of ${Object.keys(this._enumValues).map(v => JSON.stringify(v)).join(', ')}, but found ${JSON.stringify(val)} instead.`);
92
+ }
93
+ return val;
94
+ } catch (e) {
95
+ if (!this._warningHistory[e.message]) {
96
+ this._warningHistory[e.message] = true;
97
+ if (typeof console !== 'undefined') {
98
+ console.warn(e.message);
99
+ }
100
+ }
101
+ return this._defaultValue;
102
+ }
103
+ }
104
+ }
105
+
106
+ export function isExpression(expression: mixed) {
107
+ return Array.isArray(expression) && expression.length > 0 &&
108
+ typeof expression[0] === 'string' && expression[0] in definitions;
109
+ }
110
+
111
+ /**
112
+ * Parse and typecheck the given style spec JSON expression. If
113
+ * options.defaultValue is provided, then the resulting StyleExpression's
114
+ * `evaluate()` method will handle errors by logging a warning (once per
115
+ * message) and returning the default value. Otherwise, it will throw
116
+ * evaluation errors.
117
+ *
118
+ * @private
119
+ */
120
+ export function createExpression(expression: mixed, propertySpec: ?StylePropertySpecification): Result<StyleExpression, Array<ParsingError>> {
121
+ const parser = new ParsingContext(definitions, [], propertySpec ? getExpectedType(propertySpec) : undefined);
122
+
123
+ // For string-valued properties, coerce to string at the top level rather than asserting.
124
+ const parsed = parser.parse(expression, undefined, undefined, undefined,
125
+ propertySpec && propertySpec.type === 'string' ? {typeAnnotation: 'coerce'} : undefined);
126
+
127
+ if (!parsed) {
128
+ assert(parser.errors.length > 0);
129
+ return error(parser.errors);
130
+ }
131
+
132
+ return success(new StyleExpression(parsed, propertySpec));
133
+ }
134
+
135
+ export class ZoomConstantExpression<Kind: EvaluationKind> {
136
+ kind: Kind;
137
+ isStateDependent: boolean;
138
+ _styleExpression: StyleExpression;
139
+
140
+ constructor(kind: Kind, expression: StyleExpression) {
141
+ this.kind = kind;
142
+ this._styleExpression = expression;
143
+ this.isStateDependent = kind !== ('constant': EvaluationKind) && !isConstant.isStateConstant(expression.expression);
144
+ }
145
+
146
+ evaluateWithoutErrorHandling(globals: GlobalProperties, feature?: Feature, featureState?: FeatureState, canonical?: CanonicalTileID, availableImages?: Array<string>, formattedSection?: FormattedSection): any {
147
+ return this._styleExpression.evaluateWithoutErrorHandling(globals, feature, featureState, canonical, availableImages, formattedSection);
148
+ }
149
+
150
+ evaluate(globals: GlobalProperties, feature?: Feature, featureState?: FeatureState, canonical?: CanonicalTileID, availableImages?: Array<string>, formattedSection?: FormattedSection): any {
151
+ return this._styleExpression.evaluate(globals, feature, featureState, canonical, availableImages, formattedSection);
152
+ }
153
+ }
154
+
155
+ export class ZoomDependentExpression<Kind: EvaluationKind> {
156
+ kind: Kind;
157
+ zoomStops: Array<number>;
158
+ isStateDependent: boolean;
159
+
160
+ _styleExpression: StyleExpression;
161
+ interpolationType: ?InterpolationType;
162
+
163
+ constructor(kind: Kind, expression: StyleExpression, zoomStops: Array<number>, interpolationType?: InterpolationType) {
164
+ this.kind = kind;
165
+ this.zoomStops = zoomStops;
166
+ this._styleExpression = expression;
167
+ this.isStateDependent = kind !== ('camera': EvaluationKind) && !isConstant.isStateConstant(expression.expression);
168
+ this.interpolationType = interpolationType;
169
+ }
170
+
171
+ evaluateWithoutErrorHandling(globals: GlobalProperties, feature?: Feature, featureState?: FeatureState, canonical?: CanonicalTileID, availableImages?: Array<string>, formattedSection?: FormattedSection): any {
172
+ return this._styleExpression.evaluateWithoutErrorHandling(globals, feature, featureState, canonical, availableImages, formattedSection);
173
+ }
174
+
175
+ evaluate(globals: GlobalProperties, feature?: Feature, featureState?: FeatureState, canonical?: CanonicalTileID, availableImages?: Array<string>, formattedSection?: FormattedSection): any {
176
+ return this._styleExpression.evaluate(globals, feature, featureState, canonical, availableImages, formattedSection);
177
+ }
178
+
179
+ interpolationFactor(input: number, lower: number, upper: number): number {
180
+ if (this.interpolationType) {
181
+ return Interpolate.interpolationFactor(this.interpolationType, input, lower, upper);
182
+ } else {
183
+ return 0;
184
+ }
185
+ }
186
+ }
187
+
188
+ export type ConstantExpression = {
189
+ kind: 'constant',
190
+ +evaluate: (globals: GlobalProperties, feature?: Feature, featureState?: FeatureState, canonical?: CanonicalTileID, availableImages?: Array<string>) => any,
191
+ }
192
+
193
+ export type SourceExpression = {
194
+ kind: 'source',
195
+ isStateDependent: boolean,
196
+ +evaluate: (globals: GlobalProperties, feature?: Feature, featureState?: FeatureState, canonical?: CanonicalTileID, availableImages?: Array<string>, formattedSection?: FormattedSection) => any,
197
+ };
198
+
199
+ export type CameraExpression = {
200
+ kind: 'camera',
201
+ +evaluate: (globals: GlobalProperties, feature?: Feature, featureState?: FeatureState, canonical?: CanonicalTileID, availableImages?: Array<string>) => any,
202
+ +interpolationFactor: (input: number, lower: number, upper: number) => number,
203
+ zoomStops: Array<number>,
204
+ interpolationType: ?InterpolationType
205
+ };
206
+
207
+ export type CompositeExpression = {
208
+ kind: 'composite',
209
+ isStateDependent: boolean,
210
+ +evaluate: (globals: GlobalProperties, feature?: Feature, featureState?: FeatureState, canonical?: CanonicalTileID, availableImages?: Array<string>, formattedSection?: FormattedSection) => any,
211
+ +interpolationFactor: (input: number, lower: number, upper: number) => number,
212
+ zoomStops: Array<number>,
213
+ interpolationType: ?InterpolationType
214
+ };
215
+
216
+ export type StylePropertyExpression =
217
+ | ConstantExpression
218
+ | SourceExpression
219
+ | CameraExpression
220
+ | CompositeExpression;
221
+
222
+ export function createPropertyExpression(expression: mixed, propertySpec: StylePropertySpecification): Result<StylePropertyExpression, Array<ParsingError>> {
223
+ expression = createExpression(expression, propertySpec);
224
+ if (expression.result === 'error') {
225
+ return expression;
226
+ }
227
+
228
+ const parsed = expression.value.expression;
229
+
230
+ const isFeatureConstant = isConstant.isFeatureConstant(parsed);
231
+ if (!isFeatureConstant && !supportsPropertyExpression(propertySpec)) {
232
+ return error([new ParsingError('', 'data expressions not supported')]);
233
+ }
234
+
235
+ const isZoomConstant = isConstant.isGlobalPropertyConstant(parsed, ['zoom']);
236
+ if (!isZoomConstant && !supportsZoomExpression(propertySpec)) {
237
+ return error([new ParsingError('', 'zoom expressions not supported')]);
238
+ }
239
+
240
+ const zoomCurve = findZoomCurve(parsed);
241
+ if (!zoomCurve && !isZoomConstant) {
242
+ return error([new ParsingError('', '"zoom" expression may only be used as input to a top-level "step" or "interpolate" expression.')]);
243
+ } else if (zoomCurve instanceof ParsingError) {
244
+ return error([zoomCurve]);
245
+ } else if (zoomCurve instanceof Interpolate && !supportsInterpolation(propertySpec)) {
246
+ return error([new ParsingError('', '"interpolate" expressions cannot be used with this property')]);
247
+ }
248
+
249
+ if (!zoomCurve) {
250
+ return success(isFeatureConstant ?
251
+ (new ZoomConstantExpression('constant', expression.value): ConstantExpression) :
252
+ (new ZoomConstantExpression('source', expression.value): SourceExpression));
253
+ }
254
+
255
+ const interpolationType = zoomCurve instanceof Interpolate ? zoomCurve.interpolation : undefined;
256
+
257
+ return success(isFeatureConstant ?
258
+ (new ZoomDependentExpression('camera', expression.value, zoomCurve.labels, interpolationType): CameraExpression) :
259
+ (new ZoomDependentExpression('composite', expression.value, zoomCurve.labels, interpolationType): CompositeExpression));
260
+ }
261
+
262
+ import {isFunction, createFunction} from '../function';
263
+ import {Color} from './values';
264
+
265
+ // serialization wrapper for old-style stop functions normalized to the
266
+ // expression interface
267
+ export class StylePropertyFunction<T> {
268
+ _parameters: PropertyValueSpecification<T>;
269
+ _specification: StylePropertySpecification;
270
+
271
+ kind: EvaluationKind;
272
+ evaluate: (globals: GlobalProperties, feature?: Feature) => any;
273
+ interpolationFactor: ?(input: number, lower: number, upper: number) => number;
274
+ zoomStops: ?Array<number>;
275
+
276
+ constructor(parameters: PropertyValueSpecification<T>, specification: StylePropertySpecification) {
277
+ this._parameters = parameters;
278
+ this._specification = specification;
279
+ extend(this, createFunction(this._parameters, this._specification));
280
+ }
281
+
282
+ static deserialize(serialized: {_parameters: PropertyValueSpecification<T>, _specification: StylePropertySpecification}) {
283
+ return ((new StylePropertyFunction(serialized._parameters, serialized._specification)): StylePropertyFunction<T>);
284
+ }
285
+
286
+ static serialize(input: StylePropertyFunction<T>) {
287
+ return {
288
+ _parameters: input._parameters,
289
+ _specification: input._specification
290
+ };
291
+ }
292
+ }
293
+
294
+ export function normalizePropertyExpression<T>(value: PropertyValueSpecification<T>, specification: StylePropertySpecification): StylePropertyExpression {
295
+ if (isFunction(value)) {
296
+ return (new StylePropertyFunction(value, specification): any);
297
+
298
+ } else if (isExpression(value)) {
299
+ const expression = createPropertyExpression(value, specification);
300
+ if (expression.result === 'error') {
301
+ // this should have been caught in validation
302
+ throw new Error(expression.value.map(err => `${err.key}: ${err.message}`).join(', '));
303
+ }
304
+ return expression.value;
305
+
306
+ } else {
307
+ let constant: any = value;
308
+ if (typeof value === 'string' && specification.type === 'color') {
309
+ constant = Color.parse(value);
310
+ }
311
+ return {
312
+ kind: 'constant',
313
+ evaluate: () => constant
314
+ };
315
+ }
316
+ }
317
+
318
+ // Zoom-dependent expressions may only use ["zoom"] as the input to a top-level "step" or "interpolate"
319
+ // expression (collectively referred to as a "curve"). The curve may be wrapped in one or more "let" or
320
+ // "coalesce" expressions.
321
+ function findZoomCurve(expression: Expression): Step | Interpolate | ParsingError | null {
322
+ let result = null;
323
+ if (expression instanceof Let) {
324
+ result = findZoomCurve(expression.result);
325
+
326
+ } else if (expression instanceof Coalesce) {
327
+ for (const arg of expression.args) {
328
+ result = findZoomCurve(arg);
329
+ if (result) {
330
+ break;
331
+ }
332
+ }
333
+
334
+ } else if ((expression instanceof Step || expression instanceof Interpolate) &&
335
+ expression.input instanceof CompoundExpression &&
336
+ expression.input.name === 'zoom') {
337
+
338
+ result = expression;
339
+ }
340
+
341
+ if (result instanceof ParsingError) {
342
+ return result;
343
+ }
344
+
345
+ expression.eachChild((child) => {
346
+ const childResult = findZoomCurve(child);
347
+ if (childResult instanceof ParsingError) {
348
+ result = childResult;
349
+ } else if (!result && childResult) {
350
+ result = new ParsingError('', '"zoom" expression may only be used as input to a top-level "step" or "interpolate" expression.');
351
+ } else if (result && childResult && result !== childResult) {
352
+ result = new ParsingError('', 'Only one zoom-based "step" or "interpolate" subexpression may be used in an expression.');
353
+ }
354
+ });
355
+
356
+ return result;
357
+ }
358
+
359
+ import {ColorType, StringType, NumberType, BooleanType, ValueType, FormattedType, ResolvedImageType, array} from './types';
360
+
361
+ function getExpectedType(spec: StylePropertySpecification): Type {
362
+ const types = {
363
+ color: ColorType,
364
+ string: StringType,
365
+ number: NumberType,
366
+ enum: StringType,
367
+ boolean: BooleanType,
368
+ formatted: FormattedType,
369
+ resolvedImage: ResolvedImageType
370
+ };
371
+
372
+ if (spec.type === 'array') {
373
+ return array(types[spec.value] || ValueType, spec.length);
374
+ }
375
+
376
+ return types[spec.type];
377
+ }
378
+
379
+ function getDefaultValue(spec: StylePropertySpecification): Value {
380
+ if (spec.type === 'color' && isFunction(spec.default)) {
381
+ // Special case for heatmap-color: it uses the 'default:' to define a
382
+ // default color ramp, but createExpression expects a simple value to fall
383
+ // back to in case of runtime errors
384
+ return new Color(0, 0, 0, 0);
385
+ } else if (spec.type === 'color') {
386
+ return Color.parse(spec.default) || null;
387
+ } else if (spec.default === undefined) {
388
+ return null;
389
+ } else {
390
+ return spec.default;
391
+ }
392
+ }
node_modules/@plotly/mapbox-gl/src/style-spec/expression/is_constant.js ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ import CompoundExpression from './compound_expression';
4
+ import Within from './definitions/within';
5
+ import type {Expression} from './expression.js';
6
+
7
+ function isFeatureConstant(e: Expression) {
8
+ if (e instanceof CompoundExpression) {
9
+ if (e.name === 'get' && e.args.length === 1) {
10
+ return false;
11
+ } else if (e.name === 'feature-state') {
12
+ return false;
13
+ } else if (e.name === 'has' && e.args.length === 1) {
14
+ return false;
15
+ } else if (
16
+ e.name === 'properties' ||
17
+ e.name === 'geometry-type' ||
18
+ e.name === 'id'
19
+ ) {
20
+ return false;
21
+ } else if (/^filter-/.test(e.name)) {
22
+ return false;
23
+ }
24
+ }
25
+
26
+ if (e instanceof Within) {
27
+ return false;
28
+ }
29
+
30
+ let result = true;
31
+ e.eachChild(arg => {
32
+ if (result && !isFeatureConstant(arg)) { result = false; }
33
+ });
34
+ return result;
35
+ }
36
+
37
+ function isStateConstant(e: Expression) {
38
+ if (e instanceof CompoundExpression) {
39
+ if (e.name === 'feature-state') {
40
+ return false;
41
+ }
42
+ }
43
+ let result = true;
44
+ e.eachChild(arg => {
45
+ if (result && !isStateConstant(arg)) { result = false; }
46
+ });
47
+ return result;
48
+ }
49
+
50
+ function isGlobalPropertyConstant(e: Expression, properties: Array<string>) {
51
+ if (e instanceof CompoundExpression && properties.indexOf(e.name) >= 0) { return false; }
52
+ let result = true;
53
+ e.eachChild((arg) => {
54
+ if (result && !isGlobalPropertyConstant(arg, properties)) { result = false; }
55
+ });
56
+ return result;
57
+ }
58
+
59
+ export {isFeatureConstant, isGlobalPropertyConstant, isStateConstant};
node_modules/@plotly/mapbox-gl/src/style-spec/expression/parsing_context.js ADDED
@@ -0,0 +1,233 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ import Scope from './scope';
4
+ import {checkSubtype} from './types';
5
+ import ParsingError from './parsing_error';
6
+ import Literal from './definitions/literal';
7
+ import Assertion from './definitions/assertion';
8
+ import Coercion from './definitions/coercion';
9
+ import EvaluationContext from './evaluation_context';
10
+ import CompoundExpression from './compound_expression';
11
+ import CollatorExpression from './definitions/collator';
12
+ import Within from './definitions/within';
13
+ import {isGlobalPropertyConstant, isFeatureConstant} from './is_constant';
14
+ import Var from './definitions/var';
15
+
16
+ import type {Expression, ExpressionRegistry} from './expression';
17
+ import type {Type} from './types';
18
+
19
+ /**
20
+ * State associated parsing at a given point in an expression tree.
21
+ * @private
22
+ */
23
+ class ParsingContext {
24
+ registry: ExpressionRegistry;
25
+ path: Array<number>;
26
+ key: string;
27
+ scope: Scope;
28
+ errors: Array<ParsingError>;
29
+
30
+ // The expected type of this expression. Provided only to allow Expression
31
+ // implementations to infer argument types: Expression#parse() need not
32
+ // check that the output type of the parsed expression matches
33
+ // `expectedType`.
34
+ expectedType: ?Type;
35
+
36
+ constructor(
37
+ registry: ExpressionRegistry,
38
+ path: Array<number> = [],
39
+ expectedType: ?Type,
40
+ scope: Scope = new Scope(),
41
+ errors: Array<ParsingError> = []
42
+ ) {
43
+ this.registry = registry;
44
+ this.path = path;
45
+ this.key = path.map(part => `[${part}]`).join('');
46
+ this.scope = scope;
47
+ this.errors = errors;
48
+ this.expectedType = expectedType;
49
+ }
50
+
51
+ /**
52
+ * @param expr the JSON expression to parse
53
+ * @param index the optional argument index if this expression is an argument of a parent expression that's being parsed
54
+ * @param options
55
+ * @param options.omitTypeAnnotations set true to omit inferred type annotations. Caller beware: with this option set, the parsed expression's type will NOT satisfy `expectedType` if it would normally be wrapped in an inferred annotation.
56
+ * @private
57
+ */
58
+ parse(
59
+ expr: mixed,
60
+ index?: number,
61
+ expectedType?: ?Type,
62
+ bindings?: Array<[string, Expression]>,
63
+ options: {typeAnnotation?: 'assert' | 'coerce' | 'omit'} = {}
64
+ ): ?Expression {
65
+ if (index) {
66
+ return this.concat(index, expectedType, bindings)._parse(expr, options);
67
+ }
68
+ return this._parse(expr, options);
69
+ }
70
+
71
+ _parse(expr: mixed, options: {typeAnnotation?: 'assert' | 'coerce' | 'omit'}): ?Expression {
72
+ if (expr === null || typeof expr === 'string' || typeof expr === 'boolean' || typeof expr === 'number') {
73
+ expr = ['literal', expr];
74
+ }
75
+
76
+ function annotate(parsed, type, typeAnnotation: 'assert' | 'coerce' | 'omit') {
77
+ if (typeAnnotation === 'assert') {
78
+ return new Assertion(type, [parsed]);
79
+ } else if (typeAnnotation === 'coerce') {
80
+ return new Coercion(type, [parsed]);
81
+ } else {
82
+ return parsed;
83
+ }
84
+ }
85
+
86
+ if (Array.isArray(expr)) {
87
+ if (expr.length === 0) {
88
+ return this.error(`Expected an array with at least one element. If you wanted a literal array, use ["literal", []].`);
89
+ }
90
+
91
+ const op = expr[0];
92
+ if (typeof op !== 'string') {
93
+ this.error(`Expression name must be a string, but found ${typeof op} instead. If you wanted a literal array, use ["literal", [...]].`, 0);
94
+ return null;
95
+ }
96
+
97
+ const Expr = this.registry[op];
98
+ if (Expr) {
99
+ let parsed = Expr.parse(expr, this);
100
+ if (!parsed) return null;
101
+
102
+ if (this.expectedType) {
103
+ const expected = this.expectedType;
104
+ const actual = parsed.type;
105
+
106
+ // When we expect a number, string, boolean, or array but have a value, wrap it in an assertion.
107
+ // When we expect a color or formatted string, but have a string or value, wrap it in a coercion.
108
+ // Otherwise, we do static type-checking.
109
+ //
110
+ // These behaviors are overridable for:
111
+ // * The "coalesce" operator, which needs to omit type annotations.
112
+ // * String-valued properties (e.g. `text-field`), where coercion is more convenient than assertion.
113
+ //
114
+ if ((expected.kind === 'string' || expected.kind === 'number' || expected.kind === 'boolean' || expected.kind === 'object' || expected.kind === 'array') && actual.kind === 'value') {
115
+ parsed = annotate(parsed, expected, options.typeAnnotation || 'assert');
116
+ } else if ((expected.kind === 'color' || expected.kind === 'formatted' || expected.kind === 'resolvedImage') && (actual.kind === 'value' || actual.kind === 'string')) {
117
+ parsed = annotate(parsed, expected, options.typeAnnotation || 'coerce');
118
+ } else if (this.checkSubtype(expected, actual)) {
119
+ return null;
120
+ }
121
+ }
122
+
123
+ // If an expression's arguments are all literals, we can evaluate
124
+ // it immediately and replace it with a literal value in the
125
+ // parsed/compiled result. Expressions that expect an image should
126
+ // not be resolved here so we can later get the available images.
127
+ if (!(parsed instanceof Literal) && (parsed.type.kind !== 'resolvedImage') && isConstant(parsed)) {
128
+ const ec = new EvaluationContext();
129
+ try {
130
+ parsed = new Literal(parsed.type, parsed.evaluate(ec));
131
+ } catch (e) {
132
+ this.error(e.message);
133
+ return null;
134
+ }
135
+ }
136
+
137
+ return parsed;
138
+ }
139
+
140
+ return this.error(`Unknown expression "${op}". If you wanted a literal array, use ["literal", [...]].`, 0);
141
+ } else if (typeof expr === 'undefined') {
142
+ return this.error(`'undefined' value invalid. Use null instead.`);
143
+ } else if (typeof expr === 'object') {
144
+ return this.error(`Bare objects invalid. Use ["literal", {...}] instead.`);
145
+ } else {
146
+ return this.error(`Expected an array, but found ${typeof expr} instead.`);
147
+ }
148
+ }
149
+
150
+ /**
151
+ * Returns a copy of this context suitable for parsing the subexpression at
152
+ * index `index`, optionally appending to 'let' binding map.
153
+ *
154
+ * Note that `errors` property, intended for collecting errors while
155
+ * parsing, is copied by reference rather than cloned.
156
+ * @private
157
+ */
158
+ concat(index: number, expectedType?: ?Type, bindings?: Array<[string, Expression]>) {
159
+ const path = typeof index === 'number' ? this.path.concat(index) : this.path;
160
+ const scope = bindings ? this.scope.concat(bindings) : this.scope;
161
+ return new ParsingContext(
162
+ this.registry,
163
+ path,
164
+ expectedType || null,
165
+ scope,
166
+ this.errors
167
+ );
168
+ }
169
+
170
+ /**
171
+ * Push a parsing (or type checking) error into the `this.errors`
172
+ * @param error The message
173
+ * @param keys Optionally specify the source of the error at a child
174
+ * of the current expression at `this.key`.
175
+ * @private
176
+ */
177
+ error(error: string, ...keys: Array<number>) {
178
+ const key = `${this.key}${keys.map(k => `[${k}]`).join('')}`;
179
+ this.errors.push(new ParsingError(key, error));
180
+ }
181
+
182
+ /**
183
+ * Returns null if `t` is a subtype of `expected`; otherwise returns an
184
+ * error message and also pushes it to `this.errors`.
185
+ */
186
+ checkSubtype(expected: Type, t: Type): ?string {
187
+ const error = checkSubtype(expected, t);
188
+ if (error) this.error(error);
189
+ return error;
190
+ }
191
+ }
192
+
193
+ export default ParsingContext;
194
+
195
+ function isConstant(expression: Expression) {
196
+ if (expression instanceof Var) {
197
+ return isConstant(expression.boundExpression);
198
+ } else if (expression instanceof CompoundExpression && expression.name === 'error') {
199
+ return false;
200
+ } else if (expression instanceof CollatorExpression) {
201
+ // Although the results of a Collator expression with fixed arguments
202
+ // generally shouldn't change between executions, we can't serialize them
203
+ // as constant expressions because results change based on environment.
204
+ return false;
205
+ } else if (expression instanceof Within) {
206
+ return false;
207
+ }
208
+
209
+ const isTypeAnnotation = expression instanceof Coercion ||
210
+ expression instanceof Assertion;
211
+
212
+ let childrenConstant = true;
213
+ expression.eachChild(child => {
214
+ // We can _almost_ assume that if `expressions` children are constant,
215
+ // they would already have been evaluated to Literal values when they
216
+ // were parsed. Type annotations are the exception, because they might
217
+ // have been inferred and added after a child was parsed.
218
+
219
+ // So we recurse into isConstant() for the children of type annotations,
220
+ // but otherwise simply check whether they are Literals.
221
+ if (isTypeAnnotation) {
222
+ childrenConstant = childrenConstant && isConstant(child);
223
+ } else {
224
+ childrenConstant = childrenConstant && child instanceof Literal;
225
+ }
226
+ });
227
+ if (!childrenConstant) {
228
+ return false;
229
+ }
230
+
231
+ return isFeatureConstant(expression) &&
232
+ isGlobalPropertyConstant(expression, ['zoom', 'heatmap-density', 'line-progress', 'accumulated', 'is-supported-script']);
233
+ }
node_modules/@plotly/mapbox-gl/src/style-spec/expression/parsing_error.js ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ class ParsingError extends Error {
4
+ key: string;
5
+ message: string;
6
+ constructor(key: string, message: string) {
7
+ super(message);
8
+ this.message = message;
9
+ this.key = key;
10
+ }
11
+ }
12
+
13
+ export default ParsingError;
node_modules/@plotly/mapbox-gl/src/style-spec/expression/runtime_error.js ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ class RuntimeError {
4
+ name: string;
5
+ message: string;
6
+
7
+ constructor(message: string) {
8
+ this.name = 'ExpressionEvaluationError';
9
+ this.message = message;
10
+ }
11
+
12
+ toJSON() {
13
+ return this.message;
14
+ }
15
+ }
16
+
17
+ export default RuntimeError;
node_modules/@plotly/mapbox-gl/src/style-spec/expression/scope.js ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ import type {Expression} from './expression';
4
+
5
+ /**
6
+ * Tracks `let` bindings during expression parsing.
7
+ * @private
8
+ */
9
+ class Scope {
10
+ parent: ?Scope;
11
+ bindings: {[_: string]: Expression};
12
+ constructor(parent?: Scope, bindings: Array<[string, Expression]> = []) {
13
+ this.parent = parent;
14
+ this.bindings = {};
15
+ for (const [name, expression] of bindings) {
16
+ this.bindings[name] = expression;
17
+ }
18
+ }
19
+
20
+ concat(bindings: Array<[string, Expression]>) {
21
+ return new Scope(this, bindings);
22
+ }
23
+
24
+ get(name: string): Expression {
25
+ if (this.bindings[name]) { return this.bindings[name]; }
26
+ if (this.parent) { return this.parent.get(name); }
27
+ throw new Error(`${name} not found in scope.`);
28
+ }
29
+
30
+ has(name: string): boolean {
31
+ if (this.bindings[name]) return true;
32
+ return this.parent ? this.parent.has(name) : false;
33
+ }
34
+ }
35
+
36
+ export default Scope;
node_modules/@plotly/mapbox-gl/src/style-spec/expression/stops.js ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ import RuntimeError from './runtime_error';
4
+
5
+ import type {Expression} from './expression';
6
+
7
+ export type Stops = Array<[number, Expression]>;
8
+
9
+ /**
10
+ * Returns the index of the last stop <= input, or 0 if it doesn't exist.
11
+ * @private
12
+ */
13
+ export function findStopLessThanOrEqualTo(stops: Array<number>, input: number) {
14
+ const lastIndex = stops.length - 1;
15
+ let lowerIndex = 0;
16
+ let upperIndex = lastIndex;
17
+ let currentIndex = 0;
18
+ let currentValue, nextValue;
19
+
20
+ while (lowerIndex <= upperIndex) {
21
+ currentIndex = Math.floor((lowerIndex + upperIndex) / 2);
22
+ currentValue = stops[currentIndex];
23
+ nextValue = stops[currentIndex + 1];
24
+
25
+ if (currentValue <= input) {
26
+ if (currentIndex === lastIndex || input < nextValue) { // Search complete
27
+ return currentIndex;
28
+ }
29
+
30
+ lowerIndex = currentIndex + 1;
31
+ } else if (currentValue > input) {
32
+ upperIndex = currentIndex - 1;
33
+ } else {
34
+ throw new RuntimeError('Input is not a number.');
35
+ }
36
+ }
37
+
38
+ return 0;
39
+ }
node_modules/@plotly/mapbox-gl/src/style-spec/expression/types.js ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ export type NullTypeT = { kind: 'null' };
4
+ export type NumberTypeT = { kind: 'number' };
5
+ export type StringTypeT = { kind: 'string' };
6
+ export type BooleanTypeT = { kind: 'boolean' };
7
+ export type ColorTypeT = { kind: 'color' };
8
+ export type ObjectTypeT = { kind: 'object' };
9
+ export type ValueTypeT = { kind: 'value' };
10
+ export type ErrorTypeT = { kind: 'error' };
11
+ export type CollatorTypeT = { kind: 'collator' };
12
+ export type FormattedTypeT = { kind: 'formatted' };
13
+ export type ResolvedImageTypeT = { kind: 'resolvedImage' };
14
+
15
+ export type EvaluationKind = 'constant' | 'source' | 'camera' | 'composite';
16
+
17
+ export type Type =
18
+ NullTypeT |
19
+ NumberTypeT |
20
+ StringTypeT |
21
+ BooleanTypeT |
22
+ ColorTypeT |
23
+ ObjectTypeT |
24
+ ValueTypeT |
25
+ ArrayType | // eslint-disable-line no-use-before-define
26
+ ErrorTypeT |
27
+ CollatorTypeT |
28
+ FormattedTypeT |
29
+ ResolvedImageTypeT
30
+
31
+ export type ArrayType = {
32
+ kind: 'array',
33
+ itemType: Type,
34
+ N: ?number
35
+ }
36
+
37
+ export type NativeType = 'number' | 'string' | 'boolean' | 'null' | 'array' | 'object'
38
+
39
+ export const NullType = {kind: 'null'};
40
+ export const NumberType = {kind: 'number'};
41
+ export const StringType = {kind: 'string'};
42
+ export const BooleanType = {kind: 'boolean'};
43
+ export const ColorType = {kind: 'color'};
44
+ export const ObjectType = {kind: 'object'};
45
+ export const ValueType = {kind: 'value'};
46
+ export const ErrorType = {kind: 'error'};
47
+ export const CollatorType = {kind: 'collator'};
48
+ export const FormattedType = {kind: 'formatted'};
49
+ export const ResolvedImageType = {kind: 'resolvedImage'};
50
+
51
+ export function array(itemType: Type, N: ?number): ArrayType {
52
+ return {
53
+ kind: 'array',
54
+ itemType,
55
+ N
56
+ };
57
+ }
58
+
59
+ export function toString(type: Type): string {
60
+ if (type.kind === 'array') {
61
+ const itemType = toString(type.itemType);
62
+ return typeof type.N === 'number' ?
63
+ `array<${itemType}, ${type.N}>` :
64
+ type.itemType.kind === 'value' ? 'array' : `array<${itemType}>`;
65
+ } else {
66
+ return type.kind;
67
+ }
68
+ }
69
+
70
+ const valueMemberTypes = [
71
+ NullType,
72
+ NumberType,
73
+ StringType,
74
+ BooleanType,
75
+ ColorType,
76
+ FormattedType,
77
+ ObjectType,
78
+ array(ValueType),
79
+ ResolvedImageType
80
+ ];
81
+
82
+ /**
83
+ * Returns null if `t` is a subtype of `expected`; otherwise returns an
84
+ * error message.
85
+ * @private
86
+ */
87
+ export function checkSubtype(expected: Type, t: Type): ?string {
88
+ if (t.kind === 'error') {
89
+ // Error is a subtype of every type
90
+ return null;
91
+ } else if (expected.kind === 'array') {
92
+ if (t.kind === 'array' &&
93
+ ((t.N === 0 && t.itemType.kind === 'value') || !checkSubtype(expected.itemType, t.itemType)) &&
94
+ (typeof expected.N !== 'number' || expected.N === t.N)) {
95
+ return null;
96
+ }
97
+ } else if (expected.kind === t.kind) {
98
+ return null;
99
+ } else if (expected.kind === 'value') {
100
+ for (const memberType of valueMemberTypes) {
101
+ if (!checkSubtype(memberType, t)) {
102
+ return null;
103
+ }
104
+ }
105
+ }
106
+
107
+ return `Expected ${toString(expected)} but found ${toString(t)} instead.`;
108
+ }
109
+
110
+ export function isValidType(provided: Type, allowedTypes: Array<Type>): boolean {
111
+ return allowedTypes.some(t => t.kind === provided.kind);
112
+ }
113
+
114
+ export function isValidNativeType(provided: any, allowedTypes: Array<NativeType>): boolean {
115
+ return allowedTypes.some(t => {
116
+ if (t === 'null') {
117
+ return provided === null;
118
+ } else if (t === 'array') {
119
+ return Array.isArray(provided);
120
+ } else if (t === 'object') {
121
+ return provided && !Array.isArray(provided) && typeof provided === 'object';
122
+ } else {
123
+ return t === typeof provided;
124
+ }
125
+ });
126
+ }
node_modules/@plotly/mapbox-gl/src/style-spec/expression/types/collator.js ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // @flow
2
+
3
+ // Flow type declarations for Intl cribbed from
4
+ // https://github.com/facebook/flow/issues/1270
5
+
6
+ declare var Intl: {
7
+ Collator: Class<Intl$Collator>
8
+ };
9
+
10
+ declare class Intl$Collator {
11
+ constructor (
12
+ locales?: string | string[],
13
+ options?: CollatorOptions
14
+ ): Intl$Collator;
15
+
16
+ static (
17
+ locales?: string | string[],
18
+ options?: CollatorOptions
19
+ ): Intl$Collator;
20
+
21
+ compare (a: string, b: string): number;
22
+
23
+ resolvedOptions(): any;
24
+ }
25
+
26
+ type CollatorOptions = {
27
+ localeMatcher?: 'lookup' | 'best fit',
28
+ usage?: 'sort' | 'search',
29
+ sensitivity?: 'base' | 'accent' | 'case' | 'variant',
30
+ ignorePunctuation?: boolean,
31
+ numeric?: boolean,
32
+ caseFirst?: 'upper' | 'lower' | 'false'
33
+ }
34
+
35
+ export default class Collator {
36
+ locale: string | null;
37
+ sensitivity: 'base' | 'accent' | 'case' | 'variant';
38
+ collator: Intl$Collator;
39
+
40
+ constructor(caseSensitive: boolean, diacriticSensitive: boolean, locale: string | null) {
41
+ if (caseSensitive)
42
+ this.sensitivity = diacriticSensitive ? 'variant' : 'case';
43
+ else
44
+ this.sensitivity = diacriticSensitive ? 'accent' : 'base';
45
+
46
+ this.locale = locale;
47
+ this.collator = new Intl.Collator(this.locale ? this.locale : [],
48
+ {sensitivity: this.sensitivity, usage: 'search'});
49
+ }
50
+
51
+ compare(lhs: string, rhs: string): number {
52
+ return this.collator.compare(lhs, rhs);
53
+ }
54
+
55
+ resolvedLocale(): string {
56
+ // We create a Collator without "usage: search" because we don't want
57
+ // the search options encoded in our result (e.g. "en-u-co-search")
58
+ return new Intl.Collator(this.locale ? this.locale : [])
59
+ .resolvedOptions().locale;
60
+ }
61
+ }