@emuanalytics/flow-rdf-core 4.1.8 → 4.2.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/dist/index.d.mts +118 -3
- package/dist/index.d.ts +118 -3
- package/dist/index.mjs +3 -0
- package/dist/lib/map/flow-core-map.mjs +30 -5
- package/dist/lib/map/plugins/index.d.mts +2 -2
- package/dist/lib/map/plugins/index.d.ts +2 -2
- package/dist/lib/map-style/flow-style/builder.mjs +97 -0
- package/dist/lib/map-style/flow-style/data-driven.mjs +164 -0
- package/dist/lib/map-style/flow-style/expand.mjs +145 -0
- package/dist/lib/map-style/flow-style/literals.mjs +58 -0
- package/dist/lib/map-style/flow-style/stored-format.mjs +93 -0
- package/dist/lib/map-style/flow-style/validate.mjs +117 -0
- package/dist/lib/map-style/flow-style/values.mjs +249 -0
- package/dist/lib/map-style/map-layer.mjs +361 -12
- package/dist/lib/map-style/map-style.mjs +129 -32
- package/dist/package.json.mjs +1 -1
- package/dist/shared/{flow-rdf-core.1ee62df9.d.mts → flow-rdf-core.c45eb675.d.mts} +488 -46
- package/dist/shared/{flow-rdf-core.1ee62df9.d.ts → flow-rdf-core.c45eb675.d.ts} +488 -46
- package/package.json +1 -1
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { isPlainObject } from '../../utils/type-checks.mjs';
|
|
2
|
+
import { expandDataDriven, writeLiteralV2, DATA_DRIVEN_FORMAT_V2 } from './data-driven.mjs';
|
|
3
|
+
import { expressionParseError, escapeLegacyString, formatNumber } from './literals.mjs';
|
|
4
|
+
|
|
5
|
+
const FLOW_STYLE_PROPERTIES = {
|
|
6
|
+
fillColor: "color",
|
|
7
|
+
strokeColor: "color",
|
|
8
|
+
strokeWidth: "size",
|
|
9
|
+
radius: "size",
|
|
10
|
+
opacity: "number",
|
|
11
|
+
labelText: "text",
|
|
12
|
+
labelColor: "color",
|
|
13
|
+
labelHaloColor: "color",
|
|
14
|
+
labelSize: "size",
|
|
15
|
+
visibility: "boolean"
|
|
16
|
+
};
|
|
17
|
+
function isFlowStylePropertyName(name) {
|
|
18
|
+
return Object.prototype.hasOwnProperty.call(FLOW_STYLE_PROPERTIES, name);
|
|
19
|
+
}
|
|
20
|
+
const zoomSize = (a, b, c) => `interpolate(linear(), zoom(), 0, ${a}, 10, ${b}, 20, ${c})`;
|
|
21
|
+
const FLOW_STYLE_NAMED_SIZES = {
|
|
22
|
+
strokeWidth: {
|
|
23
|
+
"x-small": "0.5",
|
|
24
|
+
small: zoomSize(1, 1, 2),
|
|
25
|
+
medium: zoomSize(1, 2, 4),
|
|
26
|
+
large: zoomSize(2, 4, 8),
|
|
27
|
+
"x-large": zoomSize(4, 8, 16)
|
|
28
|
+
},
|
|
29
|
+
labelSize: {
|
|
30
|
+
"x-small": "8",
|
|
31
|
+
small: zoomSize(4, 8, 15),
|
|
32
|
+
medium: zoomSize(5, 10, 20),
|
|
33
|
+
large: zoomSize(8, 14, 30),
|
|
34
|
+
"x-large": zoomSize(10, 18, 36)
|
|
35
|
+
},
|
|
36
|
+
radius: {
|
|
37
|
+
"x-small": zoomSize(1, 2, 8),
|
|
38
|
+
small: zoomSize(1, 3, 12),
|
|
39
|
+
medium: zoomSize(2, 5, 20),
|
|
40
|
+
large: zoomSize(3, 7, 28),
|
|
41
|
+
"x-large": zoomSize(4, 10, 40)
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
function isNamedSize(value) {
|
|
45
|
+
return typeof value === "string" && Object.prototype.hasOwnProperty.call(FLOW_STYLE_NAMED_SIZES.radius, value);
|
|
46
|
+
}
|
|
47
|
+
function flowStyleVersion(style) {
|
|
48
|
+
const version = isPlainObject(style) ? style.version : void 0;
|
|
49
|
+
if (version === void 0 || version === 1) {
|
|
50
|
+
return 1;
|
|
51
|
+
}
|
|
52
|
+
return version === 2 ? 2 : void 0;
|
|
53
|
+
}
|
|
54
|
+
function flowStylePropertyExpression(version, property, value, path = property) {
|
|
55
|
+
if (value === void 0) {
|
|
56
|
+
return { expression: void 0, issues: [] };
|
|
57
|
+
}
|
|
58
|
+
const issues = [];
|
|
59
|
+
const expression = version === 1 ? propertyExpressionV1(property, value, path, issues) : propertyExpressionV2(property, value, path, issues);
|
|
60
|
+
if (expression === void 0 || issues.some((issue) => issue.severity === "error")) {
|
|
61
|
+
return { expression: void 0, issues };
|
|
62
|
+
}
|
|
63
|
+
const parseError = expressionParseError(expression);
|
|
64
|
+
if (parseError) {
|
|
65
|
+
issues.push({
|
|
66
|
+
path,
|
|
67
|
+
message: `The expression \`${expression}\` does not parse: ${parseError}.`,
|
|
68
|
+
severity: "error"
|
|
69
|
+
});
|
|
70
|
+
return { expression: void 0, issues };
|
|
71
|
+
}
|
|
72
|
+
return { expression, issues };
|
|
73
|
+
}
|
|
74
|
+
const MAX_DEPTH = 16;
|
|
75
|
+
function propertyExpressionV1(property, value, path, issues) {
|
|
76
|
+
const kind = FLOW_STYLE_PROPERTIES[property];
|
|
77
|
+
if (kind === "size" && typeof value === "string" && !value.startsWith("$")) {
|
|
78
|
+
if (isNamedSize(value)) {
|
|
79
|
+
return FLOW_STYLE_NAMED_SIZES[property][value];
|
|
80
|
+
}
|
|
81
|
+
issues.push({ path, message: `Unknown size name '${value}'.`, severity: "error" });
|
|
82
|
+
return void 0;
|
|
83
|
+
}
|
|
84
|
+
const isPlain = typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
85
|
+
if (isPlain && !kindMatches(kind, value) && !(typeof value === "string" && value.startsWith("@"))) {
|
|
86
|
+
issues.push({ path, message: `Expected ${KIND_NAMES[kind]}; it renders as it is.`, severity: "warning" });
|
|
87
|
+
}
|
|
88
|
+
return expandValueV1(value, path, issues, 0);
|
|
89
|
+
}
|
|
90
|
+
function expandValueV1(value, path, issues, depth) {
|
|
91
|
+
const error = (message, at = path) => {
|
|
92
|
+
issues.push({ path: at, message, severity: "error" });
|
|
93
|
+
return void 0;
|
|
94
|
+
};
|
|
95
|
+
if (typeof value === "string") {
|
|
96
|
+
return value.startsWith("@") ? value : `'${value}'`;
|
|
97
|
+
}
|
|
98
|
+
if (typeof value === "number" && Number.isFinite(value) || typeof value === "boolean") {
|
|
99
|
+
return value.toString();
|
|
100
|
+
}
|
|
101
|
+
if (!isPlainObject(value) || Array.isArray(value)) {
|
|
102
|
+
return error("Expected a string, a number, a boolean or a literal, expression or data-driven object.");
|
|
103
|
+
}
|
|
104
|
+
const object = value;
|
|
105
|
+
switch (object.type) {
|
|
106
|
+
case "literal":
|
|
107
|
+
if (typeof object.value === "string") {
|
|
108
|
+
return `'${object.value}'`;
|
|
109
|
+
}
|
|
110
|
+
if (typeof object.value === "number" && Number.isFinite(object.value) || typeof object.value === "boolean") {
|
|
111
|
+
return object.value.toString();
|
|
112
|
+
}
|
|
113
|
+
return error("A literal value must be a string, a number or a boolean.", `${path}.value`);
|
|
114
|
+
case "expression":
|
|
115
|
+
return expressionValue(object.value, `${path}.value`, issues, (n) => n.toString());
|
|
116
|
+
case "data-driven": {
|
|
117
|
+
if (depth >= MAX_DEPTH) {
|
|
118
|
+
return error("Data-driven values are nested too deeply.");
|
|
119
|
+
}
|
|
120
|
+
const result = expandDataDriven(object, path, dataDrivenFormatV1(depth));
|
|
121
|
+
issues.push(...result.issues);
|
|
122
|
+
return result.expression;
|
|
123
|
+
}
|
|
124
|
+
default:
|
|
125
|
+
return error("The value's `type` must be `literal`, `expression` or `data-driven`.", `${path}.type`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
function dataDrivenFormatV1(depth) {
|
|
129
|
+
return {
|
|
130
|
+
severity: "error",
|
|
131
|
+
mode(mode, keyType, path, issues) {
|
|
132
|
+
if (mode === "off" || mode === "interpolate") {
|
|
133
|
+
return mode;
|
|
134
|
+
}
|
|
135
|
+
if (mode !== void 0 && mode !== "match") {
|
|
136
|
+
issues.push({ path, message: `Unknown mode '${String(mode)}'; it is read as \`match\`.`, severity: "warning" });
|
|
137
|
+
}
|
|
138
|
+
return keyType === "number" ? "step" : "match";
|
|
139
|
+
},
|
|
140
|
+
value: (value, path, issues) => expandValueV1(value, path, issues, depth + 1),
|
|
141
|
+
key: (key) => `'${escapeLegacyString(key)}'`,
|
|
142
|
+
number: (key) => key.toString()
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
const KIND_NAMES = {
|
|
146
|
+
color: "a color string",
|
|
147
|
+
size: "a number or a named size",
|
|
148
|
+
number: "a number",
|
|
149
|
+
text: "a string",
|
|
150
|
+
boolean: "a boolean"
|
|
151
|
+
};
|
|
152
|
+
function kindMatches(kind, value) {
|
|
153
|
+
switch (kind) {
|
|
154
|
+
case "color":
|
|
155
|
+
case "text":
|
|
156
|
+
return typeof value === "string";
|
|
157
|
+
case "size":
|
|
158
|
+
return typeof value === "number" && Number.isFinite(value) || isNamedSize(value);
|
|
159
|
+
case "number":
|
|
160
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
161
|
+
case "boolean":
|
|
162
|
+
return typeof value === "boolean";
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
const V2_EXPRESSION_KEYS = ["type", "value", "dataDriven"];
|
|
166
|
+
function propertyExpressionV2(property, value, path, issues) {
|
|
167
|
+
const kind = FLOW_STYLE_PROPERTIES[property];
|
|
168
|
+
const error = (message, at = path) => {
|
|
169
|
+
issues.push({ path: at, message, severity: "error" });
|
|
170
|
+
return void 0;
|
|
171
|
+
};
|
|
172
|
+
if (isPlainObject(value) && !Array.isArray(value)) {
|
|
173
|
+
const object = value;
|
|
174
|
+
if (object.type === "literal" || object.type === "data-driven") {
|
|
175
|
+
return error(
|
|
176
|
+
object.type === "literal" ? "Version 2 has no literal objects: a plain value is a literal." : "Version 2 has no data-driven objects: use an expression with `dataDriven`.",
|
|
177
|
+
`${path}.type`
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
if (object.type !== "expression") {
|
|
181
|
+
return error('An object value must be an expression: `{type: "expression", value}`.', `${path}.type`);
|
|
182
|
+
}
|
|
183
|
+
for (const key of Object.keys(object)) {
|
|
184
|
+
if (!V2_EXPRESSION_KEYS.includes(key)) {
|
|
185
|
+
issues.push({
|
|
186
|
+
path: `${path}.${key}`,
|
|
187
|
+
message: `Unknown key '${key}' is kept but not used.`,
|
|
188
|
+
severity: "warning"
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (object.dataDriven !== void 0) {
|
|
193
|
+
checkDataDrivenV2(property, object.dataDriven, `${path}.dataDriven`, issues);
|
|
194
|
+
}
|
|
195
|
+
return expressionValue(object.value, `${path}.value`, issues, formatNumber);
|
|
196
|
+
}
|
|
197
|
+
if (kind === "size" && typeof value === "string") {
|
|
198
|
+
if (isNamedSize(value)) {
|
|
199
|
+
return FLOW_STYLE_NAMED_SIZES[property][value];
|
|
200
|
+
}
|
|
201
|
+
return error(`Unknown size name '${value}'.`);
|
|
202
|
+
}
|
|
203
|
+
if (!kindMatches(kind, value)) {
|
|
204
|
+
return error(`Expected ${KIND_NAMES[kind]} or an expression.`);
|
|
205
|
+
}
|
|
206
|
+
return writeLiteralV2(value, path, issues, "error");
|
|
207
|
+
}
|
|
208
|
+
function checkDataDrivenV2(property, dataDriven, path, issues) {
|
|
209
|
+
issues.push(...expandDataDriven(dataDriven, path, DATA_DRIVEN_FORMAT_V2).issues);
|
|
210
|
+
if (!isPlainObject(dataDriven)) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
const kind = FLOW_STYLE_PROPERTIES[property];
|
|
214
|
+
const table = dataDriven;
|
|
215
|
+
const values = [[table.default, `${path}.default`]];
|
|
216
|
+
if (Array.isArray(table.values)) {
|
|
217
|
+
table.values.forEach((row, index) => {
|
|
218
|
+
if (Array.isArray(row)) {
|
|
219
|
+
values.push([row[1], `${path}.values[${index}]`]);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
for (const [value, at] of values) {
|
|
224
|
+
if (value === void 0) {
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
if (isNamedSize(value) && kind === "size") {
|
|
228
|
+
issues.push({
|
|
229
|
+
path: at,
|
|
230
|
+
message: "Named sizes cannot be used in a data-driven table: use numbers.",
|
|
231
|
+
severity: "warning"
|
|
232
|
+
});
|
|
233
|
+
} else if (!kindMatches(kind, value)) {
|
|
234
|
+
issues.push({ path: at, message: `Expected ${KIND_NAMES[kind]}.`, severity: "warning" });
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
function expressionValue(value, path, issues, writeNumber) {
|
|
239
|
+
if (typeof value === "string") {
|
|
240
|
+
return value;
|
|
241
|
+
}
|
|
242
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
243
|
+
return writeNumber(value);
|
|
244
|
+
}
|
|
245
|
+
issues.push({ path, message: "An expression value must be a string or a number.", severity: "error" });
|
|
246
|
+
return void 0;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export { FLOW_STYLE_NAMED_SIZES, FLOW_STYLE_PROPERTIES, flowStylePropertyExpression, flowStyleVersion, isFlowStylePropertyName, isNamedSize };
|