@mapwhit/tilerenderer 0.50.0 → 0.51.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.
Files changed (142) hide show
  1. package/build/min/package.json +1 -1
  2. package/build/min/src/shaders/.dir +0 -0
  3. package/build/min/src/shaders/_prelude.fragment.glsl.js +14 -0
  4. package/build/min/src/shaders/_prelude.vertex.glsl.js +14 -0
  5. package/build/min/src/shaders/background.fragment.glsl.js +5 -0
  6. package/build/min/src/shaders/background.vertex.glsl.js +1 -0
  7. package/build/min/src/shaders/background_pattern.fragment.glsl.js +5 -0
  8. package/build/min/src/shaders/background_pattern.vertex.glsl.js +1 -0
  9. package/build/min/src/shaders/circle.fragment.glsl.js +20 -0
  10. package/build/min/src/shaders/circle.vertex.glsl.js +17 -0
  11. package/build/min/src/shaders/clipping_mask.fragment.glsl.js +1 -0
  12. package/build/min/src/shaders/clipping_mask.vertex.glsl.js +1 -0
  13. package/build/min/src/shaders/collision_box.fragment.glsl.js +1 -0
  14. package/build/min/src/shaders/collision_box.vertex.glsl.js +1 -0
  15. package/build/min/src/shaders/collision_circle.fragment.glsl.js +1 -0
  16. package/build/min/src/shaders/collision_circle.vertex.glsl.js +1 -0
  17. package/build/min/src/shaders/debug.fragment.glsl.js +1 -0
  18. package/build/min/src/shaders/debug.vertex.glsl.js +1 -0
  19. package/build/min/src/shaders/fill.fragment.glsl.js +10 -0
  20. package/build/min/src/shaders/fill.vertex.glsl.js +7 -0
  21. package/build/min/src/shaders/fill_extrusion.fragment.glsl.js +5 -0
  22. package/build/min/src/shaders/fill_extrusion.vertex.glsl.js +9 -0
  23. package/build/min/src/shaders/fill_extrusion_pattern.fragment.glsl.js +15 -0
  24. package/build/min/src/shaders/fill_extrusion_pattern.vertex.glsl.js +11 -0
  25. package/build/min/src/shaders/fill_outline.fragment.glsl.js +10 -0
  26. package/build/min/src/shaders/fill_outline.vertex.glsl.js +7 -0
  27. package/build/min/src/shaders/fill_outline_pattern.fragment.glsl.js +13 -0
  28. package/build/min/src/shaders/fill_outline_pattern.vertex.glsl.js +9 -0
  29. package/build/min/src/shaders/fill_pattern.fragment.glsl.js +13 -0
  30. package/build/min/src/shaders/fill_pattern.vertex.glsl.js +9 -0
  31. package/build/min/src/shaders/heatmap.fragment.glsl.js +10 -0
  32. package/build/min/src/shaders/heatmap.vertex.glsl.js +8 -0
  33. package/build/min/src/shaders/heatmap_texture.fragment.glsl.js +5 -0
  34. package/build/min/src/shaders/heatmap_texture.vertex.glsl.js +1 -0
  35. package/build/min/src/shaders/hillshade.fragment.glsl.js +7 -0
  36. package/build/min/src/shaders/hillshade.vertex.glsl.js +1 -0
  37. package/build/min/src/shaders/hillshade_prepare.fragment.glsl.js +8 -0
  38. package/build/min/src/shaders/hillshade_prepare.vertex.glsl.js +1 -0
  39. package/build/min/src/shaders/line.fragment.glsl.js +12 -0
  40. package/build/min/src/shaders/line.vertex.glsl.js +17 -0
  41. package/build/min/src/shaders/line_gradient.fragment.glsl.js +10 -0
  42. package/build/min/src/shaders/line_gradient.vertex.glsl.js +16 -0
  43. package/build/min/src/shaders/line_pattern.fragment.glsl.js +15 -0
  44. package/build/min/src/shaders/line_pattern.vertex.glsl.js +20 -0
  45. package/build/min/src/shaders/line_sdf.fragment.glsl.js +17 -0
  46. package/build/min/src/shaders/line_sdf.vertex.glsl.js +20 -0
  47. package/build/min/src/shaders/raster.fragment.glsl.js +5 -0
  48. package/build/min/src/shaders/raster.vertex.glsl.js +1 -0
  49. package/build/min/src/shaders/symbol_icon.fragment.glsl.js +9 -0
  50. package/build/min/src/shaders/symbol_icon.vertex.glsl.js +5 -0
  51. package/build/min/src/shaders/symbol_sdf.fragment.glsl.js +19 -0
  52. package/build/min/src/shaders/symbol_sdf.vertex.glsl.js +13 -0
  53. package/package.json +7 -7
  54. package/src/data/bucket/fill_bucket.js +1 -1
  55. package/src/data/bucket/fill_extrusion_bucket.js +2 -2
  56. package/src/data/bucket/line_bucket.js +1 -1
  57. package/src/data/bucket/symbol_bucket.js +2 -2
  58. package/src/data/feature_index.js +1 -1
  59. package/src/data/program_configuration.js +1 -1
  60. package/src/gl/color_mode.js +1 -1
  61. package/src/gl/value.js +1 -1
  62. package/src/render/draw_debug.js +1 -1
  63. package/src/render/draw_fill.js +1 -1
  64. package/src/render/draw_heatmap.js +1 -1
  65. package/src/render/glyph_manager.js +6 -130
  66. package/src/render/painter.js +1 -1
  67. package/src/render/uniform_binding.js +1 -1
  68. package/src/shaders/index.js +50 -50
  69. package/src/source/geojson_worker_source.js +4 -4
  70. package/src/source/geojson_wrapper.js +34 -26
  71. package/src/source/resources/glyphs.js +73 -0
  72. package/src/source/resources/images.js +68 -0
  73. package/src/source/resources/index.js +22 -0
  74. package/src/source/vector_tile_worker_source.js +5 -5
  75. package/src/source/worker.js +6 -5
  76. package/src/source/worker_tile.js +4 -4
  77. package/src/style/properties.js +1 -2
  78. package/src/style/style.js +3 -3
  79. package/src/style/style_layer/symbol_style_layer.js +1 -1
  80. package/src/style/style_layer.js +1 -1
  81. package/src/style-spec/feature_filter/index.js +43 -34
  82. package/src/style-spec/group_by_layout.js +10 -32
  83. package/src/symbol/mergelines.js +0 -2
  84. package/src/symbol/symbol_layout.js +0 -1
  85. package/src/symbol/symbol_size.js +1 -1
  86. package/src/symbol/transform_text.js +0 -1
  87. package/src/ui/map.js +11 -39
  88. package/src/util/browser.js +3 -18
  89. package/src/util/classify_rings.js +1 -1
  90. package/src/util/dom.js +0 -88
  91. package/src/util/find_pole_of_inaccessibility.js +2 -2
  92. package/src/util/web_worker_transfer.js +4 -4
  93. package/src/style/load_glyph_range.js +0 -17
  94. package/src/style-spec/expression/compound_expression.js +0 -132
  95. package/src/style-spec/expression/definitions/assertion.js +0 -116
  96. package/src/style-spec/expression/definitions/at.js +0 -57
  97. package/src/style-spec/expression/definitions/case.js +0 -73
  98. package/src/style-spec/expression/definitions/coalesce.js +0 -66
  99. package/src/style-spec/expression/definitions/coercion.js +0 -120
  100. package/src/style-spec/expression/definitions/collator.js +0 -80
  101. package/src/style-spec/expression/definitions/comparison.js +0 -193
  102. package/src/style-spec/expression/definitions/format.js +0 -97
  103. package/src/style-spec/expression/definitions/index.js +0 -339
  104. package/src/style-spec/expression/definitions/interpolate.js +0 -245
  105. package/src/style-spec/expression/definitions/length.js +0 -54
  106. package/src/style-spec/expression/definitions/let.js +0 -60
  107. package/src/style-spec/expression/definitions/literal.js +0 -69
  108. package/src/style-spec/expression/definitions/match.js +0 -142
  109. package/src/style-spec/expression/definitions/step.js +0 -116
  110. package/src/style-spec/expression/definitions/var.js +0 -38
  111. package/src/style-spec/expression/evaluation_context.js +0 -38
  112. package/src/style-spec/expression/index.js +0 -330
  113. package/src/style-spec/expression/is_constant.js +0 -63
  114. package/src/style-spec/expression/parsing_context.js +0 -221
  115. package/src/style-spec/expression/parsing_error.js +0 -9
  116. package/src/style-spec/expression/runtime_error.js +0 -12
  117. package/src/style-spec/expression/scope.js +0 -34
  118. package/src/style-spec/expression/stops.js +0 -37
  119. package/src/style-spec/expression/types/collator.js +0 -24
  120. package/src/style-spec/expression/types/formatted.js +0 -39
  121. package/src/style-spec/expression/types.js +0 -88
  122. package/src/style-spec/expression/values.js +0 -149
  123. package/src/style-spec/function/convert.js +0 -240
  124. package/src/style-spec/function/index.js +0 -303
  125. package/src/style-spec/util/color.js +0 -73
  126. package/src/style-spec/util/color_spaces.js +0 -128
  127. package/src/style-spec/util/get_type.js +0 -18
  128. package/src/style-spec/util/interpolate.js +0 -21
  129. package/src/style-spec/util/properties.js +0 -17
  130. package/src/style-spec/util/result.js +0 -19
  131. package/src/ui/anchor.js +0 -24
  132. package/src/ui/bind_handlers.js +0 -199
  133. package/src/ui/events.js +0 -210
  134. package/src/ui/handler/box_zoom.js +0 -151
  135. package/src/ui/handler/dblclick_zoom.js +0 -91
  136. package/src/ui/handler/drag_pan.js +0 -285
  137. package/src/ui/handler/drag_rotate.js +0 -290
  138. package/src/ui/handler/frame.js +0 -28
  139. package/src/ui/handler/inertia.js +0 -45
  140. package/src/ui/handler/keyboard.js +0 -148
  141. package/src/ui/handler/scroll_zoom.js +0 -284
  142. package/src/ui/handler/touch_zoom_rotate.js +0 -263
