@tileflow/static 0.1.0-alpha.0 → 0.1.0-alpha.10

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/README.md CHANGED
@@ -3,13 +3,17 @@
3
3
  Static map schemas, overlay helpers, and request utilities for Tileflow static map rendering.
4
4
 
5
5
  ```ts
6
- import { marker, validateStaticScene } from "@tileflow/static";
6
+ import {marker, precacheStaticMap, validateStaticScene} from '@tileflow/static';
7
7
 
8
8
  const scene = validateStaticScene({
9
- map: "madrid",
10
- camera: { type: "center", center: [-3.7038, 40.4168], zoom: 12 },
11
- size: { width: 1200, height: 800 },
12
- overlays: [marker({ coordinate: [-3.7038, 40.4168] })],
9
+ map: 'madrid',
10
+ camera: {type: 'center', center: [-3.7038, 40.4168], zoom: 12},
11
+ size: {width: 1200, height: 800},
12
+ overlays: [marker({coordinate: [-3.7038, 40.4168]})],
13
+ });
14
+
15
+ await precacheStaticMap(scene.scene, {
16
+ apiKey: process.env.TILEFLOW_API_KEY,
13
17
  });
14
18
  ```
15
19
 
package/dist/index.d.ts CHANGED
@@ -202,17 +202,17 @@ type StaticMapResult = {
202
202
  cached: boolean;
203
203
  hash: string;
204
204
  imageUrl: string;
205
- status: "ready";
205
+ status: 'ready';
206
206
  };
207
207
  type StaticMapCreateOptions = {
208
208
  apiKey?: string;
209
209
  apiUrl?: string;
210
210
  fetch?: typeof fetch;
211
211
  };
