@riebeckite/plugin-map 0.0.30 → 0.0.32
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/dist/client.js +13 -3
- package/dist/index.js +17 -45
- package/dist/src/hast.d.ts +6 -6
- package/dist/src/init.d.ts +7 -1
- package/package.json +3 -2
package/dist/client.js
CHANGED
|
@@ -4,19 +4,28 @@ var DEFAULT_LEAFLET_STYLE_URL = "https://cdn.jsdelivr.net/npm/leaflet@1.9.4/dist
|
|
|
4
4
|
var DEFAULT_TILE_URL = "https://tile.openstreetmap.org/{z}/{x}/{y}.png";
|
|
5
5
|
var DEFAULT_ATTRIBUTION = '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors';
|
|
6
6
|
var leafletPromise = null;
|
|
7
|
-
async function initMap(
|
|
7
|
+
async function initMap(context = {}) {
|
|
8
|
+
const options = context.config ?? {};
|
|
9
|
+
const root = context.root ?? document;
|
|
8
10
|
const figures = Array.from(
|
|
9
|
-
|
|
11
|
+
root.querySelectorAll('[data-rr-map="pending"]')
|
|
10
12
|
);
|
|
11
13
|
if (figures.length === 0) return;
|
|
12
14
|
const runtime = options.runtime ?? await loadLeaflet(options);
|
|
15
|
+
if (context.signal?.aborted) return;
|
|
13
16
|
if (!runtime) {
|
|
14
17
|
for (const figure of figures) setError(figure);
|
|
15
18
|
return;
|
|
16
19
|
}
|
|
20
|
+
const maps = [];
|
|
17
21
|
for (const figure of figures) {
|
|
18
|
-
|
|
22
|
+
if (context.signal?.aborted || !figure.isConnected) break;
|
|
23
|
+
const map = renderMap(runtime, figure, options);
|
|
24
|
+
if (map) maps.push(map);
|
|
19
25
|
}
|
|
26
|
+
return () => {
|
|
27
|
+
for (const map of maps) map.remove();
|
|
28
|
+
};
|
|
20
29
|
}
|
|
21
30
|
function renderMap(runtime, figure, options) {
|
|
22
31
|
const canvas = figure.querySelector("[data-rr-map-canvas]");
|
|
@@ -57,6 +66,7 @@ function renderMap(runtime, figure, options) {
|
|
|
57
66
|
map.setView([payload.center.lat, payload.center.lng], payload.zoom);
|
|
58
67
|
}
|
|
59
68
|
figure.dataset.rrMap = "rendered";
|
|
69
|
+
return map;
|
|
60
70
|
} catch {
|
|
61
71
|
setError(figure);
|
|
62
72
|
}
|
package/dist/index.js
CHANGED
|
@@ -56,50 +56,20 @@ function clampZoom(value, minimum = 1) {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
// src/hast.ts
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
function text(value) {
|
|
74
|
-
return { type: "text", value };
|
|
75
|
-
}
|
|
76
|
-
function getTextContent(node) {
|
|
77
|
-
if (node.type === "text" && "value" in node && typeof node.value === "string") {
|
|
78
|
-
return node.value;
|
|
79
|
-
}
|
|
80
|
-
return getChildren(node).map(getTextContent).join("");
|
|
81
|
-
}
|
|
82
|
-
function getStringProperty(node, key) {
|
|
83
|
-
const value = node.properties?.[key];
|
|
84
|
-
if (typeof value === "string") return value;
|
|
85
|
-
if (Array.isArray(value)) return value.join(" ");
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
function hasClass(node, className) {
|
|
89
|
-
const value = node.properties?.className;
|
|
90
|
-
const classes = Array.isArray(value) ? value.map(String) : typeof value === "string" ? value.split(/\s+/) : [];
|
|
91
|
-
return classes.includes(className);
|
|
92
|
-
}
|
|
93
|
-
function isElementNode(node) {
|
|
94
|
-
return node.type === "element";
|
|
95
|
-
}
|
|
96
|
-
function hasChildren(node) {
|
|
97
|
-
return Array.isArray(node.children);
|
|
98
|
-
}
|
|
99
|
-
function getChildren(node) {
|
|
100
|
-
const children = node.children;
|
|
101
|
-
return Array.isArray(children) ? children : [];
|
|
102
|
-
}
|
|
59
|
+
import {
|
|
60
|
+
element as sharedElement,
|
|
61
|
+
getStringProperty as sharedGetStringProperty,
|
|
62
|
+
getTextContent as sharedGetTextContent,
|
|
63
|
+
hasClass as sharedHasClass,
|
|
64
|
+
text as sharedText,
|
|
65
|
+
visitElements as sharedVisitElements
|
|
66
|
+
} from "@riebeckite/diagram";
|
|
67
|
+
var element = sharedElement;
|
|
68
|
+
var text = sharedText;
|
|
69
|
+
var getTextContent = sharedGetTextContent;
|
|
70
|
+
var getStringProperty = sharedGetStringProperty;
|
|
71
|
+
var hasClass = sharedHasClass;
|
|
72
|
+
var visitElements = sharedVisitElements;
|
|
103
73
|
|
|
104
74
|
// src/parse.ts
|
|
105
75
|
var KEY_VALUE = /^([A-Za-z][\w-]*)\s*:\s*(.*)$/;
|
|
@@ -578,7 +548,9 @@ function map(options = {}) {
|
|
|
578
548
|
attribution: resolved.attribution,
|
|
579
549
|
minZoom: resolved.minZoom,
|
|
580
550
|
maxZoom: resolved.maxZoom
|
|
581
|
-
}
|
|
551
|
+
},
|
|
552
|
+
void 0,
|
|
553
|
+
"context"
|
|
582
554
|
)
|
|
583
555
|
]
|
|
584
556
|
});
|
package/dist/src/hast.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ElementNode, HastNode, ParentNode, TextNode } from "./types.js";
|
|
2
|
-
export declare
|
|
3
|
-
export declare
|
|
4
|
-
export declare
|
|
5
|
-
export declare
|
|
6
|
-
export declare
|
|
7
|
-
export declare
|
|
2
|
+
export declare const element: (tagName: string, properties?: Record<string, unknown>, children?: HastNode[]) => ElementNode;
|
|
3
|
+
export declare const text: (value: string) => TextNode;
|
|
4
|
+
export declare const getTextContent: (node: HastNode) => string;
|
|
5
|
+
export declare const getStringProperty: (node: ElementNode, key: string) => string | null;
|
|
6
|
+
export declare const hasClass: (node: ElementNode, className: string) => boolean;
|
|
7
|
+
export declare const visitElements: (node: HastNode, visitor: (node: ElementNode, parent?: ParentNode, index?: number) => void, parent?: ParentNode, index?: number) => void;
|
package/dist/src/init.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { MapClientOptions } from "./types.js";
|
|
2
|
+
type ClientContext = {
|
|
3
|
+
root?: ParentNode;
|
|
4
|
+
signal?: AbortSignal;
|
|
5
|
+
config?: MapClientOptions;
|
|
6
|
+
};
|
|
2
7
|
/**
|
|
3
8
|
* Upgrades every server-emitted `[data-rr-map="pending"]` figure to an
|
|
4
9
|
* interactive Leaflet map.
|
|
@@ -8,4 +13,5 @@ import type { MapClientOptions } from "./types.js";
|
|
|
8
13
|
* `data-rr-map-payload`, which means the page still renders its static
|
|
9
14
|
* fallback when JavaScript is disabled or the CDN is unreachable.
|
|
10
15
|
*/
|
|
11
|
-
export declare function initMap(
|
|
16
|
+
export declare function initMap(context?: ClientContext): Promise<undefined | (() => void)>;
|
|
17
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@riebeckite/plugin-map",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.32",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"./style.css": "./style.css"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@riebeckite/core": "0.0.
|
|
24
|
+
"@riebeckite/core": "0.0.32",
|
|
25
|
+
"@riebeckite/diagram": "0.0.32"
|
|
25
26
|
},
|
|
26
27
|
"publishConfig": {
|
|
27
28
|
"access": "public"
|