maplibre-gl-layers 0.1.0 → 0.3.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/types.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: maplibre-gl-layers
3
- * version: 0.1.0
3
+ * version: 0.3.0
4
4
  * description: MapLibre's layer extension library enabling the display, movement, and modification of large numbers of dynamic sprite images
5
5
  * author: Kouji Matsui (@kekyo@mi.kekyo.net)
6
6
  * license: MIT
7
7
  * repository.url: https://github.com/kekyo/maplibre-gl-layers.git
8
- * git.commit.hash: 88b09a93779279947d9c6b1e3a7538d4d197dbcb
8
+ * git.commit.hash: fd90d1fd66e4ca9c0defa49e68ecaeb9c14fbd06
9
9
  */
10
10
 
11
11
  import { CustomLayerInterface } from 'maplibre-gl';
@@ -150,7 +150,8 @@ export interface SpriteImageDefinitionInitEntry extends SpriteImageDefinitionIni
150
150
  }
151
151
  /**
152
152
  * Parameters required to construct a new sprite.
153
- * @param TTag Tag type.
153
+ *
154
+ * @template TTag Tag type.
154
155
  */
155
156
  export interface SpriteInit<TTag> {
156
157
  /** Whether the sprite starts enabled. Defaults to true. */
@@ -162,26 +163,73 @@ export interface SpriteInit<TTag> {
162
163
  /** Optional tag value; null or omission means no tag. */
163
164
  tag?: TTag | null;
164
165
  }
165
- /** Sprite image state evaluated at runtime. */
166
+ /**
167
+ * Entry for batch sprite creation, pairing a sprite identifier with its initial settings.
168
+ *
169
+ * @template TTag Tag type.
170
+ */
171
+ export interface SpriteInitEntry<TTag> extends SpriteInit<TTag> {
172
+ /** Sprite identifier. */
173
+ spriteId: string;
174
+ }
175
+ /**
176
+ * Batch payload accepted by addSprites. Supports both record and array inputs.
177
+ *
178
+ * @template TTag Tag type.
179
+ */
180
+ export type SpriteInitCollection<TTag> = Record<string, SpriteInit<TTag>> | readonly SpriteInitEntry<TTag>[];
181
+ /**
182
+ * Sprite image state evaluated at runtime.
183
+ *
184
+ * @property {number} subLayer - Sub-layer index the image belongs to.
185
+ * @property {number} order - Ordering slot within the sub-layer.
186
+ * @property {string} imageId - Identifier of the registered image or glyph.
187
+ * @property {SpriteMode} mode - Rendering mode applied to the image.
188
+ * @property {number} opacity - Opacity multiplier applied when rendering.
189
+ * @property {number} scale - Scale factor converting pixels to meters.
190
+ * @property {Readonly<SpriteAnchor>} anchor - Anchor coordinates resolved for the image.
191
+ * @property {Readonly<SpriteImageOffset>} offset - Offset applied relative to the anchor point.
192
+ * @property {number} rotateDeg - Additional rotation in degrees.
193
+ * @property {boolean} autoRotation - Indicates whether auto-rotation is active.
194
+ * @property {number} autoRotationMinDistanceMeters - Minimum travel distance before auto-rotation updates.
195
+ * @property {number} resolvedBaseRotateDeg - Internal base rotation resolved for the current frame.
196
+ * @property {number} displayedRotateDeg - Rotation value actually used for rendering.
197
+ * @property {Readonly<SpriteImageOriginLocation> | undefined} originLocation - Optional reference to another image used for anchoring.
198
+ */
166
199
  export interface SpriteImageState {
200
+ /** Sub-layer index the image belongs to. */
167
201
  readonly subLayer: number;
202
+ /** Ordering slot within the sub-layer. */
168
203
  readonly order: number;
204
+ /** Identifier of the registered image or glyph. */
169
205
  readonly imageId: string;
206
+ /** Rendering mode applied to the image. */
170
207
  readonly mode: SpriteMode;
208
+ /** Opacity multiplier applied when rendering. */
171
209
  readonly opacity: number;
210
+ /** Scale factor converting pixels to meters. */
172
211
  readonly scale: number;
212
+ /** Anchor coordinates resolved for the image. */
173
213
  readonly anchor: Readonly<SpriteAnchor>;
214
+ /** Offset applied relative to the anchor point. */
174
215
  readonly offset: Readonly<SpriteImageOffset>;
216
+ /** Additional rotation in degrees. */
175
217
  readonly rotateDeg: number;
218
+ /** Indicates whether auto-rotation is active. */
176
219
  readonly autoRotation: boolean;
220
+ /** Minimum travel distance before auto-rotation updates. */
177
221
  readonly autoRotationMinDistanceMeters: number;
222
+ /** Internal base rotation resolved for the current frame. */
178
223
  readonly resolvedBaseRotateDeg: number;
224
+ /** Rotation value actually used for rendering. */
179
225
  readonly displayedRotateDeg: number;
226
+ /** Optional reference to another image used for anchoring. */
180
227
  readonly originLocation: Readonly<SpriteImageOriginLocation> | undefined;
181
228
  }
182
229
  /**
183
230
  * Current runtime state of a sprite.
184
- * @param TTag Tag type.
231
+ *
232
+ * @template TTag Tag type.
185
233
  */
186
234
  export interface SpriteCurrentState<TTag> {
187
235
  /** Sprite identifier. */
@@ -234,66 +282,202 @@ export interface SpriteImageRotationInterpolationOptions {
234
282
  /** Interpolation settings for offset.offsetDeg; null disables interpolation. */
235
283
  offsetDeg?: SpriteNumericInterpolationOptions | null;
236
284
  }
237
- /** Base structure for sprite updates. */
285
+ /**
286
+ * Base structure for sprite updates.
287
+ *
288
+ * @template TTag Tag type stored on the sprite.
289
+ * @property {boolean | undefined} isEnabled - Optional toggle to enable or disable the sprite.
290
+ * @property {SpriteLocation | undefined} location - Optional target location for the sprite.
291
+ * @property {SpriteInterpolationOptions | null | undefined} interpolation - Optional interpolation settings; `null` disables interpolation.
292
+ * @property {TTag | null | undefined} tag - Optional tag value to replace the current one; `null` clears the tag.
293
+ */
238
294
  export interface SpriteUpdateEntryBase<TTag> {
295
+ /** Optional toggle to enable or disable the sprite. */
239
296
  isEnabled?: boolean;
297
+ /** Optional target location for the sprite. */
240
298
  location?: SpriteLocation;
299
+ /** Optional interpolation settings; `null` disables interpolation. */
241
300
  interpolation?: SpriteInterpolationOptions | null;
301
+ /** Optional tag value to replace the current one; `null` clears the tag. */
242
302
  tag?: TTag | null;
243
303
  }
244
- /** Update entry describing a sprite image modification. */
304
+ /**
305
+ * Update entry describing a sprite image modification.
306
+ *
307
+ * @property {number} subLayer - Target sub-layer that contains the image.
308
+ * @property {number} order - Order slot within the sub-layer.
309
+ * @property {SpriteImageDefinitionUpdate | null} image - Update payload, or `null` to remove the image.
310
+ */
245
311
  export interface SpriteImageDefinitionUpdateEntry {
312
+ /** Target sub-layer that contains the image. */
246
313
  subLayer: number;
314
+ /** Order slot within the sub-layer. */
247
315
  order: number;
316
+ /** Update payload, or `null` to remove the image. */
248
317
  image: SpriteImageDefinitionUpdate | null;
249
318
  }
250
- /** Sprite update entry with optional image list. */
319
+ /**
320
+ * Sprite update entry with optional image list.
321
+ *
322
+ * @template TTag Tag type stored on the sprite.
323
+ * @property {SpriteImageDefinitionUpdateEntry[] | undefined} images - Optional set of image updates.
324
+ */
251
325
  export interface SpriteUpdateEntry<TTag> extends SpriteUpdateEntryBase<TTag> {
326
+ /** Optional set of image updates. */
252
327
  images?: SpriteImageDefinitionUpdateEntry[];
253
328
  }
254
- /** Entry consumed by updateBulk to target a specific sprite. */
329
+ /** @deprecated Scheduled for removal in a future release. Use {@link SpriteLayerInterface.mutateSprites} instead. */
255
330
  export interface SpriteUpdateBulkEntry<T> extends SpriteUpdateEntry<T> {
331
+ /** @deprecated Scheduled for removal in a future release. Use {@link SpriteLayerInterface.mutateSprites} instead. */
256
332
  spriteId: string;
257
333
  }
258
- /** Callback-based helper for mutating sprite state. */
334
+ /**
335
+ * Callback-based helper for mutating sprite state.
336
+ *
337
+ * @template TTag Tag type stored on the sprite.
338
+ * @property {() => ReadonlyMap<number, ReadonlySet<number>>} getImageIndexMap - Retrieves the current image layout.
339
+ * @property {(subLayer: number, order: number, imageInit: SpriteImageDefinitionInit) => boolean} addImage - Adds an image definition.
340
+ * @property {(subLayer: number, order: number, imageUpdate: SpriteImageDefinitionUpdate) => boolean} updateImage - Applies image updates.
341
+ * @property {(subLayer: number, order: number) => boolean} removeImage - Removes an image slot.
342
+ */
259
343
  export interface SpriteUpdaterEntry<TTag> extends SpriteUpdateEntryBase<TTag> {
344
+ /** Retrieves the current image layout. */
260
345
  readonly getImageIndexMap: () => ReadonlyMap<number, ReadonlySet<number>>;
346
+ /** Adds an image definition. */
261
347
  readonly addImage: (subLayer: number, order: number, imageInit: SpriteImageDefinitionInit) => boolean;
348
+ /** Applies image updates. */
262
349
  readonly updateImage: (subLayer: number, order: number, imageUpdate: SpriteImageDefinitionUpdate) => boolean;
350
+ /** Removes an image slot. */
263
351
  readonly removeImage: (subLayer: number, order: number) => boolean;
264
352
  }
265
- /** Represents a point in screen space. */
353
+ /**
354
+ * Result flags returned by `mutateSprites` callbacks.
355
+ * - `'notremove'`: Keep the sprite after applying any modifications.
356
+ * - `'remove'`: Remove the sprite from the layer.
357
+ */
358
+ export type SpriteModifierResult = 'notremove' | 'remove';
359
+ /** Source items supplied to `mutateSprites` must expose the target sprite ID. */
360
+ export interface SpriteMutateSourceItem {
361
+ /** Identifier of the sprite targeted by the source item. */
362
+ readonly spriteId: string;
363
+ }
364
+ /**
365
+ * Callbacks invoked by `mutateSprites` for each source item.
366
+ *
367
+ * @template TTag Sprite tag type stored by the layer.
368
+ * @template TSourceItem Source item type that satisfies {@link SpriteMutateSourceItem}.
369
+ */
370
+ export interface SpriteMutateCallbacks<TTag, TSourceItem extends SpriteMutateSourceItem> {
371
+ /**
372
+ * Invoked when the sprite ID from the source item does not yet exist.
373
+ * Return a populated {@link SpriteInit} when the sprite should be added; return `undefined`
374
+ * (or `null`) to skip creation.
375
+ *
376
+ * @param sourceItem Source item that produced the sprite ID.
377
+ * @returns Sprite initialiser to insert, or `undefined`/`null` to skip.
378
+ */
379
+ add: (sourceItem: TSourceItem) => SpriteInit<TTag> | null | undefined;
380
+ /**
381
+ * Invoked when the sprite ID already exists on the layer.
382
+ * Use `update` to mutate sprite properties or images; return `'remove'` to delete the sprite instead.
383
+ *
384
+ * @param sourceItem Source item that produced the sprite ID.
385
+ * @param sprite Current sprite state snapshot.
386
+ * @param update Helper exposing the same operations as {@link SpriteUpdaterEntry}.
387
+ * @returns `'remove'` to delete the sprite; otherwise `'notremove'`.
388
+ */
389
+ modify: (sourceItem: TSourceItem, sprite: SpriteCurrentState<TTag>, update: SpriteUpdaterEntry<TTag>) => SpriteModifierResult;
390
+ }
391
+ /**
392
+ * Represents a point in screen space.
393
+ *
394
+ * @property {number} x - Horizontal screen coordinate in pixels.
395
+ * @property {number} y - Vertical screen coordinate in pixels.
396
+ */
266
397
  export interface SpriteScreenPoint {
398
+ /** Horizontal screen coordinate in pixels. */
267
399
  readonly x: number;
400
+ /** Vertical screen coordinate in pixels. */
268
401
  readonly y: number;
269
402
  }
270
- /** Event dispatched when a sprite is clicked or tapped. */
403
+ /**
404
+ * Event dispatched when a sprite is clicked or tapped.
405
+ *
406
+ * @template T Tag type stored on sprites.
407
+ * @property {'spriteclick'} type - Discriminated event type.
408
+ * @property {SpriteCurrentState<T>} sprite - Snapshot of the sprite that was hit.
409
+ * @property {SpriteImageState} image - Sprite image that received the interaction.
410
+ * @property {SpriteScreenPoint} screenPoint - Screen position of the interaction.
411
+ * @property {MouseEvent | PointerEvent | TouchEvent} originalEvent - Original DOM event.
412
+ */
271
413
  export interface SpriteLayerClickEvent<T> {
414
+ /** Discriminated event type. */
272
415
  readonly type: 'spriteclick';
416
+ /** Snapshot of the sprite that was hit. */
273
417
  readonly sprite: SpriteCurrentState<T>;
418
+ /** Sprite image that received the interaction. */
274
419
  readonly image: SpriteImageState;
420
+ /** Screen position of the interaction. */
275
421
  readonly screenPoint: SpriteScreenPoint;
422
+ /** Original DOM event. */
276
423
  readonly originalEvent: MouseEvent | PointerEvent | TouchEvent;
277
424
  }
278
- /** Map of events emitted by SpriteLayer. */
425
+ /**
426
+ * Map of events emitted by SpriteLayer.
427
+ *
428
+ * @template T Tag type stored on sprites.
429
+ * @property {SpriteLayerClickEvent<T>} spriteclick - Event fired when a sprite image is clicked.
430
+ */
279
431
  export interface SpriteLayerEventMap<T> {
432
+ /** Event fired when a sprite image is clicked. */
280
433
  readonly spriteclick: SpriteLayerClickEvent<T>;
281
434
  }
282
- /** Event listener callback. */
435
+ /**
436
+ * Event listener callback.
437
+ *
438
+ * @template T Tag type stored on sprites.
439
+ * @template K Event key from {@link SpriteLayerEventMap}.
440
+ * @param {SpriteLayerEventMap<T>[K]} event - Event payload dispatched by SpriteLayer.
441
+ * @returns {void}
442
+ */
283
443
  export type SpriteLayerEventListener<T, K extends keyof SpriteLayerEventMap<T>> = (event: SpriteLayerEventMap<T>[K]) => void;
284
- /** Options controlling zoom-to-pixel scaling. */
444
+ /**
445
+ * Options controlling zoom-to-pixel scaling.
446
+ *
447
+ * @property {number | undefined} metersPerPixel - Overrides the baseline meters-per-pixel ratio.
448
+ * @property {number | undefined} zoomMin - Minimum zoom level before scaling adjustments apply.
449
+ * @property {number | undefined} zoomMax - Maximum zoom level before scaling adjustments apply.
450
+ * @property {number | undefined} scaleMin - Lower limit for scale clamping.
451
+ * @property {number | undefined} scaleMax - Upper limit for scale clamping.
452
+ * @property {number | undefined} spriteMinPixel - Minimum on-screen pixel size for sprites.
453
+ * @property {number | undefined} spriteMaxPixel - Maximum on-screen pixel size for sprites.
454
+ */
285
455
  export interface SpriteScalingOptions {
456
+ /** Overrides the baseline meters-per-pixel ratio. */
286
457
  metersPerPixel?: number;
458
+ /** Minimum zoom level before scaling adjustments apply. */
287
459
  zoomMin?: number;
460
+ /** Maximum zoom level before scaling adjustments apply. */
288
461
  zoomMax?: number;
462
+ /** Lower limit for scale clamping. */
289
463
  scaleMin?: number;
464
+ /** Upper limit for scale clamping. */
290
465
  scaleMax?: number;
466
+ /** Minimum on-screen pixel size for sprites. */
291
467
  spriteMinPixel?: number;
468
+ /** Maximum on-screen pixel size for sprites. */
292
469
  spriteMaxPixel?: number;
293
470
  }
294
- /** Options accepted when creating a SpriteLayer. */
471
+ /**
472
+ * Options accepted when creating a SpriteLayer.
473
+ *
474
+ * @property {string | undefined} id - Optional layer identifier supplied to MapLibre.
475
+ * @property {SpriteScalingOptions | undefined} spriteScaling - Optional scaling controls.
476
+ */
295
477
  export interface SpriteLayerOptions {
478
+ /** Optional layer identifier supplied to MapLibre. */
296
479
  id?: string;
480
+ /** Optional scaling controls. */
297
481
  spriteScaling?: SpriteScalingOptions;
298
482
  }
299
483
  /** Horizontal alignment options for text glyphs. */
@@ -313,39 +497,215 @@ export type SpriteTextGlyphDimensions = {
313
497
  readonly maxWidthPixel: number;
314
498
  readonly lineHeightPixel?: never;
315
499
  };
500
+ /**
501
+ * Text glyph appearance options.
502
+ *
503
+ * @property {string | undefined} fontFamily - Font family name.
504
+ * @property {number | undefined} fontSizePixel - Font size in pixels.
505
+ * @property {string | undefined} fontWeight - CSS font-weight value.
506
+ * @property {'normal' | 'italic' | undefined} fontStyle - CSS font-style value.
507
+ * @property {string | undefined} color - Text fill color.
508
+ * @property {number | undefined} letterSpacingPixel - Letter spacing in pixels.
509
+ * @property {string | undefined} backgroundColor - Background color applied behind the text.
510
+ * @property {SpriteTextGlyphPaddingPixel | undefined} paddingPixel - Padding around the glyph.
511
+ * @property {string | undefined} borderColor - Outline color.
512
+ * @property {number | undefined} borderWidthPixel - Outline width in pixels.
513
+ * @property {number | undefined} borderRadiusPixel - Border radius in pixels.
514
+ * @property {SpriteTextGlyphHorizontalAlign | undefined} textAlign - Horizontal alignment of multiline text.
515
+ * @property {number | undefined} renderPixelRatio - Pixel ratio used when rendering the glyph.
516
+ */
316
517
  export interface SpriteTextGlyphOptions {
518
+ /** Font family name. */
317
519
  fontFamily?: string;
520
+ /** Font size in pixels. */
318
521
  fontSizePixel?: number;
522
+ /** CSS font-weight value. */
319
523
  fontWeight?: string;
524
+ /** CSS font-style value. */
320
525
  fontStyle?: 'normal' | 'italic';
526
+ /** Text fill color. */
321
527
  color?: string;
528
+ /** Letter spacing in pixels. */
322
529
  letterSpacingPixel?: number;
530
+ /** Background color applied behind the text. */
323
531
  backgroundColor?: string;
532
+ /** Padding around the glyph. */
324
533
  paddingPixel?: SpriteTextGlyphPaddingPixel;
534
+ /** Outline color. */
325
535
  borderColor?: string;
536
+ /** Outline width in pixels. */
326
537
  borderWidthPixel?: number;
538
+ /** Border radius in pixels. */
327
539
  borderRadiusPixel?: number;
540
+ /** Horizontal alignment of multiline text. */
328
541
  textAlign?: SpriteTextGlyphHorizontalAlign;
542
+ /** Pixel ratio used when rendering the glyph. */
329
543
  renderPixelRatio?: number;
330
544
  }
331
545
  /**
332
546
  * MapLibre layer interface for SpriteLayer.
333
547
  * Renders large numbers of sprites and supports high-frequency updates.
334
- * @param T Sprite tag type.
548
+ *
549
+ * @template TTag Sprite tag type.
335
550
  */
336
- export interface SpriteLayerInterface<T = any> extends CustomLayerInterface {
551
+ export interface SpriteLayerInterface<TTag = any> extends CustomLayerInterface {
552
+ /**
553
+ * Registers an image or glyph so it can be referenced by sprite images.
554
+ *
555
+ * @param {string} imageId - Unique image identifier.
556
+ * @param {string | ImageBitmap} image - Image source (URL or ImageBitmap) to upload.
557
+ * @returns {Promise<boolean>} Resolves to `true` when the image was registered; `false` if the ID already existed.
558
+ */
337
559
  readonly registerImage: (imageId: string, image: string | ImageBitmap) => Promise<boolean>;
560
+ /**
561
+ * Registers a text glyph texture for later use.
562
+ *
563
+ * @param {string} textGlyphId - Unique identifier for the text glyph.
564
+ * @param {string} text - Text content to render.
565
+ * @param {SpriteTextGlyphDimensions} dimensions - Glyph sizing options.
566
+ * @param {SpriteTextGlyphOptions | undefined} options - Optional styling information.
567
+ * @returns {Promise<boolean>} Resolves to `true` when the glyph was registered; `false` if the ID already existed.
568
+ */
338
569
  readonly registerTextGlyph: (textGlyphId: string, text: string, dimensions: SpriteTextGlyphDimensions, options?: SpriteTextGlyphOptions) => Promise<boolean>;
570
+ /**
571
+ * Removes a previously registered image or glyph.
572
+ *
573
+ * @param {string} imageId - Identifier of the image to remove.
574
+ * @returns {boolean} `true` when the image existed and was removed.
575
+ */
339
576
  readonly unregisterImage: (imageId: string) => boolean;
340
- readonly addSprite: (spriteId: string, init: SpriteInit<T>) => boolean;
577
+ /**
578
+ * Removes every registered image and glyph, releasing associated GPU resources.
579
+ *
580
+ * @returns {void}
581
+ */
582
+ readonly unregisterAllImages: () => void;
583
+ /**
584
+ * Returns all currently registered image IDs.
585
+ *
586
+ * @returns {string[]} Array of registered image identifiers.
587
+ */
588
+ readonly getAllImageIds: () => string[];
589
+ /**
590
+ * Adds a sprite to the layer.
591
+ *
592
+ * @param {string} spriteId - Unique sprite identifier.
593
+ * @param {SpriteInit<TTag>} init - Initial sprite configuration.
594
+ * @returns {boolean} `true` when the sprite was inserted; `false` if the ID already existed.
595
+ */
596
+ readonly addSprite: (spriteId: string, init: SpriteInit<TTag>) => boolean;
597
+ /**
598
+ * Adds multiple sprites in one call.
599
+ *
600
+ * @param {SpriteInitCollection<TTag>} sprites - Sprite definitions keyed by ID or supplied as entries.
601
+ * @returns {number} Number of sprites that were inserted.
602
+ */
603
+ readonly addSprites: (sprites: SpriteInitCollection<TTag>) => number;
604
+ /**
605
+ * Removes a sprite.
606
+ *
607
+ * @param {string} spriteId - Identifier of the sprite to remove.
608
+ * @returns {void}
609
+ */
341
610
  readonly removeSprite: (spriteId: string) => void;
342
- readonly getSpriteState: (spriteId: string) => SpriteCurrentState<T> | undefined;
611
+ /**
612
+ * Removes multiple sprites.
613
+ *
614
+ * @param {readonly string[]} spriteIds - Identifiers of the sprites to remove.
615
+ * @returns {number} Number of sprites that were removed.
616
+ */
617
+ readonly removeSprites: (spriteIds: readonly string[]) => number;
618
+ /**
619
+ * Removes all sprites.
620
+ *
621
+ * @returns {number} Number of sprites that were removed.
622
+ */
623
+ readonly removeAllSprites: () => number;
624
+ /**
625
+ * Retrieves the current state for a sprite.
626
+ *
627
+ * @param {string} spriteId - Identifier of the sprite.
628
+ * @returns {SpriteCurrentState<TTag> | undefined} Current state or `undefined` when not found.
629
+ */
630
+ readonly getSpriteState: (spriteId: string) => SpriteCurrentState<TTag> | undefined;
631
+ /**
632
+ * Attaches an image definition to a sprite.
633
+ *
634
+ * @param {string} spriteId - Target sprite identifier.
635
+ * @param {number} subLayer - Sub-layer index.
636
+ * @param {number} order - Order slot within the sub-layer.
637
+ * @param {SpriteImageDefinitionInit} imageInit - Image definition to insert.
638
+ * @returns {boolean} `true` when the image slot was empty and the definition applied.
639
+ */
343
640
  readonly addSpriteImage: (spriteId: string, subLayer: number, order: number, imageInit: SpriteImageDefinitionInit) => boolean;
641
+ /**
642
+ * Updates an image assigned to a sprite.
643
+ *
644
+ * @param {string} spriteId - Target sprite identifier.
645
+ * @param {number} subLayer - Sub-layer index containing the image.
646
+ * @param {number} order - Order slot within the sub-layer.
647
+ * @param {SpriteImageDefinitionUpdate} imageUpdate - Update payload.
648
+ * @returns {boolean} `true` when the image existed and was updated.
649
+ */
344
650
  readonly updateSpriteImage: (spriteId: string, subLayer: number, order: number, imageUpdate: SpriteImageDefinitionUpdate) => boolean;
651
+ /**
652
+ * Removes an image from a sprite.
653
+ *
654
+ * @param {string} spriteId - Target sprite identifier.
655
+ * @param {number} subLayer - Sub-layer index containing the image.
656
+ * @param {number} order - Order slot within the sub-layer.
657
+ * @returns {boolean} `true` when the image existed and was removed.
658
+ */
345
659
  readonly removeSpriteImage: (spriteId: string, subLayer: number, order: number) => boolean;
346
- readonly updateSprite: (spriteId: string, update: SpriteUpdateEntry<T>) => boolean;
347
- readonly updateBulk: (updateBulkList: SpriteUpdateBulkEntry<T>[]) => number;
348
- readonly updateForEach: (updater: (sprite: SpriteCurrentState<T>, update: SpriteUpdaterEntry<T>) => boolean) => number;
349
- readonly on: <K extends keyof SpriteLayerEventMap<T>>(type: K, listener: SpriteLayerEventListener<T, K>) => void;
350
- readonly off: <K extends keyof SpriteLayerEventMap<T>>(type: K, listener: SpriteLayerEventListener<T, K>) => void;
660
+ /**
661
+ * Removes all images attached to the specified sprite.
662
+ *
663
+ * @param {string} spriteId - Identifier of the sprite whose images should be removed.
664
+ * @returns {number} Number of images that were removed.
665
+ */
666
+ readonly removeAllSpriteImages: (spriteId: string) => number;
667
+ /**
668
+ * Updates a sprite with the provided payload.
669
+ *
670
+ * @param {string} spriteId - Target sprite identifier.
671
+ * @param {SpriteUpdateEntry<TTag>} update - Update payload describing property changes.
672
+ * @returns {boolean} `true` when the sprite was found and updated.
673
+ */
674
+ readonly updateSprite: (spriteId: string, update: SpriteUpdateEntry<TTag>) => boolean;
675
+ /**
676
+ * @deprecated Use {@link SpriteLayerInterface.mutateSprites} instead for clearer mutation flows.
677
+ */
678
+ readonly updateBulk: (updateBulkList: SpriteUpdateBulkEntry<TTag>[]) => number;
679
+ /**
680
+ * Adds, updates, or removes sprites based on an arbitrary collection of source items.
681
+ *
682
+ * @param {readonly TSourceItem[]} sourceItems - Source items that describe desired sprite state.
683
+ * @param {SpriteMutateCallbacks<TTag, TSourceItem>} mutator - Callbacks responsible for creation and modification.
684
+ * @returns {number} Number of sprites that changed. Counts each `add` that returns a non-null
685
+ * initialiser and each `modify` that either invoked the updater helper or returned `'remove'`.
686
+ */
687
+ readonly mutateSprites: <TSourceItem extends SpriteMutateSourceItem>(sourceItems: readonly TSourceItem[], mutator: SpriteMutateCallbacks<TTag, TSourceItem>) => number;
688
+ /**
689
+ * Iterates over each sprite and allows modifications through a callback.
690
+ *
691
+ * @param {(sprite: SpriteCurrentState<TTag>, update: SpriteUpdaterEntry<TTag>) => boolean} updater - Callback invoked for each sprite. Return `false` to stop iteration early.
692
+ * @returns {number} Number of sprites that were updated.
693
+ */
694
+ readonly updateForEach: (updater: (sprite: SpriteCurrentState<TTag>, update: SpriteUpdaterEntry<TTag>) => boolean) => number;
695
+ /**
696
+ * Adds an event listener.
697
+ *
698
+ * @param {K} type - Event name.
699
+ * @param {SpriteLayerEventListener<TTag, K>} listener - Listener callback.
700
+ * @returns {void}
701
+ */
702
+ readonly on: <K extends keyof SpriteLayerEventMap<TTag>>(type: K, listener: SpriteLayerEventListener<TTag, K>) => void;
703
+ /**
704
+ * Removes a previously registered event listener.
705
+ *
706
+ * @param {K} type - Event name.
707
+ * @param {SpriteLayerEventListener<TTag, K>} listener - Listener callback to remove.
708
+ * @returns {void}
709
+ */
710
+ readonly off: <K extends keyof SpriteLayerEventMap<TTag>>(type: K, listener: SpriteLayerEventListener<TTag, K>) => void;
351
711
  }
package/dist/utils.d.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  /*!
2
2
  * name: maplibre-gl-layers
3
- * version: 0.1.0
3
+ * version: 0.3.0
4
4
  * description: MapLibre's layer extension library enabling the display, movement, and modification of large numbers of dynamic sprite images
5
5
  * author: Kouji Matsui (@kekyo@mi.kekyo.net)
6
6
  * license: MIT
7
7
  * repository.url: https://github.com/kekyo/maplibre-gl-layers.git
8
- * git.commit.hash: 88b09a93779279947d9c6b1e3a7538d4d197dbcb
8
+ * git.commit.hash: fd90d1fd66e4ca9c0defa49e68ecaeb9c14fbd06
9
9
  */
10
10
 
11
11
  /**
package/package.json CHANGED
@@ -1,20 +1,20 @@
1
1
  {
2
2
  "git": {
3
3
  "tags": [
4
- "0.1.0"
4
+ "0.3.0"
5
5
  ],
6
6
  "branches": [
7
7
  "main"
8
8
  ],
9
- "version": "0.1.0",
9
+ "version": "0.3.0",
10
10
  "commit": {
11
- "hash": "88b09a93779279947d9c6b1e3a7538d4d197dbcb",
12
- "shortHash": "88b09a9",
13
- "date": "2025-10-28T09:58:34+09:00Z",
14
- "message": "Initial commit"
11
+ "hash": "fd90d1fd66e4ca9c0defa49e68ecaeb9c14fbd06",
12
+ "shortHash": "fd90d1f",
13
+ "date": "2025-10-29T13:58:42+09:00Z",
14
+ "message": "Merge branch 'develop'"
15
15
  }
16
16
  },
17
- "version": "0.1.0",
17
+ "version": "0.3.0",
18
18
  "description": "MapLibre's layer extension library enabling the display, movement, and modification of large numbers of dynamic sprite images",
19
19
  "author": "Kouji Matsui (@kekyo@mi.kekyo.net)",
20
20
  "license": "MIT",