@mapsight/vector-style-compiler 8.0.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 (94) hide show
  1. package/README.md +366 -0
  2. package/bin/vector-style-compiler.js +2 -0
  3. package/dist/cli.d.ts +2 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +83 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/cssToRules/mapDeclaration.d.ts +16 -0
  8. package/dist/cssToRules/mapDeclaration.d.ts.map +1 -0
  9. package/dist/cssToRules/mapDeclaration.js +24 -0
  10. package/dist/cssToRules/mapDeclaration.js.map +1 -0
  11. package/dist/cssToRules/mapRule.d.ts +41 -0
  12. package/dist/cssToRules/mapRule.d.ts.map +1 -0
  13. package/dist/cssToRules/mapRule.js +60 -0
  14. package/dist/cssToRules/mapRule.js.map +1 -0
  15. package/dist/cssToRules/mapSelector.d.ts +27 -0
  16. package/dist/cssToRules/mapSelector.d.ts.map +1 -0
  17. package/dist/cssToRules/mapSelector.js +61 -0
  18. package/dist/cssToRules/mapSelector.js.map +1 -0
  19. package/dist/cssToRules/mapSelectorPart.d.ts +48 -0
  20. package/dist/cssToRules/mapSelectorPart.d.ts.map +1 -0
  21. package/dist/cssToRules/mapSelectorPart.js +106 -0
  22. package/dist/cssToRules/mapSelectorPart.js.map +1 -0
  23. package/dist/cssToRules/mapValue.d.ts +20 -0
  24. package/dist/cssToRules/mapValue.d.ts.map +1 -0
  25. package/dist/cssToRules/mapValue.js +67 -0
  26. package/dist/cssToRules/mapValue.js.map +1 -0
  27. package/dist/cssToRules.d.ts +50 -0
  28. package/dist/cssToRules.d.ts.map +1 -0
  29. package/dist/cssToRules.js +32 -0
  30. package/dist/cssToRules.js.map +1 -0
  31. package/dist/helpers/Replacer.d.ts +11 -0
  32. package/dist/helpers/Replacer.d.ts.map +1 -0
  33. package/dist/helpers/Replacer.js +28 -0
  34. package/dist/helpers/Replacer.js.map +1 -0
  35. package/dist/helpers/compileDeclarationBlock.d.ts +14 -0
  36. package/dist/helpers/compileDeclarationBlock.d.ts.map +1 -0
  37. package/dist/helpers/compileDeclarationBlock.js +38 -0
  38. package/dist/helpers/compileDeclarationBlock.js.map +1 -0
  39. package/dist/helpers/createModulesMapFromDependencies.d.ts +5 -0
  40. package/dist/helpers/createModulesMapFromDependencies.d.ts.map +1 -0
  41. package/dist/helpers/createModulesMapFromDependencies.js +31 -0
  42. package/dist/helpers/createModulesMapFromDependencies.js.map +1 -0
  43. package/dist/helpers/ensureObject.d.ts +3 -0
  44. package/dist/helpers/ensureObject.d.ts.map +1 -0
  45. package/dist/helpers/ensureObject.js +12 -0
  46. package/dist/helpers/ensureObject.js.map +1 -0
  47. package/dist/helpers/pathToExpression.d.ts +2 -0
  48. package/dist/helpers/pathToExpression.d.ts.map +1 -0
  49. package/dist/helpers/pathToExpression.js +6 -0
  50. package/dist/helpers/pathToExpression.js.map +1 -0
  51. package/dist/helpers/uniqueSerialized.d.ts +2 -0
  52. package/dist/helpers/uniqueSerialized.d.ts.map +1 -0
  53. package/dist/helpers/uniqueSerialized.js +5 -0
  54. package/dist/helpers/uniqueSerialized.js.map +1 -0
  55. package/dist/index.d.ts +8 -0
  56. package/dist/index.d.ts.map +1 -0
  57. package/dist/index.js +15 -0
  58. package/dist/index.js.map +1 -0
  59. package/dist/rulesToTree.d.ts +20 -0
  60. package/dist/rulesToTree.d.ts.map +1 -0
  61. package/dist/rulesToTree.js +43 -0
  62. package/dist/rulesToTree.js.map +1 -0
  63. package/dist/template.d.ts +16 -0
  64. package/dist/template.d.ts.map +1 -0
  65. package/dist/template.js +22 -0
  66. package/dist/template.js.map +1 -0
  67. package/dist/template.source.d.ts +3 -0
  68. package/dist/template.source.d.ts.map +1 -0
  69. package/dist/template.source.js +50 -0
  70. package/dist/template.source.js.map +1 -0
  71. package/dist/treeToProgram.d.ts +3 -0
  72. package/dist/treeToProgram.d.ts.map +1 -0
  73. package/dist/treeToProgram.js +158 -0
  74. package/dist/treeToProgram.js.map +1 -0
  75. package/package.json +67 -0
  76. package/src/data/custom-css-properties.json +200 -0
  77. package/src/js/cli.ts +98 -0
  78. package/src/js/cssToRules/mapDeclaration.ts +45 -0
  79. package/src/js/cssToRules/mapRule.ts +98 -0
  80. package/src/js/cssToRules/mapSelector.ts +78 -0
  81. package/src/js/cssToRules/mapSelectorPart.ts +161 -0
  82. package/src/js/cssToRules/mapValue.ts +84 -0
  83. package/src/js/cssToRules.ts +49 -0
  84. package/src/js/helpers/Replacer.ts +50 -0
  85. package/src/js/helpers/compileDeclarationBlock.ts +60 -0
  86. package/src/js/helpers/createModulesMapFromDependencies.ts +40 -0
  87. package/src/js/helpers/ensureObject.ts +17 -0
  88. package/src/js/helpers/pathToExpression.ts +5 -0
  89. package/src/js/helpers/uniqueSerialized.ts +7 -0
  90. package/src/js/index.ts +28 -0
  91. package/src/js/rulesToTree.ts +83 -0
  92. package/src/js/template.source.js +56 -0
  93. package/src/js/template.ts +50 -0
  94. package/src/js/treeToProgram.ts +220 -0
