@macrostrat/column-views 3.2.2 → 3.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.
Files changed (65) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/dist/index.cjs +15 -9
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.js +11 -5
  5. package/dist/maps/column-correlation/core.cjs +10 -30
  6. package/dist/maps/column-correlation/core.cjs.map +1 -1
  7. package/dist/maps/column-correlation/core.d.ts +1 -1
  8. package/dist/maps/column-correlation/core.js +10 -30
  9. package/dist/maps/column-correlation/core.js.map +1 -1
  10. package/dist/maps/column-navigation/mapbox/index.cjs +156 -118
  11. package/dist/maps/column-navigation/mapbox/index.cjs.map +1 -1
  12. package/dist/maps/column-navigation/mapbox/index.d.ts +23 -2
  13. package/dist/maps/column-navigation/mapbox/index.js +158 -120
  14. package/dist/maps/column-navigation/mapbox/index.js.map +1 -1
  15. package/dist/maps/column-navigation/mapbox/keyboard-navigation.cjs +7 -1
  16. package/dist/maps/column-navigation/mapbox/keyboard-navigation.cjs.map +1 -1
  17. package/dist/maps/column-navigation/mapbox/keyboard-navigation.d.ts +3 -26
  18. package/dist/maps/column-navigation/mapbox/keyboard-navigation.js +9 -3
  19. package/dist/maps/column-navigation/mapbox/keyboard-navigation.js.map +1 -1
  20. package/dist/maps/index.d.ts +2 -2
  21. package/dist/maps/{_shared/inset-map.cjs → inset-map/index.cjs} +1 -1
  22. package/dist/maps/inset-map/index.cjs.map +1 -0
  23. package/dist/maps/{_shared/inset-map.js → inset-map/index.js} +1 -1
  24. package/dist/maps/inset-map/index.js.map +1 -0
  25. package/dist/maps/layers/columns.cjs +161 -0
  26. package/dist/maps/layers/columns.cjs.map +1 -0
  27. package/dist/maps/layers/columns.d.ts +28 -0
  28. package/dist/maps/layers/columns.js +161 -0
  29. package/dist/maps/layers/columns.js.map +1 -0
  30. package/dist/maps/layers/index.d.ts +2 -0
  31. package/dist/maps/{units-overlay/index.cjs → layers/units.cjs} +41 -88
  32. package/dist/maps/layers/units.cjs.map +1 -0
  33. package/dist/maps/{units-overlay/index.d.ts → layers/units.d.ts} +1 -1
  34. package/dist/maps/{units-overlay/index.js → layers/units.js} +34 -82
  35. package/dist/maps/layers/units.js.map +1 -0
  36. package/dist/unit-details/age-range.cjs +87 -44
  37. package/dist/unit-details/age-range.cjs.map +1 -1
  38. package/dist/unit-details/age-range.d.ts +32 -5
  39. package/dist/unit-details/age-range.js +85 -44
  40. package/dist/unit-details/age-range.js.map +1 -1
  41. package/package.json +4 -4
  42. package/src/maps/column-correlation/core.ts +9 -29
  43. package/src/maps/column-navigation/mapbox/index.ts +191 -138
  44. package/src/maps/column-navigation/mapbox/keyboard-navigation.ts +17 -3
  45. package/src/maps/index.ts +2 -2
  46. package/src/maps/layers/columns.ts +210 -0
  47. package/src/maps/layers/index.ts +2 -0
  48. package/src/maps/{units-overlay/index.ts → layers/units.ts} +34 -84
  49. package/src/maps/unit-map.stories.ts +27 -12
  50. package/src/unit-details/age-range.ts +125 -47
  51. package/dist/maps/_shared/index.d.ts +0 -2
  52. package/dist/maps/_shared/inset-map.cjs.map +0 -1
  53. package/dist/maps/_shared/inset-map.js.map +0 -1
  54. package/dist/maps/_shared/styles.cjs +0 -73
  55. package/dist/maps/_shared/styles.cjs.map +0 -1
  56. package/dist/maps/_shared/styles.d.ts +0 -2
  57. package/dist/maps/_shared/styles.js +0 -73
  58. package/dist/maps/_shared/styles.js.map +0 -1
  59. package/dist/maps/units-overlay/index.cjs.map +0 -1
  60. package/dist/maps/units-overlay/index.js.map +0 -1
  61. package/src/maps/_shared/index.ts +0 -2
  62. package/src/maps/_shared/styles.ts +0 -76
  63. /package/dist/maps/{_shared/inset-map.d.ts → inset-map/index.d.ts} +0 -0
  64. /package/src/maps/{_shared/inset-map.ts → inset-map/index.ts} +0 -0
  65. /package/src/maps/{_shared → inset-map}/inset-map.stories.ts +0 -0
