@emuanalytics/flow-rdf-core 4.1.8 → 4.3.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 +322 -4
- package/dist/index.d.ts +322 -4
- package/dist/index.mjs +6 -0
- package/dist/lib/map/flow-core-map.mjs +120 -13
- package/dist/lib/map/plugins/index.d.mts +252 -223
- package/dist/lib/map/plugins/index.d.ts +252 -223
- package/dist/lib/map/plugins/selection/selection.plugin.mjs +73 -7
- package/dist/lib/map/plugins/selection/source-selection.mjs +12 -0
- package/dist/lib/map-style/composite/builder.mjs +31 -0
- package/dist/lib/map-style/composite/editing.mjs +123 -0
- package/dist/lib/map-style/composite/expand.mjs +182 -0
- package/dist/lib/map-style/composite/stored-format.mjs +18 -0
- package/dist/lib/map-style/composite/validate.mjs +376 -0
- 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-data-source.mjs +9 -0
- package/dist/lib/map-style/map-layer.mjs +555 -17
- package/dist/lib/map-style/map-style.mjs +250 -39
- package/dist/package.json.mjs +1 -1
- package/dist/shared/{flow-rdf-core.1ee62df9.d.mts → flow-rdf-core.62a36d8b.d.mts} +1077 -234
- package/dist/shared/{flow-rdf-core.1ee62df9.d.ts → flow-rdf-core.62a36d8b.d.ts} +1077 -234
- package/package.json +1 -1
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { validateFlowStyle } from './validate.mjs';
|
|
2
|
+
import { flowStyleVersion, flowStylePropertyExpression } from './values.mjs';
|
|
3
|
+
|
|
4
|
+
const VISIBILITY = ["visibility", "visibility"];
|
|
5
|
+
const CIRCLE_RULES = [
|
|
6
|
+
["circle-color", "fillColor"],
|
|
7
|
+
["circle-stroke-color", "strokeColor"],
|
|
8
|
+
["circle-stroke-width", "strokeWidth"],
|
|
9
|
+
["circle-radius", "radius"],
|
|
10
|
+
["circle-opacity", "opacity"],
|
|
11
|
+
["circle-stroke-opacity", "opacity"],
|
|
12
|
+
VISIBILITY
|
|
13
|
+
];
|
|
14
|
+
const FILL_RULES = [["fill-color", "fillColor"], ["fill-opacity", "opacity"], VISIBILITY];
|
|
15
|
+
const STROKE_RULES = [
|
|
16
|
+
["line-color", "strokeColor"],
|
|
17
|
+
["line-width", "strokeWidth"],
|
|
18
|
+
["line-opacity", "opacity"],
|
|
19
|
+
VISIBILITY
|
|
20
|
+
];
|
|
21
|
+
const LINE_RULES = {
|
|
22
|
+
1: [["line-color", "strokeColor"], ["line-width", "strokeWidth"], VISIBILITY],
|
|
23
|
+
2: STROKE_RULES
|
|
24
|
+
};
|
|
25
|
+
const LABEL_RULES = [
|
|
26
|
+
["text-field", "labelText"],
|
|
27
|
+
["text-color", "labelColor"],
|
|
28
|
+
["text-halo-color", "labelHaloColor"],
|
|
29
|
+
["text-halo-blur", { constant: "1" }],
|
|
30
|
+
["text-halo-width", { constant: "2" }],
|
|
31
|
+
["text-size", "labelSize"],
|
|
32
|
+
["text-opacity", "opacity"],
|
|
33
|
+
VISIBILITY
|
|
34
|
+
];
|
|
35
|
+
const CIRCLE_LABEL_RULES = [
|
|
36
|
+
["text-variable-anchor", { constant: "['top']" }],
|
|
37
|
+
["text-radial-offset", { constant: "1.2" }]
|
|
38
|
+
];
|
|
39
|
+
const GEOMETRIES = ["circle", "line", "fill"];
|
|
40
|
+
const STYLE_PATHS = ["", "type", "version"];
|
|
41
|
+
function expandFlowStyle(id, style, options = {}) {
|
|
42
|
+
try {
|
|
43
|
+
return expand(id, style, options);
|
|
44
|
+
} catch (e) {
|
|
45
|
+
return {
|
|
46
|
+
version: void 0,
|
|
47
|
+
geometry: void 0,
|
|
48
|
+
subLayers: [],
|
|
49
|
+
issues: [
|
|
50
|
+
{ path: "", message: `The style could not be read: ${e?.message ?? String(e)}`, severity: "error" }
|
|
51
|
+
]
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function expand(id, style, options) {
|
|
56
|
+
const issues = validateFlowStyle(style);
|
|
57
|
+
const version = flowStyleVersion(style);
|
|
58
|
+
const none = (geometry2) => ({ version, geometry: geometry2, subLayers: [], issues });
|
|
59
|
+
if (version === void 0 || issues.some((issue) => issue.severity === "error" && STYLE_PATHS.includes(issue.path))) {
|
|
60
|
+
return none();
|
|
61
|
+
}
|
|
62
|
+
const object = style;
|
|
63
|
+
const geometry = version === 2 ? object.type : options.geometry;
|
|
64
|
+
if (!GEOMETRIES.includes(geometry)) {
|
|
65
|
+
issues.push({
|
|
66
|
+
path: "",
|
|
67
|
+
message: `A version 1 flow style is drawn as a circle, line or fill layer, not ${describeValue(geometry)}.`,
|
|
68
|
+
severity: "error"
|
|
69
|
+
});
|
|
70
|
+
return none();
|
|
71
|
+
}
|
|
72
|
+
const interactive = resolveInteractive(version, options.interactive, issues);
|
|
73
|
+
const expressions = /* @__PURE__ */ new Map();
|
|
74
|
+
const expression = (property) => {
|
|
75
|
+
if (!expressions.has(property)) {
|
|
76
|
+
const value = object[property];
|
|
77
|
+
expressions.set(
|
|
78
|
+
property,
|
|
79
|
+
isSet(version, property, value) ? flowStylePropertyExpression(version, property, value).expression : void 0
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
return expressions.get(property);
|
|
83
|
+
};
|
|
84
|
+
const program = (rules) => rules.map(([property, from]) => [property, typeof from === "string" ? expression(from) : from.constant]).filter(([, value]) => value !== void 0).map(([property, value]) => `${property}: ${value};`).join("\n");
|
|
85
|
+
const subLayers = [];
|
|
86
|
+
const add = (suffix, type, role, rules) => subLayers.push({
|
|
87
|
+
id: `${id}${suffix}`,
|
|
88
|
+
type,
|
|
89
|
+
style: program(rules),
|
|
90
|
+
interactive: role !== "label" && interactive,
|
|
91
|
+
role
|
|
92
|
+
});
|
|
93
|
+
switch (geometry) {
|
|
94
|
+
case "circle":
|
|
95
|
+
add("", "circle", "geometry", CIRCLE_RULES);
|
|
96
|
+
break;
|
|
97
|
+
case "fill":
|
|
98
|
+
add("", "fill", "geometry", FILL_RULES);
|
|
99
|
+
add("__stroke", "line", "stroke", STROKE_RULES);
|
|
100
|
+
break;
|
|
101
|
+
case "line":
|
|
102
|
+
add("", "line", "geometry", LINE_RULES[version]);
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
if (hasLabel(version, object.labelText) && expression("labelText") !== void 0) {
|
|
106
|
+
const rules = LABEL_RULES.filter(
|
|
107
|
+
([property]) => !["text-halo-blur", "text-halo-width"].includes(property) || expression("labelHaloColor")
|
|
108
|
+
);
|
|
109
|
+
add("__label", "symbol", "label", geometry === "circle" ? [...rules, ...CIRCLE_LABEL_RULES] : rules);
|
|
110
|
+
}
|
|
111
|
+
return { version, geometry, subLayers, issues };
|
|
112
|
+
}
|
|
113
|
+
function isSet(version, property, value) {
|
|
114
|
+
if (version === 2) {
|
|
115
|
+
return value !== void 0;
|
|
116
|
+
}
|
|
117
|
+
return property === "visibility" ? value !== void 0 && value !== null : !!value;
|
|
118
|
+
}
|
|
119
|
+
function hasLabel(version, labelText) {
|
|
120
|
+
if (typeof labelText === "string") {
|
|
121
|
+
return labelText.length > 0;
|
|
122
|
+
}
|
|
123
|
+
return version === 2 && labelText !== void 0;
|
|
124
|
+
}
|
|
125
|
+
function resolveInteractive(version, interactive, issues) {
|
|
126
|
+
if (typeof interactive === "boolean") {
|
|
127
|
+
return interactive;
|
|
128
|
+
}
|
|
129
|
+
if (interactive !== void 0 && version === 2) {
|
|
130
|
+
issues.push({
|
|
131
|
+
path: "",
|
|
132
|
+
message: `The layer's \`interactive\` option must be a boolean, not ${describeValue(interactive)}; the default (\`true\`) applies.`,
|
|
133
|
+
severity: "warning"
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
return true;
|
|
137
|
+
}
|
|
138
|
+
function describeValue(value) {
|
|
139
|
+
if (typeof value === "string") {
|
|
140
|
+
return `'${value}'`;
|
|
141
|
+
}
|
|
142
|
+
return value === void 0 ? "none" : JSON.stringify(value) ?? String(value);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export { expandFlowStyle };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ExpressionParser } from '../../expressions/expression-parser.mjs';
|
|
2
|
+
|
|
3
|
+
const parser = new ExpressionParser();
|
|
4
|
+
function quoteString(value, quote = "'") {
|
|
5
|
+
const other = quote === "'" ? '"' : "'";
|
|
6
|
+
if (!value.includes(quote)) {
|
|
7
|
+
return `${quote}${value}${quote}`;
|
|
8
|
+
}
|
|
9
|
+
if (!value.includes(other)) {
|
|
10
|
+
return `${other}${value}${other}`;
|
|
11
|
+
}
|
|
12
|
+
const args = [];
|
|
13
|
+
value.split("'").forEach((piece, index) => {
|
|
14
|
+
if (index > 0) {
|
|
15
|
+
args.push(`"'"`);
|
|
16
|
+
}
|
|
17
|
+
if (piece.length > 0) {
|
|
18
|
+
args.push(`'${piece}'`);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return `concat(${args.join(", ")})`;
|
|
22
|
+
}
|
|
23
|
+
function isExactString(value, quote = "'") {
|
|
24
|
+
const result = parser.parseExpression(`f(${quoteString(value, quote)}, 'z')`);
|
|
25
|
+
if (!result.status) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
const [, parsed, after] = result.value;
|
|
29
|
+
if (after !== "z") {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
if (typeof parsed === "string") {
|
|
33
|
+
return parsed === value;
|
|
34
|
+
}
|
|
35
|
+
return Array.isArray(parsed) && parsed[0] === "concat" && parsed.slice(1).every((piece) => typeof piece === "string") && parsed.slice(1).join("") === value;
|
|
36
|
+
}
|
|
37
|
+
function attributeExpression(attribute) {
|
|
38
|
+
return `get(${quoteString(attribute, '"')})`;
|
|
39
|
+
}
|
|
40
|
+
function formatNumber(value) {
|
|
41
|
+
const text = String(value);
|
|
42
|
+
if (!/e/i.test(text)) {
|
|
43
|
+
return text;
|
|
44
|
+
}
|
|
45
|
+
return value.toLocaleString("en-US", { useGrouping: false, maximumFractionDigits: 20 });
|
|
46
|
+
}
|
|
47
|
+
function escapeLegacyString(value) {
|
|
48
|
+
return value.replace(/['\\]/g, "\\$&");
|
|
49
|
+
}
|
|
50
|
+
function expressionParseError(expression) {
|
|
51
|
+
const result = parser.parseExpression(expression);
|
|
52
|
+
if (result.status) {
|
|
53
|
+
return void 0;
|
|
54
|
+
}
|
|
55
|
+
return `expected ${result.expected.join(" ")} at offset ${result.index.offset}`;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export { attributeExpression, escapeLegacyString, expressionParseError, formatNumber, isExactString, quoteString };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { isPlainObject } from '../../utils/type-checks.mjs';
|
|
2
|
+
import { cloneStoredValue, isStyleExpression, toStoredValueV2, isDataDrivenTable, isFlowStyleExpression } from './builder.mjs';
|
|
3
|
+
import { dataDrivenExpression } from './data-driven.mjs';
|
|
4
|
+
import { quoteString } from './literals.mjs';
|
|
5
|
+
import { flowStyleVersion, isFlowStylePropertyName, FLOW_STYLE_PROPERTIES, flowStylePropertyExpression } from './values.mjs';
|
|
6
|
+
|
|
7
|
+
function loadStoredFlowStyle(style) {
|
|
8
|
+
return { version: flowStyleVersion(style), style: cloneStoredValue(style) };
|
|
9
|
+
}
|
|
10
|
+
function saveStoredFlowStyle(stored) {
|
|
11
|
+
return cloneStoredValue(stored.style);
|
|
12
|
+
}
|
|
13
|
+
function setStoredFlowStyleProperty(stored, property, value) {
|
|
14
|
+
const version = stored.version ?? 2;
|
|
15
|
+
const style = isPlainObject(stored.style) && !Array.isArray(stored.style) ? cloneStoredValue(stored.style) : {};
|
|
16
|
+
const written = value === void 0 || value === null ? void 0 : toStoredValue(version, property, value);
|
|
17
|
+
if (written === void 0) {
|
|
18
|
+
delete style[property];
|
|
19
|
+
} else {
|
|
20
|
+
Object.defineProperty(style, property, { value: written, enumerable: true, writable: true, configurable: true });
|
|
21
|
+
}
|
|
22
|
+
return { version: stored.version, style: version === 1 ? withVersion1(style) : style };
|
|
23
|
+
}
|
|
24
|
+
function toStoredValue(version, property, value) {
|
|
25
|
+
if (!isFlowStylePropertyName(property)) {
|
|
26
|
+
return isStyleExpression(value) ? { type: "expression", value: value.toString() } : cloneStoredValue(value);
|
|
27
|
+
}
|
|
28
|
+
return version === 1 ? toStoredValueV1(property, value) : toStoredValueV2(value);
|
|
29
|
+
}
|
|
30
|
+
function withVersion1(style) {
|
|
31
|
+
if (style.version !== void 0) {
|
|
32
|
+
return style;
|
|
33
|
+
}
|
|
34
|
+
const keys = Object.keys(style);
|
|
35
|
+
const entries = keys.includes("type") ? [] : [["version", 1]];
|
|
36
|
+
for (const key of keys) {
|
|
37
|
+
entries.push([key, style[key]]);
|
|
38
|
+
if (key === "type") {
|
|
39
|
+
entries.push(["version", 1]);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
const result = {};
|
|
43
|
+
for (const [key, entryValue] of entries) {
|
|
44
|
+
Object.defineProperty(result, key, { value: entryValue, enumerable: true, writable: true, configurable: true });
|
|
45
|
+
}
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
function toStoredValueV1(property, value) {
|
|
49
|
+
if (isStyleExpression(value)) {
|
|
50
|
+
return expressionV1(property, value.toString());
|
|
51
|
+
}
|
|
52
|
+
if (isDataDrivenTable(value)) {
|
|
53
|
+
return dataDrivenToV1(property, value);
|
|
54
|
+
}
|
|
55
|
+
if (isFlowStyleExpression(value)) {
|
|
56
|
+
const { dataDriven } = value;
|
|
57
|
+
if (isDataDrivenTable(dataDriven) && value.value === dataDrivenExpression(dataDriven)) {
|
|
58
|
+
return dataDrivenToV1(property, dataDriven);
|
|
59
|
+
}
|
|
60
|
+
return expressionV1(property, value.value);
|
|
61
|
+
}
|
|
62
|
+
if (typeof value === "string") {
|
|
63
|
+
if (FLOW_STYLE_PROPERTIES[property] === "size") {
|
|
64
|
+
return value;
|
|
65
|
+
}
|
|
66
|
+
const literal = quoteString(value);
|
|
67
|
+
if (`'${value}'` !== literal) {
|
|
68
|
+
return { type: "expression", value: literal };
|
|
69
|
+
}
|
|
70
|
+
return value.startsWith("@") ? { type: "literal", value } : value;
|
|
71
|
+
}
|
|
72
|
+
return cloneStoredValue(value);
|
|
73
|
+
}
|
|
74
|
+
function expressionV1(property, expression) {
|
|
75
|
+
if (property === "labelText" && typeof expression === "string" && expression.startsWith("@")) {
|
|
76
|
+
return expression;
|
|
77
|
+
}
|
|
78
|
+
return { type: "expression", value: expression };
|
|
79
|
+
}
|
|
80
|
+
function dataDrivenToV1(property, table) {
|
|
81
|
+
const expression = dataDrivenExpression(table);
|
|
82
|
+
const converted = {
|
|
83
|
+
type: "data-driven",
|
|
84
|
+
attribute: table.attribute,
|
|
85
|
+
default: cloneStoredValue(table.default),
|
|
86
|
+
...table.mode === "off" || table.mode === "interpolate" ? { mode: table.mode } : {},
|
|
87
|
+
values: cloneStoredValue(table.values)
|
|
88
|
+
};
|
|
89
|
+
const v1 = flowStylePropertyExpression(1, property, converted).expression;
|
|
90
|
+
return v1 === expression ? converted : expressionV1(property, expression);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { loadStoredFlowStyle, saveStoredFlowStyle, setStoredFlowStyleProperty };
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { isPlainObject } from '../../utils/type-checks.mjs';
|
|
2
|
+
import { flowStyleVersion, isFlowStylePropertyName, flowStylePropertyExpression } from './values.mjs';
|
|
3
|
+
|
|
4
|
+
const GEOMETRIES = ["circle", "line", "fill"];
|
|
5
|
+
const OTHER_MAPLIBRE_TYPES = [
|
|
6
|
+
"symbol",
|
|
7
|
+
"heatmap",
|
|
8
|
+
"fill-extrusion",
|
|
9
|
+
"raster",
|
|
10
|
+
"hillshade",
|
|
11
|
+
"background"
|
|
12
|
+
];
|
|
13
|
+
const UNUSED_BY_GEOMETRY = {
|
|
14
|
+
circle: [],
|
|
15
|
+
line: ["fillColor", "radius"],
|
|
16
|
+
fill: ["radius"]
|
|
17
|
+
};
|
|
18
|
+
function validateFlowStyle(style) {
|
|
19
|
+
try {
|
|
20
|
+
return validate(style);
|
|
21
|
+
} catch (e) {
|
|
22
|
+
return [
|
|
23
|
+
{ path: "", message: `The style could not be read: ${e?.message ?? String(e)}`, severity: "error" }
|
|
24
|
+
];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function validate(style) {
|
|
28
|
+
const issues = [];
|
|
29
|
+
const error = (path, message) => {
|
|
30
|
+
issues.push({ path, message, severity: "error" });
|
|
31
|
+
return issues;
|
|
32
|
+
};
|
|
33
|
+
if (!isPlainObject(style) || Array.isArray(style)) {
|
|
34
|
+
return error("", `A flow style must be an object, not ${describe(style)}.`);
|
|
35
|
+
}
|
|
36
|
+
const object = style;
|
|
37
|
+
const keys = Object.keys(object);
|
|
38
|
+
if (keys.length === 0) {
|
|
39
|
+
return error("", "The style is empty: it needs a `type`.");
|
|
40
|
+
}
|
|
41
|
+
const version = flowStyleVersion(object);
|
|
42
|
+
if (version === void 0) {
|
|
43
|
+
return error("version", `Unknown version ${describe(object.version)}: expected 1 or 2.`);
|
|
44
|
+
}
|
|
45
|
+
const typeIssue = checkType(object.type, version, object.version !== void 0);
|
|
46
|
+
if (typeIssue) {
|
|
47
|
+
return error("type", typeIssue);
|
|
48
|
+
}
|
|
49
|
+
const geometry = version === 2 ? object.type : void 0;
|
|
50
|
+
for (const key of keys) {
|
|
51
|
+
if (key === "type" || key === "version") {
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
if (!isFlowStylePropertyName(key)) {
|
|
55
|
+
issues.push({ path: key, message: `Unknown property '${key}' is kept but not used.`, severity: "warning" });
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
issues.push(...flowStylePropertyExpression(version, key, object[key]).issues);
|
|
59
|
+
if (geometry && UNUSED_BY_GEOMETRY[geometry].includes(key)) {
|
|
60
|
+
issues.push({ path: key, message: `\`${key}\` is not used by ${geometry} styles.`, severity: "warning" });
|
|
61
|
+
}
|
|
62
|
+
if (version === 1 && key === "labelText" && object[key] !== void 0) {
|
|
63
|
+
if (typeof object[key] !== "string") {
|
|
64
|
+
issues.push({
|
|
65
|
+
path: key,
|
|
66
|
+
message: "Version 1 draws a label only when `labelText` is a plain string, such as `@name`.",
|
|
67
|
+
severity: "warning"
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return issues;
|
|
73
|
+
}
|
|
74
|
+
function checkType(type, version, hasVersion) {
|
|
75
|
+
if (type === void 0) {
|
|
76
|
+
return "The style has no `type`.";
|
|
77
|
+
}
|
|
78
|
+
if (version === 1) {
|
|
79
|
+
if (type === "flow") {
|
|
80
|
+
return void 0;
|
|
81
|
+
}
|
|
82
|
+
if (typeof type === "string" && GEOMETRIES.includes(type)) {
|
|
83
|
+
return hasVersion ? "A version 1 style has `type: 'flow'`; its geometry is on the composite sub-layer." : `A version 2 style needs \`version: 2\`. A style with no version is read as version 1, whose \`type\` is 'flow'.`;
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
if (typeof type === "string" && GEOMETRIES.includes(type)) {
|
|
87
|
+
return void 0;
|
|
88
|
+
}
|
|
89
|
+
if (type === "flow") {
|
|
90
|
+
return "A version 2 style's `type` is its geometry: 'circle', 'line' or 'fill'.";
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (typeof type === "string" && OTHER_MAPLIBRE_TYPES.includes(type)) {
|
|
94
|
+
return `Unsupported geometry '${type}': flow styles support 'circle', 'line' and 'fill'.`;
|
|
95
|
+
}
|
|
96
|
+
return `Unknown type ${describe(type)}.`;
|
|
97
|
+
}
|
|
98
|
+
function describe(value) {
|
|
99
|
+
if (value === null) {
|
|
100
|
+
return "null";
|
|
101
|
+
}
|
|
102
|
+
if (Array.isArray(value)) {
|
|
103
|
+
return "an array";
|
|
104
|
+
}
|
|
105
|
+
if (typeof value === "string") {
|
|
106
|
+
return `'${value}'`;
|
|
107
|
+
}
|
|
108
|
+
if (typeof value === "object") {
|
|
109
|
+
return "an object";
|
|
110
|
+
}
|
|
111
|
+
if (typeof value === "function") {
|
|
112
|
+
return "a function";
|
|
113
|
+
}
|
|
114
|
+
return String(value);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export { validateFlowStyle };
|
|
@@ -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 };
|
|
@@ -49,6 +49,15 @@ const _MapDataSource = class _MapDataSource {
|
|
|
49
49
|
get featureId() {
|
|
50
50
|
return this._options.featureId;
|
|
51
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Selection options the data source declares, which the
|
|
54
|
+
* {@link flow-rdf-core/plugins!SelectionPlugin | SelectionPlugin} enables. See {@link MapDataSourceOptions.selection}.
|
|
55
|
+
*
|
|
56
|
+
* @experimental
|
|
57
|
+
*/
|
|
58
|
+
get selection() {
|
|
59
|
+
return this._options.selection;
|
|
60
|
+
}
|
|
52
61
|
get dataSourceSpecification() {
|
|
53
62
|
let src = this._srcExpression ? mobx.toJS(this._srcExpression.value) : this._options.src;
|
|
54
63
|
if (isString(src)) {
|