@classic-homes/maps-core 0.1.1

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.
@@ -0,0 +1,534 @@
1
+ import { fontFamily, colors, semanticColors } from '@classic-homes/theme-tokens';
2
+
3
+ // src/theme/generator.ts
4
+ var THEME_LIGHT = "classic-light";
5
+ var THEME_DARK = "classic-dark";
6
+ function generateLightColors() {
7
+ return {
8
+ background: colors.white,
9
+ water: colors.sky[200],
10
+ land: colors.sage[50],
11
+ park: colors.forest[100],
12
+ building: colors.gray[200],
13
+ buildingOutline: colors.gray[300],
14
+ roadPrimary: colors.white,
15
+ roadSecondary: colors.gray[100],
16
+ roadCasing: colors.gray[300],
17
+ rail: colors.gray[400],
18
+ boundary: colors.gray[400],
19
+ adminBoundary: colors.plum[300],
20
+ residential: colors.sage[100],
21
+ commercial: colors.stone[100],
22
+ industrial: colors.gray[200],
23
+ highlight: colors.teal[500],
24
+ // Core 1 - brand teal
25
+ highlightSecondary: colors.teal[300],
26
+ selection: colors.red[500],
27
+ // Brand red
28
+ textPrimary: semanticColors.light.foreground,
29
+ textSecondary: semanticColors.light.mutedForeground,
30
+ textHalo: colors.white,
31
+ poi: colors.navy[700],
32
+ // Core 2 - brand navy
33
+ labelBackground: "rgba(255, 255, 255, 0.85)"
34
+ };
35
+ }
36
+ function generateDarkColors() {
37
+ return {
38
+ background: colors.charcoal[900],
39
+ water: colors.navy[800],
40
+ land: colors.charcoal[800],
41
+ park: colors.forest[900],
42
+ building: colors.charcoal[700],
43
+ buildingOutline: colors.charcoal[600],
44
+ roadPrimary: colors.charcoal[600],
45
+ roadSecondary: colors.charcoal[700],
46
+ roadCasing: colors.charcoal[500],
47
+ rail: colors.gray[600],
48
+ boundary: colors.gray[600],
49
+ adminBoundary: colors.plum[400],
50
+ residential: colors.charcoal[700],
51
+ commercial: colors.stone[800],
52
+ industrial: colors.charcoal[700],
53
+ highlight: colors.teal[400],
54
+ // Lighter for dark mode
55
+ highlightSecondary: colors.teal[500],
56
+ selection: colors.red[400],
57
+ // Lighter for dark mode
58
+ textPrimary: semanticColors.dark.foreground,
59
+ textSecondary: semanticColors.dark.mutedForeground,
60
+ textHalo: colors.charcoal[900],
61
+ poi: colors.navy[400],
62
+ // Lighter for dark mode
63
+ labelBackground: "rgba(41, 36, 36, 0.85)"
64
+ };
65
+ }
66
+ function generateLightDataColors() {
67
+ return {
68
+ sequence: [
69
+ colors.teal[500],
70
+ // chart.1
71
+ colors.navy[700],
72
+ // chart.2
73
+ colors.plum[700],
74
+ // chart.3
75
+ colors.forest[500],
76
+ // chart.4
77
+ colors.sky[600]
78
+ // chart.5
79
+ ],
80
+ positive: colors.forest[500],
81
+ negative: colors.red[500],
82
+ neutral: colors.gray[500],
83
+ heatmapRamp: [
84
+ "rgba(59, 164, 167, 0)",
85
+ // teal transparent
86
+ colors.teal[200],
87
+ colors.teal[400],
88
+ colors.teal[500],
89
+ colors.red[400],
90
+ colors.red[500],
91
+ colors.red[600]
92
+ ]
93
+ };
94
+ }
95
+ function generateDarkDataColors() {
96
+ return {
97
+ sequence: [
98
+ colors.teal[400],
99
+ // chart.1
100
+ colors.navy[400],
101
+ // chart.2
102
+ colors.plum[400],
103
+ // chart.3
104
+ colors.forest[400],
105
+ // chart.4
106
+ colors.sky[400]
107
+ // chart.5
108
+ ],
109
+ positive: colors.forest[400],
110
+ negative: colors.red[400],
111
+ neutral: colors.gray[400],
112
+ heatmapRamp: [
113
+ "rgba(103, 204, 207, 0)",
114
+ // teal transparent
115
+ colors.teal[300],
116
+ colors.teal[400],
117
+ colors.teal[500],
118
+ colors.red[400],
119
+ colors.red[500],
120
+ colors.red[600]
121
+ ]
122
+ };
123
+ }
124
+ function getTypography() {
125
+ return {
126
+ fontFamily: fontFamily.sans.join(", "),
127
+ fontFamilySerif: fontFamily.serif.join(", "),
128
+ fontFamilyMono: fontFamily.mono.join(", ")
129
+ };
130
+ }
131
+ function generateLightTheme() {
132
+ return {
133
+ name: THEME_LIGHT,
134
+ colors: generateLightColors(),
135
+ dataColors: generateLightDataColors(),
136
+ typography: getTypography()
137
+ };
138
+ }
139
+ function generateDarkTheme() {
140
+ return {
141
+ name: THEME_DARK,
142
+ colors: generateDarkColors(),
143
+ dataColors: generateDarkDataColors(),
144
+ typography: getTypography()
145
+ };
146
+ }
147
+ var lightTheme = generateLightTheme();
148
+ var darkTheme = generateDarkTheme();
149
+ function getTheme(name) {
150
+ if (name === "dark" || name === THEME_DARK) {
151
+ return darkTheme;
152
+ }
153
+ return lightTheme;
154
+ }
155
+
156
+ // src/theme/style.ts
157
+ var DEFAULT_TILE_SOURCE = {
158
+ type: "vector",
159
+ url: "https://api.maptiler.com/tiles/v3/tiles.json?key=get_your_own_key"
160
+ };
161
+ var OSM_RASTER_SOURCE = {
162
+ type: "raster",
163
+ tiles: ["https://tile.openstreetmap.org/{z}/{x}/{y}.png"],
164
+ tileSize: 256,
165
+ attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
166
+ };
167
+ function generateBasicStyle(theme = lightTheme) {
168
+ const colors2 = theme.colors;
169
+ return {
170
+ version: 8,
171
+ name: `Classic Theme - ${theme.name}`,
172
+ sources: {
173
+ osm: OSM_RASTER_SOURCE
174
+ },
175
+ layers: [
176
+ {
177
+ id: "background",
178
+ type: "background",
179
+ paint: {
180
+ "background-color": colors2.background
181
+ }
182
+ },
183
+ {
184
+ id: "osm-tiles",
185
+ type: "raster",
186
+ source: "osm",
187
+ minzoom: 0,
188
+ maxzoom: 19,
189
+ paint: {
190
+ "raster-opacity": theme.name === THEME_DARK ? 0.6 : 1,
191
+ "raster-saturation": theme.name === THEME_DARK ? -0.3 : 0
192
+ }
193
+ }
194
+ ],
195
+ metadata: {
196
+ "classic-theme": theme.name
197
+ }
198
+ };
199
+ }
200
+ function createWaterLayer(colors2) {
201
+ return {
202
+ id: "water",
203
+ type: "fill",
204
+ source: "openmaptiles",
205
+ "source-layer": "water",
206
+ paint: {
207
+ "fill-color": colors2.water,
208
+ "fill-opacity": 1
209
+ }
210
+ };
211
+ }
212
+ function createLanduseLayers(colors2) {
213
+ return [
214
+ {
215
+ id: "landuse-residential",
216
+ type: "fill",
217
+ source: "openmaptiles",
218
+ "source-layer": "landuse",
219
+ filter: ["==", "class", "residential"],
220
+ paint: {
221
+ "fill-color": colors2.residential,
222
+ "fill-opacity": 0.6
223
+ }
224
+ },
225
+ {
226
+ id: "landuse-commercial",
227
+ type: "fill",
228
+ source: "openmaptiles",
229
+ "source-layer": "landuse",
230
+ filter: ["==", "class", "commercial"],
231
+ paint: {
232
+ "fill-color": colors2.commercial,
233
+ "fill-opacity": 0.6
234
+ }
235
+ },
236
+ {
237
+ id: "landuse-industrial",
238
+ type: "fill",
239
+ source: "openmaptiles",
240
+ "source-layer": "landuse",
241
+ filter: ["==", "class", "industrial"],
242
+ paint: {
243
+ "fill-color": colors2.industrial,
244
+ "fill-opacity": 0.6
245
+ }
246
+ },
247
+ {
248
+ id: "landuse-park",
249
+ type: "fill",
250
+ source: "openmaptiles",
251
+ "source-layer": "landuse",
252
+ filter: ["in", "class", "park", "grass", "cemetery"],
253
+ paint: {
254
+ "fill-color": colors2.park,
255
+ "fill-opacity": 0.8
256
+ }
257
+ }
258
+ ];
259
+ }
260
+ function createBuildingLayers(colors2) {
261
+ return [
262
+ {
263
+ id: "building",
264
+ type: "fill",
265
+ source: "openmaptiles",
266
+ "source-layer": "building",
267
+ minzoom: 13,
268
+ paint: {
269
+ "fill-color": colors2.building,
270
+ "fill-opacity": ["interpolate", ["linear"], ["zoom"], 13, 0, 15, 1]
271
+ }
272
+ },
273
+ {
274
+ id: "building-outline",
275
+ type: "line",
276
+ source: "openmaptiles",
277
+ "source-layer": "building",
278
+ minzoom: 13,
279
+ paint: {
280
+ "line-color": colors2.buildingOutline,
281
+ "line-width": 1,
282
+ "line-opacity": ["interpolate", ["linear"], ["zoom"], 13, 0, 15, 1]
283
+ }
284
+ }
285
+ ];
286
+ }
287
+ function createRoadLayers(colors2) {
288
+ return [
289
+ // Road casings (outlines)
290
+ {
291
+ id: "road-casing-primary",
292
+ type: "line",
293
+ source: "openmaptiles",
294
+ "source-layer": "transportation",
295
+ filter: ["in", "class", "primary", "trunk", "motorway"],
296
+ paint: {
297
+ "line-color": colors2.roadCasing,
298
+ "line-width": ["interpolate", ["linear"], ["zoom"], 5, 0.5, 12, 4, 18, 20]
299
+ },
300
+ layout: {
301
+ "line-cap": "round",
302
+ "line-join": "round"
303
+ }
304
+ },
305
+ {
306
+ id: "road-casing-secondary",
307
+ type: "line",
308
+ source: "openmaptiles",
309
+ "source-layer": "transportation",
310
+ filter: ["in", "class", "secondary", "tertiary"],
311
+ paint: {
312
+ "line-color": colors2.roadCasing,
313
+ "line-width": ["interpolate", ["linear"], ["zoom"], 8, 0.5, 12, 2, 18, 12]
314
+ },
315
+ layout: {
316
+ "line-cap": "round",
317
+ "line-join": "round"
318
+ }
319
+ },
320
+ // Road fills
321
+ {
322
+ id: "road-primary",
323
+ type: "line",
324
+ source: "openmaptiles",
325
+ "source-layer": "transportation",
326
+ filter: ["in", "class", "primary", "trunk", "motorway"],
327
+ paint: {
328
+ "line-color": colors2.roadPrimary,
329
+ "line-width": ["interpolate", ["linear"], ["zoom"], 5, 0.25, 12, 3, 18, 18]
330
+ },
331
+ layout: {
332
+ "line-cap": "round",
333
+ "line-join": "round"
334
+ }
335
+ },
336
+ {
337
+ id: "road-secondary",
338
+ type: "line",
339
+ source: "openmaptiles",
340
+ "source-layer": "transportation",
341
+ filter: ["in", "class", "secondary", "tertiary"],
342
+ paint: {
343
+ "line-color": colors2.roadSecondary,
344
+ "line-width": ["interpolate", ["linear"], ["zoom"], 8, 0.25, 12, 1.5, 18, 10]
345
+ },
346
+ layout: {
347
+ "line-cap": "round",
348
+ "line-join": "round"
349
+ }
350
+ },
351
+ {
352
+ id: "road-minor",
353
+ type: "line",
354
+ source: "openmaptiles",
355
+ "source-layer": "transportation",
356
+ filter: ["in", "class", "minor", "service", "path"],
357
+ minzoom: 13,
358
+ paint: {
359
+ "line-color": colors2.roadSecondary,
360
+ "line-width": ["interpolate", ["linear"], ["zoom"], 13, 0.5, 18, 6]
361
+ },
362
+ layout: {
363
+ "line-cap": "round",
364
+ "line-join": "round"
365
+ }
366
+ },
367
+ // Rail
368
+ {
369
+ id: "rail",
370
+ type: "line",
371
+ source: "openmaptiles",
372
+ "source-layer": "transportation",
373
+ filter: ["==", "class", "rail"],
374
+ minzoom: 10,
375
+ paint: {
376
+ "line-color": colors2.rail,
377
+ "line-width": ["interpolate", ["linear"], ["zoom"], 10, 0.5, 18, 2],
378
+ "line-dasharray": [2, 2]
379
+ }
380
+ }
381
+ ];
382
+ }
383
+ function createBoundaryLayers(colors2) {
384
+ return [
385
+ {
386
+ id: "boundary-country",
387
+ type: "line",
388
+ source: "openmaptiles",
389
+ "source-layer": "boundary",
390
+ filter: ["==", "admin_level", 2],
391
+ paint: {
392
+ "line-color": colors2.adminBoundary,
393
+ "line-width": ["interpolate", ["linear"], ["zoom"], 2, 0.5, 10, 2],
394
+ "line-dasharray": [3, 2]
395
+ }
396
+ },
397
+ {
398
+ id: "boundary-state",
399
+ type: "line",
400
+ source: "openmaptiles",
401
+ "source-layer": "boundary",
402
+ filter: ["==", "admin_level", 4],
403
+ minzoom: 4,
404
+ paint: {
405
+ "line-color": colors2.boundary,
406
+ "line-width": ["interpolate", ["linear"], ["zoom"], 4, 0.5, 10, 1.5],
407
+ "line-dasharray": [2, 2]
408
+ }
409
+ }
410
+ ];
411
+ }
412
+ function createLabelLayers(colors2, typography) {
413
+ return [
414
+ {
415
+ id: "place-labels-city",
416
+ type: "symbol",
417
+ source: "openmaptiles",
418
+ "source-layer": "place",
419
+ filter: ["in", "class", "city", "town"],
420
+ paint: {
421
+ "text-color": colors2.textPrimary,
422
+ "text-halo-color": colors2.textHalo,
423
+ "text-halo-width": 1.5
424
+ },
425
+ layout: {
426
+ "text-field": ["get", "name"],
427
+ "text-font": [typography.fontFamily.split(",")[0].trim()],
428
+ "text-size": ["interpolate", ["linear"], ["zoom"], 6, 10, 14, 18],
429
+ "text-anchor": "center",
430
+ "text-max-width": 10
431
+ }
432
+ },
433
+ {
434
+ id: "place-labels-neighborhood",
435
+ type: "symbol",
436
+ source: "openmaptiles",
437
+ "source-layer": "place",
438
+ filter: ["in", "class", "suburb", "neighbourhood", "quarter"],
439
+ minzoom: 12,
440
+ paint: {
441
+ "text-color": colors2.textSecondary,
442
+ "text-halo-color": colors2.textHalo,
443
+ "text-halo-width": 1
444
+ },
445
+ layout: {
446
+ "text-field": ["get", "name"],
447
+ "text-font": [typography.fontFamily.split(",")[0].trim()],
448
+ "text-size": ["interpolate", ["linear"], ["zoom"], 12, 10, 16, 14],
449
+ "text-anchor": "center",
450
+ "text-max-width": 8
451
+ }
452
+ },
453
+ {
454
+ id: "road-labels",
455
+ type: "symbol",
456
+ source: "openmaptiles",
457
+ "source-layer": "transportation_name",
458
+ minzoom: 13,
459
+ paint: {
460
+ "text-color": colors2.textPrimary,
461
+ "text-halo-color": colors2.textHalo,
462
+ "text-halo-width": 1
463
+ },
464
+ layout: {
465
+ "text-field": ["get", "name"],
466
+ "text-font": [typography.fontFamily.split(",")[0].trim()],
467
+ "text-size": ["interpolate", ["linear"], ["zoom"], 13, 9, 18, 14],
468
+ "symbol-placement": "line",
469
+ "text-rotation-alignment": "map",
470
+ "text-max-angle": 30
471
+ }
472
+ },
473
+ {
474
+ id: "poi-labels",
475
+ type: "symbol",
476
+ source: "openmaptiles",
477
+ "source-layer": "poi",
478
+ minzoom: 14,
479
+ paint: {
480
+ "text-color": colors2.poi,
481
+ "text-halo-color": colors2.textHalo,
482
+ "text-halo-width": 1
483
+ },
484
+ layout: {
485
+ "text-field": ["get", "name"],
486
+ "text-font": [typography.fontFamily.split(",")[0].trim()],
487
+ "text-size": 11,
488
+ "text-anchor": "top",
489
+ "text-offset": [0, 0.5],
490
+ "text-max-width": 8
491
+ }
492
+ }
493
+ ];
494
+ }
495
+ function generateVectorStyle(theme = lightTheme, tileSource, glyphsUrl, spriteUrl) {
496
+ const colors2 = theme.colors;
497
+ return {
498
+ version: 8,
499
+ name: `Classic Theme Vector - ${theme.name}`,
500
+ sources: {
501
+ openmaptiles: tileSource || DEFAULT_TILE_SOURCE
502
+ },
503
+ glyphs: glyphsUrl || "https://fonts.openmaptiles.org/{fontstack}/{range}.pbf",
504
+ sprite: spriteUrl,
505
+ layers: [
506
+ {
507
+ id: "background",
508
+ type: "background",
509
+ paint: {
510
+ "background-color": colors2.land
511
+ }
512
+ },
513
+ createWaterLayer(colors2),
514
+ ...createLanduseLayers(colors2),
515
+ ...createBuildingLayers(colors2),
516
+ ...createRoadLayers(colors2),
517
+ ...createBoundaryLayers(colors2),
518
+ ...createLabelLayers(colors2, theme.typography)
519
+ ],
520
+ metadata: {
521
+ "classic-theme": theme.name
522
+ }
523
+ };
524
+ }
525
+ var lightBasicStyle = generateBasicStyle(lightTheme);
526
+ var darkBasicStyle = generateBasicStyle(darkTheme);
527
+ function getBasicStyle(themeName) {
528
+ if (themeName === "dark" || themeName === THEME_DARK) {
529
+ return darkBasicStyle;
530
+ }
531
+ return lightBasicStyle;
532
+ }
533
+
534
+ export { THEME_DARK, THEME_LIGHT, darkBasicStyle, darkTheme, generateBasicStyle, generateDarkColors, generateDarkDataColors, generateDarkTheme, generateLightColors, generateLightDataColors, generateLightTheme, generateVectorStyle, getBasicStyle, getTheme, getTypography, lightBasicStyle, lightTheme };
@@ -0,0 +1,141 @@
1
+ /**
2
+ * Map data types
3
+ *
4
+ * Re-exports GeoJSON types and defines additional map-specific data structures
5
+ */
6
+ /**
7
+ * Longitude/Latitude coordinate pair
8
+ * Following GeoJSON convention: [longitude, latitude]
9
+ */
10
+ type LngLat = [number, number];
11
+ /**
12
+ * Map bounds defined by southwest and northeast corners
13
+ */
14
+ interface MapBounds {
15
+ /** Southwest corner [lng, lat] */
16
+ southwest: LngLat;
17
+ /** Northeast corner [lng, lat] */
18
+ northeast: LngLat;
19
+ }
20
+ /**
21
+ * Shorthand for bounds as array: [[sw_lng, sw_lat], [ne_lng, ne_lat]]
22
+ */
23
+ type BoundsArray = [LngLat, LngLat];
24
+ /**
25
+ * Map viewport/camera state
26
+ */
27
+ interface MapViewport {
28
+ /** Center coordinates [lng, lat] */
29
+ center: LngLat;
30
+ /** Zoom level (0-24) */
31
+ zoom: number;
32
+ /** Map bearing/rotation in degrees (0-360) */
33
+ bearing?: number;
34
+ /** Map pitch/tilt in degrees (0-85) */
35
+ pitch?: number;
36
+ }
37
+ /**
38
+ * GeoJSON Feature type (simplified for our use)
39
+ */
40
+ interface GeoJSONFeature<G extends GeoJSONGeometry = GeoJSONGeometry, P = Record<string, unknown>> {
41
+ type: 'Feature';
42
+ id?: string | number;
43
+ geometry: G;
44
+ properties: P;
45
+ }
46
+ /**
47
+ * GeoJSON FeatureCollection
48
+ */
49
+ interface GeoJSONFeatureCollection<G extends GeoJSONGeometry = GeoJSONGeometry, P = Record<string, unknown>> {
50
+ type: 'FeatureCollection';
51
+ features: GeoJSONFeature<G, P>[];
52
+ }
53
+ /**
54
+ * GeoJSON Geometry types
55
+ */
56
+ type GeoJSONGeometry = GeoJSONPoint | GeoJSONMultiPoint | GeoJSONLineString | GeoJSONMultiLineString | GeoJSONPolygon | GeoJSONMultiPolygon;
57
+ interface GeoJSONPoint {
58
+ type: 'Point';
59
+ coordinates: LngLat;
60
+ }
61
+ interface GeoJSONMultiPoint {
62
+ type: 'MultiPoint';
63
+ coordinates: LngLat[];
64
+ }
65
+ interface GeoJSONLineString {
66
+ type: 'LineString';
67
+ coordinates: LngLat[];
68
+ }
69
+ interface GeoJSONMultiLineString {
70
+ type: 'MultiLineString';
71
+ coordinates: LngLat[][];
72
+ }
73
+ interface GeoJSONPolygon {
74
+ type: 'Polygon';
75
+ coordinates: LngLat[][];
76
+ }
77
+ interface GeoJSONMultiPolygon {
78
+ type: 'MultiPolygon';
79
+ coordinates: LngLat[][][];
80
+ }
81
+ /**
82
+ * Marker data for displaying points of interest
83
+ */
84
+ interface MarkerData {
85
+ /** Unique identifier */
86
+ id: string;
87
+ /** Marker position [lng, lat] */
88
+ coordinates: LngLat;
89
+ /** Optional marker label */
90
+ label?: string;
91
+ /** Optional marker color */
92
+ color?: string;
93
+ /** Optional custom icon name */
94
+ icon?: string;
95
+ /** Optional popup content */
96
+ popup?: string | {
97
+ title?: string;
98
+ content: string;
99
+ };
100
+ /** Custom properties for the marker */
101
+ properties?: Record<string, unknown>;
102
+ }
103
+ /**
104
+ * Cluster configuration for grouping markers
105
+ */
106
+ interface ClusterConfig {
107
+ /** Enable clustering */
108
+ enabled: boolean;
109
+ /** Radius of each cluster */
110
+ radius?: number;
111
+ /** Max zoom level for clustering */
112
+ maxZoom?: number;
113
+ /** Properties to aggregate in clusters */
114
+ clusterProperties?: Record<string, [string, unknown]>;
115
+ }
116
+ /**
117
+ * Heatmap data point
118
+ */
119
+ interface HeatmapPoint {
120
+ /** Point coordinates [lng, lat] */
121
+ coordinates: LngLat;
122
+ /** Weight/intensity of the point (0-1) */
123
+ weight?: number;
124
+ }
125
+ /**
126
+ * Building extrusion data
127
+ */
128
+ interface ExtrusionData {
129
+ /** Height of the extrusion in meters */
130
+ height: number;
131
+ /** Base height of the extrusion in meters */
132
+ baseHeight?: number;
133
+ /** Extrusion color */
134
+ color?: string;
135
+ }
136
+ /**
137
+ * Source data types that can be used with map sources
138
+ */
139
+ type MapSourceData = GeoJSONFeatureCollection | GeoJSONFeature | string | MarkerData[];
140
+
141
+ export type { BoundsArray as B, ClusterConfig as C, ExtrusionData as E, GeoJSONFeatureCollection as G, HeatmapPoint as H, LngLat as L, MapBounds as M, GeoJSONFeature as a, MarkerData as b, GeoJSONPolygon as c, MapViewport as d, GeoJSONGeometry as e, GeoJSONPoint as f, GeoJSONMultiPoint as g, GeoJSONLineString as h, GeoJSONMultiLineString as i, GeoJSONMultiPolygon as j, MapSourceData as k };