UNPKG

geostyler-sld-parser

Version:
173 lines (172 loc) 5.35 kB
import { isGeoStylerNumberFunction as k, isGeoStylerFunction as N } from "geostyler-style"; import { ARITHMETIC_OPERATORS as T } from "../SldStyleParser.js"; function C(t) { return k(t) ? t : Number(t); } function V(t) { return N(t) ? L(t) : [{ "#text": t.toString() }]; } function L(t) { const { name: r } = t; if (r === "pi" || r === "random") return [{ "ogc:Function": [], ":@": { "@_name": r } }]; if (r === "property") return { "ogc:PropertyName": [{ "#text": t.args[0] }] }; const i = t.args.map((n) => { if (N(n)) { const o = L(n); return Array.isArray(o) ? o[0] : o; } else return { "ogc:Literal": [{ "#text": n }] }; }); return T.includes(r.toLowerCase()) ? [{ ["ogc:" + r[0].toUpperCase() + r.slice(1).toLowerCase()]: i }] : [{ "ogc:Function": i, ":@": { "@_name": r === "custom" ? t.fnName : r } }]; } function P(t) { var n, o, u, e, a, f; if (t != null && t["#text"]) return C(t["#text"]); if ((o = (n = t == null ? void 0 : t.Literal) == null ? void 0 : n[0]) != null && o["#text"]) return (e = (u = t == null ? void 0 : t.Literal) == null ? void 0 : u[0]) == null ? void 0 : e["#text"]; if ((a = t == null ? void 0 : t[":@"]) != null && a["@_name"]) return S([t]); const r = Object.keys(t)[0], i = r.toLowerCase(); if (T.includes(i)) return { name: i, args: ((f = t[r]) == null ? void 0 : f.map((c) => P(c))) ?? [] }; } function S(t) { var o, u; const r = (u = (o = t == null ? void 0 : t[0]) == null ? void 0 : o[":@"]) == null ? void 0 : u["@_name"], i = t == null ? void 0 : t[0].Function.map((e) => { var a, f, c, s; return e.Function ? S([e]) : e.PropertyName ? { name: "property", args: [(f = (a = e == null ? void 0 : e.PropertyName) == null ? void 0 : a[0]) == null ? void 0 : f["#text"]] } : (s = (c = e == null ? void 0 : e.Literal) == null ? void 0 : c[0]) == null ? void 0 : s["#text"]; }), n = { name: r }; return N(n) || (n.fnName = r, n.name = "custom", n.args = []), i.length > 0 && (n.args = i), n; } function b(t, r) { return t == null ? void 0 : t.filter((i) => Object.keys(i).includes(r)); } function h(t, r, i) { var o, u, e, a, f, c, s, p, y, x; if (!t) return; const n = t.filter((g) => { var O; return (O = Object.keys(g)) == null ? void 0 : O.includes(i); }).find((g) => { var O; return ((O = g == null ? void 0 : g[":@"]) == null ? void 0 : O["@_name"]) === r; }); return (u = (o = n == null ? void 0 : n[i]) == null ? void 0 : o[0]) != null && u.Function ? S(n == null ? void 0 : n[i]) : (a = (e = n == null ? void 0 : n[i]) == null ? void 0 : e[0]) != null && a.Literal ? (p = (s = (c = (f = n == null ? void 0 : n[i]) == null ? void 0 : f[0]) == null ? void 0 : c.Literal) == null ? void 0 : s[0]) == null ? void 0 : p["#text"] : (x = (y = n == null ? void 0 : n[i]) == null ? void 0 : y[0]) == null ? void 0 : x["#text"]; } function _(t, r, i) { return h(t, r, i === "1.0.0" ? "CssParameter" : "SvgParameter"); } function w(t, r) { return h(t, r, "VendorOption"); } function F(t, r) { var i; return (i = t == null ? void 0 : t[":@"]) == null ? void 0 : i[`@_${r}`]; } function I(t) { return Object.keys(t).some((r) => r.endsWith("Symbolizer")); } function W(t, r, i) { var f, c, s, p, y, x; const n = r.split(/\.(.*)/s); let o = n[0]; const u = n[1]; let e = t, a = 0; if (u != null && u.startsWith("@")) return e = b(t, o)[a], F(e, u.substring(1)); if (Array.isArray(t)) { if (o === "#text") { if ((f = e[0]) != null && f.Function) return S(e); if ((c = e[0]) != null && c.Literal) return (y = (p = (s = e[0]) == null ? void 0 : s.Literal) == null ? void 0 : p[0]) == null ? void 0 : y["#text"]; } if (o === "#text" && ((x = e[0]) != null && x.Function)) return S(e); if (o.startsWith("$") && i) return _(e, o.substring(1), i); o.endsWith("]") && (a = Number(o.split("[")[1].split("]")[0]), o = o.split("[")[0]), e = b(t, o)[a]; } if (e) return u ? W(e[o], u, i) : e[o]; } function R(t, r) { return Object.keys(t).filter((i) => t[i] === r); } function z(t) { const r = t.split(","); if (r.length !== 2 || !r[0].startsWith("data:image/") || !r[0].endsWith(";base64")) return; const i = r[0].split(";"); if (i.length !== 2) return; const n = i[0].split("/").pop(); if (n) return { data: r[1], extension: n }; } function B(t) { return typeof t == "number" && !isNaN(t); } function $(t) { return t != null && typeof t.valueOf() == "string"; } function m(t, r) { for (const i in r) r[i] instanceof Object && Object.assign(r[i], m(t[i] ?? {}, r[i])); return Object.assign(t || {}, r), t; } export { V as geoStylerFunctionOrTextToSld, L as geoStylerFunctionToSldFunction, W as get, F as getAttribute, z as getBase64Object, b as getChildren, _ as getParameterValue, h as getTextValueInSldObject, w as getVendorOptionValue, B as isNumber, $ as isString, I as isSymbolizer, R as keysByValue, m as merge, C as numberExpression, S as sldFunctionToGeoStylerFunction, P as sldNumberOperatorOrFunctionOrTextToGeostyler }; //# sourceMappingURL=SldUtil.js.map