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