@@ -0,0 +1,161 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const mapboxReact = require("@macrostrat/mapbox-react");
4
+ const mapboxUtils = require("@macrostrat/mapbox-utils");
5
+ const colorUtils = require("@macrostrat/color-utils");
6
+ function BaseColumnsLayer({
7
+ enabled = true,
8
+ columns,
9
+ ...rest
10
+ }) {
11
+ mapboxReact.useOverlayStyle(() => enabled ? buildColumnsStyle(rest) : null, [enabled]);
12
+ mapboxReact.useMapStyleOperator(
13
+ (map) => {
14
+ if (columns == null) {
15
+ return;
16
+ }
17
+ mapboxUtils.setGeoJSON(map, "columns", promoteToFeatureCollection(columns));
18
+ },
19
+ [columns, enabled]
20
+ );
21
+ return null;
22
+ }
23
+ function promoteToFeatureCollection(data) {
24
+ if (data == null) return null;
25
+ if ("type" in data && data.type == "Feature") {
26
+ return {
27
+ type: "FeatureCollection",
28
+ features: [data]
29
+ };
30
+ }
31
+ if ("type" in data && data.type == "FeatureCollection" && "features" in data) {
32
+ return data;
33
+ }
34
+ return {
35
+ type: "FeatureCollection",
36
+ features: data
37
+ };
38
+ }
39
+ function buildColumnsStyle(opts = {}) {
40
+ const { color } = opts;
41
+ const columnBaseColor = color ?? colorUtils.getCSSVariable("--text-subtle-color", "black");
42
+ let columnColor = columnBaseColor;
43
+ const columnSelectedColor = opts.selectedColor ?? colorUtils.getCSSVariable("--selection-color", "purple");
44
+ const lineColor = opts.lineColor ?? columnBaseColor;
45
+ const isHovered = ["boolean", ["feature-state", "hover"], false];
46
+ if (typeof columnColor === "string") {
47
+ columnColor = [
48
+ "coalesce",
49
+ ["feature-state", "color"],
50
+ ["get", "color"],
51
+ columnColor
52
+ ];
53
+ }
54
+ const fillOpacity = opts.opacity ?? 0.1;
55
+ const lineOpacity = opts.lineOpacity ?? 0.5;
56
+ const lineWidth = opts.lineWidth ?? 2;
57
+ const circleRadius = opts.circleRadius ?? 4;
58
+ return {
59
+ sources: {
60
+ columns: mapboxUtils.buildGeoJSONSource()
61
+ },
62
+ version: 8,
63
+ layers: [
64
+ {
65
+ id: "columns-fill",
66
+ type: "fill",
67
+ source: "columns",
68
+ paint: {
69
+ "fill-color": columnColor,
70
+ "fill-opacity": fillOpacity
71
+ }
72
+ },
73
+ {
74
+ id: "columns-points",
75
+ type: "circle",
76
+ source: "columns",
77
+ paint: {
78
+ "circle-radius": circleRadius,
79
+ "circle-color": columnColor,
80
+ "circle-opacity": fillOpacity
81
+ },
82
+ filter: ["==", "$type", "Point"]
83
+ },
84
+ {
85
+ id: "columns-line",
86
+ type: "line",
87
+ source: "columns",
88
+ paint: {
89
+ "line-color": ["case", isHovered, columnSelectedColor, lineColor],
90
+ "line-width": lineWidth,
91
+ "line-opacity": ["case", isHovered, 1, lineOpacity]
92
+ }
93
+ }
94
+ ]
95
+ };
96
+ }
97
+ const selectedColumnSourceID = "selectedColumn";
98
+ function SelectedColumnOverlay({
99
+ selectedColumn,
100
+ ...styleOpts
101
+ }) {
102
+ mapboxReact.useOverlayStyle(() => buildSelectedColumnStyle(styleOpts), []);
103
+ mapboxReact.useMapStyleOperator(
104
+ (map) => {
105
+ mapboxUtils.setGeoJSON(
106
+ map,
107
+ selectedColumnSourceID,
108
+ promoteToFeatureCollection(selectedColumn)
109
+ );
110
+ },
111
+ [selectedColumn]
112
+ );
113
+ return null;
114
+ }
115
+ function buildSelectedColumnStyle(opts = {}) {
116
+ const columnSelectedColor = opts.color ?? colorUtils.getCSSVariable("--selection-color", "purple");
117
+ return {
118
+ sources: {
119
+ selectedColumn: mapboxUtils.buildGeoJSONSource()
120
+ },
121
+ version: 8,
122
+ layers: [
123
+ {
124
+ id: "selected-column-highlight",
125
+ type: "fill",
126
+ source: selectedColumnSourceID,
127
+ paint: {
128
+ "fill-color": columnSelectedColor,
129
+ "fill-opacity": 0.5
130
+ },
131
+ filter: ["==", "$type", "Polygon"]
132
+ },
133
+ {
134
+ id: "selected-column-edge",
135
+ type: "line",
136
+ source: selectedColumnSourceID,
137
+ paint: {
138
+ "line-color": columnSelectedColor,
139
+ "line-width": 2,
140
+ "line-opacity": 1
141
+ },
142
+ filter: ["==", "$type", "Polygon"]
143
+ },
144
+ {
145
+ id: "selected-column-point",
146
+ type: "circle",
147
+ source: selectedColumnSourceID,
148
+ paint: {
149
+ "circle-radius": 6,
150
+ "circle-color": columnSelectedColor,
151
+ "circle-opacity": 1
152
+ },
153
+ filter: ["==", "$type", "Point"]
154
+ }
155
+ ]
156
+ };
157
+ }
158
+ exports.BaseColumnsLayer = BaseColumnsLayer;
159
+ exports.SelectedColumnOverlay = SelectedColumnOverlay;
160
+ exports.buildColumnsStyle = buildColumnsStyle;
161
+ //# sourceMappingURL=columns.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"columns.cjs","sources":["../../../src/maps/layers/columns.ts"],"sourcesContent":["import { useMapStyleOperator, useOverlayStyle } from \"@macrostrat/mapbox-react\";\nimport { setGeoJSON } from \"@macrostrat/mapbox-utils\";\nimport GeoJSON, { FeatureCollection } from \"geojson\";\nimport { GeoJSONFeature } from \"mapbox-gl\";\nimport { getCSSVariable } from \"@macrostrat/color-utils\";\nimport { buildGeoJSONSource } from \"@macrostrat/mapbox-utils\";\nimport { StyleFragment } from \"@macrostrat/mapbox-react\";\n\nexport interface ColumnsStyleOptions {\n color?: string | any[];\n selectedColor?: string | any[];\n opacity?: number | any[];\n circleRadius?: number | any[];\n lineOpacity?: number | any[];\n lineWidth?: number | any[];\n lineColor?: string | any[];\n}\n\ninterface ColumnLayerOptions extends ColumnsStyleOptions {\n enabled: boolean;\n columns: FeatureCollection | GeoJSONFeature[];\n}\n\nexport function BaseColumnsLayer({\n enabled = true,\n columns,\n ...rest\n}: ColumnLayerOptions) {\n useOverlayStyle(() => (enabled ? buildColumnsStyle(rest) : null), [enabled]);\n\n useMapStyleOperator(\n (map) => {\n if (columns == null) {\n return;\n }\n\n setGeoJSON(map, \"columns\", promoteToFeatureCollection(columns));\n },\n [columns, enabled],\n );\n return null;\n}\n\nfunction promoteToFeatureCollection(\n data: FeatureCollection | GeoJSONFeature | GeoJSONFeature[] | null,\n): FeatureCollection | null {\n if (data == null) return null;\n if (\"type\" in data && data.type == \"Feature\") {\n return {\n type: \"FeatureCollection\",\n features: [data],\n };\n }\n if (\n \"type\" in data &&\n data.type == \"FeatureCollection\" &&\n \"features\" in data\n ) {\n return data;\n }\n return {\n type: \"FeatureCollection\",\n features: data,\n };\n}\n\nexport function buildColumnsStyle(\n opts: ColumnsStyleOptions = {},\n): StyleFragment {\n const { color } = opts;\n const columnBaseColor =\n color ?? getCSSVariable(\"--text-subtle-color\", \"black\");\n let columnColor: any = columnBaseColor;\n const columnSelectedColor =\n opts.selectedColor ?? getCSSVariable(\"--selection-color\", \"purple\");\n\n const lineColor = opts.lineColor ?? columnBaseColor;\n const isHovered = [\"boolean\", [\"feature-state\", \"hover\"], false];\n // If color is in the feature state or geojson properties, use that as second choice\n if (typeof columnColor === \"string\") {\n columnColor = [\n \"coalesce\",\n [\"feature-state\", \"color\"],\n [\"get\", \"color\"],\n columnColor,\n ];\n }\n\n const fillOpacity = opts.opacity ?? 0.1;\n\n const lineOpacity = opts.lineOpacity ?? 0.5;\n const lineWidth = opts.lineWidth ?? 2;\n\n const circleRadius = opts.circleRadius ?? 4;\n\n return {\n sources: {\n columns: buildGeoJSONSource(),\n },\n version: 8,\n layers: [\n {\n id: \"columns-fill\",\n type: \"fill\",\n source: \"columns\",\n paint: {\n \"fill-color\": columnColor,\n \"fill-opacity\": fillOpacity,\n },\n },\n {\n id: \"columns-points\",\n type: \"circle\",\n source: \"columns\",\n paint: {\n \"circle-radius\": circleRadius,\n \"circle-color\": columnColor,\n \"circle-opacity\": fillOpacity,\n },\n filter: [\"==\", \"$type\", \"Point\"],\n },\n {\n id: \"columns-line\",\n type: \"line\",\n source: \"columns\",\n paint: {\n \"line-color\": [\"case\", isHovered, columnSelectedColor, lineColor],\n \"line-width\": lineWidth,\n \"line-opacity\": [\"case\", isHovered, 1.0, lineOpacity],\n },\n },\n ],\n };\n}\n\nexport type ColumnFeature = GeoJSON.Feature & { id: number };\n\nconst selectedColumnSourceID = \"selectedColumn\";\n\nexport function SelectedColumnOverlay({\n selectedColumn,\n ...styleOpts\n}: { selectedColumn: ColumnFeature | null } & SelectedColumnStyleOpts) {\n useOverlayStyle(() => buildSelectedColumnStyle(styleOpts), []);\n\n useMapStyleOperator(\n (map) => {\n setGeoJSON(\n map,\n selectedColumnSourceID,\n promoteToFeatureCollection(selectedColumn as GeoJSONFeature | null),\n );\n },\n [selectedColumn],\n );\n\n return null;\n}\n\ninterface SelectedColumnStyleOpts {\n color?: string | any[];\n}\n\nfunction buildSelectedColumnStyle(\n opts: SelectedColumnStyleOpts = {},\n): StyleFragment {\n const columnSelectedColor: any =\n opts.color ?? getCSSVariable(\"--selection-color\", \"purple\");\n\n return {\n sources: {\n selectedColumn: buildGeoJSONSource(),\n },\n version: 8,\n layers: [\n {\n id: \"selected-column-highlight\",\n type: \"fill\",\n source: selectedColumnSourceID,\n paint: {\n \"fill-color\": columnSelectedColor,\n \"fill-opacity\": 0.5,\n },\n filter: [\"==\", \"$type\", \"Polygon\"],\n },\n {\n id: \"selected-column-edge\",\n type: \"line\",\n source: selectedColumnSourceID,\n paint: {\n \"line-color\": columnSelectedColor,\n \"line-width\": 2,\n \"line-opacity\": 1.0,\n },\n filter: [\"==\", \"$type\", \"Polygon\"],\n },\n {\n id: \"selected-column-point\",\n type: \"circle\",\n source: selectedColumnSourceID,\n paint: {\n \"circle-radius\": 6,\n \"circle-color\": columnSelectedColor,\n \"circle-opacity\": 1.0,\n },\n filter: [\"==\", \"$type\", \"Point\"],\n },\n ],\n };\n}\n"],"names":["useOverlayStyle","useMapStyleOperator","setGeoJSON","getCSSVariable","buildGeoJSONSource"],"mappings":";;;;;AAuBO,SAAS,iBAAiB;AAAA,EAC/B,UAAU;AAAA,EACV;AAAA,EACA,GAAG;AACL,GAAuB;AACrBA,cAAAA,gBAAgB,MAAO,UAAU,kBAAkB,IAAI,IAAI,MAAO,CAAC,OAAO,C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AAA;AAAA,QAElB,QAAQ,CAAC,MAAM,SAAS,SAAS;AAAA,MAAA;AAAA,MAEnC;AAAA,QACE,IAAI;AAAA,QACJ,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,OAAO;AAAA,UACL,cAAc;AAAA,UACd,cAAc;AAAA,UACd,gBAAgB;AAAA,QAAA;AAAA,QAElB,QAAQ,CAAC,MAAM,SAAS,SAAS;AAAA,MAAA;AAAA,MAEnC;AAAA,QACE,IAAI;AAAA,QACJ,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,OAAO;AAAA,UACL,iBAAiB;AAAA,UACjB,gBAAgB;AAAA,UAChB,kBAAkB;AAAA,QAAA;AAAA,QAEpB,QAAQ,CAAC,MAAM,SAAS,OAAO;AAAA,MAAA;AAAA,IACjC;AAAA,EACF;AAEJ;;;;"}
@@ -0,0 +1,28 @@
1
+ import { default as GeoJSON, FeatureCollection } from 'geojson';
2
+ import { GeoJSONFeature } from 'mapbox-gl';
3
+ import { StyleFragment } from '@macrostrat/mapbox-react';
4
+ export interface ColumnsStyleOptions {
5
+ color?: string | any[];
6
+ selectedColor?: string | any[];
7
+ opacity?: number | any[];
8
+ circleRadius?: number | any[];
9
+ lineOpacity?: number | any[];
10
+ lineWidth?: number | any[];
11
+ lineColor?: string | any[];
12
+ }
13
+ interface ColumnLayerOptions extends ColumnsStyleOptions {
14
+ enabled: boolean;
15
+ columns: FeatureCollection | GeoJSONFeature[];
16
+ }
17
+ export declare function BaseColumnsLayer({ enabled, columns, ...rest }: ColumnLayerOptions): any;
18
+ export declare function buildColumnsStyle(opts?: ColumnsStyleOptions): StyleFragment;
19
+ export type ColumnFeature = GeoJSON.Feature & {
20
+ id: number;
21
+ };
22
+ export declare function SelectedColumnOverlay({ selectedColumn, ...styleOpts }: {
23
+ selectedColumn: ColumnFeature | null;
24
+ } & SelectedColumnStyleOpts): any;
25
+ interface SelectedColumnStyleOpts {
26
+ color?: string | any[];
27
+ }
28
+ export {};
@@ -0,0 +1,161 @@
1
+ import { useOverlayStyle, useMapStyleOperator } from "@macrostrat/mapbox-react";
2
+ import { setGeoJSON, buildGeoJSONSource } from "@macrostrat/mapbox-utils";
3
+ import { getCSSVariable } from "@macrostrat/color-utils";
4
+ function BaseColumnsLayer({
5
+ enabled = true,
6
+ columns,
7
+ ...rest
8
+ }) {
9
+ useOverlayStyle(() => enabled ? buildColumnsStyle(rest) : null, [enabled]);
10
+ useMapStyleOperator(
11
+ (map) => {
12
+ if (columns == null) {
13
+ return;
14
+ }
15
+ setGeoJSON(map, "columns", promoteToFeatureCollection(columns));
16
+ },
17
+ [columns, enabled]
18
+ );
19
+ return null;
20
+ }
21
+ function promoteToFeatureCollection(data) {
22
+ if (data == null) return null;
23
+ if ("type" in data && data.type == "Feature") {
24
+ return {
25
+ type: "FeatureCollection",
26
+ features: [data]
27
+ };
28
+ }
29
+ if ("type" in data && data.type == "FeatureCollection" && "features" in data) {
30
+ return data;
31
+ }
32
+ return {
33
+ type: "FeatureCollection",
34
+ features: data
35
+ };
36
+ }
37
+ function buildColumnsStyle(opts = {}) {
38
+ const { color } = opts;
39
+ const columnBaseColor = color ?? getCSSVariable("--text-subtle-color", "black");
40
+ let columnColor = columnBaseColor;
41
+ const columnSelectedColor = opts.selectedColor ?? getCSSVariable("--selection-color", "purple");
42
+ const lineColor = opts.lineColor ?? columnBaseColor;
43
+ const isHovered = ["boolean", ["feature-state", "hover"], false];
44
+ if (typeof columnColor === "string") {
45
+ columnColor = [
46
+ "coalesce",
47
+ ["feature-state", "color"],
48
+ ["get", "color"],
49
+ columnColor
50
+ ];
51
+ }
52
+ const fillOpacity = opts.opacity ?? 0.1;
53
+ const lineOpacity = opts.lineOpacity ?? 0.5;
54
+ const lineWidth = opts.lineWidth ?? 2;
55
+ const circleRadius = opts.circleRadius ?? 4;
56
+ return {
57
+ sources: {
58
+ columns: buildGeoJSONSource()
59
+ },
60
+ version: 8,
61
+ layers: [
62
+ {
63
+ id: "columns-fill",
64
+ type: "fill",
65
+ source: "columns",
66
+ paint: {
67
+ "fill-color": columnColor,
68
+ "fill-opacity": fillOpacity
69
+ }
70
+ },
71
+ {
72
+ id: "columns-points",
73
+ type: "circle",
74
+ source: "columns",
75
+ paint: {
76
+ "circle-radius": circleRadius,
77
+ "circle-color": columnColor,
78
+ "circle-opacity": fillOpacity
79
+ },
80
+ filter: ["==", "$type", "Point"]
81
+ },
82
+ {
83
+ id: "columns-line",
84
+ type: "line",
85
+ source: "columns",
86
+ paint: {
87
+ "line-color": ["case", isHovered, columnSelectedColor, lineColor],
88
+ "line-width": lineWidth,
89
+ "line-opacity": ["case", isHovered, 1, lineOpacity]
90
+ }
91
+ }
92
+ ]
93
+ };
94
+ }
95
+ const selectedColumnSourceID = "selectedColumn";
96
+ function SelectedColumnOverlay({
97
+ selectedColumn,
98
+ ...styleOpts
99
+ }) {
100
+ useOverlayStyle(() => buildSelectedColumnStyle(styleOpts), []);
101
+ useMapStyleOperator(
102
+ (map) => {
103
+ setGeoJSON(
104
+ map,
105
+ selectedColumnSourceID,
106
+ promoteToFeatureCollection(selectedColumn)
107
+ );
108
+ },
109
+ [selectedColumn]
110
+ );
111
+ return null;
112
+ }
113
+ function buildSelectedColumnStyle(opts = {}) {
114
+ const columnSelectedColor = opts.color ?? getCSSVariable("--selection-color", "purple");
115
+ return {
116
+ sources: {
117
+ selectedColumn: buildGeoJSONSource()
118
+ },
119
+ version: 8,
120
+ layers: [
121
+ {
122
+ id: "selected-column-highlight",
123
+ type: "fill",
124
+ source: selectedColumnSourceID,
125
+ paint: {
126
+ "fill-color": columnSelectedColor,
127
+ "fill-opacity": 0.5
128
+ },
129
+ filter: ["==", "$type", "Polygon"]
130
+ },
131
+ {
132
+ id: "selected-column-edge",
133
+ type: "line",
134
+ source: selectedColumnSourceID,
135
+ paint: {
136
+ "line-color": columnSelectedColor,
137
+ "line-width": 2,
138
+ "line-opacity": 1
139
+ },
140
+ filter: ["==", "$type", "Polygon"]
141
+ },
142
+ {
143
+ id: "selected-column-point",
144
+ type: "circle",
145
+ source: selectedColumnSourceID,
146
+ paint: {
147
+ "circle-radius": 6,
148
+ "circle-color": columnSelectedColor,
149
+ "circle-opacity": 1
150
+ },
151
+ filter: ["==", "$type", "Point"]
152
+ }
153
+ ]
154
+ };
155
+ }
156
+ export {
157
+ BaseColumnsLayer,
158
+ SelectedColumnOverlay,
159
+ buildColumnsStyle
160
+ };
161
+ //# sourceMappingURL=columns.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"columns.js","sources":["../../../src/maps/layers/columns.ts"],"sourcesContent":["import { useMapStyleOperator, useOverlayStyle } from \"@macrostrat/mapbox-react\";\nimport { setGeoJSON } from \"@macrostrat/mapbox-utils\";\nimport GeoJSON, { FeatureCollection } from \"geojson\";\nimport { GeoJSONFeature } from \"mapbox-gl\";\nimport { getCSSVariable } from \"@macrostrat/color-utils\";\nimport { buildGeoJSONSource } from \"@macrostrat/mapbox-utils\";\nimport { StyleFragment } from \"@macrostrat/mapbox-react\";\n\nexport interface ColumnsStyleOptions {\n color?: string | any[];\n selectedColor?: string | any[];\n opacity?: number | any[];\n circleRadius?: number | any[];\n lineOpacity?: number | any[];\n lineWidth?: number | any[];\n lineColor?: string | any[];\n}\n\ninterface ColumnLayerOptions extends ColumnsStyleOptions {\n enabled: boolean;\n columns: FeatureCollection | GeoJSONFeature[];\n}\n\nexport function BaseColumnsLayer({\n enabled = true,\n columns,\n ...rest\n}: ColumnLayerOptions) {\n useOverlayStyle(() => (enabled ? buildColumnsStyle(rest) : null), [enabled]);\n\n useMapStyleOperator(\n (map) => {\n if (columns == null) {\n return;\n }\n\n setGeoJSON(map, \"columns\", promoteToFeatureCollection(columns));\n },\n [columns, enabled],\n );\n return null;\n}\n\nfunction promoteToFeatureCollection(\n data: FeatureCollection | GeoJSONFeature | GeoJSONFeature[] | null,\n): FeatureCollection | null {\n if (data == null) return null;\n if (\"type\" in data && data.type == \"Feature\") {\n return {\n type: \"FeatureCollection\",\n features: [data],\n };\n }\n if (\n \"type\" in data &&\n data.type == \"FeatureCollection\" &&\n \"features\" in data\n ) {\n return data;\n }\n return {\n type: \"FeatureCollection\",\n features: data,\n };\n}\n\nexport function buildColumnsStyle(\n opts: ColumnsStyleOptions = {},\n): StyleFragment {\n const { color } = opts;\n const columnBaseColor =\n color ?? getCSSVariable(\"--text-subtle-color\", \"black\");\n let columnColor: any = columnBaseColor;\n const columnSelectedColor =\n opts.selectedColor ?? getCSSVariable(\"--selection-color\", \"purple\");\n\n const lineColor = opts.lineColor ?? columnBaseColor;\n const isHovered = [\"boolean\", [\"feature-state\", \"hover\"], false];\n // If color is in the feature state or geojson properties, use that as second choice\n if (typeof columnColor === \"string\") {\n columnColor = [\n \"coalesce\",\n [\"feature-state\", \"color\"],\n [\"get\", \"color\"],\n columnColor,\n ];\n }\n\n const fillOpacity = opts.opacity ?? 0.1;\n\n const lineOpacity = opts.lineOpacity ?? 0.5;\n const lineWidth = opts.lineWidth ?? 2;\n\n const circleRadius = opts.circleRadius ?? 4;\n\n return {\n sources: {\n columns: buildGeoJSONSource(),\n },\n version: 8,\n layers: [\n {\n id: \"columns-fill\",\n type: \"fill\",\n source: \"columns\",\n paint: {\n \"fill-color\": columnColor,\n \"fill-opacity\": fillOpacity,\n },\n },\n {\n id: \"columns-points\",\n type: \"circle\",\n source: \"columns\",\n paint: {\n \"circle-radius\": circleRadius,\n \"circle-color\": columnColor,\n \"circle-opacity\": fillOpacity,\n },\n filter: [\"==\", \"$type\", \"Point\"],\n },\n {\n id: \"columns-line\",\n type: \"line\",\n source: \"columns\",\n paint: {\n \"line-color\": [\"case\", isHovered, columnSelectedColor, lineColor],\n \"line-width\": lineWidth,\n \"line-opacity\": [\"case\", isHovered, 1.0, lineOpacity],\n },\n },\n ],\n };\n}\n\nexport type ColumnFeature = GeoJSON.Feature & { id: number };\n\nconst selectedColumnSourceID = \"selectedColumn\";\n\nexport function SelectedColumnOverlay({\n selectedColumn,\n ...styleOpts\n}: { selectedColumn: ColumnFeature | null } & SelectedColumnStyleOpts) {\n useOverlayStyle(() => buildSelectedColumnStyle(styleOpts), []);\n\n useMapStyleOperator(\n (map) => {\n setGeoJSON(\n map,\n selectedColumnSourceID,\n promoteToFeatureCollection(selectedColumn as GeoJSONFeature | null),\n );\n },\n [selectedColumn],\n );\n\n return null;\n}\n\ninterface SelectedColumnStyleOpts {\n color?: string | any[];\n}\n\nfunction buildSelectedColumnStyle(\n opts: SelectedColumnStyleOpts = {},\n): StyleFragment {\n const columnSelectedColor: any =\n opts.color ?? getCSSVariable(\"--selection-color\", \"purple\");\n\n return {\n sources: {\n selectedColumn: buildGeoJSONSource(),\n },\n version: 8,\n layers: [\n {\n id: \"selected-column-highlight\",\n type: \"fill\",\n source: selectedColumnSourceID,\n paint: {\n \"fill-color\": columnSelectedColor,\n \"fill-opacity\": 0.5,\n },\n filter: [\"==\", \"$type\", \"Polygon\"],\n },\n {\n id: \"selected-column-edge\",\n type: \"line\",\n source: selectedColumnSourceID,\n paint: {\n \"line-color\": columnSelectedColor,\n \"line-width\": 2,\n \"line-opacity\": 1.0,\n },\n filter: [\"==\", \"$type\", \"Polygon\"],\n },\n {\n id: \"selected-column-point\",\n type: \"circle\",\n source: selectedColumnSourceID,\n paint: {\n \"circle-radius\": 6,\n \"circle-color\": columnSelectedColor,\n \"circle-opacity\": 1.0,\n },\n filter: [\"==\", \"$type\", \"Point\"],\n },\n ],\n };\n}\n"],"names":[],"mappings":";;;AAuBO,SAAS,iBAAiB;AAAA,EAC/B,UAAU;AAAA,EACV;AAAA,EACA,GAAG;AACL,GAAuB;AACrB,kBAAgB,MAAO,UAAU,kBAAkB,IAAI,IAAI,MAAO,CAAC,OAAO,CAAC;AAE3E;AAAA,IACE,CAAC,QAAQ;AACP,UAAI,WAAW,MAAM;AACnB;AAAA,MACF;AAEA,iBAAW,KAAK,WAAW,2BAA2B,OAAO,CAAC;AAAA,IAChE;AAAA,IACA,CAAC,SAAS,OAAO;AAAA,EAAA;AAEnB,SAAO;AACT;AAEA,SAAS,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E,IAAI;AAAA,QACJ,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,OAAO;AAAA,UACL,iBAAiB;AAAA,UACjB,gBAAgB;AAAA,UAChB,kBAAkB;AAAA,QAAA;AAAA,QAEpB,QAAQ,CAAC,MAAM,SAAS,OAAO;AAAA,MAAA;AAAA,IACjC;AAAA,EACF;AAEJ;"}
@@ -0,0 +1,2 @@
1
+ export * from './columns';
2
+ export * from './units';
@@ -9,12 +9,18 @@ const resolvers = require("../../units/resolvers.cjs");
9
9
  const mapStyles = require("@macrostrat/map-styles");
