ol 7.5.1 → 8.0.0-dev.1692053484481
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/DataTile.d.ts +2 -2
- package/DataTile.d.ts.map +1 -1
- package/DataTile.js +3 -2
- package/Image.d.ts +139 -40
- package/Image.d.ts.map +1 -1
- package/Image.js +194 -96
- package/ImageCanvas.d.ts +2 -2
- package/ImageCanvas.d.ts.map +1 -1
- package/ImageCanvas.js +2 -2
- package/Object.d.ts +7 -0
- package/Object.d.ts.map +1 -1
- package/Object.js +8 -0
- package/dist/ol.js +2 -2
- package/dist/ol.js.map +1 -1
- package/expr/cpu.d.ts +71 -0
- package/expr/cpu.d.ts.map +1 -0
- package/expr/cpu.js +312 -0
- package/expr/expression.d.ts +97 -0
- package/expr/expression.d.ts.map +1 -0
- package/expr/expression.js +373 -0
- package/has.d.ts +5 -0
- package/has.d.ts.map +1 -1
- package/has.js +6 -0
- package/index.d.ts +1 -2
- package/index.js +1 -1
- package/layer/Base.d.ts +12 -8
- package/layer/Base.d.ts.map +1 -1
- package/layer/Base.js +12 -8
- package/layer/BaseVector.d.ts.map +1 -1
- package/layer/BaseVector.js +67 -33
- package/layer/Heatmap.d.ts.map +1 -1
- package/layer/Heatmap.js +16 -55
- package/layer/Layer.d.ts +2 -2
- package/layer/Layer.d.ts.map +1 -1
- package/layer/Layer.js +1 -1
- package/layer/WebGLPoints.d.ts +7 -12
- package/layer/WebGLPoints.d.ts.map +1 -1
- package/layer/WebGLPoints.js +7 -12
- package/package.json +1 -1
- package/render/Feature.d.ts +8 -0
- package/render/Feature.d.ts.map +1 -1
- package/render/Feature.js +9 -0
- package/render/canvas/Immediate.d.ts.map +1 -1
- package/render/canvas/Immediate.js +5 -3
- package/render/canvas/TextBuilder.js +2 -2
- package/render/canvas/style.d.ts +69 -0
- package/render/canvas/style.d.ts.map +1 -0
- package/render/canvas/style.js +1192 -0
- package/render/canvas.js +1 -1
- package/render/webgl/VectorStyleRenderer.d.ts.map +1 -1
- package/render/webgl/VectorStyleRenderer.js +4 -0
- package/renderer/Layer.d.ts +2 -2
- package/renderer/Layer.d.ts.map +1 -1
- package/renderer/Layer.js +1 -1
- package/renderer/canvas/ImageLayer.d.ts +4 -4
- package/renderer/canvas/ImageLayer.d.ts.map +1 -1
- package/renderer/canvas/ImageLayer.js +17 -12
- package/renderer/canvas/Layer.d.ts +2 -2
- package/renderer/canvas/Layer.d.ts.map +1 -1
- package/renderer/canvas/Layer.js +1 -1
- package/renderer/canvas/VectorImageLayer.d.ts.map +1 -1
- package/renderer/canvas/VectorImageLayer.js +3 -2
- package/renderer/webgl/VectorLayer.d.ts +1 -2
- package/renderer/webgl/VectorLayer.d.ts.map +1 -1
- package/reproj/Image.d.ts +5 -5
- package/reproj/Image.d.ts.map +1 -1
- package/reproj/Image.js +6 -6
- package/reproj.d.ts +2 -2
- package/reproj.d.ts.map +1 -1
- package/reproj.js +1 -1
- package/resolution.d.ts +13 -0
- package/resolution.d.ts.map +1 -0
- package/resolution.js +18 -0
- package/source/Image.d.ts +44 -7
- package/source/Image.d.ts.map +1 -1
- package/source/Image.js +97 -8
- package/source/ImageArcGISRest.d.ts +0 -23
- package/source/ImageArcGISRest.d.ts.map +1 -1
- package/source/ImageArcGISRest.js +18 -120
- package/source/ImageMapGuide.d.ts +0 -24
- package/source/ImageMapGuide.d.ts.map +1 -1
- package/source/ImageMapGuide.js +21 -113
- package/source/ImageStatic.d.ts +2 -27
- package/source/ImageStatic.d.ts.map +1 -1
- package/source/ImageStatic.js +20 -70
- package/source/ImageWMS.d.ts +2 -46
- package/source/ImageWMS.d.ts.map +1 -1
- package/source/ImageWMS.js +43 -201
- package/source/{Stamen.d.ts → StadiaMaps.d.ts} +17 -7
- package/source/StadiaMaps.d.ts.map +1 -0
- package/source/{Stamen.js → StadiaMaps.js} +85 -38
- package/source/TileArcGISRest.d.ts.map +1 -1
- package/source/TileArcGISRest.js +11 -22
- package/source/TileWMS.d.ts +0 -1
- package/source/TileWMS.d.ts.map +1 -1
- package/source/TileWMS.js +43 -106
- package/source/arcgisRest.d.ts +88 -0
- package/source/arcgisRest.d.ts.map +1 -0
- package/source/arcgisRest.js +131 -0
- package/source/common.d.ts +5 -0
- package/source/common.d.ts.map +1 -1
- package/source/common.js +6 -0
- package/source/mapguide.d.ts +52 -0
- package/source/mapguide.d.ts.map +1 -0
- package/source/mapguide.js +116 -0
- package/source/static.d.ts +45 -0
- package/source/static.d.ts.map +1 -0
- package/source/static.js +44 -0
- package/source/wms.d.ts +109 -1
- package/source/wms.d.ts.map +1 -1
- package/source/wms.js +170 -0
- package/source.d.ts +5 -1
- package/source.d.ts.map +1 -1
- package/source.js +5 -1
- package/style/flat.d.ts +332 -173
- package/style/flat.d.ts.map +1 -1
- package/style/flat.js +176 -248
- package/style/literal.d.ts +27 -72
- package/style/literal.d.ts.map +1 -1
- package/style/literal.js +14 -35
- package/util.d.ts.map +1 -1
- package/util.js +1 -1
- package/webgl/Helper.d.ts +7 -2
- package/webgl/Helper.d.ts.map +1 -1
- package/webgl/Helper.js +16 -27
- package/webgl/ShaderBuilder.d.ts +4 -14
- package/webgl/ShaderBuilder.d.ts.map +1 -1
- package/webgl/ShaderBuilder.js +72 -72
- package/webgl/styleparser.d.ts +3 -9
- package/webgl/styleparser.d.ts.map +1 -1
- package/webgl/styleparser.js +503 -88
- package/ImageBase.d.ts +0 -65
- package/ImageBase.d.ts.map +0 -1
- package/ImageBase.js +0 -98
- package/source/Stamen.d.ts.map +0 -1
package/expr/cpu.d.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview This module includes functions to build expressions for evaluation on the CPU.
|
|
3
|
+
* Building is composed of two steps: parsing and compiling. The parsing step takes an encoded
|
|
4
|
+
* expression and returns an instance of one of the expression classes. The compiling step takes
|
|
5
|
+
* the expression instance and returns a function that can be evaluated in to return a literal
|
|
6
|
+
* value. The evaluator function should do as little allocation and work as possible.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* @typedef {Object} EvaluationContext
|
|
10
|
+
* @property {Object} properties The values for properties used in 'get' expressions.
|
|
11
|
+
* @property {Object} variables The values for variables used in 'var' expressions.
|
|
12
|
+
* @property {number} resolution The map resolution.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* @return {EvaluationContext} A new evaluation context.
|
|
16
|
+
*/
|
|
17
|
+
export function newEvaluationContext(): EvaluationContext;
|
|
18
|
+
/**
|
|
19
|
+
* @typedef {function(EvaluationContext):import("./expression.js").LiteralValue} ExpressionEvaluator
|
|
20
|
+
*/
|
|
21
|
+
/**
|
|
22
|
+
* @typedef {function(EvaluationContext):boolean} BooleanEvaluator
|
|
23
|
+
*/
|
|
24
|
+
/**
|
|
25
|
+
* @typedef {function(EvaluationContext):number} NumberEvaluator
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* @typedef {function(EvaluationContext):string} StringEvaluator
|
|
29
|
+
*/
|
|
30
|
+
/**
|
|
31
|
+
* @typedef {function(EvaluationContext):(Array<number>|string)} ColorLikeEvaluator
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* @typedef {function(EvaluationContext):Array<number>} NumberArrayEvaluator
|
|
35
|
+
*/
|
|
36
|
+
/**
|
|
37
|
+
* @typedef {function(EvaluationContext):Array<number>} CoordinateEvaluator
|
|
38
|
+
*/
|
|
39
|
+
/**
|
|
40
|
+
* @typedef {function(EvaluationContext):(Array<number>|number)} SizeLikeEvaluator
|
|
41
|
+
*/
|
|
42
|
+
/**
|
|
43
|
+
* @param {import('./expression.js').EncodedExpression} encoded The encoded expression.
|
|
44
|
+
* @param {number} type The expected type.
|
|
45
|
+
* @param {import('./expression.js').ParsingContext} context The parsing context.
|
|
46
|
+
* @return {ExpressionEvaluator} The expression evaluator.
|
|
47
|
+
*/
|
|
48
|
+
export function buildExpression(encoded: import('./expression.js').EncodedExpression, type: number, context: import('./expression.js').ParsingContext): ExpressionEvaluator;
|
|
49
|
+
export type EvaluationContext = {
|
|
50
|
+
/**
|
|
51
|
+
* The values for properties used in 'get' expressions.
|
|
52
|
+
*/
|
|
53
|
+
properties: any;
|
|
54
|
+
/**
|
|
55
|
+
* The values for variables used in 'var' expressions.
|
|
56
|
+
*/
|
|
57
|
+
variables: any;
|
|
58
|
+
/**
|
|
59
|
+
* The map resolution.
|
|
60
|
+
*/
|
|
61
|
+
resolution: number;
|
|
62
|
+
};
|
|
63
|
+
export type ExpressionEvaluator = (arg0: EvaluationContext) => import("./expression.js").LiteralValue;
|
|
64
|
+
export type BooleanEvaluator = (arg0: EvaluationContext) => boolean;
|
|
65
|
+
export type NumberEvaluator = (arg0: EvaluationContext) => number;
|
|
66
|
+
export type StringEvaluator = (arg0: EvaluationContext) => string;
|
|
67
|
+
export type ColorLikeEvaluator = (arg0: EvaluationContext) => (Array<number> | string);
|
|
68
|
+
export type NumberArrayEvaluator = (arg0: EvaluationContext) => Array<number>;
|
|
69
|
+
export type CoordinateEvaluator = (arg0: EvaluationContext) => Array<number>;
|
|
70
|
+
export type SizeLikeEvaluator = (arg0: EvaluationContext) => (Array<number> | number);
|
|
71
|
+
//# sourceMappingURL=cpu.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cpu.d.ts","sourceRoot":"","sources":["cpu.js"],"names":[],"mappings":"AAYA;;;;;;GAMG;AAEH;;;;;GAKG;AAEH;;GAEG;AACH,wCAFY,iBAAiB,CAQ5B;AAED;;GAEG;AAEH;;GAEG;AAEH;;GAEG;AAEH;;GAEG;AAEH;;GAEG;AAEH;;GAEG;AAEH;;GAEG;AAEH;;GAEG;AAEH;;;;;GAKG;AACH,yCALW,OAAO,iBAAiB,EAAE,iBAAiB,QAC3C,MAAM,WACN,OAAO,iBAAiB,EAAE,cAAc,GACvC,mBAAmB,CAY9B;;;;;;;;;;;;;gBA9Da,MAAM;;yCAeE,iBAAiB,KAAE,OAAO,iBAAiB,EAAE,YAAY;sCAIzD,iBAAiB,KAAE,OAAO;qCAI1B,iBAAiB,KAAE,MAAM;qCAIzB,iBAAiB,KAAE,MAAM;wCAIzB,iBAAiB,KAAE,CAAC,MAAM,MAAM,CAAC,GAAC,MAAM,CAAC;0CAIzC,iBAAiB,KAAE,MAAM,MAAM,CAAC;yCAIhC,iBAAiB,KAAE,MAAM,MAAM,CAAC;uCAIhC,iBAAiB,KAAE,CAAC,MAAM,MAAM,CAAC,GAAC,MAAM,CAAC"}
|
package/expr/cpu.js
ADDED
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module ol/expr/cpu
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
LiteralExpression,
|
|
7
|
+
Ops,
|
|
8
|
+
overlapsType,
|
|
9
|
+
parse,
|
|
10
|
+
typeName,
|
|
11
|
+
} from './expression.js';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @fileoverview This module includes functions to build expressions for evaluation on the CPU.
|
|
15
|
+
* Building is composed of two steps: parsing and compiling. The parsing step takes an encoded
|
|
16
|
+
* expression and returns an instance of one of the expression classes. The compiling step takes
|
|
17
|
+
* the expression instance and returns a function that can be evaluated in to return a literal
|
|
18
|
+
* value. The evaluator function should do as little allocation and work as possible.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @typedef {Object} EvaluationContext
|
|
23
|
+
* @property {Object} properties The values for properties used in 'get' expressions.
|
|
24
|
+
* @property {Object} variables The values for variables used in 'var' expressions.
|
|
25
|
+
* @property {number} resolution The map resolution.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @return {EvaluationContext} A new evaluation context.
|
|
30
|
+
*/
|
|
31
|
+
export function newEvaluationContext() {
|
|
32
|
+
return {
|
|
33
|
+
variables: {},
|
|
34
|
+
properties: {},
|
|
35
|
+
resolution: NaN,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @typedef {function(EvaluationContext):import("./expression.js").LiteralValue} ExpressionEvaluator
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @typedef {function(EvaluationContext):boolean} BooleanEvaluator
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @typedef {function(EvaluationContext):number} NumberEvaluator
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @typedef {function(EvaluationContext):string} StringEvaluator
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @typedef {function(EvaluationContext):(Array<number>|string)} ColorLikeEvaluator
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @typedef {function(EvaluationContext):Array<number>} NumberArrayEvaluator
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @typedef {function(EvaluationContext):Array<number>} CoordinateEvaluator
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @typedef {function(EvaluationContext):(Array<number>|number)} SizeLikeEvaluator
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @param {import('./expression.js').EncodedExpression} encoded The encoded expression.
|
|
73
|
+
* @param {number} type The expected type.
|
|
74
|
+
* @param {import('./expression.js').ParsingContext} context The parsing context.
|
|
75
|
+
* @return {ExpressionEvaluator} The expression evaluator.
|
|
76
|
+
*/
|
|
77
|
+
export function buildExpression(encoded, type, context) {
|
|
78
|
+
const expression = parse(encoded, context);
|
|
79
|
+
if (!overlapsType(type, expression.type)) {
|
|
80
|
+
const expected = typeName(type);
|
|
81
|
+
const actual = typeName(expression.type);
|
|
82
|
+
throw new Error(
|
|
83
|
+
`Expected expression to be of type ${expected}, got ${actual}`
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
return compileExpression(expression, context);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @param {import("./expression.js").Expression} expression The expression.
|
|
91
|
+
* @param {import('./expression.js').ParsingContext} context The parsing context.
|
|
92
|
+
* @return {ExpressionEvaluator} The evaluator function.
|
|
93
|
+
*/
|
|
94
|
+
function compileExpression(expression, context) {
|
|
95
|
+
if (expression instanceof LiteralExpression) {
|
|
96
|
+
return function () {
|
|
97
|
+
return expression.value;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
const operator = expression.operator;
|
|
101
|
+
switch (operator) {
|
|
102
|
+
case Ops.Get:
|
|
103
|
+
case Ops.Var: {
|
|
104
|
+
return compileAccessorExpression(expression, context);
|
|
105
|
+
}
|
|
106
|
+
case Ops.Equal:
|
|
107
|
+
case Ops.NotEqual:
|
|
108
|
+
case Ops.LessThan:
|
|
109
|
+
case Ops.LessThanOrEqualTo:
|
|
110
|
+
case Ops.GreaterThan:
|
|
111
|
+
case Ops.GreaterThanOrEqualTo: {
|
|
112
|
+
return compileComparisonExpression(expression, context);
|
|
113
|
+
}
|
|
114
|
+
case Ops.Multiply:
|
|
115
|
+
case Ops.Divide:
|
|
116
|
+
case Ops.Add:
|
|
117
|
+
case Ops.Subtract:
|
|
118
|
+
case Ops.Clamp:
|
|
119
|
+
case Ops.Mod:
|
|
120
|
+
case Ops.Pow:
|
|
121
|
+
case Ops.Abs:
|
|
122
|
+
case Ops.Floor:
|
|
123
|
+
case Ops.Ceil:
|
|
124
|
+
case Ops.Round:
|
|
125
|
+
case Ops.Sin:
|
|
126
|
+
case Ops.Cos:
|
|
127
|
+
case Ops.Atan:
|
|
128
|
+
case Ops.Sqrt: {
|
|
129
|
+
return compileNumericExpression(expression, context);
|
|
130
|
+
}
|
|
131
|
+
case Ops.Match: {
|
|
132
|
+
return compileMatchExpression(expression, context);
|
|
133
|
+
}
|
|
134
|
+
default: {
|
|
135
|
+
throw new Error(`Unsupported operator ${operator}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* @param {import('./expression.js').CallExpression} expression The call expression.
|
|
142
|
+
* @param {import('./expression.js').ParsingContext} context The parsing context.
|
|
143
|
+
* @return {ExpressionEvaluator} The evaluator function.
|
|
144
|
+
*/
|
|
145
|
+
function compileAccessorExpression(expression, context) {
|
|
146
|
+
const nameExpression = expression.args[0];
|
|
147
|
+
if (!(nameExpression instanceof LiteralExpression)) {
|
|
148
|
+
throw new Error('Expected literal name');
|
|
149
|
+
}
|
|
150
|
+
const name = nameExpression.value;
|
|
151
|
+
if (typeof name !== 'string') {
|
|
152
|
+
throw new Error('Expected string name');
|
|
153
|
+
}
|
|
154
|
+
switch (expression.operator) {
|
|
155
|
+
case Ops.Get: {
|
|
156
|
+
return (context) => context.properties[name];
|
|
157
|
+
}
|
|
158
|
+
case Ops.Var: {
|
|
159
|
+
return (context) => context.variables[name];
|
|
160
|
+
}
|
|
161
|
+
default: {
|
|
162
|
+
throw new Error(`Unsupported accessor operator ${expression.operator}`);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* @param {import('./expression.js').CallExpression} expression The call expression.
|
|
169
|
+
* @param {import('./expression.js').ParsingContext} context The parsing context.
|
|
170
|
+
* @return {BooleanEvaluator} The evaluator function.
|
|
171
|
+
*/
|
|
172
|
+
function compileComparisonExpression(expression, context) {
|
|
173
|
+
const op = expression.operator;
|
|
174
|
+
const left = compileExpression(expression.args[0], context);
|
|
175
|
+
const right = compileExpression(expression.args[1], context);
|
|
176
|
+
switch (op) {
|
|
177
|
+
case Ops.Equal: {
|
|
178
|
+
return (context) => left(context) === right(context);
|
|
179
|
+
}
|
|
180
|
+
case Ops.NotEqual: {
|
|
181
|
+
return (context) => left(context) !== right(context);
|
|
182
|
+
}
|
|
183
|
+
case Ops.LessThan: {
|
|
184
|
+
return (context) => left(context) < right(context);
|
|
185
|
+
}
|
|
186
|
+
case Ops.LessThanOrEqualTo: {
|
|
187
|
+
return (context) => left(context) <= right(context);
|
|
188
|
+
}
|
|
189
|
+
case Ops.GreaterThan: {
|
|
190
|
+
return (context) => left(context) > right(context);
|
|
191
|
+
}
|
|
192
|
+
case Ops.GreaterThanOrEqualTo: {
|
|
193
|
+
return (context) => left(context) >= right(context);
|
|
194
|
+
}
|
|
195
|
+
default: {
|
|
196
|
+
throw new Error(`Unsupported comparison operator ${op}`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* @param {import('./expression.js').CallExpression} expression The call expression.
|
|
203
|
+
* @param {import('./expression.js').ParsingContext} context The parsing context.
|
|
204
|
+
* @return {NumberEvaluator} The evaluator function.
|
|
205
|
+
*/
|
|
206
|
+
function compileNumericExpression(expression, context) {
|
|
207
|
+
const op = expression.operator;
|
|
208
|
+
const length = expression.args.length;
|
|
209
|
+
|
|
210
|
+
const args = new Array(length);
|
|
211
|
+
for (let i = 0; i < length; ++i) {
|
|
212
|
+
args[i] = compileExpression(expression.args[i], context);
|
|
213
|
+
}
|
|
214
|
+
switch (op) {
|
|
215
|
+
case Ops.Multiply: {
|
|
216
|
+
return (context) => {
|
|
217
|
+
let value = 1;
|
|
218
|
+
for (let i = 0; i < length; ++i) {
|
|
219
|
+
value *= args[i](context);
|
|
220
|
+
}
|
|
221
|
+
return value;
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
case Ops.Divide: {
|
|
225
|
+
return (context) => args[0](context) / args[1](context);
|
|
226
|
+
}
|
|
227
|
+
case Ops.Add: {
|
|
228
|
+
return (context) => {
|
|
229
|
+
let value = 0;
|
|
230
|
+
for (let i = 0; i < length; ++i) {
|
|
231
|
+
value += args[i](context);
|
|
232
|
+
}
|
|
233
|
+
return value;
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
case Ops.Subtract: {
|
|
237
|
+
return (context) => args[0](context) - args[1](context);
|
|
238
|
+
}
|
|
239
|
+
case Ops.Clamp: {
|
|
240
|
+
return (context) => {
|
|
241
|
+
const value = args[0](context);
|
|
242
|
+
const min = args[1](context);
|
|
243
|
+
if (value < min) {
|
|
244
|
+
return min;
|
|
245
|
+
}
|
|
246
|
+
const max = args[2](context);
|
|
247
|
+
if (value > max) {
|
|
248
|
+
return max;
|
|
249
|
+
}
|
|
250
|
+
return value;
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
case Ops.Mod: {
|
|
254
|
+
return (context) => args[0](context) % args[1](context);
|
|
255
|
+
}
|
|
256
|
+
case Ops.Pow: {
|
|
257
|
+
return (context) => Math.pow(args[0](context), args[1](context));
|
|
258
|
+
}
|
|
259
|
+
case Ops.Abs: {
|
|
260
|
+
return (context) => Math.abs(args[0](context));
|
|
261
|
+
}
|
|
262
|
+
case Ops.Floor: {
|
|
263
|
+
return (context) => Math.floor(args[0](context));
|
|
264
|
+
}
|
|
265
|
+
case Ops.Ceil: {
|
|
266
|
+
return (context) => Math.ceil(args[0](context));
|
|
267
|
+
}
|
|
268
|
+
case Ops.Round: {
|
|
269
|
+
return (context) => Math.round(args[0](context));
|
|
270
|
+
}
|
|
271
|
+
case Ops.Sin: {
|
|
272
|
+
return (context) => Math.sin(args[0](context));
|
|
273
|
+
}
|
|
274
|
+
case Ops.Cos: {
|
|
275
|
+
return (context) => Math.cos(args[0](context));
|
|
276
|
+
}
|
|
277
|
+
case Ops.Atan: {
|
|
278
|
+
if (length === 2) {
|
|
279
|
+
return (context) => Math.atan2(args[0](context), args[1](context));
|
|
280
|
+
}
|
|
281
|
+
return (context) => Math.atan(args[0](context));
|
|
282
|
+
}
|
|
283
|
+
case Ops.Sqrt: {
|
|
284
|
+
return (context) => Math.sqrt(args[0](context));
|
|
285
|
+
}
|
|
286
|
+
default: {
|
|
287
|
+
throw new Error(`Unsupported numeric operator ${op}`);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* @param {import('./expression.js').CallExpression} expression The call expression.
|
|
294
|
+
* @param {import('./expression.js').ParsingContext} context The parsing context.
|
|
295
|
+
* @return {ExpressionEvaluator} The evaluator function.
|
|
296
|
+
*/
|
|
297
|
+
function compileMatchExpression(expression, context) {
|
|
298
|
+
const length = expression.args.length;
|
|
299
|
+
const args = new Array(length);
|
|
300
|
+
for (let i = 0; i < length; ++i) {
|
|
301
|
+
args[i] = compileExpression(expression.args[i], context);
|
|
302
|
+
}
|
|
303
|
+
return (context) => {
|
|
304
|
+
const value = args[0](context);
|
|
305
|
+
for (let i = 1; i < length; i += 2) {
|
|
306
|
+
if (value === args[i](context)) {
|
|
307
|
+
return args[i + 1](context);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return args[length - 1](context);
|
|
311
|
+
};
|
|
312
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get a string representation for a type.
|
|
3
|
+
* @param {number} type The type.
|
|
4
|
+
* @return {string} The type name.
|
|
5
|
+
*/
|
|
6
|
+
export function typeName(type: number): string;
|
|
7
|
+
/**
|
|
8
|
+
* @param {number} broad The broad type.
|
|
9
|
+
* @param {number} specific The specific type.
|
|
10
|
+
* @return {boolean} The broad type includes the specific type.
|
|
11
|
+
*/
|
|
12
|
+
export function includesType(broad: number, specific: number): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* @param {number} oneType One type.
|
|
15
|
+
* @param {number} otherType Another type.
|
|
16
|
+
* @return {boolean} The set of types overlap (share a common specific type)
|
|
17
|
+
*/
|
|
18
|
+
export function overlapsType(oneType: number, otherType: number): boolean;
|
|
19
|
+
/**
|
|
20
|
+
* @param {number} type The type.
|
|
21
|
+
* @param {number} expected The expected type.
|
|
22
|
+
* @return {boolean} The given type is exactly the expected type.
|
|
23
|
+
*/
|
|
24
|
+
export function isType(type: number, expected: number): boolean;
|
|
25
|
+
/**
|
|
26
|
+
* @typedef {LiteralExpression|CallExpression} Expression
|
|
27
|
+
*/
|
|
28
|
+
/**
|
|
29
|
+
* @typedef {Object} ParsingContext
|
|
30
|
+
* @property {Set<string>} variables Variables referenced with the 'var' operator.
|
|
31
|
+
* @property {Set<string>} properties Properties referenced with the 'get' operator.
|
|
32
|
+
*/
|
|
33
|
+
/**
|
|
34
|
+
* @return {ParsingContext} A new parsing context.
|
|
35
|
+
*/
|
|
36
|
+
export function newParsingContext(): ParsingContext;
|
|
37
|
+
/**
|
|
38
|
+
* @typedef {LiteralValue|Array} EncodedExpression
|
|
39
|
+
*/
|
|
40
|
+
/**
|
|
41
|
+
* @param {EncodedExpression} encoded The encoded expression.
|
|
42
|
+
* @param {ParsingContext} context The parsing context.
|
|
43
|
+
* @return {Expression} The parsed expression result.
|
|
44
|
+
*/
|
|
45
|
+
export function parse(encoded: EncodedExpression, context: ParsingContext): Expression;
|
|
46
|
+
export const NoneType: 0;
|
|
47
|
+
export const BooleanType: number;
|
|
48
|
+
export const NumberType: number;
|
|
49
|
+
export const StringType: number;
|
|
50
|
+
export const ColorType: number;
|
|
51
|
+
export const NumberArrayType: number;
|
|
52
|
+
export const AnyType: number;
|
|
53
|
+
/**
|
|
54
|
+
* @typedef {boolean|number|string|Array<number>} LiteralValue
|
|
55
|
+
*/
|
|
56
|
+
export class LiteralExpression {
|
|
57
|
+
/**
|
|
58
|
+
* @param {number} type The value type.
|
|
59
|
+
* @param {LiteralValue} value The literal value.
|
|
60
|
+
*/
|
|
61
|
+
constructor(type: number, value: LiteralValue);
|
|
62
|
+
type: number;
|
|
63
|
+
value: LiteralValue;
|
|
64
|
+
}
|
|
65
|
+
export class CallExpression {
|
|
66
|
+
/**
|
|
67
|
+
* @param {number} type The return type.
|
|
68
|
+
* @param {string} operator The operator.
|
|
69
|
+
* @param {...Expression} args The arguments.
|
|
70
|
+
*/
|
|
71
|
+
constructor(type: number, operator: string, ...args: Expression[]);
|
|
72
|
+
type: number;
|
|
73
|
+
operator: string;
|
|
74
|
+
args: Expression[];
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* @type {Object<string, string>}
|
|
78
|
+
*/
|
|
79
|
+
export const Ops: {
|
|
80
|
+
[x: string]: string;
|
|
81
|
+
};
|
|
82
|
+
export type Expression = LiteralExpression | CallExpression;
|
|
83
|
+
export type ParsingContext = {
|
|
84
|
+
/**
|
|
85
|
+
* Variables referenced with the 'var' operator.
|
|
86
|
+
*/
|
|
87
|
+
variables: Set<string>;
|
|
88
|
+
/**
|
|
89
|
+
* Properties referenced with the 'get' operator.
|
|
90
|
+
*/
|
|
91
|
+
properties: Set<string>;
|
|
92
|
+
};
|
|
93
|
+
export type EncodedExpression = LiteralValue | any[];
|
|
94
|
+
export type ArgValidator = (arg0: any[], arg1: ParsingContext) => Array<Expression>;
|
|
95
|
+
export type LiteralValue = boolean | number | string | Array<number>;
|
|
96
|
+
export type Parser = (arg0: any[], arg1: ParsingContext) => Expression;
|
|
97
|
+
//# sourceMappingURL=expression.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expression.d.ts","sourceRoot":"","sources":["expression.js"],"names":[],"mappings":"AAgCA;;;;GAIG;AACH,+BAHW,MAAM,GACL,MAAM,CAgBjB;AAED;;;;GAIG;AACH,oCAJW,MAAM,YACN,MAAM,GACL,OAAO,CAIlB;AAED;;;;GAIG;AACH,sCAJW,MAAM,aACN,MAAM,GACL,OAAO,CAIlB;AAED;;;;GAIG;AACH,6BAJW,MAAM,YACN,MAAM,GACL,OAAO,CAIlB;AA8BD;;GAEG;AAEH;;;;GAIG;AAEH;;GAEG;AACH,qCAFY,cAAc,CAOzB;AAED;;GAEG;AAEH;;;;GAIG;AACH,+BAJW,iBAAiB,WACjB,cAAc,GACb,UAAU,CA0CrB;AAnKD,yBAA0B;AAC1B,iCAA2C;AAC3C,gCAA0C;AAC1C,gCAA0C;AAC1C,+BAAyC;AACzC,qCAA+C;AAC/C,6BAAiD;AA4DjD;;GAEG;AAEH;IACE;;;OAGG;IACH,kBAHW,MAAM,SACN,YAAY,EAKtB;IAFC,aAAgB;IAChB,oBAAkB;CAErB;AAED;IACE;;;;OAIG;IACH,kBAJW,MAAM,YACN,MAAM,WACH,UAAU,IAMvB;IAHC,aAAgB;IAChB,iBAAwB;IACxB,mBAAgB;CAEnB;AAyED;;GAEG;AACH;QAFiB,MAAM,GAAE,MAAM;EA4B7B;yBAnGW,iBAAiB,GAAC,cAAc;;;;;eAK/B,IAAI,MAAM,CAAC;;;;gBACX,IAAI,MAAM,CAAC;;gCAcZ,YAAY,QAAM;+CA2HF,cAAc,KAAE,MAAM,UAAU,CAAC;2BA3KjD,OAAO,GAAC,MAAM,GAAC,MAAM,GAAC,MAAM,MAAM,CAAC;yCAkInB,cAAc,KAAE,UAAU"}
|