@mapbox/mapbox-gl-style-spec 14.36.0 → 14.37.0-rc.1

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.
@@ -9,8 +9,9 @@ import type {Type} from '../types';
9
9
  import type {Expression, SerializedExpression} from '../expression';
10
10
  import type ParsingContext from '../parsing_context';
11
11
  import type EvaluationContext from '../evaluation_context';
12
+ import type {ConfigOptions} from '../../types/config_options';
12
13
 
13
- const FQIDSeparator = '\u001F';
14
+ export const FQIDSeparator = '\u001F';
14
15
 
15
16
  export function makeConfigFQID(id: string, ownScope?: string | null, contextScope?: string | null): string {
16
17
  let fqid = id || '';
@@ -19,6 +20,32 @@ export function makeConfigFQID(id: string, ownScope?: string | null, contextScop
19
20
  return fqid;
20
21
  }
21
22
 
23
+ /** The scope that configures `scope`: everything after its own id. */
24
+ export function getConfigParentScope(scope: string): string {
25
+ const separator = scope.indexOf(FQIDSeparator);
26
+ return separator >= 0 ? scope.slice(separator + 1) : '';
27
+ }
28
+
29
+ // `GlobalDependency` flags of the config option `fqid`, following the `config` references in its default (resolved in
30
+ // `scope`) and in its value (resolved in the parent scope), as `evaluate` does; `visited` guards against cycles
31
+ export function getConfigGlobalDependencies(options: ConfigOptions, fqid: string, scope: string, visited: Set<string> = new Set()): number {
32
+ const config = options.get(fqid);
33
+ if (!config || visited.has(fqid)) return 0;
34
+ visited.add(fqid);
35
+
36
+ const getDeps = (e: Expression, s: string) => {
37
+ let flags = isConstant.getGlobalDependencies(e);
38
+ const visit = (node: Expression) => {
39
+ if (node instanceof Config) flags |= getConfigGlobalDependencies(options, makeConfigFQID(node.key, node.scope, s), s, visited);
40
+ node.eachChild(visit);
41
+ };
42
+ visit(e);
43
+ return flags;
44
+ };
45
+
46
+ return getDeps(config.default, scope) | (config.value ? getDeps(config.value, getConfigParentScope(scope)) : 0);
47
+ }
48
+
22
49
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
50
  function coerceValue(type: string, value: any): any {
24
51
  switch (type) {
@@ -58,12 +85,14 @@ class Config implements Expression {
58
85
  key: string;
59
86
  scope: string | null | undefined;
60
87
  featureConstant: boolean;
88
+ globalDependencies: number;
61
89
 
62
- constructor(type: Type, key: string, scope?: string, featureConstant: boolean = false) {
90
+ constructor(type: Type, key: string, scope?: string, featureConstant: boolean = false, globalDependencies: number = 0) {
63
91
  this.type = type;
64
92
  this.key = key;
65
93
  this.scope = scope;
66
94
  this.featureConstant = featureConstant;
95
+ this.globalDependencies = globalDependencies;
67
96
  }
68
97
 
69
98
  static parse(args: ReadonlyArray<unknown>, context: ParsingContext): Config | null | void {
@@ -79,6 +108,7 @@ class Config implements Expression {
79
108
  }
80
109
 
81
110
  let featureConstant = true;
111
+ let globalDependencies = 0;
82
112
  let configScopeValue: string | undefined;
83
113
  const configKeyValue = valueToString(configKey.value);
84
114
 
@@ -96,10 +126,17 @@ class Config implements Expression {
96
126
  const config = context.options.get(fqid);
97
127
  if (config) {
98
128
  featureConstant = isConstant.isFeatureConstant(config.value || config.default);
129
+ // `evaluate` runs both the default and the value, so a light or zoom input in either, or in an option they
130
+ // reference (e.g. one forwarded from a parent style), makes the result depend on it; reported as
131
+ // `ConfigLight` / `ConfigZoom` so properties still parse as before
132
+ const {Light, Zoom, ConfigLight, ConfigZoom} = isConstant.GlobalDependency;
133
+ const deps = getConfigGlobalDependencies(context.options, fqid, context._scope || '');
134
+ if (deps & (Light | ConfigLight)) globalDependencies |= ConfigLight;
135
+ if (deps & (Zoom | ConfigZoom)) globalDependencies |= ConfigZoom;
99
136
  }
100
137
  }
101
138
 
102
- return new Config(type, configKeyValue, configScopeValue, featureConstant);
139
+ return new Config(type, configKeyValue, configScopeValue, featureConstant, globalDependencies);
103
140
  }
104
141
 
105
142
  evaluate(ctx: EvaluationContext): unknown {
@@ -117,9 +154,7 @@ class Config implements Expression {
117
154
  if (value) {
118
155
  // temporarily override scope to parent to evaluate config expressions passed from the parent
119
156
  const originalScope = ctx.scope;
120
- const scope = originalScope || '';
121
- const sep = scope.indexOf(FQIDSeparator);
122
- ctx.scope = sep >= 0 ? scope.slice(sep + 1) : '';
157
+ ctx.scope = getConfigParentScope(originalScope || '');
123
158
  // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
124
159
  result = value.evaluate(ctx);
125
160
  ctx.scope = originalScope;
@@ -13,6 +13,11 @@ export interface Expression {
13
13
  * (e.g. `within`, `distance`, `config`); `isFeatureConstant` returns it without recursing.
14
14
  */
15
15
  readonly featureConstant?: boolean;
16
+ /**
17
+ * Set by expressions whose global dependencies can't be derived from their children (e.g. `config`);
18
+ * a `GlobalDependency` bitmask that `getGlobalDependencies` uses in place of the expression's own flags.
19
+ */
20
+ readonly globalDependencies?: number;
16
21
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
17
22
  evaluate: (ctx: EvaluationContext) => any;
18
23
  eachChild: (fn: (arg1: Expression) => void) => void;
@@ -230,12 +230,17 @@ export class ZoomConstantExpression<Kind extends EvaluationKind> {
230
230
  _styleExpression: StyleExpression;
231
231
  isLightConstant: boolean | null | undefined;
232
232
  isLineProgressConstant: boolean | null | undefined;
233
+ // Depends on zoom or pitch through a `config` value, which needs re-evaluation on camera changes. Only set for
234
+ // feature-constant values: data-driven ones are evaluated per feature at the tile's zoom, like any `zoom` outside
235
+ // a top-level curve, since refreshing their paint arrays on every camera change would be too costly.
236
+ isConfigZoomDependent: boolean;
233
237
 
234
- constructor(kind: Kind, expression: StyleExpression, isLightConstant?: boolean | null, isLineProgressConstant?: boolean | null) {
238
+ constructor(kind: Kind, expression: StyleExpression, isLightConstant?: boolean | null, isLineProgressConstant?: boolean | null, isConfigZoomDependent: boolean = false) {
235
239
  this.kind = kind;
236
240
  this._styleExpression = expression;
237
241
  this.isLightConstant = isLightConstant;
238
242
  this.isLineProgressConstant = isLineProgressConstant;
243
+ this.isConfigZoomDependent = isConfigZoomDependent;
239
244
  this.isStateDependent = kind !== ('constant' as EvaluationKind) && !isConstant.isStateConstant(expression.expression);
240
245
  // Already walked by the wrapped `StyleExpression` over the same parsed expression
241
246
  this.configDependencies = expression.configDependencies;
@@ -328,6 +333,7 @@ export class ZoomDependentExpression<Kind extends EvaluationKind> {
328
333
 
329
334
  export type ConstantExpression = {
330
335
  kind: 'constant';
336
+ isConfigZoomDependent?: boolean;
331
337
  configDependencies: Set<string>;
332
338
  isIndoorDependent: boolean;
333
339
  readonly evaluate: <T = unknown>(
@@ -424,10 +430,10 @@ export function createPropertyExpression(
424
430
  return error([new ParsingError('', 'zoom expressions not supported')]);
425
431
  }
426
432
 
427
- const isLightConstant = (globalDependencies & isConstant.GlobalDependency.Light) === 0;
428
- if (!isLightConstant && !supportsLightExpression(propertySpec)) {
433
+ if ((globalDependencies & isConstant.GlobalDependency.Light) && !supportsLightExpression(propertySpec)) {
429
434
  return error([new ParsingError('', 'measure-light expression not supported')]);
430
435
  }
436
+ const isLightConstant = (globalDependencies & (isConstant.GlobalDependency.Light | isConstant.GlobalDependency.ConfigLight)) === 0;
431
437
 
432
438
  const isLineProgressConstant = (globalDependencies & isConstant.GlobalDependency.LineProgress) === 0;
433
439
  if (!isLineProgressConstant && !supportsLineProgressExpression(propertySpec)) {
@@ -445,8 +451,9 @@ export function createPropertyExpression(
445
451
  }
446
452
 
447
453
  if (!zoomCurve) {
454
+ const isConfigZoomDependent = (globalDependencies & isConstant.GlobalDependency.ConfigZoom) !== 0;
448
455
  return success((isFeatureConstant && isLineProgressConstant) ?
449
- (new ZoomConstantExpression('constant', styleExpression.value, isLightConstant, isLineProgressConstant) as ConstantExpression) :
456
+ (new ZoomConstantExpression('constant', styleExpression.value, isLightConstant, isLineProgressConstant, isConfigZoomDependent) as ConstantExpression) :
450
457
  (new ZoomConstantExpression('source', styleExpression.value, isLightConstant, isLineProgressConstant) as SourceExpression));
451
458
  }
452
459
 
@@ -61,7 +61,10 @@ function isGlobalPropertyConstant(e: Expression, properties: Array<string>): boo
61
61
  // Bitmask so that one walk answers all three: `createPropertyExpression` used to call
62
62
  // `isGlobalPropertyConstant` once per group, traversing every expression of every property in
63
63
  // full each time, since those calls only exit early on the rare dependent branch.
64
- export const GlobalDependency = {Zoom: 1, Light: 2, LineProgress: 4};
64
+ // `ConfigLight` and `ConfigZoom` are a `measure-light` and a zoom/pitch/distance-from-center reached through a `config`
65
+ // value: they make the result depend on that input for re-evaluation, but unlike `Light` and `Zoom` they aren't subject
66
+ // to the property's support checks, and `ConfigZoom` doesn't require a top-level zoom curve.
67
+ export const GlobalDependency = {Zoom: 1, Light: 2, LineProgress: 4, ConfigLight: 8, ConfigZoom: 16};
65
68
 
66
69
  const globalDependencyFlags: Record<string, number> = {
67
70
  'zoom': GlobalDependency.Zoom,
@@ -72,7 +75,8 @@ const globalDependencyFlags: Record<string, number> = {
72
75
  };
73
76
 
74
77
  function getGlobalDependencies(e: Expression): number {
75
- let flags = e instanceof CompoundExpression ? globalDependencyFlags[e.name] || 0 : 0;
78
+ let flags = e.globalDependencies !== undefined ? e.globalDependencies :
79
+ e instanceof CompoundExpression ? globalDependencyFlags[e.name] || 0 : 0;
76
80
  e.eachChild(arg => { flags |= getGlobalDependencies(arg); });
77
81
  return flags;
78
82
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapbox/mapbox-gl-style-spec",
3
- "version": "14.36.0",
3
+ "version": "14.37.0-rc.1",
4
4
  "description": "a specification for mapbox gl styles",
5
5
  "author": "Mapbox",
6
6
  "license": "SEE LICENSE IN LICENSE.txt",
package/reference/v8.json CHANGED
@@ -6935,7 +6935,9 @@
6935
6935
  ],
6936
6936
  "sdk-support": {
6937
6937
  "basic functionality": {
6938
- "js": "2.6.0"
6938
+ "js": "2.6.0",
6939
+ "android": "11.37.0",
6940
+ "ios": "11.37.0"
6939
6941
  }
6940
6942
  }
6941
6943
  },
@@ -6962,7 +6964,9 @@
6962
6964
  ],
6963
6965
  "sdk-support": {
6964
6966
  "basic functionality": {
6965
- "js": "2.6.0"
6967
+ "js": "2.6.0",
6968
+ "android": "11.37.0",
6969
+ "ios": "11.37.0"
6966
6970
  }
6967
6971
  }
6968
6972
  }
@@ -0,0 +1,8 @@
1
+ declare module 'csscolorparser' {
2
+ /**
3
+ * Parse CSS color string and return RGBA values
4
+ * @param input - CSS color string (e.g., "#ff0000", "rgba(255,0,0,1)", "red")
5
+ * @returns Array of [r, g, b, a] where r,g,b are 0-255 and a is 0-1, or null if invalid
6
+ */
7
+ export function parseCSSColor(input: string): [number, number, number, number] | null;
8
+ }
package/util/color.ts CHANGED
@@ -1,3 +1,5 @@
1
+ // eslint-disable-next-line @typescript-eslint/triple-slash-reference
2
+ /// <reference path="../types/csscolorparser.d.ts" />
1
3
  import {parseCSSColor} from 'csscolorparser';
2
4
  import {lerp} from './lerp';
3
5
 
@@ -52,7 +52,7 @@ export default function validateImport(options: ImportValidatorOptions): Validat
52
52
 
53
53
  if (data) {
54
54
  const key = `${options.key}.data`;
55
- errors = errors.concat(validateStyle(data, styleSpec, {key}));
55
+ errors = errors.concat(validateStyle(data, styleSpec, {key, fragment: true}));
56
56
  }
57
57
 
58
58
  return errors;
@@ -4,6 +4,7 @@ import {unbundle} from '../util/unbundle_jsonlint';
4
4
  import {isObject} from '../util/get_type';
5
5
 
6
6
  import type ValidationError from '../error/validation_error';
7
+ import type {StylePropertySpecification} from '../style-spec';
7
8
  import type {ValidatorOptions} from './validate';
8
9
  import type {ObjectElementValidator} from './validate_object';
9
10
 
@@ -13,6 +14,7 @@ import type {ObjectElementValidator} from './validate_object';
13
14
  // the option's expected type instead of `*` (any).
14
15
  export default function validateOption(options: ValidatorOptions): ValidationError[] {
15
16
  const styleSpec = options.styleSpec;
17
+ const optionSpec = styleSpec.option as Record<string, Partial<StylePropertySpecification>>;
16
18
  const optionValue = options.value as {type?: unknown; array?: unknown} | null | undefined;
17
19
  // Don't propagate the declared type for array options: `getExpectedType`
18
20
  // doesn't model the schema's `array: true` flag, so forcing a scalar type
@@ -42,10 +44,9 @@ export default function validateOption(options: ValidatorOptions): ValidationErr
42
44
 
43
45
  return validateObject({
44
46
  ...options,
45
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
46
- valueSpec: styleSpec.option,
47
+ valueSpec: optionSpec,
47
48
  objectElementValidators: {
48
- default: validateDefault,
49
+ default: validateDefault
49
50
  } as Record<string, ObjectElementValidator>,
50
51
  });
51
52
  }
@@ -97,7 +97,7 @@ export default function validateProperty(options: PropertyValidatorOptions, prop
97
97
  const errors: ValidationError[] = [];
98
98
 
99
99
  if (options.layerType === 'symbol') {
100
- if (propertyKey === 'text-field' && style && !style.glyphs && !style.imports) {
100
+ if (propertyKey === 'text-field' && style && !style.glyphs && !style.imports && !style.fragment) {
101
101
  errors.push(new ValidationError(key, value, 'use of "text-field" requires a style "glyphs" property'));
102
102
  }
103
103
  if (propertyKey === 'text-font' && isFunction(deepUnbundle(value)) && unbundle((value as {type: unknown}).type) === 'identity') {
@@ -8,9 +8,12 @@ import type {StyleSpecification} from '../types';
8
8
 
9
9
  type StyleValidatorOptions = {
10
10
  key?: string;
11
+ /** Validate as a fragment, which may omit the properties its parent defines. */
12
+ fragment?: boolean;
11
13
  };
12
14
 
13
15
  export default function validateStyle(style: unknown, styleSpec: StyleReference = latestStyleSpec, options: StyleValidatorOptions = {}): ValidationError[] {
16
+ const root = style as Partial<StyleSpecification>;
14
17
  const errors = validateObject({
15
18
  key: options.key || '',
16
19
  value: style,
@@ -21,7 +24,7 @@ export default function validateStyle(style: unknown, styleSpec: StyleReference
21
24
  '*': {type: '*'},
22
25
  },
23
26
  styleSpec,
24
- style: style as Partial<StyleSpecification>,
27
+ style: options.fragment ? {...root, fragment: true} : root,
25
28
  objectElementValidators: {
26
29
  glyphs: validateGlyphsURL
27
30
  }