@mapbox/mapbox-gl-style-spec
Advanced tools
Comparing version 14.1.0 to 14.2.0-beta.1
@@ -0,1 +1,2 @@ | ||
// @noflow | ||
@@ -2,0 +3,0 @@ export default function (style) { |
@@ -85,3 +85,3 @@ // @flow | ||
// we eventually succeed, we haven't polluted `context.errors`. | ||
signatureContext = new ParsingContext(context.registry, context.path, null, context.scope, undefined, context.options); | ||
signatureContext = new ParsingContext(context.registry, context.path, null, context.scope, undefined, context._scope, context.options); | ||
@@ -88,0 +88,0 @@ // First parse all the args, potentially coercing to the |
@@ -49,2 +49,3 @@ // @flow | ||
import Distance from './distance.js'; | ||
import {mulberry32} from '../../util/random.js'; | ||
@@ -54,3 +55,2 @@ import type EvaluationContext from '../evaluation_context.js'; | ||
import type {Expression, ExpressionRegistry} from '../expression.js'; | ||
import {mulberry32} from '../../util/random.js'; | ||
@@ -173,6 +173,9 @@ const expressions: ExpressionRegistry = { | ||
function getConfig(ctx: EvaluationContext, key: string, scope: string) { | ||
if (scope.length) { | ||
key += `\u{1f}${scope}`; | ||
} | ||
const FQIDSeparator = '\u001F'; | ||
function getConfig(ctx: EvaluationContext, key: string, scope: ?string) { | ||
// Create a fully qualified key from the requested scope | ||
// and the scope from the current evaluation context | ||
key = [key, scope, ctx.scope].filter(Boolean).join(FQIDSeparator); | ||
const config = ctx.getConfig(key); | ||
@@ -184,4 +187,12 @@ if (!config) return null; | ||
const defaultValue = config.default.evaluate(ctx); | ||
let result = value ? value.evaluate(ctx) : defaultValue; | ||
let result = defaultValue; | ||
if (value) { | ||
// temporarily override scope to parent to evaluate config expressions passed from the parent | ||
const originalScope = ctx.scope; | ||
ctx.scope = (originalScope || '').split(FQIDSeparator).slice(1).join(FQIDSeparator); | ||
result = value.evaluate(ctx); | ||
ctx.scope = originalScope; | ||
} | ||
if (type) result = coerceValue(type, result); | ||
@@ -302,3 +313,3 @@ | ||
[StringType], | ||
(ctx, [key]) => getConfig(ctx, key.evaluate(ctx), '') | ||
(ctx, [key]) => getConfig(ctx, key.evaluate(ctx)) | ||
], [ | ||
@@ -305,0 +316,0 @@ [StringType, StringType], |
@@ -10,30 +10,2 @@ // @flow | ||
declare var Intl: { | ||
NumberFormat: Class<Intl$NumberFormat> | ||
}; | ||
declare class Intl$NumberFormat { | ||
constructor ( | ||
locales?: string | string[], | ||
options?: NumberFormatOptions | ||
): Intl$NumberFormat; | ||
static ( | ||
locales?: string | string[], | ||
options?: NumberFormatOptions | ||
): Intl$NumberFormat; | ||
format(a: number): string; | ||
resolvedOptions(): any; | ||
} | ||
type NumberFormatOptions = { | ||
style?: 'decimal' | 'currency' | 'percent' | 'unit'; | ||
currency?: null | string; | ||
unit?: null | string; | ||
minimumFractionDigits?: null | string; | ||
maximumFractionDigits?: null | string; | ||
}; | ||
export default class NumberFormat implements Expression { | ||
@@ -40,0 +12,0 @@ type: Type; |
@@ -23,2 +23,3 @@ // @flow | ||
featureDistanceData: ?FeatureDistanceData; | ||
scope: ?string; | ||
options: ?ConfigOptions; | ||
@@ -28,3 +29,3 @@ | ||
constructor(options?: ?ConfigOptions) { | ||
constructor(scope: ?string, options: ?ConfigOptions) { | ||
this.globals = (null: any); | ||
@@ -39,2 +40,3 @@ this.feature = null; | ||
this.featureDistanceData = null; | ||
this.scope = scope; | ||
this.options = options; | ||
@@ -41,0 +43,0 @@ } |
@@ -68,6 +68,6 @@ // @flow | ||
constructor(expression: Expression, propertySpec: ?StylePropertySpecification, options?: ?ConfigOptions) { | ||
constructor(expression: Expression, propertySpec: ?StylePropertySpecification, scope?: ?string, options?: ?ConfigOptions) { | ||
this.expression = expression; | ||
this._warningHistory = {}; | ||
this._evaluator = new EvaluationContext(options); | ||
this._evaluator = new EvaluationContext(scope, options); | ||
this._defaultValue = propertySpec ? getDefaultValue(propertySpec) : null; | ||
@@ -136,4 +136,4 @@ this._enumValues = propertySpec && propertySpec.type === 'enum' ? propertySpec.values : null; | ||
*/ | ||
export function createExpression(expression: mixed, propertySpec: ?StylePropertySpecification, options?: ?ConfigOptions): Result<StyleExpression, Array<ParsingError>> { | ||
const parser = new ParsingContext(definitions, [], propertySpec ? getExpectedType(propertySpec) : undefined, undefined, undefined, options); | ||
export function createExpression(expression: mixed, propertySpec: ?StylePropertySpecification, scope?: ?string, options?: ?ConfigOptions): Result<StyleExpression, Array<ParsingError>> { | ||
const parser = new ParsingContext(definitions, [], propertySpec ? getExpectedType(propertySpec) : undefined, undefined, undefined, scope, options); | ||
@@ -149,3 +149,3 @@ // For string-valued properties, coerce to string at the top level rather than asserting. | ||
return success(new StyleExpression(parsed, propertySpec, options)); | ||
return success(new StyleExpression(parsed, propertySpec, scope, options)); | ||
} | ||
@@ -255,4 +255,4 @@ | ||
export function createPropertyExpression(expression: mixed, propertySpec: StylePropertySpecification, options?: ?ConfigOptions): Result<StylePropertyExpression, Array<ParsingError>> { | ||
expression = createExpression(expression, propertySpec, options); | ||
export function createPropertyExpression(expression: mixed, propertySpec: StylePropertySpecification, scope?: ?string, options?: ?ConfigOptions): Result<StylePropertyExpression, Array<ParsingError>> { | ||
expression = createExpression(expression, propertySpec, scope, options); | ||
if (expression.result === 'error') { | ||
@@ -338,3 +338,3 @@ return expression; | ||
export function normalizePropertyExpression<T>(value: PropertyValueSpecification<T>, specification: StylePropertySpecification, options?: ?ConfigOptions): StylePropertyExpression { | ||
export function normalizePropertyExpression<T>(value: PropertyValueSpecification<T>, specification: StylePropertySpecification, scope?: ?string, options?: ?ConfigOptions): StylePropertyExpression { | ||
if (isFunction(value)) { | ||
@@ -344,3 +344,3 @@ return (new StylePropertyFunction(value, specification): any); | ||
} else if (isExpression(value) || (Array.isArray(value) && value.length > 0)) { | ||
const expression = createPropertyExpression(value, specification, options); | ||
const expression = createPropertyExpression(value, specification, scope, options); | ||
if (expression.result === 'error') { | ||
@@ -347,0 +347,0 @@ // this should have been caught in validation |
@@ -31,2 +31,3 @@ // @flow | ||
errors: Array<ParsingError>; | ||
_scope: ?string; | ||
options: ?ConfigOptions; | ||
@@ -46,2 +47,3 @@ | ||
errors: Array<ParsingError> = [], | ||
_scope: ?string, | ||
options?: ?ConfigOptions | ||
@@ -55,2 +57,3 @@ ) { | ||
this.expectedType = expectedType; | ||
this._scope = _scope; | ||
this.options = options; | ||
@@ -130,3 +133,3 @@ } | ||
if (!(parsed instanceof Literal) && (parsed.type.kind !== 'resolvedImage') && isConstant(parsed)) { | ||
const ec = new EvaluationContext(this.options); | ||
const ec = new EvaluationContext(this._scope, this.options); | ||
try { | ||
@@ -171,2 +174,3 @@ parsed = new Literal(parsed.type, parsed.evaluate(ec)); | ||
this.errors, | ||
this._scope, | ||
this.options | ||
@@ -173,0 +177,0 @@ ); |
// @flow | ||
// Flow type declarations for Intl cribbed from | ||
// https://github.com/facebook/flow/issues/1270 | ||
declare var Intl: { | ||
Collator: Class<Intl$Collator> | ||
}; | ||
declare class Intl$Collator { | ||
constructor ( | ||
locales?: string | string[], | ||
options?: CollatorOptions | ||
): Intl$Collator; | ||
static ( | ||
locales?: string | string[], | ||
options?: CollatorOptions | ||
): Intl$Collator; | ||
compare (a: string, b: string): number; | ||
resolvedOptions(): any; | ||
} | ||
type CollatorOptions = { | ||
localeMatcher?: 'lookup' | 'best fit', | ||
usage?: 'sort' | 'search', | ||
sensitivity?: 'base' | 'accent' | 'case' | 'variant', | ||
ignorePunctuation?: boolean, | ||
numeric?: boolean, | ||
caseFirst?: 'upper' | 'lower' | 'false' | ||
} | ||
export default class Collator { | ||
@@ -36,0 +4,0 @@ locale: string | null; |
@@ -18,3 +18,12 @@ // @flow strict | ||
export type WebGL2RenderingContext = WebGLRenderingContext & { | ||
declare class WebGL2RenderingContext extends WebGLRenderingContext { | ||
R8: 0x8229; | ||
R32F: 0x822E; | ||
RGBA16F: 0x881A; | ||
RED: 0x1903; | ||
HALF_FLOAT: 0x140B; | ||
QUERY_RESULT: 0x8866; | ||
MIN: 0x8007; | ||
MAX: 0x8008; | ||
createVertexArray: () => WebGLVertexArrayObject | null; | ||
@@ -21,0 +30,0 @@ deleteVertexArray: (vertexArray: WebGLVertexArrayObject | null) => void; |
@@ -0,1 +1,2 @@ | ||
// @noflow | ||
@@ -2,0 +3,0 @@ import reference from './reference/latest.js'; |
@@ -0,1 +1,2 @@ | ||
// @noflow | ||
@@ -2,0 +3,0 @@ import * as colorSpaces from '../util/color_spaces.js'; |
@@ -0,1 +1,2 @@ | ||
// @noflow | ||
@@ -2,0 +3,0 @@ import migrateToV8 from './migrate/v8.js'; |
@@ -1,2 +0,2 @@ | ||
// @noflow | ||
import URL from 'url'; | ||
@@ -3,0 +3,0 @@ import {eachSource, eachLayer, eachProperty} from '../visit.js'; |
@@ -1,2 +0,2 @@ | ||
// @noflow | ||
import deref from '../deref.js'; | ||
@@ -3,0 +3,0 @@ |
{ | ||
"name": "@mapbox/mapbox-gl-style-spec", | ||
"description": "a specification for mapbox gl styles", | ||
"version": "14.1.0", | ||
"version": "14.2.0-beta.1", | ||
"author": "Mapbox", | ||
@@ -6,0 +6,0 @@ "keywords": [ |
@@ -0,1 +1,3 @@ | ||
// @noflow | ||
import ParsingError from './error/parsing_error.js'; | ||
@@ -2,0 +4,0 @@ import jsonlint from '@mapbox/jsonlint-lines-primitives'; |
@@ -0,1 +1,3 @@ | ||
// @noflow | ||
import path from 'path'; | ||
@@ -2,0 +4,0 @@ import replace from '@rollup/plugin-replace'; |
// @flow | ||
type ExpressionType = 'data-driven' | 'color-ramp' | 'data-constant' | 'constant'; | ||
type ExpressionParameters = Array<'zoom' | 'feature' | 'feature-state' | 'heatmap-density' | 'line-progress' | 'raster-value' | 'sky-radial-progress' | 'pitch' | 'distance-from-center'>; | ||
type ExpressionParameters = Array<'zoom' | 'feature' | 'feature-state' | 'heatmap-density' | 'line-progress' | 'raster-value' | 'sky-radial-progress' | 'pitch' | 'distance-from-center' | 'measure-light'>; | ||
@@ -6,0 +6,0 @@ export type ExpressionSpecification = { |
#!/usr/bin/env node | ||
// @noflow | ||
/* eslint-disable no-process-exit */ | ||
@@ -3,0 +4,0 @@ |
@@ -5,3 +5,5 @@ // @flow | ||
function expressionHasParameter(expression: ?ExpressionSpecification, parameter: string): boolean { | ||
type ExpressionParameter = ExpressionSpecification['parameters'][number]; | ||
function expressionHasParameter(expression: ?ExpressionSpecification, parameter: ExpressionParameter): boolean { | ||
return !!expression && !!expression.parameters && expression.parameters.indexOf(parameter) > -1; | ||
@@ -8,0 +10,0 @@ } |
// @flow | ||
import ValidationError from '../error/validation_error.js'; | ||
import {default as ValidationError, ValidationWarning} from '../error/validation_error.js'; | ||
import {unbundle} from '../util/unbundle_jsonlint.js'; | ||
@@ -33,3 +33,3 @@ import validateObject from './validate_object.js'; | ||
if (!value.url && !value.tiles) { | ||
errors.push(new ValidationError(key, value, 'Either "url" or "tiles" is required.')); | ||
errors.push(new ValidationWarning(key, value, 'Either "url" or "tiles" is required.')); | ||
} | ||
@@ -36,0 +36,0 @@ } |
@@ -12,3 +12,3 @@ // @flow | ||
type StyleValidationOptions = { | ||
key?: ValidationOptions["key"] | ||
key?: $PropertyType<ValidationOptions, 'key'> | ||
} | ||
@@ -15,0 +15,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4033683
139
62315
2