@riebeckite/plugin-map 0.0.6
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.
- package/LICENSE +201 -0
- package/README.md +176 -0
- package/README_ja.md +142 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.js +164 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +628 -0
- package/dist/src/hast.d.ts +7 -0
- package/dist/src/init.d.ts +11 -0
- package/dist/src/options.d.ts +30 -0
- package/dist/src/parse.d.ts +35 -0
- package/dist/src/rehype.d.ts +11 -0
- package/dist/src/types.d.ts +159 -0
- package/package.json +62 -0
- package/style.css +107 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { MapCoordinates, MapData } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Parses a fenced `map` code block into a notation-neutral {@link MapData}.
|
|
4
|
+
*
|
|
5
|
+
* The body is a small, dependency-free key/value format:
|
|
6
|
+
*
|
|
7
|
+
* ```text
|
|
8
|
+
* center: 35.6812, 139.7671
|
|
9
|
+
* zoom: 13
|
|
10
|
+
* label: Tokyo Station
|
|
11
|
+
* markers:
|
|
12
|
+
* - 35.6812, 139.7671 | Tokyo Station
|
|
13
|
+
* - 35.6586, 139.7454 | Tokyo Tower | A lattice tower
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* A bare `lat, lng` line is treated as an implicit marker, so a single-point
|
|
17
|
+
* map can be written as just the coordinates. Returns `null` when the body
|
|
18
|
+
* contains neither a marker nor a center, which the rehype transformer reports
|
|
19
|
+
* as an invalid block.
|
|
20
|
+
*/
|
|
21
|
+
export declare function parseMapSource(source: string): MapData | null;
|
|
22
|
+
/**
|
|
23
|
+
* Normalizes a frontmatter value into {@link MapData}.
|
|
24
|
+
*
|
|
25
|
+
* Accepts a coordinate string (`"35.68, 139.76"`), a `[lat, lng]` pair, an
|
|
26
|
+
* array of markers, or an object with `lat`/`lng` (or `latitude`/`longitude`),
|
|
27
|
+
* `zoom`, `label`, `tiles`, `attribution`, `image`, and `markers`.
|
|
28
|
+
*/
|
|
29
|
+
export declare function normalizeMapInput(value: unknown): MapData | null;
|
|
30
|
+
/** Formats coordinates for display (`35.6812, 139.7671`). */
|
|
31
|
+
export declare function formatCoordinates(coordinates: MapCoordinates): string;
|
|
32
|
+
/** Builds a human-readable label for the whole map. */
|
|
33
|
+
export declare function describeMap(data: MapData): string;
|
|
34
|
+
/** Builds an OpenStreetMap link centered on the coordinates. */
|
|
35
|
+
export declare function openStreetMapUrl(coordinates: MapCoordinates, zoom: number): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { HastNode, MapOptions } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Replaces every fenced `map` code block with a map figure, and prepends a
|
|
4
|
+
* figure for the configured frontmatter property when present.
|
|
5
|
+
*
|
|
6
|
+
* The figure carries the resolved map data in `data-rr-map-payload` and a
|
|
7
|
+
* static fallback (coordinates, place, OpenStreetMap links) so the page is
|
|
8
|
+
* usable without JavaScript. `initMap` upgrades each figure to an interactive
|
|
9
|
+
* Leaflet map in the browser.
|
|
10
|
+
*/
|
|
11
|
+
export declare function rehypeMap(options?: MapOptions): (tree: HastNode, file: unknown) => void;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public types for the Map plugin.
|
|
3
|
+
*
|
|
4
|
+
* This module is imported by the build-time transformer, the browser
|
|
5
|
+
* initializer, and the package entry point, so it must stay free of Node-only
|
|
6
|
+
* imports.
|
|
7
|
+
*/
|
|
8
|
+
/** A single latitude/longitude pair. */
|
|
9
|
+
export type MapCoordinates = {
|
|
10
|
+
lat: number;
|
|
11
|
+
lng: number;
|
|
12
|
+
};
|
|
13
|
+
/** A marker on the map, optionally named. */
|
|
14
|
+
export type MapMarker = MapCoordinates & {
|
|
15
|
+
/** Human-readable place name, shown in the popup and static fallback. */
|
|
16
|
+
label?: string;
|
|
17
|
+
/** Optional longer text shown in the marker popup. */
|
|
18
|
+
description?: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* A parsed map specification. It is the notation-neutral seam of the plugin:
|
|
22
|
+
* the fenced-block parser and the frontmatter normalizer both produce it, and
|
|
23
|
+
* the figure emitter consumes it without knowing the input notation.
|
|
24
|
+
*/
|
|
25
|
+
export type MapData = {
|
|
26
|
+
/** Markers to draw, in document order. May be empty when only a view is set. */
|
|
27
|
+
markers: MapMarker[];
|
|
28
|
+
/** Explicit map center. Defaults to the first marker when omitted. */
|
|
29
|
+
center?: MapCoordinates;
|
|
30
|
+
/** Zoom level. Defaults to the plugin option when omitted. */
|
|
31
|
+
zoom?: number;
|
|
32
|
+
/** Human-readable place name for the whole map. */
|
|
33
|
+
label?: string;
|
|
34
|
+
/** Per-map tile URL template override. */
|
|
35
|
+
tiles?: string;
|
|
36
|
+
/** Per-map attribution override. */
|
|
37
|
+
attribution?: string;
|
|
38
|
+
/** Per-map static image URL (already resolved). */
|
|
39
|
+
image?: string;
|
|
40
|
+
};
|
|
41
|
+
/** Options accepted by the `map` plugin factory. */
|
|
42
|
+
export type MapOptions = {
|
|
43
|
+
/** Fenced-code language to recognize. Defaults to `"map"`. */
|
|
44
|
+
language?: string;
|
|
45
|
+
/** Base CSS class applied to the figure. Defaults to `"rr-map"`. */
|
|
46
|
+
className?: string;
|
|
47
|
+
/** Map height in pixels. Defaults to `320`. */
|
|
48
|
+
height?: number;
|
|
49
|
+
/** Default zoom level (0–19). Defaults to `13`. */
|
|
50
|
+
zoom?: number;
|
|
51
|
+
/** Minimum zoom level forwarded to the tile layer. Defaults to `1`. */
|
|
52
|
+
minZoom?: number;
|
|
53
|
+
/** Maximum zoom level forwarded to the tile layer. Defaults to `19`. */
|
|
54
|
+
maxZoom?: number;
|
|
55
|
+
/**
|
|
56
|
+
* Tile URL template with `{z}`, `{x}`, `{y}` placeholders. Defaults to the
|
|
57
|
+
* OpenStreetMap standard tiles. See the README for the tile usage policy.
|
|
58
|
+
*/
|
|
59
|
+
tileUrl?: string;
|
|
60
|
+
/**
|
|
61
|
+
* Attribution HTML required by the tile provider. Defaults to the
|
|
62
|
+
* OpenStreetMap attribution. Keep it visible on every map.
|
|
63
|
+
*/
|
|
64
|
+
attribution?: string;
|
|
65
|
+
/** Render a `<details>` block holding the raw block source. Defaults to `true`. */
|
|
66
|
+
fallback?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Render the static fallback (coordinates, place, OpenStreetMap links) that
|
|
69
|
+
* stays visible when JavaScript is disabled. Defaults to `true`.
|
|
70
|
+
*/
|
|
71
|
+
staticFallback?: boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Optional static image URL template with `{lat}`, `{lng}`, `{zoom}`, `{width}`
|
|
74
|
+
* and `{height}` placeholders. No default: a static map service usually needs
|
|
75
|
+
* a key, which site owners must supply themselves.
|
|
76
|
+
*/
|
|
77
|
+
staticImageUrl?: string;
|
|
78
|
+
/** Frontmatter property holding map coordinates. Defaults to `"map"`. */
|
|
79
|
+
frontmatterKey?: string;
|
|
80
|
+
};
|
|
81
|
+
/** Options after defaults have been applied. */
|
|
82
|
+
export type ResolvedMapOptions = {
|
|
83
|
+
language: string;
|
|
84
|
+
className: string;
|
|
85
|
+
height: number;
|
|
86
|
+
zoom: number;
|
|
87
|
+
minZoom: number;
|
|
88
|
+
maxZoom: number;
|
|
89
|
+
tileUrl: string;
|
|
90
|
+
attribution: string;
|
|
91
|
+
fallback: boolean;
|
|
92
|
+
staticFallback: boolean;
|
|
93
|
+
staticImageUrl: string | null;
|
|
94
|
+
frontmatterKey: string;
|
|
95
|
+
};
|
|
96
|
+
/** The JSON payload embedded in the figure and consumed by `initMap`. */
|
|
97
|
+
export type MapPayload = {
|
|
98
|
+
markers: MapMarker[];
|
|
99
|
+
center: MapCoordinates;
|
|
100
|
+
zoom: number;
|
|
101
|
+
label: string | null;
|
|
102
|
+
tiles: string;
|
|
103
|
+
attribution: string;
|
|
104
|
+
image: string | null;
|
|
105
|
+
};
|
|
106
|
+
/** Options accepted by `initMap` when called programmatically. */
|
|
107
|
+
export type MapClientOptions = {
|
|
108
|
+
/** Default tile URL when a figure does not carry its own. */
|
|
109
|
+
tileUrl?: string;
|
|
110
|
+
/** Default attribution when a figure does not carry its own. */
|
|
111
|
+
attribution?: string;
|
|
112
|
+
/** Default minimum zoom level. Defaults to `1`. */
|
|
113
|
+
minZoom?: number;
|
|
114
|
+
/** Default maximum zoom level. Defaults to `19`. */
|
|
115
|
+
maxZoom?: number;
|
|
116
|
+
/** ESM/UMD URL of the Leaflet script. Defaults to the pinned jsDelivr build. */
|
|
117
|
+
leafletScriptUrl?: string;
|
|
118
|
+
/** URL of the Leaflet stylesheet. Defaults to the pinned jsDelivr build. */
|
|
119
|
+
leafletStyleUrl?: string;
|
|
120
|
+
/** Preloaded Leaflet runtime, used to skip the network load. */
|
|
121
|
+
runtime?: MapRuntime;
|
|
122
|
+
};
|
|
123
|
+
/** The subset of the Leaflet API the initializer uses. */
|
|
124
|
+
export type LeafletLayer = {
|
|
125
|
+
addTo(map: LeafletMap): LeafletLayer;
|
|
126
|
+
bindPopup?(content: string): LeafletLayer;
|
|
127
|
+
};
|
|
128
|
+
export type LeafletMap = {
|
|
129
|
+
setView(center: [number, number], zoom: number): LeafletMap;
|
|
130
|
+
fitBounds(bounds: unknown, options?: Record<string, unknown>): LeafletMap;
|
|
131
|
+
remove(): void;
|
|
132
|
+
};
|
|
133
|
+
export type MapRuntime = {
|
|
134
|
+
map(element: HTMLElement, options?: Record<string, unknown>): LeafletMap;
|
|
135
|
+
tileLayer(url: string, options?: Record<string, unknown>): LeafletLayer;
|
|
136
|
+
marker(coordinates: [number, number], options?: Record<string, unknown>): LeafletLayer;
|
|
137
|
+
latLngBounds(coordinates: Array<[number, number]>): unknown;
|
|
138
|
+
};
|
|
139
|
+
export type ElementNode = {
|
|
140
|
+
type: string;
|
|
141
|
+
tagName?: string;
|
|
142
|
+
properties?: Record<string, unknown>;
|
|
143
|
+
children?: HastNode[];
|
|
144
|
+
};
|
|
145
|
+
export type ParentNode = HastNode & {
|
|
146
|
+
children?: HastNode[];
|
|
147
|
+
};
|
|
148
|
+
export type TextNode = {
|
|
149
|
+
type: "text";
|
|
150
|
+
value: string;
|
|
151
|
+
};
|
|
152
|
+
export type RawNode = {
|
|
153
|
+
type: "raw";
|
|
154
|
+
value: string;
|
|
155
|
+
};
|
|
156
|
+
export type HastNode = ElementNode | TextNode | RawNode | {
|
|
157
|
+
type: string;
|
|
158
|
+
[key: string]: unknown;
|
|
159
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@riebeckite/plugin-map",
|
|
3
|
+
"version": "0.0.6",
|
|
4
|
+
"license": "Apache-2.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"source": "./index.ts",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./client": {
|
|
16
|
+
"types": "./dist/client.d.ts",
|
|
17
|
+
"import": "./dist/client.js",
|
|
18
|
+
"source": "./client.ts",
|
|
19
|
+
"default": "./dist/client.js"
|
|
20
|
+
},
|
|
21
|
+
"./style.css": "./style.css"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@riebeckite/core": "0.0.6"
|
|
25
|
+
},
|
|
26
|
+
"publishConfig": {
|
|
27
|
+
"access": "public"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"LICENSE",
|
|
31
|
+
"README.md",
|
|
32
|
+
"README_ja.md",
|
|
33
|
+
"dist",
|
|
34
|
+
"style.css"
|
|
35
|
+
],
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "https://github.com/Rerurate514/riebeckite.git",
|
|
39
|
+
"directory": "packages/plugins/map"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://github.com/Rerurate514/riebeckite#readme",
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/Rerurate514/riebeckite/issues"
|
|
44
|
+
},
|
|
45
|
+
"description": "Interactive and static OpenStreetMap embeds for Riebeckite.",
|
|
46
|
+
"keywords": [
|
|
47
|
+
"riebeckite",
|
|
48
|
+
"plugin",
|
|
49
|
+
"map",
|
|
50
|
+
"openstreetmap",
|
|
51
|
+
"leaflet"
|
|
52
|
+
],
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
55
|
+
},
|
|
56
|
+
"sideEffects": [
|
|
57
|
+
"./style.css"
|
|
58
|
+
],
|
|
59
|
+
"scripts": {
|
|
60
|
+
"build": "node ../../../scripts/build_package.mjs"
|
|
61
|
+
}
|
|
62
|
+
}
|
package/style.css
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
.rr-map {
|
|
2
|
+
--rr-map-paper: var(--rb-color-paper, #ffffff);
|
|
3
|
+
--rr-map-ink: var(--rb-color-ink, #000000);
|
|
4
|
+
--rr-map-muted: var(--rb-color-muted, #69645c);
|
|
5
|
+
--rr-map-rule: var(
|
|
6
|
+
--rb-color-border,
|
|
7
|
+
color-mix(in srgb, var(--rr-map-ink) 18%, transparent)
|
|
8
|
+
);
|
|
9
|
+
--rr-map-accent: var(--rb-color-accent, #0b6e99);
|
|
10
|
+
margin: 2rem 0;
|
|
11
|
+
border: 1px solid var(--rr-map-rule);
|
|
12
|
+
background: color-mix(in srgb, var(--rr-map-paper) 96%, var(--rr-map-ink));
|
|
13
|
+
color: var(--rr-map-ink);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.rr-map__caption {
|
|
17
|
+
padding: 0.625rem 0.75rem;
|
|
18
|
+
border-bottom: 1px solid var(--rr-map-rule);
|
|
19
|
+
color: var(--rr-map-muted);
|
|
20
|
+
font-size: 0.875rem;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.rr-map__canvas {
|
|
24
|
+
height: 320px;
|
|
25
|
+
background: color-mix(in srgb, var(--rr-map-ink) 4%, transparent);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.rr-map:not([data-rr-map="rendered"]) .rr-map__canvas {
|
|
29
|
+
display: none;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.rr-map__canvas .leaflet-container {
|
|
33
|
+
background: transparent;
|
|
34
|
+
font: inherit;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.rr-map__static {
|
|
38
|
+
padding: 0.75rem 0.875rem 0.875rem;
|
|
39
|
+
border-top: 1px solid var(--rr-map-rule);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.rr-map__image {
|
|
43
|
+
display: block;
|
|
44
|
+
width: 100%;
|
|
45
|
+
height: auto;
|
|
46
|
+
margin-bottom: 0.75rem;
|
|
47
|
+
border: 1px solid var(--rr-map-rule);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.rr-map__place {
|
|
51
|
+
margin: 0 0 0.5rem;
|
|
52
|
+
font-weight: 600;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.rr-map__markers {
|
|
56
|
+
margin: 0;
|
|
57
|
+
padding: 0;
|
|
58
|
+
list-style: none;
|
|
59
|
+
display: grid;
|
|
60
|
+
gap: 0.25rem;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.rr-map__marker {
|
|
64
|
+
color: var(--rr-map-muted);
|
|
65
|
+
font-size: 0.875rem;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.rr-map__link {
|
|
69
|
+
color: var(--rr-map-accent);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.rr-map__attribution {
|
|
73
|
+
margin: 0.625rem 0 0;
|
|
74
|
+
color: var(--rr-map-muted);
|
|
75
|
+
font-size: 0.75rem;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
.rr-map__fallback {
|
|
79
|
+
border-top: 1px solid var(--rr-map-rule);
|
|
80
|
+
color: var(--rr-map-muted);
|
|
81
|
+
font-size: 0.8125rem;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.rr-map__fallback summary {
|
|
85
|
+
cursor: pointer;
|
|
86
|
+
padding: 0.5rem 0.75rem;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
.rr-map__fallback pre {
|
|
90
|
+
overflow: auto;
|
|
91
|
+
margin: 0 1rem;
|
|
92
|
+
padding: 0.75rem;
|
|
93
|
+
border-top: 1px solid var(--rr-map-rule);
|
|
94
|
+
color: var(--rr-map-ink);
|
|
95
|
+
background: color-mix(in srgb, var(--rr-map-ink) 6%, transparent);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.rr-map[data-rr-map="error"] .rr-map__static::before {
|
|
99
|
+
content: "The interactive map could not be loaded. ";
|
|
100
|
+
color: var(--rr-map-muted);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
html[data-theme="dark"] .rr-map,
|
|
104
|
+
html.dark .rr-map {
|
|
105
|
+
--rr-map-paper: var(--rb-color-ink, #000000);
|
|
106
|
+
--rr-map-ink: var(--rb-color-paper, #ffffff);
|
|
107
|
+
}
|