@mapwhit/tilerenderer 0.47.2 → 0.48.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/build/min/package.json +1 -1
- package/package.json +1 -1
- package/src/data/bucket/symbol_bucket.js +25 -11
- package/src/data/program_configuration.js +18 -10
- package/src/geo/transform.js +4 -2
- package/src/index.js +1 -1
- package/src/source/rtl_text_plugin.js +1 -0
- package/src/source/source_cache.js +1 -1
- package/src/source/tile.js +6 -5
- package/src/source/worker.js +1 -10
- package/src/style/style.js +4 -19
- package/src/style/style_layer/symbol_style_layer_properties.js +1 -1
- package/src/style-spec/expression/compound_expression.js +30 -16
- package/src/style-spec/expression/definitions/coercion.js +13 -0
- package/src/style-spec/expression/definitions/comparison.js +193 -0
- package/src/style-spec/expression/definitions/formatted.js +123 -0
- package/src/style-spec/expression/definitions/index.js +10 -60
- package/src/style-spec/expression/definitions/interpolate.js +17 -7
- package/src/style-spec/expression/definitions/literal.js +5 -0
- package/src/style-spec/expression/parsing_context.js +4 -0
- package/src/style-spec/expression/types.js +12 -1
- package/src/style-spec/feature_filter/index.js +1 -1
- package/src/style-spec/reference/v8.json +118 -47
- package/src/symbol/get_anchors.js +11 -22
- package/src/symbol/mergelines.js +4 -1
- package/src/symbol/placement.js +8 -2
- package/src/symbol/quads.js +7 -6
- package/src/symbol/shaping.js +185 -40
- package/src/symbol/symbol_layout.js +9 -6
- package/src/symbol/transform_text.js +12 -1
- package/src/ui/map.js +8 -25
- package/src/style-spec/expression/definitions/equals.js +0 -93
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
const { NumberType, ValueType, FormattedType, array, StringType } = require('../types');
|
|
2
|
+
|
|
3
|
+
class FormattedSection {
|
|
4
|
+
constructor(text, scale, fontStack) {
|
|
5
|
+
this.text = text;
|
|
6
|
+
this.scale = scale;
|
|
7
|
+
this.fontStack = fontStack;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
class Formatted {
|
|
12
|
+
constructor(sections) {
|
|
13
|
+
this.sections = sections;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
toString() {
|
|
17
|
+
return this.sections.map(section => section.text).join('');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
serialize() {
|
|
21
|
+
const serialized = ['format'];
|
|
22
|
+
for (const section of this.sections) {
|
|
23
|
+
serialized.push(section.text);
|
|
24
|
+
const fontStack = section.fontStack ? ['literal', section.fontStack.split(',')] : null;
|
|
25
|
+
serialized.push({ 'text-font': fontStack, 'font-scale': section.scale });
|
|
26
|
+
}
|
|
27
|
+
return serialized;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
class FormatExpression {
|
|
32
|
+
constructor(sections) {
|
|
33
|
+
this.type = FormattedType;
|
|
34
|
+
this.sections = sections;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
static parse(args, context) {
|
|
38
|
+
if (args.length < 3) {
|
|
39
|
+
return context.error('Expected at least two arguments.');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if ((args.length - 1) % 2 !== 0) {
|
|
43
|
+
return context.error('Expected an even number of arguments.');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const sections = [];
|
|
47
|
+
for (let i = 1; i < args.length - 1; i += 2) {
|
|
48
|
+
const text = context.parse(args[i], 1, ValueType);
|
|
49
|
+
if (!text) return null;
|
|
50
|
+
const kind = text.type.kind;
|
|
51
|
+
if (kind !== 'string' && kind !== 'value' && kind !== 'null')
|
|
52
|
+
return context.error("Formatted text type must be 'string', 'value', or 'null'.");
|
|
53
|
+
|
|
54
|
+
const options = args[i + 1];
|
|
55
|
+
if (typeof options !== 'object' || Array.isArray(options))
|
|
56
|
+
return context.error('Format options argument must be an object.');
|
|
57
|
+
|
|
58
|
+
let scale = null;
|
|
59
|
+
if (options['font-scale']) {
|
|
60
|
+
scale = context.parse(options['font-scale'], 1, NumberType);
|
|
61
|
+
if (!scale) return null;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let font = null;
|
|
65
|
+
if (options['text-font']) {
|
|
66
|
+
font = context.parse(options['text-font'], 1, array(StringType));
|
|
67
|
+
if (!font) return null;
|
|
68
|
+
}
|
|
69
|
+
sections.push({ text, scale, font });
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return new FormatExpression(sections);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
evaluate(ctx) {
|
|
76
|
+
return new Formatted(
|
|
77
|
+
this.sections.map(
|
|
78
|
+
section =>
|
|
79
|
+
new FormattedSection(
|
|
80
|
+
section.text.evaluate(ctx) || '',
|
|
81
|
+
section.scale ? section.scale.evaluate(ctx) : null,
|
|
82
|
+
section.font ? section.font.evaluate(ctx).join(',') : null
|
|
83
|
+
)
|
|
84
|
+
)
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
eachChild(fn) {
|
|
89
|
+
for (const section of this.sections) {
|
|
90
|
+
fn(section.text);
|
|
91
|
+
if (section.scale) {
|
|
92
|
+
fn(section.scale);
|
|
93
|
+
}
|
|
94
|
+
if (section.font) {
|
|
95
|
+
fn(section.font);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
possibleOutputs() {
|
|
101
|
+
// Technically the combinatoric set of all children
|
|
102
|
+
// Usually, this.text will be undefined anyway
|
|
103
|
+
return [undefined];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
serialize() {
|
|
107
|
+
const serialized = ['format'];
|
|
108
|
+
for (const section of this.sections) {
|
|
109
|
+
serialized.push(section.text.serialize());
|
|
110
|
+
const options = {};
|
|
111
|
+
if (section.scale) {
|
|
112
|
+
options['font-scale'] = section.scale.serialize();
|
|
113
|
+
}
|
|
114
|
+
if (section.font) {
|
|
115
|
+
options['text-font'] = section.font.serialize();
|
|
116
|
+
}
|
|
117
|
+
serialized.push(options);
|
|
118
|
+
}
|
|
119
|
+
return serialized;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
module.exports = { Formatted, FormatExpression };
|
|
@@ -26,21 +26,29 @@ const Case = require('./case');
|
|
|
26
26
|
const Step = require('./step');
|
|
27
27
|
const Interpolate = require('./interpolate');
|
|
28
28
|
const Coalesce = require('./coalesce');
|
|
29
|
-
const { Equals, NotEquals } = require('./
|
|
29
|
+
const { Equals, NotEquals, LessThan, GreaterThan, LessThanOrEqual, GreaterThanOrEqual } = require('./comparison');
|
|
30
30
|
const { CollatorExpression } = require('./collator');
|
|
31
|
+
const { Formatted, FormatExpression } = require('./formatted');
|
|
31
32
|
const Length = require('./length');
|
|
32
33
|
|
|
33
34
|
const expressions = {
|
|
34
35
|
// special forms
|
|
35
36
|
'==': Equals,
|
|
36
37
|
'!=': NotEquals,
|
|
38
|
+
'>': GreaterThan,
|
|
39
|
+
'<': LessThan,
|
|
40
|
+
'>=': GreaterThanOrEqual,
|
|
41
|
+
'<=': LessThanOrEqual,
|
|
37
42
|
array: ArrayAssertion,
|
|
38
43
|
at: At,
|
|
39
44
|
boolean: Assertion,
|
|
40
45
|
case: Case,
|
|
41
46
|
coalesce: Coalesce,
|
|
42
47
|
collator: CollatorExpression,
|
|
48
|
+
format: FormatExpression,
|
|
43
49
|
interpolate: Interpolate,
|
|
50
|
+
'interpolate-hcl': Interpolate,
|
|
51
|
+
'interpolate-lab': Interpolate,
|
|
44
52
|
length: Length,
|
|
45
53
|
let: Let,
|
|
46
54
|
literal: Literal,
|
|
@@ -73,32 +81,6 @@ function get(key, obj) {
|
|
|
73
81
|
return typeof v === 'undefined' ? null : v;
|
|
74
82
|
}
|
|
75
83
|
|
|
76
|
-
function lt(ctx, [a, b]) {
|
|
77
|
-
return a.evaluate(ctx) < b.evaluate(ctx);
|
|
78
|
-
}
|
|
79
|
-
function gt(ctx, [a, b]) {
|
|
80
|
-
return a.evaluate(ctx) > b.evaluate(ctx);
|
|
81
|
-
}
|
|
82
|
-
function lteq(ctx, [a, b]) {
|
|
83
|
-
return a.evaluate(ctx) <= b.evaluate(ctx);
|
|
84
|
-
}
|
|
85
|
-
function gteq(ctx, [a, b]) {
|
|
86
|
-
return a.evaluate(ctx) >= b.evaluate(ctx);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
function ltCollate(ctx, [a, b, c]) {
|
|
90
|
-
return c.evaluate(ctx).compare(a.evaluate(ctx), b.evaluate(ctx)) < 0;
|
|
91
|
-
}
|
|
92
|
-
function gtCollate(ctx, [a, b, c]) {
|
|
93
|
-
return c.evaluate(ctx).compare(a.evaluate(ctx), b.evaluate(ctx)) > 0;
|
|
94
|
-
}
|
|
95
|
-
function lteqCollate(ctx, [a, b, c]) {
|
|
96
|
-
return c.evaluate(ctx).compare(a.evaluate(ctx), b.evaluate(ctx)) <= 0;
|
|
97
|
-
}
|
|
98
|
-
function gteqCollate(ctx, [a, b, c]) {
|
|
99
|
-
return c.evaluate(ctx).compare(a.evaluate(ctx), b.evaluate(ctx)) >= 0;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
84
|
function binarySearch(v, a, i, j) {
|
|
103
85
|
while (i <= j) {
|
|
104
86
|
const m = (i + j) >> 1;
|
|
@@ -134,7 +116,7 @@ CompoundExpression.register(expressions, {
|
|
|
134
116
|
if (type === 'string' || type === 'number' || type === 'boolean') {
|
|
135
117
|
return String(v);
|
|
136
118
|
}
|
|
137
|
-
if (v instanceof Color) {
|
|
119
|
+
if (v instanceof Color || v instanceof Formatted) {
|
|
138
120
|
return v.toString();
|
|
139
121
|
}
|
|
140
122
|
return JSON.stringify(v);
|
|
@@ -323,38 +305,6 @@ CompoundExpression.register(expressions, {
|
|
|
323
305
|
// assumes v is a array literal with values sorted in ascending order and of a single type
|
|
324
306
|
(ctx, [k, v]) => binarySearch(ctx.properties()[k.value], v.value, 0, v.value.length - 1)
|
|
325
307
|
],
|
|
326
|
-
'>': {
|
|
327
|
-
type: BooleanType,
|
|
328
|
-
overloads: [
|
|
329
|
-
[[NumberType, NumberType], gt],
|
|
330
|
-
[[StringType, StringType], gt],
|
|
331
|
-
[[StringType, StringType, CollatorType], gtCollate]
|
|
332
|
-
]
|
|
333
|
-
},
|
|
334
|
-
'<': {
|
|
335
|
-
type: BooleanType,
|
|
336
|
-
overloads: [
|
|
337
|
-
[[NumberType, NumberType], lt],
|
|
338
|
-
[[StringType, StringType], lt],
|
|
339
|
-
[[StringType, StringType, CollatorType], ltCollate]
|
|
340
|
-
]
|
|
341
|
-
},
|
|
342
|
-
'>=': {
|
|
343
|
-
type: BooleanType,
|
|
344
|
-
overloads: [
|
|
345
|
-
[[NumberType, NumberType], gteq],
|
|
346
|
-
[[StringType, StringType], gteq],
|
|
347
|
-
[[StringType, StringType, CollatorType], gteqCollate]
|
|
348
|
-
]
|
|
349
|
-
},
|
|
350
|
-
'<=': {
|
|
351
|
-
type: BooleanType,
|
|
352
|
-
overloads: [
|
|
353
|
-
[[NumberType, NumberType], lteq],
|
|
354
|
-
[[StringType, StringType], lteq],
|
|
355
|
-
[[StringType, StringType, CollatorType], lteqCollate]
|
|
356
|
-
]
|
|
357
|
-
},
|
|
358
308
|
all: {
|
|
359
309
|
type: BooleanType,
|
|
360
310
|
overloads: [
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
const UnitBezier = require('@mapbox/unitbezier');
|
|
2
2
|
|
|
3
3
|
const interpolate = require('../../util/interpolate');
|
|
4
|
-
const { toString, NumberType } = require('../types');
|
|
4
|
+
const { toString, ColorType, NumberType } = require('../types');
|
|
5
5
|
const { findStopLessThanOrEqualTo } = require('../stops');
|
|
6
|
+
const { hcl, lab } = require('../../util/color_spaces');
|
|
6
7
|
|
|
7
8
|
class Interpolate {
|
|
8
|
-
constructor(type, interpolation, input, stops) {
|
|
9
|
+
constructor(type, operator, interpolation, input, stops) {
|
|
9
10
|
this.type = type;
|
|
11
|
+
this.operator = operator;
|
|
10
12
|
this.interpolation = interpolation;
|
|
11
13
|
this.input = input;
|
|
12
14
|
|
|
@@ -33,7 +35,7 @@ class Interpolate {
|
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
static parse(args, context) {
|
|
36
|
-
let [, interpolation, input, ...rest] = args;
|
|
38
|
+
let [operator, interpolation, input, ...rest] = args;
|
|
37
39
|
|
|
38
40
|
if (!Array.isArray(interpolation) || interpolation.length === 0) {
|
|
39
41
|
return context.error('Expected an interpolation type expression.', 1);
|
|
@@ -79,7 +81,9 @@ class Interpolate {
|
|
|
79
81
|
const stops = [];
|
|
80
82
|
|
|
81
83
|
let outputType = null;
|
|
82
|
-
if (
|
|
84
|
+
if (operator === 'interpolate-hcl' || operator === 'interpolate-lab') {
|
|
85
|
+
outputType = ColorType;
|
|
86
|
+
} else if (context.expectedType && context.expectedType.kind !== 'value') {
|
|
83
87
|
outputType = context.expectedType;
|
|
84
88
|
}
|
|
85
89
|
|
|
@@ -118,7 +122,7 @@ class Interpolate {
|
|
|
118
122
|
return context.error(`Type ${toString(outputType)} is not interpolatable.`);
|
|
119
123
|
}
|
|
120
124
|
|
|
121
|
-
return new Interpolate(outputType, interpolation, input, stops);
|
|
125
|
+
return new Interpolate(outputType, operator, interpolation, input, stops);
|
|
122
126
|
}
|
|
123
127
|
|
|
124
128
|
evaluate(ctx) {
|
|
@@ -147,7 +151,13 @@ class Interpolate {
|
|
|
147
151
|
const outputLower = outputs[index].evaluate(ctx);
|
|
148
152
|
const outputUpper = outputs[index + 1].evaluate(ctx);
|
|
149
153
|
|
|
150
|
-
|
|
154
|
+
if (this.operator === 'interpolate') {
|
|
155
|
+
return interpolate[this.type.kind.toLowerCase()](outputLower, outputUpper, t);
|
|
156
|
+
}
|
|
157
|
+
if (this.operator === 'interpolate-hcl') {
|
|
158
|
+
return hcl.reverse(hcl.interpolate(hcl.forward(outputLower), hcl.forward(outputUpper), t));
|
|
159
|
+
}
|
|
160
|
+
return lab.reverse(lab.interpolate(lab.forward(outputLower), lab.forward(outputUpper), t));
|
|
151
161
|
}
|
|
152
162
|
|
|
153
163
|
eachChild(fn) {
|
|
@@ -175,7 +185,7 @@ class Interpolate {
|
|
|
175
185
|
interpolation = ['cubic-bezier'].concat(this.interpolation.controlPoints);
|
|
176
186
|
}
|
|
177
187
|
|
|
178
|
-
const serialized = [
|
|
188
|
+
const serialized = [this.operator, interpolation, this.input.serialize()];
|
|
179
189
|
|
|
180
190
|
for (let i = 0; i < this.labels.length; i++) {
|
|
181
191
|
serialized.push(this.labels[i], this.outputs[i].serialize());
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const assert = require('assert');
|
|
2
2
|
const { isValue, typeOf, Color } = require('../values');
|
|
3
|
+
const { Formatted } = require('./formatted');
|
|
3
4
|
|
|
4
5
|
class Literal {
|
|
5
6
|
constructor(type, value) {
|
|
@@ -51,6 +52,10 @@ class Literal {
|
|
|
51
52
|
// so we have to implement an equivalent serialization here
|
|
52
53
|
return ['rgba'].concat(this.value.toArray());
|
|
53
54
|
}
|
|
55
|
+
if (this.value instanceof Formatted) {
|
|
56
|
+
// Same as Color
|
|
57
|
+
return this.value.serialize();
|
|
58
|
+
}
|
|
54
59
|
assert(
|
|
55
60
|
this.value === null ||
|
|
56
61
|
typeof this.value === 'string' ||
|
|
@@ -97,6 +97,10 @@ class ParsingContext {
|
|
|
97
97
|
if (!options.omitTypeAnnotations) {
|
|
98
98
|
parsed = new Coercion(expected, [parsed]);
|
|
99
99
|
}
|
|
100
|
+
} else if (expected.kind === 'formatted' && (actual.kind === 'value' || actual.kind === 'string')) {
|
|
101
|
+
if (!options.omitTypeAnnotations) {
|
|
102
|
+
parsed = new Coercion(expected, [parsed]);
|
|
103
|
+
}
|
|
100
104
|
} else if (this.checkSubtype(this.expectedType, parsed.type)) {
|
|
101
105
|
return null;
|
|
102
106
|
}
|
|
@@ -7,6 +7,7 @@ const ObjectType = { kind: 'object' };
|
|
|
7
7
|
const ValueType = { kind: 'value' };
|
|
8
8
|
const ErrorType = { kind: 'error' };
|
|
9
9
|
const CollatorType = { kind: 'collator' };
|
|
10
|
+
const FormattedType = { kind: 'formatted' };
|
|
10
11
|
|
|
11
12
|
function array(itemType, N) {
|
|
12
13
|
return {
|
|
@@ -28,7 +29,16 @@ function toString(type) {
|
|
|
28
29
|
return type.kind;
|
|
29
30
|
}
|
|
30
31
|
|
|
31
|
-
const valueMemberTypes = [
|
|
32
|
+
const valueMemberTypes = [
|
|
33
|
+
NullType,
|
|
34
|
+
NumberType,
|
|
35
|
+
StringType,
|
|
36
|
+
BooleanType,
|
|
37
|
+
ColorType,
|
|
38
|
+
FormattedType,
|
|
39
|
+
ObjectType,
|
|
40
|
+
array(ValueType)
|
|
41
|
+
];
|
|
32
42
|
|
|
33
43
|
/**
|
|
34
44
|
* Returns null if `t` is a subtype of `expected`; otherwise returns an
|
|
@@ -67,6 +77,7 @@ module.exports = {
|
|
|
67
77
|
StringType,
|
|
68
78
|
BooleanType,
|
|
69
79
|
ColorType,
|
|
80
|
+
FormattedType,
|
|
70
81
|
ObjectType,
|
|
71
82
|
ValueType,
|
|
72
83
|
ErrorType,
|
|
@@ -24,7 +24,7 @@ function isExpressionFilter(filter) {
|
|
|
24
24
|
case '>=':
|
|
25
25
|
case '<':
|
|
26
26
|
case '<=':
|
|
27
|
-
return filter.length
|
|
27
|
+
return filter.length !== 3 || Array.isArray(filter[1]) || Array.isArray(filter[2]);
|
|
28
28
|
|
|
29
29
|
case 'any':
|
|
30
30
|
case 'all':
|