212
- declare function line(input: Omit<z.input<typeof lineOverlaySchema>, "type">): StaticOverlay;
213
- declare function circle(input: Omit<z.input<typeof circleOverlaySchema>, "type">): StaticOverlay;
214
- declare function marker(input: Omit<z.input<typeof markerOverlaySchema>, "type">): StaticOverlay;
215
- declare function polygon(input: Omit<z.input<typeof polygonOverlaySchema>, "type">): StaticOverlay;
212
+ declare function line(input: Omit<z.input<typeof lineOverlaySchema>, 'type'>): StaticOverlay;
213
+ declare function circle(input: Omit<z.input<typeof circleOverlaySchema>, 'type'>): StaticOverlay;
214
+ declare function marker(input: Omit<z.input<typeof markerOverlaySchema>, 'type'>): StaticOverlay;
215
+ declare function polygon(input: Omit<z.input<typeof polygonOverlaySchema>, 'type'>): StaticOverlay;
216
216
  declare function validateStaticScene(input: unknown): {
217
217
  ok: true;
218
218
  scene: StaticScene;
@@ -242,6 +242,7 @@ declare function compileStaticOverlays(overlays: StaticOverlay[]): {
242
242
  sources: Record<string, Record<string, unknown>>;
243
243
  };
244
244
  declare function createStaticMap(scene: StaticSceneInput, options?: StaticMapCreateOptions): Promise<StaticMapResult>;
245
+ declare function precacheStaticMap(scene: StaticSceneInput, options?: StaticMapCreateOptions): Promise<StaticMapResult>;
245
246
  declare function stableStringify(value: unknown): string;
246
247
 
247
- export { type StaticCoordinate, type StaticMapCreateOptions, type StaticMapResult, type StaticOverlay, type StaticOverlayInput, type StaticRenderManifest, type StaticScene, type StaticSceneInput, circle, compileStaticOverlays, createRenderManifest, createStaticMap, hashRenderManifest, line, marker, normalizeStaticScene, polygon, stableStringify, staticOverlaySchema, staticRenderManifestSchema, staticRendererSchemaVersion, staticSceneLimits, staticSceneSchema, staticSceneSchemaVersion, validateStaticRenderManifest, validateStaticScene };
248
+ export { type StaticCoordinate, type StaticMapCreateOptions, type StaticMapResult, type StaticOverlay, type StaticOverlayInput, type StaticRenderManifest, type StaticScene, type StaticSceneInput, circle, compileStaticOverlays, createRenderManifest, createStaticMap, hashRenderManifest, line, marker, normalizeStaticScene, polygon, precacheStaticMap, stableStringify, staticOverlaySchema, staticRenderManifestSchema, staticRendererSchemaVersion, staticSceneLimits, staticSceneSchema, staticSceneSchemaVersion, validateStaticRenderManifest, validateStaticScene };
package/dist/index.js CHANGED
@@ -10,12 +10,9 @@ var staticSceneLimits = {
10
10
  maxPhysicalPixels: 1280 * 1280,
11
11
  minDimension: 64
12
12
  };
13
- var coordinateSchema = z.tuple([z.number().finite(), z.number().finite()]).refine(
14
- ([lng, lat]) => lng >= -180 && lng <= 180 && lat >= -90 && lat <= 90,
15
- {
16
- message: "Expected [lng, lat] within world bounds"
17
- }
18
- );
13
+ var coordinateSchema = z.tuple([z.number().finite(), z.number().finite()]).refine(([lng, lat]) => lng >= -180 && lng <= 180 && lat >= -90 && lat <= 90, {
14
+ message: "Expected [lng, lat] within world bounds"
15
+ });
19
16
  var colorSchema = z.string().regex(/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/, {
20
17
  message: "Expected a hex color like #C6A15B"
21
18
  });
@@ -37,12 +34,7 @@ var centerCameraSchema = z.object({
37
34
  });
38
35
  var boundsCameraSchema = z.object({
39
36
  bearing: z.number().finite().min(-180).max(180).optional(),
40
- bounds: z.tuple([
41
- z.number().finite(),
42
- z.number().finite(),
43
- z.number().finite(),
44
- z.number().finite()
45
- ]).refine(
37
+ bounds: z.tuple([z.number().finite(), z.number().finite(), z.number().finite(), z.number().finite()]).refine(
46
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,
47
39
  { message: "Expected bounds as [west, south, east, north]" }
48
40
  ),
@@ -78,10 +70,16 @@ var markerOverlaySchema = z.object({
78
70
  strokeWidth: z.number().finite().min(0).max(16).default(2),
79
71
  type: z.literal("marker")
80
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
81
  var polygonOverlaySchema = z.object({
82
- coordinates: z.array(
83
- z.array(coordinateSchema).min(4).max(staticSceneLimits.maxPathCoordinates)
84
- ).min(1).max(16),
82
+ coordinates: z.array(polygonRingSchema).min(1).max(16),
85
83
  fill: colorSchema.default("#C6A15B"),
86
84
  id: z.string().trim().min(1).max(64).optional(),
87
85
  opacity: z.number().finite().min(0).max(1).default(0.28),
@@ -96,10 +94,7 @@ var staticOverlaySchema = z.discriminatedUnion("type", [
96
94
  polygonOverlaySchema
97
95
  ]);
98
96
  var staticSceneSchema = z.object({
99
- camera: z.discriminatedUnion("type", [
100
- centerCameraSchema,
101
- boundsCameraSchema
102
- ]),
97
+ camera: z.discriminatedUnion("type", [centerCameraSchema, boundsCameraSchema]),
103
98
  map: z.string().trim().min(1).max(128),
104
99
  overlays: z.array(staticOverlaySchema).max(staticSceneLimits.maxOverlays).default([]),
105
100
  size: sizeSchema
@@ -147,9 +142,7 @@ function validateStaticRenderManifest(input) {
147
142
  const parsed = staticRenderManifestSchema.safeParse(input);
148
143
  if (!parsed.success) {
149
144
  return {
150
- error: parsed.error.issues.map(
151
- (issue) => `${issue.path.join(".") || "manifest"}: ${issue.message}`
152
- ).join("; "),
145
+ error: parsed.error.issues.map((issue) => `${issue.path.join(".") || "manifest"}: ${issue.message}`).join("; "),
153
146
  ok: false
154
147
  };
155
148
  }
@@ -222,9 +215,7 @@ function compileStaticOverlays(overlays) {
222
215
  const sources = {};
223
216
  const layers = [];
224
217
  for (const [index, overlay] of overlays.entries()) {
225
- const id = safeLayerId(
226
- `overlay-${index + 1}-${overlay.id ?? overlay.type}`
227
- );
218
+ const id = safeLayerId(`overlay-${index + 1}-${overlay.id ?? overlay.type}`);
228
219
  const sourceId = `${id}-source`;
229
220
  if (overlay.type === "line") {
230
221
  sources[sourceId] = {
@@ -292,6 +283,12 @@ function compileStaticOverlays(overlays) {
292
283
  return { layers, sources };
293
284
  }
294
285
  async function createStaticMap(scene, options = {}) {
286
+ return requestStaticMap(scene, options, "/v1/static/maps");
287
+ }
288
+ async function precacheStaticMap(scene, options = {}) {
289
+ return requestStaticMap(scene, options, "/v1/static/maps/precache");
290
+ }
291
+ async function requestStaticMap(scene, options, path) {
295
292
  const validation = validateStaticScene(scene);
296
293
  if (!validation.ok) {
297
294
  throw new Error(`Invalid Tileflow static scene: ${validation.error}`);
@@ -304,7 +301,7 @@ async function createStaticMap(scene, options = {}) {
304
301
  if (options.apiKey) {
305
302
  headers.Authorization = `Bearer ${options.apiKey}`;
306
303
  }
307
- const response = await fetcher(`${apiUrl}/v1/static/maps`, {
304
+ const response = await fetcher(`${apiUrl}${path}`, {
308
305
  body: JSON.stringify(validation.scene),
309
306
  headers,
310
307
  method: "POST"
@@ -322,9 +319,7 @@ function normalizeOverlay(overlay) {
322
319
  const parsed = staticOverlaySchema.parse(overlay);
323
320
  const normalized = stripUndefined({ ...parsed });
324
321
  if ("coordinate" in normalized) {
325
- normalized.coordinate = normalizeCoordinate(
326
- normalized.coordinate
327
- );
322
+ normalized.coordinate = normalizeCoordinate(normalized.coordinate);
328
323
  }
329
324
  if ("coordinates" in normalized) {
330
325
  normalized.coordinates = normalizeCoordinates(normalized.coordinates);
@@ -350,9 +345,7 @@ function stripUndefined(value) {
350
345
  if (!value || typeof value !== "object" || Array.isArray(value)) {
351
346
  return value;
352
347
  }
353
- return Object.fromEntries(
354
- Object.entries(value).filter(([, entry]) => entry !== void 0)
355
- );
348
+ return Object.fromEntries(Object.entries(value).filter(([, entry]) => entry !== void 0));
356
349
  }
357
350
  function sortJson(value) {
358
351
  if (Array.isArray(value)) {
@@ -398,6 +391,7 @@ export {
398
391
  marker,
399
392
  normalizeStaticScene,
400
393
  polygon,
394
+ precacheStaticMap,
401
395
  stableStringify,
402
396
  staticOverlaySchema,
403
397
  staticRenderManifestSchema,
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "@tileflow/static",
3
- "version": "0.1.0-alpha.0",
3
+ "version": "0.1.0-alpha.10",
4
4
  "description": "Static map request schemas and helpers for Tileflow.",
5
5
  "type": "module",
6
+ "sideEffects": false,
6
7
  "homepage": "https://tileflow.dev",
7
8
  "repository": {
8
9
  "type": "git",
@@ -39,6 +40,7 @@
39
40
  },
40
41
  "scripts": {
41
42
  "build": "tsup src/index.ts --format esm --dts --clean",
43
+ "verify": "tsx --test test/*.test.ts",
42
44
  "typecheck": "tsc -p tsconfig.json --noEmit",
43
45
  "lint": "tsc -p tsconfig.json --noEmit"
44
46
  }