@@ -1,120 +0,0 @@
1
- const assert = require('assert');
2
-
3
- const { BooleanType, ColorType, NumberType, StringType, ValueType } = require('../types');
4
- const { Color, toString: valueToString, validateRGBA } = require('../values');
5
- const RuntimeError = require('../runtime_error');
6
- const { FormatExpression } = require('../definitions/format');
7
- const { Formatted } = require('../types/formatted');
8
-
9
- const types = {
10
- 'to-boolean': BooleanType,
11
- 'to-color': ColorType,
12
- 'to-number': NumberType,
13
- 'to-string': StringType
14
- };
15
-
16
- /**
17
- * Special form for error-coalescing coercion expressions "to-number",
18
- * "to-color". Since these coercions can fail at runtime, they accept multiple
19
- * arguments, only evaluating one at a time until one succeeds.
20
- *
21
- * @private
22
- */
23
- class Coercion {
24
- constructor(type, args) {
25
- this.type = type;
26
- this.args = args;
27
- }
28
-
29
- static parse(args, context) {
30
- if (args.length < 2) return context.error('Expected at least one argument.');
31
-
32
- const name = args[0];
33
- assert(types[name], name);
34
-
35
- if ((name === 'to-boolean' || name === 'to-string') && args.length !== 2)
36
- return context.error('Expected one argument.');
37
-
38
- const type = types[name];
39
-
40
- const parsed = [];
41
- for (let i = 1; i < args.length; i++) {
42
- const input = context.parse(args[i], i, ValueType);
43
- if (!input) return null;
44
- parsed.push(input);
45
- }
46
-
47
- return new Coercion(type, parsed);
48
- }
49
-
50
- evaluate(ctx) {
51
- if (this.type.kind === 'boolean') {
52
- return Boolean(this.args[0].evaluate(ctx));
53
- }
54
- if (this.type.kind === 'color') {
55
- let input;
56
- let error;
57
- for (const arg of this.args) {
58
- input = arg.evaluate(ctx);
59
- error = null;
60
- if (input instanceof Color) {
61
- return input;
62
- }
63
- if (typeof input === 'string') {
64
- const c = ctx.parseColor(input);
65
- if (c) return c;
66
- } else if (Array.isArray(input)) {
67
- if (input.length < 3 || input.length > 4) {
68
- error = `Invalid rbga value ${JSON.stringify(input)}: expected an array containing either three or four numeric values.`;
69
- } else {
70
- error = validateRGBA(input[0], input[1], input[2], input[3]);
71
- }
72
- if (!error) {
73
- return new Color(input[0] / 255, input[1] / 255, input[2] / 255, input[3]);
74
- }
75
- }
76
- }
77
- throw new RuntimeError(
78
- error || `Could not parse color from value '${typeof input === 'string' ? input : JSON.stringify(input)}'`
79
- );
80
- }
81
- if (this.type.kind === 'number') {
82
- let value = null;
83
- for (const arg of this.args) {
84
- value = arg.evaluate(ctx);
85
- if (value === null) return 0;
86
- const num = Number(value);
87
- if (isNaN(num)) continue;
88
- return num;
89
- }
90
- throw new RuntimeError(`Could not convert ${JSON.stringify(value)} to number.`);
91
- }
92
- if (this.type.kind === 'formatted') {
93
- // There is no explicit 'to-formatted' but this coercion can be implicitly
94
- // created by properties that expect the 'formatted' type.
95
- return Formatted.fromString(valueToString(this.args[0].evaluate(ctx)));
96
- }
97
- return valueToString(this.args[0].evaluate(ctx));
98
- }
99
-
100
- eachChild(fn) {
101
- this.args.forEach(fn);
102
- }
103
-
104
- possibleOutputs() {
105
- return [].concat(...this.args.map(arg => arg.possibleOutputs()));
106
- }
107
-
108
- serialize() {
109
- if (this.type.kind === 'formatted') {
110
- return new FormatExpression([{ text: this.args[0], scale: null, font: null }]).serialize();
111
- }
112
- const serialized = [`to-${this.type.kind}`];
113
- this.eachChild(child => {
114
- serialized.push(child.serialize());
115
- });
116
- return serialized;
117
- }
118
- }
119
-
120
- module.exports = Coercion;
@@ -1,80 +0,0 @@
1
- const { StringType, BooleanType, CollatorType } = require('../types');
2
- const { Collator } = require('../types/collator');
3
-
4
- class CollatorExpression {
5
- constructor(caseSensitive, diacriticSensitive, locale) {
6
- this.type = CollatorType;
7
- this.locale = locale;
8
- this.caseSensitive = caseSensitive;
9
- this.diacriticSensitive = diacriticSensitive;
10
- }
11
-
12
- static parse(args, context) {
13
- if (args.length !== 2) return context.error('Expected one argument.');
14
-
15
- const options = args[1];
16
- if (typeof options !== 'object' || Array.isArray(options))
17
- return context.error('Collator options argument must be an object.');
18
-
19
- const caseSensitive = context.parse(
20
- options['case-sensitive'] === undefined ? false : options['case-sensitive'],
21
- 1,
22
- BooleanType
23
- );
24
- if (!caseSensitive) return null;
25
-
26
- const diacriticSensitive = context.parse(
27
- options['diacritic-sensitive'] === undefined ? false : options['diacritic-sensitive'],
28
- 1,
29
- BooleanType
30
- );
31
- if (!diacriticSensitive) return null;
32
-
33
- let locale = null;
34
- if (options['locale']) {
35
- locale = context.parse(options['locale'], 1, StringType);
36
- if (!locale) return null;
37
- }
38
-
39
- return new CollatorExpression(caseSensitive, diacriticSensitive, locale);
40
- }
41
-
42
- evaluate(ctx) {
43
- return new Collator(
44
- this.caseSensitive.evaluate(ctx),
45
- this.diacriticSensitive.evaluate(ctx),
46
- this.locale ? this.locale.evaluate(ctx) : null
47
- );
48
- }
49
-
50
- eachChild(fn) {
51
- fn(this.caseSensitive);
52
- fn(this.diacriticSensitive);
53
- if (this.locale) {
54
- fn(this.locale);
55
- }
56
- }
57
-
58
- possibleOutputs() {
59
- // Technically the set of possible outputs is the combinatoric set of Collators produced
60
- // by all possibleOutputs of locale/caseSensitive/diacriticSensitive
61
- // But for the primary use of Collators in comparison operators, we ignore the Collator's
62
- // possibleOutputs anyway, so we can get away with leaving this undefined for now.
63
- return [undefined];
64
- }
65
-
66
- serialize() {
67
- const options = {};
68
- options['case-sensitive'] = this.caseSensitive.serialize();
69
- options['diacritic-sensitive'] = this.diacriticSensitive.serialize();
70
- if (this.locale) {
71
- options['locale'] = this.locale.serialize();
72
- }
73
- return ['collator', options];
74
- }
75
- }
76
-
77
- module.exports = {
78
- Collator,
79
- CollatorExpression
80
- };
@@ -1,193 +0,0 @@
1
- const { toString, ValueType, BooleanType, CollatorType } = require('../types');
2
- const Assertion = require('./assertion');
3
- const { typeOf } = require('../values');
4
- const RuntimeError = require('../runtime_error');
5
-
6
- function isComparableType(op, type) {
7
- if (op === '==' || op === '!=') {
8
- // equality operator
9
- return (
10
- type.kind === 'boolean' ||
11
- type.kind === 'string' ||
12
- type.kind === 'number' ||
13
- type.kind === 'null' ||
14
- type.kind === 'value'
15
- );
16
- }
17
- // ordering operator
18
- return type.kind === 'string' || type.kind === 'number' || type.kind === 'value';
19
- }
20
-
21
- function eq(ctx, a, b) {
22
- return a === b;
23
- }
24
- function neq(ctx, a, b) {
25
- return a !== b;
26
- }
27
- function lt(ctx, a, b) {
28
- return a < b;
29
- }
30
- function gt(ctx, a, b) {
31
- return a > b;
32
- }
33
- function lteq(ctx, a, b) {
34
- return a <= b;
35
- }
36
- function gteq(ctx, a, b) {
37
- return a >= b;
38
- }
39
-
40
- function eqCollate(ctx, a, b, c) {
41
- return c.compare(a, b) === 0;
42
- }
43
- function neqCollate(ctx, a, b, c) {
44
- return !eqCollate(ctx, a, b, c);
45
- }
46
- function ltCollate(ctx, a, b, c) {
47
- return c.compare(a, b) < 0;
48
- }
49
- function gtCollate(ctx, a, b, c) {
50
- return c.compare(a, b) > 0;
51
- }
52
- function lteqCollate(ctx, a, b, c) {
53
- return c.compare(a, b) <= 0;
54
- }
55
- function gteqCollate(ctx, a, b, c) {
56
- return c.compare(a, b) >= 0;
57
- }
58
-
59
- /**
60
- * Special form for comparison operators, implementing the signatures:
61
- * - (T, T, ?Collator) => boolean
62
- * - (T, value, ?Collator) => boolean
63
- * - (value, T, ?Collator) => boolean
64
- *
65
- * For inequalities, T must be either value, string, or number. For ==/!=, it
66
- * can also be boolean or null.
67
- *
68
- * Equality semantics are equivalent to Javascript's strict equality (===/!==)
69
- * -- i.e., when the arguments' types don't match, == evaluates to false, != to
70
- * true.
71
- *
72
- * When types don't match in an ordering comparison, a runtime error is thrown.
73
- *
74
- * @private
75
- */
76
- function makeComparison(op, compareBasic, compareWithCollator) {
77
- const isOrderComparison = op !== '==' && op !== '!=';
78
-
79
- return class Comparison {
80
- constructor(lhs, rhs, collator) {
81
- this.type = BooleanType;
82
- this.lhs = lhs;
83
- this.rhs = rhs;
84
- this.collator = collator;
85
- this.hasUntypedArgument = lhs.type.kind === 'value' || rhs.type.kind === 'value';
86
- }
87
-
88
- static parse(args, context) {
89
- if (args.length !== 3 && args.length !== 4) return context.error('Expected two or three arguments.');
90
-
91
- const op = args[0];
92
-
93
- let lhs = context.parse(args[1], 1, ValueType);
94
- if (!lhs) return null;
95
- if (!isComparableType(op, lhs.type)) {
96
- return context.concat(1).error(`"${op}" comparisons are not supported for type '${toString(lhs.type)}'.`);
97
- }
98
- let rhs = context.parse(args[2], 2, ValueType);
99
- if (!rhs) return null;
100
- if (!isComparableType(op, rhs.type)) {
101
- return context.concat(2).error(`"${op}" comparisons are not supported for type '${toString(rhs.type)}'.`);
102
- }
103
-
104
- if (lhs.type.kind !== rhs.type.kind && lhs.type.kind !== 'value' && rhs.type.kind !== 'value') {
105
- return context.error(`Cannot compare types '${toString(lhs.type)}' and '${toString(rhs.type)}'.`);
106
- }
107
-
108
- if (isOrderComparison) {
109
- // typing rules specific to less/greater than operators
110
- if (lhs.type.kind === 'value' && rhs.type.kind !== 'value') {
111
- // (value, T)
112
- lhs = new Assertion(rhs.type, [lhs]);
113
- } else if (lhs.type.kind !== 'value' && rhs.type.kind === 'value') {
114
- // (T, value)
115
- rhs = new Assertion(lhs.type, [rhs]);
116
- }
117
- }
118
-
119
- let collator = null;
120
- if (args.length === 4) {
121
- if (
122
- lhs.type.kind !== 'string' &&
123
- rhs.type.kind !== 'string' &&
124
- lhs.type.kind !== 'value' &&
125
- rhs.type.kind !== 'value'
126
- ) {
127
- return context.error('Cannot use collator to compare non-string types.');
128
- }
129
- collator = context.parse(args[3], 3, CollatorType);
130
- if (!collator) return null;
131
- }
132
-
133
- return new Comparison(lhs, rhs, collator);
134
- }
135
-
136
- evaluate(ctx) {
137
- const lhs = this.lhs.evaluate(ctx);
138
- const rhs = this.rhs.evaluate(ctx);
139
-
140
- if (isOrderComparison && this.hasUntypedArgument) {
141
- const lt = typeOf(lhs);
142
- const rt = typeOf(rhs);
143
- // check that type is string or number, and equal
144
- if (lt.kind !== rt.kind || !(lt.kind === 'string' || lt.kind === 'number')) {
145
- throw new RuntimeError(
146
- `Expected arguments for "${op}" to be (string, string) or (number, number), but found (${lt.kind}, ${rt.kind}) instead.`
147
- );
148
- }
149
- }
150
-
151
- if (this.collator && !isOrderComparison && this.hasUntypedArgument) {
152
- const lt = typeOf(lhs);
153
- const rt = typeOf(rhs);
154
- if (lt.kind !== 'string' || rt.kind !== 'string') {
155
- return compareBasic(ctx, lhs, rhs);
156
- }
157
- }
158
-
159
- return this.collator
160
- ? compareWithCollator(ctx, lhs, rhs, this.collator.evaluate(ctx))
161
- : compareBasic(ctx, lhs, rhs);
162
- }
163
-
164
- eachChild(fn) {
165
- fn(this.lhs);
166
- fn(this.rhs);
167
- if (this.collator) {
168
- fn(this.collator);
169
- }
170
- }
171
-
172
- possibleOutputs() {
173
- return [true, false];
174
- }
175
-
176
- serialize() {
177
- const serialized = [op];
178
- this.eachChild(child => {
179
- serialized.push(child.serialize());
180
- });
181
- return serialized;
182
- }
183
- };
184
- }
185
-
186
- module.exports = {
187
- Equals: makeComparison('==', eq, eqCollate),
188
- NotEquals: makeComparison('!=', neq, neqCollate),
189
- LessThan: makeComparison('<', lt, ltCollate),
190
- GreaterThan: makeComparison('>', gt, gtCollate),
191
- LessThanOrEqual: makeComparison('<=', lteq, lteqCollate),
192
- GreaterThanOrEqual: makeComparison('>=', gteq, gteqCollate)
193
- };
@@ -1,97 +0,0 @@
1
- const { NumberType, ValueType, FormattedType, array, StringType } = require('../types');
2
- const { Formatted, FormattedSection } = require('../types/formatted');
3
- const { toString } = require('../values');
4
-
5
- class FormatExpression {
6
- constructor(sections) {
7
- this.type = FormattedType;
8
- this.sections = sections;
9
- }
10
-
11
- static parse(args, context) {
12
- if (args.length < 3) {
13
- return context.error('Expected at least two arguments.');
14
- }
15
-
16
- if ((args.length - 1) % 2 !== 0) {
17
- return context.error('Expected an even number of arguments.');
18
- }
19
-
20
- const sections = [];
21
- for (let i = 1; i < args.length - 1; i += 2) {
22
- const text = context.parse(args[i], 1, ValueType);
23
- if (!text) return null;
24
- const kind = text.type.kind;
25
- if (kind !== 'string' && kind !== 'value' && kind !== 'null')
26
- return context.error("Formatted text type must be 'string', 'value', or 'null'.");
27
-
28
- const options = args[i + 1];
29
- if (typeof options !== 'object' || Array.isArray(options))
30
- return context.error('Format options argument must be an object.');
31
-
32
- let scale = null;
33
- if (options['font-scale']) {
34
- scale = context.parse(options['font-scale'], 1, NumberType);
35
- if (!scale) return null;
36
- }
37
-
38
- let font = null;
39
- if (options['text-font']) {
40
- font = context.parse(options['text-font'], 1, array(StringType));
41
- if (!font) return null;
42
- }
43
- sections.push({ text, scale, font });
44
- }
45
-
46
- return new FormatExpression(sections);
47
- }
48
-
49
- evaluate(ctx) {
50
- return new Formatted(
51
- this.sections.map(
52
- section =>
53
- new FormattedSection(
54
- toString(section.text.evaluate(ctx)),
55
- section.scale ? section.scale.evaluate(ctx) : null,
56
- section.font ? section.font.evaluate(ctx).join(',') : null
57
- )
58
- )
59
- );
60
- }
61
-
62
- eachChild(fn) {
63
- for (const section of this.sections) {
64
- fn(section.text);
65
- if (section.scale) {
66
- fn(section.scale);
67
- }
68
- if (section.font) {
69
- fn(section.font);
70
- }
71
- }
72
- }
73
-
74
- possibleOutputs() {
75
- // Technically the combinatoric set of all children
76
- // Usually, this.text will be undefined anyway
77
- return [undefined];
78
- }
79
-
80
- serialize() {
81
- const serialized = ['format'];
82
- for (const section of this.sections) {
83
- serialized.push(section.text.serialize());
84
- const options = {};
85
- if (section.scale) {
86
- options['font-scale'] = section.scale.serialize();
87
- }
88
- if (section.font) {
89
- options['text-font'] = section.font.serialize();
90
- }
91
- serialized.push(options);
92
- }
93
- return serialized;
94
- }
95
- }
96
-
97
- module.exports = { Formatted, FormatExpression };