@mapbox/mapbox-gl-style-spec 14.11.0 → 14.12.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.
- package/composite.ts +2 -0
- package/deref.ts +5 -5
- package/diff.ts +65 -31
- package/dist/index.cjs +816 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +224 -16
- package/dist/index.es.js +816 -16
- package/dist/index.es.js.map +1 -1
- package/error/validation_error.ts +1 -3
- package/expression/compound_expression.ts +1 -1
- package/expression/definitions/assertion.ts +2 -1
- package/expression/definitions/at.ts +1 -1
- package/expression/definitions/at_interpolated.ts +1 -1
- package/expression/definitions/case.ts +3 -1
- package/expression/definitions/coalesce.ts +3 -2
- package/expression/definitions/coercion.ts +3 -1
- package/expression/definitions/collator.ts +2 -1
- package/expression/definitions/comparison.ts +15 -1
- package/expression/definitions/config.ts +4 -1
- package/expression/definitions/distance.ts +6 -4
- package/expression/definitions/format.ts +1 -1
- package/expression/definitions/index.ts +24 -2
- package/expression/definitions/index_of.ts +1 -0
- package/expression/definitions/interpolate.ts +7 -3
- package/expression/definitions/let.ts +1 -0
- package/expression/definitions/literal.ts +2 -2
- package/expression/definitions/match.ts +4 -2
- package/expression/definitions/number_format.ts +3 -4
- package/expression/definitions/slice.ts +1 -0
- package/expression/definitions/step.ts +2 -1
- package/expression/definitions/var.ts +1 -0
- package/expression/definitions/within.ts +6 -2
- package/expression/evaluation_context.ts +3 -5
- package/expression/expression.ts +3 -0
- package/expression/index.ts +20 -10
- package/expression/parsing_context.ts +1 -1
- package/expression/types/image_variant.ts +2 -2
- package/expression/types.ts +1 -0
- package/expression/values.ts +1 -3
- package/feature_filter/convert.ts +13 -6
- package/feature_filter/index.ts +17 -1
- package/format.ts +1 -0
- package/function/convert.ts +5 -1
- package/function/index.ts +28 -0
- package/group_by_layout.ts +17 -8
- package/migrate/expressions.ts +3 -3
- package/migrate/v8.ts +10 -1
- package/migrate/v9.ts +2 -1
- package/migrate.ts +2 -1
- package/package.json +1 -1
- package/read_style.ts +1 -0
- package/reference/latest.ts +1 -0
- package/reference/v8.json +425 -8
- package/test.js +2 -4
- package/types.ts +207 -1
- package/union-to-intersection.ts +1 -0
- package/util/extend.ts +2 -1
- package/util/geometry_util.ts +25 -9
- package/util/interpolate.ts +1 -1
- package/validate/validate.ts +6 -0
- package/validate/validate_array.ts +2 -0
- package/validate/validate_enum.ts +1 -0
- package/validate/validate_expression.ts +4 -0
- package/validate/validate_filter.ts +4 -2
- package/validate/validate_fog.ts +4 -1
- package/validate/validate_function.ts +7 -2
- package/validate/validate_glyphs_url.ts +1 -1
- package/validate/validate_iconset.ts +1 -0
- package/validate/validate_layer.ts +3 -2
- package/validate/validate_light.ts +4 -1
- package/validate/validate_lights.ts +7 -1
- package/validate/validate_model.ts +4 -0
- package/validate/validate_object.ts +2 -2
- package/validate/validate_projection.ts +1 -0
- package/validate/validate_property.ts +5 -1
- package/validate/validate_rain.ts +3 -0
- package/validate/validate_snow.ts +3 -0
- package/validate/validate_source.ts +9 -9
- package/validate/validate_terrain.ts +5 -1
- package/validate_mapbox_api_supported.ts +31 -20
- package/validate_style.ts +1 -0
- package/visit.ts +4 -2
package/composite.ts
CHANGED
|
@@ -21,6 +21,7 @@ export default function (style) {
|
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
if (styleIDs.length < 2)
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
24
25
|
return style;
|
|
25
26
|
|
|
26
27
|
styleIDs.forEach((id) => {
|
|
@@ -48,5 +49,6 @@ export default function (style) {
|
|
|
48
49
|
}
|
|
49
50
|
});
|
|
50
51
|
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
|
51
53
|
return style;
|
|
52
54
|
}
|
package/deref.ts
CHANGED
|
@@ -3,7 +3,7 @@ import refProperties from './util/ref_properties';
|
|
|
3
3
|
import type {LayerSpecification} from './types';
|
|
4
4
|
|
|
5
5
|
function deref(layer: LayerSpecification, parent: LayerSpecification): LayerSpecification {
|
|
6
|
-
const result
|
|
6
|
+
const result = {} as LayerSpecification;
|
|
7
7
|
|
|
8
8
|
for (const k in layer) {
|
|
9
9
|
if (k !== 'ref') {
|
|
@@ -13,11 +13,11 @@ function deref(layer: LayerSpecification, parent: LayerSpecification): LayerSpec
|
|
|
13
13
|
|
|
14
14
|
refProperties.forEach((k) => {
|
|
15
15
|
if (k in parent) {
|
|
16
|
-
result[k] =
|
|
16
|
+
result[k] = parent[k];
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
-
return result
|
|
20
|
+
return result;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
/**
|
|
@@ -36,14 +36,14 @@ function deref(layer: LayerSpecification, parent: LayerSpecification): LayerSpec
|
|
|
36
36
|
export default function derefLayers(layers: Array<LayerSpecification>): Array<LayerSpecification> {
|
|
37
37
|
layers = layers.slice();
|
|
38
38
|
|
|
39
|
-
const map:
|
|
39
|
+
const map: Record<string, LayerSpecification> = Object.create(null);
|
|
40
40
|
for (let i = 0; i < layers.length; i++) {
|
|
41
41
|
map[layers[i].id] = layers[i];
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
for (let i = 0; i < layers.length; i++) {
|
|
45
45
|
if ('ref' in layers[i]) {
|
|
46
|
-
layers[i] = deref(layers[i], map[(layers[i] as
|
|
46
|
+
layers[i] = deref(layers[i], map[(layers[i] as LayerSpecification & {ref: string}).ref]);
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
|
package/diff.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import isEqual from './util/deep_equal';
|
|
2
2
|
|
|
3
|
-
import type {StyleSpecification, ImportSpecification, SourceSpecification, LayerSpecification} from './types';
|
|
3
|
+
import type {StyleSpecification, ImportSpecification, SourceSpecification, LayerSpecification, IconsetsSpecification} from './types';
|
|
4
4
|
|
|
5
5
|
type Sources = {
|
|
6
6
|
[key: string]: SourceSpecification;
|
|
@@ -8,12 +8,10 @@ type Sources = {
|
|
|
8
8
|
|
|
9
9
|
type Command = {
|
|
10
10
|
command: string;
|
|
11
|
-
args:
|
|
11
|
+
args: unknown[];
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
export const operations
|
|
15
|
-
[_: string]: string;
|
|
16
|
-
} = {
|
|
14
|
+
export const operations = {
|
|
17
15
|
|
|
18
16
|
/*
|
|
19
17
|
* { command: 'setStyle', args: [stylesheet] }
|
|
@@ -163,8 +161,18 @@ export const operations: {
|
|
|
163
161
|
/**
|
|
164
162
|
* { command: 'updateImport', args: [importId, importSpecification | styleUrl] }
|
|
165
163
|
*/
|
|
166
|
-
updateImport: 'updateImport'
|
|
167
|
-
|
|
164
|
+
updateImport: 'updateImport',
|
|
165
|
+
|
|
166
|
+
/*
|
|
167
|
+
* { command: 'addIconset', args: [iconsetId, IconsetSpecification] }
|
|
168
|
+
*/
|
|
169
|
+
addIconset: 'addIconset',
|
|
170
|
+
|
|
171
|
+
/*
|
|
172
|
+
* { command: 'removeIconset', args: [iconsetId] }
|
|
173
|
+
*/
|
|
174
|
+
removeIconset: 'removeIconset'
|
|
175
|
+
} as const;
|
|
168
176
|
|
|
169
177
|
function addSource(sourceId: string, after: Sources, commands: Array<Command>) {
|
|
170
178
|
commands.push({command: operations.addSource, args: [sourceId, after[sourceId]]});
|
|
@@ -201,9 +209,7 @@ function canUpdateGeoJSON(before: Sources, after: Sources, sourceId: string) {
|
|
|
201
209
|
return true;
|
|
202
210
|
}
|
|
203
211
|
|
|
204
|
-
function diffSources(before: Sources, after: Sources, commands: Array<Command>, sourcesRemoved: {
|
|
205
|
-
[key: string]: true;
|
|
206
|
-
}) {
|
|
212
|
+
function diffSources(before: Sources, after: Sources, commands: Array<Command>, sourcesRemoved: {[key: string]: true}) {
|
|
207
213
|
before = before || {};
|
|
208
214
|
after = after || {};
|
|
209
215
|
|
|
@@ -234,7 +240,16 @@ function diffSources(before: Sources, after: Sources, commands: Array<Command>,
|
|
|
234
240
|
}
|
|
235
241
|
}
|
|
236
242
|
|
|
237
|
-
function diffLayerPropertyChanges(before:
|
|
243
|
+
function diffLayerPropertyChanges(before: LayerSpecification['layout'], after: LayerSpecification['layout'], commands: Array<Command>, layerId: string, klass: string | null | undefined, command: string): void;
|
|
244
|
+
function diffLayerPropertyChanges(before: LayerSpecification['paint'], after: LayerSpecification['paint'], commands: Array<Command>, layerId: string, klass: string | null | undefined, command: string): void;
|
|
245
|
+
function diffLayerPropertyChanges(
|
|
246
|
+
before: LayerSpecification['paint'] | LayerSpecification['layout'],
|
|
247
|
+
after: LayerSpecification['paint'] | LayerSpecification['layout'],
|
|
248
|
+
commands: Command[],
|
|
249
|
+
layerId: string,
|
|
250
|
+
klass: string | null | undefined,
|
|
251
|
+
command: string
|
|
252
|
+
) {
|
|
238
253
|
before = before || {};
|
|
239
254
|
after = after || {};
|
|
240
255
|
|
|
@@ -254,22 +269,11 @@ function diffLayerPropertyChanges(before: any, after: any, commands: Array<Comma
|
|
|
254
269
|
}
|
|
255
270
|
}
|
|
256
271
|
|
|
257
|
-
function pluckId<T extends {
|
|
258
|
-
id: string;
|
|
259
|
-
}>(item: T): string {
|
|
272
|
+
function pluckId<T extends {id: string}>(item: T): string {
|
|
260
273
|
return item.id;
|
|
261
274
|
}
|
|
262
275
|
|
|
263
|
-
function indexById<T extends {
|
|
264
|
-
id: string;
|
|
265
|
-
}>(
|
|
266
|
-
group: {
|
|
267
|
-
[key: string]: T;
|
|
268
|
-
},
|
|
269
|
-
item: T,
|
|
270
|
-
): {
|
|
271
|
-
[id: string]: T;
|
|
272
|
-
} {
|
|
276
|
+
function indexById<T extends {id: string}>(group: {[key: string]: T}, item: T): {[id: string]: T} {
|
|
273
277
|
group[item.id] = item;
|
|
274
278
|
return group;
|
|
275
279
|
}
|
|
@@ -283,14 +287,14 @@ function diffLayers(before: Array<LayerSpecification>, after: Array<LayerSpecifi
|
|
|
283
287
|
const afterOrder = after.map(pluckId);
|
|
284
288
|
|
|
285
289
|
// index of layer by id
|
|
286
|
-
const beforeIndex = before.reduce
|
|
287
|
-
const afterIndex = after.reduce
|
|
290
|
+
const beforeIndex = before.reduce(indexById, {});
|
|
291
|
+
const afterIndex = after.reduce(indexById, {});
|
|
288
292
|
|
|
289
293
|
// track order of layers as if they have been mutated
|
|
290
294
|
const tracker = beforeOrder.slice();
|
|
291
295
|
|
|
292
296
|
// layers that have been added do not need to be diffed
|
|
293
|
-
const clean
|
|
297
|
+
const clean = Object.create(null);
|
|
294
298
|
|
|
295
299
|
let i, d, layerId, beforeLayer: LayerSpecification, afterLayer: LayerSpecification, insertBeforeLayerId, prop;
|
|
296
300
|
|
|
@@ -395,8 +399,8 @@ export function diffImports(before: Array<ImportSpecification> | null | undefine
|
|
|
395
399
|
const afterOrder = after.map(pluckId);
|
|
396
400
|
|
|
397
401
|
// index imports by id
|
|
398
|
-
const beforeIndex = before.reduce
|
|
399
|
-
const afterIndex = after.reduce
|
|
402
|
+
const beforeIndex = before.reduce(indexById, {});
|
|
403
|
+
const afterIndex = after.reduce(indexById, {});
|
|
400
404
|
|
|
401
405
|
// track order of imports as if they have been mutated
|
|
402
406
|
const tracker = beforeOrder.slice();
|
|
@@ -446,6 +450,33 @@ export function diffImports(before: Array<ImportSpecification> | null | undefine
|
|
|
446
450
|
}
|
|
447
451
|
}
|
|
448
452
|
|
|
453
|
+
function diffIconsets(before: IconsetsSpecification, after: IconsetsSpecification, commands: Array<Command>) {
|
|
454
|
+
before = before || {};
|
|
455
|
+
after = after || {};
|
|
456
|
+
|
|
457
|
+
let iconsetId;
|
|
458
|
+
|
|
459
|
+
// look for iconsets to remove
|
|
460
|
+
for (iconsetId in before) {
|
|
461
|
+
if (!before.hasOwnProperty(iconsetId)) continue;
|
|
462
|
+
if (!after.hasOwnProperty(iconsetId)) {
|
|
463
|
+
commands.push({command: operations.removeIconset, args: [iconsetId]});
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// look for iconsets to add/update
|
|
468
|
+
for (iconsetId in after) {
|
|
469
|
+
if (!after.hasOwnProperty(iconsetId)) continue;
|
|
470
|
+
const iconset = after[iconsetId];
|
|
471
|
+
if (!before.hasOwnProperty(iconsetId)) {
|
|
472
|
+
commands.push({command: operations.addIconset, args: [iconsetId, iconset]});
|
|
473
|
+
} else if (!isEqual(before[iconsetId], iconset)) {
|
|
474
|
+
commands.push({command: operations.removeIconset, args: [iconsetId]});
|
|
475
|
+
commands.push({command: operations.addIconset, args: [iconsetId, iconset]});
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
|
|
449
480
|
/**
|
|
450
481
|
* Diff two stylesheet
|
|
451
482
|
*
|
|
@@ -520,6 +551,9 @@ export default function diffStyles(before: StyleSpecification, after: StyleSpeci
|
|
|
520
551
|
if (!isEqual(before.camera, after.camera)) {
|
|
521
552
|
commands.push({command: operations.setCamera, args: [after.camera]});
|
|
522
553
|
}
|
|
554
|
+
if (!isEqual(before.iconsets, after.iconsets)) {
|
|
555
|
+
diffIconsets(before.iconsets, after.iconsets, commands);
|
|
556
|
+
}
|
|
523
557
|
if (!isEqual(before["color-theme"], after["color-theme"])) {
|
|
524
558
|
// Update this to setColorTheme after
|
|
525
559
|
// https://mapbox.atlassian.net/browse/GLJS-842 is implemented
|
|
@@ -529,7 +563,7 @@ export default function diffStyles(before: StyleSpecification, after: StyleSpeci
|
|
|
529
563
|
// Handle changes to `sources`
|
|
530
564
|
// If a source is to be removed, we also--before the removeSource
|
|
531
565
|
// command--need to remove all the style layers that depend on it.
|
|
532
|
-
const sourcesRemoved: Record<string,
|
|
566
|
+
const sourcesRemoved: Record<string, true> = {};
|
|
533
567
|
|
|
534
568
|
// First collect the {add,remove}Source commands
|
|
535
569
|
const removeOrAddSourceCommands = [];
|
|
@@ -570,7 +604,7 @@ export default function diffStyles(before: StyleSpecification, after: StyleSpeci
|
|
|
570
604
|
|
|
571
605
|
// Handle changes to `layers`
|
|
572
606
|
diffLayers(beforeLayers, after.layers, commands);
|
|
573
|
-
} catch (e
|
|
607
|
+
} catch (e) {
|
|
574
608
|
// fall back to setStyle
|
|
575
609
|
console.warn('Unable to compute style diff:', e);
|
|
576
610
|
commands = [{command: operations.setStyle, args: [after]}];
|