draw-libre 0.6.0 → 1.0.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/index.d.ts CHANGED
@@ -1,5 +1,568 @@
1
- import { CircleLayerSpecification, LineLayerSpecification, FillLayerSpecification } from 'maplibre-gl';
2
- import mapboxgl from 'mapbox-gl';
1
+ /// <reference types="geojson" />
2
+ //#endregion
3
+ //#region src/types.g.d.ts
4
+ type ColorSpecification = string;
5
+ type ProjectionDefinitionT = [string, string, number];
6
+ type ProjectionDefinitionSpecification = string | ProjectionDefinitionT | PropertyValueSpecification<ProjectionDefinitionT>;
7
+ type ResolvedImageSpecification = string;
8
+ type ExpressionInputType = string | number | boolean;
9
+ type VariableExpressionSpecification = ['var', string];
10
+ type CollatorExpressionSpecification = ['collator', {
11
+ 'case-sensitive'?: boolean | ExpressionSpecification;
12
+ 'diacritic-sensitive'?: boolean | ExpressionSpecification;
13
+ locale?: string | ExpressionSpecification;
14
+ }];
15
+ type InterpolationSpecification = ['linear'] | ['exponential', number] | ['cubic-bezier', number, number, number, number];
16
+ type ExpressionSpecification = ['array', ExpressionSpecification] | ['array', 'string' | 'number' | 'boolean', ExpressionSpecification] | ['array', 'string' | 'number' | 'boolean', number, ExpressionSpecification] | ['boolean', unknown | ExpressionSpecification, ...(unknown | ExpressionSpecification)[]] | CollatorExpressionSpecification | ['format', ...(string | ['image', ExpressionSpecification] | ExpressionSpecification | {
17
+ 'font-scale'?: number | ExpressionSpecification;
18
+ 'text-font'?: ExpressionSpecification;
19
+ 'text-color'?: ColorSpecification | ExpressionSpecification;
20
+ 'vertical-align'?: 'bottom' | 'center' | 'top';
21
+ })[]] | ['image', string | ExpressionSpecification] | ['literal', unknown] | ['semiliteral', unknown] | ['number', unknown | ExpressionSpecification, ...(unknown | ExpressionSpecification)[]] | ['number-format', number | ExpressionSpecification, {
22
+ 'locale'?: string | ExpressionSpecification;
23
+ 'currency'?: string | ExpressionSpecification;
24
+ 'min-fraction-digits'?: number | ExpressionSpecification;
25
+ 'max-fraction-digits'?: number | ExpressionSpecification;
26
+ }] | ['number-format', number | ExpressionSpecification, {
27
+ 'locale'?: string | ExpressionSpecification;
28
+ 'unit'?: string | ExpressionSpecification;
29
+ 'min-fraction-digits'?: number | ExpressionSpecification;
30
+ 'max-fraction-digits'?: number | ExpressionSpecification;
31
+ }] | ['object', unknown | ExpressionSpecification, ...(unknown | ExpressionSpecification)[]] | ['string', unknown | ExpressionSpecification, ...(unknown | ExpressionSpecification)[]] | ['to-boolean', unknown | ExpressionSpecification] | ['to-color', unknown | ExpressionSpecification, ...(unknown | ExpressionSpecification)[]] | ['to-number', unknown | ExpressionSpecification, ...(unknown | ExpressionSpecification)[]] | ['to-string', unknown | ExpressionSpecification] | ['typeof', unknown | ExpressionSpecification] | ['accumulated'] | ['feature-state', string | ExpressionSpecification] | ['geometry-type'] | ['id'] | ['line-progress'] | ['properties'] | ['at', number | ExpressionSpecification, ExpressionSpecification] | ['get', string | ExpressionSpecification, ExpressionSpecification?] | ['global-state', string] | ['has', string | ExpressionSpecification, ExpressionSpecification?] | ['in', null | ExpressionInputType | ExpressionSpecification, string | ExpressionSpecification] | ['index-of', null | ExpressionInputType | ExpressionSpecification, string | ExpressionSpecification, (number | ExpressionSpecification)?] | ['length', string | ExpressionSpecification] | ['slice', string | ExpressionSpecification, number | ExpressionSpecification, (number | ExpressionSpecification)?] | ['!', boolean | ExpressionSpecification] | ['!=', null | ExpressionInputType | ExpressionSpecification, null | ExpressionInputType | ExpressionSpecification, (CollatorExpressionSpecification | VariableExpressionSpecification)?] | ['<', string | number | ExpressionSpecification, string | number | ExpressionSpecification, (CollatorExpressionSpecification | VariableExpressionSpecification)?] | ['<=', string | number | ExpressionSpecification, string | number | ExpressionSpecification, (CollatorExpressionSpecification | VariableExpressionSpecification)?] | ['==', null | ExpressionInputType | ExpressionSpecification, null | ExpressionInputType | ExpressionSpecification, (CollatorExpressionSpecification | VariableExpressionSpecification)?] | ['>', string | number | ExpressionSpecification, string | number | ExpressionSpecification, (CollatorExpressionSpecification | VariableExpressionSpecification)?] | ['>=', string | number | ExpressionSpecification, string | number | ExpressionSpecification, (CollatorExpressionSpecification | VariableExpressionSpecification)?] | ['all', ...(boolean | ExpressionSpecification)[]] | ['any', ...(boolean | ExpressionSpecification)[]] | ['case', boolean | ExpressionSpecification, null | ExpressionInputType | ExpressionSpecification, ...(boolean | null | ExpressionInputType | ExpressionSpecification)[], null | ExpressionInputType | ExpressionSpecification] | ['coalesce', ...(ExpressionInputType | ExpressionSpecification)[]] | ['match', string | number | ExpressionSpecification, string | number | string[] | number[], null | ExpressionInputType | ExpressionSpecification, ...(string | number | string[] | number[] | null | ExpressionInputType | ExpressionSpecification)[],
32
+ // repeated as above
33
+ null | ExpressionInputType | ExpressionSpecification] | ['within', GeoJSON.GeoJSON] | ['interpolate', InterpolationSpecification, number | ExpressionSpecification, ...(number | ColorSpecification | ExpressionSpecification | ProjectionDefinitionSpecification)[]] | ['interpolate-hcl', InterpolationSpecification, number | ExpressionSpecification, ...(number | ColorSpecification | ExpressionSpecification)[]] | ['interpolate-lab', InterpolationSpecification, number | ExpressionSpecification, ...(number | ColorSpecification | ExpressionSpecification)[]] | ['step', number | ExpressionSpecification, ExpressionInputType | ExpressionSpecification, ...(number | ExpressionInputType | ExpressionSpecification)[]] | ['let', string, ExpressionInputType | ExpressionSpecification, ...(string | ExpressionInputType | ExpressionSpecification)[]] | VariableExpressionSpecification | ['concat', ...(ExpressionInputType | ExpressionSpecification)[]] | ['downcase', string | ExpressionSpecification] | ['is-supported-script', string | ExpressionSpecification] | ['join', string[] | ExpressionSpecification, string | ExpressionSpecification] | ['resolved-locale', CollatorExpressionSpecification] | ['split', string | ExpressionSpecification, string | ExpressionSpecification] | ['upcase', string | ExpressionSpecification] | ['rgb', number | ExpressionSpecification, number | ExpressionSpecification, number | ExpressionSpecification] | ['rgba', number | ExpressionSpecification, number | ExpressionSpecification, number | ExpressionSpecification, number | ExpressionSpecification] | ['to-rgba', ColorSpecification | ExpressionSpecification] | ['-', number | ExpressionSpecification, (number | ExpressionSpecification)?] | ['*', number | ExpressionSpecification, number | ExpressionSpecification, ...(number | ExpressionSpecification)[]] | ['/', number | ExpressionSpecification, number | ExpressionSpecification] | ['%', number | ExpressionSpecification, number | ExpressionSpecification] | ['^', number | ExpressionSpecification, number | ExpressionSpecification] | ['+', ...(number | ExpressionSpecification)[]] | ['abs', number | ExpressionSpecification] | ['acos', number | ExpressionSpecification] | ['asin', number | ExpressionSpecification] | ['atan', number | ExpressionSpecification] | ['ceil', number | ExpressionSpecification] | ['cos', number | ExpressionSpecification] | ['distance', GeoJSON.GeoJSON] | ['e'] | ['floor', number | ExpressionSpecification] | ['ln', number | ExpressionSpecification] | ['ln2'] | ['log10', number | ExpressionSpecification] | ['log2', number | ExpressionSpecification] | ['max', number | ExpressionSpecification, ...(number | ExpressionSpecification)[]] | ['min', number | ExpressionSpecification, ...(number | ExpressionSpecification)[]] | ['pi'] | ['round', number | ExpressionSpecification] | ['sin', number | ExpressionSpecification] | ['sqrt', number | ExpressionSpecification] | ['tan', number | ExpressionSpecification] | ['zoom'] | ['heatmap-density'] | ['elevation'] | ['global-state', string];
34
+ type ExpressionFilterSpecification = boolean | ExpressionSpecification;
35
+ type LegacyFilterSpecification = ['has', string] | ['!has', string] | ['==', string, string | number | boolean] | ['!=', string, string | number | boolean] | ['>', string, string | number | boolean] | ['>=', string, string | number | boolean] | ['<', string, string | number | boolean] | ['<=', string, string | number | boolean] | ['in', string, ...(string | number | boolean)[]] | ['!in', string, ...(string | number | boolean)[]] | ['all', ...LegacyFilterSpecification[]] | ['any', ...LegacyFilterSpecification[]] | ['none', ...LegacyFilterSpecification[]];
36
+ type FilterSpecification = ExpressionFilterSpecification | LegacyFilterSpecification;
37
+ type VisibilitySpecification = 'visible' | 'none' | ExpressionSpecification;
38
+ type TransitionSpecification = {
39
+ duration?: number;
40
+ delay?: number;
41
+ };
42
+ type CameraFunctionSpecification<T> = {
43
+ type: 'exponential';
44
+ stops: Array<[number, T]>;
45
+ } | {
46
+ type: 'interval';
47
+ stops: Array<[number, T]>;
48
+ };
49
+ type SourceFunctionSpecification<T> = {
50
+ type: 'exponential';
51
+ stops: Array<[number, T]>;
52
+ property: string;
53
+ default?: T;
54
+ } | {
55
+ type: 'interval';
56
+ stops: Array<[number, T]>;
57
+ property: string;
58
+ default?: T;
59
+ } | {
60
+ type: 'categorical';
61
+ stops: Array<[string | number | boolean, T]>;
62
+ property: string;
63
+ default?: T;
64
+ } | {
65
+ type: 'identity';
66
+ property: string;
67
+ default?: T;
68
+ };
69
+ type CompositeFunctionSpecification<T> = {
70
+ type: 'exponential';
71
+ stops: Array<[{
72
+ zoom: number;
73
+ value: number;
74
+ }, T]>;
75
+ property: string;
76
+ default?: T;
77
+ } | {
78
+ type: 'interval';
79
+ stops: Array<[{
80
+ zoom: number;
81
+ value: number;
82
+ }, T]>;
83
+ property: string;
84
+ default?: T;
85
+ } | {
86
+ type: 'categorical';
87
+ stops: Array<[{
88
+ zoom: number;
89
+ value: string | number | boolean;
90
+ }, T]>;
91
+ property: string;
92
+ default?: T;
93
+ };
94
+ type PropertyValueSpecification<T> = T | CameraFunctionSpecification<T> | ExpressionSpecification;
95
+ type DataDrivenPropertyValueSpecification<T> = T | CameraFunctionSpecification<T> | SourceFunctionSpecification<T> | CompositeFunctionSpecification<T> | ExpressionSpecification;
96
+ type FillLayerSpecification = {
97
+ /**
98
+ * Unique layer name.
99
+ */
100
+ "id": string;
101
+ "type": "fill";
102
+ /**
103
+ * Arbitrary properties useful to track with the layer, but do not influence rendering. Properties should be prefixed to avoid collisions, like 'maplibre:'.
104
+ *
105
+ * @example
106
+ * ```json
107
+ * {"source:comment": "Hydrology FCCODE 460 - Narrow wash"}
108
+ * ```
109
+ */
110
+ "metadata"?: unknown;
111
+ /**
112
+ * Name of a source description to be used for this layer. Required for all layer types except `background`.
113
+ */
114
+ "source": string;
115
+ /**
116
+ * Layer to use from a vector tile source. Required for vector tile sources; prohibited for all other source types, including GeoJSON sources.
117
+ */
118
+ "source-layer"?: string;
119
+ /**
120
+ * The minimum zoom level for the layer. At zoom levels less than the minzoom, the layer will be hidden.
121
+ */
122
+ "minzoom"?: number;
123
+ /**
124
+ * The maximum zoom level for the layer. At zoom levels equal to or greater than the maxzoom, the layer will be hidden.
125
+ */
126
+ "maxzoom"?: number;
127
+ /**
128
+ * A expression specifying conditions on source features. Only features that match the filter are displayed. Zoom expressions in filters are only evaluated at integer zoom levels. The `feature-state` expression is not supported in filter expressions.
129
+ */
130
+ "filter"?: FilterSpecification;
131
+ /**
132
+ * Layout properties for the layer.
133
+ */
134
+ "layout"?: {
135
+ /**
136
+ * Sorts features in ascending order based on this value. Features with a higher sort key will appear above features with a lower sort key.
137
+ */
138
+ "fill-sort-key"?: DataDrivenPropertyValueSpecification<number>;
139
+ /**
140
+ * Whether this layer is displayed.
141
+ *
142
+ * @default
143
+ * ```json
144
+ * "visible"
145
+ * ```
146
+ */
147
+ "visibility"?: VisibilitySpecification;
148
+ };
149
+ /**
150
+ * Default paint properties for this layer.
151
+ */
152
+ "paint"?: {
153
+ /**
154
+ * Whether or not the fill should be antialiased.
155
+ *
156
+ * @default
157
+ * ```json
158
+ * true
159
+ * ```
160
+ */
161
+ "fill-antialias"?: PropertyValueSpecification<boolean>;
162
+ /**
163
+ * The opacity of the entire fill layer. In contrast to the `fill-color`, this value will also affect the 1px stroke around the fill, if the stroke is used.
164
+ *
165
+ * @default
166
+ * ```json
167
+ * 1
168
+ * ```
169
+ */
170
+ "fill-opacity"?: DataDrivenPropertyValueSpecification<number>;
171
+ "fill-opacity-transition"?: TransitionSpecification;
172
+ /**
173
+ * Opacity applied to the layer as a whole. Unlike `fill-opacity` and alpha values in `fill-color`, which are applied per feature and accumulate where fills overlap, `fill-layer-opacity` is applied once so overlapping fills appear as a single surface at the given opacity. When both `fill-opacity` and `fill-layer-opacity` are set, the per-feature, overlap accumulation is preserved, then `fill-layer-opacity` composites the result. This property affects only the layer it is set on and cannot be used to composite multiple layers together or control how this layer blends with layers above or below it.
174
+ *
175
+ * ![fill-opacity vs. fill-layer-opacity](assets/fill-layer-opacity.svg)
176
+ *
177
+ * @default
178
+ * ```json
179
+ * 1
180
+ * ```
181
+ */
182
+ "fill-layer-opacity"?: PropertyValueSpecification<number>;
183
+ "fill-layer-opacity-transition"?: TransitionSpecification;
184
+ /**
185
+ * The color of the filled part of this layer. This color can be specified as `rgba` with an alpha component and the color's opacity will not affect the opacity of the 1px stroke, if it is used. When used with an SDF fill pattern, this serves as the foreground color of the pattern.
186
+ *
187
+ * @default
188
+ * ```json
189
+ * "#000000"
190
+ * ```
191
+ */
192
+ "fill-color"?: DataDrivenPropertyValueSpecification<ColorSpecification>;
193
+ "fill-color-transition"?: TransitionSpecification;
194
+ /**
195
+ * The outline color of the fill. Matches the value of `fill-color` if unspecified.
196
+ */
197
+ "fill-outline-color"?: DataDrivenPropertyValueSpecification<ColorSpecification>;
198
+ "fill-outline-color-transition"?: TransitionSpecification;
199
+ /**
200
+ * The geometry's offset. Values are `[x, y]` where negatives indicate left and up, respectively.
201
+ *
202
+ * @default
203
+ * ```json
204
+ * [0, 0]
205
+ * ```
206
+ */
207
+ "fill-translate"?: PropertyValueSpecification<[number, number]>;
208
+ "fill-translate-transition"?: TransitionSpecification;
209
+ /**
210
+ * Controls the frame of reference for `fill-translate`.
211
+ *
212
+ * @default
213
+ * ```json
214
+ * "map"
215
+ * ```
216
+ */
217
+ "fill-translate-anchor"?: PropertyValueSpecification<"map" | "viewport">;
218
+ /**
219
+ * Name of image in sprite to use for drawing image fills. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). Note that zoom-dependent expressions will be evaluated only at integer zoom levels.
220
+ */
221
+ "fill-pattern"?: DataDrivenPropertyValueSpecification<ResolvedImageSpecification>;
222
+ "fill-pattern-transition"?: TransitionSpecification;
223
+ };
224
+ };
225
+ type LineLayerSpecification = {
226
+ /**
227
+ * Unique layer name.
228
+ */
229
+ "id": string;
230
+ "type": "line";
231
+ /**
232
+ * Arbitrary properties useful to track with the layer, but do not influence rendering. Properties should be prefixed to avoid collisions, like 'maplibre:'.
233
+ *
234
+ * @example
235
+ * ```json
236
+ * {"source:comment": "Hydrology FCCODE 460 - Narrow wash"}
237
+ * ```
238
+ */
239
+ "metadata"?: unknown;
240
+ /**
241
+ * Name of a source description to be used for this layer. Required for all layer types except `background`.
242
+ */
243
+ "source": string;
244
+ /**
245
+ * Layer to use from a vector tile source. Required for vector tile sources; prohibited for all other source types, including GeoJSON sources.
246
+ */
247
+ "source-layer"?: string;
248
+ /**
249
+ * The minimum zoom level for the layer. At zoom levels less than the minzoom, the layer will be hidden.
250
+ */
251
+ "minzoom"?: number;
252
+ /**
253
+ * The maximum zoom level for the layer. At zoom levels equal to or greater than the maxzoom, the layer will be hidden.
254
+ */
255
+ "maxzoom"?: number;
256
+ /**
257
+ * A expression specifying conditions on source features. Only features that match the filter are displayed. Zoom expressions in filters are only evaluated at integer zoom levels. The `feature-state` expression is not supported in filter expressions.
258
+ */
259
+ "filter"?: FilterSpecification;
260
+ /**
261
+ * Layout properties for the layer.
262
+ */
263
+ "layout"?: {
264
+ /**
265
+ * The display of line endings.
266
+ *
267
+ * @default
268
+ * ```json
269
+ * "butt"
270
+ * ```
271
+ */
272
+ "line-cap"?: DataDrivenPropertyValueSpecification<"butt" | "round" | "square">;
273
+ /**
274
+ * The display of lines when joining.
275
+ *
276
+ * @default
277
+ * ```json
278
+ * "miter"
279
+ * ```
280
+ */
281
+ "line-join"?: DataDrivenPropertyValueSpecification<"bevel" | "round" | "miter">;
282
+ /**
283
+ * Used to automatically convert miter joins to bevel joins for sharp angles.
284
+ *
285
+ * @default
286
+ * ```json
287
+ * 2
288
+ * ```
289
+ */
290
+ "line-miter-limit"?: DataDrivenPropertyValueSpecification<number>;
291
+ /**
292
+ * Used to automatically convert round joins to miter joins for shallow angles.
293
+ *
294
+ * @default
295
+ * ```json
296
+ * 1.05
297
+ * ```
298
+ */
299
+ "line-round-limit"?: DataDrivenPropertyValueSpecification<number>;
300
+ /**
301
+ * Sorts features in ascending order based on this value. Features with a higher sort key will appear above features with a lower sort key.
302
+ */
303
+ "line-sort-key"?: DataDrivenPropertyValueSpecification<number>;
304
+ /**
305
+ * Whether this layer is displayed.
306
+ *
307
+ * @default
308
+ * ```json
309
+ * "visible"
310
+ * ```
311
+ */
312
+ "visibility"?: VisibilitySpecification;
313
+ };
314
+ /**
315
+ * Default paint properties for this layer.
316
+ */
317
+ "paint"?: {
318
+ /**
319
+ * The opacity at which the line will be drawn.
320
+ *
321
+ * @default
322
+ * ```json
323
+ * 1
324
+ * ```
325
+ */
326
+ "line-opacity"?: DataDrivenPropertyValueSpecification<number>;
327
+ "line-opacity-transition"?: TransitionSpecification;
328
+ /**
329
+ * Opacity applied to the layer as a whole. Unlike `line-opacity` and alpha values in `line-color`, which are applied per feature and accumulate where lines overlap, `line-layer-opacity` is applied once so overlapping lines appear as a single surface at the given opacity. When both `line-opacity` and `line-layer-opacity` are set, the per-feature, overlap accumulation is preserved, then layer-opacity composites the result. This property affects only the layer it is set on and cannot be used to composite multiple layers together or control how this layer blends with layers above or below it.
330
+ *
331
+ * ![line-opacity vs. line-layer-opacity](assets/line-layer-opacity.svg)
332
+ *
333
+ * @default
334
+ * ```json
335
+ * 1
336
+ * ```
337
+ */
338
+ "line-layer-opacity"?: PropertyValueSpecification<number>;
339
+ "line-layer-opacity-transition"?: TransitionSpecification;
340
+ /**
341
+ * The color with which the line will be drawn.
342
+ *
343
+ * @default
344
+ * ```json
345
+ * "#000000"
346
+ * ```
347
+ */
348
+ "line-color"?: DataDrivenPropertyValueSpecification<ColorSpecification>;
349
+ "line-color-transition"?: TransitionSpecification;
350
+ /**
351
+ * The geometry's offset. Values are `[x, y]` where negatives indicate left and up, respectively.
352
+ *
353
+ * @default
354
+ * ```json
355
+ * [0, 0]
356
+ * ```
357
+ */
358
+ "line-translate"?: PropertyValueSpecification<[number, number]>;
359
+ "line-translate-transition"?: TransitionSpecification;
360
+ /**
361
+ * Controls the frame of reference for `line-translate`.
362
+ *
363
+ * @default
364
+ * ```json
365
+ * "map"
366
+ * ```
367
+ */
368
+ "line-translate-anchor"?: PropertyValueSpecification<"map" | "viewport">;
369
+ /**
370
+ * Stroke thickness.
371
+ *
372
+ * @default
373
+ * ```json
374
+ * 1
375
+ * ```
376
+ */
377
+ "line-width"?: DataDrivenPropertyValueSpecification<number>;
378
+ "line-width-transition"?: TransitionSpecification;
379
+ /**
380
+ * Draws a line casing outside of a line's actual path. Value indicates the width of the inner gap.
381
+ */
382
+ "line-gap-width"?: DataDrivenPropertyValueSpecification<number>;
383
+ "line-gap-width-transition"?: TransitionSpecification;
384
+ /**
385
+ * The line's offset. For linear features, a positive value offsets the line to the right, relative to the direction of the line, and a negative value to the left. For polygon features, a positive value results in an inset, and a negative value results in an outset.
386
+ */
387
+ "line-offset"?: DataDrivenPropertyValueSpecification<number>;
388
+ "line-offset-transition"?: TransitionSpecification;
389
+ /**
390
+ * Blur applied to the line, in pixels.
391
+ */
392
+ "line-blur"?: DataDrivenPropertyValueSpecification<number>;
393
+ "line-blur-transition"?: TransitionSpecification;
394
+ /**
395
+ * Specifies the lengths of the alternating dashes and gaps that form the dash pattern. The lengths are later scaled by the line width. To convert a dash length to pixels, multiply the length by the current line width. GeoJSON sources with `lineMetrics: true` specified won't render dashed lines to the expected scale. Zoom-dependent expressions will be evaluated only at integer zoom levels. The only way to create an array value is using `["literal", [...]]`; arrays cannot be read from or derived from feature properties.
396
+ */
397
+ "line-dasharray"?: DataDrivenPropertyValueSpecification<Array<number>>;
398
+ "line-dasharray-transition"?: TransitionSpecification;
399
+ /**
400
+ * Name of image in sprite to use for drawing image lines. For seamless patterns, image width must be a factor of two (2, 4, 8, ..., 512). Note that zoom-dependent expressions will be evaluated only at integer zoom levels.
401
+ */
402
+ "line-pattern"?: DataDrivenPropertyValueSpecification<ResolvedImageSpecification>;
403
+ "line-pattern-transition"?: TransitionSpecification;
404
+ /**
405
+ * Defines a gradient with which to color a line feature. Can only be used with GeoJSON sources that specify `"lineMetrics": true`.
406
+ */
407
+ "line-gradient"?: ExpressionSpecification;
408
+ };
409
+ };
410
+ type CircleLayerSpecification = {
411
+ /**
412
+ * Unique layer name.
413
+ */
414
+ "id": string;
415
+ "type": "circle";
416
+ /**
417
+ * Arbitrary properties useful to track with the layer, but do not influence rendering. Properties should be prefixed to avoid collisions, like 'maplibre:'.
418
+ *
419
+ * @example
420
+ * ```json
421
+ * {"source:comment": "Hydrology FCCODE 460 - Narrow wash"}
422
+ * ```
423
+ */
424
+ "metadata"?: unknown;
425
+ /**
426
+ * Name of a source description to be used for this layer. Required for all layer types except `background`.
427
+ */
428
+ "source": string;
429
+ /**
430
+ * Layer to use from a vector tile source. Required for vector tile sources; prohibited for all other source types, including GeoJSON sources.
431
+ */
432
+ "source-layer"?: string;
433
+ /**
434
+ * The minimum zoom level for the layer. At zoom levels less than the minzoom, the layer will be hidden.
435
+ */
436
+ "minzoom"?: number;
437
+ /**
438
+ * The maximum zoom level for the layer. At zoom levels equal to or greater than the maxzoom, the layer will be hidden.
439
+ */
440
+ "maxzoom"?: number;
441
+ /**
442
+ * A expression specifying conditions on source features. Only features that match the filter are displayed. Zoom expressions in filters are only evaluated at integer zoom levels. The `feature-state` expression is not supported in filter expressions.
443
+ */
444
+ "filter"?: FilterSpecification;
445
+ /**
446
+ * Layout properties for the layer.
447
+ */
448
+ "layout"?: {
449
+ /**
450
+ * Sorts features in ascending order based on this value. Features with a higher sort key will appear above features with a lower sort key.
451
+ */
452
+ "circle-sort-key"?: DataDrivenPropertyValueSpecification<number>;
453
+ /**
454
+ * Whether this layer is displayed.
455
+ *
456
+ * @default
457
+ * ```json
458
+ * "visible"
459
+ * ```
460
+ */
461
+ "visibility"?: VisibilitySpecification;
462
+ };
463
+ /**
464
+ * Default paint properties for this layer.
465
+ */
466
+ "paint"?: {
467
+ /**
468
+ * Circle radius.
469
+ *
470
+ * @default
471
+ * ```json
472
+ * 5
473
+ * ```
474
+ */
475
+ "circle-radius"?: DataDrivenPropertyValueSpecification<number>;
476
+ "circle-radius-transition"?: TransitionSpecification;
477
+ /**
478
+ * The fill color of the circle.
479
+ *
480
+ * @default
481
+ * ```json
482
+ * "#000000"
483
+ * ```
484
+ */
485
+ "circle-color"?: DataDrivenPropertyValueSpecification<ColorSpecification>;
486
+ "circle-color-transition"?: TransitionSpecification;
487
+ /**
488
+ * Amount to blur the circle. 1 blurs the circle such that only the centerpoint is full opacity.
489
+ */
490
+ "circle-blur"?: DataDrivenPropertyValueSpecification<number>;
491
+ "circle-blur-transition"?: TransitionSpecification;
492
+ /**
493
+ * The opacity at which the circle will be drawn.
494
+ *
495
+ * @default
496
+ * ```json
497
+ * 1
498
+ * ```
499
+ */
500
+ "circle-opacity"?: DataDrivenPropertyValueSpecification<number>;
501
+ "circle-opacity-transition"?: TransitionSpecification;
502
+ /**
503
+ * The geometry's offset. Values are `[x, y]` where negatives indicate left and up, respectively.
504
+ *
505
+ * @default
506
+ * ```json
507
+ * [0, 0]
508
+ * ```
509
+ */
510
+ "circle-translate"?: PropertyValueSpecification<[number, number]>;
511
+ "circle-translate-transition"?: TransitionSpecification;
512
+ /**
513
+ * Controls the frame of reference for `circle-translate`.
514
+ *
515
+ * @default
516
+ * ```json
517
+ * "map"
518
+ * ```
519
+ */
520
+ "circle-translate-anchor"?: PropertyValueSpecification<"map" | "viewport">;
521
+ /**
522
+ * Controls the scaling behavior of the circle when the map is pitched.
523
+ *
524
+ * @default
525
+ * ```json
526
+ * "map"
527
+ * ```
528
+ */
529
+ "circle-pitch-scale"?: PropertyValueSpecification<"map" | "viewport">;
530
+ /**
531
+ * Orientation of circle when map is pitched.
532
+ *
533
+ * @default
534
+ * ```json
535
+ * "viewport"
536
+ * ```
537
+ */
538
+ "circle-pitch-alignment"?: PropertyValueSpecification<"map" | "viewport">;
539
+ /**
540
+ * The width of the circle's stroke. Strokes are placed outside of the `circle-radius`.
541
+ */
542
+ "circle-stroke-width"?: DataDrivenPropertyValueSpecification<number>;
543
+ "circle-stroke-width-transition"?: TransitionSpecification;
544
+ /**
545
+ * The stroke color of the circle.
546
+ *
547
+ * @default
548
+ * ```json
549
+ * "#000000"
550
+ * ```
551
+ */
552
+ "circle-stroke-color"?: DataDrivenPropertyValueSpecification<ColorSpecification>;
553
+ "circle-stroke-color-transition"?: TransitionSpecification;
554
+ /**
555
+ * The opacity of the circle's stroke.
556
+ *
557
+ * @default
558
+ * ```json
559
+ * 1
560
+ * ```
561
+ */
562
+ "circle-stroke-opacity"?: DataDrivenPropertyValueSpecification<number>;
563
+ "circle-stroke-opacity-transition"?: TransitionSpecification;
564
+ };
565
+ };
3
566
 
