import { StyleSpecification, SourceSpecification, GeoJSONSourceSpecification, VectorSourceSpecification, RasterSourceSpecification, RasterDEMSourceSpecification } from '@maplibre/maplibre-gl-style-spec'; import { GeoJSON, BBox } from 'geojson'; import * as stream from 'stream'; import { Readable } from 'stream'; import { SetRequired } from 'type-fest'; import * as readable_stream from 'readable-stream'; import { EventEmitter } from 'events'; /** @typedef {string | Buffer | Uint8Array | import('stream').Readable } Source */ /** @typedef {string | Buffer | import('stream').Readable} SourceInternal */ /** @typedef {`${number}-${number}`} GlyphRange */ /** @typedef {'png' | 'mvt' | 'jpg' | 'webp'} TileFormat */ /** * @typedef {object} SourceInfo * @property {import('./types.js').SMPSource} source * @property {string} encodedSourceId * @property {TileFormat} [format] */ /** * @typedef {object} TileInfo * @property {number} z * @property {number} x * @property {number} y * @property {string} sourceId * @property {TileFormat} [format] */ /** * @typedef {object} GlyphInfo * @property {string} font * @property {GlyphRange} range */ /** @import { StyleSpecification } from '@maplibre/maplibre-gl-style-spec' */ /** @import { InputSource, SMPSource } from './types.js' */ declare const SUPPORTED_SOURCE_TYPES: readonly ["raster", "vector", "geojson"]; /** * Write a styled map package to a stream. Stream `writer.outputStream` to a * destination, e.g. `fs.createWriteStream('my-map.styledmap')`. You must call * `witer.finish()` and then wait for your writable stream to `finish` before * using the output. */ declare class Writer extends EventEmitter<[never]> { static SUPPORTED_SOURCE_TYPES: readonly ["raster", "vector", "geojson"]; /** * @param {any} style A v7 or v8 MapLibre style. v7 styles will be migrated to * v8. (There are currently no typescript declarations for v7 styles, hence * this is typed as `any` and validated internally) * @param {object} opts * @param {number} [opts.highWaterMark=1048576] The maximum number of bytes to buffer during write */ constructor(style: any, { highWaterMark }?: { highWaterMark?: number | undefined; }); /** * @returns {import('stream').Readable} Readable stream of the styled map package */ get outputStream(): stream.Readable; /** * Add a tile to the styled map package * * @param {Source} tileData * @param {TileInfo} opts */ addTile(tileData: Source, { z, x, y, sourceId, format }: TileInfo): Promise; /** * Create a write stream for adding tiles to the styled map package * * @param {object} opts * @param {number} [opts.concurrency=16] The number of concurrent writes * * @returns */ createTileWriteStream({ concurrency }?: { concurrency?: number | undefined; }): readable_stream.Writable; /** * Add a sprite to the styled map package * * @param {object} options * @param {Source} options.json * @param {Source} options.png * @param {number} [options.pixelRatio] * @param {string} [options.id='default'] * @returns {Promise} */ addSprite({ json, png, pixelRatio, id }: { json: Source; png: Source; pixelRatio?: number | undefined; id?: string | undefined; }): Promise; /** * Add glyphs to the styled map package * * @param {Source} glyphData * @param {GlyphInfo} glyphInfo * @returns {Promise} */ addGlyphs(glyphData: Source, { font: fontName, range }: GlyphInfo): Promise; /** * Create a write stream for adding glyphs to the styled map package * * @param {object} opts * @param {number} [opts.concurrency=16] The number of concurrent writes * @returns */ createGlyphWriteStream({ concurrency }?: { concurrency?: number | undefined; }): readable_stream.Writable; /** * Finalize the styled map package and write the style to the archive. * This method must be called to complete the archive. * You must wait for your destination write stream to 'finish' before using the output. */ finish(): Promise; #private; } type ZipEntry = { name: string; }; type Source = string | Buffer | Uint8Array | stream.Readable; type SourceInternal = string | Buffer | stream.Readable; type GlyphRange = `${number}-${number}`; type TileFormat = "png" | "mvt" | "jpg" | "webp"; type SourceInfo = { source: SMPSource; encodedSourceId: string; format?: TileFormat | undefined; }; type TileInfo = { z: number; x: number; y: number; sourceId: string; format?: TileFormat | undefined; }; type GlyphInfo = { font: string; range: GlyphRange; }; type TransformInlinedSource = T extends GeoJSONSourceSpecification ? OmitUnion & { data: GeoJSON; } : T extends VectorSourceSpecification | RasterSourceSpecification | RasterDEMSourceSpecification ? SetRequired, 'tiles'> : T; /** * This is a slightly stricter version of SourceSpecification that requires * sources to be inlined (e.g. no urls to TileJSON or GeoJSON files). */ type InlinedSource = TransformInlinedSource; type SupportedInlinedSource = Extract; /** * This is a slightly stricter version of StyleSpecification that requires * sources to be inlined (e.g. no urls to TileJSON or GeoJSON files). */ type StyleInlinedSources = Omit & { sources: { [_: string]: InlinedSource; }; }; type SMPSource = TransformSMPInputSource; /** * This is a slightly stricter version of StyleSpecification that is provided in * a Styled Map Package. Tile sources must have tile URLs inlined (they cannot * refer to a TileJSON url), and they must have bounds, minzoom, and maxzoom. * GeoJSON sources must have inlined GeoJSON (not a URL to a GeoJSON file). */ type SMPStyle = TransformSMPStyle; type TransformSMPInputSource = T extends GeoJSONSourceSpecification ? T & { data: { bbox: BBox; }; } : T extends RasterSourceSpecification | VectorSourceSpecification ? SetRequired : T; type TransformSMPStyle = Omit & { metadata: { 'smp:bounds': [number, number, number, number]; 'smp:maxzoom': 0; 'smp:sourceFolders': { [_: string]: string; }; }; sources: { [_: string]: SMPSource; }; }; interface DownloadStream extends Readable { iterator(...args: Parameters): AsyncIterableIterator; [Symbol.asyncIterator](): AsyncIterableIterator; } type OmitUnion = T extends unknown ? Omit : never; export { type DownloadStream as D, type GlyphInfo as G, type InlinedSource as I, type SMPSource as S, type TileInfo as T, Writer as W, type ZipEntry as Z, type SMPStyle as a, type StyleInlinedSources as b, type TileFormat as c, type GlyphRange as d, SUPPORTED_SOURCE_TYPES as e, type Source as f, type SourceInfo as g, type SourceInternal as h };