@vexpay/maps 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +144 -2
- package/dist/chunk-2U3TCV53.js +771 -0
- package/dist/chunk-2U3TCV53.js.map +1 -0
- package/dist/index.cjs +820 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +40 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.js +33 -0
- package/dist/index.js.map +1 -0
- package/dist/location-picker-DnqD4Pi3.d.cts +208 -0
- package/dist/location-picker-DnqD4Pi3.d.ts +208 -0
- package/dist/react.cjs +865 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +41 -0
- package/dist/react.d.ts +41 -0
- package/dist/react.js +81 -0
- package/dist/react.js.map +1 -0
- package/dist/vexmaps.global.js +59 -0
- package/dist/vexmaps.global.js.map +1 -0
- package/package.json +52 -4
package/dist/react.cjs
ADDED
|
@@ -0,0 +1,865 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/react.tsx
|
|
31
|
+
var react_exports = {};
|
|
32
|
+
__export(react_exports, {
|
|
33
|
+
AddressSearch: () => AddressSearch,
|
|
34
|
+
LocationPicker: () => LocationPicker,
|
|
35
|
+
VexMap: () => VexMap,
|
|
36
|
+
useVexMaps: () => useVexMaps
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(react_exports);
|
|
39
|
+
var React = __toESM(require("react"), 1);
|
|
40
|
+
|
|
41
|
+
// src/errors.ts
|
|
42
|
+
var VexMapsError = class extends Error {
|
|
43
|
+
constructor(code, message, status, retryAfter) {
|
|
44
|
+
super(message);
|
|
45
|
+
this.code = code;
|
|
46
|
+
this.status = status;
|
|
47
|
+
this.retryAfter = retryAfter;
|
|
48
|
+
this.name = "VexMapsError";
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// src/client.ts
|
|
53
|
+
var MAP_THEMES = ["light", "dark", "white", "grayscale", "purple"];
|
|
54
|
+
var DEFAULT_BASE_URL = "https://maps.chuventures.com";
|
|
55
|
+
var DEFAULT_TILES_URL = "https://tiles.chuventures.com";
|
|
56
|
+
var DEFAULT_STYLE_URL = `${DEFAULT_TILES_URL}/style.json`;
|
|
57
|
+
function styleUrlFor(theme = "light", tilesUrl = DEFAULT_TILES_URL) {
|
|
58
|
+
if (!MAP_THEMES.includes(theme)) throw new VexMapsError("error", `Unknown map theme "${theme}". Use one of: ${MAP_THEMES.join(", ")}.`);
|
|
59
|
+
return `${tilesUrl.replace(/\/+$/, "")}/styles/${theme}.json`;
|
|
60
|
+
}
|
|
61
|
+
var isBrowser = () => typeof window !== "undefined" && typeof document !== "undefined";
|
|
62
|
+
var MESSAGES = {
|
|
63
|
+
unavailable: "VEX Maps is not reachable right now.",
|
|
64
|
+
invalid_api_key: "The VEX Maps key is missing, wrong or revoked.",
|
|
65
|
+
origin_not_allowed: "This page\u2019s origin is not allowed for this publishable key.",
|
|
66
|
+
country_not_allowed: "This key may not use that country.",
|
|
67
|
+
secret_key_required: "This call needs a secret key (servers only).",
|
|
68
|
+
invalid_text: "Search text must be 3 to 120 characters.",
|
|
69
|
+
point_outside_country: "The point is outside the country.",
|
|
70
|
+
rate_limited: "Too many requests; try again shortly."
|
|
71
|
+
};
|
|
72
|
+
function createVexMaps(options) {
|
|
73
|
+
var _a, _b, _c, _d, _e;
|
|
74
|
+
const key = (_a = options == null ? void 0 : options.key) == null ? void 0 : _a.trim();
|
|
75
|
+
if (!key) throw new VexMapsError("invalid_api_key", "createVexMaps needs a key.");
|
|
76
|
+
if (isBrowser() && key.startsWith("vexmap_sk_")) {
|
|
77
|
+
throw new VexMapsError("secret_key_in_browser", "Only publishable keys (vexmap_pk_\u2026) may be used in browsers. Keep secret keys on your server.");
|
|
78
|
+
}
|
|
79
|
+
const base = ((_b = options.baseUrl) != null ? _b : DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
80
|
+
const timeoutMs = (_c = options.timeoutMs) != null ? _c : 2e3;
|
|
81
|
+
const doFetch = (_d = options.fetch) != null ? _d : ((...a) => fetch(...a));
|
|
82
|
+
async function call(method, path, body, outer) {
|
|
83
|
+
var _a2;
|
|
84
|
+
const ctl = new AbortController();
|
|
85
|
+
const timer = setTimeout(() => ctl.abort(), timeoutMs);
|
|
86
|
+
const onOuter = () => ctl.abort();
|
|
87
|
+
outer == null ? void 0 : outer.addEventListener("abort", onOuter);
|
|
88
|
+
let res;
|
|
89
|
+
try {
|
|
90
|
+
res = await doFetch(`${base}${path}`, {
|
|
91
|
+
method,
|
|
92
|
+
headers: { Authorization: `Bearer ${key}`, ...body !== void 0 && { "Content-Type": "application/json" } },
|
|
93
|
+
body: body === void 0 ? void 0 : JSON.stringify(body),
|
|
94
|
+
signal: ctl.signal
|
|
95
|
+
});
|
|
96
|
+
} catch (e) {
|
|
97
|
+
if (outer == null ? void 0 : outer.aborted) throw e;
|
|
98
|
+
throw new VexMapsError("unavailable", MESSAGES.unavailable);
|
|
99
|
+
} finally {
|
|
100
|
+
clearTimeout(timer);
|
|
101
|
+
outer == null ? void 0 : outer.removeEventListener("abort", onOuter);
|
|
102
|
+
}
|
|
103
|
+
if (res.status >= 500 || res.status === 0) throw new VexMapsError("unavailable", MESSAGES.unavailable, res.status);
|
|
104
|
+
let data = {};
|
|
105
|
+
try {
|
|
106
|
+
data = await res.json();
|
|
107
|
+
} catch {
|
|
108
|
+
if (!res.ok) throw new VexMapsError("unavailable", MESSAGES.unavailable, res.status);
|
|
109
|
+
}
|
|
110
|
+
if (!res.ok) {
|
|
111
|
+
const code = typeof data.error === "string" ? data.error : res.status === 429 ? "rate_limited" : "error";
|
|
112
|
+
const ra = Number(res.headers.get("retry-after"));
|
|
113
|
+
throw new VexMapsError(code, (_a2 = MESSAGES[code]) != null ? _a2 : typeof data.message === "string" ? data.message : `HTTP ${res.status}`, res.status, Number.isFinite(ra) && ra > 0 ? ra : void 0);
|
|
114
|
+
}
|
|
115
|
+
return data;
|
|
116
|
+
}
|
|
117
|
+
const countryOf = (c) => {
|
|
118
|
+
const v = c != null ? c : options.country;
|
|
119
|
+
if (v !== "ve" && v !== "co") throw new VexMapsError("invalid_country", 'Pass country "ve" or "co".');
|
|
120
|
+
return v;
|
|
121
|
+
};
|
|
122
|
+
return {
|
|
123
|
+
country: options.country,
|
|
124
|
+
styleUrl: (_e = options.styleUrl) != null ? _e : options.theme ? styleUrlFor(options.theme) : DEFAULT_STYLE_URL,
|
|
125
|
+
async search(text, o = {}) {
|
|
126
|
+
const t = (text != null ? text : "").trim();
|
|
127
|
+
if (t.length < 3 || t.length > 120) throw new VexMapsError("invalid_text", MESSAGES.invalid_text, 400);
|
|
128
|
+
return call("POST", "/v1/search", { country: countryOf(o.country), text: t, ...o.near && { near: o.near } }, o.signal);
|
|
129
|
+
},
|
|
130
|
+
async reverse(point, o = {}) {
|
|
131
|
+
if (!point || !Number.isFinite(point.lat) || !Number.isFinite(point.lng)) throw new VexMapsError("invalid_point", "A point needs numeric lat and lng.", 400);
|
|
132
|
+
return call("POST", "/v1/reverse", { country: countryOf(o.country), point: { lat: point.lat, lng: point.lng } }, o.signal);
|
|
133
|
+
},
|
|
134
|
+
async countries() {
|
|
135
|
+
return (await call("GET", "/v1/countries")).countries;
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// src/signature.ts
|
|
141
|
+
var OSM_COPYRIGHT = "https://www.openstreetmap.org/copyright";
|
|
142
|
+
var SIGNATURE_CSS = `:host{display:block!important;visibility:visible!important;opacity:1!important;filter:none!important;clip-path:none!important;transform:none!important;z-index:2147483000!important}
|
|
143
|
+
.s{all:initial;display:inline-block!important;font:11px/1.4 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif!important;color:#1f2933!important;
|
|
144
|
+
background:rgba(255,255,255,.88)!important;padding:2px 6px!important;border-radius:4px!important;visibility:visible!important;opacity:1!important}
|
|
145
|
+
a{color:inherit!important;text-decoration:underline!important;font:inherit!important}
|
|
146
|
+
b{font-weight:600!important}
|
|
147
|
+
.o,.o a{color:#5f6b7a!important;text-decoration:none!important}
|
|
148
|
+
.o a:hover{text-decoration:underline!important}`;
|
|
149
|
+
var HOST_STYLES = {
|
|
150
|
+
display: "block",
|
|
151
|
+
visibility: "visible",
|
|
152
|
+
opacity: "1",
|
|
153
|
+
"clip-path": "none",
|
|
154
|
+
transform: "none",
|
|
155
|
+
filter: "none",
|
|
156
|
+
"pointer-events": "auto",
|
|
157
|
+
"max-height": "none",
|
|
158
|
+
"max-width": "none",
|
|
159
|
+
overflow: "visible",
|
|
160
|
+
"font-size": "11px",
|
|
161
|
+
"line-height": "1.4",
|
|
162
|
+
"z-index": "2147483000",
|
|
163
|
+
"min-width": "0"
|
|
164
|
+
};
|
|
165
|
+
function pin(el, extra) {
|
|
166
|
+
for (const [k, v] of Object.entries({ ...HOST_STYLES, ...extra })) el.style.setProperty(k, v, "important");
|
|
167
|
+
el.hidden = false;
|
|
168
|
+
el.removeAttribute("aria-hidden");
|
|
169
|
+
}
|
|
170
|
+
function createSignature(kind, placement = {}) {
|
|
171
|
+
const el = document.createElement("vexmaps-signature");
|
|
172
|
+
el.setAttribute("data-vexmaps-signature", kind);
|
|
173
|
+
el.setAttribute("role", kind === "map" ? "contentinfo" : "note");
|
|
174
|
+
const root = el.attachShadow({ mode: "closed" });
|
|
175
|
+
const style = document.createElement("style");
|
|
176
|
+
style.textContent = SIGNATURE_CSS;
|
|
177
|
+
const span = document.createElement("span");
|
|
178
|
+
span.className = "s";
|
|
179
|
+
if (kind === "map") {
|
|
180
|
+
const b = document.createElement("b");
|
|
181
|
+
b.textContent = "VEX Maps";
|
|
182
|
+
const a = document.createElement("a");
|
|
183
|
+
a.href = OSM_COPYRIGHT;
|
|
184
|
+
a.target = "_blank";
|
|
185
|
+
a.rel = "noopener";
|
|
186
|
+
a.textContent = "\xA9 OpenStreetMap";
|
|
187
|
+
const o = document.createElement("span");
|
|
188
|
+
o.className = "o";
|
|
189
|
+
o.append(document.createTextNode(" \xB7 "), a);
|
|
190
|
+
span.append(b, o);
|
|
191
|
+
} else {
|
|
192
|
+
span.append(document.createTextNode("B\xFAsqueda por "));
|
|
193
|
+
const b = document.createElement("b");
|
|
194
|
+
b.textContent = "VEX Maps";
|
|
195
|
+
span.append(b);
|
|
196
|
+
}
|
|
197
|
+
root.append(style, span);
|
|
198
|
+
pin(el, placement);
|
|
199
|
+
const parentRef = { current: null };
|
|
200
|
+
const obs = new MutationObserver(() => pin(el, placement));
|
|
201
|
+
obs.observe(el, { attributes: true, attributeFilter: ["style", "hidden", "class", "aria-hidden"] });
|
|
202
|
+
const timer = setInterval(() => {
|
|
203
|
+
pin(el, placement);
|
|
204
|
+
if (parentRef.current && !el.isConnected && parentRef.current.isConnected) parentRef.current.appendChild(el);
|
|
205
|
+
}, 1e3);
|
|
206
|
+
queueMicrotask(() => {
|
|
207
|
+
parentRef.current = el.parentNode;
|
|
208
|
+
});
|
|
209
|
+
return { el, destroy: () => {
|
|
210
|
+
obs.disconnect();
|
|
211
|
+
clearInterval(timer);
|
|
212
|
+
el.remove();
|
|
213
|
+
} };
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// src/widgets/css.ts
|
|
217
|
+
var CSS = `
|
|
218
|
+
.vxm-search{position:relative;font:14px/1.4 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif}
|
|
219
|
+
.vxm-search input{box-sizing:border-box;width:100%;padding:10px 12px;border:1px solid #c7ccd1;border-radius:8px;font:inherit;background:#fff;color:#1f2933}
|
|
220
|
+
.vxm-search input:focus-visible{outline:2px solid #2b8a7a;outline-offset:1px}
|
|
221
|
+
.vxm-pop{position:absolute;left:0;right:0;top:calc(100% + 4px);z-index:1000;background:#fff;border:1px solid #d9dde1;border-radius:8px;box-shadow:0 8px 24px rgba(0,0,0,.12);overflow:hidden}
|
|
222
|
+
.vxm-pop[data-open="false"] .vxm-list,.vxm-pop[data-open="false"] .vxm-status{display:none}
|
|
223
|
+
.vxm-pop[data-open="false"]{position:static;border:0;box-shadow:none;background:transparent;margin-top:4px}
|
|
224
|
+
.vxm-list{list-style:none;margin:0;padding:4px 0;max-height:320px;overflow:auto}
|
|
225
|
+
.vxm-opt{padding:8px 12px;cursor:pointer;color:#1f2933}
|
|
226
|
+
.vxm-opt[aria-selected="true"],.vxm-opt:hover{background:#eef6f4}
|
|
227
|
+
.vxm-opt small{display:block;color:#5f6b76;font-size:12px}
|
|
228
|
+
.vxm-status{padding:8px 12px;color:#5f6b76;font-size:13px}
|
|
229
|
+
.vxm-foot{display:flex;justify-content:flex-end;padding:4px 8px}
|
|
230
|
+
.vxm-map{isolation:isolate;position:relative;width:100%;height:100%;min-height:240px;overflow:hidden;border-radius:8px;background:#e8ecef}
|
|
231
|
+
.vxm-map-canvas{position:absolute;inset:0}
|
|
232
|
+
.vxm-sig-map{position:absolute;left:6px;bottom:6px}
|
|
233
|
+
.vxm-picker{display:grid;gap:8px;height:100%;min-height:0;grid-template-rows:auto minmax(200px,1fr) auto auto auto;font:14px/1.4 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif}
|
|
234
|
+
/* The map takes whatever height the page gives the picker; 320px when the page sets none. */
|
|
235
|
+
.vxm-picker .vxm-map-host{min-height:200px}
|
|
236
|
+
.vxm-picker .vxm-map{height:100%;min-height:320px}
|
|
237
|
+
.vxm-picker[data-fill] .vxm-map{min-height:0}
|
|
238
|
+
.vxm-pin{--vxm-pin:#d1372b;position:absolute;left:50%;top:50%;width:0;height:0;pointer-events:none;z-index:2}
|
|
239
|
+
.vxm-pin>span{position:absolute;display:block}
|
|
240
|
+
.vxm-pin-body{left:-13px;top:-34px;width:26px;height:35px;color:var(--vxm-pin);transform-origin:50% 100%;transition:transform .18s cubic-bezier(.2,.8,.2,1);filter:drop-shadow(0 2px 2px rgba(0,0,0,.22))}
|
|
241
|
+
.vxm-pin-body svg{display:block}
|
|
242
|
+
.vxm-pin-shadow{left:-8px;top:-3px;width:16px;height:6px;border-radius:50%;background:radial-gradient(closest-side,rgba(0,0,0,.38),rgba(0,0,0,0));transition:transform .18s ease-out,opacity .18s ease-out}
|
|
243
|
+
.vxm-pin-dot{left:-3px;top:-3px;width:6px;height:6px;border-radius:50%;background:var(--vxm-pin);box-shadow:0 0 0 2px #fff,0 1px 3px rgba(0,0,0,.3);opacity:0;transform:scale(.4);transition:transform .15s ease-out,opacity .15s ease-out}
|
|
244
|
+
.vxm-pin-pulse{left:-9px;top:-9px;width:18px;height:18px;border-radius:50%;border:2px solid var(--vxm-pin);opacity:0}
|
|
245
|
+
.vxm-pin[data-state="lift"] .vxm-pin-body{transform:translateY(-12px) scale(1.05)}
|
|
246
|
+
.vxm-pin[data-state="lift"] .vxm-pin-shadow{transform:scale(.6);opacity:.55}
|
|
247
|
+
.vxm-pin[data-state="lift"] .vxm-pin-dot{opacity:1;transform:scale(1)}
|
|
248
|
+
.vxm-pin.vxm-drop .vxm-pin-body{animation:vxm-pin-drop .42s cubic-bezier(.3,1.4,.5,1)}
|
|
249
|
+
.vxm-pin.vxm-drop .vxm-pin-pulse{animation:vxm-pin-pulse .7s ease-out}
|
|
250
|
+
@keyframes vxm-pin-drop{0%{transform:translateY(-12px) scale(1.05)}55%{transform:translateY(0) scale(1.08,.9)}75%{transform:translateY(-2px) scale(.98,1.02)}100%{transform:none}}
|
|
251
|
+
@keyframes vxm-pin-pulse{0%{transform:scale(.4);opacity:.6}100%{transform:scale(2.6);opacity:0}}
|
|
252
|
+
.vxm-ctrl{position:absolute;top:10px;right:10px;z-index:3;display:flex;flex-direction:column;gap:8px}
|
|
253
|
+
.vxm-ctrl-group{display:flex;flex-direction:column;background:#fff;border-radius:8px;box-shadow:0 1px 4px rgba(0,0,0,.18),0 0 0 1px rgba(0,0,0,.06);overflow:hidden}
|
|
254
|
+
.vxm-ctrl-btn{appearance:none;display:grid;place-items:center;width:40px;height:40px;margin:0;padding:0;border:0;background:#fff;color:#1f2933;cursor:pointer;transition:background-color .12s ease-out}
|
|
255
|
+
.vxm-ctrl-btn+.vxm-ctrl-btn{border-top:1px solid #e3e6e9}
|
|
256
|
+
.vxm-ctrl-btn:hover{background:#f2f4f6}
|
|
257
|
+
.vxm-ctrl-btn:active{background:#e6e9ec}
|
|
258
|
+
.vxm-ctrl-btn:focus-visible{outline:2px solid #2b8a7a;outline-offset:-2px}
|
|
259
|
+
.vxm-ctrl-btn[disabled]{color:#a7b0b8;background:#fff;cursor:default}
|
|
260
|
+
.vxm-row{display:flex;flex-wrap:wrap;gap:8px;align-items:center}
|
|
261
|
+
.vxm-btn{appearance:none;border:1px solid #c7ccd1;background:#fff;color:#1f2933;border-radius:8px;padding:8px 12px;font:inherit;cursor:pointer;min-height:40px}
|
|
262
|
+
.vxm-btn-primary{background:#1f6f62;border-color:#1f6f62;color:#fff}
|
|
263
|
+
.vxm-btn:focus-visible{outline:2px solid #2b8a7a;outline-offset:2px}
|
|
264
|
+
.vxm-btn[disabled]{opacity:.6;cursor:default}
|
|
265
|
+
.vxm-addr{color:#1f2933;min-height:1.4em}
|
|
266
|
+
.vxm-hint{color:#5f6b76;font-size:13px}
|
|
267
|
+
@media (prefers-reduced-motion: reduce){.vxm-map *{transition:none!important;animation:none!important}.vxm-pin[data-state="lift"] .vxm-pin-body{transform:none}}
|
|
268
|
+
`;
|
|
269
|
+
var done = false;
|
|
270
|
+
function injectCss(doc = document) {
|
|
271
|
+
if (done && doc.getElementById("vexmaps-css")) return;
|
|
272
|
+
if (doc.getElementById("vexmaps-css")) {
|
|
273
|
+
done = true;
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
const s = doc.createElement("style");
|
|
277
|
+
s.id = "vexmaps-css";
|
|
278
|
+
s.textContent = CSS;
|
|
279
|
+
doc.head.appendChild(s);
|
|
280
|
+
done = true;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// src/widgets/emitter.ts
|
|
284
|
+
var Emitter = class {
|
|
285
|
+
constructor() {
|
|
286
|
+
this.l = {};
|
|
287
|
+
}
|
|
288
|
+
on(event, fn) {
|
|
289
|
+
var _a, _b;
|
|
290
|
+
((_b = (_a = this.l)[event]) != null ? _b : _a[event] = /* @__PURE__ */ new Set()).add(fn);
|
|
291
|
+
return () => {
|
|
292
|
+
var _a2;
|
|
293
|
+
return (_a2 = this.l[event]) == null ? void 0 : _a2.delete(fn);
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
emit(event, payload) {
|
|
297
|
+
var _a;
|
|
298
|
+
(_a = this.l[event]) == null ? void 0 : _a.forEach((fn) => {
|
|
299
|
+
try {
|
|
300
|
+
fn(payload);
|
|
301
|
+
} catch (e) {
|
|
302
|
+
setTimeout(() => {
|
|
303
|
+
throw e;
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
clear() {
|
|
309
|
+
this.l = {};
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
// src/widgets/strings.ts
|
|
314
|
+
var DEFAULT_STRINGS = {
|
|
315
|
+
placeholder: "Busca tu urbanizaci\xF3n, calle o edificio",
|
|
316
|
+
label: "Direcci\xF3n",
|
|
317
|
+
searching: "Buscando\u2026",
|
|
318
|
+
noResults: "Sin resultados. Prueba con otro nombre o mueve el mapa.",
|
|
319
|
+
unavailable: "La b\xFAsqueda no est\xE1 disponible ahora.",
|
|
320
|
+
useMyLocation: "Usar mi ubicaci\xF3n",
|
|
321
|
+
locating: "Buscando tu ubicaci\xF3n\u2026",
|
|
322
|
+
locationDenied: "No pudimos obtener tu ubicaci\xF3n.",
|
|
323
|
+
confirm: "Confirmar ubicaci\xF3n",
|
|
324
|
+
adjustPin: "Mueve el mapa para poner el pin en tu puerta.",
|
|
325
|
+
mapUnavailable: "El mapa no est\xE1 disponible ahora.",
|
|
326
|
+
zoomIn: "Acercar",
|
|
327
|
+
zoomOut: "Alejar",
|
|
328
|
+
recenter: "Volver al lugar elegido",
|
|
329
|
+
mapControls: "Controles del mapa"
|
|
330
|
+
};
|
|
331
|
+
function strings(over) {
|
|
332
|
+
const out = { ...DEFAULT_STRINGS };
|
|
333
|
+
if (over) {
|
|
334
|
+
for (const k of Object.keys(DEFAULT_STRINGS)) if (typeof over[k] === "string") out[k] = over[k];
|
|
335
|
+
}
|
|
336
|
+
return out;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// src/widgets/address-search.ts
|
|
340
|
+
var uid = 0;
|
|
341
|
+
function mountAddressSearch(container, opts) {
|
|
342
|
+
var _a;
|
|
343
|
+
injectCss(container.ownerDocument);
|
|
344
|
+
const s = strings(opts.strings);
|
|
345
|
+
const ev = new Emitter();
|
|
346
|
+
const id = `vxm-${++uid}`;
|
|
347
|
+
const root = document.createElement("div");
|
|
348
|
+
root.className = "vxm-search";
|
|
349
|
+
const label = document.createElement("label");
|
|
350
|
+
label.htmlFor = `${id}-input`;
|
|
351
|
+
label.textContent = s.label;
|
|
352
|
+
label.style.cssText = "position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap";
|
|
353
|
+
const input = document.createElement("input");
|
|
354
|
+
Object.assign(input, { id: `${id}-input`, type: "search", placeholder: s.placeholder, autocomplete: "off", spellcheck: false, value: (_a = opts.initialValue) != null ? _a : "" });
|
|
355
|
+
input.setAttribute("role", "combobox");
|
|
356
|
+
input.setAttribute("aria-autocomplete", "list");
|
|
357
|
+
input.setAttribute("aria-expanded", "false");
|
|
358
|
+
input.setAttribute("aria-controls", `${id}-list`);
|
|
359
|
+
const pop = document.createElement("div");
|
|
360
|
+
pop.className = "vxm-pop";
|
|
361
|
+
pop.dataset.open = "false";
|
|
362
|
+
const list = document.createElement("ul");
|
|
363
|
+
list.className = "vxm-list";
|
|
364
|
+
list.id = `${id}-list`;
|
|
365
|
+
list.setAttribute("role", "listbox");
|
|
366
|
+
list.setAttribute("aria-label", s.label);
|
|
367
|
+
const status = document.createElement("div");
|
|
368
|
+
status.className = "vxm-status";
|
|
369
|
+
status.setAttribute("role", "status");
|
|
370
|
+
status.setAttribute("aria-live", "polite");
|
|
371
|
+
const foot = document.createElement("div");
|
|
372
|
+
foot.className = "vxm-foot";
|
|
373
|
+
const sig = createSignature("search");
|
|
374
|
+
foot.appendChild(sig.el);
|
|
375
|
+
pop.append(list, status, foot);
|
|
376
|
+
root.append(label, input, pop);
|
|
377
|
+
container.appendChild(root);
|
|
378
|
+
let results = [];
|
|
379
|
+
let active = -1;
|
|
380
|
+
let timer;
|
|
381
|
+
let inflight = null;
|
|
382
|
+
let seq = 0;
|
|
383
|
+
const open = (o) => {
|
|
384
|
+
pop.dataset.open = String(o);
|
|
385
|
+
input.setAttribute("aria-expanded", String(o && results.length > 0));
|
|
386
|
+
};
|
|
387
|
+
const render = () => {
|
|
388
|
+
list.replaceChildren(...results.map((r, i) => {
|
|
389
|
+
const li = document.createElement("li");
|
|
390
|
+
li.className = "vxm-opt";
|
|
391
|
+
li.id = `${id}-opt-${i}`;
|
|
392
|
+
li.setAttribute("role", "option");
|
|
393
|
+
li.setAttribute("aria-selected", String(i === active));
|
|
394
|
+
li.textContent = r.label;
|
|
395
|
+
const sub = [r.neighbourhood, r.admin.level2, r.admin.level1].filter((x, j, a) => x && a.indexOf(x) === j && x !== r.label).join(", ");
|
|
396
|
+
if (sub) {
|
|
397
|
+
const small = document.createElement("small");
|
|
398
|
+
small.textContent = sub;
|
|
399
|
+
li.appendChild(small);
|
|
400
|
+
}
|
|
401
|
+
li.addEventListener("mousedown", (e) => {
|
|
402
|
+
e.preventDefault();
|
|
403
|
+
pick(i);
|
|
404
|
+
});
|
|
405
|
+
return li;
|
|
406
|
+
}));
|
|
407
|
+
if (active >= 0) input.setAttribute("aria-activedescendant", `${id}-opt-${active}`);
|
|
408
|
+
else input.removeAttribute("aria-activedescendant");
|
|
409
|
+
};
|
|
410
|
+
const pick = (i) => {
|
|
411
|
+
const r = results[i];
|
|
412
|
+
if (!r) return;
|
|
413
|
+
input.value = r.label;
|
|
414
|
+
open(false);
|
|
415
|
+
ev.emit("select", r);
|
|
416
|
+
};
|
|
417
|
+
const run = async () => {
|
|
418
|
+
const text = input.value.trim();
|
|
419
|
+
inflight == null ? void 0 : inflight.abort();
|
|
420
|
+
if (text.length < 3) {
|
|
421
|
+
results = [];
|
|
422
|
+
active = -1;
|
|
423
|
+
render();
|
|
424
|
+
status.textContent = "";
|
|
425
|
+
open(false);
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
const mine = ++seq;
|
|
429
|
+
inflight = new AbortController();
|
|
430
|
+
status.textContent = s.searching;
|
|
431
|
+
open(true);
|
|
432
|
+
try {
|
|
433
|
+
const near = typeof opts.near === "function" ? opts.near() : opts.near;
|
|
434
|
+
const res = await opts.client.search(text, { country: opts.country, near, signal: inflight.signal });
|
|
435
|
+
if (mine !== seq) return;
|
|
436
|
+
results = res.results;
|
|
437
|
+
active = -1;
|
|
438
|
+
render();
|
|
439
|
+
status.textContent = results.length ? "" : s.noResults;
|
|
440
|
+
open(true);
|
|
441
|
+
ev.emit("results", results);
|
|
442
|
+
} catch (e) {
|
|
443
|
+
if (mine !== seq || (e == null ? void 0 : e.name) === "AbortError") return;
|
|
444
|
+
results = [];
|
|
445
|
+
render();
|
|
446
|
+
status.textContent = s.unavailable;
|
|
447
|
+
open(true);
|
|
448
|
+
if (e instanceof VexMapsError && e.code === "unavailable") ev.emit("unavailable", e);
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
const onInput = () => {
|
|
452
|
+
var _a2;
|
|
453
|
+
clearTimeout(timer);
|
|
454
|
+
timer = setTimeout(run, (_a2 = opts.debounceMs) != null ? _a2 : 250);
|
|
455
|
+
};
|
|
456
|
+
const onKey = (e) => {
|
|
457
|
+
if (e.key === "ArrowDown" && results.length) {
|
|
458
|
+
e.preventDefault();
|
|
459
|
+
active = (active + 1) % results.length;
|
|
460
|
+
render();
|
|
461
|
+
open(true);
|
|
462
|
+
} else if (e.key === "ArrowUp" && results.length) {
|
|
463
|
+
e.preventDefault();
|
|
464
|
+
active = active <= 0 ? results.length - 1 : active - 1;
|
|
465
|
+
render();
|
|
466
|
+
} else if (e.key === "Enter" && active >= 0) {
|
|
467
|
+
e.preventDefault();
|
|
468
|
+
pick(active);
|
|
469
|
+
} else if (e.key === "Escape") {
|
|
470
|
+
open(false);
|
|
471
|
+
}
|
|
472
|
+
};
|
|
473
|
+
const onBlur = () => setTimeout(() => open(false), 150);
|
|
474
|
+
input.addEventListener("input", onInput);
|
|
475
|
+
input.addEventListener("keydown", onKey);
|
|
476
|
+
input.addEventListener("blur", onBlur);
|
|
477
|
+
return {
|
|
478
|
+
on: ev.on.bind(ev),
|
|
479
|
+
setValue(v) {
|
|
480
|
+
input.value = v;
|
|
481
|
+
},
|
|
482
|
+
focus() {
|
|
483
|
+
input.focus();
|
|
484
|
+
},
|
|
485
|
+
destroy() {
|
|
486
|
+
clearTimeout(timer);
|
|
487
|
+
inflight == null ? void 0 : inflight.abort();
|
|
488
|
+
ev.clear();
|
|
489
|
+
sig.destroy();
|
|
490
|
+
root.remove();
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
// src/widgets/map.ts
|
|
496
|
+
async function loadMapLibre(given) {
|
|
497
|
+
var _a;
|
|
498
|
+
if (given) return given;
|
|
499
|
+
const w = typeof window !== "undefined" ? window.maplibregl : void 0;
|
|
500
|
+
if (w) return w;
|
|
501
|
+
const mod = await import("maplibre-gl");
|
|
502
|
+
return (_a = mod.default) != null ? _a : mod;
|
|
503
|
+
}
|
|
504
|
+
function mountMap(container, opts = {}) {
|
|
505
|
+
injectCss(container.ownerDocument);
|
|
506
|
+
const ev = new Emitter();
|
|
507
|
+
const wrap = document.createElement("div");
|
|
508
|
+
wrap.className = "vxm-map";
|
|
509
|
+
wrap.style.setProperty("isolation", "isolate", "important");
|
|
510
|
+
const canvas = document.createElement("div");
|
|
511
|
+
canvas.className = "vxm-map-canvas";
|
|
512
|
+
const sig = createSignature("map", { position: "absolute", left: "6px", bottom: "6px", right: "auto", top: "auto" });
|
|
513
|
+
wrap.append(canvas, sig.el);
|
|
514
|
+
container.appendChild(wrap);
|
|
515
|
+
let map = null;
|
|
516
|
+
let destroyed = false;
|
|
517
|
+
let ro = null;
|
|
518
|
+
const fail = (msg) => {
|
|
519
|
+
if (!destroyed) ev.emit("unavailable", new VexMapsError("unavailable", msg));
|
|
520
|
+
};
|
|
521
|
+
void (async () => {
|
|
522
|
+
var _a, _b, _c;
|
|
523
|
+
let ml;
|
|
524
|
+
try {
|
|
525
|
+
ml = await loadMapLibre(opts.maplibregl);
|
|
526
|
+
} catch {
|
|
527
|
+
fail("maplibre-gl could not be loaded.");
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
if (destroyed) return;
|
|
531
|
+
try {
|
|
532
|
+
const c = (_a = opts.center) != null ? _a : { lat: 10.4917, lng: -66.8538 };
|
|
533
|
+
map = new ml.Map({
|
|
534
|
+
...opts.mapOptions,
|
|
535
|
+
container: canvas,
|
|
536
|
+
style: (_b = opts.styleUrl) != null ? _b : opts.theme ? styleUrlFor(opts.theme) : DEFAULT_STYLE_URL,
|
|
537
|
+
center: [c.lng, c.lat],
|
|
538
|
+
zoom: (_c = opts.zoom) != null ? _c : 14,
|
|
539
|
+
// The signature badge ("VEX Maps · © OpenStreetMap") is the attribution:
|
|
540
|
+
// no MapLibre control, no info button.
|
|
541
|
+
attributionControl: false
|
|
542
|
+
});
|
|
543
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
544
|
+
ro = new ResizeObserver(() => map == null ? void 0 : map.resize());
|
|
545
|
+
ro.observe(wrap);
|
|
546
|
+
}
|
|
547
|
+
let loaded = false;
|
|
548
|
+
map.on("load", () => {
|
|
549
|
+
loaded = true;
|
|
550
|
+
ev.emit("ready", map);
|
|
551
|
+
});
|
|
552
|
+
map.on("error", (e) => {
|
|
553
|
+
var _a2, _b2;
|
|
554
|
+
if (!loaded) fail(String((_b2 = (_a2 = e.error) == null ? void 0 : _a2.message) != null ? _b2 : "The map could not load."));
|
|
555
|
+
});
|
|
556
|
+
map.on("moveend", () => {
|
|
557
|
+
const p = map.getCenter();
|
|
558
|
+
ev.emit("moveend", { lat: p.lat, lng: p.lng });
|
|
559
|
+
});
|
|
560
|
+
} catch (e) {
|
|
561
|
+
fail(e.message || "The map could not start.");
|
|
562
|
+
}
|
|
563
|
+
})();
|
|
564
|
+
return {
|
|
565
|
+
on: ev.on.bind(ev),
|
|
566
|
+
get map() {
|
|
567
|
+
return map;
|
|
568
|
+
},
|
|
569
|
+
center() {
|
|
570
|
+
if (!map) return null;
|
|
571
|
+
const p = map.getCenter();
|
|
572
|
+
return { lat: p.lat, lng: p.lng };
|
|
573
|
+
},
|
|
574
|
+
flyTo(p, zoom) {
|
|
575
|
+
map == null ? void 0 : map.jumpTo({ center: [p.lng, p.lat], zoom: zoom != null ? zoom : Math.max(map.getZoom(), 16) });
|
|
576
|
+
},
|
|
577
|
+
destroy() {
|
|
578
|
+
destroyed = true;
|
|
579
|
+
ro == null ? void 0 : ro.disconnect();
|
|
580
|
+
ev.clear();
|
|
581
|
+
sig.destroy();
|
|
582
|
+
map == null ? void 0 : map.remove();
|
|
583
|
+
wrap.remove();
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
// src/widgets/location-picker.ts
|
|
589
|
+
var PIN_HTML = '<span class="vxm-pin-shadow"></span><span class="vxm-pin-pulse"></span><span class="vxm-pin-dot"></span><span class="vxm-pin-body"><svg viewBox="0 0 34 46" width="26" height="35" aria-hidden="true" focusable="false"><path d="M17 1C8.2 1 1 8 1 16.6c0 11.6 14.2 26.5 15.1 27.5a1.2 1.2 0 0 0 1.8 0C18.8 43.1 33 28.2 33 16.6 33 8 25.8 1 17 1z" fill="currentColor" stroke="rgba(0,0,0,.2)" stroke-width="1"/><path d="M17 3C9.4 3 3 9 3 16.4c0 3 .9 6.1 2.4 9.1C6 15 11 7.5 20 4.2 19 3.4 18 3 17 3z" fill="#fff" opacity=".22"/><circle cx="17" cy="16.5" r="7" fill="#fff"/><circle cx="17" cy="16.5" r="3.2" fill="currentColor"/></svg></span>';
|
|
590
|
+
function mountLocationPicker(container, opts) {
|
|
591
|
+
var _a, _b, _c, _d;
|
|
592
|
+
injectCss(container.ownerDocument);
|
|
593
|
+
const s = strings(opts.strings);
|
|
594
|
+
const ev = new Emitter();
|
|
595
|
+
const root = document.createElement("div");
|
|
596
|
+
root.className = "vxm-picker";
|
|
597
|
+
if (container.clientHeight > 0) root.setAttribute("data-fill", "");
|
|
598
|
+
const searchHost = document.createElement("div");
|
|
599
|
+
const mapHost = document.createElement("div");
|
|
600
|
+
mapHost.className = "vxm-map-host";
|
|
601
|
+
mapHost.style.position = "relative";
|
|
602
|
+
const pin2 = document.createElement("div");
|
|
603
|
+
pin2.className = "vxm-pin";
|
|
604
|
+
pin2.setAttribute("data-state", "rest");
|
|
605
|
+
pin2.innerHTML = PIN_HTML;
|
|
606
|
+
if (opts.pinColor) pin2.style.setProperty("--vxm-pin", opts.pinColor);
|
|
607
|
+
const hint = document.createElement("p");
|
|
608
|
+
hint.className = "vxm-hint";
|
|
609
|
+
hint.textContent = s.adjustPin;
|
|
610
|
+
const addr = document.createElement("div");
|
|
611
|
+
addr.className = "vxm-addr";
|
|
612
|
+
addr.setAttribute("aria-live", "polite");
|
|
613
|
+
const row = document.createElement("div");
|
|
614
|
+
row.className = "vxm-row";
|
|
615
|
+
const locate = document.createElement("button");
|
|
616
|
+
locate.type = "button";
|
|
617
|
+
locate.className = "vxm-btn";
|
|
618
|
+
locate.textContent = s.useMyLocation;
|
|
619
|
+
const confirm = document.createElement("button");
|
|
620
|
+
confirm.type = "button";
|
|
621
|
+
confirm.className = "vxm-btn vxm-btn-primary";
|
|
622
|
+
confirm.textContent = s.confirm;
|
|
623
|
+
row.append(locate, confirm);
|
|
624
|
+
root.append(searchHost, mapHost, hint, addr, row);
|
|
625
|
+
container.appendChild(root);
|
|
626
|
+
let unavailable = false;
|
|
627
|
+
const down = (e) => {
|
|
628
|
+
if (!unavailable) {
|
|
629
|
+
unavailable = true;
|
|
630
|
+
ev.emit("unavailable", e);
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
let picked = null;
|
|
634
|
+
let last = null;
|
|
635
|
+
let revSeq = 0;
|
|
636
|
+
let revTimer;
|
|
637
|
+
const search = mountAddressSearch(searchHost, { client: opts.client, country: opts.country, strings: opts.strings, near: () => {
|
|
638
|
+
var _a2;
|
|
639
|
+
return (_a2 = map.center()) != null ? _a2 : opts.center;
|
|
640
|
+
} });
|
|
641
|
+
search.on("unavailable", down);
|
|
642
|
+
const map = mountMap(mapHost, {
|
|
643
|
+
center: opts.center,
|
|
644
|
+
zoom: (_a = opts.zoom) != null ? _a : opts.center ? 17 : 12,
|
|
645
|
+
styleUrl: opts.theme ? styleUrlFor(opts.theme) : opts.client.styleUrl,
|
|
646
|
+
maplibregl: opts.maplibregl,
|
|
647
|
+
// The pin is fixed at the centre, so zoom must keep the centre still: wheel, trackpad and pinch
|
|
648
|
+
// zoom around the centre (set at creation: MapLibre ignores enable() on a handler that is
|
|
649
|
+
// already on), and double-click is replaced below so it can't zoom toward the pointer.
|
|
650
|
+
mapOptions: { scrollZoom: { around: "center" }, touchZoomRotate: { around: "center" }, doubleClickZoom: false }
|
|
651
|
+
});
|
|
652
|
+
(_b = mapHost.querySelector(".vxm-map")) == null ? void 0 : _b.appendChild(pin2);
|
|
653
|
+
const icon = (d) => `<svg viewBox="0 0 20 20" width="18" height="18" aria-hidden="true" focusable="false" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round">${d}</svg>`;
|
|
654
|
+
const ctrlButton = (cls, label, svg) => {
|
|
655
|
+
const b = document.createElement("button");
|
|
656
|
+
b.type = "button";
|
|
657
|
+
b.className = `vxm-ctrl-btn ${cls}`;
|
|
658
|
+
b.disabled = true;
|
|
659
|
+
b.setAttribute("aria-label", label);
|
|
660
|
+
b.title = label;
|
|
661
|
+
b.innerHTML = svg;
|
|
662
|
+
return b;
|
|
663
|
+
};
|
|
664
|
+
const zoomInBtn = ctrlButton("vxm-zoom-in", s.zoomIn, icon('<path d="M10 4v12M4 10h12"/>'));
|
|
665
|
+
const zoomOutBtn = ctrlButton("vxm-zoom-out", s.zoomOut, icon('<path d="M4 10h12"/>'));
|
|
666
|
+
const homeBtn = ctrlButton("vxm-recenter", s.recenter, icon('<circle cx="10" cy="10" r="4.5"/><path d="M10 1.5v3M10 15.5v3M1.5 10h3M15.5 10h3"/>'));
|
|
667
|
+
const ctrl = document.createElement("div");
|
|
668
|
+
ctrl.className = "vxm-ctrl";
|
|
669
|
+
ctrl.setAttribute("role", "group");
|
|
670
|
+
ctrl.setAttribute("aria-label", s.mapControls);
|
|
671
|
+
const zoomGroup = document.createElement("div");
|
|
672
|
+
zoomGroup.className = "vxm-ctrl-group";
|
|
673
|
+
zoomGroup.append(zoomInBtn, zoomOutBtn);
|
|
674
|
+
const homeGroup = document.createElement("div");
|
|
675
|
+
homeGroup.className = "vxm-ctrl-group";
|
|
676
|
+
homeGroup.append(homeBtn);
|
|
677
|
+
ctrl.append(zoomGroup, homeGroup);
|
|
678
|
+
(_c = mapHost.querySelector(".vxm-map")) == null ? void 0 : _c.appendChild(ctrl);
|
|
679
|
+
let home = opts.center ? { point: opts.center, zoom: (_d = opts.zoom) != null ? _d : 17 } : null;
|
|
680
|
+
const goTo = (p, zoom) => {
|
|
681
|
+
home = { point: p, zoom };
|
|
682
|
+
map.flyTo(p, zoom);
|
|
683
|
+
};
|
|
684
|
+
map.on("unavailable", (e) => {
|
|
685
|
+
addr.textContent = s.mapUnavailable;
|
|
686
|
+
down(e);
|
|
687
|
+
});
|
|
688
|
+
map.on("ready", (m) => {
|
|
689
|
+
m.touchZoomRotate.disableRotation();
|
|
690
|
+
if (!home) {
|
|
691
|
+
const c = m.getCenter();
|
|
692
|
+
home = { point: { lat: c.lat, lng: c.lng }, zoom: m.getZoom() };
|
|
693
|
+
}
|
|
694
|
+
const zoomBy = (d) => m.easeTo({ zoom: Math.min(m.getMaxZoom(), Math.max(m.getMinZoom(), m.getZoom() + d)), center: m.getCenter() });
|
|
695
|
+
zoomInBtn.addEventListener("click", () => zoomBy(1));
|
|
696
|
+
zoomOutBtn.addEventListener("click", () => zoomBy(-1));
|
|
697
|
+
homeBtn.addEventListener("click", () => {
|
|
698
|
+
if (home) m.easeTo({ center: [home.point.lng, home.point.lat], zoom: home.zoom });
|
|
699
|
+
});
|
|
700
|
+
zoomInBtn.disabled = zoomOutBtn.disabled = homeBtn.disabled = false;
|
|
701
|
+
m.on("movestart", () => {
|
|
702
|
+
pin2.classList.remove("vxm-drop");
|
|
703
|
+
pin2.setAttribute("data-state", "lift");
|
|
704
|
+
});
|
|
705
|
+
m.on("moveend", () => {
|
|
706
|
+
pin2.setAttribute("data-state", "rest");
|
|
707
|
+
pin2.classList.remove("vxm-drop");
|
|
708
|
+
void pin2.offsetWidth;
|
|
709
|
+
pin2.classList.add("vxm-drop");
|
|
710
|
+
});
|
|
711
|
+
m.on("dblclick", (e) => {
|
|
712
|
+
e.preventDefault();
|
|
713
|
+
setTimeout(() => m.easeTo({ zoom: m.getZoom() + 1, center: m.getCenter() }), 0);
|
|
714
|
+
});
|
|
715
|
+
});
|
|
716
|
+
const describe = (r) => {
|
|
717
|
+
var _a2, _b2, _c2;
|
|
718
|
+
return [(_a2 = r.street) == null ? void 0 : _a2.label, (_b2 = r.place) == null ? void 0 : _b2.label, (_c2 = r.neighbourhood) == null ? void 0 : _c2.label, r.admin.level2].filter((x, i, a) => x && a.indexOf(x) === i).join(", ");
|
|
719
|
+
};
|
|
720
|
+
const reverseAt = async (p) => {
|
|
721
|
+
const mine = ++revSeq;
|
|
722
|
+
try {
|
|
723
|
+
const r = await opts.client.reverse(p, { country: opts.country });
|
|
724
|
+
if (mine !== revSeq) return null;
|
|
725
|
+
last = { point: p, reverse: r };
|
|
726
|
+
addr.textContent = describe(r);
|
|
727
|
+
return r;
|
|
728
|
+
} catch (e) {
|
|
729
|
+
if (mine === revSeq) {
|
|
730
|
+
last = { point: p, reverse: null };
|
|
731
|
+
addr.textContent = "";
|
|
732
|
+
}
|
|
733
|
+
if (e instanceof VexMapsError && e.code === "unavailable") down(e);
|
|
734
|
+
return null;
|
|
735
|
+
}
|
|
736
|
+
};
|
|
737
|
+
map.on("moveend", (p) => {
|
|
738
|
+
ev.emit("move", p);
|
|
739
|
+
if (opts.liveReverse === false) return;
|
|
740
|
+
clearTimeout(revTimer);
|
|
741
|
+
revTimer = setTimeout(() => void reverseAt(p), 300);
|
|
742
|
+
});
|
|
743
|
+
search.on("select", (r) => {
|
|
744
|
+
picked = r;
|
|
745
|
+
goTo(r.point, r.precision === "AREA" ? 16 : 18);
|
|
746
|
+
});
|
|
747
|
+
locate.addEventListener("click", () => {
|
|
748
|
+
if (!navigator.geolocation) {
|
|
749
|
+
addr.textContent = s.locationDenied;
|
|
750
|
+
return;
|
|
751
|
+
}
|
|
752
|
+
locate.disabled = true;
|
|
753
|
+
locate.textContent = s.locating;
|
|
754
|
+
navigator.geolocation.getCurrentPosition(
|
|
755
|
+
(pos) => {
|
|
756
|
+
locate.disabled = false;
|
|
757
|
+
locate.textContent = s.useMyLocation;
|
|
758
|
+
picked = null;
|
|
759
|
+
goTo({ lat: pos.coords.latitude, lng: pos.coords.longitude }, 18);
|
|
760
|
+
},
|
|
761
|
+
() => {
|
|
762
|
+
locate.disabled = false;
|
|
763
|
+
locate.textContent = s.useMyLocation;
|
|
764
|
+
addr.textContent = s.locationDenied;
|
|
765
|
+
},
|
|
766
|
+
{ enableHighAccuracy: true, timeout: 1e4, maximumAge: 6e4 }
|
|
767
|
+
);
|
|
768
|
+
});
|
|
769
|
+
confirm.addEventListener("click", async () => {
|
|
770
|
+
var _a2, _b2;
|
|
771
|
+
const p = (_b2 = (_a2 = map.center()) != null ? _a2 : picked == null ? void 0 : picked.point) != null ? _b2 : opts.center;
|
|
772
|
+
if (!p) return;
|
|
773
|
+
confirm.disabled = true;
|
|
774
|
+
const same = last && Math.abs(last.point.lat - p.lat) < 1e-7 && Math.abs(last.point.lng - p.lng) < 1e-7;
|
|
775
|
+
const reverse = same ? last.reverse : await reverseAt(p);
|
|
776
|
+
confirm.disabled = false;
|
|
777
|
+
ev.emit("confirm", { point: { lat: p.lat, lng: p.lng }, reverse, picked });
|
|
778
|
+
});
|
|
779
|
+
return {
|
|
780
|
+
on: ev.on.bind(ev),
|
|
781
|
+
point: () => map.center(),
|
|
782
|
+
destroy() {
|
|
783
|
+
clearTimeout(revTimer);
|
|
784
|
+
ev.clear();
|
|
785
|
+
search.destroy();
|
|
786
|
+
map.destroy();
|
|
787
|
+
root.remove();
|
|
788
|
+
}
|
|
789
|
+
};
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
// src/react.tsx
|
|
793
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
794
|
+
function useVexMaps(options) {
|
|
795
|
+
const { key, country, baseUrl, styleUrl, timeoutMs, theme } = options;
|
|
796
|
+
return React.useMemo(
|
|
797
|
+
() => createVexMaps({ key, country, baseUrl, styleUrl, timeoutMs, theme, fetch: options.fetch }),
|
|
798
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
799
|
+
[key, country, baseUrl, styleUrl, timeoutMs, theme]
|
|
800
|
+
);
|
|
801
|
+
}
|
|
802
|
+
function useLatest(v) {
|
|
803
|
+
const r = React.useRef(v);
|
|
804
|
+
r.current = v;
|
|
805
|
+
return r;
|
|
806
|
+
}
|
|
807
|
+
function VexMap({ client, theme, center, zoom, onReady, onUnavailable, maplibregl, className, style }) {
|
|
808
|
+
const ref = React.useRef(null);
|
|
809
|
+
const cb = useLatest({ onReady, onUnavailable });
|
|
810
|
+
React.useEffect(() => {
|
|
811
|
+
const w = mountMap(ref.current, { center, zoom, theme, styleUrl: theme ? void 0 : client == null ? void 0 : client.styleUrl, maplibregl });
|
|
812
|
+
w.on("ready", (m) => {
|
|
813
|
+
var _a, _b;
|
|
814
|
+
return (_b = (_a = cb.current).onReady) == null ? void 0 : _b.call(_a, m);
|
|
815
|
+
});
|
|
816
|
+
w.on("unavailable", (e) => {
|
|
817
|
+
var _a, _b;
|
|
818
|
+
return (_b = (_a = cb.current).onUnavailable) == null ? void 0 : _b.call(_a, e);
|
|
819
|
+
});
|
|
820
|
+
return () => w.destroy();
|
|
821
|
+
}, [client == null ? void 0 : client.styleUrl, theme]);
|
|
822
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref, className, style: { height: 320, ...style } });
|
|
823
|
+
}
|
|
824
|
+
function AddressSearch({ client, country, near, strings: strings2, onSelect, onUnavailable, className, style }) {
|
|
825
|
+
const ref = React.useRef(null);
|
|
826
|
+
const cb = useLatest({ onSelect, onUnavailable, near });
|
|
827
|
+
React.useEffect(() => {
|
|
828
|
+
const w = mountAddressSearch(ref.current, { client, country, strings: strings2, near: () => cb.current.near });
|
|
829
|
+
w.on("select", (r) => {
|
|
830
|
+
var _a, _b;
|
|
831
|
+
return (_b = (_a = cb.current).onSelect) == null ? void 0 : _b.call(_a, r);
|
|
832
|
+
});
|
|
833
|
+
w.on("unavailable", (e) => {
|
|
834
|
+
var _a, _b;
|
|
835
|
+
return (_b = (_a = cb.current).onUnavailable) == null ? void 0 : _b.call(_a, e);
|
|
836
|
+
});
|
|
837
|
+
return () => w.destroy();
|
|
838
|
+
}, [client, country, JSON.stringify(strings2 != null ? strings2 : {})]);
|
|
839
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref, className, style });
|
|
840
|
+
}
|
|
841
|
+
function LocationPicker({ client, country, theme, center, zoom, strings: strings2, maplibregl, pinColor, onConfirm, onUnavailable, className, style }) {
|
|
842
|
+
const ref = React.useRef(null);
|
|
843
|
+
const cb = useLatest({ onConfirm, onUnavailable });
|
|
844
|
+
React.useEffect(() => {
|
|
845
|
+
const w = mountLocationPicker(ref.current, { client, country, theme, center, zoom, strings: strings2, maplibregl, pinColor });
|
|
846
|
+
w.on("confirm", (r) => {
|
|
847
|
+
var _a, _b;
|
|
848
|
+
return (_b = (_a = cb.current).onConfirm) == null ? void 0 : _b.call(_a, r);
|
|
849
|
+
});
|
|
850
|
+
w.on("unavailable", (e) => {
|
|
851
|
+
var _a, _b;
|
|
852
|
+
return (_b = (_a = cb.current).onUnavailable) == null ? void 0 : _b.call(_a, e);
|
|
853
|
+
});
|
|
854
|
+
return () => w.destroy();
|
|
855
|
+
}, [client, country, theme, pinColor, JSON.stringify(strings2 != null ? strings2 : {})]);
|
|
856
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref, className, style });
|
|
857
|
+
}
|
|
858
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
859
|
+
0 && (module.exports = {
|
|
860
|
+
AddressSearch,
|
|
861
|
+
LocationPicker,
|
|
862
|
+
VexMap,
|
|
863
|
+
useVexMaps
|
|
864
|
+
});
|
|
865
|
+
//# sourceMappingURL=react.cjs.map
|