@evergis/common 0.0.112 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +0 -28
  3. package/dist/classification/ClientStyleValidator/ClientStyleValidator.d.ts +26 -0
  4. package/dist/classification/ClientStyleValidator/constants.d.ts +2 -0
  5. package/dist/classification/ClientStyleValidator/index.d.ts +2 -0
  6. package/dist/classification/ClientStyleValidator/types.d.ts +10 -0
  7. package/dist/classification/enrichStyleItemsWithIds.d.ts +2 -0
  8. package/dist/classification/enrichStyleModelsWithIds.d.ts +2 -0
  9. package/dist/classification/findAttributeInExpression.d.ts +2 -0
  10. package/dist/classification/getActualExtrusionHeight.d.ts +2 -0
  11. package/dist/classification/getClientStyleItemId.d.ts +3 -0
  12. package/dist/classification/getLayerClientStyle.d.ts +3 -0
  13. package/dist/classification/getStyleAttributes.d.ts +2 -0
  14. package/dist/classification/index.d.ts +8 -0
  15. package/dist/common.esm.js +2507 -279
  16. package/dist/common.esm.js.map +1 -1
  17. package/dist/constants/index.d.ts +1 -0
  18. package/dist/constants/styling.d.ts +36 -0
  19. package/dist/icons/index.d.ts +1 -0
  20. package/dist/icons/parseIconNames.d.ts +27 -0
  21. package/dist/index.d.ts +7 -5
  22. package/dist/index.js +2609 -5
  23. package/dist/index.js.map +1 -0
  24. package/dist/map/constants.d.ts +4 -0
  25. package/dist/map/getMapView.d.ts +10 -0
  26. package/dist/map/index.d.ts +4 -0
  27. package/dist/map/parseMapStyle.d.ts +19 -0
  28. package/dist/map/types.d.ts +7 -0
  29. package/dist/taskParameters/SchemaResolver.d.ts +14 -0
  30. package/dist/taskParameters/buildDefaultForSchema.d.ts +23 -0
  31. package/dist/taskParameters/getPrimaryType.d.ts +2 -0
  32. package/dist/taskParameters/index.d.ts +6 -0
  33. package/dist/taskParameters/mergeHiddenFieldDefaults.d.ts +2 -0
  34. package/dist/taskParameters/orderPropertyKeys.d.ts +2 -0
  35. package/dist/taskParameters/types.d.ts +36 -0
  36. package/dist/types/attribute.d.ts +18 -0
  37. package/dist/types/feature.d.ts +11 -0
  38. package/dist/types/index.d.ts +6 -0
  39. package/dist/types/layer.d.ts +5 -0
  40. package/dist/types/project.d.ts +4 -0
  41. package/dist/types/styling.d.ts +36 -0
  42. package/dist/types/theme.d.ts +4 -0
  43. package/dist/utils/color.d.ts +28 -0
  44. package/dist/utils/date.d.ts +16 -0
  45. package/dist/utils/debounce.d.ts +1 -0
  46. package/dist/utils/format.d.ts +47 -0
  47. package/dist/utils/geometryToEwkt.d.ts +2 -0
  48. package/dist/utils/index.d.ts +10 -1
  49. package/dist/utils/isLayerService.d.ts +2 -0
  50. package/dist/utils/isNumeric.d.ts +1 -0
  51. package/dist/utils/isObject.d.ts +1 -0
  52. package/dist/utils/metersPerPixel.d.ts +1 -0
  53. package/dist/utils/roundTotalSum.d.ts +2 -0
  54. package/package.json +35 -54
  55. package/dist/ApiProvider.d.ts +0 -7
  56. package/dist/common.cjs.development.js +0 -310
  57. package/dist/common.cjs.development.js.map +0 -1
  58. package/dist/common.cjs.production.min.js +0 -2
  59. package/dist/common.cjs.production.min.js.map +0 -1
  60. package/dist/components/Politics/PolicyItem.d.ts +0 -3
  61. package/dist/components/Politics/hooks/usePolitics.d.ts +0 -8
  62. package/dist/components/Politics/index.d.ts +0 -3
  63. package/dist/components/Politics/styled.d.ts +0 -11
  64. package/dist/components/Politics/types.d.ts +0 -24
  65. package/dist/components/index.d.ts +0 -1
  66. package/dist/i18n/index.d.ts +0 -24
  67. package/dist/resources/index.d.ts +0 -1
  68. package/dist/resources/limits.d.ts +0 -2
  69. package/dist/utils/formatNumber.d.ts +0 -1
package/dist/index.js CHANGED
@@ -1,8 +1,2612 @@
1
+ 'use strict';
1
2
 
2
- 'use strict'
3
+ var mapboxGlStyleSpec = require('@mapbox/mapbox-gl-style-spec');
4
+ var lodash = require('lodash');
5
+ var uuid = require('uuid');
6
+ var turf = require('@turf/turf');
7
+ var dateFns = require('date-fns');
8
+ var locale = require('date-fns/locale');
9
+ var api = require('@evergis/api');
10
+ var wkt = require('wkt');
3
11
 
