@mapbox/mapbox-gl-style-spec 14.12.0 → 14.13.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/diff.ts +3 -1
- package/dist/index.cjs +321 -237
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +26 -26
- package/dist/index.es.js +321 -237
- package/dist/index.es.js.map +1 -1
- package/expression/definitions/config.ts +30 -10
- package/expression/definitions/format.ts +2 -1
- package/expression/definitions/index.ts +8 -3
- package/expression/definitions/literal.ts +1 -1
- package/expression/definitions/match.ts +2 -2
- package/expression/index.ts +1 -0
- package/expression/is_constant.ts +4 -0
- package/expression/parsing_context.ts +1 -1
- package/expression/types/formatted.ts +1 -1
- package/expression/types.ts +8 -0
- package/expression/values.ts +1 -3
- package/group_by_layout.ts +1 -9
- package/package.json +1 -1
- package/reference/v8.json +102 -19
- package/types.ts +12 -4
- package/union-to-intersection.ts +1 -2
- package/util/color.ts +85 -69
- package/util/interpolate.ts +0 -4
- package/validate/validate_lights.ts +21 -21
package/util/color.ts
CHANGED
|
@@ -56,9 +56,9 @@ class Color {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
return new Color(
|
|
59
|
-
rgba[0] / 255
|
|
60
|
-
rgba[1] / 255
|
|
61
|
-
rgba[2] / 255
|
|
59
|
+
rgba[0] / 255,
|
|
60
|
+
rgba[1] / 255,
|
|
61
|
+
rgba[2] / 255,
|
|
62
62
|
rgba[3]
|
|
63
63
|
);
|
|
64
64
|
}
|
|
@@ -73,16 +73,6 @@ class Color {
|
|
|
73
73
|
* var translucentGreen = new Color.parse('rgba(26, 207, 26, .73)');
|
|
74
74
|
* translucentGreen.toString(); // = "rgba(26,207,26,0.73)"
|
|
75
75
|
*/
|
|
76
|
-
toStringPremultipliedAlpha(): string {
|
|
77
|
-
const [r, g, b, a] = this.a === 0 ? [0, 0, 0, 0] : [
|
|
78
|
-
this.r * 255 / this.a,
|
|
79
|
-
this.g * 255 / this.a,
|
|
80
|
-
this.b * 255 / this.a,
|
|
81
|
-
this.a
|
|
82
|
-
];
|
|
83
|
-
return `rgba(${Math.round(r)},${Math.round(g)},${Math.round(b)},${a})`;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
76
|
toString(): string {
|
|
87
77
|
const [r, g, b, a] = [
|
|
88
78
|
this.r,
|
|
@@ -93,9 +83,14 @@ class Color {
|
|
|
93
83
|
return `rgba(${Math.round(r * 255)},${Math.round(g * 255)},${Math.round(b * 255)},${a})`;
|
|
94
84
|
}
|
|
95
85
|
|
|
96
|
-
|
|
86
|
+
toNonPremultipliedRenderColor(lut: LUT | null): NonPremultipliedRenderColor {
|
|
87
|
+
const {r, g, b, a} = this;
|
|
88
|
+
return new NonPremultipliedRenderColor(lut, r, g, b, a);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
toPremultipliedRenderColor(lut: LUT | null): NonPremultipliedRenderColor {
|
|
97
92
|
const {r, g, b, a} = this;
|
|
98
|
-
return new
|
|
93
|
+
return new PremultipliedRenderColor(lut, r * a, g * a, b * a, a);
|
|
99
94
|
}
|
|
100
95
|
|
|
101
96
|
clone(): Color {
|
|
@@ -103,16 +98,16 @@ class Color {
|
|
|
103
98
|
}
|
|
104
99
|
}
|
|
105
100
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
export class RenderColor {
|
|
101
|
+
export abstract class RenderColor {
|
|
102
|
+
premultiplied: boolean = false;
|
|
103
|
+
|
|
110
104
|
r: number;
|
|
111
105
|
g: number;
|
|
112
106
|
b: number;
|
|
113
107
|
a: number;
|
|
114
108
|
|
|
115
|
-
constructor(lut: LUT | null, r: number, g: number, b: number, a: number) {
|
|
109
|
+
constructor(lut: LUT | null, r: number, g: number, b: number, a: number, premultiplied: boolean = false) {
|
|
110
|
+
this.premultiplied = premultiplied;
|
|
116
111
|
if (!lut) {
|
|
117
112
|
this.r = r;
|
|
118
113
|
this.g = g;
|
|
@@ -121,10 +116,18 @@ export class RenderColor {
|
|
|
121
116
|
} else {
|
|
122
117
|
const N = lut.image.height;
|
|
123
118
|
const N2 = N * N;
|
|
119
|
+
|
|
124
120
|
// Normalize to cube dimensions.
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
121
|
+
|
|
122
|
+
if (this.premultiplied) {
|
|
123
|
+
r = a === 0 ? 0 : (r / a) * (N - 1);
|
|
124
|
+
g = a === 0 ? 0 : (g / a) * (N - 1);
|
|
125
|
+
b = a === 0 ? 0 : (b / a) * (N - 1);
|
|
126
|
+
} else {
|
|
127
|
+
r = r * (N - 1);
|
|
128
|
+
g = g * (N - 1);
|
|
129
|
+
b = b * (N - 1);
|
|
130
|
+
}
|
|
128
131
|
|
|
129
132
|
// Determine boundary values for the cube the color is in.
|
|
130
133
|
const r0 = Math.floor(r);
|
|
@@ -159,54 +162,59 @@ export class RenderColor {
|
|
|
159
162
|
lerp(data[i2], data[i3], bw), gw),
|
|
160
163
|
lerp(
|
|
161
164
|
lerp(data[i4], data[i5], bw),
|
|
162
|
-
lerp(data[i6], data[i7], bw), gw), rw) / 255 * a;
|
|
165
|
+
lerp(data[i6], data[i7], bw), gw), rw) / 255 * (this.premultiplied ? a : 1);
|
|
163
166
|
this.g = lerp(
|
|
164
167
|
lerp(
|
|
165
168
|
lerp(data[i0 + 1], data[i1 + 1], bw),
|
|
166
169
|
lerp(data[i2 + 1], data[i3 + 1], bw), gw),
|
|
167
170
|
lerp(
|
|
168
171
|
lerp(data[i4 + 1], data[i5 + 1], bw),
|
|
169
|
-
lerp(data[i6 + 1], data[i7 + 1], bw), gw), rw) / 255 * a;
|
|
172
|
+
lerp(data[i6 + 1], data[i7 + 1], bw), gw), rw) / 255 * (this.premultiplied ? a : 1);
|
|
170
173
|
this.b = lerp(
|
|
171
174
|
lerp(
|
|
172
175
|
lerp(data[i0 + 2], data[i1 + 2], bw),
|
|
173
176
|
lerp(data[i2 + 2], data[i3 + 2], bw), gw),
|
|
174
177
|
lerp(
|
|
175
178
|
lerp(data[i4 + 2], data[i5 + 2], bw),
|
|
176
|
-
lerp(data[i6 + 2], data[i7 + 2], bw), gw), rw) / 255 * a;
|
|
179
|
+
lerp(data[i6 + 2], data[i7 + 2], bw), gw), rw) / 255 * (this.premultiplied ? a : 1);
|
|
177
180
|
this.a = a;
|
|
178
181
|
}
|
|
179
182
|
}
|
|
180
183
|
|
|
181
184
|
/**
|
|
182
|
-
* Returns an RGBA array of values representing the color
|
|
183
|
-
*
|
|
185
|
+
* Returns an RGBA array of values representing the color.
|
|
184
186
|
* @returns An array of RGBA color values in the range [0, 255].
|
|
185
187
|
*/
|
|
186
188
|
toArray(): [number, number, number, number] {
|
|
187
189
|
const {r, g, b, a} = this;
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
190
|
+
|
|
191
|
+
return [
|
|
192
|
+
r * 255,
|
|
193
|
+
g * 255,
|
|
194
|
+
b * 255,
|
|
192
195
|
a
|
|
193
196
|
];
|
|
197
|
+
|
|
194
198
|
}
|
|
195
199
|
|
|
196
200
|
/**
|
|
197
201
|
* Returns an HSLA array of values representing the color, unpremultiplied by A.
|
|
198
|
-
*
|
|
199
202
|
* @returns An array of HSLA color values.
|
|
200
203
|
*/
|
|
201
204
|
toHslaArray(): [number, number, number, number] {
|
|
202
|
-
|
|
203
|
-
|
|
205
|
+
let {r, g, b, a} = this;
|
|
206
|
+
|
|
207
|
+
if (this.premultiplied) {
|
|
208
|
+
if (a === 0) return [0, 0, 0, 0];
|
|
209
|
+
|
|
210
|
+
r /= a;
|
|
211
|
+
g /= a;
|
|
212
|
+
b /= a;
|
|
204
213
|
}
|
|
205
|
-
const {r, g, b, a} = this;
|
|
206
214
|
|
|
207
|
-
const red = Math.min(Math.max(r
|
|
208
|
-
const green = Math.min(Math.max(g
|
|
209
|
-
const blue = Math.min(Math.max(b
|
|
215
|
+
const red = Math.min(Math.max(r, 0.0), 1.0);
|
|
216
|
+
const green = Math.min(Math.max(g, 0.0), 1.0);
|
|
217
|
+
const blue = Math.min(Math.max(b, 0.0), 1.0);
|
|
210
218
|
|
|
211
219
|
const min = Math.min(red, green, blue);
|
|
212
220
|
const max = Math.max(red, green, blue);
|
|
@@ -241,16 +249,17 @@ export class RenderColor {
|
|
|
241
249
|
}
|
|
242
250
|
|
|
243
251
|
/**
|
|
244
|
-
* Returns a RGBA array of float values representing the color
|
|
252
|
+
* Returns a RGBA array of float values representing the color.
|
|
245
253
|
*
|
|
246
254
|
* @returns An array of RGBA color values in the range [0, 1].
|
|
247
255
|
*/
|
|
248
256
|
toArray01(): [number, number, number, number] {
|
|
249
257
|
const {r, g, b, a} = this;
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
258
|
+
|
|
259
|
+
return [
|
|
260
|
+
r,
|
|
261
|
+
g,
|
|
262
|
+
b,
|
|
254
263
|
a
|
|
255
264
|
];
|
|
256
265
|
}
|
|
@@ -262,46 +271,53 @@ export class RenderColor {
|
|
|
262
271
|
* @returns An array of RGB color values in the range [0, 1].
|
|
263
272
|
*/
|
|
264
273
|
toArray01Scaled(scale: number): [number, number, number] {
|
|
265
|
-
const {r, g, b
|
|
266
|
-
return a === 0 ? [0, 0, 0] : [
|
|
267
|
-
(r / a) * scale,
|
|
268
|
-
(g / a) * scale,
|
|
269
|
-
(b / a) * scale
|
|
270
|
-
];
|
|
271
|
-
}
|
|
274
|
+
const {r, g, b} = this;
|
|
272
275
|
|
|
273
|
-
/**
|
|
274
|
-
* Returns an RGBA array of values representing the color, premultiplied by A.
|
|
275
|
-
*
|
|
276
|
-
* @returns An array of RGBA color values in the range [0, 1].
|
|
277
|
-
*/
|
|
278
|
-
toArray01PremultipliedAlpha(): [number, number, number, number] {
|
|
279
|
-
const {r, g, b, a} = this;
|
|
280
276
|
return [
|
|
281
|
-
r,
|
|
282
|
-
g,
|
|
283
|
-
b
|
|
284
|
-
a
|
|
277
|
+
r * scale,
|
|
278
|
+
g * scale,
|
|
279
|
+
b * scale
|
|
285
280
|
];
|
|
286
281
|
}
|
|
287
282
|
|
|
288
283
|
/**
|
|
289
|
-
* Returns an RGBA array of values representing the color
|
|
290
|
-
* The color is defined by sRGB primaries, but the sRGB transfer function
|
|
291
|
-
*
|
|
284
|
+
* Returns an RGBA array of values representing the color converted to linear color space.
|
|
285
|
+
* The color is defined by sRGB primaries, but the sRGB transfer function
|
|
286
|
+
* is reversed to obtain linear energy.
|
|
292
287
|
* @returns An array of RGBA color values in the range [0, 1].
|
|
293
288
|
*/
|
|
294
289
|
toArray01Linear(): [number, number, number, number] {
|
|
295
290
|
const {r, g, b, a} = this;
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
Math.pow(
|
|
299
|
-
Math.pow(
|
|
291
|
+
|
|
292
|
+
return [
|
|
293
|
+
Math.pow(r, 2.2),
|
|
294
|
+
Math.pow(g, 2.2),
|
|
295
|
+
Math.pow(b, 2.2),
|
|
300
296
|
a
|
|
301
297
|
];
|
|
302
298
|
}
|
|
303
299
|
}
|
|
304
300
|
|
|
301
|
+
/**
|
|
302
|
+
* Renderable color created from a Color and an optional LUT value.
|
|
303
|
+
* Represent a color value with non-premultiplied alpha.
|
|
304
|
+
*/
|
|
305
|
+
export class NonPremultipliedRenderColor extends RenderColor {
|
|
306
|
+
constructor(lut: LUT | null, r: number, g: number, b: number, a: number) {
|
|
307
|
+
super(lut, r, g, b, a, false);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Renderable color created from a Color and an optional LUT value.
|
|
313
|
+
* Represent a color value with premultiplied alpha.
|
|
314
|
+
*/
|
|
315
|
+
export class PremultipliedRenderColor extends RenderColor {
|
|
316
|
+
constructor(lut: LUT | null, r: number, g: number, b: number, a: number) {
|
|
317
|
+
super(lut, r, g, b, a, true);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
305
321
|
Color.black = new Color(0, 0, 0, 1);
|
|
306
322
|
Color.white = new Color(1, 1, 1, 1);
|
|
307
323
|
Color.transparent = new Color(0, 0, 0, 0);
|
package/util/interpolate.ts
CHANGED
|
@@ -70,7 +70,26 @@ export default function validateLights(options: Options): Array<ValidationError>
|
|
|
70
70
|
return errors;
|
|
71
71
|
}
|
|
72
72
|
for (const propertyKey in properties) {
|
|
73
|
-
|
|
73
|
+
const transitionMatch = propertyKey.match(/^(.*)-transition$/);
|
|
74
|
+
const useThemeMatch = propertyKey.match(/^(.*)-use-theme$/);
|
|
75
|
+
|
|
76
|
+
if (useThemeMatch && lightPropertySpec[useThemeMatch[1]]) {
|
|
77
|
+
errors = errors.concat(validate({
|
|
78
|
+
key,
|
|
79
|
+
value: properties[propertyKey],
|
|
80
|
+
valueSpec: {type: 'string'},
|
|
81
|
+
style,
|
|
82
|
+
styleSpec
|
|
83
|
+
}));
|
|
84
|
+
} else if (transitionMatch && lightPropertySpec[transitionMatch[1]] && lightPropertySpec[transitionMatch[1]].transition) {
|
|
85
|
+
errors = errors.concat(validate({
|
|
86
|
+
key,
|
|
87
|
+
value: light[key],
|
|
88
|
+
valueSpec: styleSpec.transition,
|
|
89
|
+
style,
|
|
90
|
+
styleSpec
|
|
91
|
+
}));
|
|
92
|
+
} else if (!lightPropertySpec[propertyKey]) {
|
|
74
93
|
errors = errors.concat([new ValidationWarning(options.key, properties[propertyKey], `unknown property "${propertyKey}"`)]);
|
|
75
94
|
} else {
|
|
76
95
|
errors = errors.concat(validate({
|
|
@@ -83,26 +102,7 @@ export default function validateLights(options: Options): Array<ValidationError>
|
|
|
83
102
|
}
|
|
84
103
|
}
|
|
85
104
|
} else {
|
|
86
|
-
|
|
87
|
-
const useThemeMatch = key.match(/^(.*)-use-theme$/);
|
|
88
|
-
|
|
89
|
-
if (useThemeMatch && lightSpec[useThemeMatch[1]]) {
|
|
90
|
-
errors = errors.concat(validate({
|
|
91
|
-
key,
|
|
92
|
-
value: light[key],
|
|
93
|
-
valueSpec: {type: 'string'},
|
|
94
|
-
style,
|
|
95
|
-
styleSpec
|
|
96
|
-
}));
|
|
97
|
-
} else if (transitionMatch && lightSpec[transitionMatch[1]] && lightSpec[transitionMatch[1]].transition) {
|
|
98
|
-
errors = errors.concat(validate({
|
|
99
|
-
key,
|
|
100
|
-
value: light[key],
|
|
101
|
-
valueSpec: styleSpec.transition,
|
|
102
|
-
style,
|
|
103
|
-
styleSpec
|
|
104
|
-
}));
|
|
105
|
-
} else if (lightSpec[key]) {
|
|
105
|
+
if (lightSpec[key]) {
|
|
106
106
|
errors = errors.concat(validate({
|
|
107
107
|
key,
|
|
108
108
|
value: light[key],
|