@tileflow/static 0.1.0-alpha.17 → 0.1.0-alpha.19
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/GENERATED_OUTPUT_LICENSE.md +21 -0
- package/LICENSE +201 -0
- package/NOTICE +9 -0
- package/README.md +34 -0
- package/TRADEMARKS.md +10 -0
- package/dist/chunk-43QGLF6K.js +304 -0
- package/dist/chunk-HKYA7ZIU.js +79 -0
- package/dist/chunk-LGEYA6FQ.js +106 -0
- package/dist/chunk-ROBEGDDY.js +63 -0
- package/dist/chunk-YUG3PBK2.js +198 -0
- package/dist/client.d.ts +58 -0
- package/dist/client.js +25 -0
- package/dist/index.d.ts +6 -278
- package/dist/index.js +38 -565
- package/dist/manifest.d.ts +85 -0
- package/dist/manifest.js +18 -0
- package/dist/overlays.d.ts +14 -0
- package/dist/overlays.js +18 -0
- package/dist/scene-contract-DzsUeJ_V.d.ts +141 -0
- package/dist/scene.d.ts +14 -0
- package/dist/scene.js +16 -0
- package/package.json +28 -3
package/dist/index.js
CHANGED
|
@@ -1,568 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
bounds: z.tuple([z.number().finite(), z.number().finite(), z.number().finite(), z.number().finite()]).refine(
|
|
38
|
-
([west, south, east, north]) => west >= -180 && west <= 180 && east >= -180 && east <= 180 && south >= -90 && south <= 90 && north >= -90 && north <= 90 && west !== east && south !== north,
|
|
39
|
-
{ message: "Expected bounds as [west, south, east, north]" }
|
|
40
|
-
),
|
|
41
|
-
padding: z.number().int().min(0).max(256).optional(),
|
|
42
|
-
type: z.literal("bounds")
|
|
43
|
-
}).refine((camera) => camera.bounds[3] > camera.bounds[1], {
|
|
44
|
-
message: "Bounds north must be greater than south"
|
|
45
|
-
});
|
|
46
|
-
var lineOverlaySchema = z.object({
|
|
47
|
-
color: colorSchema.default("#C6A15B"),
|
|
48
|
-
coordinates: z.array(coordinateSchema).min(2).max(staticSceneLimits.maxPathCoordinates),
|
|
49
|
-
id: z.string().trim().min(1).max(64).optional(),
|
|
50
|
-
opacity: z.number().finite().min(0).max(1).default(1),
|
|
51
|
-
type: z.literal("line"),
|
|
52
|
-
width: z.number().finite().min(0.5).max(32).default(4)
|
|
53
|
-
});
|
|
54
|
-
var circleOverlaySchema = z.object({
|
|
55
|
-
color: colorSchema.default("#C6A15B"),
|
|
56
|
-
coordinate: coordinateSchema,
|
|
57
|
-
id: z.string().trim().min(1).max(64).optional(),
|
|
58
|
-
opacity: z.number().finite().min(0).max(1).default(1),
|
|
59
|
-
radius: z.number().finite().min(1).max(64).default(6),
|
|
60
|
-
strokeColor: colorSchema.optional(),
|
|
61
|
-
strokeWidth: z.number().finite().min(0).max(16).default(0),
|
|
62
|
-
type: z.literal("circle")
|
|
63
|
-
});
|
|
64
|
-
var markerOverlaySchema = z.object({
|
|
65
|
-
color: colorSchema.default("#C6A15B"),
|
|
66
|
-
coordinate: coordinateSchema,
|
|
67
|
-
id: z.string().trim().min(1).max(64).optional(),
|
|
68
|
-
radius: z.number().finite().min(2).max(64).default(8),
|
|
69
|
-
strokeColor: colorSchema.default("#ffffff"),
|
|
70
|
-
strokeWidth: z.number().finite().min(0).max(16).default(2),
|
|
71
|
-
type: z.literal("marker")
|
|
72
|
-
});
|
|
73
|
-
var polygonRingSchema = z.array(coordinateSchema).min(4).max(staticSceneLimits.maxPathCoordinates).refine(
|
|
74
|
-
(ring) => {
|
|
75
|
-
const first = ring[0];
|
|
76
|
-
const last = ring[ring.length - 1];
|
|
77
|
-
return Boolean(first && last && first[0] === last[0] && first[1] === last[1]);
|
|
78
|
-
},
|
|
79
|
-
{ message: "Polygon rings must end at their starting coordinate" }
|
|
80
|
-
);
|
|
81
|
-
var polygonOverlaySchema = z.object({
|
|
82
|
-
coordinates: z.array(polygonRingSchema).min(1).max(16),
|
|
83
|
-
fill: colorSchema.default("#C6A15B"),
|
|
84
|
-
id: z.string().trim().min(1).max(64).optional(),
|
|
85
|
-
opacity: z.number().finite().min(0).max(1).default(0.28),
|
|
86
|
-
stroke: colorSchema.optional(),
|
|
87
|
-
strokeWidth: z.number().finite().min(0).max(16).default(0),
|
|
88
|
-
type: z.literal("polygon")
|
|
89
|
-
});
|
|
90
|
-
var staticOverlaySchema = z.discriminatedUnion("type", [
|
|
91
|
-
lineOverlaySchema,
|
|
92
|
-
circleOverlaySchema,
|
|
93
|
-
markerOverlaySchema,
|
|
94
|
-
polygonOverlaySchema
|
|
95
|
-
]);
|
|
96
|
-
var staticSceneSchema = z.object({
|
|
97
|
-
camera: z.discriminatedUnion("type", [centerCameraSchema, boundsCameraSchema]),
|
|
98
|
-
map: z.string().trim().min(1).max(128),
|
|
99
|
-
overlays: z.array(staticOverlaySchema).max(staticSceneLimits.maxOverlays).default([]),
|
|
100
|
-
size: sizeSchema
|
|
101
|
-
});
|
|
102
|
-
var staticRenderManifestSchema = z.object({
|
|
103
|
-
mapId: z.string().trim().min(1).max(128),
|
|
104
|
-
rendererVersion: z.string().trim().min(1).max(64),
|
|
105
|
-
schemaVersion: z.literal(staticRendererSchemaVersion),
|
|
106
|
-
scene: staticSceneSchema,
|
|
107
|
-
styleId: z.string().trim().min(1).max(128).optional(),
|
|
108
|
-
styleRevision: z.string().trim().min(1).max(128),
|
|
109
|
-
styleUrl: z.string().trim().url().max(512).refine((value) => /^https?:\/\//.test(value), {
|
|
110
|
-
message: "Expected an http(s) style URL"
|
|
111
|
-
})
|
|
112
|
-
});
|
|
113
|
-
var staticMapIdempotencyKeyPattern = /^[A-Za-z0-9][A-Za-z0-9._:-]{7,127}$/;
|
|
114
|
-
var staticMapReadyResultSchema = z.object({
|
|
115
|
-
cached: z.boolean(),
|
|
116
|
-
hash: z.string().regex(/^[A-Za-z0-9_-]{43}$/),
|
|
117
|
-
imageUrl: z.string().trim().url().max(2048).refine(isSafeHttpUrl, { message: "Expected an http(s) URL without credentials" }),
|
|
118
|
-
operationId: z.string().min(20).max(68),
|
|
119
|
-
remainingUnits: z.number().int().nonnegative(),
|
|
120
|
-
status: z.literal("ready"),
|
|
121
|
-
unitCost: z.literal(15)
|
|
122
|
-
}).strict();
|
|
123
|
-
var staticMapProcessingResultSchema = z.object({
|
|
124
|
-
operationId: z.string().min(20).max(68),
|
|
125
|
-
retryAfterMs: z.number().int().min(0).max(5e3),
|
|
126
|
-
status: z.literal("processing")
|
|
127
|
-
}).strict();
|
|
128
|
-
function validateStaticMapIdempotencyKey(value) {
|
|
129
|
-
if (typeof value !== "string" || !staticMapIdempotencyKeyPattern.test(value)) {
|
|
130
|
-
return {
|
|
131
|
-
error: "Idempotency key must contain 8-128 ASCII letters, digits, dot, underscore, colon, or hyphen and start with a letter or digit",
|
|
132
|
-
ok: false
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
return { key: value, ok: true };
|
|
136
|
-
}
|
|
137
|
-
function createStaticMapIdempotencyKey() {
|
|
138
|
-
const key = `static_${crypto.randomUUID()}`;
|
|
139
|
-
if (!validateStaticMapIdempotencyKey(key).ok) {
|
|
140
|
-
throw new Error("Unable to create a valid Tileflow Static Maps idempotency key");
|
|
141
|
-
}
|
|
142
|
-
return key;
|
|
143
|
-
}
|
|
144
|
-
function line(input) {
|
|
145
|
-
return normalizeOverlay({ ...input, type: "line" });
|
|
146
|
-
}
|
|
147
|
-
function circle(input) {
|
|
148
|
-
return normalizeOverlay({ ...input, type: "circle" });
|
|
149
|
-
}
|
|
150
|
-
function marker(input) {
|
|
151
|
-
return normalizeOverlay({ ...input, type: "marker" });
|
|
152
|
-
}
|
|
153
|
-
function polygon(input) {
|
|
154
|
-
return normalizeOverlay({ ...input, type: "polygon" });
|
|
155
|
-
}
|
|
156
|
-
function validateStaticScene(input) {
|
|
157
|
-
const parsed = staticSceneSchema.safeParse(input);
|
|
158
|
-
if (!parsed.success) {
|
|
159
|
-
return {
|
|
160
|
-
error: parsed.error.issues.map((issue) => `${issue.path.join(".") || "scene"}: ${issue.message}`).join("; "),
|
|
161
|
-
ok: false
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
if (jsonByteLength(parsed.data.overlays) > staticSceneLimits.maxGeoJsonBytes) {
|
|
165
|
-
return {
|
|
166
|
-
error: `overlays exceed ${staticSceneLimits.maxGeoJsonBytes} bytes`,
|
|
167
|
-
ok: false
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
return { ok: true, scene: normalizeStaticScene(parsed.data) };
|
|
171
|
-
}
|
|
172
|
-
function validateStaticRenderManifest(input) {
|
|
173
|
-
const parsed = staticRenderManifestSchema.safeParse(input);
|
|
174
|
-
if (!parsed.success) {
|
|
175
|
-
return {
|
|
176
|
-
error: parsed.error.issues.map((issue) => `${issue.path.join(".") || "manifest"}: ${issue.message}`).join("; "),
|
|
177
|
-
ok: false
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
|
-
const sceneValidation = validateStaticScene(parsed.data.scene);
|
|
181
|
-
if (!sceneValidation.ok) {
|
|
182
|
-
return sceneValidation;
|
|
183
|
-
}
|
|
184
|
-
return {
|
|
185
|
-
manifest: {
|
|
186
|
-
...parsed.data,
|
|
187
|
-
scene: sceneValidation.scene
|
|
188
|
-
},
|
|
189
|
-
ok: true
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
function normalizeStaticScene(scene) {
|
|
193
|
-
const parsed = staticSceneSchema.parse(scene);
|
|
194
|
-
return stripUndefined({
|
|
195
|
-
camera: parsed.camera.type === "center" ? {
|
|
196
|
-
bearing: roundNumber(parsed.camera.bearing ?? 0),
|
|
197
|
-
center: normalizeCoordinate(parsed.camera.center),
|
|
198
|
-
type: "center",
|
|
199
|
-
zoom: roundNumber(parsed.camera.zoom)
|
|
200
|
-
} : {
|
|
201
|
-
bearing: roundNumber(parsed.camera.bearing ?? 0),
|
|
202
|
-
bounds: parsed.camera.bounds.map(roundNumber),
|
|
203
|
-
padding: parsed.camera.padding ?? 32,
|
|
204
|
-
type: "bounds"
|
|
205
|
-
},
|
|
206
|
-
map: parsed.map,
|
|
207
|
-
overlays: parsed.overlays.map(
|
|
208
|
-
(overlay, index) => normalizeOverlay({
|
|
209
|
-
...overlay,
|
|
210
|
-
id: overlay.id ?? `overlay-${index + 1}`
|
|
211
|
-
})
|
|
212
|
-
),
|
|
213
|
-
size: {
|
|
214
|
-
dpr: parsed.size.dpr ?? 1,
|
|
215
|
-
height: parsed.size.height,
|
|
216
|
-
width: parsed.size.width
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
function createRenderManifest(input) {
|
|
221
|
-
return staticRenderManifestSchema.parse(
|
|
222
|
-
stripUndefined({
|
|
223
|
-
mapId: input.mapId,
|
|
224
|
-
rendererVersion: input.rendererVersion,
|
|
225
|
-
schemaVersion: staticRendererSchemaVersion,
|
|
226
|
-
scene: normalizeStaticScene({
|
|
227
|
-
...input.scene,
|
|
228
|
-
map: input.mapId
|
|
229
|
-
}),
|
|
230
|
-
styleId: input.styleId,
|
|
231
|
-
styleRevision: input.styleRevision,
|
|
232
|
-
styleUrl: input.styleUrl
|
|
233
|
-
})
|
|
234
|
-
);
|
|
235
|
-
}
|
|
236
|
-
async function hashRenderManifest(manifest) {
|
|
237
|
-
const normalized = staticRenderManifestSchema.parse({
|
|
238
|
-
...manifest,
|
|
239
|
-
scene: normalizeStaticScene(manifest.scene)
|
|
240
|
-
});
|
|
241
|
-
const bytes = new TextEncoder().encode(stableStringify(normalized));
|
|
242
|
-
const digest = await crypto.subtle.digest("SHA-256", bytes);
|
|
243
|
-
return base64Url(new Uint8Array(digest));
|
|
244
|
-
}
|
|
245
|
-
async function hashStaticSceneRequest(scene) {
|
|
246
|
-
const validation = validateStaticScene(scene);
|
|
247
|
-
if (!validation.ok) throw new Error(`Invalid Tileflow static scene: ${validation.error}`);
|
|
248
|
-
return hashStableValue(validation.scene);
|
|
249
|
-
}
|
|
250
|
-
function compileStaticOverlays(overlays) {
|
|
251
|
-
const sources = {};
|
|
252
|
-
const layers = [];
|
|
253
|
-
for (const [index, overlay] of overlays.entries()) {
|
|
254
|
-
const id = safeLayerId(`overlay-${index + 1}-${overlay.id ?? overlay.type}`);
|
|
255
|
-
const sourceId = `${id}-source`;
|
|
256
|
-
if (overlay.type === "line") {
|
|
257
|
-
sources[sourceId] = {
|
|
258
|
-
data: feature("LineString", overlay.coordinates),
|
|
259
|
-
type: "geojson"
|
|
260
|
-
};
|
|
261
|
-
layers.push({
|
|
262
|
-
id,
|
|
263
|
-
layout: { "line-cap": "round", "line-join": "round" },
|
|
264
|
-
paint: {
|
|
265
|
-
"line-color": overlay.color,
|
|
266
|
-
"line-opacity": overlay.opacity,
|
|
267
|
-
"line-width": overlay.width
|
|
268
|
-
},
|
|
269
|
-
source: sourceId,
|
|
270
|
-
type: "line"
|
|
271
|
-
});
|
|
272
|
-
continue;
|
|
273
|
-
}
|
|
274
|
-
if (overlay.type === "polygon") {
|
|
275
|
-
sources[sourceId] = {
|
|
276
|
-
data: feature("Polygon", overlay.coordinates),
|
|
277
|
-
type: "geojson"
|
|
278
|
-
};
|
|
279
|
-
layers.push({
|
|
280
|
-
id,
|
|
281
|
-
paint: {
|
|
282
|
-
"fill-color": overlay.fill,
|
|
283
|
-
"fill-opacity": overlay.opacity
|
|
284
|
-
},
|
|
285
|
-
source: sourceId,
|
|
286
|
-
type: "fill"
|
|
287
|
-
});
|
|
288
|
-
if (overlay.stroke && overlay.strokeWidth > 0) {
|
|
289
|
-
layers.push({
|
|
290
|
-
id: `${id}-stroke`,
|
|
291
|
-
layout: { "line-cap": "round", "line-join": "round" },
|
|
292
|
-
paint: {
|
|
293
|
-
"line-color": overlay.stroke,
|
|
294
|
-
"line-width": overlay.strokeWidth
|
|
295
|
-
},
|
|
296
|
-
source: sourceId,
|
|
297
|
-
type: "line"
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
continue;
|
|
301
|
-
}
|
|
302
|
-
sources[sourceId] = {
|
|
303
|
-
data: feature("Point", overlay.coordinate),
|
|
304
|
-
type: "geojson"
|
|
305
|
-
};
|
|
306
|
-
layers.push({
|
|
307
|
-
id,
|
|
308
|
-
paint: {
|
|
309
|
-
"circle-color": overlay.color,
|
|
310
|
-
"circle-opacity": overlay.type === "circle" ? overlay.opacity : 1,
|
|
311
|
-
"circle-radius": overlay.radius,
|
|
312
|
-
"circle-stroke-color": overlay.strokeColor ?? overlay.color,
|
|
313
|
-
"circle-stroke-width": overlay.strokeWidth
|
|
314
|
-
},
|
|
315
|
-
source: sourceId,
|
|
316
|
-
type: "circle"
|
|
317
|
-
});
|
|
318
|
-
}
|
|
319
|
-
return { layers, sources };
|
|
320
|
-
}
|
|
321
|
-
async function createStaticMap(scene, options) {
|
|
322
|
-
return requestStaticMap(scene, options, "/v1/static/maps");
|
|
323
|
-
}
|
|
324
|
-
async function precacheStaticMap(scene, options) {
|
|
325
|
-
return requestStaticMap(scene, options, "/v1/static/maps/precache");
|
|
326
|
-
}
|
|
327
|
-
async function requestStaticMap(scene, options, path) {
|
|
328
|
-
const validation = validateStaticScene(scene);
|
|
329
|
-
if (!validation.ok) {
|
|
330
|
-
throw new Error(`Invalid Tileflow static scene: ${validation.error}`);
|
|
331
|
-
}
|
|
332
|
-
const idempotency = validateStaticMapIdempotencyKey(options.idempotencyKey);
|
|
333
|
-
if (!idempotency.ok) {
|
|
334
|
-
throw new Error(`Invalid Tileflow Static Maps idempotency key: ${idempotency.error}`);
|
|
335
|
-
}
|
|
336
|
-
const maxWaitMs = boundedClientDuration(options.maxWaitMs, 3e4, 100, 12e4, "maxWaitMs");
|
|
337
|
-
const pollIntervalMs = boundedClientDuration(
|
|
338
|
-
options.pollIntervalMs,
|
|
339
|
-
500,
|
|
340
|
-
0,
|
|
341
|
-
5e3,
|
|
342
|
-
"pollIntervalMs"
|
|
343
|
-
);
|
|
344
|
-
const fetcher = options.fetch ?? fetch;
|
|
345
|
-
const apiUrl = normalizeUrl(options.apiUrl ?? "https://api.tileflow.dev");
|
|
346
|
-
const headers = {
|
|
347
|
-
"Content-Type": "application/json",
|
|
348
|
-
"Idempotency-Key": idempotency.key
|
|
349
|
-
};
|
|
350
|
-
if (options.apiKey) {
|
|
351
|
-
headers.Authorization = `Bearer ${options.apiKey}`;
|
|
352
|
-
}
|
|
353
|
-
return runWithinStaticMapBudget(maxWaitMs, options.signal, async (signal) => {
|
|
354
|
-
const body = JSON.stringify(validation.scene);
|
|
355
|
-
let operationId = null;
|
|
356
|
-
while (true) {
|
|
357
|
-
const response = await fetcher(`${apiUrl}${path}`, {
|
|
358
|
-
body,
|
|
359
|
-
headers,
|
|
360
|
-
method: "POST",
|
|
361
|
-
signal
|
|
362
|
-
});
|
|
363
|
-
throwIfAborted(signal);
|
|
364
|
-
if (!response.ok) {
|
|
365
|
-
const error = await response.text();
|
|
366
|
-
throwIfAborted(signal);
|
|
367
|
-
throw new Error(`Tileflow static map failed: ${response.status} ${error}`);
|
|
368
|
-
}
|
|
369
|
-
const json = await readJsonResponse(response);
|
|
370
|
-
throwIfAborted(signal);
|
|
371
|
-
if (response.status !== 202) {
|
|
372
|
-
const parsed = staticMapReadyResultSchema.safeParse(json);
|
|
373
|
-
if (!parsed.success) {
|
|
374
|
-
throw new Error(
|
|
375
|
-
`Tileflow static map returned an invalid response: ${parsed.error.message}`
|
|
376
|
-
);
|
|
377
|
-
}
|
|
378
|
-
assertStaticMapOperationIdentity(operationId, parsed.data.operationId);
|
|
379
|
-
return parsed.data;
|
|
380
|
-
}
|
|
381
|
-
const pending = staticMapProcessingResultSchema.safeParse(json);
|
|
382
|
-
if (!pending.success) {
|
|
383
|
-
throw new Error(
|
|
384
|
-
`Tileflow static map returned an invalid response: ${pending.error.message}`
|
|
385
|
-
);
|
|
386
|
-
}
|
|
387
|
-
assertStaticMapOperationIdentity(operationId, pending.data.operationId);
|
|
388
|
-
operationId ??= pending.data.operationId;
|
|
389
|
-
await delay(Math.max(pollIntervalMs, pending.data.retryAfterMs), signal);
|
|
390
|
-
}
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
function stableStringify(value) {
|
|
394
|
-
return JSON.stringify(sortJson(value));
|
|
395
|
-
}
|
|
396
|
-
function normalizeOverlay(overlay) {
|
|
397
|
-
const parsed = staticOverlaySchema.parse(overlay);
|
|
398
|
-
const normalized = stripUndefined({ ...parsed });
|
|
399
|
-
if ("coordinate" in normalized) {
|
|
400
|
-
normalized.coordinate = normalizeCoordinate(normalized.coordinate);
|
|
401
|
-
}
|
|
402
|
-
if ("coordinates" in normalized) {
|
|
403
|
-
normalized.coordinates = normalizeCoordinates(normalized.coordinates);
|
|
404
|
-
}
|
|
405
|
-
return normalized;
|
|
406
|
-
}
|
|
407
|
-
function normalizeCoordinates(value) {
|
|
408
|
-
if (!Array.isArray(value)) {
|
|
409
|
-
return value;
|
|
410
|
-
}
|
|
411
|
-
if (value.length === 2 && typeof value[0] === "number" && typeof value[1] === "number") {
|
|
412
|
-
return normalizeCoordinate(value);
|
|
413
|
-
}
|
|
414
|
-
return value.map(normalizeCoordinates);
|
|
415
|
-
}
|
|
416
|
-
function normalizeCoordinate(coordinate) {
|
|
417
|
-
return [roundNumber(coordinate[0]), roundNumber(coordinate[1])];
|
|
418
|
-
}
|
|
419
|
-
function roundNumber(value) {
|
|
420
|
-
return Number(value.toFixed(6));
|
|
421
|
-
}
|
|
422
|
-
function stripUndefined(value) {
|
|
423
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
424
|
-
return value;
|
|
425
|
-
}
|
|
426
|
-
return Object.fromEntries(Object.entries(value).filter(([, entry]) => entry !== void 0));
|
|
427
|
-
}
|
|
428
|
-
function sortJson(value) {
|
|
429
|
-
if (Array.isArray(value)) {
|
|
430
|
-
return value.map(sortJson);
|
|
431
|
-
}
|
|
432
|
-
if (value && typeof value === "object") {
|
|
433
|
-
return Object.fromEntries(
|
|
434
|
-
Object.entries(value).sort(([left], [right]) => left.localeCompare(right)).map(([key, entry]) => [key, sortJson(entry)])
|
|
435
|
-
);
|
|
436
|
-
}
|
|
437
|
-
return value;
|
|
438
|
-
}
|
|
439
|
-
function feature(type, coordinates) {
|
|
440
|
-
return {
|
|
441
|
-
geometry: { coordinates, type },
|
|
442
|
-
properties: {},
|
|
443
|
-
type: "Feature"
|
|
444
|
-
};
|
|
445
|
-
}
|
|
446
|
-
function safeLayerId(value) {
|
|
447
|
-
return value.replace(/[^a-zA-Z0-9_-]/g, "-").slice(0, 80);
|
|
448
|
-
}
|
|
449
|
-
function jsonByteLength(value) {
|
|
450
|
-
return new TextEncoder().encode(JSON.stringify(value)).length;
|
|
451
|
-
}
|
|
452
|
-
function base64Url(bytes) {
|
|
453
|
-
let binary = "";
|
|
454
|
-
for (const byte of bytes) {
|
|
455
|
-
binary += String.fromCharCode(byte);
|
|
456
|
-
}
|
|
457
|
-
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
458
|
-
}
|
|
459
|
-
async function hashStableValue(value) {
|
|
460
|
-
const bytes = new TextEncoder().encode(stableStringify(value));
|
|
461
|
-
const digest = await crypto.subtle.digest("SHA-256", bytes);
|
|
462
|
-
return base64Url(new Uint8Array(digest));
|
|
463
|
-
}
|
|
464
|
-
function boundedClientDuration(value, fallback, minimum, maximum, name) {
|
|
465
|
-
const resolved = value ?? fallback;
|
|
466
|
-
if (!Number.isSafeInteger(resolved) || resolved < minimum || resolved > maximum) {
|
|
467
|
-
throw new Error(
|
|
468
|
-
`Tileflow Static Maps ${name} must be an integer from ${minimum} to ${maximum}`
|
|
469
|
-
);
|
|
470
|
-
}
|
|
471
|
-
return resolved;
|
|
472
|
-
}
|
|
473
|
-
async function readJsonResponse(response) {
|
|
474
|
-
try {
|
|
475
|
-
return await response.json();
|
|
476
|
-
} catch {
|
|
477
|
-
throw new Error("Tileflow static map returned an invalid response: expected JSON");
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
async function runWithinStaticMapBudget(maxWaitMs, externalSignal, operation) {
|
|
481
|
-
const controller = new AbortController();
|
|
482
|
-
const timeoutError = new Error(`Tileflow static map timed out after ${maxWaitMs}ms`);
|
|
483
|
-
const abortFromCaller = () => controller.abort(externalSignal?.reason);
|
|
484
|
-
if (externalSignal?.aborted) {
|
|
485
|
-
abortFromCaller();
|
|
486
|
-
} else {
|
|
487
|
-
externalSignal?.addEventListener("abort", abortFromCaller, { once: true });
|
|
488
|
-
}
|
|
489
|
-
const timeout = setTimeout(() => controller.abort(timeoutError), maxWaitMs);
|
|
490
|
-
try {
|
|
491
|
-
throwIfAborted(controller.signal);
|
|
492
|
-
const pending = operation(controller.signal);
|
|
493
|
-
return await raceWithAbort(pending, controller.signal);
|
|
494
|
-
} finally {
|
|
495
|
-
clearTimeout(timeout);
|
|
496
|
-
externalSignal?.removeEventListener("abort", abortFromCaller);
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
function delay(milliseconds, signal) {
|
|
500
|
-
if (milliseconds === 0) {
|
|
501
|
-
throwIfAborted(signal);
|
|
502
|
-
return Promise.resolve();
|
|
503
|
-
}
|
|
504
|
-
return new Promise((resolve, reject) => {
|
|
505
|
-
const timeout = setTimeout(() => {
|
|
506
|
-
signal.removeEventListener("abort", onAbort);
|
|
507
|
-
resolve();
|
|
508
|
-
}, milliseconds);
|
|
509
|
-
const onAbort = () => {
|
|
510
|
-
clearTimeout(timeout);
|
|
511
|
-
reject(abortReason(signal));
|
|
512
|
-
};
|
|
513
|
-
if (signal.aborted) {
|
|
514
|
-
onAbort();
|
|
515
|
-
} else {
|
|
516
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
517
|
-
}
|
|
518
|
-
});
|
|
519
|
-
}
|
|
520
|
-
function raceWithAbort(operation, signal) {
|
|
521
|
-
if (signal.aborted) return Promise.reject(abortReason(signal));
|
|
522
|
-
return new Promise((resolve, reject) => {
|
|
523
|
-
const onAbort = () => {
|
|
524
|
-
cleanup();
|
|
525
|
-
reject(abortReason(signal));
|
|
526
|
-
};
|
|
527
|
-
const cleanup = () => signal.removeEventListener("abort", onAbort);
|
|
528
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
529
|
-
operation.then(
|
|
530
|
-
(value) => {
|
|
531
|
-
cleanup();
|
|
532
|
-
resolve(value);
|
|
533
|
-
},
|
|
534
|
-
(error) => {
|
|
535
|
-
cleanup();
|
|
536
|
-
reject(error);
|
|
537
|
-
}
|
|
538
|
-
);
|
|
539
|
-
});
|
|
540
|
-
}
|
|
541
|
-
function throwIfAborted(signal) {
|
|
542
|
-
if (signal.aborted) throw abortReason(signal);
|
|
543
|
-
}
|
|
544
|
-
function abortReason(signal) {
|
|
545
|
-
if (signal.reason instanceof Error) return signal.reason;
|
|
546
|
-
const error = new Error("Tileflow static map request was aborted");
|
|
547
|
-
error.name = "AbortError";
|
|
548
|
-
return error;
|
|
549
|
-
}
|
|
550
|
-
function assertStaticMapOperationIdentity(expected, actual) {
|
|
551
|
-
if (expected !== null && actual !== expected) {
|
|
552
|
-
throw new Error("Tileflow static map changed operation identity while polling");
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
function isSafeHttpUrl(value) {
|
|
556
|
-
try {
|
|
557
|
-
const url = new URL(value);
|
|
558
|
-
return ["http:", "https:"].includes(url.protocol) && !url.username && !url.password;
|
|
559
|
-
} catch {
|
|
560
|
-
return false;
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
function normalizeUrl(value) {
|
|
564
|
-
return value.replace(/\/+$/, "");
|
|
565
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
createStaticMap,
|
|
3
|
+
createStaticMapIdempotencyKey,
|
|
4
|
+
precacheStaticMap,
|
|
5
|
+
prepareStaticMapRequest,
|
|
6
|
+
requestStaticMapUntilReady,
|
|
7
|
+
staticMapProcessingResultSchema,
|
|
8
|
+
staticMapReadyResultSchema,
|
|
9
|
+
validateStaticMapIdempotencyKey
|
|
10
|
+
} from "./chunk-43QGLF6K.js";
|
|
11
|
+
import {
|
|
12
|
+
createRenderManifest,
|
|
13
|
+
hashRenderManifest,
|
|
14
|
+
hashStaticSceneRequest,
|
|
15
|
+
staticRenderManifestSchema,
|
|
16
|
+
staticRendererSchemaVersion,
|
|
17
|
+
validateStaticRenderManifest
|
|
18
|
+
} from "./chunk-HKYA7ZIU.js";
|
|
19
|
+
import {
|
|
20
|
+
circle,
|
|
21
|
+
compileStaticOverlays,
|
|
22
|
+
line,
|
|
23
|
+
marker,
|
|
24
|
+
polygon
|
|
25
|
+
} from "./chunk-LGEYA6FQ.js";
|
|
26
|
+
import {
|
|
27
|
+
normalizeStaticScene,
|
|
28
|
+
validateStaticScene
|
|
29
|
+
} from "./chunk-ROBEGDDY.js";
|
|
30
|
+
import {
|
|
31
|
+
stableStringify,
|
|
32
|
+
staticOverlaySchema,
|
|
33
|
+
staticSceneLimits,
|
|
34
|
+
staticSceneSchema,
|
|
35
|
+
staticSceneSchemaVersion
|
|
36
|
+
} from "./chunk-YUG3PBK2.js";
|
|
566
37
|
export {
|
|
567
38
|
circle,
|
|
568
39
|
compileStaticOverlays,
|
|
@@ -576,6 +47,8 @@ export {
|
|
|
576
47
|
normalizeStaticScene,
|
|
577
48
|
polygon,
|
|
578
49
|
precacheStaticMap,
|
|
50
|
+
prepareStaticMapRequest,
|
|
51
|
+
requestStaticMapUntilReady,
|
|
579
52
|
stableStringify,
|
|
580
53
|
staticMapProcessingResultSchema,
|
|
581
54
|
staticMapReadyResultSchema,
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { d as StaticSceneInput } from './scene-contract-DzsUeJ_V.js';
|
|
3
|
+
|
|
4
|
+
declare const staticRendererSchemaVersion = 1;
|
|
5
|
+
declare const staticRenderManifestSchema: z.ZodObject<{
|
|
6
|
+
mapId: z.ZodString;
|
|
7
|
+
rendererVersion: z.ZodString;
|
|
8
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
9
|
+
scene: z.ZodObject<{
|
|
10
|
+
camera: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
11
|
+
bearing: z.ZodOptional<z.ZodNumber>;
|
|
12
|
+
center: z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>;
|
|
13
|
+
type: z.ZodLiteral<"center">;
|
|
14
|
+
zoom: z.ZodNumber;
|
|
15
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
16
|
+
bearing: z.ZodOptional<z.ZodNumber>;
|
|
17
|
+
bounds: z.ZodTuple<[z.ZodNumber, z.ZodNumber, z.ZodNumber, z.ZodNumber], null>;
|
|
18
|
+
padding: z.ZodOptional<z.ZodNumber>;
|
|
19
|
+
type: z.ZodLiteral<"bounds">;
|
|
20
|
+
}, z.core.$strip>], "type">;
|
|
21
|
+
map: z.ZodString;
|
|
22
|
+
overlays: z.ZodDefault<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
23
|
+
color: z.ZodDefault<z.ZodString>;
|
|
24
|
+
coordinates: z.ZodArray<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>;
|
|
25
|
+
id: z.ZodOptional<z.ZodString>;
|
|
26
|
+
opacity: z.ZodDefault<z.ZodNumber>;
|
|
27
|
+
type: z.ZodLiteral<"line">;
|
|
28
|
+
width: z.ZodDefault<z.ZodNumber>;
|
|
29
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
30
|
+
color: z.ZodDefault<z.ZodString>;
|
|
31
|
+
coordinate: z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>;
|
|
32
|
+
id: z.ZodOptional<z.ZodString>;
|
|
33
|
+
opacity: z.ZodDefault<z.ZodNumber>;
|
|
34
|
+
radius: z.ZodDefault<z.ZodNumber>;
|
|
35
|
+
strokeColor: z.ZodOptional<z.ZodString>;
|
|
36
|
+
strokeWidth: z.ZodDefault<z.ZodNumber>;
|
|
37
|
+
type: z.ZodLiteral<"circle">;
|
|
38
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
39
|
+
color: z.ZodDefault<z.ZodString>;
|
|
40
|
+
coordinate: z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>;
|
|
41
|
+
id: z.ZodOptional<z.ZodString>;
|
|
42
|
+
radius: z.ZodDefault<z.ZodNumber>;
|
|
43
|
+
strokeColor: z.ZodDefault<z.ZodString>;
|
|
44
|
+
strokeWidth: z.ZodDefault<z.ZodNumber>;
|
|
45
|
+
type: z.ZodLiteral<"marker">;
|
|
46
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
47
|
+
coordinates: z.ZodArray<z.ZodArray<z.ZodTuple<[z.ZodNumber, z.ZodNumber], null>>>;
|
|
48
|
+
fill: z.ZodDefault<z.ZodString>;
|
|
49
|
+
id: z.ZodOptional<z.ZodString>;
|
|
50
|
+
opacity: z.ZodDefault<z.ZodNumber>;
|
|
51
|
+
stroke: z.ZodOptional<z.ZodString>;
|
|
52
|
+
strokeWidth: z.ZodDefault<z.ZodNumber>;
|
|
53
|
+
type: z.ZodLiteral<"polygon">;
|
|
54
|
+
}, z.core.$strip>], "type">>>;
|
|
55
|
+
size: z.ZodObject<{
|
|
56
|
+
dpr: z.ZodOptional<z.ZodLiteral<1>>;
|
|
57
|
+
height: z.ZodNumber;
|
|
58
|
+
width: z.ZodNumber;
|
|
59
|
+
}, z.core.$strip>;
|
|
60
|
+
theme: z.ZodString;
|
|
61
|
+
}, z.core.$strip>;
|
|
62
|
+
styleId: z.ZodOptional<z.ZodString>;
|
|
63
|
+
styleRevision: z.ZodString;
|
|
64
|
+
styleUrl: z.ZodString;
|
|
65
|
+
}, z.core.$strip>;
|
|
66
|
+
type StaticRenderManifest = z.infer<typeof staticRenderManifestSchema>;
|
|
67
|
+
declare function validateStaticRenderManifest(input: unknown): {
|
|
68
|
+
manifest: StaticRenderManifest;
|
|
69
|
+
ok: true;
|
|
70
|
+
} | {
|
|
71
|
+
error: string;
|
|
72
|
+
ok: false;
|
|
73
|
+
};
|
|
74
|
+
declare function createRenderManifest(input: {
|
|
75
|
+
mapId: string;
|
|
76
|
+
rendererVersion: string;
|
|
77
|
+
scene: StaticSceneInput;
|
|
78
|
+
styleId?: string;
|
|
79
|
+
styleRevision: string;
|
|
80
|
+
styleUrl: string;
|
|
81
|
+
}): StaticRenderManifest;
|
|
82
|
+
declare function hashRenderManifest(manifest: StaticRenderManifest): Promise<string>;
|
|
83
|
+
declare function hashStaticSceneRequest(scene: StaticSceneInput): Promise<string>;
|
|
84
|
+
|
|
85
|
+
export { type StaticRenderManifest, createRenderManifest, hashRenderManifest, hashStaticSceneRequest, staticRenderManifestSchema, staticRendererSchemaVersion, validateStaticRenderManifest };
|