@mapbox/mapbox-gl-style-spec 14.28.0 → 14.29.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 +5 -5
- package/diff.ts +38 -40
- package/dist/index.cjs +362 -238
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +101 -13
- package/dist/index.es.js +362 -238
- package/dist/index.es.js.map +1 -1
- package/expression/compound_expression.ts +6 -6
- package/expression/definitions/assertion.ts +9 -12
- package/expression/definitions/at.ts +1 -1
- package/expression/definitions/at_interpolated.ts +1 -1
- package/expression/definitions/case.ts +1 -2
- package/expression/definitions/coalesce.ts +1 -1
- package/expression/definitions/coercion.ts +10 -12
- package/expression/definitions/collator.ts +8 -8
- package/expression/definitions/comparison.ts +0 -1
- package/expression/definitions/distance.ts +135 -73
- package/expression/definitions/format.ts +10 -13
- package/expression/definitions/image.ts +8 -8
- package/expression/definitions/index.ts +92 -90
- package/expression/definitions/interpolate.ts +18 -19
- package/expression/definitions/let.ts +1 -2
- package/expression/definitions/literal.ts +1 -1
- package/expression/definitions/match.ts +7 -8
- package/expression/definitions/number_format.ts +7 -8
- package/expression/definitions/step.ts +11 -11
- package/expression/definitions/within.ts +23 -24
- package/expression/evaluation_context.ts +4 -4
- package/expression/expression.ts +1 -1
- package/expression/index.ts +43 -21
- package/expression/parsing_context.ts +2 -2
- package/expression/stops.ts +2 -2
- package/expression/values.ts +2 -2
- package/feature_filter/index.ts +3 -3
- package/function/convert.ts +8 -8
- package/function/index.ts +4 -2
- package/group_by_layout.ts +6 -4
- package/package.json +1 -1
- package/read_style.ts +2 -2
- package/reference/v8.json +86 -5
- package/types/config_options.ts +1 -1
- package/types.ts +16 -6
- package/util/properties.ts +1 -1
- package/validate/validate.ts +15 -5
- package/validate/validate_appearance.ts +7 -7
- package/validate/validate_array.ts +7 -7
- package/validate/validate_enum.ts +2 -3
- package/validate/validate_fog.ts +2 -2
- package/validate/validate_function.ts +14 -13
- package/validate/validate_layer.ts +10 -9
- package/validate/validate_light.ts +2 -2
- package/validate/validate_lights.ts +3 -3
- package/validate/validate_number.ts +10 -7
- package/validate/validate_object.ts +11 -10
- package/validate/validate_option.ts +24 -9
- package/validate/validate_property.ts +4 -4
- package/validate/validate_rain.ts +1 -1
- package/validate/validate_snow.ts +1 -1
- package/validate/validate_style.ts +2 -1
- package/validate/validate_terrain.ts +2 -2
- package/validate_mapbox_api_supported.ts +5 -6
- package/validate_style.min.ts +2 -1
- package/visit.ts +11 -10
package/composite.ts
CHANGED
|
@@ -5,20 +5,20 @@ const MAPBOX_URL_RE = /^mapbox:\/\/(.*)/;
|
|
|
5
5
|
export default function (style: StyleSpecification): StyleSpecification {
|
|
6
6
|
const styleIDs: string[] = [];
|
|
7
7
|
const sourceIDs: string[] = [];
|
|
8
|
-
const compositedSourceLayers: string
|
|
8
|
+
const compositedSourceLayers: Array<string | undefined> = [];
|
|
9
9
|
|
|
10
10
|
for (const id in style.sources) {
|
|
11
|
-
const source = style.sources[id]
|
|
11
|
+
const source = style.sources[id]!;
|
|
12
12
|
|
|
13
13
|
if (source.type !== "vector")
|
|
14
14
|
continue;
|
|
15
15
|
|
|
16
|
-
const match = MAPBOX_URL_RE.exec(source.url);
|
|
16
|
+
const match = MAPBOX_URL_RE.exec(source.url!);
|
|
17
17
|
if (!match)
|
|
18
18
|
continue;
|
|
19
19
|
|
|
20
20
|
styleIDs.push(id);
|
|
21
|
-
sourceIDs.push(match[1]);
|
|
21
|
+
sourceIDs.push(match[1]!);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
if (styleIDs.length < 2)
|
|
@@ -36,7 +36,7 @@ export default function (style: StyleSpecification): StyleSpecification {
|
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
style.layers.forEach((layer) => {
|
|
39
|
-
if (styleIDs.includes(layer.source)) {
|
|
39
|
+
if (styleIDs.includes(layer.source!)) {
|
|
40
40
|
layer.source = compositeID;
|
|
41
41
|
|
|
42
42
|
if ('source-layer' in layer) {
|
package/diff.ts
CHANGED
|
@@ -2,10 +2,18 @@ import isEqual from './util/deep_equal';
|
|
|
2
2
|
|
|
3
3
|
import type {StyleSpecification, ImportSpecification, SourceSpecification, LayerSpecification, IconsetsSpecification} from './types';
|
|
4
4
|
|
|
5
|
+
type Source = SourceSpecification & Record<string, unknown>;
|
|
6
|
+
|
|
5
7
|
type Sources = {
|
|
6
|
-
[key: string]:
|
|
8
|
+
[key: string]: Source;
|
|
7
9
|
};
|
|
8
10
|
|
|
11
|
+
type LayerProperties = (LayerSpecification['paint'] | LayerSpecification['layout']) & Record<string, unknown>;
|
|
12
|
+
|
|
13
|
+
type Indexed<T> = T extends LayerSpecification ? T & Record<string, LayerSpecification['paint']> : T;
|
|
14
|
+
|
|
15
|
+
type DiffLayer = Indexed<LayerSpecification>;
|
|
16
|
+
|
|
9
17
|
type Command = {
|
|
10
18
|
command: string;
|
|
11
19
|
args: unknown[];
|
|
@@ -194,15 +202,15 @@ function updateSource(sourceId: string, after: Sources, commands: Array<Command>
|
|
|
194
202
|
|
|
195
203
|
function canUpdateGeoJSON(before: Sources, after: Sources, sourceId: string) {
|
|
196
204
|
let prop: string;
|
|
197
|
-
for (prop in before[sourceId]) {
|
|
198
|
-
if (!Object.hasOwn(before[sourceId]
|
|
199
|
-
if (prop !== 'data' && !isEqual(before[sourceId][prop], after[sourceId][prop])) {
|
|
205
|
+
for (prop in before[sourceId]!) {
|
|
206
|
+
if (!Object.hasOwn(before[sourceId]!, prop)) continue;
|
|
207
|
+
if (prop !== 'data' && !isEqual(before[sourceId]![prop], after[sourceId]![prop])) {
|
|
200
208
|
return false;
|
|
201
209
|
}
|
|
202
210
|
}
|
|
203
|
-
for (prop in after[sourceId]) {
|
|
204
|
-
if (!Object.hasOwn(after[sourceId]
|
|
205
|
-
if (prop !== 'data' && !isEqual(before[sourceId][prop], after[sourceId][prop])) {
|
|
211
|
+
for (prop in after[sourceId]!) {
|
|
212
|
+
if (!Object.hasOwn(after[sourceId]!, prop)) continue;
|
|
213
|
+
if (prop !== 'data' && !isEqual(before[sourceId]![prop], after[sourceId]![prop])) {
|
|
206
214
|
return false;
|
|
207
215
|
}
|
|
208
216
|
}
|
|
@@ -226,11 +234,11 @@ function diffSources(before: Sources, after: Sources, commands: Array<Command>,
|
|
|
226
234
|
// look for sources to add/update
|
|
227
235
|
for (sourceId in after) {
|
|
228
236
|
if (!Object.hasOwn(after, sourceId)) continue;
|
|
229
|
-
const source = after[sourceId]
|
|
237
|
+
const source = after[sourceId]!;
|
|
230
238
|
if (!Object.hasOwn(before, sourceId)) {
|
|
231
239
|
addSource(sourceId, after, commands);
|
|
232
240
|
} else if (!isEqual(before[sourceId], source)) {
|
|
233
|
-
if (before[sourceId]
|
|
241
|
+
if (before[sourceId]!.type === 'geojson' && source.type === 'geojson' && canUpdateGeoJSON(before, after, sourceId)) {
|
|
234
242
|
commands.push({command: operations.setGeoJSONSourceData, args: [sourceId, source.data]});
|
|
235
243
|
} else {
|
|
236
244
|
// no update command, must remove then add
|
|
@@ -240,11 +248,9 @@ function diffSources(before: Sources, after: Sources, commands: Array<Command>,
|
|
|
240
248
|
}
|
|
241
249
|
}
|
|
242
250
|
|
|
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
251
|
function diffLayerPropertyChanges(
|
|
246
|
-
before:
|
|
247
|
-
after:
|
|
252
|
+
before: LayerProperties | null | undefined,
|
|
253
|
+
after: LayerProperties | null | undefined,
|
|
248
254
|
commands: Command[],
|
|
249
255
|
layerId: string,
|
|
250
256
|
klass: string | null | undefined,
|
|
@@ -273,8 +279,8 @@ function pluckId<T extends {id: string}>(item: T): string {
|
|
|
273
279
|
return item.id;
|
|
274
280
|
}
|
|
275
281
|
|
|
276
|
-
function indexById<T extends {id: string}>(group: {[key: string]: T}, item: T): {[id: string]: T} {
|
|
277
|
-
group[item.id] = item
|
|
282
|
+
function indexById<T extends {id: string}>(group: {[key: string]: Indexed<T>}, item: T): {[id: string]: Indexed<T>} {
|
|
283
|
+
group[item.id] = item as Indexed<T>;
|
|
278
284
|
return group;
|
|
279
285
|
}
|
|
280
286
|
|
|
@@ -287,27 +293,27 @@ function diffLayers(before: Array<LayerSpecification>, after: Array<LayerSpecifi
|
|
|
287
293
|
const afterOrder = after.map(pluckId);
|
|
288
294
|
|
|
289
295
|
// index of layer by id
|
|
290
|
-
const beforeIndex = before.reduce(indexById, {});
|
|
291
|
-
const afterIndex = after.reduce(indexById, {});
|
|
296
|
+
const beforeIndex = before.reduce<Record<string, DiffLayer>>(indexById, {});
|
|
297
|
+
const afterIndex = after.reduce<Record<string, DiffLayer>>(indexById, {});
|
|
292
298
|
|
|
293
299
|
// track order of layers as if they have been mutated
|
|
294
300
|
const tracker = beforeOrder.slice();
|
|
295
301
|
|
|
296
302
|
// layers that have been added do not need to be diffed
|
|
297
303
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
298
|
-
const clean = Object.create(null);
|
|
304
|
+
const clean: Record<string, true> = Object.create(null);
|
|
299
305
|
|
|
300
306
|
let i: number;
|
|
301
307
|
let d: number;
|
|
302
308
|
let layerId: string;
|
|
303
|
-
let beforeLayer:
|
|
304
|
-
let afterLayer:
|
|
305
|
-
let insertBeforeLayerId: string;
|
|
309
|
+
let beforeLayer: DiffLayer;
|
|
310
|
+
let afterLayer: DiffLayer;
|
|
311
|
+
let insertBeforeLayerId: string | undefined;
|
|
306
312
|
let prop: string;
|
|
307
313
|
|
|
308
314
|
// remove layers
|
|
309
315
|
for (i = 0, d = 0; i < beforeOrder.length; i++) {
|
|
310
|
-
layerId = beforeOrder[i]
|
|
316
|
+
layerId = beforeOrder[i]!;
|
|
311
317
|
if (!Object.hasOwn(afterIndex, layerId)) {
|
|
312
318
|
commands.push({command: operations.removeLayer, args: [layerId]});
|
|
313
319
|
tracker.splice(tracker.indexOf(layerId, d), 1);
|
|
@@ -320,7 +326,7 @@ function diffLayers(before: Array<LayerSpecification>, after: Array<LayerSpecifi
|
|
|
320
326
|
// add/reorder layers
|
|
321
327
|
for (i = 0, d = 0; i < afterOrder.length; i++) {
|
|
322
328
|
// work backwards as insert is before an existing layer
|
|
323
|
-
layerId = afterOrder[afterOrder.length - 1 - i]
|
|
329
|
+
layerId = afterOrder[afterOrder.length - 1 - i]!;
|
|
324
330
|
|
|
325
331
|
if (tracker[tracker.length - 1 - i] === layerId) continue;
|
|
326
332
|
|
|
@@ -337,20 +343,16 @@ function diffLayers(before: Array<LayerSpecification>, after: Array<LayerSpecifi
|
|
|
337
343
|
insertBeforeLayerId = tracker[tracker.length - i];
|
|
338
344
|
commands.push({command: operations.addLayer, args: [afterIndex[layerId], insertBeforeLayerId]});
|
|
339
345
|
tracker.splice(tracker.length - i, 0, layerId);
|
|
340
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
341
346
|
clean[layerId] = true;
|
|
342
347
|
}
|
|
343
348
|
|
|
344
349
|
// update layers
|
|
345
350
|
for (i = 0; i < afterOrder.length; i++) {
|
|
346
|
-
layerId = afterOrder[i]
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
350
|
-
afterLayer = afterIndex[layerId];
|
|
351
|
+
layerId = afterOrder[i]!;
|
|
352
|
+
beforeLayer = beforeIndex[layerId]!;
|
|
353
|
+
afterLayer = afterIndex[layerId]!;
|
|
351
354
|
|
|
352
355
|
// no need to update if previously added (new or moved)
|
|
353
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
354
356
|
if (clean[layerId] || isEqual(beforeLayer, afterLayer)) continue;
|
|
355
357
|
|
|
356
358
|
// If source, source-layer, or type have changes, then remove the layer
|
|
@@ -383,7 +385,6 @@ function diffLayers(before: Array<LayerSpecification>, after: Array<LayerSpecifi
|
|
|
383
385
|
if (prop === 'layout' || prop === 'paint' || prop === 'filter' ||
|
|
384
386
|
prop === 'metadata' || prop === 'minzoom' || prop === 'maxzoom' || prop === 'slot') continue;
|
|
385
387
|
if (prop.indexOf('paint.') === 0) {
|
|
386
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
387
388
|
diffLayerPropertyChanges(beforeLayer[prop], afterLayer[prop], commands, layerId, prop.slice(6), operations.setPaintProperty);
|
|
388
389
|
} else if (!isEqual(beforeLayer[prop], afterLayer[prop])) {
|
|
389
390
|
commands.push({command: operations.setLayerProperty, args: [layerId, prop, afterLayer[prop]]});
|
|
@@ -394,7 +395,6 @@ function diffLayers(before: Array<LayerSpecification>, after: Array<LayerSpecifi
|
|
|
394
395
|
if (prop === 'layout' || prop === 'paint' || prop === 'filter' ||
|
|
395
396
|
prop === 'metadata' || prop === 'minzoom' || prop === 'maxzoom' || prop === 'slot') continue;
|
|
396
397
|
if (prop.indexOf('paint.') === 0) {
|
|
397
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
398
398
|
diffLayerPropertyChanges(beforeLayer[prop], afterLayer[prop], commands, layerId, prop.slice(6), operations.setPaintProperty);
|
|
399
399
|
} else if (!isEqual(beforeLayer[prop], afterLayer[prop])) {
|
|
400
400
|
commands.push({command: operations.setLayerProperty, args: [layerId, prop, afterLayer[prop]]});
|
|
@@ -412,8 +412,8 @@ export function diffImports(before: Array<ImportSpecification> | null | undefine
|
|
|
412
412
|
const afterOrder = after.map(pluckId);
|
|
413
413
|
|
|
414
414
|
// index imports by id
|
|
415
|
-
const beforeIndex = before.reduce(indexById, {});
|
|
416
|
-
const afterIndex = after.reduce(indexById, {});
|
|
415
|
+
const beforeIndex = before.reduce<Record<string, ImportSpecification>>(indexById, {});
|
|
416
|
+
const afterIndex = after.reduce<Record<string, ImportSpecification>>(indexById, {});
|
|
417
417
|
|
|
418
418
|
// track order of imports as if they have been mutated
|
|
419
419
|
const tracker = beforeOrder.slice();
|
|
@@ -421,11 +421,11 @@ export function diffImports(before: Array<ImportSpecification> | null | undefine
|
|
|
421
421
|
let i: number;
|
|
422
422
|
let d: number;
|
|
423
423
|
let importId: string;
|
|
424
|
-
let insertBefore: string;
|
|
424
|
+
let insertBefore: string | undefined;
|
|
425
425
|
|
|
426
426
|
// remove imports
|
|
427
427
|
for (i = 0, d = 0; i < beforeOrder.length; i++) {
|
|
428
|
-
importId = beforeOrder[i]
|
|
428
|
+
importId = beforeOrder[i]!;
|
|
429
429
|
if (!Object.hasOwn(afterIndex, importId)) {
|
|
430
430
|
commands.push({command: operations.removeImport, args: [importId]});
|
|
431
431
|
tracker.splice(tracker.indexOf(importId, d), 1);
|
|
@@ -438,7 +438,7 @@ export function diffImports(before: Array<ImportSpecification> | null | undefine
|
|
|
438
438
|
// add/reorder imports
|
|
439
439
|
for (i = 0, d = 0; i < afterOrder.length; i++) {
|
|
440
440
|
// work backwards as insert is before an existing import
|
|
441
|
-
importId = afterOrder[afterOrder.length - 1 - i]
|
|
441
|
+
importId = afterOrder[afterOrder.length - 1 - i]!;
|
|
442
442
|
|
|
443
443
|
if (tracker[tracker.length - 1 - i] === importId) continue;
|
|
444
444
|
|
|
@@ -459,10 +459,8 @@ export function diffImports(before: Array<ImportSpecification> | null | undefine
|
|
|
459
459
|
|
|
460
460
|
// update imports
|
|
461
461
|
for (const afterImport of after) {
|
|
462
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
463
462
|
const beforeImport = beforeIndex[afterImport.id];
|
|
464
463
|
if (!beforeImport) continue;
|
|
465
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
466
464
|
delete beforeImport.data;
|
|
467
465
|
if (isEqual(beforeImport, afterImport)) continue;
|
|
468
466
|
|
|
@@ -470,7 +468,7 @@ export function diffImports(before: Array<ImportSpecification> | null | undefine
|
|
|
470
468
|
}
|
|
471
469
|
}
|
|
472
470
|
|
|
473
|
-
function diffIconsets(before: IconsetsSpecification, after: IconsetsSpecification, commands: Array<Command>) {
|
|
471
|
+
function diffIconsets(before: IconsetsSpecification | undefined, after: IconsetsSpecification | undefined, commands: Array<Command>) {
|
|
474
472
|
before = before || {};
|
|
475
473
|
after = after || {};
|
|
476
474
|
|