@mapvx/web-js 1.1.0 → 1.2.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/dist/cjs/domain/models/circle.js +218 -0
- package/dist/cjs/domain/models/circle.js.map +1 -0
- package/dist/cjs/domain/models/marker.js +6 -0
- package/dist/cjs/domain/models/marker.js.map +1 -1
- package/dist/cjs/index.js +10 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/logger/logger.js +15 -8
- package/dist/cjs/logger/logger.js.map +1 -1
- package/dist/cjs/logger/rollbar.js +16 -8
- package/dist/cjs/logger/rollbar.js.map +1 -1
- package/dist/cjs/map/map.js +274 -3
- package/dist/cjs/map/map.js.map +1 -1
- package/dist/cjs/utils/preconnect.js +131 -0
- package/dist/cjs/utils/preconnect.js.map +1 -0
- package/dist/es/domain/models/circle.d.ts +183 -0
- package/dist/es/domain/models/circle.d.ts.map +1 -0
- package/dist/es/domain/models/circle.js +212 -0
- package/dist/es/domain/models/circle.js.map +1 -0
- package/dist/es/domain/models/marker.d.ts +8 -0
- package/dist/es/domain/models/marker.d.ts.map +1 -1
- package/dist/es/domain/models/marker.js +6 -0
- package/dist/es/domain/models/marker.js.map +1 -1
- package/dist/es/index.d.ts +3 -0
- package/dist/es/index.d.ts.map +1 -1
- package/dist/es/index.js +3 -0
- package/dist/es/index.js.map +1 -1
- package/dist/es/logger/logger.d.ts.map +1 -1
- package/dist/es/logger/logger.js +15 -8
- package/dist/es/logger/logger.js.map +1 -1
- package/dist/es/logger/rollbar.d.ts.map +1 -1
- package/dist/es/logger/rollbar.js +16 -8
- package/dist/es/logger/rollbar.js.map +1 -1
- package/dist/es/map/map.d.ts +196 -0
- package/dist/es/map/map.d.ts.map +1 -1
- package/dist/es/map/map.js +274 -3
- package/dist/es/map/map.js.map +1 -1
- package/dist/es/utils/preconnect.d.ts +45 -0
- package/dist/es/utils/preconnect.d.ts.map +1 -0
- package/dist/es/utils/preconnect.js +127 -0
- package/dist/es/utils/preconnect.js.map +1 -0
- package/dist/umd/index.js +735 -36
- package/dist/umd/index.js.map +1 -1
- package/package.json +5 -5
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hostnames that MapVX maps typically need to talk to during the first
|
|
3
|
+
* paint: vector tiles, sprite, glyphs and indoor tile sources. Exposed so
|
|
4
|
+
* that consumer apps can call `injectPreconnects(MAPVX_DEFAULT_PRECONNECT_HOSTS)`
|
|
5
|
+
* without having to maintain the list themselves.
|
|
6
|
+
*
|
|
7
|
+
* @group Utils
|
|
8
|
+
*/
|
|
9
|
+
export const MAPVX_DEFAULT_PRECONNECT_HOSTS = [
|
|
10
|
+
"https://tiles.mapvx.com",
|
|
11
|
+
"https://api.maptiler.com",
|
|
12
|
+
"https://indoorequals.mapvx.com",
|
|
13
|
+
];
|
|
14
|
+
/**
|
|
15
|
+
* Injects `<link rel="preconnect">` (and a `<link rel="dns-prefetch">` fallback)
|
|
16
|
+
* tags into `document.head` for the given origins, so the browser starts the
|
|
17
|
+
* DNS + TLS handshake before MapLibre actually requests sprite/glyph/tile
|
|
18
|
+
* resources.
|
|
19
|
+
*
|
|
20
|
+
* Call this as early as possible — ideally before {@link initializeSDK} — to
|
|
21
|
+
* maximize the savings. In real captures this shaves ~150-300 ms off the
|
|
22
|
+
* first-paint cascade.
|
|
23
|
+
*
|
|
24
|
+
* Idempotent: hosts that already have a `<link rel="preconnect" crossorigin>`
|
|
25
|
+
* are skipped. If an existing `preconnect` link is missing `crossorigin`, it
|
|
26
|
+
* is upgraded in place (added `crossorigin="anonymous"`) — without that
|
|
27
|
+
* attribute the warmed socket can't be reused for the CORS tile/font/sprite
|
|
28
|
+
* fetches MapLibre performs, so leaving the existing link untouched would
|
|
29
|
+
* silently defeat the optimization. Existing `crossorigin="use-credentials"`
|
|
30
|
+
* is respected and never overwritten.
|
|
31
|
+
*
|
|
32
|
+
* @param hosts - Origin URLs (`"https://tiles.mapvx.com"`) or bare hostnames
|
|
33
|
+
* (`"tiles.mapvx.com"`, normalized to `https://`). Invalid entries are
|
|
34
|
+
* silently ignored.
|
|
35
|
+
* @returns The origins where the helper made a change — either a new link was
|
|
36
|
+
* appended, or an existing one was upgraded with `crossorigin="anonymous"`.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```ts
|
|
40
|
+
* import { initializeSDK, injectPreconnects, MAPVX_DEFAULT_PRECONNECT_HOSTS } from "@mapvx/web-js"
|
|
41
|
+
*
|
|
42
|
+
* injectPreconnects(MAPVX_DEFAULT_PRECONNECT_HOSTS)
|
|
43
|
+
* const sdk = initializeSDK(apiKey)
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @group Utils
|
|
47
|
+
*/
|
|
48
|
+
export function injectPreconnects(hosts) {
|
|
49
|
+
if (typeof document === "undefined" || !document.head)
|
|
50
|
+
return [];
|
|
51
|
+
if (!Array.isArray(hosts) || hosts.length === 0)
|
|
52
|
+
return [];
|
|
53
|
+
const injected = [];
|
|
54
|
+
for (const raw of hosts) {
|
|
55
|
+
if (typeof raw !== "string" || raw.length === 0)
|
|
56
|
+
continue;
|
|
57
|
+
const origin = normalizeOrigin(raw);
|
|
58
|
+
if (origin === null)
|
|
59
|
+
continue;
|
|
60
|
+
// Check what's already in <head>. We may need to UPGRADE an existing
|
|
61
|
+
// preconnect — server-rendered or hand-authored hints frequently omit
|
|
62
|
+
// `crossorigin`, and a warmed socket without it cannot be reused for
|
|
63
|
+
// the CORS tile/font/sprite fetches that MapLibre performs. Without
|
|
64
|
+
// this branch the optimization would silently no-op when the page
|
|
65
|
+
// already had a partial hint.
|
|
66
|
+
const existingPreconnect = findLinkForOrigin("preconnect", origin);
|
|
67
|
+
let preconnectChanged = false;
|
|
68
|
+
if (existingPreconnect) {
|
|
69
|
+
if (!existingPreconnect.hasAttribute("crossorigin")) {
|
|
70
|
+
existingPreconnect.crossOrigin = "anonymous";
|
|
71
|
+
preconnectChanged = true;
|
|
72
|
+
}
|
|
73
|
+
// If the existing link already has any `crossorigin` value
|
|
74
|
+
// (including `use-credentials`), respect the author's intent and
|
|
75
|
+
// leave it alone.
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
const preconnect = document.createElement("link");
|
|
79
|
+
preconnect.rel = "preconnect";
|
|
80
|
+
preconnect.href = origin;
|
|
81
|
+
preconnect.crossOrigin = "anonymous";
|
|
82
|
+
document.head.appendChild(preconnect);
|
|
83
|
+
preconnectChanged = true;
|
|
84
|
+
}
|
|
85
|
+
// dns-prefetch is a fallback for older browsers that ignore preconnect.
|
|
86
|
+
if (!findLinkForOrigin("dns-prefetch", origin)) {
|
|
87
|
+
const dnsPrefetch = document.createElement("link");
|
|
88
|
+
dnsPrefetch.rel = "dns-prefetch";
|
|
89
|
+
dnsPrefetch.href = origin;
|
|
90
|
+
document.head.appendChild(dnsPrefetch);
|
|
91
|
+
}
|
|
92
|
+
if (preconnectChanged)
|
|
93
|
+
injected.push(origin);
|
|
94
|
+
}
|
|
95
|
+
return injected;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Returns the first `<link rel="${rel}">` in `<head>` whose resolved origin
|
|
99
|
+
* matches `origin`, or null. We compare canonical URL origins instead of
|
|
100
|
+
* the raw `href` attribute text — the same origin can be written as
|
|
101
|
+
* `https://tiles.mapvx.com` or `https://tiles.mapvx.com/`, and a strict
|
|
102
|
+
* attribute selector would miss the second form and inject a duplicate.
|
|
103
|
+
*/
|
|
104
|
+
function findLinkForOrigin(rel, origin) {
|
|
105
|
+
const links = document.head.querySelectorAll(`link[rel="${rel}"]`);
|
|
106
|
+
for (let i = 0; i < links.length; i++) {
|
|
107
|
+
const link = links[i];
|
|
108
|
+
try {
|
|
109
|
+
if (new URL(link.href).origin === origin)
|
|
110
|
+
return link;
|
|
111
|
+
}
|
|
112
|
+
catch (_a) {
|
|
113
|
+
// Malformed href — skip and keep scanning.
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
function normalizeOrigin(raw) {
|
|
119
|
+
try {
|
|
120
|
+
const candidate = /^https?:\/\//i.test(raw) ? raw : `https://${raw}`;
|
|
121
|
+
return new URL(candidate).origin;
|
|
122
|
+
}
|
|
123
|
+
catch (_a) {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=preconnect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"preconnect.js","sourceRoot":"","sources":["../../../src/utils/preconnect.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAsB;IAC/D,yBAAyB;IACzB,0BAA0B;IAC1B,gCAAgC;CACjC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,UAAU,iBAAiB,CAAC,KAAwB;IACxD,IAAI,OAAO,QAAQ,KAAK,WAAW,IAAI,CAAC,QAAQ,CAAC,IAAI;QAAE,OAAO,EAAE,CAAA;IAChE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAA;IAE1D,MAAM,QAAQ,GAAa,EAAE,CAAA;IAC7B,KAAK,MAAM,GAAG,IAAI,KAAK,EAAE;QACvB,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC;YAAE,SAAQ;QACzD,MAAM,MAAM,GAAG,eAAe,CAAC,GAAG,CAAC,CAAA;QACnC,IAAI,MAAM,KAAK,IAAI;YAAE,SAAQ;QAE7B,qEAAqE;QACrE,sEAAsE;QACtE,qEAAqE;QACrE,oEAAoE;QACpE,kEAAkE;QAClE,8BAA8B;QAC9B,MAAM,kBAAkB,GAAG,iBAAiB,CAAC,YAAY,EAAE,MAAM,CAAC,CAAA;QAClE,IAAI,iBAAiB,GAAG,KAAK,CA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