10
10
  const colorUtils = require("@macrostrat/color-utils");
11
11
  const pMap = require("p-map");
12
+ const columns = require("./columns.cjs");
13
+ const h = require("@macrostrat/hyper");
12
14
  const colors = require("../../units/colors.cjs");
13
15
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
14
16
  const pMap__default = /* @__PURE__ */ _interopDefault(pMap);
17
+ const h__default = /* @__PURE__ */ _interopDefault(h);
15
18
  function MacrostratUnitsOverlay(props) {
16
19
  const { time, ageSpan = 0.05, patterns = false } = props;
17
20
  const lithMap = dataProvider.useLithologies();
21
+ mapboxReact.useOverlayStyle(() => {
22
+ return buildUnitsStyle({ patterns });
23
+ }, [patterns]);
18
24
  mapboxReact.useMapStyleOperator(
19
25
  (map) => {
20
26
  if (!patterns) return;
@@ -38,46 +44,54 @@ function MacrostratUnitsOverlay(props) {
38
44
  };
39
45
  }, [time, ageSpan, props.project]);
40
46
  const units = uiComponents.useAPIResult("/units", params);
41
- const columns = dataProvider.useMacrostratColumns(params.project, false);
47
+ const columns$1 = dataProvider.useMacrostratColumns(params.project, false);
42
48
  mapboxReact.useMapStyleOperator(
43
49
  (map) => {
44
- if (columns == null) {
45
- return;
46
- }
47
- const data = {
48
- type: "FeatureCollection",
49
- features: columns
50
- };
51
- mapboxUtils.setGeoJSON(map, "columns", data);
52
- },
53
- [columns]
54
- );
55
- mapboxReact.useMapStyleOperator(
56
- (map) => {
57
- if (units == null || columns == null || lithMap == null) {
50
+ if (units == null || columns$1 == null || lithMap == null) {
58
51
  return;
59
52
  }
60
53
  const getColorForLithology = (data) => {
61
54
  return lithMap?.get(data.lith_id)?.color ?? null;
62
55
  };
63
56
  const unitsMap = postProcessUnits(units, getColorForLithology);
64
- handleUnitsLayerUpdate(map, unitsMap, columns);
57
+ handleUnitsLayerUpdate(map, unitsMap, columns$1);
65
58
  if (patterns) {
66
59
  handlePatternOverlayUpdate(
67
60
  map,
68
61
  unitsMap,
69
- columns,
62
+ columns$1,
70
63
  getColorForLithology
71
64
  ).then(() => {
72
65
  });
73
66
  }
74
67
  },
75
- [units, lithMap, columns, patterns]
68
+ [units, lithMap, columns$1, patterns]
76
69
  );
77
- return null;
70
+ const isHovered = ["boolean", ["feature-state", "hover"], false];
71
+ const isShown = ["boolean", ["feature-state", "shown"], false];
72
+ const opacity = [
73
+ "case",
74
+ ["all", isHovered, isShown],
75
+ 0.9,
76
+ isShown,
77
+ 0.8,
78
+ isHovered,
79
+ 0.3,
80
+ 0
81
+ ];
82
+ return h__default.default([
83
+ h__default.default(columns.BaseColumnsLayer, {
84
+ enabled: true,
85
+ columns: columns$1,
86
+ opacity,
87
+ lineOpacity: 0.2,
88
+ lineColor: "lightgray",
89
+ color: "transparent"
90
+ })
91
+ ]);
78
92
  }
79
- function handleUnitsLayerUpdate(map, unitsMap, columns) {
80
- for (const column of columns) {
93
+ function handleUnitsLayerUpdate(map, unitsMap, columns2) {
94
+ for (const column of columns2) {
81
95
  const col_id = column.properties.col_id;
82
96
  const info = unitsMap.get(Number(col_id));
83
97
  const color = info?.color;
@@ -90,10 +104,10 @@ function handleUnitsLayerUpdate(map, unitsMap, columns) {
90
104
  );
91
105
  }
92
106
  }
93
- async function handlePatternOverlayUpdate(map, unitsMap, columns, getColor) {
107
+ async function handlePatternOverlayUpdate(map, unitsMap, columns2, getColor) {
94
108
  const colsWithPatterns = [];
95
109
  const patternIDs = /* @__PURE__ */ new Set();
96
- for (const column of columns) {
110
+ for (const column of columns2) {
97
111
  const col_id = column.properties.col_id;
98
112
  const info = unitsMap.get(Number(col_id));
99
113
  if (info == null) continue;
@@ -162,71 +176,10 @@ function getPatternSpec(liths, getColor) {
162
176
  return `fgdc:${patternID}:${color}:transparent`;
163
177
  }
164
178
  function buildUnitsStyle(opts = {}) {
165
- const { color = null, patterns = false } = opts;
166
- let columnBaseColor = color ?? colorUtils.getCSSVariable("--text-subtle-color", "black");
167
- colorUtils.getCSSVariable("--selection-color", "purple");
168
- let columnColor = [
169
- "coalesce",
170
- ["feature-state", "color"],
171
- ["get", "color"],
172
- columnBaseColor
173
- ];
179
+ const { patterns = false } = opts;
174
180
  const baseStyle = {
175
- sources: {
176
- columns: mapboxUtils.buildGeoJSONSource()
177
- },
178
- version: 8,
179
- layers: [
180
- {
181
- id: "columns-fill",
182
- type: "fill",
183
- source: "columns",
184
- paint: {
185
- "fill-color": columnColor,
186
- "fill-opacity": [
187
- "case",
188
- ["boolean", ["feature-state", "shown"], false],
189
- 0.8,
190
- ["boolean", ["feature-state", "hover"], false],
191
- 0.3,
192
- 0.1
193
- ]
194
- }
195
- },
196
- {
197
- id: "columns-line",
198
- type: "line",
199
- source: "columns",
200
- paint: {
201
- "line-color": columnColor,
202
- "line-width": 1,
203
- "line-opacity": 0.5
204
- }
205
- },
206
- {
207
- id: "columns-points",
208
- type: "circle",
209
- source: "columns",
210
- paint: {
211
- "circle-radius": 4,
212
- "circle-color": [
213
- "case",
214
- ["boolean", ["feature-state", "shown"], false],
215
- columnColor,
216
- columnBaseColor
217
- ],
218
- "circle-opacity": [
219
- "case",
220
- ["boolean", ["feature-state", "shown"], false],
221
- 0.8,
222
- ["boolean", ["feature-state", "hover"], false],
223
- 0.3,
224
- 0.1
225
- ]
226
- },
227
- filter: ["==", "$type", "Point"]
228
- }
229
- ]
181
+ sources: {},
182
+ version: 8
230
183
  };
231
184
  if (!patterns) {
232
185
  return baseStyle;
@@ -251,4 +204,4 @@ function buildUnitsStyle(opts = {}) {
251
204
  }
252
205
  exports.MacrostratUnitsOverlay = MacrostratUnitsOverlay;
253
206
  exports.buildUnitsStyle = buildUnitsStyle;
254
- //# sourceMappingURL=index.cjs.map
207
+ //# sourceMappingURL=units.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"units.cjs","sources":["../../../src/maps/layers/units.ts"],"sourcesContent":["import {\n useLithologies,\n useMacrostratColumns,\n} from \"@macrostrat/data-provider\";\nimport { useAPIResult } from \"@macrostrat/ui-components\";\nimport { useMapStyleOperator, useOverlayStyle } from \"@macrostrat/mapbox-react\";\nimport { FeatureCollection } from \"geojson\";\nimport { useMemo } from \"react\";\nimport { mergeStyles, setGeoJSON } from \"@macrostrat/mapbox-utils\";\nimport { UnitLithology, UnitLong } from \"@macrostrat/api-types\";\nimport { flattenLithologies, getMixedColorForData } from \"../../units\";\nimport { getBestFGDCPatternForLithologyList } from \"../../units/resolvers\";\nimport {\n setupStyleImageManager,\n loadStyleImage,\n StyleFragment,\n} from \"@macrostrat/map-styles\";\nimport { asChromaColor } from \"@macrostrat/color-utils\";\nimport { buildGeoJSONSource } from \"@macrostrat/mapbox-utils\";\nimport pMap from \"p-map\";\nimport { BaseColumnsLayer } from \"./columns\";\nimport h from \"@macrostrat/hyper\";\n\nexport interface UnitsOverlayProps {\n time: number;\n ageSpan?: number;\n project?: number | number[];\n patterns?: boolean;\n}\n\nexport function MacrostratUnitsOverlay(props: UnitsOverlayProps) {\n const { time, ageSpan = 0.05, patterns = false } = props;\n const lithMap = useLithologies();\n\n useOverlayStyle(() => {\n return buildUnitsStyle({ patterns });\n }, [patterns]);\n\n useMapStyleOperator(\n (map) => {\n if (!patterns) return;\n setupStyleImageManager(map, { verbose: false });\n },\n [patterns],\n );\n\n const params = useMemo(() => {\n let project: number[] | undefined;\n if (Number.isFinite(props.project)) {\n project = [props.project as number];\n } else if (!Array.isArray(props.project)) {\n project = undefined;\n }\n // Project can only be a single project for now\n const projectCompat =\n project != null && project.length > 0 ? project[0] : undefined;\n\n return {\n age_bottom: time + ageSpan / 2,\n age_top: time - ageSpan / 2,\n response: \"long\",\n project: projectCompat,\n };\n }, [time, ageSpan, props.project]);\n\n const units: UnitLong[] = useAPIResult(\"/units\", params);\n const columns = useMacrostratColumns(params.project, false);\n\n useMapStyleOperator(\n (map) => {\n if (units == null || columns == null || lithMap == null) {\n return;\n }\n\n const getColorForLithology = (data: UnitLithology): string | null => {\n return lithMap?.get(data.lith_id)?.color ?? null;\n };\n\n const unitsMap = postProcessUnits(units, getColorForLithology);\n handleUnitsLayerUpdate(map, unitsMap, columns);\n if (patterns) {\n handlePatternOverlayUpdate(\n map,\n unitsMap,\n columns,\n getColorForLithology,\n ).then(() => {});\n }\n },\n [units, lithMap, columns, patterns],\n );\n\n const isHovered = [\"boolean\", [\"feature-state\", \"hover\"], false];\n const isShown = [\"boolean\", [\"feature-state\", \"shown\"], false];\n\n const opacity = [\n \"case\",\n [\"all\", isHovered, isShown],\n 0.9,\n isShown,\n 0.8,\n isHovered,\n 0.3,\n 0.0,\n ];\n\n return h([\n h(BaseColumnsLayer, {\n enabled: true,\n columns,\n opacity,\n lineOpacity: 0.2,\n lineColor: \"lightgray\",\n color: \"transparent\",\n }),\n ]);\n}\n\nfunction handleUnitsLayerUpdate(\n map,\n unitsMap: Map<number, UnitsDisplayInfo>,\n columns: any[],\n) {\n // Update feature states\n for (const column of columns) {\n const col_id = column.properties.col_id;\n const info = unitsMap.get(Number(col_id));\n const color = info?.color;\n map.setFeatureState(\n { source: \"columns\", id: col_id },\n {\n color,\n shown: color != null,\n },\n );\n }\n}\n\nasync function handlePatternOverlayUpdate(\n map,\n unitsMap: Map<number, UnitsDisplayInfo>,\n columns: any[],\n getColor: LithologyColorGetter,\n) {\n // synthesize patterns not yet in cache\n\n const colsWithPatterns = [];\n const patternIDs = new Set<string>();\n // Update feature states\n for (const column of columns) {\n const col_id = column.properties.col_id;\n const info = unitsMap.get(Number(col_id));\n if (info == null) continue;\n const pattern = getPatternSpec(info?.liths, getColor);\n if (pattern == null) continue;\n\n colsWithPatterns.push({\n type: \"Feature\",\n geometry: column.geometry,\n properties: {\n col_id,\n pattern,\n },\n });\n patternIDs.add(pattern);\n }\n\n const patternsToLoad = patternIDs.values().filter((d) => !map.hasImage(d));\n\n const mapper = async (patternID) => {\n try {\n await loadStyleImage(map, patternID, { pixelRatio: 10 });\n } catch (e) {}\n };\n // Load all pattern images\n await pMap(patternsToLoad, mapper, { concurrency: 5 });\n\n // Set data for pattern layer\n // This is inefficient but the only way to set per-feature patterns in Mapbox\n const patternData: FeatureCollection = {\n type: \"FeatureCollection\",\n features: colsWithPatterns,\n };\n setGeoJSON(map, \"column-patterns\", patternData);\n}\n\nconst cachedColors = new Map<string, string>();\n\nfunction getDarkenedColor(color: string): string {\n /** Memoized function to get a darkened version of a color for pattern use */\n if (cachedColors.has(color)) {\n return cachedColors.get(color);\n }\n const c1 = asChromaColor(color).set(\"hsl.l\", 0.4).set(\"hsl.s\", 0.8).hex();\n cachedColors.set(color, c1);\n return c1;\n}\n\ninterface UnitsDisplayInfo {\n col_id: number;\n units: UnitLong[];\n color: string;\n liths: UnitLithology[];\n}\n\ntype LithologyColorGetter = (val: UnitLithology) => string | null;\n\nfunction postProcessUnits(\n units: UnitLong[],\n getColor: LithologyColorGetter,\n): Map<number, UnitsDisplayInfo> {\n // Group by col_id\n const unitsByColumn: Map<number, UnitLong[]> = new Map();\n for (const unit of units) {\n const col_id = Number(unit.col_id);\n if (!unitsByColumn.has(col_id)) {\n unitsByColumn.set(col_id, [unit]);\n } else {\n unitsByColumn.set(col_id, [...unitsByColumn.get(col_id), unit]);\n }\n }\n\n // Summarize units for display\n const res = new Map<number, UnitsDisplayInfo>();\n for (const [col_id, unitList] of unitsByColumn.entries()) {\n const liths = flattenLithologies(unitList.map((u) => u.lith));\n res.set(col_id, {\n col_id,\n units: unitList,\n liths,\n color: getMixedColorForData(liths, getColor),\n });\n }\n\n return res;\n}\n\nfunction getPatternSpec(\n liths: UnitLithology[],\n getColor: LithologyColorGetter,\n): string | null {\n const patternData = getBestFGDCPatternForLithologyList(liths);\n if (patternData == null) return null;\n let { patternID, lith } = patternData;\n const color = getDarkenedColor(getColor(lith));\n return `fgdc:${patternID}:${color}:transparent`;\n}\n\ntype UnitsStyleOptions = {\n color?: string;\n patterns?: boolean;\n};\n\nexport function buildUnitsStyle(opts: UnitsStyleOptions = {}): StyleFragment {\n const { patterns = false } = opts;\n\n // If color is in the feature state or geojson properties, use that as second choice\n\n const baseStyle: StyleFragment = {\n sources: {},\n version: 8,\n };\n\n if (!patterns) {\n return baseStyle;\n }\n\n const patternStyle: StyleFragment = {\n sources: {\n \"column-patterns\": buildGeoJSONSource(),\n },\n layers: [\n {\n id: \"columns-fill-pattern\",\n type: \"fill\",\n source: \"column-patterns\",\n paint: {\n \"fill-pattern\": [\"get\", \"pattern\"],\n \"fill-opacity\": 1,\n },\n },\n ],\n };\n\n return mergeStyles(baseStyle, patternStyle);\n}\n"],"names":["useLithologies","useOverlayStyle","useMapStyleOperator","setupStyleImageManager","useMemo","useAPIResult","columns","useMacrostratColumns","h","BaseColumnsLayer","loadStyleImage","pMap","setGeoJSON","asChromaColor","flattenLithologies","getMixedColorForData","getBestFGDCPatternForLithologyList","buildGeoJSONSource","mergeStyles"],"mappings":";;;;;;;;;;;;;;;;;AA8BO,SAAS,uBAAuB,OAA0B;AAC/D,QAAM,EAAE,MAAM,UAAU,MAAM,WAAW,UAAU;AACnD,QAAM,UAAUA,aAAAA,eAAA;AAEhBC,cAAAA,gBAAgB,MAAM;AACpB,WAAO,gBAAgB,EAAE,UAAU;AAAA,EACrC,GAAG,CAAC,QAAQ,CAAC;AAEbC,cAAAA;AAAAA,IACE,CAAC,QAAQ;AACP,UAAI,CAAC,SAAU;AACfC,gBAAAA,uBAAuB,KAAK,EAAE,SAAS,MAAA,CAAO;AAAA,IAChD;AAAA,IACA,CAAC,QAAQ;AAAA,EAAA;AAGX,QAAM,SAASC,MAAAA,QAAQ,MAAM;AAC3B,QAAI;AACJ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AC;AAC7C,SAAO,QAAQ,SAAS,IAAI,KAAK;AACnC;AAOO,SAAS,gBAAgB,OAA0B,IAAmB;AAC3E,QAAM,EAAE,WAAW,MAAA,IAAU;AAI7B,QAAM,YAA2B;AAAA,IAC/B,SAAS,CAAA;AAAA,IACT,SAAS;AAAA,EAAA;AAGX,MAAI,CAAC,UAAU;AACb,WAAO;AAAA,EACT;AAEA,QAAM,eAA8B;AAAA,IAClC,SAAS;AAAA,MACP,mBAAmBC,YAAAA,mBAAA;AAAA,IAAmB;AAAA,IAExC,QAAQ;AAAA,MACN;AAAA,QACE,IAAI;AAAA,QACJ,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,OAAO;AAAA,UACL,gBAAgB,CAAC,OAAO,SAAS;AAAA,UACjC,gBAAgB;AAAA,QAAA;AAAA,MAClB;AAAA,IACF;AAAA,EACF;AAGF,SAAOC,YAAAA,YAAY,WAAW,YAAY;AAC5C;;;"}
@@ -5,7 +5,7 @@ export interface UnitsOverlayProps {
5
5
  project?: number | number[];
6
6
  patterns?: boolean;
7
7
  }
8
- export declare function MacrostratUnitsOverlay(props: UnitsOverlayProps): any;
8
+ export declare function MacrostratUnitsOverlay(props: UnitsOverlayProps): import('react').ReactElement<unknown, string | import('react').JSXElementConstructor<any>>;
9
9
  type UnitsStyleOptions = {
10
10
  color?: string;
11
11
  patterns?: boolean;