4
- if (process.env.NODE_ENV === 'production') {
5
- module.exports = require('./common.cjs.production.min.js')
6
- } else {
7
- module.exports = require('./common.cjs.development.js')
12
+ /* ---------------------------------------------------------------------------------------------------------------- *
13
+ * Data-driven style information provided according to https://docs.mapbox.com/style-spec/reference/layers/ *
14
+ * Note: MapLibre is based on the fork of the final open-source Mapbox version 1.13.0 *
15
+ * ---------------------------------------------------------------------------------------------------------------- */
16
+ const SPEC_PROP_VALUE_OPTIONS = {
17
+ // circle
18
+ "circle-color": {
19
+ dataExpressionSupport: true,
20
+ interpolateExpressionSupport: true,
21
+ transitionable: true,
22
+ valueTypeAllowed: "string",
23
+ },
24
+ "circle-opacity": {
25
+ dataExpressionSupport: true,
26
+ interpolateExpressionSupport: true,
27
+ transitionable: true,
28
+ valueTypeAllowed: "number",
29
+ },
30
+ "circle-stroke-color": {
31
+ dataExpressionSupport: true,
32
+ interpolateExpressionSupport: true,
33
+ transitionable: true,
34
+ valueTypeAllowed: "string",
35
+ },
36
+ "circle-stroke-opacity": {
37
+ dataExpressionSupport: true,
38
+ interpolateExpressionSupport: true,
39
+ transitionable: true,
40
+ valueTypeAllowed: "number",
41
+ },
42
+ "circle-radius": {
43
+ dataExpressionSupport: true,
44
+ interpolateExpressionSupport: true,
45
+ transitionable: true,
46
+ valueTypeAllowed: "number",
47
+ },
48
+ "circle-stroke-width": {
49
+ dataExpressionSupport: true,
50
+ interpolateExpressionSupport: true,
51
+ transitionable: true,
52
+ valueTypeAllowed: "number",
53
+ },
54
+ "circle-blur": {
55
+ dataExpressionSupport: true,
56
+ interpolateExpressionSupport: true,
57
+ transitionable: true,
58
+ valueTypeAllowed: "number",
59
+ },
60
+ "circle-translate": {
61
+ dataExpressionSupport: false,
62
+ interpolateExpressionSupport: true,
63
+ transitionable: true,
64
+ valueTypeAllowed: "number",
65
+ arrayValue: true,
66
+ },
67
+ // fill
68
+ "fill-color": {
69
+ dataExpressionSupport: true,
70
+ interpolateExpressionSupport: true,
71
+ transitionable: true,
72
+ valueTypeAllowed: "string",
73
+ },
74
+ "fill-opacity": {
75
+ dataExpressionSupport: true,
76
+ interpolateExpressionSupport: true,
77
+ transitionable: true,
78
+ valueTypeAllowed: "number",
79
+ },
80
+ // fill-extrusion
81
+ "fill-extrusion-color": {
82
+ dataExpressionSupport: true,
83
+ interpolateExpressionSupport: true,
84
+ transitionable: true,
85
+ valueTypeAllowed: "string",
86
+ },
87
+ "fill-extrusion-opacity": {
88
+ dataExpressionSupport: false,
89
+ interpolateExpressionSupport: true,
90
+ transitionable: true,
91
+ valueTypeAllowed: "number",
92
+ },
93
+ "fill-extrusion-base": {
94
+ dataExpressionSupport: true,
95
+ interpolateExpressionSupport: true,
96
+ transitionable: true,
97
+ valueTypeAllowed: "number",
98
+ },
99
+ "fill-extrusion-height": {
100
+ dataExpressionSupport: true,
101
+ interpolateExpressionSupport: true,
102
+ transitionable: true,
103
+ valueTypeAllowed: "number",
104
+ },
105
+ // line
106
+ "line-color": {
107
+ dataExpressionSupport: true,
108
+ interpolateExpressionSupport: true,
109
+ transitionable: true,
110
+ valueTypeAllowed: "string",
111
+ },
112
+ "line-opacity": {
113
+ dataExpressionSupport: true,
114
+ interpolateExpressionSupport: true,
115
+ transitionable: true,
116
+ valueTypeAllowed: "number",
117
+ },
118
+ "line-width": {
119
+ dataExpressionSupport: true,
120
+ interpolateExpressionSupport: true,
121
+ transitionable: true,
122
+ valueTypeAllowed: "number",
123
+ },
124
+ "line-blur": {
125
+ dataExpressionSupport: true,
126
+ interpolateExpressionSupport: true,
127
+ transitionable: true,
128
+ valueTypeAllowed: "number",
129
+ },
130
+ "line-dasharray": {
131
+ dataExpressionSupport: false,
132
+ interpolateExpressionSupport: false,
133
+ transitionable: false,
134
+ valueTypeAllowed: "number",
135
+ arrayValue: true,
136
+ },
137
+ "line-cap": {
138
+ dataExpressionSupport: false,
139
+ interpolateExpressionSupport: false,
140
+ transitionable: false,
141
+ valueTypeAllowed: "string",
142
+ },
143
+ "line-join": {
144
+ dataExpressionSupport: true,
145
+ interpolateExpressionSupport: false,
146
+ transitionable: false,
147
+ valueTypeAllowed: "string",
148
+ },
149
+ "line-translate": {
150
+ dataExpressionSupport: false,
151
+ interpolateExpressionSupport: true,
152
+ transitionable: true,
153
+ valueTypeAllowed: "number",
154
+ arrayValue: true,
155
+ },
156
+ // icon
157
+ "icon-image": {
158
+ dataExpressionSupport: true,
159
+ interpolateExpressionSupport: false,
160
+ transitionable: false,
161
+ valueTypeAllowed: "string",
162
+ },
163
+ "icon-size": {
164
+ dataExpressionSupport: true,
165
+ interpolateExpressionSupport: true,
166
+ transitionable: false,
167
+ valueTypeAllowed: "number",
168
+ },
169
+ "icon-color": {
170
+ dataExpressionSupport: true,
171
+ interpolateExpressionSupport: true,
172
+ transitionable: true,
173
+ valueTypeAllowed: "string",
174
+ },
175
+ "icon-opacity": {
176
+ dataExpressionSupport: true,
177
+ interpolateExpressionSupport: true,
178
+ transitionable: true,
179
+ valueTypeAllowed: "number",
180
+ },
181
+ "icon-translate": {
182
+ dataExpressionSupport: false,
183
+ interpolateExpressionSupport: true,
184
+ transitionable: true,
185
+ valueTypeAllowed: "number",
186
+ arrayValue: true,
187
+ },
188
+ "icon-halo-color": {
189
+ dataExpressionSupport: true,
190
+ interpolateExpressionSupport: true,
191
+ transitionable: true,
192
+ valueTypeAllowed: "string",
193
+ },
194
+ "icon-halo-width": {
195
+ dataExpressionSupport: true,
196
+ interpolateExpressionSupport: true,
197
+ transitionable: true,
198
+ valueTypeAllowed: "number",
199
+ },
200
+ "icon-halo-blur": {
201
+ dataExpressionSupport: true,
202
+ interpolateExpressionSupport: true,
203
+ transitionable: true,
204
+ valueTypeAllowed: "number",
205
+ },
206
+ "icon-overlap": {
207
+ dataExpressionSupport: false,
208
+ interpolateExpressionSupport: false,
209
+ transitionable: false,
210
+ valueTypeAllowed: "string",
211
+ },
212
+ "icon-anchor": {
213
+ dataExpressionSupport: true,
214
+ interpolateExpressionSupport: false,
215
+ transitionable: false,
216
+ valueTypeAllowed: "string",
217
+ },
218
+ "icon-rotate": {
219
+ dataExpressionSupport: true,
220
+ interpolateExpressionSupport: true,
221
+ transitionable: false,
222
+ valueTypeAllowed: "number",
223
+ },
224
+ "icon-padding": {
225
+ dataExpressionSupport: false,
226
+ interpolateExpressionSupport: true,
227
+ transitionable: false,
228
+ valueTypeAllowed: "number",
229
+ arrayValue: true,
230
+ },
231
+ // text
232
+ "text-field": {
233
+ dataExpressionSupport: true,
234
+ interpolateExpressionSupport: false,
235
+ transitionable: false,
236
+ valueTypeAllowed: "string",
237
+ },
238
+ "text-color": {
239
+ dataExpressionSupport: true,
240
+ interpolateExpressionSupport: true,
241
+ transitionable: true,
242
+ valueTypeAllowed: "string",
243
+ },
244
+ "text-opacity": {
245
+ dataExpressionSupport: true,
246
+ interpolateExpressionSupport: true,
247
+ transitionable: true,
248
+ valueTypeAllowed: "number",
249
+ },
250
+ "text-font": {
251
+ dataExpressionSupport: true,
252
+ interpolateExpressionSupport: false,
253
+ transitionable: false,
254
+ valueTypeAllowed: "string",
255
+ arrayValue: true,
256
+ },
257
+ "text-size": {
258
+ dataExpressionSupport: true,
259
+ interpolateExpressionSupport: true,
260
+ transitionable: false,
261
+ valueTypeAllowed: "number",
262
+ },
263
+ "text-transform": {
264
+ dataExpressionSupport: true,
265
+ interpolateExpressionSupport: false,
266
+ transitionable: false,
267
+ valueTypeAllowed: "string",
268
+ },
269
+ "text-anchor": {
270
+ dataExpressionSupport: true,
271
+ interpolateExpressionSupport: false,
272
+ transitionable: false,
273
+ valueTypeAllowed: "string",
274
+ },
275
+ "text-justify": {
276
+ dataExpressionSupport: true,
277
+ interpolateExpressionSupport: false,
278
+ transitionable: false,
279
+ valueTypeAllowed: "string",
280
+ },
281
+ "text-translate": {
282
+ dataExpressionSupport: false,
283
+ interpolateExpressionSupport: true,
284
+ transitionable: true,
285
+ valueTypeAllowed: "number",
286
+ arrayValue: true,
287
+ },
288
+ "text-halo-color": {
289
+ dataExpressionSupport: true,
290
+ interpolateExpressionSupport: true,
291
+ transitionable: true,
292
+ valueTypeAllowed: "string",
293
+ },
294
+ "text-halo-width": {
295
+ dataExpressionSupport: true,
296
+ interpolateExpressionSupport: true,
297
+ transitionable: true,
298
+ valueTypeAllowed: "number",
299
+ },
300
+ "text-halo-blur": {
301
+ dataExpressionSupport: true,
302
+ interpolateExpressionSupport: true,
303
+ transitionable: true,
304
+ valueTypeAllowed: "number",
305
+ },
306
+ // symbol
307
+ "symbol-placement": {
308
+ dataExpressionSupport: false,
309
+ interpolateExpressionSupport: false,
310
+ transitionable: false,
311
+ valueTypeAllowed: "string",
312
+ },
313
+ "symbol-spacing": {
314
+ dataExpressionSupport: false,
315
+ interpolateExpressionSupport: true,
316
+ transitionable: false,
317
+ valueTypeAllowed: "number",
318
+ },
319
+ // heatmap
320
+ "heatmap-color": {
321
+ dataExpressionSupport: false,
322
+ interpolateExpressionSupport: true,
323
+ transitionable: false,
324
+ valueTypeAllowed: "string",
325
+ },
326
+ "heatmap-opacity": {
327
+ dataExpressionSupport: false,
328
+ interpolateExpressionSupport: true,
329
+ transitionable: true,
330
+ valueTypeAllowed: "number",
331
+ },
332
+ "heatmap-radius": {
333
+ dataExpressionSupport: true,
334
+ interpolateExpressionSupport: true,
335
+ transitionable: true,
336
+ valueTypeAllowed: "number",
337
+ },
338
+ "heatmap-intensity": {
339
+ dataExpressionSupport: false,
340
+ interpolateExpressionSupport: true,
341
+ transitionable: true,
342
+ valueTypeAllowed: "number",
343
+ },
344
+ "heatmap-weight": {
345
+ dataExpressionSupport: true,
346
+ interpolateExpressionSupport: true,
347
+ transitionable: false,
348
+ valueTypeAllowed: "number",
349
+ },
350
+ };
351
+
352
+ /* eslint-disable max-lines, no-console, class-methods-use-this, @typescript-eslint/no-magic-numbers */
353
+ class ClientStyleValidator {
354
+ options;
355
+ constructor(options) {
356
+ this.options = options || {};
357
+ }
358
+ validate(clientStyle) {
359
+ if (lodash.isNil(clientStyle) || lodash.isEmpty(clientStyle) || lodash.isNil(clientStyle?.items) || lodash.isEmpty(clientStyle?.items)) {
360
+ return true;
361
+ }
362
+ if (clientStyle.items.some(item => lodash.isNil(item.paint))) {
363
+ if (this.options.verbose) {
364
+ console.error("Validate client style:", "`paint` prop is mandatory", "\n");
365
+ }
366
+ return false;
367
+ }
368
+ return clientStyle.items.every(item => Object.entries({ ...item.layout, ...item.paint }).every(([key, value]) => this.validateSpecPropValue(key, value)));
369
+ }
370
+ getSpecPropValueOptions(key) {
371
+ return SPEC_PROP_VALUE_OPTIONS[key];
372
+ }
373
+ isHeatmapColorValid(value) {
374
+ return (mapboxGlStyleSpec.expression.isExpression(value) &&
375
+ lodash.isEqual(value[0], "interpolate") &&
376
+ lodash.isEqual(value[1], ["linear"]) &&
377
+ lodash.isEqual(value[2], ["heatmap-density"]) &&
378
+ value.length % 2 !== 0 &&
379
+ value.length > 3 &&
380
+ value
381
+ .slice(3)
382
+ .filter((_, i) => i % 2 === 0)
383
+ .every(e => typeof e === "number") &&
384
+ value
385
+ .slice(3)
386
+ .filter((_, i) => i % 2 !== 0)
387
+ .every(e => typeof e === "string"));
388
+ }
389
+ isZoomInterpolate(value) {
390
+ return Array.isArray(value) && value[0] === "interpolate" && Array.isArray(value[2]) && value[2][0] === "zoom";
391
+ }
392
+ validateSupportedConcatExpression(key, value) {
393
+ if (key !== "text-field") {
394
+ if (this.options.verbose) {
395
+ console.error("Validate supported concat expression:", "supported only for `text-field`", key, value, "\n");
396
+ }
397
+ return false;
398
+ }
399
+ if (!mapboxGlStyleSpec.expression.isExpression(value)) {
400
+ if (this.options.verbose) {
401
+ console.error("Validate supported concat expression:", "not an expression", key, value, "\n");
402
+ }
403
+ return false;
404
+ }
405
+ const result = value[0] === "concat" &&
406
+ value.length > 2 &&
407
+ value
408
+ .slice(1)
409
+ .every(i => typeof i === "string" || (Array.isArray(i) && i[0] === "get" && typeof i[1] === "string"));
410
+ if (!result) {
411
+ if (this.options.verbose) {
412
+ console.error("Validate supported concat expression:", "invalid expression", key, value, "\n");
413
+ }
414
+ }
415
+ return result;
416
+ }
417
+ validateSupportedMatchExpression(key, value) {
418
+ if (!this.getSpecPropValueOptions(key)?.dataExpressionSupport) {
419
+ if (this.options.verbose) {
420
+ console.error("Validate supported match expression:", "expression not supported", key, value, "\n");
421
+ }
422
+ return false;
423
+ }
424
+ if (!mapboxGlStyleSpec.expression.isExpression(value)) {
425
+ if (this.options.verbose) {
426
+ console.error("Validate supported match expression:", "not an expression", key, value, "\n");
427
+ }
428
+ return false;
429
+ }
430
+ const result = value[0] === "match" &&
431
+ Array.isArray(value[1]) &&
432
+ value[1].length === 2 &&
433
+ value[1][0] === "get" &&
434
+ typeof value[1][1] === "string" &&
435
+ value.length > 3 &&
436
+ value.length % 2 !== 0 &&
437
+ value
438
+ .slice(2)
439
+ .every(e => typeof e === "number" ||
440
+ typeof e === "string" ||
441
+ (key === "text-field" && this.validateSupportedConcatExpression(key, e)));
442
+ if (!result) {
443
+ if (this.options.verbose) {
444
+ console.error("Validate supported match expression:", "invalid expression", key, value, "\n");
445
+ }
446
+ }
447
+ return result;
448
+ }
449
+ validateSupportedCaseExpression(key, value) {
450
+ if (!this.getSpecPropValueOptions(key)?.dataExpressionSupport) {
451
+ if (this.options.verbose) {
452
+ console.error("Validate supported case expression:", "expression not supported", key, value, "\n");
453
+ }
454
+ return false;
455
+ }
456
+ if (!mapboxGlStyleSpec.expression.isExpression(value)) {
457
+ if (this.options.verbose) {
458
+ console.error("Validate supported case expression:", "not an expression", key, value, "\n");
459
+ }
460
+ return false;
461
+ }
462
+ const result = value[0] === "case" &&
463
+ value.length > 3 &&
464
+ value.length % 2 === 0 &&
465
+ value
466
+ .slice(1)
467
+ .filter((_, i) => i % 2 === 0 && i < value.slice(1).length - 1)
468
+ .every(e => Array.isArray(e) &&
469
+ e[0] === "all" &&
470
+ e.length > 1 &&
471
+ e
472
+ .slice(1)
473
+ .every(ce => Array.isArray(ce) &&
474
+ ce.length === 3 &&
475
+ [">=", ">", "<", "<="].includes(ce[0]) &&
476
+ ce[1][0] === "get" &&
477
+ typeof ce[1][1] === "string" &&
478
+ typeof ce[2] === "number")) &&
479
+ value
480
+ .slice(1)
481
+ .filter((_, i) => i % 2 !== 0)
482
+ .every(e => typeof e === "number" ||
483
+ typeof e === "string" ||
484
+ (key === "text-field" && this.validateSupportedConcatExpression(key, e))) &&
485
+ (typeof value[value.slice(1).length - 1] === "number" ||
486
+ typeof value[value.slice(1).length - 1] === "string" ||
487
+ (key === "text-field" && this.validateSupportedConcatExpression(key, value)));
488
+ if (!result) {
489
+ if (this.options.verbose) {
490
+ console.error("Validate supported case expression:", "invalid expression", key, value, "\n");
491
+ }
492
+ }
493
+ return result;
494
+ }
495
+ validateSupportedStepExpression(key, value) {
496
+ if (!this.getSpecPropValueOptions(key)?.dataExpressionSupport) {
497
+ if (this.options.verbose) {
498
+ console.error("Validate supported step expression:", "expression not supported", key, value, "\n");
499
+ }
500
+ return false;
501
+ }
502
+ if (!mapboxGlStyleSpec.expression.isExpression(value)) {
503
+ if (this.options.verbose) {
504
+ console.error("Validate supported step expression:", "not an expression", key, value, "\n");
505
+ }
506
+ return false;
507
+ }
508
+ const result = value[0] === "step" &&
509
+ Array.isArray(value[1]) &&
510
+ value[1].length === 2 &&
511
+ value[1][0] === "get" &&
512
+ typeof value[1][1] === "string" &&
513
+ value.length > 3 &&
514
+ value.length % 2 !== 0 &&
515
+ value
516
+ .slice(2)
517
+ .filter((_, i) => i % 2 === 0)
518
+ .every(e => typeof e === "number" ||
519
+ typeof e === "string" ||
520
+ (key === "text-field" && this.validateSupportedConcatExpression(key, e))) &&
521
+ value
522
+ .slice(2)
523
+ .filter((_, i) => i % 2 !== 0)
524
+ .every(e => typeof e === "number");
525
+ if (!result) {
526
+ if (this.options.verbose) {
527
+ console.error("Validate supported step expression:", "invalid expression", key, value, "\n");
528
+ }
529
+ }
530
+ return result;
531
+ }
532
+ validateLinearZoomInterpolate(key, value) {
533
+ return (this.getSpecPropValueOptions(key)?.interpolateExpressionSupport &&
534
+ lodash.isEqual(value[0], "interpolate") &&
535
+ lodash.isEqual(value[1], ["linear"]) &&
536
+ lodash.isEqual(value[2], ["zoom"]) &&
537
+ value.length % 2 !== 0 &&
538
+ value.length > 4 &&
539
+ value
540
+ .slice(3)
541
+ .filter((_, i) => i % 2 === 0)
542
+ .every(e => typeof e === "number") &&
543
+ value
544
+ .slice(3)
545
+ .filter((_, i) => i % 2 !== 0)
546
+ .every(e => {
547
+ return (typeof e === "number" ||
548
+ typeof e === "string" ||
549
+ this.validateSupportedExpression(key, e, true) ||
550
+ (key === "text-field" && this.validateSupportedConcatExpression(key, e)));
551
+ }));
552
+ }
553
+ validateExponentialZoomInterpolate(key, value) {
554
+ return (this.getSpecPropValueOptions(key)?.interpolateExpressionSupport &&
555
+ lodash.isEqual(value[0], "interpolate") &&
556
+ Array.isArray(value[1]) &&
557
+ value[1].length === 2 &&
558
+ value[1][0] === "exponential" &&
559
+ typeof value[1][1] === "number" &&
560
+ lodash.isEqual(value[2], ["zoom"]) &&
561
+ value.length % 2 !== 0 &&
562
+ value.length > 4 &&
563
+ value
564
+ .slice(3)
565
+ .filter((_, i) => i % 2 === 0)
566
+ .every(e => typeof e === "number") &&
567
+ value
568
+ .slice(3)
569
+ .filter((_, i) => i % 2 !== 0)
570
+ .every(e => {
571
+ return (typeof e === "number" ||
572
+ typeof e === "string" ||
573
+ this.validateSupportedExpression(key, e, true) ||
574
+ (key === "text-field" && this.validateSupportedConcatExpression(key, e)));
575
+ }));
576
+ }
577
+ validateCubicBezierZoomInterpolate(key, value) {
578
+ return (this.getSpecPropValueOptions(key)?.interpolateExpressionSupport &&
579
+ lodash.isEqual(value[0], "interpolate") &&
580
+ Array.isArray(value[1]) &&
581
+ value[1].length === 5 &&
582
+ value[1][0] === "cubic-bezier" &&
583
+ value[1].slice(1).every(e => typeof e === "number") &&
584
+ lodash.isEqual(value[2], ["zoom"]) &&
585
+ value.length % 2 !== 0 &&
586
+ value.length > 4 &&
587
+ value
588
+ .slice(3)
589
+ .filter((_, i) => i % 2 === 0)
590
+ .every(e => typeof e === "number") &&
591
+ value
592
+ .slice(3)
593
+ .filter((_, i) => i % 2 !== 0)
594
+ .every(e => {
595
+ return (typeof e === "number" ||
596
+ typeof e === "string" ||
597
+ this.validateSupportedExpression(key, e, true) ||
598
+ (key === "text-field" && this.validateSupportedConcatExpression(key, e)));
599
+ }));
600
+ }
601
+ validateLinearDataInterpolate(key, value) {
602
+ return (this.getSpecPropValueOptions(key)?.dataExpressionSupport &&
603
+ lodash.isEqual(value[0], "interpolate") &&
604
+ lodash.isEqual(value[1], ["linear"]) &&
605
+ Array.isArray(value[2]) &&
606
+ value[2].length === 2 &&
607
+ value[2][0] === "get" &&
608
+ typeof value[2][1] === "string" &&
609
+ value.length % 2 !== 0 &&
610
+ value.length > 4 &&
611
+ value
612
+ .slice(3)
613
+ .filter((_, i) => i % 2 === 0)
614
+ .every(e => typeof e === "number") &&
615
+ value
616
+ .slice(3)
617
+ .filter((_, i) => i % 2 !== 0)
618
+ .every(e => typeof e === "number" ||
619
+ typeof e === "string" ||
620
+ (key === "text-field" && this.validateSupportedConcatExpression(key, e))));
621
+ }
622
+ validateExponentialDataInterpolate(key, value) {
623
+ return (this.getSpecPropValueOptions(key)?.dataExpressionSupport &&
624
+ lodash.isEqual(value[0], "interpolate") &&
625
+ Array.isArray(value[1]) &&
626
+ value[1].length === 2 &&
627
+ value[1][0] === "exponential" &&
628
+ typeof value[1][1] === "number" &&
629
+ Array.isArray(value[2]) &&
630
+ value[2].length === 2 &&
631
+ value[2][0] === "get" &&
632
+ typeof value[2][1] === "string" &&
633
+ value.length % 2 !== 0 &&
634
+ value.length > 4 &&
635
+ value
636
+ .slice(3)
637
+ .filter((_, i) => i % 2 === 0)
638
+ .every(e => typeof e === "number") &&
639
+ value
640
+ .slice(3)
641
+ .filter((_, i) => i % 2 !== 0)
642
+ .every(e => typeof e === "number" ||
643
+ typeof e === "string" ||
644
+ (key === "text-field" && this.validateSupportedConcatExpression(key, e))));
645
+ }
646
+ validateCubicBezierDataInterpolate(key, value) {
647
+ return (this.getSpecPropValueOptions(key)?.dataExpressionSupport &&
648
+ lodash.isEqual(value[0], "interpolate") &&
649
+ Array.isArray(value[1]) &&
650
+ value[1].length === 5 &&
651
+ value[1][0] === "cubic-bezier" &&
652
+ value[1].slice(1).every(e => typeof e === "number") &&
653
+ Array.isArray(value[2]) &&
654
+ value[2].length === 2 &&
655
+ value[2][0] === "get" &&
656
+ typeof value[2][1] === "string" &&
657
+ value.length % 2 !== 0 &&
658
+ value.length > 4 &&
659
+ value
660
+ .slice(3)
661
+ .filter((_, i) => i % 2 === 0)
662
+ .every(e => typeof e === "number") &&
663
+ value
664
+ .slice(3)
665
+ .filter((_, i) => i % 2 !== 0)
666
+ .every(e => typeof e === "number" ||
667
+ typeof e === "string" ||
668
+ (key === "text-field" && this.validateSupportedConcatExpression(key, e))));
669
+ }
670
+ validateZoomInterpolate(key, value) {
671
+ return (this.validateLinearZoomInterpolate(key, value) ||
672
+ this.validateExponentialZoomInterpolate(key, value) ||
673
+ this.validateCubicBezierZoomInterpolate(key, value));
674
+ }
675
+ validateDataInterpolate(key, value) {
676
+ return (this.validateLinearDataInterpolate(key, value) ||
677
+ this.validateExponentialDataInterpolate(key, value) ||
678
+ this.validateCubicBezierDataInterpolate(key, value));
679
+ }
680
+ validateSupportedInterpolateExpression(key, value, excludeZoomInterpolate) {
681
+ if (!mapboxGlStyleSpec.expression.isExpression(value)) {
682
+ if (this.options.verbose) {
683
+ console.error("Validate supported interpolate expression:", "not an expression", key, value, "\n");
684
+ }
685
+ return false;
686
+ }
687
+ if (key === "heatmap-color") {
688
+ const isColorValid = this.isHeatmapColorValid(value);
689
+ if (!isColorValid) {
690
+ if (this.options.verbose) {
691
+ console.error("Validate supported interpolate expression:", "invalid color value", key, value, "\n");
692
+ }
693
+ }
694
+ return this.isHeatmapColorValid(value);
695
+ }
696
+ if (!this.getSpecPropValueOptions(key)?.interpolateExpressionSupport &&
697
+ !this.getSpecPropValueOptions(key)?.dataExpressionSupport) {
698
+ if (this.options.verbose) {
699
+ console.error("Validate supported interpolate expression:", "interpolate not supported", key, value, "\n");
700
+ }
701
+ }
702
+ const result = (!excludeZoomInterpolate && this.validateZoomInterpolate(key, value)) || this.validateDataInterpolate(key, value);
703
+ if (!result) {
704
+ if (this.options.verbose) {
705
+ console.error("Validate supported interpolate expression:", "invalid expression", key, value, "\n");
706
+ }
707
+ }
708
+ return result;
709
+ }
710
+ validateSupportedExpression(key, value, excludeZoomInterpolate) {
711
+ if (!mapboxGlStyleSpec.expression.isExpression(value)) {
712
+ if (this.options.verbose) {
713
+ console.error("Validate supported expression:", "not an expression", key, value, "\n");
714
+ }
715
+ return false;
716
+ }
717
+ const expressionType = value[0];
718
+ if (typeof expressionType !== "string" ||
719
+ !["match", "case", "step", "interpolate", "concat"].includes(expressionType)) {
720
+ if (this.options.verbose) {
721
+ console.error("Validate supported expression:", "expression type not supported", key, value, "\n");
722
+ }
723
+ return false;
724
+ }
725
+ switch (expressionType) {
726
+ case "match":
727
+ return this.validateSupportedMatchExpression(key, value);
728
+ case "case":
729
+ return this.validateSupportedCaseExpression(key, value);
730
+ case "step":
731
+ return this.validateSupportedStepExpression(key, value);
732
+ case "concat":
733
+ return this.validateSupportedConcatExpression(key, value);
734
+ case "interpolate":
735
+ return this.validateSupportedInterpolateExpression(key, value, excludeZoomInterpolate);
736
+ default:
737
+ return false;
738
+ }
739
+ }
740
+ validateTransitionValue(key, value) {
741
+ const propValueOptions = this.getSpecPropValueOptions(key.replace(/-transition$/, ""));
742
+ if (propValueOptions && propValueOptions.transitionable === false) {
743
+ if (this.options.verbose) {
744
+ console.error("Validate transition value:", "transition not supported", key, value, "\n");
745
+ }
746
+ return false;
747
+ }
748
+ const result = lodash.isObject(value) &&
749
+ (("delay" in value && typeof value.delay === "number") ||
750
+ ("duration" in value && typeof value.duration === "number"));
751
+ if (!result) {
752
+ if (this.options.verbose) {
753
+ console.error("Validate transition value:", "invalid transition value", key, value, "\n");
754
+ }
755
+ }
756
+ return result;
757
+ }
758
+ validateSpecPropValue(key, value) {
759
+ if (key.endsWith("-transition")) {
760
+ return this.validateTransitionValue(key, value);
761
+ }
762
+ const propValueOptions = this.getSpecPropValueOptions(key);
763
+ if (!propValueOptions) {
764
+ return (typeof value === "string" ||
765
+ typeof value === "number" ||
766
+ typeof value === "boolean" ||
767
+ (Array.isArray(value) && value.every(item => typeof item === "number")) ||
768
+ (Array.isArray(value) && value.every(item => typeof item === "string")) ||
769
+ mapboxGlStyleSpec.expression.isExpression(value));
770
+ }
771
+ if (propValueOptions.arrayValue) {
772
+ return (typeof value === propValueOptions.valueTypeAllowed ||
773
+ (Array.isArray(value) && value.every(item => typeof item === propValueOptions.valueTypeAllowed)) ||
774
+ this.validateSupportedExpression(key, value));
775
+ }
776
+ return typeof value === propValueOptions.valueTypeAllowed || this.validateSupportedExpression(key, value);
777
+ }
778
+ }
779
+
780
+ const enrichStyleItemsWithIds = (style) => {
781
+ return {
782
+ ...style,
783
+ items: style.items.map(item => {
784
+ return {
785
+ ...item,
786
+ id: item.id || uuid.v4(),
787
+ };
788
+ }),
789
+ };
790
+ };
791
+
792
+ /** Стабильный ID элемента стиля для MapLibre, в том числе когда `item.id` не задан. */
793
+ const getClientStyleItemId = (items, index) => {
794
+ const explicitId = items[index]?.id;
795
+ if (explicitId) {
796
+ return explicitId;
797
+ }
798
+ const explicitIds = new Set(items.map(item => item.id).filter(Boolean));
799
+ let generatedId = `__item_${index}`;
800
+ while (explicitIds.has(generatedId)) {
801
+ generatedId = `_${generatedId}`;
802
+ }
803
+ return generatedId;
804
+ };
805
+
806
+ const enrichStyleModelsWithIds = (style) => {
807
+ return {
808
+ ...style,
809
+ models: style.models.map(model => {
810
+ return {
811
+ ...model,
812
+ id: model.id || uuid.v4(),
813
+ };
814
+ }),
815
+ };
816
+ };
817
+
818
+ const findAttributeInExpression = (expression) => {
819
+ if (Array.isArray(expression) && expression.length === 2 && expression[0] === "get") {
820
+ return [expression[1]];
821
+ }
822
+ return expression.reduce((acc, curr) => {
823
+ if (!Array.isArray(curr)) {
824
+ return acc;
825
+ }
826
+ if (curr[0] === "get") {
827
+ return [...new Set([...acc, curr[1]])];
828
+ }
829
+ return [...new Set([...acc, ...findAttributeInExpression(curr)])];
830
+ }, []);
831
+ };
832
+
833
+ const getActualExtrusionHeight = (paint) => {
834
+ return Array.isArray(paint?.["fill-extrusion-height"]) && paint?.["fill-extrusion-height"][0] === "+"
835
+ ? paint?.["fill-extrusion-height"][1]
836
+ : paint?.["fill-extrusion-height"];
837
+ };
838
+
839
+ const getLayerClientStyle = (layer) => {
840
+ const clientStyle = layer?.configuration?.clientStyle;
841
+ return {
842
+ ...clientStyle,
843
+ items: clientStyle?.items ?? [],
844
+ };
845
+ };
846
+
847
+ const extractAttributesFromObject = (obj) => {
848
+ if (!obj || lodash.isEmpty(obj)) {
849
+ return [];
850
+ }
851
+ return Object.entries(obj).reduce((acc, [, value]) => {
852
+ if (!Array.isArray(value)) {
853
+ return acc;
854
+ }
855
+ return [...new Set([...acc, ...findAttributeInExpression(value)])];
856
+ }, []);
857
+ };
858
+ const getStyleAttributes = (style) => {
859
+ if (!style) {
860
+ return [];
861
+ }
862
+ return style?.items?.reduce((acc, curr) => {
863
+ const paintAttributes = extractAttributesFromObject(curr.paint);
864
+ const layoutAttributes = extractAttributesFromObject(curr.layout);
865
+ const filterAttributes = curr.filter
866
+ ? findAttributeInExpression(curr.filter)
867
+ : [];
868
+ return [...new Set([...acc, ...paintAttributes, ...layoutAttributes, ...filterAttributes])];
869
+ }, []);
870
+ };
871
+
872
+ const DEFAULT_COLOR = "#00ffff";
873
+ const DEFAULT_BLUR = 0;
874
+ const DEFAULT_OPACITY = 0.5;
875
+ const DEFAULT_TRANSLATE = [0, 0];
876
+ const DEFAULT_FILL_EXTRUSION_BASE = 0;
877
+ const DEFAULT_FILL_EXTRUSION_VERTICAL_GRADIENT = true;
878
+ const DEFAULT_FILL_EXTRUSION_HEIGHT = 0;
879
+ const DEFAULT_CIRCLE_RADIUS = 4;
880
+ const DEFAULT_CIRCLE_STROKE_WIDTH = 0;
881
+ const DEFAULT_LINE_WIDTH = 1;
882
+ const DEFAULT_LINE_CAP = "butt";
883
+ const DEFAULT_LINE_JOIN = "miter";
884
+ const DEFAULT_SYMBOL_COLOR = "#000000";
885
+ const DEFAULT_SYMBOL_HALO_COLOR = "#ffffff";
886
+ const DEFAULT_SYMBOL_PLACEMENT = "point";
887
+ const DEFAULT_SYMBOL_SPACING = 250;
888
+ const DEFAULT_ICON_OVERLAP = "never";
889
+ const DEFAULT_ICON_SIZE = 0.5;
890
+ const DEFAULT_ICON_ANCHOR = "center";
891
+ const DEFAULT_ICON_PADDING = [2];
892
+ const DEFAULT_ICON_ROTATE = 0;
893
+ const DEFAULT_TEXT_SIZE = 16;
894
+ const DEFAULT_TEXT_ANCHOR = "center";
895
+ const DEFAULT_TEXT_JUSTIFY = "center";
896
+ const DEFAULT_TEXT_TRANSFORM = "none";
897
+ const DEFAULT_HEATMAP_RADIUS = 30;
898
+ const DEFAULT_HEATMAP_WEIGHT = 1;
899
+ const DEFAULT_HEATMAP_INTENSITY = 1;
900
+ const DEFAULT_HEATMAP_COLOR = [
901
+ "interpolate",
902
+ ["linear"],
903
+ ["heatmap-density"],
904
+ 0, "rgba(0, 0, 255, 0)",
905
+ 0.1, "royalblue",
906
+ 0.3, "cyan",
907
+ 0.5, "lime",
908
+ 0.7, "yellow",
909
+ 1, "red",
910
+ ];
911
+ const DEFAULT_FILL_STYLE = {
912
+ items: [
913
+ {
914
+ type: "fill",
915
+ layout: {},
916
+ paint: {
917
+ "fill-color": DEFAULT_COLOR,
918
+ "fill-opacity": DEFAULT_OPACITY,
919
+ },
920
+ },
921
+ ],
922
+ };
923
+ const DEFAULT_FILL_EXTRUSION_STYLE = {
924
+ items: [
925
+ {
926
+ type: "fill-extrusion",
927
+ layout: {},
928
+ paint: {
929
+ "fill-extrusion-base": DEFAULT_FILL_EXTRUSION_BASE,
930
+ "fill-extrusion-vertical-gradient": DEFAULT_FILL_EXTRUSION_VERTICAL_GRADIENT,
931
+ "fill-extrusion-color": DEFAULT_COLOR,
932
+ "fill-extrusion-opacity": DEFAULT_OPACITY,
933
+ "fill-extrusion-height": DEFAULT_FILL_EXTRUSION_HEIGHT,
934
+ },
935
+ },
936
+ ],
937
+ };
938
+ const DEFAULT_LINE_STYLE = {
939
+ items: [
940
+ {
941
+ type: "line",
942
+ layout: {
943
+ "line-cap": DEFAULT_LINE_CAP,
944
+ "line-join": DEFAULT_LINE_JOIN,
945
+ },
946
+ paint: {
947
+ "line-color": DEFAULT_COLOR,
948
+ "line-width": DEFAULT_LINE_WIDTH,
949
+ "line-blur": DEFAULT_BLUR,
950
+ "line-opacity": DEFAULT_OPACITY,
951
+ "line-translate": DEFAULT_TRANSLATE,
952
+ },
953
+ },
954
+ ],
955
+ };
956
+ const DEFAULT_CIRCLE_STYLE = {
957
+ items: [
958
+ {
959
+ type: "circle",
960
+ layout: {},
961
+ paint: {
962
+ "circle-radius": DEFAULT_CIRCLE_RADIUS,
963
+ "circle-color": DEFAULT_COLOR,
964
+ "circle-blur": DEFAULT_BLUR,
965
+ "circle-opacity": DEFAULT_OPACITY,
966
+ "circle-translate": DEFAULT_TRANSLATE,
967
+ "circle-stroke-width": DEFAULT_CIRCLE_STROKE_WIDTH,
968
+ "circle-stroke-color": DEFAULT_COLOR,
969
+ "circle-stroke-opacity": DEFAULT_OPACITY,
970
+ },
971
+ },
972
+ ],
973
+ };
974
+ const DEFAULT_SYMBOL_STYLE = {
975
+ items: [
976
+ {
977
+ type: "symbol",
978
+ layout: {
979
+ "symbol-placement": DEFAULT_SYMBOL_PLACEMENT,
980
+ "symbol-spacing": DEFAULT_SYMBOL_SPACING,
981
+ "icon-overlap": DEFAULT_ICON_OVERLAP,
982
+ "icon-size": DEFAULT_ICON_SIZE,
983
+ "icon-anchor": DEFAULT_ICON_ANCHOR,
984
+ "icon-padding": DEFAULT_ICON_PADDING,
985
+ "icon-rotate": DEFAULT_ICON_ROTATE,
986
+ "text-size": DEFAULT_TEXT_SIZE,
987
+ "text-anchor": DEFAULT_TEXT_ANCHOR,
988
+ "text-justify": DEFAULT_TEXT_JUSTIFY,
989
+ "text-transform": DEFAULT_TEXT_TRANSFORM,
990
+ },
991
+ paint: {
992
+ "icon-color": DEFAULT_SYMBOL_COLOR,
993
+ "icon-halo-color": DEFAULT_SYMBOL_HALO_COLOR,
994
+ "icon-opacity": DEFAULT_OPACITY,
995
+ "text-color": DEFAULT_SYMBOL_COLOR,
996
+ "text-halo-color": DEFAULT_SYMBOL_HALO_COLOR,
997
+ "text-opacity": DEFAULT_OPACITY,
998
+ },
999
+ },
1000
+ ],
1001
+ };
1002
+ const DEFAULT_HEATMAP_STYLE = {
1003
+ items: [
1004
+ {
1005
+ type: "heatmap",
1006
+ layout: {},
1007
+ paint: {
1008
+ "heatmap-radius": DEFAULT_HEATMAP_RADIUS,
1009
+ "heatmap-weight": DEFAULT_HEATMAP_WEIGHT,
1010
+ "heatmap-intensity": DEFAULT_HEATMAP_INTENSITY,
1011
+ "heatmap-color": DEFAULT_HEATMAP_COLOR,
1012
+ "heatmap-opacity": DEFAULT_OPACITY,
1013
+ },
1014
+ },
1015
+ ],
1016
+ };
1017
+
1018
+ /**
1019
+ * Извлекает имена иконок из выражения icon-image.
1020
+ *
1021
+ * Поддерживает:
1022
+ * - Строки: "parking" → ["parking"]
1023
+ * - match: ["match", ["get", "type"], "a", "icon-a", "b", "icon-b", "default"] → ["icon-a", "icon-b", "default"]
1024
+ * - case: ["case", [...], "icon-a", "icon-b"] → ["icon-a", "icon-b"]
1025
+ * - coalesce: ["coalesce", ["image", "icon-a"], ["image", "icon-b"]] → ["icon-a", "icon-b"]
1026
+ * - image: ["image", "icon-a"] → ["icon-a"]
1027
+ *
1028
+ * @param iconImage - значение icon-image из layout
1029
+ * @returns массив имён иконок
1030
+ */
1031
+ const parseIconNames = (iconImage) => {
1032
+ if (!iconImage) {
1033
+ return [];
1034
+ }
1035
+ // Простая строка: "parking"
1036
+ if (typeof iconImage === "string") {
1037
+ return [iconImage];
1038
+ }
1039
+ // Выражение Mapbox
1040
+ if (Array.isArray(iconImage) && iconImage.length > 0) {
1041
+ const [operator, ...args] = iconImage;
1042
+ switch (operator) {
1043
+ // ["match", input, label1, output1, label2, output2, ..., fallback]
1044
+ case "match": {
1045
+ const results = [];
1046
+ // Пропускаем первый аргумент (input), берём каждый второй начиная с индекса 2
1047
+ for (let i = 2; i < args.length; i += 2) {
1048
+ if (typeof args[i] === "string") {
1049
+ results.push(args[i]);
1050
+ }
1051
+ else if (Array.isArray(args[i])) {
1052
+ results.push(...parseIconNames(args[i]));
1053
+ }
1054
+ }
1055
+ // Последний аргумент - fallback (если нечётное количество после input)
1056
+ const lastArg = args[args.length - 1];
1057
+ if (typeof lastArg === "string") {
1058
+ results.push(lastArg);
1059
+ }
1060
+ else if (Array.isArray(lastArg)) {
1061
+ results.push(...parseIconNames(lastArg));
1062
+ }
1063
+ return [...new Set(results)];
1064
+ }
1065
+ // ["case", condition1, output1, condition2, output2, ..., fallback]
1066
+ case "case": {
1067
+ const results = [];
1068
+ for (let i = 1; i < args.length; i += 2) {
1069
+ if (typeof args[i] === "string") {
1070
+ results.push(args[i]);
1071
+ }
1072
+ else if (Array.isArray(args[i])) {
1073
+ results.push(...parseIconNames(args[i]));
1074
+ }
1075
+ }
1076
+ // Fallback
1077
+ if (args.length % 2 === 0) {
1078
+ const lastArg = args[args.length - 1];
1079
+ if (typeof lastArg === "string") {
1080
+ results.push(lastArg);
1081
+ }
1082
+ else if (Array.isArray(lastArg)) {
1083
+ results.push(...parseIconNames(lastArg));
1084
+ }
1085
+ }
1086
+ return [...new Set(results)];
1087
+ }
1088
+ // ["coalesce", expr1, expr2, ...]
1089
+ case "coalesce": {
1090
+ const results = [];
1091
+ args.forEach(arg => {
1092
+ if (typeof arg === "string") {
1093
+ results.push(arg);
1094
+ }
1095
+ else if (Array.isArray(arg)) {
1096
+ results.push(...parseIconNames(arg));
1097
+ }
1098
+ });
1099
+ return [...new Set(results)];
1100
+ }
1101
+ // ["image", name] или ["image", name1, name2, ...]
1102
+ case "image": {
1103
+ return args.filter((arg) => typeof arg === "string");
1104
+ }
1105
+ // ["concat", ...] или другие - рекурсивно ищем строки
1106
+ default: {
1107
+ const results = [];
1108
+ args.forEach(arg => {
1109
+ if (Array.isArray(arg)) {
1110
+ results.push(...parseIconNames(arg));
1111
+ }
1112
+ });
1113
+ return [...new Set(results)];
1114
+ }
1115
+ }
1116
+ }
1117
+ return [];
1118
+ };
1119
+ /**
1120
+ * Свойства, содержащие имена изображений (иконки и паттерны).
1121
+ */
1122
+ const IMAGE_PROPERTIES = {
1123
+ layout: ["icon-image"],
1124
+ paint: ["fill-pattern", "line-pattern", "fill-extrusion-pattern"],
1125
+ };
1126
+ /**
1127
+ * Извлекает все имена изображений из clientStyle.
1128
+ * Включает иконки (icon-image) и паттерны (fill-pattern, line-pattern, fill-extrusion-pattern).
1129
+ *
1130
+ * @param clientStyle - конфигурация стиля слоя
1131
+ * @returns массив уникальных имён изображений
1132
+ */
1133
+ const parseIconNamesFromClientStyle = (clientStyle) => {
1134
+ if (!clientStyle?.items) {
1135
+ return [];
1136
+ }
1137
+ const imageNames = new Set();
1138
+ clientStyle.items.forEach(item => {
1139
+ // Парсим icon-image из layout
1140
+ IMAGE_PROPERTIES.layout.forEach(prop => {
1141
+ const value = item.layout?.[prop];
1142
+ if (value) {
1143
+ parseIconNames(value).forEach(name => imageNames.add(name));
1144
+ }
1145
+ });
1146
+ // Парсим fill-pattern, line-pattern, fill-extrusion-pattern из paint
1147
+ IMAGE_PROPERTIES.paint.forEach(prop => {
1148
+ const value = item.paint?.[prop];
1149
+ if (value) {
1150
+ parseIconNames(value).forEach(name => imageNames.add(name));
1151
+ }
1152
+ });
1153
+ });
1154
+ return [...imageNames];
1155
+ };
1156
+
1157
+ /** Предел широты сферического меркатора (EPSG:3857): дальше проекция уходит в бесконечность. */
1158
+ const MERCATOR_MAX_LATITUDE = 85.05112878;
1159
+ /** Предел долготы: карта рендерит копии мира, но экстент за пределами ±180° бэкенду не нужен. */
1160
+ const MERCATOR_MAX_LONGITUDE = 180;
1161
+
1162
+ /**
1163
+ * Returns true if n is a finite number, otherwise false
1164
+ * @param n
1165
+ */
1166
+ const isNumber = function (n) {
1167
+ return typeof n === 'number' && isFinite(n);
1168
+ };
1169
+ /**
1170
+ * Returns true if s is a string, otherwise false
1171
+ * @param s
1172
+ */
1173
+ const isString = function (s) {
1174
+ return typeof s === 'string';
1175
+ };
1176
+
1177
+ /**
1178
+ * Utility class for working with different representations of colors in browsers
1179
+ * @alias sGis.utils.Color
1180
+ */
1181
+ class Color {
1182
+ /**
1183
+ * @param string - any valid css color string
1184
+ */
1185
+ constructor(string) {
1186
+ this._original = string;
1187
+ if (!isString(string))
1188
+ string = string.toString();
1189
+ this._color = string && string.trim() || 'transparent';
1190
+ this._setChannels();
1191
+ }
1192
+ _setChannels() {
1193
+ let format = this.format;
1194
+ if (format && formats[format]) {
1195
+ this._channels = formats[format](this._color);
1196
+ }
1197
+ else {
1198
+ this._channels = { r: NaN, g: NaN, b: NaN, a: NaN };
1199
+ }
1200
+ }
1201
+ get _min() { return Math.min(this._channels.r, this._channels.g, this._channels.b); }
1202
+ get _max() { return Math.max(this._channels.r, this._channels.g, this._channels.b); }
1203
+ get _delta() { return this._max - this._min; }
1204
+ /**
1205
+ * Returns the color as a string in the requested format
1206
+ * @param format - target format. Available values: "hex" - #AARRGGBB, "rgb" - "rgb(r, g, b)", "rgba" - "rgba(r, g, b, a)"
1207
+ */
1208
+ toString(format) {
1209
+ if (format === 'hex') {
1210
+ return '#' + decToHex(this.r) + decToHex(this.g) + decToHex(this.b) + decToHex(this.a);
1211
+ }
1212
+ else if (format === 'rgb') {
1213
+ return 'rgb(' + this.r + ',' + this.g + ',' + this.b + ')';
1214
+ }
1215
+ else {
1216
+ return 'rgba(' + this.r + ',' + this.g + ',' + this.b + ',' + (this.a / 255).toFixed(2).replace(/\.*0+$/, '') + ')';
1217
+ }
1218
+ }
1219
+ /**
1220
+ * Returns the string given to the constructor of the instance
1221
+ * @type {String}
1222
+ */
1223
+ get original() { return this._original; }
1224
+ /**
1225
+ * Returns true if the instance represents a valid color, i.e. that after parsing of the string given to the constructor,
1226
+ * the format is recognized and values of all channels are resolved to valid numbers.
1227
+ * @returns {Boolean}
1228
+ */
1229
+ get isValid() { return isNumber(this._channels.a) && isNumber(this._channels.r) && isNumber(this._channels.g) && isNumber(this._channels.b); }
1230
+ /**
1231
+ * Converts HSV color value into RGB
1232
+ * @param h - hue value
1233
+ * @param s - saturation value
1234
+ * @param v - 'value' value
1235
+ */
1236
+ setHsv(h, s, v) {
1237
+ let rgbColors = [];
1238
+ h /= 60;
1239
+ s /= 100;
1240
+ v /= 100;
1241
+ let floor = Math.floor(h);
1242
+ let mod = floor % 6;
1243
+ let f = h - floor;
1244
+ let p = Math.round(255 * v * (1 - s));
1245
+ let q = Math.round(255 * v * (1 - s * f));
1246
+ let t = Math.round(255 * v * (1 - s * (1 - f)));
1247
+ v = Math.round(255 * v);
1248
+ switch (mod) {
1249
+ case 0:
1250
+ rgbColors = [v, t, p];
1251
+ break;
1252
+ case 1:
1253
+ rgbColors = [q, v, p];
1254
+ break;
1255
+ case 2:
1256
+ rgbColors = [p, v, t];
1257
+ break;
1258
+ case 3:
1259
+ rgbColors = [p, q, v];
1260
+ break;
1261
+ case 4:
1262
+ rgbColors = [t, p, v];
1263
+ break;
1264
+ case 5:
1265
+ rgbColors = [v, p, q];
1266
+ break;
1267
+ }
1268
+ this._channels.r = rgbColors[0];
1269
+ this._channels.g = rgbColors[1];
1270
+ this._channels.b = rgbColors[2];
1271
+ return this;
1272
+ }
1273
+ /**
1274
+ * Returns the format of the input color sting. Possible values: hex3, hex6, hex4, hex8, rgb, rgba, name.
1275
+ * (name is the named css color values like "white")
1276
+ */
1277
+ get format() {
1278
+ if (this._color.substr(0, 1) === '#' && this._color.search(/[^#0-9a-fA-F]/) === -1) {
1279
+ if (this._color.length === 4) {
1280
+ return 'hex3';
1281
+ }
1282
+ else if (this._color.length === 7) {
1283
+ return 'hex6';
1284
+ }
1285
+ else if (this._color.length === 5) {
1286
+ return 'hex4';
1287
+ }
1288
+ else if (this._color.length === 9) {
1289
+ return 'hex8';
1290
+ }
1291
+ }
1292
+ else if (this._color.substr(0, 4) === 'rgb(') {
1293
+ return 'rgb';
1294
+ }
1295
+ else if (this._color.substr(0, 5) === 'rgba(') {
1296
+ return 'rgba';
1297
+ }
1298
+ else if (this._color.substr(0, 4) === 'hsv(') {
1299
+ return 'hsv';
1300
+ }
1301
+ else if (this._color in Color.names) {
1302
+ return 'name';
1303
+ }
1304
+ }
1305
+ /**
1306
+ * Returns red channel value as integer from 0 to 255.
1307
+ */
1308
+ get r() { return this._channels.r; }
1309
+ set r(v) { this._channels.r = v; }
1310
+ /**
1311
+ * Returns green channel value as integer from 0 to 255.
1312
+ */
1313
+ get g() { return this._channels.g; }
1314
+ set g(v) { this._channels.g = v; }
1315
+ /**
1316
+ * Returns blue channel value as integer from 0 to 255.
1317
+ */
1318
+ get b() { return this._channels.b; }
1319
+ set b(v) { this._channels.b = v; }
1320
+ /**
1321
+ * Returns opacity channel value as integer from 0 to 255.
1322
+ */
1323
+ get a() { return this._channels.a; }
1324
+ set a(v) { this._channels.a = v; }
1325
+ /**
1326
+ * Returns hue channel value as integer from 0 to 360.
1327
+ */
1328
+ get h() {
1329
+ let max = this._max;
1330
+ let min = this._min;
1331
+ let delta = this._delta;
1332
+ let h;
1333
+ let { r, g, b } = this._channels;
1334
+ if (max === min)
1335
+ h = 0;
1336
+ else if (r === max)
1337
+ h = (g - b) / delta;
1338
+ else if (g === max)
1339
+ h = 2 + (b - r) / delta;
1340
+ else if (b === max)
1341
+ h = 4 + (r - g) / delta;
1342
+ h = Math.min(h * 60, 360);
1343
+ if (h < 0)
1344
+ h += 360;
1345
+ h = Math.round(h);
1346
+ return h;
1347
+ }
1348
+ /**
1349
+ * Returns saturation channel value as integer from 0 to 100.
1350
+ */
1351
+ get s() {
1352
+ let s;
1353
+ let max = this._max;
1354
+ if (max === 0)
1355
+ s = 0;
1356
+ else
1357
+ s = this._delta / max * 1000 / 10;
1358
+ s = Math.round(s);
1359
+ return s;
1360
+ }
1361
+ /**
1362
+ * Returns 'value' channel of hsv space as integer from 0 to 100.
1363
+ */
1364
+ get v() { return Math.round(this._max / 255 * 1000 / 10); }
1365
+ /**
1366
+ * Returns values of the channels as integers from 0 to 255. Format is { r: r, g: g, b: b, a: a }.
1367
+ */
1368
+ get channels() { return Object.assign({}, this._channels); }
1369
+ }
1370
+ // Big List of Colors
1371
+ // ------------------
1372
+ // <http://www.w3.org/TR/css3-color/#svg-color>
1373
+ //noinspection SpellCheckingInspection
1374
+ Color.names = {
1375
+ aliceblue: "f0f8ff",
1376
+ antiquewhite: "faebd7",
1377
+ aqua: "0ff",
1378
+ aquamarine: "7fffd4",
1379
+ azure: "f0ffff",
1380
+ beige: "f5f5dc",
1381
+ bisque: "ffe4c4",
1382
+ black: "000",
1383
+ blanchedalmond: "ffebcd",
1384
+ blue: "00f",
1385
+ blueviolet: "8a2be2",
1386
+ brown: "a52a2a",
1387
+ burlywood: "deb887",
1388
+ burntsienna: "ea7e5d",
1389
+ cadetblue: "5f9ea0",
1390
+ chartreuse: "7fff00",
1391
+ chocolate: "d2691e",
1392
+ coral: "ff7f50",
1393
+ cornflowerblue: "6495ed",
1394
+ cornsilk: "fff8dc",
1395
+ crimson: "dc143c",
1396
+ cyan: "0ff",
1397
+ darkblue: "00008b",
1398
+ darkcyan: "008b8b",
1399
+ darkgoldenrod: "b8860b",
1400
+ darkgray: "a9a9a9",
1401
+ darkgreen: "006400",
1402
+ darkgrey: "a9a9a9",
1403
+ darkkhaki: "bdb76b",
1404
+ darkmagenta: "8b008b",
1405
+ darkolivegreen: "556b2f",
1406
+ darkorange: "ff8c00",
1407
+ darkorchid: "9932cc",
1408
+ darkred: "8b0000",
1409
+ darksalmon: "e9967a",
1410
+ darkseagreen: "8fbc8f",
1411
+ darkslateblue: "483d8b",
1412
+ darkslategray: "2f4f4f",
1413
+ darkslategrey: "2f4f4f",
1414
+ darkturquoise: "00ced1",
1415
+ darkviolet: "9400d3",
1416
+ deeppink: "ff1493",
1417
+ deepskyblue: "00bfff",
1418
+ dimgray: "696969",
1419
+ dimgrey: "696969",
1420
+ dodgerblue: "1e90ff",
1421
+ firebrick: "b22222",
1422
+ floralwhite: "fffaf0",
1423
+ forestgreen: "228b22",
1424
+ fuchsia: "f0f",
1425
+ gainsboro: "dcdcdc",
1426
+ ghostwhite: "f8f8ff",
1427
+ gold: "ffd700",
1428
+ goldenrod: "daa520",
1429
+ gray: "808080",
1430
+ green: "008000",
1431
+ greenyellow: "adff2f",
1432
+ grey: "808080",
1433
+ honeydew: "f0fff0",
1434
+ hotpink: "ff69b4",
1435
+ indianred: "cd5c5c",
1436
+ indigo: "4b0082",
1437
+ ivory: "fffff0",
1438
+ khaki: "f0e68c",
1439
+ lavender: "e6e6fa",
1440
+ lavenderblush: "fff0f5",
1441
+ lawngreen: "7cfc00",
1442
+ lemonchiffon: "fffacd",
1443
+ lightblue: "add8e6",
1444
+ lightcoral: "f08080",
1445
+ lightcyan: "e0ffff",
1446
+ lightgoldenrodyellow: "fafad2",
1447
+ lightgray: "d3d3d3",
1448
+ lightgreen: "90ee90",
1449
+ lightgrey: "d3d3d3",
1450
+ lightpink: "ffb6c1",
1451
+ lightsalmon: "ffa07a",
1452
+ lightseagreen: "20b2aa",
1453
+ lightskyblue: "87cefa",
1454
+ lightslategray: "789",
1455
+ lightslategrey: "789",
1456
+ lightsteelblue: "b0c4de",
1457
+ lightyellow: "ffffe0",
1458
+ lime: "0f0",
1459
+ limegreen: "32cd32",
1460
+ linen: "faf0e6",
1461
+ magenta: "f0f",
1462
+ maroon: "800000",
1463
+ mediumaquamarine: "66cdaa",
1464
+ mediumblue: "0000cd",
1465
+ mediumorchid: "ba55d3",
1466
+ mediumpurple: "9370db",
1467
+ mediumseagreen: "3cb371",
1468
+ mediumslateblue: "7b68ee",
1469
+ mediumspringgreen: "00fa9a",
1470
+ mediumturquoise: "48d1cc",
1471
+ mediumvioletred: "c71585",
1472
+ midnightblue: "191970",
1473
+ mintcream: "f5fffa",
1474
+ mistyrose: "ffe4e1",
1475
+ moccasin: "ffe4b5",
1476
+ navajowhite: "ffdead",
1477
+ navy: "000080",
1478
+ oldlace: "fdf5e6",
1479
+ olive: "808000",
1480
+ olivedrab: "6b8e23",
1481
+ orange: "ffa500",
1482
+ orangered: "ff4500",
1483
+ orchid: "da70d6",
1484
+ palegoldenrod: "eee8aa",
1485
+ palegreen: "98fb98",
1486
+ paleturquoise: "afeeee",
1487
+ palevioletred: "db7093",
1488
+ papayawhip: "ffefd5",
1489
+ peachpuff: "ffdab9",
1490
+ peru: "cd853f",
1491
+ pink: "ffc0cb",
1492
+ plum: "dda0dd",
1493
+ powderblue: "b0e0e6",
1494
+ purple: "800080",
1495
+ rebeccapurple: "663399",
1496
+ red: "f00",
1497
+ rosybrown: "bc8f8f",
1498
+ royalblue: "4169e1",
1499
+ saddlebrown: "8b4513",
1500
+ salmon: "fa8072",
1501
+ sandybrown: "f4a460",
1502
+ seagreen: "2e8b57",
1503
+ seashell: "fff5ee",
1504
+ sienna: "a0522d",
1505
+ silver: "c0c0c0",
1506
+ skyblue: "87ceeb",
1507
+ slateblue: "6a5acd",
1508
+ slategray: "708090",
1509
+ slategrey: "708090",
1510
+ snow: "fffafa",
1511
+ springgreen: "00ff7f",
1512
+ steelblue: "4682b4",
1513
+ tan: "d2b48c",
1514
+ teal: "008080",
1515
+ thistle: "d8bfd8",
1516
+ tomato: "ff6347",
1517
+ turquoise: "40e0d0",
1518
+ violet: "ee82ee",
1519
+ wheat: "f5deb3",
1520
+ white: "fff",
1521
+ whitesmoke: "f5f5f5",
1522
+ yellow: "ff0",
1523
+ yellowgreen: "9acd32",
1524
+ transparent: '0000'
1525
+ };
1526
+ function decToHex(dec) {
1527
+ let hex = Math.floor(dec).toString(16);
1528
+ return hex.length === 1 ? '0' + hex : hex;
8
1529
  }
1530
+ let formats = {
1531
+ hex3: function (string) {
1532
+ return {
1533
+ r: parseInt(string.substr(1, 1) + string.substr(1, 1), 16),
1534
+ g: parseInt(string.substr(2, 1) + string.substr(2, 1), 16),
1535
+ b: parseInt(string.substr(3, 1) + string.substr(3, 1), 16),
1536
+ a: 255
1537
+ };
1538
+ },
1539
+ hex6: function (string) {
1540
+ return {
1541
+ r: parseInt(string.substr(1, 2), 16),
1542
+ g: parseInt(string.substr(3, 2), 16),
1543
+ b: parseInt(string.substr(5, 2), 16),
1544
+ a: 255
1545
+ };
1546
+ },
1547
+ hex4: function (string) {
1548
+ return {
1549
+ r: parseInt(string.substr(1, 1) + string.substr(1, 1), 16),
1550
+ g: parseInt(string.substr(2, 1) + string.substr(2, 1), 16),
1551
+ b: parseInt(string.substr(3, 1) + string.substr(3, 1), 16),
1552
+ a: parseInt(string.substr(4, 1) + string.substr(4, 1), 16)
1553
+ };
1554
+ },
1555
+ hex8: function (string) {
1556
+ return {
1557
+ r: parseInt(string.substr(1, 2), 16),
1558
+ g: parseInt(string.substr(3, 2), 16),
1559
+ b: parseInt(string.substr(5, 2), 16),
1560
+ a: parseInt(string.substr(7, 2), 16)
1561
+ };
1562
+ },
1563
+ rgb: function (string) {
1564
+ let percents = string.match(/%/g);
1565
+ if (!percents || percents.length === 3) {
1566
+ var channels = string.substring(string.search(/\(/) + 1, string.length - 1).split(',');
1567
+ for (var i = 0; i < 3; i++) {
1568
+ if (channels[i]) {
1569
+ channels[i] = channels[i].trim();
1570
+ var percent = channels[i].match(/[.\d\-]+%/);
1571
+ if (percent) {
1572
+ var points = channels[i].match(/\./g);
1573
+ channels[i] = channels[i].search(/[^\d.\-%]/) === -1 && (!points || points.length < 2) ? parseFloat(percent[0]) : NaN;
1574
+ if (channels[i] < 0) {
1575
+ channels[i] = 0;
1576
+ }
1577
+ else if (channels[i] > 100) {
1578
+ channels[i] = 100;
1579
+ }
1580
+ channels[i] = Math.floor(channels[i] * 255 / 100);
1581
+ }
1582
+ else {
1583
+ channels[i] = channels[i] && (channels[i].match(/[^ \-0-9]/) === null) && channels[i].match(/[0-9]+/g).length === 1 ? parseInt(channels[i]) : NaN;
1584
+ if (channels[i] < 0) {
1585
+ channels[i] = 0;
1586
+ }
1587
+ else if (channels[i] > 255) {
1588
+ channels[i] = 255;
1589
+ }
1590
+ }
1591
+ }
1592
+ }
1593
+ }
1594
+ else {
1595
+ channels = [];
1596
+ }
1597
+ return {
1598
+ r: channels[0],
1599
+ g: channels[1],
1600
+ b: channels[2],
1601
+ a: 255
1602
+ };
1603
+ },
1604
+ rgba: function (string) {
1605
+ let channels = formats.rgb(string);
1606
+ channels.a = undefined;
1607
+ let match = string.match(/[\-0-9\.]+/g);
1608
+ if (match && match[3]) {
1609
+ let points = match[3].match(/\./g);
1610
+ if (!points || points.length === 1) {
1611
+ channels.a = parseFloat(match[3]);
1612
+ if (channels.a < 0) {
1613
+ channels.a = 0;
1614
+ }
1615
+ else if (channels.a > 1) {
1616
+ channels.a = 1;
1617
+ }
1618
+ channels.a = Math.round(channels.a * 255);
1619
+ }
1620
+ }
1621
+ return channels;
1622
+ },
1623
+ name: function (string) {
1624
+ let color = new Color('#' + Color.names[string]);
1625
+ return color.channels;
1626
+ }
1627
+ };
1628
+
1629
+ class ColorScale {
1630
+ constructor(palette) {
1631
+ this.palette = palette;
1632
+ }
1633
+ getColor(p) {
1634
+ const palette = this.palette.slice();
1635
+ palette[0][0] = 0;
1636
+ palette[palette.length - 1][0] = 1;
1637
+ let colors = palette.map(item => { return new Color(item[1]); });
1638
+ if (p >= 1) {
1639
+ let color = new Color(palette[palette.length - 1][1]);
1640
+ color.a = 255;
1641
+ return color.toString();
1642
+ }
1643
+ for (let i = 0; i < palette.length; i++) {
1644
+ if (palette[i][0] > p) {
1645
+ let width = palette[i][0] - palette[i - 1][0];
1646
+ let color1 = colors[i - 1];
1647
+ let color2 = colors[i];
1648
+ let k = (p - palette[i - 1][0]) / width;
1649
+ let channels = ['r', 'g', 'b', 'a'].map(function (ch) { return Math.round(color1[ch] + (color2[ch] - color1[ch]) * k); });
1650
+ channels[3] = 1;
1651
+ return 'rgba(' + channels.join(',') + ')';
1652
+ }
1653
+ }
1654
+ return null;
1655
+ }
1656
+ ;
1657
+ }
1658
+
1659
+ const transparentizeColor = (originalColor, percent) => {
1660
+ const color = new Color(originalColor);
1661
+ color.a = Math.round((255 / 100) * percent);
1662
+ return color.toString("hex");
1663
+ };
1664
+ const hexToRgba = (hexCode, opacity = 1) => {
1665
+ let hex = hexCode.replace("#", "");
1666
+ if (hex.length === 3) {
1667
+ hex = `${hex[0]}${hex[0]}${hex[1]}${hex[1]}${hex[2]}${hex[2]}`;
1668
+ }
1669
+ const r = parseInt(hex.substring(0, 2), 16);
1670
+ const g = parseInt(hex.substring(2, 4), 16);
1671
+ const b = parseInt(hex.substring(4, 6), 16);
1672
+ return `rgba(${r}, ${g}, ${b}, ${opacity})`;
1673
+ };
1674
+ const rgbToHex = (r, g, b) => {
1675
+ const componentToHex = (c) => {
1676
+ const hex = c.toString(16);
1677
+ return hex.padStart(2, "0");
1678
+ };
1679
+ return `#${componentToHex(r)}${componentToHex(g)}${componentToHex(b)}`;
1680
+ };
1681
+ const decimalOpacityToHex = (opacity) => {
1682
+ const hex = Math.round(opacity * 255).toString(16);
1683
+ return hex.padStart(2, "0");
1684
+ };
1685
+ const GRADIENT_COLORS = [
1686
+ "#00C2FF",
1687
+ "#67ADFE",
1688
+ "#766EFB",
1689
+ "#9D60F2",
1690
+ "#EC63D6",
1691
+ "#F35991",
1692
+ "#EC474C",
1693
+ "#FF7144",
1694
+ "#FF9F33",
1695
+ "#DEDE56",
1696
+ "#A1E062",
1697
+ "#51D8A5",
1698
+ ];
1699
+ const HEX_RRGGBB_LENGTH = 7;
1700
+ /**
1701
+ * Растягивает палитру на нужное количество цветов: опорные цвета равномерно
1702
+ * раскладываются по шкале, недостающие интерполируются между ними.
1703
+ * @param colors - опорные цвета палитры в hex
1704
+ * @param count - требуемое количество цветов
1705
+ * @returns массив ровно из count цветов
1706
+ */
1707
+ const stretchPalette = (colors, count) => {
1708
+ if (!colors?.length || count <= 0)
1709
+ return [];
1710
+ if (colors.length === 1)
1711
+ return Array.from({ length: count }, () => colors[0]);
1712
+ const scale = new ColorScale(colors.map((color, index) => [index / (colors.length - 1), color]));
1713
+ return Array.from({ length: count }, (_, index) => {
1714
+ const color = scale.getColor(count === 1 ? 0 : index / (count - 1));
1715
+ return color ? new Color(color).toString("hex").slice(0, HEX_RRGGBB_LENGTH) : colors[colors.length - 1];
1716
+ });
1717
+ };
1718
+ const getGradientColors = (colorsCount) => stretchPalette(GRADIENT_COLORS, colorsCount === undefined || colorsCount < GRADIENT_COLORS.length ? GRADIENT_COLORS.length : colorsCount);
1719
+ /**
1720
+ * Converts HSL hue value to RGB
1721
+ * @param p - lower bound
1722
+ * @param q - upper bound
1723
+ * @param t - hue value
1724
+ * @returns RGB component value (0-1)
1725
+ */
1726
+ const hue2rgb = (p, q, t) => {
1727
+ if (t < 0)
1728
+ t += 1;
1729
+ if (t > 1)
1730
+ t -= 1;
1731
+ if (t < 1 / 6)
1732
+ return p + (q - p) * 6 * t;
1733
+ if (t < 1 / 2)
1734
+ return q;
1735
+ if (t < 2 / 3)
1736
+ return p + (q - p) * (2 / 3 - t) * 6;
1737
+ return p;
1738
+ };
1739
+ /**
1740
+ * Converts RGB component (0-1) to hex string
1741
+ * @param value - RGB component value (0-1)
1742
+ * @returns hex string (00-ff)
1743
+ */
1744
+ const toHex = (value) => {
1745
+ const hex = Math.round(value * 255).toString(16);
1746
+ return hex.padStart(2, "0");
1747
+ };
1748
+ /**
1749
+ * Adjusts color brightness
1750
+ * @param color - hex color string (e.g., "#2196f3")
1751
+ * @param lightnessAdjustment - lightness adjustment in HSL units (e.g., 5 or -5)
1752
+ * @returns adjusted color in hex format
1753
+ */
1754
+ const adjustColor = (color, lightnessAdjustment = 5) => {
1755
+ // Convert hex to RGB
1756
+ const hex = color.replace("#", "");
1757
+ const r = parseInt(hex.substring(0, 2), 16) / 255;
1758
+ const g = parseInt(hex.substring(2, 4), 16) / 255;
1759
+ const b = parseInt(hex.substring(4, 6), 16) / 255;
1760
+ // Convert RGB to HSL
1761
+ const max = Math.max(r, g, b);
1762
+ const min = Math.min(r, g, b);
1763
+ let h = 0;
1764
+ let s = 0;
1765
+ const l = (max + min) / 2;
1766
+ if (max !== min) {
1767
+ const d = max - min;
1768
+ s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
1769
+ switch (max) {
1770
+ case r:
1771
+ h = ((g - b) / d + (g < b ? 6 : 0)) / 6;
1772
+ break;
1773
+ case g:
1774
+ h = ((b - r) / d + 2) / 6;
1775
+ break;
1776
+ case b:
1777
+ h = ((r - g) / d + 4) / 6;
1778
+ break;
1779
+ }
1780
+ }
1781
+ const adjustedL = Math.max(0, Math.min(100, (l * 100) + lightnessAdjustment)) / 100;
1782
+ // Convert HSL back to RGB
1783
+ let rNew;
1784
+ let gNew;
1785
+ let bNew;
1786
+ if (s === 0) {
1787
+ rNew = gNew = bNew = adjustedL;
1788
+ }
1789
+ else {
1790
+ const q = adjustedL < 0.5 ? adjustedL * (1 + s) : adjustedL + s - adjustedL * s;
1791
+ const p = 2 * adjustedL - q;
1792
+ rNew = hue2rgb(p, q, h + 1 / 3);
1793
+ gNew = hue2rgb(p, q, h);
1794
+ bNew = hue2rgb(p, q, h - 1 / 3);
1795
+ }
1796
+ return `#${toHex(rNew)}${toHex(gNew)}${toHex(bNew)}`;
1797
+ };
1798
+ const OPAQUE_ALPHA = "ff";
1799
+ /**
1800
+ * Цвет в hex: `#rrggbb`, а при неполной непрозрачности — `#rrggbbaa`.
1801
+ *
1802
+ * Полностью непрозрачная альфа отбрасывается: в значении она ничего не уточняет, а строку
1803
+ * удлиняет — и в конфиге, и в данных удобнее короткая запись.
1804
+ */
1805
+ const colorToHex = (color) => {
1806
+ const hex = color.toString("hex");
1807
+ return hex.slice(HEX_RRGGBB_LENGTH).toLowerCase() === OPAQUE_ALPHA ? hex.slice(0, HEX_RRGGBB_LENGTH) : hex;
1808
+ };
1809
+
1810
+ const NO_CONTENT_VALUE = "—";
1811
+ exports.DateFormat = void 0;
1812
+ (function (DateFormat) {
1813
+ DateFormat["ClientDefaultFormat"] = "dd.MM.yyyy HH:mm";
1814
+ DateFormat["DateTime"] = "dd.MM.yyyy HH:mm:ss";
1815
+ DateFormat["UTC"] = "yyyy-MM-dd'T'HH:mm:ss.sssxxx";
1816
+ DateFormat["AxisTooltip"] = "d MMMM yyyy";
1817
+ })(exports.DateFormat || (exports.DateFormat = {}));
1818
+ const stringDateParsers = [dateFns.parseJSON, dateFns.parseISO, rawDate => new Date(rawDate)];
1819
+ const getDate = (rawDate) => {
1820
+ if (!rawDate) {
1821
+ return null;
1822
+ }
1823
+ if (typeof rawDate === "string") {
1824
+ for (const parser of stringDateParsers) {
1825
+ const date = parser(rawDate);
1826
+ if (dateFns.isValid(date)) {
1827
+ return dateFns.toDate(date);
1828
+ }
1829
+ }
1830
+ return null;
1831
+ }
1832
+ const parsedDate = dateFns.toDate(rawDate);
1833
+ return dateFns.isValid(parsedDate) ? parsedDate : null;
1834
+ };
1835
+ const formatDate$1 = (date, { dateFormat = exports.DateFormat.ClientDefaultFormat, defaultValue = NO_CONTENT_VALUE } = {}) => {
1836
+ const dateValue = date ? getDate(date) : null;
1837
+ if (dateFns.isValid(dateValue)) {
1838
+ return dateFns.format(dateValue, dateFormat);
1839
+ }
1840
+ return `${defaultValue}`;
1841
+ };
1842
+
1843
+ const debounce = (callback, delay) => {
1844
+ let timeId;
1845
+ return (...args) => {
1846
+ if (timeId) {
1847
+ window.clearTimeout(timeId);
1848
+ }
1849
+ timeId = window.setTimeout(() => {
1850
+ callback(...args);
1851
+ }, delay);
1852
+ };
1853
+ };
1854
+
1855
+ const MILLION = 1000000;
1856
+ const TEN_THOUSANDS = 10000;
1857
+ const THOUSAND = 1000;
1858
+ const COMPACT_FRACTION_DIGITS = 1;
1859
+ const roundTotalSum = (value, fractionDigits) => {
1860
+ if (!value)
1861
+ return "";
1862
+ const digits = fractionDigits ?? COMPACT_FRACTION_DIGITS;
1863
+ if (value >= MILLION) {
1864
+ return `${(value / MILLION).toFixed(digits)}M`;
1865
+ }
1866
+ if (value >= TEN_THOUSANDS) {
1867
+ return `${(value / THOUSAND).toFixed(digits)}K`;
1868
+ }
1869
+ return value;
1870
+ };
1871
+
1872
+ const TIME_ZONE_FORMAT = ' "GMT"z'; // eslint-disable-line
1873
+ exports.ScalingFactor = void 0;
1874
+ (function (ScalingFactor) {
1875
+ ScalingFactor[ScalingFactor["Default"] = 1] = "Default";
1876
+ ScalingFactor[ScalingFactor["Thousands"] = 0.001] = "Thousands";
1877
+ ScalingFactor[ScalingFactor["Millions"] = 0.000001] = "Millions";
1878
+ ScalingFactor[ScalingFactor["Acres"] = 0.01] = "Acres";
1879
+ ScalingFactor[ScalingFactor["Hectares"] = 0.0001] = "Hectares";
1880
+ })(exports.ScalingFactor || (exports.ScalingFactor = {}));
1881
+ const formatDate = (str, isRuLocale) => dateFns.format(Date.now(), str, { locale: isRuLocale ? locale.ru : locale.enUS });
1882
+ const timeOptions = [
1883
+ {
1884
+ text: formatDate("kk:mm:ss"),
1885
+ value: "hh:mm:ss",
1886
+ },
1887
+ {
1888
+ text: formatDate("hh:mm:ss aa"),
1889
+ value: "hh:mm:ss tt",
1890
+ },
1891
+ {
1892
+ text: formatDate("kk:mm"),
1893
+ value: "hh:mm",
1894
+ },
1895
+ {
1896
+ text: formatDate("hh:mm aa"),
1897
+ value: "hh:mm tt",
1898
+ },
1899
+ ];
1900
+ const dateOptions = [
1901
+ {
1902
+ text: formatDate("dd.MM.yyyy"),
1903
+ value: "dd.MM.yyyy",
1904
+ },
1905
+ {
1906
+ text: formatDate("dd MMMM yyyy", true),
1907
+ value: "dd MMMM yyyy",
1908
+ },
1909
+ {
1910
+ text: formatDate("yyyy, dd MMMM", true),
1911
+ value: "yyyy, dd MMMM",
1912
+ },
1913
+ ];
1914
+ const pointOptions = [
1915
+ {
1916
+ value: "default",
1917
+ localizationKey: "defaultValue",
1918
+ },
1919
+ {
1920
+ value: "DD MM SS",
1921
+ localizationKey: "degreesMinutesSeconds",
1922
+ },
1923
+ {
1924
+ value: "DD.",
1925
+ localizationKey: "decimalDegrees",
1926
+ },
1927
+ ];
1928
+ const numberOptions = [
1929
+ {
1930
+ value: exports.ScalingFactor.Default.toString(),
1931
+ localizationKey: "defaultValue",
1932
+ },
1933
+ {
1934
+ value: exports.ScalingFactor.Thousands.toString(),
1935
+ localizationKey: "inThousands",
1936
+ },
1937
+ {
1938
+ value: exports.ScalingFactor.Millions.toString(),
1939
+ localizationKey: "inMillions",
1940
+ },
1941
+ {
1942
+ value: exports.ScalingFactor.Acres.toString(),
1943
+ localizationKey: "inAcres",
1944
+ },
1945
+ {
1946
+ value: exports.ScalingFactor.Hectares.toString(),
1947
+ localizationKey: "inHectares",
1948
+ },
1949
+ ];
1950
+ const convertDDToDMS = (value) => {
1951
+ const absolute = Math.abs(value);
1952
+ const degrees = Math.floor(absolute);
1953
+ const minutesNotTruncated = (absolute - degrees) * 60;
1954
+ const minutes = Math.floor(minutesNotTruncated);
1955
+ const seconds = Math.floor((minutesNotTruncated - minutes) * 60);
1956
+ return `${degrees}° ${minutes}' ${seconds}"`;
1957
+ };
1958
+ const formatPointValue = ({ t, stringFormat, value }) => {
1959
+ if (stringFormat.format === pointOptions[1].value) {
1960
+ const lon = value[1];
1961
+ const lat = value[0];
1962
+ const lonDirection = lon >= 0 ? t("east", { ns: "common" }) : t("west", { ns: "common" });
1963
+ const latDirection = lat >= 0 ? t("north", { ns: "common" }) : t("south", { ns: "common" });
1964
+ return `${convertDDToDMS(lon)} ${lonDirection}, ${convertDDToDMS(lat)} ${latDirection}`;
1965
+ }
1966
+ if (stringFormat.format.includes("DD.") && value.length) {
1967
+ const rounding = stringFormat.format.replace("DD.", "").length;
1968
+ return `${value[0].toFixed(rounding)}, ${value[1].toFixed(rounding)}`;
1969
+ }
1970
+ return null;
1971
+ };
1972
+ const getValueFromOptions = (options, format) => options.find(({ value }) => format && format.includes(value));
1973
+ const numberWithSpaces = (input, precision) => {
1974
+ if (input === null || input === undefined) {
1975
+ return "";
1976
+ }
1977
+ return parseFloat((typeof input === "string" ? parseFloat(input) : input).toString()).toLocaleString("ru-RU", {
1978
+ maximumFractionDigits: precision ?? 10,
1979
+ });
1980
+ };
1981
+ const formatDateValue = (stringFormat, dateValue) => {
1982
+ let value = dateValue;
1983
+ if (typeof value === "string") {
1984
+ value = new Date(value).getTime();
1985
+ }
1986
+ const isRuLocale = stringFormat.culture && stringFormat.culture === "ru-RU";
1987
+ const showTimeZone = stringFormat.format.includes(TIME_ZONE_FORMAT);
1988
+ const dateOption = getValueFromOptions(dateOptions, stringFormat.format);
1989
+ const dateOptionValue = dateOption && dateOption.value;
1990
+ const dateFormat = value && dateOptionValue
1991
+ ? dateFns.format(value, dateOptionValue, {
1992
+ locale: locale.ru,
1993
+ })
1994
+ : "";
1995
+ const timeOption = getValueFromOptions(timeOptions, stringFormat.format);
1996
+ const timeOptionValue = timeOption && (isRuLocale ? timeOption.value : `${timeOption.value} aa`);
1997
+ const timeFormat = (timeOptionValue && dateFns.format(value, showTimeZone ? `${timeOptionValue} zz` : timeOptionValue)) || "";
1998
+ return dateFormat ? [dateFormat, timeFormat].filter(Boolean).join(" ") : "";
1999
+ };
2000
+ const appendUnitsLabel = (value, unitsLabel, noUnits) => (unitsLabel && !noUnits ? `${value} ${unitsLabel}` : value)?.toString() || "";
2001
+ const formatNumberValue = (stringFormat, value, type, noUnits = false) => {
2002
+ const { scalingFactor, rounding, splitDigitGroup, roundDigitGroup, unitsLabel } = stringFormat || {};
2003
+ const isIntValue = [api.AttributeType.Int32, api.AttributeType.Int64].includes(type);
2004
+ const isDefaultScaling = stringFormat && stringFormat.scalingFactor === +numberOptions[0].value;
2005
+ let currentValue = value;
2006
+ if (isIntValue && isDefaultScaling && currentValue) {
2007
+ currentValue = parseInt(currentValue.toString(), 10);
2008
+ }
2009
+ if (scalingFactor) {
2010
+ currentValue *= scalingFactor;
2011
+ }
2012
+ const hasRounding = !lodash.isNil(rounding);
2013
+ const compactValue = roundDigitGroup
2014
+ ? roundTotalSum(Number(currentValue), hasRounding ? rounding : undefined)
2015
+ : null;
2016
+ if (typeof compactValue === "string" && compactValue) {
2017
+ return appendUnitsLabel(compactValue, unitsLabel, noUnits);
2018
+ }
2019
+ if (hasRounding && (!isIntValue || !isDefaultScaling) && !lodash.isNil(currentValue)) {
2020
+ currentValue = Number(currentValue).toFixed(rounding);
2021
+ }
2022
+ if (splitDigitGroup) {
2023
+ currentValue = numberWithSpaces(currentValue);
2024
+ }
2025
+ if (currentValue) {
2026
+ currentValue = currentValue.toString().replace(".", ",");
2027
+ }
2028
+ return appendUnitsLabel(currentValue, unitsLabel, noUnits);
2029
+ };
2030
+ const formatAttributeValue = ({ t, type, value, stringFormat, noUnits = false }) => {
2031
+ const isNilValue = lodash.isNil(value);
2032
+ if (type === api.AttributeType.Point) {
2033
+ if (!stringFormat?.format || isNilValue) {
2034
+ return null;
2035
+ }
2036
+ return formatPointValue({ t, stringFormat, value: value?.coordinates });
2037
+ }
2038
+ if (type === api.AttributeType.DateTime) {
2039
+ if (isNilValue) {
2040
+ return null;
2041
+ }
2042
+ if (!stringFormat?.format) {
2043
+ return value;
2044
+ }
2045
+ return formatDateValue(stringFormat, value);
2046
+ }
2047
+ if ([
2048
+ api.AttributeType.Int32,
2049
+ api.AttributeType.Int64,
2050
+ api.AttributeType.Double,
2051
+ api.AttributeType.Polygon,
2052
+ api.AttributeType.LineString,
2053
+ api.AttributeType.MultiPoint,
2054
+ api.AttributeType.MultiPolygon,
2055
+ api.AttributeType.MultiLineString,
2056
+ ].includes(type) &&
2057
+ !isNaN(value)) {
2058
+ if (!stringFormat && !isNilValue) {
2059
+ return value.toString();
2060
+ }
2061
+ return formatNumberValue(stringFormat, value, type, noUnits);
2062
+ }
2063
+ if (type === api.AttributeType.Json) {
2064
+ if (isNilValue || value?.length === 0) {
2065
+ return "";
2066
+ }
2067
+ return `${t("total", { ns: "table" })} ${value.length}`;
2068
+ }
2069
+ return !isNilValue ? value.toString() : "";
2070
+ };
2071
+ const formatNumber = (number) => {
2072
+ let result = "";
2073
+ const gapSize = 3;
2074
+ if (typeof number === "number") {
2075
+ const numsArray = String(number).split(".");
2076
+ const numeral = numsArray[0];
2077
+ let spaceBefore = numeral.length % gapSize;
2078
+ for (let i = 0; i < numeral.length; i += 1) {
2079
+ if (i === spaceBefore) {
2080
+ result = `${result} `;
2081
+ spaceBefore += 3;
2082
+ }
2083
+ result += numeral[i];
2084
+ }
2085
+ if (numsArray[1]) {
2086
+ return [result.trim(), numsArray[1]].join(".");
2087
+ }
2088
+ return result.trim();
2089
+ }
2090
+ return number || "0";
2091
+ };
2092
+ const formatArea = (t, num) => {
2093
+ let result = num;
2094
+ let measure = t("sqMeter", { ns: "common" });
2095
+ if (num >= 10000000) {
2096
+ result = num / 1000000;
2097
+ measure = t("sqKilometer", { ns: "common" });
2098
+ }
2099
+ else if (num >= 10000) {
2100
+ result = num / 10000;
2101
+ measure = t("hectare", { ns: "common" });
2102
+ }
2103
+ return `${numberWithSpaces(result, 2)} ${measure}`;
2104
+ };
2105
+ const formatLength = (t, num) => {
2106
+ let result = num;
2107
+ let measure = t("meter", { ns: "common" });
2108
+ if (num > 10000) {
2109
+ result = num / 1000;
2110
+ measure = t("kilometer", { ns: "common" });
2111
+ }
2112
+ return `${numberWithSpaces(result, 2)} ${measure}`;
2113
+ };
2114
+ const formatPolygonMeasure = (t, area, perimiter) => {
2115
+ return `S : ${formatArea(t, area)} P : ${formatLength(t, perimiter)}`;
2116
+ };
2117
+
2118
+ const geometryToEwkt = (geometry) => {
2119
+ if (!geometry) {
2120
+ return "";
2121
+ }
2122
+ const projected = turf.toMercator({ type: "Feature", geometry, properties: {} });
2123
+ const projectedCoords = projected?.geometry?.coordinates;
2124
+ const wkt$1 = wkt.stringify({ ...geometry, coordinates: projectedCoords });
2125
+ return `SRID=3857;${wkt$1}`;
2126
+ };
2127
+
2128
+ function isObject(value) {
2129
+ return value !== null && typeof value === "object" && !Array.isArray(value);
2130
+ }
2131
+
2132
+ const isLayerService = (value) => isObject(value) && "name" in value;
2133
+
2134
+ const isNumeric = (number) => !isNaN(parseFloat(number)) && isFinite(number);
2135
+
2136
+ const metersPerPixel = (zoom, lat) => {
2137
+ return (156543.03 * Math.cos(lat * (Math.PI / 180))) / 2 ** zoom;
2138
+ };
2139
+
2140
+ const clamp = (value, limit) => Math.min(Math.max(value, -limit), limit);
2141
+ /**
2142
+ * Снимок текущего вида карты. `getBounds()` отдаёт градусы WGS84, `geometryToEwkt` переводит их
2143
+ * в меркатор и ставит префикс `SRID=3857;` — тот же формат, что у геометрического фильтра.
2144
+ *
2145
+ * Клампинг обязателен: на полностью отдалённой или наклонённой карте bounds выходят за пределы
2146
+ * проекции, и меркатор возвращает `Infinity` — такой WKT бэкенд не примет.
2147
+ */
2148
+ const getMapView = (map) => {
2149
+ if (!map) {
2150
+ return {};
2151
+ }
2152
+ const bounds = map.getBounds();
2153
+ const polygon = turf.bboxPolygon([
2154
+ clamp(bounds.getWest(), MERCATOR_MAX_LONGITUDE),
2155
+ clamp(bounds.getSouth(), MERCATOR_MAX_LATITUDE),
2156
+ clamp(bounds.getEast(), MERCATOR_MAX_LONGITUDE),
2157
+ clamp(bounds.getNorth(), MERCATOR_MAX_LATITUDE),
2158
+ ]);
2159
+ return {
2160
+ ewktExtent: geometryToEwkt(polygon.geometry),
2161
+ zoomLevel: Math.round(map.getZoom()),
2162
+ };
2163
+ };
2164
+
2165
+ const parseMapStyle = (style) => {
2166
+ if (!isObject(style)) {
2167
+ return style;
2168
+ }
2169
+ let result = { ...style };
2170
+ if (style.metadata?.["basemap:sky"]?.enabled === false) {
2171
+ result = {
2172
+ ...result,
2173
+ sky: undefined,
2174
+ };
2175
+ }
2176
+ if (style.metadata?.["basemap:terrain"]?.enabled === false) {
2177
+ result = {
2178
+ ...result,
2179
+ terrain: undefined,
2180
+ };
2181
+ }
2182
+ if (style.metadata?.["basemap:hillshade"]?.enabled === false) {
2183
+ result = {
2184
+ ...result,
2185
+ layers: result.layers?.filter(({ id }) => id !== "hillshade"),
2186
+ };
2187
+ }
2188
+ if (style.metadata?.["basemap:buildings3d"]?.enabled === false) {
2189
+ result = {
2190
+ ...result,
2191
+ layers: result.layers?.filter(({ id }) => id !== "building-3d"),
2192
+ };
2193
+ }
2194
+ return result;
2195
+ };
2196
+
2197
+ const getPrimaryType = (schema) => {
2198
+ if (!schema?.type) {
2199
+ return undefined;
2200
+ }
2201
+ if (Array.isArray(schema.type)) {
2202
+ return schema.type.find(typeName => typeName !== "null") ?? schema.type[0];
2203
+ }
2204
+ return schema.type;
2205
+ };
2206
+
2207
+ const compareByOrder = (left, right) => {
2208
+ const leftOrder = left?.["x-order"];
2209
+ const rightOrder = right?.["x-order"];
2210
+ if (leftOrder !== undefined && rightOrder !== undefined) {
2211
+ return leftOrder - rightOrder;
2212
+ }
2213
+ if (leftOrder !== undefined) {
2214
+ return -1;
2215
+ }
2216
+ if (rightOrder !== undefined) {
2217
+ return 1;
2218
+ }
2219
+ return 0;
2220
+ };
2221
+ const orderPropertyKeys = (schema) => {
2222
+ const keys = Object.keys(schema.properties ?? {});
2223
+ const required = schema.required ?? [];
2224
+ const properties = schema.properties ?? {};
2225
+ const hasExplicitOrder = keys.some(key => properties[key]?.["x-order"] !== undefined);
2226
+ if (hasExplicitOrder) {
2227
+ return [...keys].sort((leftKey, rightKey) => compareByOrder(properties[leftKey], properties[rightKey]));
2228
+ }
2229
+ const requiredSet = new Set(required);
2230
+ const requiredOrdered = required.filter(key => keys.includes(key));
2231
+ const rest = keys.filter(key => !requiredSet.has(key));
2232
+ return [...requiredOrdered, ...rest];
2233
+ };
2234
+
2235
+ const FORM_DEFAULT_OPTIONS = {
2236
+ stringDefault: undefined,
2237
+ objectDepth: "recursive",
2238
+ propertyKeys: "default",
2239
+ emptyObject: "undefined",
2240
+ ignoreSchemaDefault: false,
2241
+ };
2242
+ const ARRAY_ITEM_OBJECT_OPTIONS = {
2243
+ stringDefault: "",
2244
+ objectDepth: "shallow",
2245
+ propertyKeys: "ordered",
2246
+ emptyObject: "empty",
2247
+ ignoreSchemaDefault: true,
2248
+ };
2249
+ const getPropertyKeys = (resolved, propertyKeys) => {
2250
+ if (propertyKeys === "ordered") {
2251
+ return orderPropertyKeys(resolved);
2252
+ }
2253
+ return Object.keys(resolved.properties ?? {});
2254
+ };
2255
+ const buildShallowChildDefault = (resolver, childSchema, options) => {
2256
+ const childResolved = resolver.resolve(childSchema) ?? childSchema;
2257
+ if (childResolved.default !== undefined) {
2258
+ return childResolved.default;
2259
+ }
2260
+ const primaryType = getPrimaryType(childResolved);
2261
+ if (primaryType === "boolean") {
2262
+ return false;
2263
+ }
2264
+ if (primaryType === "string" && options.stringDefault !== undefined) {
2265
+ return options.stringDefault;
2266
+ }
2267
+ return undefined;
2268
+ };
2269
+ const buildDefault = (resolver, schema, options, ignoreSchemaDefault) => {
2270
+ const resolved = resolver.resolve(schema);
2271
+ if (!resolved) {
2272
+ return undefined;
2273
+ }
2274
+ if (!ignoreSchemaDefault && resolved.default !== undefined) {
2275
+ return resolved.default;
2276
+ }
2277
+ const primaryType = getPrimaryType(resolved);
2278
+ if (primaryType === "object" && resolved.properties) {
2279
+ const result = {};
2280
+ const keys = getPropertyKeys(resolved, options.propertyKeys);
2281
+ for (const key of keys) {
2282
+ const childSchema = resolved.properties[key];
2283
+ const childDefault = options.objectDepth === "shallow"
2284
+ ? buildShallowChildDefault(resolver, childSchema, options)
2285
+ : buildDefault(resolver, childSchema, options, false);
2286
+ if (childDefault !== undefined) {
2287
+ result[key] = childDefault;
2288
+ }
2289
+ }
2290
+ if (Object.keys(result).length === 0) {
2291
+ return options.emptyObject === "empty" ? {} : undefined;
2292
+ }
2293
+ return result;
2294
+ }
2295
+ if (primaryType === "array" && options.objectDepth === "recursive") {
2296
+ return [];
2297
+ }
2298
+ if (primaryType === "boolean") {
2299
+ return false;
2300
+ }
2301
+ if (primaryType === "integer" || primaryType === "number") {
2302
+ return undefined;
2303
+ }
2304
+ if (primaryType === "string" && options.stringDefault !== undefined) {
2305
+ return options.stringDefault;
2306
+ }
2307
+ return undefined;
2308
+ };
2309
+ const buildDefaultForSchema = (resolver, schema, options) => {
2310
+ const mergedOptions = {
2311
+ ...FORM_DEFAULT_OPTIONS,
2312
+ ...options,
2313
+ };
2314
+ return buildDefault(resolver, schema, mergedOptions, mergedOptions.ignoreSchemaDefault);
2315
+ };
2316
+
2317
+ const getHiddenDefaultValue = (resolver, propertySchema) => {
2318
+ const resolved = resolver.resolve(propertySchema) ?? propertySchema;
2319
+ if (resolved.default !== undefined) {
2320
+ return resolved.default;
2321
+ }
2322
+ return undefined;
2323
+ };
2324
+ const mergeHiddenFieldsAtLevel = (resolver, schema, data) => {
2325
+ const resolved = resolver.resolve(schema) ?? schema;
2326
+ const properties = resolved.properties ?? {};
2327
+ if (Object.keys(properties).length === 0) {
2328
+ return data;
2329
+ }
2330
+ let result = { ...data };
2331
+ for (const [propertyKey, propertySchema] of Object.entries(properties)) {
2332
+ const propertyResolved = resolver.resolve(propertySchema) ?? propertySchema;
2333
+ if (propertyResolved["x-hide"]) {
2334
+ if (result[propertyKey] !== undefined) {
2335
+ continue;
2336
+ }
2337
+ const hiddenDefault = getHiddenDefaultValue(resolver, propertySchema);
2338
+ if (hiddenDefault !== undefined) {
2339
+ result = { ...result, [propertyKey]: hiddenDefault };
2340
+ }
2341
+ continue;
2342
+ }
2343
+ const primaryType = getPrimaryType(propertyResolved);
2344
+ if (primaryType === "object" && propertyResolved.properties) {
2345
+ const nestedData = result[propertyKey] !== null && typeof result[propertyKey] === "object" && !Array.isArray(result[propertyKey])
2346
+ ? result[propertyKey]
2347
+ : {};
2348
+ const mergedNested = mergeHiddenFieldsAtLevel(resolver, propertySchema, nestedData);
2349
+ if (mergedNested !== nestedData) {
2350
+ result = { ...result, [propertyKey]: mergedNested };
2351
+ }
2352
+ }
2353
+ }
2354
+ return result;
2355
+ };
2356
+ const mergeHiddenFieldDefaults = (resolver, formData) => {
2357
+ return mergeHiddenFieldsAtLevel(resolver, resolver.rootSchema, formData);
2358
+ };
2359
+
2360
+ const EVERGIS_TYPE_ATTRIBUTE = "Attribute";
2361
+ const scopeToKeys = (scope) => {
2362
+ if (!scope.startsWith("#/")) {
2363
+ return [];
2364
+ }
2365
+ return scope
2366
+ .slice(2)
2367
+ .split("/")
2368
+ .filter(segment => segment !== "properties");
2369
+ };
2370
+ const isAttributeStringSchema = (schema) => getPrimaryType(schema) === "string" && schema["x-evergis-type"] === EVERGIS_TYPE_ATTRIBUTE;
2371
+ class SchemaResolver {
2372
+ root;
2373
+ constructor(rootSchema) {
2374
+ this.root = rootSchema;
2375
+ }
2376
+ get rootSchema() {
2377
+ return this.root;
2378
+ }
2379
+ resolve(schema) {
2380
+ if (!schema) {
2381
+ return undefined;
2382
+ }
2383
+ if (schema.$ref) {
2384
+ return this.resolve(this.resolveRef(schema.$ref));
2385
+ }
2386
+ if (schema.allOf?.length) {
2387
+ return this.mergeAllOf(schema.allOf);
2388
+ }
2389
+ if (schema.oneOf?.length) {
2390
+ return this.resolve(schema.oneOf[0]);
2391
+ }
2392
+ if (schema.anyOf?.length) {
2393
+ return this.resolve(schema.anyOf[0]);
2394
+ }
2395
+ return schema;
2396
+ }
2397
+ oneOfBranches(schema) {
2398
+ if (!schema) {
2399
+ return [];
2400
+ }
2401
+ if (schema.$ref) {
2402
+ return this.oneOfBranches(this.resolveRef(schema.$ref));
2403
+ }
2404
+ if (schema.allOf?.length) {
2405
+ return [this.mergeAllOf(schema.allOf)];
2406
+ }
2407
+ if (schema.oneOf?.length) {
2408
+ return schema.oneOf.map(branch => this.resolve(branch)).filter(Boolean);
2409
+ }
2410
+ if (schema.anyOf?.length) {
2411
+ return schema.anyOf.map(branch => this.resolve(branch)).filter(Boolean);
2412
+ }
2413
+ return [schema];
2414
+ }
2415
+ schemaAtScope(scope) {
2416
+ const keys = scopeToKeys(scope);
2417
+ let current = this.resolve(this.root);
2418
+ for (const key of keys) {
2419
+ if (!current) {
2420
+ return undefined;
2421
+ }
2422
+ const resolved = this.resolve(current);
2423
+ const properties = resolved?.properties;
2424
+ if (!properties?.[key]) {
2425
+ return undefined;
2426
+ }
2427
+ current = properties[key];
2428
+ }
2429
+ return this.resolve(current);
2430
+ }
2431
+ isScopeRequired(scope) {
2432
+ const keys = scopeToKeys(scope);
2433
+ if (keys.length === 0) {
2434
+ return false;
2435
+ }
2436
+ let current = this.resolve(this.root);
2437
+ for (let index = 0; index < keys.length; index += 1) {
2438
+ const key = keys[index];
2439
+ const resolved = this.resolve(current);
2440
+ const required = resolved?.required ?? [];
2441
+ if (index === keys.length - 1) {
2442
+ return required.includes(key);
2443
+ }
2444
+ current = resolved?.properties?.[key];
2445
+ }
2446
+ return false;
2447
+ }
2448
+ arrayItemSchema(itemsSchema) {
2449
+ if (!itemsSchema) {
2450
+ return undefined;
2451
+ }
2452
+ const branches = this.oneOfBranches(itemsSchema);
2453
+ if (branches.length === 1) {
2454
+ return this.resolve(branches[0]);
2455
+ }
2456
+ return this.resolve(itemsSchema);
2457
+ }
2458
+ arrayItemKind(arraySchema) {
2459
+ const resolvedArray = this.resolve(arraySchema) ?? arraySchema;
2460
+ const itemSchema = this.arrayItemSchema(resolvedArray.items);
2461
+ if (!itemSchema) {
2462
+ return null;
2463
+ }
2464
+ const itemResolved = this.resolve(itemSchema) ?? itemSchema;
2465
+ const branches = this.oneOfBranches(resolvedArray.items ?? itemSchema);
2466
+ if (branches.length === 1 && isAttributeStringSchema(branches[0])) {
2467
+ return { kind: "attribute", itemSchema: branches[0] };
2468
+ }
2469
+ if (isAttributeStringSchema(itemResolved)) {
2470
+ return { kind: "attribute", itemSchema: itemResolved };
2471
+ }
2472
+ const primaryType = getPrimaryType(itemResolved);
2473
+ if (primaryType === "string") {
2474
+ return { kind: "string", itemSchema: itemResolved };
2475
+ }
2476
+ if (primaryType === "object" && itemResolved.properties) {
2477
+ return { kind: "composite", itemSchema: itemResolved };
2478
+ }
2479
+ return null;
2480
+ }
2481
+ resolveRef(ref) {
2482
+ if (!ref.startsWith("#/")) {
2483
+ return undefined;
2484
+ }
2485
+ const segments = ref.slice(2).split("/");
2486
+ let current = this.root;
2487
+ for (const segment of segments) {
2488
+ if (!current) {
2489
+ return undefined;
2490
+ }
2491
+ current = current[segment];
2492
+ }
2493
+ return current;
2494
+ }
2495
+ mergeAllOf(schemas) {
2496
+ const merged = { type: "object", properties: {} };
2497
+ for (const part of schemas) {
2498
+ const resolved = this.resolve(part);
2499
+ if (resolved?.properties) {
2500
+ merged.properties = { ...merged.properties, ...resolved.properties };
2501
+ }
2502
+ if (resolved?.type && !merged.type) {
2503
+ merged.type = resolved.type;
2504
+ }
2505
+ if (resolved?.description && !merged.description) {
2506
+ merged.description = resolved.description;
2507
+ }
2508
+ if (resolved?.["x-evergis-type"] && !merged["x-evergis-type"]) {
2509
+ merged["x-evergis-type"] = resolved["x-evergis-type"];
2510
+ }
2511
+ }
2512
+ return merged;
2513
+ }
2514
+ }
2515
+
2516
+ exports.EditGeometryType = void 0;
2517
+ (function (EditGeometryType) {
2518
+ EditGeometryType["Raster"] = "raster";
2519
+ })(exports.EditGeometryType || (exports.EditGeometryType = {}));
2520
+
2521
+ exports.ThemeName = void 0;
2522
+ (function (ThemeName) {
2523
+ ThemeName["Light"] = "light";
2524
+ ThemeName["Dark"] = "dark";
2525
+ })(exports.ThemeName || (exports.ThemeName = {}));
2526
+
2527
+ exports.ARRAY_ITEM_OBJECT_OPTIONS = ARRAY_ITEM_OBJECT_OPTIONS;
2528
+ exports.COMPACT_FRACTION_DIGITS = COMPACT_FRACTION_DIGITS;
2529
+ exports.ClientStyleValidator = ClientStyleValidator;
2530
+ exports.DEFAULT_BLUR = DEFAULT_BLUR;
2531
+ exports.DEFAULT_CIRCLE_RADIUS = DEFAULT_CIRCLE_RADIUS;
2532
+ exports.DEFAULT_CIRCLE_STROKE_WIDTH = DEFAULT_CIRCLE_STROKE_WIDTH;
2533
+ exports.DEFAULT_CIRCLE_STYLE = DEFAULT_CIRCLE_STYLE;
2534
+ exports.DEFAULT_COLOR = DEFAULT_COLOR;
2535
+ exports.DEFAULT_FILL_EXTRUSION_BASE = DEFAULT_FILL_EXTRUSION_BASE;
2536
+ exports.DEFAULT_FILL_EXTRUSION_HEIGHT = DEFAULT_FILL_EXTRUSION_HEIGHT;
2537
+ exports.DEFAULT_FILL_EXTRUSION_STYLE = DEFAULT_FILL_EXTRUSION_STYLE;
2538
+ exports.DEFAULT_FILL_EXTRUSION_VERTICAL_GRADIENT = DEFAULT_FILL_EXTRUSION_VERTICAL_GRADIENT;
2539
+ exports.DEFAULT_FILL_STYLE = DEFAULT_FILL_STYLE;
2540
+ exports.DEFAULT_HEATMAP_COLOR = DEFAULT_HEATMAP_COLOR;
2541
+ exports.DEFAULT_HEATMAP_INTENSITY = DEFAULT_HEATMAP_INTENSITY;
2542
+ exports.DEFAULT_HEATMAP_RADIUS = DEFAULT_HEATMAP_RADIUS;
2543
+ exports.DEFAULT_HEATMAP_STYLE = DEFAULT_HEATMAP_STYLE;
2544
+ exports.DEFAULT_HEATMAP_WEIGHT = DEFAULT_HEATMAP_WEIGHT;
2545
+ exports.DEFAULT_ICON_ANCHOR = DEFAULT_ICON_ANCHOR;
2546
+ exports.DEFAULT_ICON_OVERLAP = DEFAULT_ICON_OVERLAP;
2547
+ exports.DEFAULT_ICON_PADDING = DEFAULT_ICON_PADDING;
2548
+ exports.DEFAULT_ICON_ROTATE = DEFAULT_ICON_ROTATE;
2549
+ exports.DEFAULT_ICON_SIZE = DEFAULT_ICON_SIZE;
2550
+ exports.DEFAULT_LINE_CAP = DEFAULT_LINE_CAP;
2551
+ exports.DEFAULT_LINE_JOIN = DEFAULT_LINE_JOIN;
2552
+ exports.DEFAULT_LINE_STYLE = DEFAULT_LINE_STYLE;
2553
+ exports.DEFAULT_LINE_WIDTH = DEFAULT_LINE_WIDTH;
2554
+ exports.DEFAULT_OPACITY = DEFAULT_OPACITY;
2555
+ exports.DEFAULT_SYMBOL_COLOR = DEFAULT_SYMBOL_COLOR;
2556
+ exports.DEFAULT_SYMBOL_HALO_COLOR = DEFAULT_SYMBOL_HALO_COLOR;
2557
+ exports.DEFAULT_SYMBOL_PLACEMENT = DEFAULT_SYMBOL_PLACEMENT;
2558
+ exports.DEFAULT_SYMBOL_SPACING = DEFAULT_SYMBOL_SPACING;
2559
+ exports.DEFAULT_SYMBOL_STYLE = DEFAULT_SYMBOL_STYLE;
2560
+ exports.DEFAULT_TEXT_ANCHOR = DEFAULT_TEXT_ANCHOR;
2561
+ exports.DEFAULT_TEXT_JUSTIFY = DEFAULT_TEXT_JUSTIFY;
2562
+ exports.DEFAULT_TEXT_SIZE = DEFAULT_TEXT_SIZE;
2563
+ exports.DEFAULT_TEXT_TRANSFORM = DEFAULT_TEXT_TRANSFORM;
2564
+ exports.DEFAULT_TRANSLATE = DEFAULT_TRANSLATE;
2565
+ exports.FORM_DEFAULT_OPTIONS = FORM_DEFAULT_OPTIONS;
2566
+ exports.MERCATOR_MAX_LATITUDE = MERCATOR_MAX_LATITUDE;
2567
+ exports.MERCATOR_MAX_LONGITUDE = MERCATOR_MAX_LONGITUDE;
2568
+ exports.NO_CONTENT_VALUE = NO_CONTENT_VALUE;
2569
+ exports.SchemaResolver = SchemaResolver;
2570
+ exports.TIME_ZONE_FORMAT = TIME_ZONE_FORMAT;
2571
+ exports.adjustColor = adjustColor;
2572
+ exports.buildDefaultForSchema = buildDefaultForSchema;
2573
+ exports.colorToHex = colorToHex;
2574
+ exports.dateOptions = dateOptions;
2575
+ exports.debounce = debounce;
2576
+ exports.decimalOpacityToHex = decimalOpacityToHex;
2577
+ exports.enrichStyleItemsWithIds = enrichStyleItemsWithIds;
2578
+ exports.enrichStyleModelsWithIds = enrichStyleModelsWithIds;
2579
+ exports.findAttributeInExpression = findAttributeInExpression;
2580
+ exports.formatArea = formatArea;
2581
+ exports.formatAttributeValue = formatAttributeValue;
2582
+ exports.formatDate = formatDate$1;
2583
+ exports.formatLength = formatLength;
2584
+ exports.formatNumber = formatNumber;
2585
+ exports.formatPolygonMeasure = formatPolygonMeasure;
2586
+ exports.geometryToEwkt = geometryToEwkt;
2587
+ exports.getActualExtrusionHeight = getActualExtrusionHeight;
2588
+ exports.getClientStyleItemId = getClientStyleItemId;
2589
+ exports.getDate = getDate;
2590
+ exports.getGradientColors = getGradientColors;
2591
+ exports.getLayerClientStyle = getLayerClientStyle;
2592
+ exports.getMapView = getMapView;
2593
+ exports.getPrimaryType = getPrimaryType;
2594
+ exports.getStyleAttributes = getStyleAttributes;
2595
+ exports.hexToRgba = hexToRgba;
2596
+ exports.isLayerService = isLayerService;
2597
+ exports.isNumeric = isNumeric;
2598
+ exports.isObject = isObject;
2599
+ exports.mergeHiddenFieldDefaults = mergeHiddenFieldDefaults;
2600
+ exports.metersPerPixel = metersPerPixel;
2601
+ exports.numberOptions = numberOptions;
2602
+ exports.orderPropertyKeys = orderPropertyKeys;
2603
+ exports.parseIconNames = parseIconNames;
2604
+ exports.parseIconNamesFromClientStyle = parseIconNamesFromClientStyle;
2605
+ exports.parseMapStyle = parseMapStyle;
2606
+ exports.pointOptions = pointOptions;
2607
+ exports.rgbToHex = rgbToHex;
2608
+ exports.roundTotalSum = roundTotalSum;
2609
+ exports.stretchPalette = stretchPalette;
2610
+ exports.timeOptions = timeOptions;
2611
+ exports.transparentizeColor = transparentizeColor;
2612
+ //# sourceMappingURL=index.js.map