@mapvx/web-js 1.0.1 → 1.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.
Files changed (69) hide show
  1. package/README.md +5 -2
  2. package/dist/cjs/controllers/routeController.js +8 -12
  3. package/dist/cjs/controllers/routeController.js.map +1 -1
  4. package/dist/cjs/domain/models/animation.js +2 -1
  5. package/dist/cjs/domain/models/animation.js.map +1 -1
  6. package/dist/cjs/domain/models/marker.js +6 -0
  7. package/dist/cjs/domain/models/marker.js.map +1 -1
  8. package/dist/cjs/index.js +6 -1
  9. package/dist/cjs/index.js.map +1 -1
  10. package/dist/cjs/logger/logger.js +15 -8
  11. package/dist/cjs/logger/logger.js.map +1 -1
  12. package/dist/cjs/logger/rollbar.js +16 -8
  13. package/dist/cjs/logger/rollbar.js.map +1 -1
  14. package/dist/cjs/repository/repository.js +24 -0
  15. package/dist/cjs/repository/repository.js.map +1 -1
  16. package/dist/cjs/repository/requester.js +64 -8
  17. package/dist/cjs/repository/requester.js.map +1 -1
  18. package/dist/cjs/sdk.js +24 -0
  19. package/dist/cjs/sdk.js.map +1 -1
  20. package/dist/cjs/utils/mapvxHostname.js +21 -0
  21. package/dist/cjs/utils/mapvxHostname.js.map +1 -0
  22. package/dist/cjs/utils/preconnect.js +131 -0
  23. package/dist/cjs/utils/preconnect.js.map +1 -0
  24. package/dist/es/config/sdkConfig.d.ts +10 -2
  25. package/dist/es/config/sdkConfig.d.ts.map +1 -1
  26. package/dist/es/controllers/routeController.d.ts.map +1 -1
  27. package/dist/es/controllers/routeController.js +8 -12
  28. package/dist/es/controllers/routeController.js.map +1 -1
  29. package/dist/es/domain/models/animation.d.ts +8 -0
  30. package/dist/es/domain/models/animation.d.ts.map +1 -1
  31. package/dist/es/domain/models/animation.js +2 -1
  32. package/dist/es/domain/models/animation.js.map +1 -1
  33. package/dist/es/domain/models/marker.d.ts +8 -0
  34. package/dist/es/domain/models/marker.d.ts.map +1 -1
  35. package/dist/es/domain/models/marker.js +6 -0
  36. package/dist/es/domain/models/marker.js.map +1 -1
  37. package/dist/es/index.d.ts +3 -1
  38. package/dist/es/index.d.ts.map +1 -1
  39. package/dist/es/index.js +2 -0
  40. package/dist/es/index.js.map +1 -1
  41. package/dist/es/logger/logger.d.ts.map +1 -1
  42. package/dist/es/logger/logger.js +15 -8
  43. package/dist/es/logger/logger.js.map +1 -1
  44. package/dist/es/logger/rollbar.d.ts.map +1 -1
  45. package/dist/es/logger/rollbar.js +16 -8
  46. package/dist/es/logger/rollbar.js.map +1 -1
  47. package/dist/es/repository/repository.d.ts +1 -0
  48. package/dist/es/repository/repository.d.ts.map +1 -1
  49. package/dist/es/repository/repository.js +24 -0
  50. package/dist/es/repository/repository.js.map +1 -1
  51. package/dist/es/repository/requester.d.ts +25 -4
  52. package/dist/es/repository/requester.d.ts.map +1 -1
  53. package/dist/es/repository/requester.js +64 -8
  54. package/dist/es/repository/requester.js.map +1 -1
  55. package/dist/es/sdk.d.ts +51 -0
  56. package/dist/es/sdk.d.ts.map +1 -1
  57. package/dist/es/sdk.js +24 -0
  58. package/dist/es/sdk.js.map +1 -1
  59. package/dist/es/utils/mapvxHostname.d.ts +11 -0
  60. package/dist/es/utils/mapvxHostname.d.ts.map +1 -0
  61. package/dist/es/utils/mapvxHostname.js +17 -0
  62. package/dist/es/utils/mapvxHostname.js.map +1 -0
  63. package/dist/es/utils/preconnect.d.ts +45 -0
  64. package/dist/es/utils/preconnect.d.ts.map +1 -0
  65. package/dist/es/utils/preconnect.js +127 -0
  66. package/dist/es/utils/preconnect.js.map +1 -0
  67. package/dist/umd/index.js +714 -260
  68. package/dist/umd/index.js.map +1 -1
  69. package/package.json +12 -6
@@ -0,0 +1,45 @@
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 declare const MAPVX_DEFAULT_PRECONNECT_HOSTS: readonly string[];
10
+ /**
11
+ * Injects `<link rel="preconnect">` (and a `<link rel="dns-prefetch">` fallback)
12
+ * tags into `document.head` for the given origins, so the browser starts the
13
+ * DNS + TLS handshake before MapLibre actually requests sprite/glyph/tile
14
+ * resources.
15
+ *
16
+ * Call this as early as possible — ideally before {@link initializeSDK} — to
17
+ * maximize the savings. In real captures this shaves ~150-300 ms off the
18
+ * first-paint cascade.
19
+ *
20
+ * Idempotent: hosts that already have a `<link rel="preconnect" crossorigin>`
21
+ * are skipped. If an existing `preconnect` link is missing `crossorigin`, it
22
+ * is upgraded in place (added `crossorigin="anonymous"`) — without that
23
+ * attribute the warmed socket can't be reused for the CORS tile/font/sprite
24
+ * fetches MapLibre performs, so leaving the existing link untouched would
25
+ * silently defeat the optimization. Existing `crossorigin="use-credentials"`
26
+ * is respected and never overwritten.
27
+ *
28
+ * @param hosts - Origin URLs (`"https://tiles.mapvx.com"`) or bare hostnames
29
+ * (`"tiles.mapvx.com"`, normalized to `https://`). Invalid entries are
30
+ * silently ignored.
31
+ * @returns The origins where the helper made a change — either a new link was
32
+ * appended, or an existing one was upgraded with `crossorigin="anonymous"`.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * import { initializeSDK, injectPreconnects, MAPVX_DEFAULT_PRECONNECT_HOSTS } from "@mapvx/web-js"
37
+ *
38
+ * injectPreconnects(MAPVX_DEFAULT_PRECONNECT_HOSTS)
39
+ * const sdk = initializeSDK(apiKey)
40
+ * ```
41
+ *
42
+ * @group Utils
43
+ */
44
+ export declare function injectPreconnects(hosts: readonly string[]): string[];
45
+ //# sourceMappingURL=preconnect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preconnect.d.ts","sourceRoot":"","sources":["../../../src/utils/preconnect.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,eAAO,MAAM,8BAA8B,EAAE,SAAS,MAAM,EAI3D,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CA+CpE"}
@@ -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,OAA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