@mapbox/mapbox-gl-style-spec
Advanced tools
Comparing version 13.1.0 to 13.1.1-beta.1
@@ -0,1 +1,9 @@ | ||
## 13.1.1 | ||
## 🐛 Bug fixes | ||
* Fix broken module import in mapboxgl-style-spec (v13.0.1) ([#6984](https://github.com/mapbox/mapbox-gl-js/issues/6984), fixed by [#6997](https://api.github.com/repos/mapbox/mapbox-gl-js/pulls/6997)) | ||
## ✨ Features and improvements | ||
* Improve formatting for style output ([#7029](https://github.com/mapbox/mapbox-gl-js/pull/7029)) | ||
## 13.1.0 | ||
@@ -2,0 +10,0 @@ |
@@ -46,3 +46,3 @@ // @flow | ||
serialize() { | ||
serialize(): Array<mixed> { | ||
return [this.name].concat(this.args.map(arg => arg.serialize())); | ||
@@ -71,18 +71,2 @@ } | ||
// First parse all the args | ||
const parsedArgs: Array<Expression> = []; | ||
for (let i = 1; i < args.length; i++) { | ||
const arg = args[i]; | ||
let expected; | ||
if (overloads.length === 1) { | ||
const params = overloads[0][0]; | ||
expected = Array.isArray(params) ? | ||
params[i - 1] : | ||
params.type; | ||
} | ||
const parsed = context.parse(arg, 1 + parsedArgs.length, expected); | ||
if (!parsed) return null; | ||
parsedArgs.push(parsed); | ||
} | ||
let signatureContext: ParsingContext = (null: any); | ||
@@ -95,2 +79,25 @@ | ||
// First parse all the args, potentially coercing to the | ||
// types expected by this overload. | ||
const parsedArgs: Array<Expression> = []; | ||
let argParseFailed = false; | ||
for (let i = 1; i < args.length; i++) { | ||
const arg = args[i]; | ||
const expectedType = Array.isArray(params) ? | ||
params[i - 1] : | ||
params.type; | ||
const parsed = signatureContext.parse(arg, 1 + parsedArgs.length, expectedType); | ||
if (!parsed) { | ||
argParseFailed = true; | ||
break; | ||
} | ||
parsedArgs.push(parsed); | ||
} | ||
if (argParseFailed) { | ||
// Couldn't coerce args of this overload to expected type, move | ||
// on to next one. | ||
continue; | ||
} | ||
if (Array.isArray(params)) { | ||
@@ -123,6 +130,12 @@ if (params.length !== parsedArgs.length) { | ||
.join(' | '); | ||
const actualTypes = parsedArgs | ||
.map(arg => toString(arg.type)) | ||
.join(', '); | ||
context.error(`Expected arguments of type ${signatures}, but found (${actualTypes}) instead.`); | ||
const actualTypes = []; | ||
// For error message, re-parse arguments without trying to | ||
// apply any coercions | ||
for (let i = 1; i < args.length; i++) { | ||
const parsed = context.parse(args[i], 1 + actualTypes.length); | ||
if (!parsed) return null; | ||
actualTypes.push(toString(parsed.type)); | ||
} | ||
context.error(`Expected arguments of type ${signatures}, but found (${actualTypes.join(', ')}) instead.`); | ||
} | ||
@@ -129,0 +142,0 @@ |
@@ -20,2 +20,3 @@ // @flow | ||
import type EvaluationContext from '../evaluation_context'; | ||
import type { Value } from '../values'; | ||
import type { Type } from '../types'; | ||
@@ -77,7 +78,7 @@ | ||
possibleOutputs() { | ||
possibleOutputs(): Array<Value | void> { | ||
return [].concat(...this.args.map((arg) => arg.possibleOutputs())); | ||
} | ||
serialize() { | ||
serialize(): Array<mixed> { | ||
return [this.type.kind].concat(this.args.map(arg => arg.serialize())); | ||
@@ -84,0 +85,0 @@ } |
@@ -10,2 +10,3 @@ // @flow | ||
import type EvaluationContext from '../evaluation_context'; | ||
import type { Value } from '../values'; | ||
import type { Type } from '../types'; | ||
@@ -75,3 +76,3 @@ | ||
possibleOutputs() { | ||
possibleOutputs(): Array<Value | void> { | ||
return [] | ||
@@ -78,0 +79,0 @@ .concat(...this.branches.map(([_, out]) => out.possibleOutputs())) |
@@ -10,2 +10,3 @@ // @flow | ||
import type EvaluationContext from '../evaluation_context'; | ||
import type { Value } from '../values'; | ||
import type { Type } from '../types'; | ||
@@ -67,3 +68,3 @@ | ||
possibleOutputs() { | ||
possibleOutputs(): Array<Value | void> { | ||
return [].concat(...this.args.map((arg) => arg.possibleOutputs())); | ||
@@ -70,0 +71,0 @@ } |
@@ -12,3 +12,5 @@ // @flow | ||
import type EvaluationContext from '../evaluation_context'; | ||
import type { Value } from '../values'; | ||
import type { Type } from '../types'; | ||
import { Formatted, FormattedSection } from './formatted'; | ||
@@ -77,2 +79,11 @@ const types = { | ||
throw new RuntimeError(error || `Could not parse color from value '${typeof input === 'string' ? input : JSON.stringify(input)}'`); | ||
} else if (this.type.kind === 'formatted') { | ||
let input; | ||
for (const arg of this.args) { | ||
input = arg.evaluate(ctx); | ||
if (typeof input === 'string') { | ||
return new Formatted([new FormattedSection(input, null, null)]); | ||
} | ||
} | ||
throw new RuntimeError(`Could not parse formatted text from value '${typeof input === 'string' ? input : JSON.stringify(input)}'`); | ||
} else { | ||
@@ -95,3 +106,3 @@ let value = null; | ||
possibleOutputs() { | ||
possibleOutputs(): Array<Value | void> { | ||
return [].concat(...this.args.map((arg) => arg.possibleOutputs())); | ||
@@ -98,0 +109,0 @@ } |
@@ -20,4 +20,12 @@ // @flow | ||
import Coalesce from './coalesce'; | ||
import { Equals, NotEquals } from './equals'; | ||
import { | ||
Equals, | ||
NotEquals, | ||
LessThan, | ||
GreaterThan, | ||
LessThanOrEqual, | ||
GreaterThanOrEqual | ||
} from './comparison'; | ||
import { CollatorExpression } from './collator'; | ||
import { Formatted, FormatExpression } from './formatted'; | ||
import Length from './length'; | ||
@@ -33,2 +41,6 @@ | ||
'!=': NotEquals, | ||
'>': GreaterThan, | ||
'<': LessThan, | ||
'>=': GreaterThanOrEqual, | ||
'<=': LessThanOrEqual, | ||
'array': ArrayAssertion, | ||
@@ -40,2 +52,3 @@ 'at': At, | ||
'collator': CollatorExpression, | ||
'format': FormatExpression, | ||
'interpolate': Interpolate, | ||
@@ -74,12 +87,2 @@ 'length': Length, | ||
function lt(ctx, [a, b]) { return a.evaluate(ctx) < b.evaluate(ctx); } | ||
function gt(ctx, [a, b]) { return a.evaluate(ctx) > b.evaluate(ctx); } | ||
function lteq(ctx, [a, b]) { return a.evaluate(ctx) <= b.evaluate(ctx); } | ||
function gteq(ctx, [a, b]) { return a.evaluate(ctx) >= b.evaluate(ctx); } | ||
function ltCollate(ctx, [a, b, c]) { return c.evaluate(ctx).compare(a.evaluate(ctx), b.evaluate(ctx)) < 0; } | ||
function gtCollate(ctx, [a, b, c]) { return c.evaluate(ctx).compare(a.evaluate(ctx), b.evaluate(ctx)) > 0; } | ||
function lteqCollate(ctx, [a, b, c]) { return c.evaluate(ctx).compare(a.evaluate(ctx), b.evaluate(ctx)) <= 0; } | ||
function gteqCollate(ctx, [a, b, c]) { return c.evaluate(ctx).compare(a.evaluate(ctx), b.evaluate(ctx)) >= 0; } | ||
function binarySearch(v, a, i, j) { | ||
@@ -123,3 +126,3 @@ while (i <= j) { | ||
return String(v); | ||
} else if (v instanceof Color) { | ||
} else if (v instanceof Color || v instanceof Formatted) { | ||
return v.toString(); | ||
@@ -481,34 +484,2 @@ } else { | ||
], | ||
'>': { | ||
type: BooleanType, | ||
overloads: [ | ||
[[NumberType, NumberType], gt], | ||
[[StringType, StringType], gt], | ||
[[StringType, StringType, CollatorType], gtCollate] | ||
] | ||
}, | ||
'<': { | ||
type: BooleanType, | ||
overloads: [ | ||
[[NumberType, NumberType], lt], | ||
[[StringType, StringType], lt], | ||
[[StringType, StringType, CollatorType], ltCollate] | ||
] | ||
}, | ||
'>=': { | ||
type: BooleanType, | ||
overloads: [ | ||
[[NumberType, NumberType], gteq], | ||
[[StringType, StringType], gteq], | ||
[[StringType, StringType, CollatorType], gteqCollate] | ||
] | ||
}, | ||
'<=': { | ||
type: BooleanType, | ||
overloads: [ | ||
[[NumberType, NumberType], lteq], | ||
[[StringType, StringType], lteq], | ||
[[StringType, StringType, CollatorType], lteqCollate] | ||
] | ||
}, | ||
'all': { | ||
@@ -515,0 +486,0 @@ type: BooleanType, |
@@ -13,2 +13,3 @@ // @flow | ||
import type EvaluationContext from '../evaluation_context'; | ||
import type { Value } from '../values'; | ||
import type { Type } from '../types'; | ||
@@ -179,7 +180,7 @@ | ||
possibleOutputs() { | ||
possibleOutputs(): Array<Value | void> { | ||
return [].concat(...this.outputs.map((output) => output.possibleOutputs())); | ||
} | ||
serialize() { | ||
serialize(): Array<mixed> { | ||
let interpolation; | ||
@@ -186,0 +187,0 @@ if (this.interpolation.name === 'linear') { |
@@ -5,2 +5,3 @@ // @flow | ||
import { isValue, typeOf, Color } from '../values'; | ||
import { Formatted } from './formatted'; | ||
@@ -56,3 +57,3 @@ import type { Type } from '../types'; | ||
serialize() { | ||
serialize(): Array<mixed> { | ||
if (this.type.kind === 'array' || this.type.kind === 'object') { | ||
@@ -65,2 +66,5 @@ return ["literal", this.value]; | ||
return ["rgba"].concat(this.value.toArray()); | ||
} else if (this.value instanceof Formatted) { | ||
// Same as Color | ||
return this.value.serialize(); | ||
} else { | ||
@@ -67,0 +71,0 @@ assert(this.value === null || |
@@ -11,2 +11,3 @@ // @flow | ||
import type EvaluationContext from '../evaluation_context'; | ||
import type { Value } from '../values'; | ||
@@ -115,3 +116,3 @@ // Map input label values to output expression index | ||
possibleOutputs() { | ||
possibleOutputs(): Array<Value | void> { | ||
return [] | ||
@@ -122,3 +123,3 @@ .concat(...this.outputs.map((out) => out.possibleOutputs())) | ||
serialize() { | ||
serialize(): Array<mixed> { | ||
const serialized = ["match", this.input.serialize()]; | ||
@@ -125,0 +126,0 @@ |
@@ -11,2 +11,3 @@ // @flow | ||
import type EvaluationContext from '../evaluation_context'; | ||
import type { Value } from '../values'; | ||
import type { Type } from '../types'; | ||
@@ -109,3 +110,3 @@ | ||
possibleOutputs() { | ||
possibleOutputs(): Array<Value | void> { | ||
return [].concat(...this.outputs.map((output) => output.possibleOutputs())); | ||
@@ -112,0 +113,0 @@ } |
@@ -26,2 +26,3 @@ // @flow | ||
import type {InterpolationType} from './definitions/interpolate'; | ||
import type {PropertyValueSpecification} from '../types'; | ||
@@ -28,0 +29,0 @@ export type Feature = { |
@@ -116,2 +116,6 @@ // @flow | ||
} | ||
} else if (expected.kind === 'formatted' && (actual.kind === 'value' || actual.kind === 'string')) { | ||
if (!options.omitTypeAnnotations) { | ||
parsed = new Coercion(expected, [parsed]); | ||
} | ||
} else if (this.checkSubtype(this.expectedType, parsed.type)) { | ||
@@ -118,0 +122,0 @@ return null; |
@@ -12,2 +12,3 @@ // @flow | ||
export type CollatorTypeT = { kind: 'collator' }; | ||
export type FormattedTypeT = { kind: 'formatted' }; | ||
@@ -24,3 +25,4 @@ export type Type = | ||
ErrorTypeT | | ||
CollatorTypeT | ||
CollatorTypeT | | ||
FormattedTypeT | ||
@@ -42,2 +44,3 @@ export type ArrayType = { | ||
export const CollatorType = { kind: 'collator' }; | ||
export const FormattedType = { kind: 'formatted' }; | ||
@@ -69,2 +72,3 @@ export function array(itemType: Type, N: ?number): ArrayType { | ||
ColorType, | ||
FormattedType, | ||
ObjectType, | ||
@@ -71,0 +75,0 @@ array(ValueType) |
declare module "@mapbox/point-geometry" { | ||
declare type PointLike = Point | [number, number]; | ||
declare class Point { | ||
@@ -3,0 +5,0 @@ x: number; |
import type Pbf from 'pbf'; | ||
import type Point from '@mapbox/point-geometry'; | ||
import type { GeoJSONFeature } from '@mapbox/geojson-types'; | ||
@@ -3,0 +5,0 @@ declare interface VectorTile { |
import reference from './reference/latest.js'; | ||
import sortObject from 'sort-object'; | ||
import stringifyPretty from 'json-stringify-pretty-compact'; | ||
function sameOrderAs(reference) { | ||
const keyOrder = {}; | ||
Object.keys(reference).forEach((k, i) => { | ||
keyOrder[k] = i + 1; | ||
}); | ||
return { | ||
sort: function (a, b) { | ||
return (keyOrder[a] || Infinity) - | ||
(keyOrder[b] || Infinity); | ||
function sortKeysBy(obj, reference) { | ||
const result = {}; | ||
for (const key in reference) { | ||
if (obj[key] !== undefined) { | ||
result[key] = obj[key]; | ||
} | ||
}; | ||
} | ||
for (const key in obj) { | ||
if (result[key] === undefined) { | ||
result[key] = obj[key]; | ||
} | ||
} | ||
return result; | ||
} | ||
@@ -41,15 +41,12 @@ | ||
*/ | ||
function format(style, space) { | ||
if (space === undefined) space = 2; | ||
style = sortObject(style, sameOrderAs(reference.$root)); | ||
function format(style, space = 2) { | ||
style = sortKeysBy(style, reference.$root); | ||
if (style.layers) { | ||
style.layers = style.layers.map((layer) => { | ||
return sortObject(layer, sameOrderAs(reference.layer)); | ||
}); | ||
style.layers = style.layers.map((layer) => sortKeysBy(layer, reference.layer)); | ||
} | ||
return JSON.stringify(style, null, space); | ||
return stringifyPretty(style, {indent: space}); | ||
} | ||
export default format; |
@@ -8,2 +8,3 @@ // @flow | ||
import type {StylePropertySpecification} from '../style-spec'; | ||
import type {PropertyValueSpecification} from '../types'; | ||
@@ -58,3 +59,3 @@ export default convertFunction; | ||
function convertIdentityFunction(parameters, propertySpec, defaultExpression) { | ||
function convertIdentityFunction(parameters, propertySpec, defaultExpression): Array<mixed> { | ||
const get = ['get', parameters.property]; | ||
@@ -239,4 +240,3 @@ | ||
let pos = 0; | ||
let match; | ||
while ((match = re.exec(s)) !== null) { | ||
for (let match = re.exec(s); match !== null; match = re.exec(s)) { | ||
const literal = s.slice(pos, re.lastIndex - match[0].length); | ||
@@ -243,0 +243,0 @@ pos = re.lastIndex; |
{ | ||
"name": "@mapbox/mapbox-gl-style-spec", | ||
"description": "a specification for mapbox gl styles", | ||
"version": "13.1.0", | ||
"version": "13.1.1-beta.1", | ||
"author": "Mapbox", | ||
@@ -30,5 +30,6 @@ "keywords": [ | ||
"dependencies": { | ||
"@mapbox/jsonlint-lines-primitives": "~2.0.1", | ||
"@mapbox/jsonlint-lines-primitives": "~2.0.2", | ||
"@mapbox/unitbezier": "^0.0.0", | ||
"csscolorparser": "~1.0.2", | ||
"json-stringify-pretty-compact": "^1.2.0", | ||
"minimist": "0.0.8", | ||
@@ -35,0 +36,0 @@ "rw": "^1.3.3", |
@@ -18,3 +18,3 @@ // @flow | ||
export function array(from: Array<number>, to: Array<number>, t: number) { | ||
export function array(from: Array<number>, to: Array<number>, t: number): Array<number> { | ||
return from.map((d, i) => { | ||
@@ -21,0 +21,0 @@ return number(d, to[i], t); |
@@ -21,2 +21,3 @@ | ||
import validateString from './validate_string'; | ||
import validateFormatted from './validate_formatted'; | ||
@@ -39,3 +40,4 @@ const VALIDATORS = { | ||
'light': validateLight, | ||
'string': validateString | ||
'string': validateString, | ||
'formatted': validateFormatted | ||
}; | ||
@@ -69,6 +71,7 @@ | ||
} else { | ||
return validateObject(extend({}, options, { | ||
const valid = validateObject(extend({}, options, { | ||
valueSpec: valueSpec.type ? styleSpec[valueSpec.type] : valueSpec | ||
})); | ||
return valid; | ||
} | ||
} |
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
1419971
20948
7
102
2
+ Addedjson-stringify-pretty-compact@1.2.0(transitive)