@@ -0,0 +1,61 @@
1
+ import unique from "@mapsight/lib-js/array/unique";
2
+ import { isTruthy } from "@mapsight/lib-js/boolean";
3
+ import { ensureNonNullable } from "@mapsight/lib-js/nonNullable";
4
+ import mapSelectorPart from "./mapSelectorPart.js";
5
+ /**
6
+ * Finds
7
+ * A) Words incl. whitespace enclosed by matching single quotes ('), square brackets ([,]), not (:not(,)) or matching double quotes (") and
8
+ * B) Words (groups of non-whitespace characters)
9
+ *
10
+ * @type {RegExp}
11
+ */
12
+ const REGEX_SELECTOR_PART = /('.*?'|\[.*?]|:not\(.*?\)|".*?"|\S+)/g;
13
+ export default function mapSelector(selector) {
14
+ const selectorParts = ensureNonNullable(selector.match(REGEX_SELECTOR_PART))
15
+ .map((part) => mapSelectorPart(part))
16
+ .filter(isTruthy);
17
+ const checks = unique(selectorParts.map((a) => "check" in a && a.check).filter(isTruthy));
18
+ const mergedStateNames = unique(selectorParts
19
+ .map((part) => "stateNames" in part.__meta
20
+ ? part.__meta.stateNames
21
+ : undefined)
22
+ .filter(isTruthy)
23
+ .flat());
24
+ const mergedStyleProps = unique(selectorParts
25
+ .map((part) => "styleProps" in part.__meta
26
+ ? part.__meta.styleProps
27
+ : undefined)
28
+ .filter(isTruthy)
29
+ .flat());
30
+ const mergedStylePropExpressions = unique(selectorParts
31
+ .map((part) => "stylePropExpressions" in part.__meta
32
+ ? part.__meta.stylePropExpressions
33
+ : undefined)
34
+ .filter(isTruthy)
35
+ .flat());
36
+ let style;
37
+ let state;
38
+ let group;
39
+ for (const part of selectorParts) {
40
+ if (!state && "group" in part)
41
+ group = part.group;
42
+ if (!style && "style" in part)
43
+ style = part.style;
44
+ if (!state && "state" in part)
45
+ state = part.state;
46
+ if (state && style && group)
47
+ break;
48
+ }
49
+ return {
50
+ style: style,
51
+ state: state,
52
+ group: group || "default",
53
+ checks: checks?.length ? checks : undefined,
54
+ __meta: {
55
+ stateNames: mergedStateNames,
56
+ styleProps: mergedStyleProps,
57
+ stylePropExpressions: mergedStylePropExpressions,
58
+ },
59
+ };
60
+ }
61
+ //# sourceMappingURL=mapSelector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapSelector.js","sourceRoot":"","sources":["../../src/js/cssToRules/mapSelector.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,+BAA+B,CAAC;AACnD,OAAO,EAAC,QAAQ,EAAC,MAAM,0BAA0B,CAAC;AAClD,OAAO,EAAC,iBAAiB,EAAC,MAAM,8BAA8B,CAAC;AAE/D,OAAO,eAAe,MAAM,sBAAsB,CAAC;AAEnD;;;;;;GAMG;AACH,MAAM,mBAAmB,GAAW,uCAAuC,CAAC;AAI5E,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,QAAgB;IACnD,MAAM,aAAa,GAAG,iBAAiB,CAAC,QAAQ,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;SAC1E,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,C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,CAAC;QAClD,IAAI,CAAC,KAAK,IAAI,OAAO,IAAI,IAAI;YAAE,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QAClD,IAAI,CAAC,KAAK,IAAI,OAAO,IAAI,IAAI;YAAE,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QAClD,IAAI,KAAK,IAAI,KAAK,IAAI,KAAK;YAAE,MAAM;IACpC,CAAC;IAED,OAAO;QACN,KAAK,EAAE,KAAK;QACZ,KAAK,EAAE,KAAK;QACZ,KAAK,EAAE,KAAK,IAAI,SAAS;QACzB,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;QAE3C,MAAM,EAAE;YACP,UAAU,EAAE,gBAAgB;YAC5B,UAAU,EAAE,gBAAgB;YAC5B,oBAAoB,EAAE,0BAA0B;SAChD;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,48 @@
1
+ type JsCheck = {
2
+ type: "js";
3
+ expression: string;
4
+ negate: boolean;
5
+ };
6
+ type GeometryTypeCheck = {
7
+ type: "geometryType";
8
+ value: string;
9
+ negate: boolean;
10
+ };
11
+ type ValueCheck = {
12
+ type: "value";
13
+ target: "props" | "env";
14
+ path: string[];
15
+ value?: string | number | null;
16
+ negate: boolean;
17
+ };
18
+ export type Check = JsCheck | GeometryTypeCheck | ValueCheck;
19
+ export default function mapSelectorPart(part: string, negate?: boolean): {
20
+ check: Check;
21
+ __meta: {
22
+ styleProps?: string[];
23
+ stylePropExpressions?: string[];
24
+ stateNames?: string[];
25
+ };
26
+ } | {
27
+ readonly __meta: {};
28
+ readonly state?: undefined;
29
+ readonly style?: undefined;
30
+ readonly group?: undefined;
31
+ } | {
32
+ readonly state: string;
33
+ readonly __meta: {};
34
+ readonly style?: undefined;
35
+ readonly group?: undefined;
36
+ } | {
37
+ readonly style: string;
38
+ readonly __meta: {};
39
+ readonly state?: undefined;
40
+ readonly group?: undefined;
41
+ } | {
42
+ readonly group: string;
43
+ readonly __meta: {};
44
+ readonly state?: undefined;
45
+ readonly style?: undefined;
46
+ } | null;
47
+ export {};
48
+ //# sourceMappingURL=mapSelectorPart.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapSelectorPart.d.ts","sourceRoot":"","sources":["../../src/js/cssToRules/mapSelectorPart.ts"],"names":[],"mappings":"AAIA,KAAK,OAAO,GAAG;IACd,IAAI,EAAE,IAAI,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACxB,IAAI,EAAE,cAAc,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF,KAAK,UAAU,GAAG;IACjB,IAAI,EAAE,OAAO,CAAC;IACd,MAAM,EAAE,OAAO,GAAG,KAAK,CAAC;IACxB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC/B,MAAM,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,KAAK,GAAG,OAAO,GAAG,iBAAiB,GAAG,UAAU,CAAC;AAoG7D,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,UAAQ;WA9F5D,KAAK;YACJ;QACP,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;QACtB,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;QAChC,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;KACtB;;;;;;;;;;;;;;;;;;;;;SA6HD"}
@@ -0,0 +1,106 @@
1
+ import trimQuotes from "@mapsight/lib-js/string/trimQuotes";
2
+ import mapValue from "./mapValue.js";
3
+ function mapAttributeSelectorPart(part, negate = false) {
4
+ const operands = part
5
+ .slice(1, -1) // remove square brackets
6
+ .split("="); // split by first equal sign
7
+ let leftHandOperand = operands?.shift()?.trim() || "";
8
+ const rightHandOperand = operands.length
9
+ ? trimQuotes(operands.join("=").trim())
10
+ : undefined;
11
+ // special case: js expression
12
+ if (leftHandOperand.startsWith("|js")) {
13
+ return {
14
+ check: {
15
+ type: "js",
16
+ expression: rightHandOperand || "",
17
+ negate,
18
+ },
19
+ __meta: {},
20
+ };
21
+ }
22
+ // special case: geometry type
23
+ if (leftHandOperand === "geometry|type") {
24
+ const { value, __meta: valueMeta } = mapValue(rightHandOperand);
25
+ return {
26
+ check: {
27
+ type: "geometryType",
28
+ value: String(value ?? ""),
29
+ negate,
30
+ },
31
+ __meta: valueMeta,
32
+ };
33
+ }
34
+ let target = "props";
35
+ // env target
36
+ if (leftHandOperand.startsWith("env|")) {
37
+ target = "env";
38
+ leftHandOperand = leftHandOperand.slice(4);
39
+ }
40
+ else if (leftHandOperand.startsWith("props|")) {
41
+ // trim optional prefix
42
+ leftHandOperand = leftHandOperand.slice(6);
43
+ }
44
+ // kebab case to dot separated string
45
+ const path = leftHandOperand.split("-");
46
+ // keep track of props used for styling
47
+ let stateNames = [];
48
+ let styleProps = [];
49
+ let stylePropExpressions = [];
50
+ if (target === "props") {
51
+ styleProps.push(path[0]);
52
+ }
53
+ let value = undefined;
54
+ if (rightHandOperand !== undefined) {
55
+ const mappedValue = mapValue(rightHandOperand);
56
+ value = mappedValue.value;
57
+ styleProps = styleProps.concat(mappedValue.__meta.styleProps);
58
+ stylePropExpressions = stylePropExpressions.concat(mappedValue.__meta.stylePropExpressions);
59
+ if (leftHandOperand === "state") {
60
+ stateNames = [rightHandOperand];
61
+ }
62
+ }
63
+ return {
64
+ check: {
65
+ type: "value",
66
+ target,
67
+ path,
68
+ value,
69
+ negate,
70
+ },
71
+ __meta: {
72
+ stateNames: stateNames,
73
+ styleProps: styleProps,
74
+ stylePropExpressions: stylePropExpressions,
75
+ },
76
+ };
77
+ }
78
+ export default function mapSelectorPart(part, negate = false) {
79
+ // Handle :not(...) negation using recursion
80
+ if (part.startsWith(":not(") && part.endsWith(")")) {
81
+ const inner = part.slice(5, -1).trim(); // remove :not( and )
82
+ return mapSelectorPart(inner, !negate);
83
+ }
84
+ const firstLetter = part.charAt(0);
85
+ if (firstLetter === "[") {
86
+ return mapAttributeSelectorPart(part, negate);
87
+ }
88
+ if (negate) {
89
+ throw new Error("Cannot negate selector part [" + part + "] with :not().");
90
+ }
91
+ if (firstLetter === "*") {
92
+ return { __meta: {} };
93
+ }
94
+ const rest = part.slice(1);
95
+ if (firstLetter === ":") {
96
+ return { state: rest, __meta: {} };
97
+ }
98
+ if (firstLetter === "#") {
99
+ return { style: rest, __meta: {} };
100
+ }
101
+ if (firstLetter === ".") {
102
+ return { group: rest, __meta: {} };
103
+ }
104
+ return null;
105
+ }
106
+ //# sourceMappingURL=mapSelectorPart.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapSelectorPart.js","sourceRoot":"","sources":["../../src/js/cssToRules/mapSelectorPart.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,oCAAoC,CAAC;AAE5D,OAAO,QAAQ,MAAM,eAAe,CAAC;AAwBrC,SAAS,wBAAwB,CAChC,IAAY,EACZ,MAAM,GAAG,KAAK;IASd,MAAM,QAAQ,GAAG,IAAI;SACnB,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,yBAAyB;SACtC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,4BAA4B;IAC1C,IAAI,eAAe,GAAG,QAAQ,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACtD,MAAM,gBAAgB,GAAG,QAAQ,CAAC,MAAM;QACvC,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;QACvC,CAAC,CAAC,SAAS,CAAC;IAEb,8BAA8B;IAC9B,IAAI,eAAe,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;QACvC,OAAO;YAC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,GAAG,IAAI,GAAG,gBAAgB,CACzD,CAAC;IACH,CAAC;IAED,IAAI,WAAW,KAAK,GAAG,EAAE,CAAC;QACzB,OAAO,EAAC,MAAM,EAAE,EAAE,EAAU,CAAC;IAC9B,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC3B,IAAI,WAAW,KAAK,GAAG,EAAE,CAAC;QACzB,OAAO,EAAC,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAU,CAAC;IAC3C,CAAC;IAED,IAAI,WAAW,KAAK,GAAG,EAAE,CAAC;QACzB,OAAO,EAAC,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAU,CAAC;IAC3C,CAAC;IAED,IAAI,WAAW,KAAK,GAAG,EAAE,CAAC;QACzB,OAAO,EAAC,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAU,CAAC;IAC3C,CAAC;IAED,OAAO,IAAI,CAAC;AACb,CAAC"}
@@ -0,0 +1,20 @@
1
+ export default function mapValue(value: string | number | null | undefined | boolean): {
2
+ value: null;
3
+ __meta: {
4
+ styleProps: Array<string>;
5
+ stylePropExpressions: Array<string>;
6
+ };
7
+ } | {
8
+ value: number;
9
+ __meta: {
10
+ styleProps: Array<string>;
11
+ stylePropExpressions: Array<string>;
12
+ };
13
+ } | {
14
+ readonly value: string;
15
+ readonly __meta: {
16
+ readonly styleProps: string[];
17
+ readonly stylePropExpressions: string[];
18
+ };
19
+ };
20
+ //# sourceMappingURL=mapValue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapValue.d.ts","sourceRoot":"","sources":["../../src/js/cssToRules/mapValue.ts"],"names":[],"mappings":"AA+BA,MAAM,CAAC,OAAO,UAAU,QAAQ,CAC/B,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO;;;oBAGhC,KAAK,CAAC,MAAM,CAAC;8BACH,KAAK,CAAC,MAAM,CAAC;;;;;oBADvB,KAAK,CAAC,MAAM,CAAC;8BACH,KAAK,CAAC,MAAM,CAAC;;;;;;;;EA+C1C"}
@@ -0,0 +1,67 @@
1
+ import uniq from "lodash/uniq.js";
2
+ import { ensureNonNullable } from "@mapsight/lib-js/nonNullable";
3
+ import trimQuotes from "@mapsight/lib-js/string/trimQuotes";
4
+ import isNumberLike from "@mapsight/lib-js/types/isNumberLike";
5
+ import Replacer from "../helpers/Replacer.js";
6
+ import pathToExpression from "../helpers/pathToExpression.js";
7
+ const replace = (_match, parameter) => {
8
+ const [search, replacement, subject] = parameter
9
+ .split(",")
10
+ .map((a) => a.trim())
11
+ .map(trimQuotes);
12
+ return `' + replace('${search}', '${replacement}', '${subject}') + '`;
13
+ };
14
+ const calc = (_match, parameter, replacer) => {
15
+ // parameter is e.g. "%%%0%%% * 5"
16
+ // Resolve the inner tags back to their actual string representations
17
+ let resolvedParam = replacer.replace(parameter);
18
+ // Clean up the string concatenations generated by the earlier `attr` pass.
19
+ // It extracts `props['test']` out of `' + props['test'] + '`
20
+ resolvedParam = resolvedParam.replace(/' \+ (.*?) \+ '/g, "$1");
21
+ return `' + (${resolvedParam}) + '`;
22
+ };
23
+ export default function mapValue(value) {
24
+ const meta = {
25
+ styleProps: [],
26
+ stylePropExpressions: [],
27
+ };
28
+ if (!value) {
29
+ return { value: null, __meta: meta };
30
+ }
31
+ let valueStr = String(value);
32
+ if (isNumberLike(value)) {
33
+ return { value: parseFloat(valueStr), __meta: meta };
34
+ }
35
+ valueStr = trimQuotes(valueStr);
36
+ const replacer = new Replacer([
37
+ [
38
+ "attr",
39
+ (_match, parameter) => {
40
+ const isEnv = parameter.startsWith("--env-");
41
+ const parameters = parameter.split("-");
42
+ if (isEnv) {
43
+ const restParameters = parameters.slice(3);
44
+ return `' + ${pathToExpression("env", restParameters)} + '`;
45
+ }
46
+ const expression = pathToExpression("props", parameters);
47
+ meta.styleProps.push(ensureNonNullable(parameters[0]));
48
+ meta.stylePropExpressions.push(expression);
49
+ return `' + ${expression} + '`;
50
+ },
51
+ ],
52
+ ["replace", replace],
53
+ ["calc", calc],
54
+ ]);
55
+ valueStr = replacer.execute(valueStr);
56
+ valueStr = valueStr.replace(/'/g, "\\'");
57
+ valueStr = replacer.replace(valueStr);
58
+ valueStr = `'${valueStr}'`;
59
+ return {
60
+ value: valueStr,
61
+ __meta: {
62
+ styleProps: uniq(meta.styleProps),
63
+ stylePropExpressions: uniq(meta.stylePropExpressions),
64
+ },
65
+ };
66
+ }
67
+ //# sourceMappingURL=mapValue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mapValue.js","sourceRoot":"","sources":["../../src/js/cssToRules/mapValue.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,gBAAgB,CAAC;AAElC,OAAO,EAAC,iBAAiB,EAAC,MAAM,8BAA8B,CAAC;AAC/D,OAAO,UAAU,MAAM,oCAAoC,CAAC;AAC5D,OAAO,YAAY,MAAM,qCAAqC,CAAC;AAG/D,OAAO,QAAQ,MAAM,wBAAwB,CAAC;AAC9C,OAAO,gBAAgB,MAAM,gCAAgC,CAAC;AAE9D,MAAM,OAAO,GAAe,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE;IACjD,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,CAAC,GAAG,SAAS;SAC9C,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SACpB,GAAG,CAAC,UAAU,CAAC,CAAC;IAElB,OAAO,gBAAgB,MAAM,OAAO,WAAW,OAAO,OAAO,QAAQ,CAAC;AACvE,CAAC,CAAC;AAEF,MAAM,IAAI,GAAe,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE;IACxD,kCAAkC;IAClC,qEAAqE;IACrE,IAAI,aAAa,GAAG,QAAQ,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC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C,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;gBACvD,IAAI,CAAC,oBAAoB,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;gBAC3C,OAAO,OAAO,UAAU,MAAM,CAAC;YAChC,CAAC;SACD;QACD,CAAC,SAAS,EAAE,OAAO,CAAC;QACpB,CAAC,MAAM,EAAE,IAAI,CAAC;KACd,CAAC,CAAC;IACH,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACtC,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACzC,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACtC,QAAQ,GAAG,IAAI,QAAQ,GAAG,CAAC;IAE3B,OAAO;QACN,KAAK,EAAE,QAAQ;QAEf,MAAM,EAAE;YACP,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC;YACjC,oBAAoB,EAAE,IAAI,CAAC,IAAI,CAAC,oBAAoB,CAAC;SACrD;KACQ,CAAC;AACZ,CAAC"}
@@ -0,0 +1,50 @@
1
+ export type Rules = ReturnType<typeof cssToRules>;
2
+ export default function cssToRules(content: string): {
3
+ rules: {
4
+ conditions: {
5
+ style: string | undefined;
6
+ state: string | undefined;
7
+ group: string;
8
+ checks: ({
9
+ type: "js";
10
+ expression: string;
11
+ negate: boolean;
12
+ } | {
13
+ type: "geometryType";
14
+ value: string;
15
+ negate: boolean;
16
+ } | {
17
+ type: "value";
18
+ target: "props" | "env";
19
+ path: string[];
20
+ value?: string | number | null;
21
+ negate: boolean;
22
+ })[] | undefined;
23
+ __meta: {
24
+ stateNames: string[];
25
+ styleProps: string[];
26
+ stylePropExpressions: string[];
27
+ };
28
+ }[];
29
+ declarations: {
30
+ [x: string]: import("./cssToRules/mapDeclaration.ts").DeclarationNode;
31
+ };
32
+ __meta: {
33
+ styleNames: string[];
34
+ stateNames: string[];
35
+ groupNames: string[];
36
+ declarationNames: string[];
37
+ styleProps: string[];
38
+ stylePropExpressions: string[];
39
+ };
40
+ }[];
41
+ __meta: {
42
+ styleNames: string[];
43
+ stateNames: string[];
44
+ groupNames: string[];
45
+ declarationNames: string[];
46
+ styleProps: string[];
47
+ stylePropExpressions: string[];
48
+ };
49
+ };
50
+ //# sourceMappingURL=cssToRules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cssToRules.d.ts","sourceRoot":"","sources":["../src/js/cssToRules.ts"],"names":[],"mappings":"AAgCA,MAAM,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,UAAU,CAAC,CAAC;AAElD,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,OAAO,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAcjD"}
@@ -0,0 +1,32 @@
1
+ import { parse } from "css";
2
+ import unique from "@mapsight/lib-js/array/unique";
3
+ import mapRule from "./cssToRules/mapRule.js";
4
+ const collectMeta = (vals, key) => {
5
+ const values = vals.map((v) => v.__meta[key]).flat();
6
+ return unique(values);
7
+ };
8
+ function isRule(val) {
9
+ return val.type === "rule";
10
+ }
11
+ // types: rule,
12
+ // ignored types: media, stylesheet, comment, charset, custom-media, document, font-face,
13
+ // import, keyframes, keyframe, media, namespace, page, supports
14
+ function cssOmToRules(om) {
15
+ return om.stylesheet?.rules.filter(isRule).flatMap(mapRule) ?? [];
16
+ }
17
+ export default function cssToRules(content) {
18
+ const om = parse(content);
19
+ const rules = cssOmToRules(om);
20
+ return {
21
+ rules,
22
+ __meta: {
23
+ styleNames: collectMeta(rules, "styleNames"),
24
+ stateNames: collectMeta(rules, "stateNames"),
25
+ groupNames: collectMeta(rules, "groupNames"),
26
+ declarationNames: collectMeta(rules, "declarationNames"),
27
+ styleProps: collectMeta(rules, "styleProps"),
28
+ stylePropExpressions: collectMeta(rules, "stylePropExpressions"),
29
+ },
30
+ };
31
+ }
32
+ //# sourceMapping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E,WAAW,CAAC,KAAK,EAAE,YAAY,CAAC;YAC5C,oBAAoB,EAAE,WAAW,CAAC,KAAK,EAAE,sBAAsB,CAAC;SAChE;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,11 @@
1
+ export type ReplacerFn = (match: string, parameter: string, replacer: Replacer) => string;
2
+ export default class Replacer {
3
+ private replacementCounter;
4
+ private replacements;
5
+ private functions;
6
+ constructor(functions?: Array<[string, ReplacerFn]>);
7
+ addFunction(functionName: string, replacer: ReplacerFn): void;
8
+ execute(value: string): string;
9
+ replace(value: string): string;
10
+ }
11
+ //# sourceMappingURL=Replacer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Replacer.d.ts","sourceRoot":"","sources":["../../src/js/helpers/Replacer.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,UAAU,GAAG,CACxB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,QAAQ,KACd,MAAM,CAAC;AAEZ,MAAM,CAAC,OAAO,OAAO,QAAQ;IAC5B,OAAO,CAAC,kBAAkB,CAAa;IACvC,OAAO,CAAC,YAAY,CAAiD;IACrE,OAAO,CAAC,SAAS,CAAsC;gBAE3C,SAAS,GAAE,KAAK,CAAC,CAAC,MAAM,EAAE,UAAU,CAAC,CAAM;IAMvD,WAAW,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU;IAiBtD,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAI9B,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;CAO9B"}
@@ -0,0 +1,28 @@
1
+ const RE_FUNCTION_PARAMETER = "([^\\)]*?)";
2
+ const RE_DOUBLE_QUOTES_IN_PARIS_ONLY = '(?:(?:[^"]*"){2})*[^"]*$';
3
+ const TAG_DELIMITER = "%%%";
4
+ export default class Replacer {
5
+ replacementCounter = 0;
6
+ replacements = [];
7
+ functions = [];
8
+ constructor(functions = []) {
9
+ functions.forEach(([functionName, replacer]) => this.addFunction(functionName, replacer));
10
+ }
11
+ addFunction(functionName, replacer) {
12
+ const regex = new RegExp(`(${functionName}\\(${RE_FUNCTION_PARAMETER}\\))(?=${RE_DOUBLE_QUOTES_IN_PARIS_ONLY})`, "ig");
13
+ const fn = (value) => value.replace(regex, (match, _, parameter) => {
14
+ const tag = TAG_DELIMITER + this.replacementCounter++ + TAG_DELIMITER;
15
+ const replacement = replacer(match, parameter, this);
16
+ this.replacements.push({ tag, replacement });
17
+ return tag;
18
+ });
19
+ this.functions.push(fn);
20
+ }
21
+ execute(value) {
22
+ return this.functions.reduce((acc, fn) => fn(acc), value);
23
+ }
24
+ replace(value) {
25
+ return this.replacements.reduceRight((acc, { tag, replacement }) => acc.replace(new RegExp(tag, "g"), replacement), value);
26
+ }
27
+ }
28
+ //# sourceMappingURL=Replacer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Replacer.js","sourceRoot":"","sources":["../../src/js/helpers/Replacer.ts"],"names":[],"mappings":"AAAA,MAAM,qBAAqB,GAAG,YAAY,CAAC;AAC3C,MAAM,8BAA8B,GAAG,0BAA0B,CAAC;AAClE,MAAM,aAAa,GAAG,KAAK,CAAC;AAQ5B,MAAM,CAAC,OAAO,OAAO,QAAQ;IACpB,kBAAkB,GAAW,CAAC,CAAC;IAC/B,YAAY,GAA8C,EAAE,CAAC;IAC7D,SAAS,GAAmC,EAAE,CAAC;IAEvD,YAAY,YAAyC,EAAE;QACtD,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,EAAE,QAAQ,CAAC,EAAE,EAAE,CAC9C,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,QAAQ,CAAC,CACxC,CAAC;IACH,CAAC;IAED,WAAW,CAAC,YAAoB,EAAE,QAAoB;QACrD,MAAM,KAAK,GAAG,IAAI,MAAM,CACvB,IAAI,YAAY,MAAM,qBAAqB,UAAU,8BAA8B,GAAG,EACtF,IAAI,CACJ,CAAC;QACF,MAAM,EAAE,GAAG,CAAC,KAAa,EAAU,EAAE,CACpC,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,SAAS,EAAE,EAAE;YAC5C,MAAM,GAAG,GACR,aAAa,GAAG,IAAI,CAAC,kBAAkB,EAAE,GAAG,aAAa,CAAC;YAC3D,MAAM,WAAW,GAAG,QAAQ,CAAC,KAAK,EAAE,SAAmB,EAAE,IAAI,CAAC,CAAC;YAC/D,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,EAAC,GAAG,EAAE,WAAW,EAAC,CAAC,CAAC;YAE3C,OAAO,GAAG,CAAC;QACZ,CAAC,CAAC,CAAC;QACJ,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACzB,CAAC;IAED,OAAO,CAAC,KAAa;QACpB,OAAO,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,CAAC;IAC3D,CAAC;IAED,OAAO,CAAC,KAAa;QACpB,OAAO,IAAI,CAAC,YAAY,CAAC,WAAW,CACnC,CAAC,GAAG,EAAE,EAAC,GAAG,EAAE,WAAW,EAAC,EAAE,EAAE,CAC3B,GAAG,CAAC,OAAO,CAAC,IAAI,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,WAAW,CAAC,EAC/C,KAAK,CACL,CAAC;IACH,CAAC;CACD"}
@@ -0,0 +1,14 @@
1
+ export type NodeValue = {
2
+ value: string | number | boolean | null;
3
+ };
4
+ export type BlockTree = {
5
+ [property: string]: BlockTree | NodeValue | null;
6
+ };
7
+ /**
8
+ * Compiles a parsed Style AST block into highly optimized JS assignments.
9
+ * @param ast The parsed style block
10
+ * @param rootName The name of the base object (default: "declaration")
11
+ * @param indent String used for indentation
12
+ */
13
+ export declare function compileDeclarationBlock(ast: BlockTree, rootName?: string, indent?: string): string;
14
+ //# sourceMappingURL=compileDeclarationBlock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compileDeclarationBlock.d.ts","sourceRoot":"","sources":["../../src/js/helpers/compileDeclarationBlock.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG;IAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,CAAA;CAAC,CAAC;AAElE,MAAM,MAAM,SAAS,GAAG;IACvB,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,IAAI,CAAC;CACjD,CAAC;AAUF;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACtC,GAAG,EAAE,SAAS,EACd,QAAQ,GAAE,MAAsB,EAChC,MAAM,GAAE,MAAa,GACnB,MAAM,CAmCR"}
@@ -0,0 +1,38 @@
1
+ const isValueNode = (node) => node !== null && typeof node === "object" && "value" in node;
2
+ const getPropertyAccess = (key) => {
3
+ const isValidIdentifier = /^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(key);
4
+ return isValidIdentifier ? `.${key}` : `["${key}"]`;
5
+ };
6
+ /**
7
+ * Compiles a parsed Style AST block into highly optimized JS assignments.
8
+ * @param ast The parsed style block
9
+ * @param rootName The name of the base object (default: "declaration")
10
+ * @param indent String used for indentation
11
+ */
12
+ export function compileDeclarationBlock(ast, rootName = "declaration", indent = " ") {
13
+ const lines = [];
14
+ function traverse(node, parentRef, path) {
15
+ for (const [key, child] of Object.entries(node)) {
16
+ const access = getPropertyAccess(key);
17
+ if (child === null) {
18
+ lines.push(`${indent}${parentRef}${access} = null;`);
19
+ continue;
20
+ }
21
+ if (isValueNode(child)) {
22
+ lines.push(`${indent}${parentRef}${access} = { value: ${child.value} };`);
23
+ }
24
+ else {
25
+ const newPath = [...path, key];
26
+ const cacheVar = "_" +
27
+ newPath
28
+ .map((p) => p.replace(/[^a-zA-Z0-9]/g, ""))
29
+ .join("_");
30
+ lines.push(`${indent}const ${cacheVar} = (${indent}${parentRef}${access} ??= {});`);
31
+ traverse(child, cacheVar, newPath);
32
+ }
33
+ }
34
+ }
35
+ traverse(ast, rootName, []);
36
+ return lines.join("");
37
+ }
38
+ //# sourceMappingURL=compileDeclarationBlock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compileDeclarationBlock.js","sourceRoot":"","sources":["../../src/js/helpers/compileDeclarationBlock.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,GAAG,CAAC,IAAa,EAAqB,EAAE,CACxD,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,OAAO,IAAI,IAAI,CAAC;AAE9D,MAAM,iBAAiB,GAAG,CAAC,GAAW,EAAU,EAAE;IACjD,MAAM,iBAAiB,GAAG,4BAA4B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACjE,OAAO,iBAAiB,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC;AACrD,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CACtC,GAAc,EACd,WAAmB,aAAa,EAChC,SAAiB,IAAI;IAErB,MAAM,KAAK,GAAa,EAAE,CAAC;IAE3B,SAAS,QAAQ,CAAC,IAAe,EAAE,SAAiB,EAAE,IAAc;QACnE,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACjD,MAAM,MAAM,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC;YAEtC,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;gBACpB,KAAK,CAAC,IAAI,CAAC,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,UAAU,CAAC,CAAC;gBACrD,SAAS;YACV,CAAC;YAED,IAAI,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;gBACxB,KAAK,CAAC,IAAI,CACT,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,eAAe,KAAK,CAAC,KAAK,KAAK,CAC7D,CAAC;YACH,CAAC;iBAAM,CAAC;gBACP,MAAM,OAAO,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,CAAC,CAAC;gBAC/B,MAAM,QAAQ,GACb,GAAG;oBACH,OAAO;yBACL,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;yBAC1C,IAAI,CAAC,GAAG,CAAC,CAAC;gBAEb,KAAK,CAAC,IAAI,CACT,GAAG,MAAM,SAAS,QAAQ,OAAO,MAAM,GAAG,SAAS,GAAG,MAAM,WAAW,CACvE,CAAC;gBAEF,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;YACpC,CAAC;QACF,CAAC;IACF,CAAC;IAED,QAAQ,CAAC,GAAG,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC;IAC5B,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACvB,CAAC"}
@@ -0,0 +1,5 @@
1
+ export default function createModulesMapFromDependencies(declarationNames: Array<string>): {
2
+ imports: string;
3
+ map: string;
4
+ };
5
+ //# sourceMappingURL=createModulesMapFromDependencies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createModulesMapFromDependencies.d.ts","sourceRoot":"","sources":["../../src/js/helpers/createModulesMapFromDependencies.ts"],"names":[],"mappings":"AAiBA,MAAM,CAAC,OAAO,UAAU,gCAAgC,CACvD,gBAAgB,EAAE,KAAK,CAAC,MAAM,CAAC;;;EAqB/B"}
@@ -0,0 +1,31 @@
1
+ import uniq from "lodash/uniq.js";
2
+ import { isTruthy } from "@mapsight/lib-js/boolean";
3
+ const IMPORT_PREFIX = "__vectorStyle_";
4
+ const OL_IMPORT_PATH_BY_NAME = {
5
+ style: "ol/style/Style",
6
+ image: "ol/style/Image",
7
+ icon: "ol/style/Icon",
8
+ circle: "ol/style/Circle",
9
+ stroke: "ol/style/Stroke",
10
+ text: "ol/style/Text",
11
+ fill: "ol/style/Fill",
12
+ regularShape: "ol/style/RegularShape",
13
+ };
14
+ export default function createModulesMapFromDependencies(declarationNames) {
15
+ // @TODO: Find a better way?:
16
+ // special case for circle. we cannot detect fill and stroke if they are used in circle (circle-stroke-color etc.)
17
+ // this assumes a circle uses fill and stroke (which it might not!)
18
+ if (declarationNames.indexOf("circle") > -1) {
19
+ declarationNames.push("stroke");
20
+ declarationNames.push("fill");
21
+ }
22
+ const names = uniq(declarationNames
23
+ .concat(["style"]) /* we always need at least ol.style.Style */
24
+ .filter(isTruthy)).filter((name) => OL_IMPORT_PATH_BY_NAME[name]);
25
+ // prettier-ignore
26
+ return {
27
+ imports: names.map(name => `import ${IMPORT_PREFIX}${name} from '${OL_IMPORT_PATH_BY_NAME[name]}';`).join('\n'),
28
+ map: `{${names.map(name => `${name}: ${IMPORT_PREFIX}${name},`).join('\n')}}`,
29
+ };
30
+ }
31
+ //# sourceMappingURL=createModulesMapFromDependencies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createModulesMapFromDependencies.js","sourceRoot":"","sources":["../../src/js/helpers/createModulesMapFromDependencies.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,gBAAgB,CAAC;AAElC,OAAO,EAAC,QAAQ,EAAC,MAAM,0BAA0B,CAAC;AAElD,MAAM,aAAa,GAAG,gBAAgB,CAAC;AAEvC,MAAM,sBAAsB,GAA2B;IACtD,KAAK,EAAE,gBAAgB;IACvB,KAAK,EAAE,gBAAgB;IACvB,IAAI,EAAE,eAAe;IACrB,MAAM,EAAE,iBAAiB;IACzB,MAAM,EAAE,iBAAiB;IACzB,IAAI,EAAE,eAAe;IACrB,IAAI,EAAE,eAAe;IACrB,YAAY,EAAE,uBAAuB;CACrC,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,gCAAgC,CACvD,gBAA+B;IAE/B,6BAA6B;IAC7B,kHAAkH;IAClH,mEAAmE;IACnE,IAAI,gBAAgB,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;QAC7C,gBAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAChC,gBAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/B,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,CACjB,gBAAgB;SACd,MAAM,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,4CAA4C;SAC9D,MAAM,CAAC,QAAQ,CAAC,CAClB,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC,CAAC;IAEjD,kBAAkB;IAClB,OAAO;QACN,OAAO,EAAE,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,UAAU,aAAa,GAAG,IAAI,UAAU,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;QAC/G,GAAG,EAAE,IAAI,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,KAAK,aAAa,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;KAC7E,CAAC;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** Replaces the value if it's falsy. */
2
+ export default function ensureObject<T extends object, K extends keyof T>(parent: T, key: K, base: T[K]): T[K];
3
+ //# sourceMappingURL=ensureObject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ensureObject.d.ts","sourceRoot":"","sources":["../../src/js/helpers/ensureObject.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,CAAC,EACvE,MAAM,EAAE,CAAC,EACT,GAAG,EAAE,CAAC,EACN,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,GACR,CAAC,CAAC,CAAC,CAAC,CAWN"}
@@ -0,0 +1,12 @@
1
+ /** Replaces the value if it's falsy. */
2
+ export default function ensureObject(parent, key, base) {
3
+ if (parent === null || parent === undefined) {
4
+ return base;
5
+ }
6
+ if (parent[key]) {
7
+ return parent[key];
8
+ }
9
+ parent[key] = base;
10
+ return base;
11
+ }
12
+ //# sourceMappingURL=ensureObject.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ensureObject.js","sourceRoot":"","sources":["../../src/js/helpers/ensureObject.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,MAAM,CAAC,OAAO,UAAU,YAAY,CACnC,MAAS,EACT,GAAM,EACN,IAAU;IAEV,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QAC7C,OAAO,IAAI,CAAC;IACb,CAAC;IAED,IAAI,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;QACjB,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC;IAED,MAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;IACnB,OAAO,IAAI,CAAC;AACb,CAAC"}
@@ -0,0 +1,2 @@
1
+ export default function pathToExpression(target: string, path: string[]): string;
2
+ //# sourceMappingURL=pathToExpression.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pathToExpression.d.ts","sourceRoot":"","sources":["../../src/js/helpers/pathToExpression.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,UAItE"}
@@ -0,0 +1,6 @@
1
+ export default function pathToExpression(target, path) {
2
+ return path.length > 1
3
+ ? `get(${target}, [${path.map((a) => `'${a}'`).join(", ")}])`
4
+ : `${target}['${path[0]}']`;
5
+ }
6
+ //# sourceMappingURL=pathToExpression.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pathToExpression.js","sourceRoot":"","sources":["../../src/js/helpers/pathToExpression.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,MAAc,EAAE,IAAc;IACtE,OAAO,IAAI,CAAC,MAAM,GAAG,CAAC;QACrB,CAAC,CAAC,OAAO,MAAM,MAAM,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;QAC7D,CAAC,CAAC,GAAG,MAAM,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export default function uniqueSerialized<T>(a: Array<T>): Array<T>;
2
+ //# sourceMappingURL=uniqueSerialized.d.ts.map