4
567
  type AnyFunction = (...args: any) => any;
5
568
  type DeepRequired<T> = T extends AnyFunction ? T : {
@@ -44,12 +607,26 @@ type Initial = InitialSteps & {
44
607
  geometry: "line" | "polygon";
45
608
  closeGeometry: boolean;
46
609
  };
610
+ type Paint<T extends {
611
+ paint?: unknown;
612
+ }> = NonNullable<T["paint"]> | Record<string, any>;
47
613
  interface LayersPaint {
614
+ onLinePoint?: Paint<CircleLayerSpecification>;
615
+ firstPoint?: Paint<CircleLayerSpecification>;
616
+ points?: Paint<CircleLayerSpecification>;
617
+ auxiliaryPoint?: Paint<CircleLayerSpecification>;
618
+ line?: Paint<LineLayerSpecification>;
619
+ dynamicLine?: Paint<LineLayerSpecification>;
620
+ polygon?: Paint<FillLayerSpecification>;
621
+ breakLine?: Paint<LineLayerSpecification>;
622
+ }
623
+ interface StrictLayersPaint {
48
624
  onLinePoint?: CircleLayerSpecification["paint"];
49
625
  firstPoint?: CircleLayerSpecification["paint"];
50
626
  points?: CircleLayerSpecification["paint"];
51
627
  auxiliaryPoint?: CircleLayerSpecification["paint"];
52
628
  line?: LineLayerSpecification["paint"];
629
+ dynamicLine?: LineLayerSpecification["paint"];
53
630
  polygon?: FillLayerSpecification["paint"];
54
631
  breakLine?: LineLayerSpecification["paint"];
55
632
  }
@@ -63,6 +640,7 @@ interface Locale {
63
640
  break?: string;
64
641
  closeLine?: string;
65
642
  createPolygon?: string;
643
+ removePoint?: string;
66
644
  }
67
645
  interface DrawOptions {
68
646
  pointGeneration?: "manual" | "auto";
@@ -89,7 +667,11 @@ interface DrawOptions {
89
667
  dynamicLine?: boolean;
90
668
  }
91
669
  type RequiredDrawOptions = DeepRequired<Omit<DrawOptions, "layersPaint">> & {
92
- layersPaint: LayersPaint;
670
+ layersPaint: StrictLayersPaint;
671
+ interaction: {
672
+ lineHitRadius: number;
673
+ pointHitRadius: number;
674
+ };
93
675
  };
94
676
 
95
677
  declare class ListNode {
@@ -99,94 +681,117 @@ declare class ListNode {
99
681
  constructor(val?: Step | null, next?: ListNode | null, prev?: ListNode | null);
100
682
  }
101
683
 
102
- type UnifiedMap = maplibregl.Map & mapboxgl.Map;
103
- type IControl = maplibregl.IControl & mapboxgl.IControl;
684
+ interface MapLike {
685
+ getContainer(): HTMLElement;
686
+ getCanvasContainer(): HTMLElement;
687
+ }
688
+ interface DrawLibreControl {
689
+ onAdd(map: MapLike): HTMLElement;
690
+ onRemove(map: MapLike): void;
691
+ }
692
+ type UnifiedMap = MapLike;
104
693
 
105
694
  interface ModeEvent {
106
695
  geometry: Mode;
107
696
  closedGeometry: boolean;
108
697
  }
109
- interface UndoEvent {
698
+ interface StepEvent {
699
+ id: StepId;
110
700
  coordinates: LatLng;
111
- originalEvent: MouseEvent;
112
- id: Uuid;
113
701
  total: number;
114
702
  timestamp: number;
115
- target: UnifiedMap;
703
+ target: MapLike;
704
+ }
705
+ interface HistoryEvent {
706
+ originalEvent?: Event;
707
+ id?: StepId;
708
+ coordinates?: LatLng;
709
+ total: number;
710
+ timestamp: number;
711
+ target: MapLike;
712
+ }
713
+ interface UndoEvent extends HistoryEvent {
116
714
  type: "mdl:undo";
117
715
  }
716
+ interface RedoEvent extends HistoryEvent {
717
+ type: "mdl:redo";
718
+ }
118
719
  interface RemoveAllEvent {
119
- originalEvent: MouseEvent;
720
+ originalEvent?: Event;
120
721
  type: "mdl:removeall";
121
- target: UnifiedMap;
722
+ target: MapLike;
122
723
  }
123
724
  interface SaveEvent {
124
- originalEvent: MouseEvent;
725
+ originalEvent?: Event;
125
726
  timestamp: number;
126
727
  steps: Step[];
127
728
  mode: ModeEvent;
128
- target: UnifiedMap;
729
+ target: MapLike;
129
730
  type: "mdl:save";
130
731
  }
131
- interface PointRightClickRemoveEvent {
132
- id: Uuid;
133
- total: number;
134
- timestamp: number;
135
- target: UnifiedMap;
136
- coordinates: LatLng;
137
- type: "mdl:rightclickremove";
732
+ interface PointRemoveEvent extends StepEvent {
733
+ type: "mdl:pointremove";
138
734
  }
139
- interface PointAddEvent {
140
- id: Uuid;
141
- total: number;
142
- timestamp: number;
143
- target: UnifiedMap;
144
- coordinates: LatLng;
735
+ interface PointAddEvent extends StepEvent {
145
736
  mode: ModeEvent;
146
737
  type: "mdl:add";
147
738
  }
148
739
  interface PointMoveEvent {
149
740
  start_coordinates: LatLng;
150
741
  end_coordinates: LatLng;
151
- id: Uuid;
742
+ id: StepId;
152
743
  total: number;
153
744
  timestamp: number;
154
- target: UnifiedMap;
745
+ target: MapLike;
155
746
  type: "mdl:moveend";
156
747
  }
157
- interface PointEnterEvent {
158
- coordinates: LatLng;
159
- id: Uuid;
160
- total: number;
161
- timestamp: number;
162
- target: UnifiedMap;
748
+ interface PointEnterEvent extends StepEvent {
163
749
  type: "mdl:pointenter";
164
750
  }
165
- interface PointLeaveEvent {
166
- coordinates: LatLng;
167
- id: Uuid;
168
- total: number;
169
- timestamp: number;
170
- target: UnifiedMap;
751
+ interface PointLeaveEvent extends StepEvent {
171
752
  type: "mdl:pointleave";
172
753
  }
173
754
  interface ModeChangeEvent {
174
755
  mode: Mode | "break";
175
- target: UnifiedMap;
756
+ target: MapLike;
176
757
  type: "mdl:modechanged";
177
758
  }
178
759
  interface UndoStackChangeEvent {
179
- mode: Mode | "break";
180
- target: UnifiedMap;
760
+ length: number;
761
+ target: MapLike;
181
762
  type: "mdl:undostackchanged";
182
763
  }
183
764
  interface RedoStackChangeEvent {
184
- mode: Mode | "break";
185
- target: UnifiedMap;
765
+ length: number;
766
+ target: MapLike;
186
767
  type: "mdl:redostackchanged";
187
768
  }
769
+ interface BreakEvent {
770
+ target: MapLike;
771
+ type: "mdl:break";
772
+ }
773
+ type DrawLibreEventType = {
774
+ "mdl:add": PointAddEvent;
775
+ "mdl:pointremove": PointRemoveEvent;
776
+ "mdl:pointenter": PointEnterEvent;
777
+ "mdl:pointleave": PointLeaveEvent;
778
+ "mdl:moveend": PointMoveEvent;
779
+ "mdl:undo": UndoEvent;
780
+ "mdl:redo": RedoEvent;
781
+ "mdl:removeall": RemoveAllEvent;
782
+ "mdl:save": SaveEvent;
783
+ "mdl:break": BreakEvent;
784
+ "mdl:modechanged": ModeChangeEvent;
785
+ "mdl:undostackchanged": UndoStackChangeEvent;
786
+ "mdl:redostackchanged": RedoStackChangeEvent;
787
+ };
788
+
789
+ interface DrawLibreSubscription {
790
+ unsubscribe(): void;
791
+ }
188
792
 
189
- declare class DrawLibre implements IControl {
793
+ declare class DrawLibre implements DrawLibreControl {
794
+ #private;
190
795
  private container;
191
796
  private store;
192
797
  private mode;
@@ -197,16 +802,16 @@ declare class DrawLibre implements IControl {
197
802
  private cursor;
198
803
  private mouseEvents;
199
804
  private timelineAdapter;
805
+ private projection;
806
+ private readonly events;
200
807
  private renderer;
201
- static instance: DrawLibre | null;
202
- private constructor();
203
- static getInstance(options?: DrawOptions): DrawLibre;
808
+ constructor(options?: DrawOptions);
204
809
  /**
205
810
  * DO NOT USE IMPLICITLY. PASS TO map.addControl().
206
811
  *
207
812
  * @example ```ts
208
813
  * const map = new Map();
209
- * const draw = DrawLibre.getInstance();
814
+ * const draw = new DrawLibre();
210
815
  * map.addControl(draw)
211
816
  * ```
212
817
  *
@@ -218,13 +823,13 @@ declare class DrawLibre implements IControl {
218
823
  * to the DOM: the map will insert the control's element into the DOM
219
824
  * as necessary.
220
825
  */
221
- onAdd: (map: UnifiedMap) => HTMLElement;
826
+ onAdd: (map: MapLike) => HTMLElement;
222
827
  /**
223
828
  * DO NOT USE IMPLICITLY. PASS TO map.removeControl().
224
829
  *
225
830
  * @example ```ts
226
831
  * const map = new Map();
227
- * const draw = DrawLibre.getInstance();
832
+ * const draw = new DrawLibre();
228
833
  * map.removeControl(draw)
229
834
  * ```
230
835
  *
@@ -234,7 +839,7 @@ declare class DrawLibre implements IControl {
234
839
  */
235
840
  onRemove: () => void;
236
841
  /**
237
- * Adds a series of steps to the store. If a step ID is not provided, it will be automatically generated.
842
+ * Replaces all steps in the store. If a step ID is not provided, it will be automatically generated.
238
843
  *
239
844
  * @param step - The step to add to the store, which can be of type Step or LatLng.
240
845
  */
@@ -245,14 +850,14 @@ declare class DrawLibre implements IControl {
245
850
  * @param id - The ID of the step to retrieve.
246
851
  * @returns The step with the specified ID, or null if not found.
247
852
  */
248
- findStepById: (id: StepId) => Step | null | undefined;
853
+ findStepById: (id: StepId) => Step | null;
249
854
  /**
250
855
  * Retrieves a node from the store by its ID.
251
856
  *
252
857
  * @param id - The ID of the node to retrieve.
253
858
  * @returns The node with the specified ID, or null if not found.
254
859
  */
255
- findNodeById: (id: StepId) => ListNode | null | undefined;
860
+ findNodeById: (id: StepId) => ListNode | null;
256
861
  /**
257
862
  * Retrieves all steps from the store, either as an array or as a linked list, based on the type specified.
258
863
  *
@@ -260,16 +865,18 @@ declare class DrawLibre implements IControl {
260
865
  * @returns An array of all steps or the linked list of steps.
261
866
  */
262
867
  getAllSteps: (type?: "array" | "linkedlist") => Step[] | {
263
- head: ListNode | null | undefined;
264
- tail: ListNode | null | undefined;
265
- size: number | undefined;
868
+ head: ListNode | null;
869
+ tail: ListNode | null;
870
+ size: number;
266
871
  };
267
- setOptions: (fn: (options: RequiredDrawOptions) => RequiredDrawOptions) => void;
268
- undo: (e: Event) => void;
269
- redo: (e: Event) => void;
270
- clear: () => void;
271
- save: () => void;
272
- removeAllSteps: () => void;
872
+ undo: (e?: Event) => void;
873
+ redo: (e?: Event) => void;
874
+ clear: (e?: Event) => void;
875
+ save: (e?: Event) => void;
876
+ removeAllSteps: (e?: Event) => void;
877
+ on: <T extends keyof DrawLibreEventType>(type: T, listener: (event: DrawLibreEventType[T]) => void) => DrawLibreSubscription;
878
+ once: <T extends keyof DrawLibreEventType>(type: T, listener: (event: DrawLibreEventType[T]) => void) => DrawLibreSubscription;
879
+ off: <T extends keyof DrawLibreEventType>(type: T, listener: (event: DrawLibreEventType[T]) => void) => void;
273
880
  }
274
881
 
275
- export { type DrawOptions, type ModeChangeEvent, type PointAddEvent, type PointEnterEvent, type PointLeaveEvent, type PointMoveEvent, type PointRightClickRemoveEvent, type RedoStackChangeEvent, type RemoveAllEvent, type RequiredDrawOptions, type SaveEvent, type UndoEvent, type UndoStackChangeEvent, type UnifiedMap, DrawLibre as default };
882
+ export { type BreakEvent, type DrawLibreControl, type DrawLibreEventType, type DrawLibreSubscription, type DrawOptions, type LatLng, type MapLike, type ModeChangeEvent, type PointAddEvent, type PointEnterEvent, type PointLeaveEvent, type PointMoveEvent, type PointRemoveEvent, type RedoEvent, type RedoStackChangeEvent, type RemoveAllEvent, type RequiredDrawOptions, type SaveEvent, type Step, type StepId, type UndoEvent, type UndoStackChangeEvent, type UnifiedMap, DrawLibre as default };