@blorkfield/overlay-core 0.5.0 → 0.5.1

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.cts CHANGED
@@ -30,6 +30,33 @@ interface FloorConfig {
30
30
  * If not provided, segments have infinite capacity.
31
31
  */
32
32
  threshold?: number | number[];
33
+ /**
34
+ * Thickness of floor segments in pixels:
35
+ * - number: Same thickness for all segments (default: 50)
36
+ * - number[]: Per-segment thickness (segment 0 uses value[0], etc.)
37
+ */
38
+ thickness?: number | number[];
39
+ /**
40
+ * Color of floor segments (visible when set):
41
+ * - string: Same color for all segments
42
+ * - string[]: Per-segment colors (segment 0 uses value[0], etc.)
43
+ * If not provided, floor segments are invisible.
44
+ */
45
+ color?: string | string[];
46
+ /**
47
+ * Minimum number of segments that must remain for floor integrity.
48
+ * When remaining segments drops below this value, ALL remaining segments collapse.
49
+ * Example: segments=10, minIntegrity=7 means once 4+ segments collapse, the rest follow.
50
+ * If set higher than segments count, floor collapses immediately.
51
+ */
52
+ minIntegrity?: number;
53
+ /**
54
+ * Proportional widths for each segment (must sum to 1.0):
55
+ * - number[]: Per-segment width proportions (e.g., [0.2, 0.3, 0.5] for 3 segments)
56
+ * If not provided, segments have equal widths.
57
+ * Array length should match segments count.
58
+ */
59
+ segmentWidths?: number[];
33
60
  }
34
61
  interface Bounds {
35
62
  top: number;
@@ -68,6 +95,8 @@ interface DespawnEffectConfig {
68
95
  interface ObjectConfig {
69
96
  x: number;
70
97
  y: number;
98
+ /** DOM element to link to physics. When provided, element moves with physics body and shadow clones the element */
99
+ element?: HTMLElement;
71
100
  /** Radius for circle/polygon shapes */
72
101
  radius?: number;
73
102
  /** Width for rectangle objects (ignored if imageUrl is provided) */
@@ -90,6 +119,12 @@ interface ObjectConfig {
90
119
  despawnEffect?: DespawnEffectConfig;
91
120
  /** Weight for pressure calculation (default: 1). Higher weight = more pressure contribution */
92
121
  weight?: number;
122
+ /** Pressure threshold config - when reached, object collapses */
123
+ pressureThreshold?: PressureThresholdConfig;
124
+ /** Shadow config - when enabled, a visual copy remains after collapse (true for default opacity) */
125
+ shadow?: ShadowConfig | boolean;
126
+ /** Click to fall config - when set, object collapses after being clicked N times */
127
+ clickToFall?: ClickToFallConfig;
93
128
  }
94
129
  /**
95
130
  * Dynamic object data passed to update callbacks.
@@ -247,16 +282,25 @@ interface ClickToFallConfig {
247
282
  */
248
283
  clicks: number;
249
284
  }
285
+ /**
286
+ * Text alignment option for positioning text obstacles.
287
+ * - 'left': x coordinate is the left edge of the text (default)
288
+ * - 'center': x coordinate is the center of the text
289
+ * - 'right': x coordinate is the right edge of the text
290
+ */
291
+ type TextAlign = 'left' | 'center' | 'right';
250
292
  /**
251
293
  * Configuration for creating text objects from strings
252
294
  */
253
295
  interface TextObstacleConfig {
254
296
  /** The text to create objects from (A-Z, 0-9 supported, supports \n for multiline) */
255
297
  text: string;
256
- /** X position of the first letter's center */
298
+ /** X position (interpretation depends on align setting) */
257
299
  x: number;
258
300
  /** Y position of the letter centers */
259
301
  y: number;
302
+ /** Text alignment - 'left' (default), 'center', or 'right' */
303
+ align?: TextAlign;
260
304
  /** Size of each letter (width/height) */
261
305
  letterSize: number;
262
306
  /** Spacing between letter centers (default: letterSize) */
@@ -305,6 +349,24 @@ interface LetterDebugInfo {
305
349
  centerX: number;
306
350
  centerY: number;
307
351
  }
352
+ /**
353
+ * Bounding box for text obstacles.
354
+ * Useful for positioning subsequent elements relative to the text.
355
+ */
356
+ interface TextBounds {
357
+ /** X position of the left edge of the text */
358
+ left: number;
359
+ /** X position of the right edge of the text */
360
+ right: number;
361
+ /** Y position of the top edge of the text */
362
+ top: number;
363
+ /** Y position of the bottom edge of the text */
364
+ bottom: number;
365
+ /** Total width of the text */
366
+ width: number;
367
+ /** Total height of the text (including all lines) */
368
+ height: number;
369
+ }
308
370
  /**
309
371
  * Result of creating text obstacles
310
372
  */
@@ -319,6 +381,8 @@ interface TextObstacleResult {
319
381
  letterMap: Map<string, string>;
320
382
  /** Debug info for each letter (for drawing original dimension boxes) */
321
383
  letterDebugInfo: LetterDebugInfo[];
384
+ /** Bounding box of the entire text block */
385
+ bounds: TextBounds;
322
386
  }
323
387
  /**
324
388
  * Configuration for creating text objects from a TTF font
@@ -326,10 +390,12 @@ interface TextObstacleResult {
326
390
  interface TTFTextObstacleConfig {
327
391
  /** Text to display (supports \n for multiline) */
328
392
  text: string;
329
- /** X position of the start of text */
393
+ /** X position (interpretation depends on align setting) */
330
394
  x: number;
331
395
  /** Y position of the text baseline */
332
396
  y: number;
397
+ /** Text alignment - 'left' (default), 'center', or 'right' */
398
+ align?: TextAlign;
333
399
  /** Font size in pixels */
334
400
  fontSize: number;
335
401
  /** URL path to the TTF/OTF font file */
@@ -353,41 +419,6 @@ interface TTFTextObstacleConfig {
353
419
  /** Click to fall config - when set, letters collapse after being clicked N times */
354
420
  clickToFall?: ClickToFallConfig;
355
421
  }
356
- /**
357
- * Configuration for attaching a DOM element to physics.
358
- * The element will follow the physics body and can have pressure/shadow/click behavior.
359
- */
360
- interface DOMObstacleConfig {
361
- /** The DOM element to attach to physics */
362
- element: HTMLElement;
363
- /** X position of the element center */
364
- x: number;
365
- /** Y position of the element center */
366
- y: number;
367
- /** Width of the collision body (defaults to element.offsetWidth) */
368
- width?: number;
369
- /** Height of the collision body (defaults to element.offsetHeight) */
370
- height?: number;
371
- /** Tags that define object behavior */
372
- tags?: string[];
373
- /** Pressure threshold config - when reached, element collapses */
374
- pressureThreshold?: PressureThresholdConfig;
375
- /** Weight for pressure calculation (default: 1) */
376
- weight?: number;
377
- /** Shadow config - when enabled, a cloned element remains after collapse */
378
- shadow?: ShadowConfig;
379
- /** Click to fall config - when set, element collapses after being clicked N times */
380
- clickToFall?: ClickToFallConfig;
381
- }
382
- /**
383
- * Result of attaching a DOM element to physics
384
- */
385
- interface DOMObstacleResult {
386
- /** ID of the created physics object */
387
- id: string;
388
- /** The shadow element if shadow was configured (null until collapse) */
389
- shadowElement: HTMLElement | null;
390
- }
391
422
  /**
392
423
  * Information about an available font
393
424
  */
@@ -451,6 +482,10 @@ declare class OverlayScene {
451
482
  private checkFloorSegmentThresholds;
452
483
  /** Collapse a single floor segment */
453
484
  private collapseFloorSegment;
485
+ /** Check if floor integrity requirement is violated and collapse all remaining if so */
486
+ private checkFloorIntegrity;
487
+ /** Check floor integrity on initialization (handles minIntegrity > segments) */
488
+ private checkInitialFloorIntegrity;
454
489
  /** Log a summary of pressure on all obstacles, grouped by word */
455
490
  private logPressureSummary;
456
491
  /** Calculate weighted pressure from a set of object IDs */
@@ -586,15 +621,10 @@ declare class OverlayScene {
586
621
  */
587
622
  areFontsInitialized(): boolean;
588
623
  /**
589
- * Attach a DOM element to physics. The element will follow the physics body
590
- * and can have pressure threshold, shadow, and click-to-fall behavior.
591
- *
592
- * When the element collapses (becomes dynamic), its CSS transform will be
593
- * updated each frame to match the physics body position and rotation.
594
- *
595
- * Shadow creates a cloned DOM element that stays at the original position.
624
+ * Internal: Attach a DOM element to physics.
625
+ * Called by spawnObject when element is provided.
596
626
  */
597
- addDOMObstacle(config: DOMObstacleConfig): DOMObstacleResult;
627
+ private addDOMObstacleInternal;
598
628
  /**
599
629
  * Get the shadow element for a DOM obstacle (available after collapse).
600
630
  */
@@ -750,4 +780,4 @@ declare function measureText(loadedFont: LoadedFont, text: string, fontSize: num
750
780
  */
751
781
  declare function clearFontCache(): void;
752
782
 
753
- export { type BaseEffectConfig, type Bounds, type BurstEffectConfig, type ClickToFallConfig, type ContainerOptions, type DOMObstacleConfig, type DOMObstacleResult, type DespawnEffectConfig, type DynamicObject, type EffectConfig, type EffectObjectConfig, type EffectType, type FloorConfig, type FontInfo, type FontManifest, type GlyphData, type LoadedFont, type ObjectConfig, OverlayScene, type OverlaySceneConfig, type PressureThresholdConfig, type RainEffectConfig, type ShadowConfig, type ShapeConfig, type ShapePreset, type StreamEffectConfig, type TTFTextObstacleConfig, type TextObstacleConfig, type TextObstacleResult, type UpdateCallback, type UpdateCallbackData, type WeightConfig, clearFontCache, getGlyphData, getKerning, getLogLevel, loadFont, logger, measureText, setLogLevel };
783
+ export { type BaseEffectConfig, type Bounds, type BurstEffectConfig, type ClickToFallConfig, type ContainerOptions, type DespawnEffectConfig, type DynamicObject, type EffectConfig, type EffectObjectConfig, type EffectType, type FloorConfig, type FontInfo, type FontManifest, type GlyphData, type LoadedFont, type ObjectConfig, OverlayScene, type OverlaySceneConfig, type PressureThresholdConfig, type RainEffectConfig, type ShadowConfig, type ShapeConfig, type ShapePreset, type StreamEffectConfig, type TTFTextObstacleConfig, type TextAlign, type TextBounds, type TextObstacleConfig, type TextObstacleResult, type UpdateCallback, type UpdateCallbackData, type WeightConfig, clearFontCache, getGlyphData, getKerning, getLogLevel, loadFont, logger, measureText, setLogLevel };
package/dist/index.d.ts CHANGED
@@ -30,6 +30,33 @@ interface FloorConfig {
30
30
  * If not provided, segments have infinite capacity.
31
31
  */
32
32
  threshold?: number | number[];
33
+ /**
34
+ * Thickness of floor segments in pixels:
35
+ * - number: Same thickness for all segments (default: 50)
36
+ * - number[]: Per-segment thickness (segment 0 uses value[0], etc.)
37
+ */
38
+ thickness?: number | number[];
39
+ /**
40
+ * Color of floor segments (visible when set):
41
+ * - string: Same color for all segments
42
+ * - string[]: Per-segment colors (segment 0 uses value[0], etc.)
43
+ * If not provided, floor segments are invisible.
44
+ */
45
+ color?: string | string[];
46
+ /**
47
+ * Minimum number of segments that must remain for floor integrity.
48
+ * When remaining segments drops below this value, ALL remaining segments collapse.
49
+ * Example: segments=10, minIntegrity=7 means once 4+ segments collapse, the rest follow.
50
+ * If set higher than segments count, floor collapses immediately.
51
+ */
52
+ minIntegrity?: number;
53
+ /**
54
+ * Proportional widths for each segment (must sum to 1.0):
55
+ * - number[]: Per-segment width proportions (e.g., [0.2, 0.3, 0.5] for 3 segments)
56
+ * If not provided, segments have equal widths.
57
+ * Array length should match segments count.
58
+ */
59
+ segmentWidths?: number[];
33
60
  }
34
61
  interface Bounds {
35
62
  top: number;
@@ -68,6 +95,8 @@ interface DespawnEffectConfig {
68
95
  interface ObjectConfig {
69
96
  x: number;
70
97
  y: number;
98
+ /** DOM element to link to physics. When provided, element moves with physics body and shadow clones the element */
99
+ element?: HTMLElement;
71
100
  /** Radius for circle/polygon shapes */
72
101
  radius?: number;
73
102
  /** Width for rectangle objects (ignored if imageUrl is provided) */
@@ -90,6 +119,12 @@ interface ObjectConfig {
90
119
  despawnEffect?: DespawnEffectConfig;
91
120
  /** Weight for pressure calculation (default: 1). Higher weight = more pressure contribution */
92
121
  weight?: number;
122
+ /** Pressure threshold config - when reached, object collapses */
123
+ pressureThreshold?: PressureThresholdConfig;
124
+ /** Shadow config - when enabled, a visual copy remains after collapse (true for default opacity) */
125
+ shadow?: ShadowConfig | boolean;
126
+ /** Click to fall config - when set, object collapses after being clicked N times */
127
+ clickToFall?: ClickToFallConfig;
93
128
  }
94
129
  /**
95
130
  * Dynamic object data passed to update callbacks.
@@ -247,16 +282,25 @@ interface ClickToFallConfig {
247
282
  */
248
283
  clicks: number;
249
284
  }
285
+ /**
286
+ * Text alignment option for positioning text obstacles.
287
+ * - 'left': x coordinate is the left edge of the text (default)
288
+ * - 'center': x coordinate is the center of the text
289
+ * - 'right': x coordinate is the right edge of the text
290
+ */
291
+ type TextAlign = 'left' | 'center' | 'right';
250
292
  /**
251
293
  * Configuration for creating text objects from strings
252
294
  */
253
295
  interface TextObstacleConfig {
254
296
  /** The text to create objects from (A-Z, 0-9 supported, supports \n for multiline) */
255
297
  text: string;
256
- /** X position of the first letter's center */
298
+ /** X position (interpretation depends on align setting) */
257
299
  x: number;
258
300
  /** Y position of the letter centers */
259
301
  y: number;
302
+ /** Text alignment - 'left' (default), 'center', or 'right' */
303
+ align?: TextAlign;
260
304
  /** Size of each letter (width/height) */
261
305
  letterSize: number;
262
306
  /** Spacing between letter centers (default: letterSize) */
@@ -305,6 +349,24 @@ interface LetterDebugInfo {
305
349
  centerX: number;
306
350
  centerY: number;
307
351
  }
352
+ /**
353
+ * Bounding box for text obstacles.
354
+ * Useful for positioning subsequent elements relative to the text.
355
+ */
356
+ interface TextBounds {
357
+ /** X position of the left edge of the text */
358
+ left: number;
359
+ /** X position of the right edge of the text */
360
+ right: number;
361
+ /** Y position of the top edge of the text */
362
+ top: number;
363
+ /** Y position of the bottom edge of the text */
364
+ bottom: number;
365
+ /** Total width of the text */
366
+ width: number;
367
+ /** Total height of the text (including all lines) */
368
+ height: number;
369
+ }
308
370
  /**
309
371
  * Result of creating text obstacles
310
372
  */
@@ -319,6 +381,8 @@ interface TextObstacleResult {
319
381
  letterMap: Map<string, string>;
320
382
  /** Debug info for each letter (for drawing original dimension boxes) */
321
383
  letterDebugInfo: LetterDebugInfo[];
384
+ /** Bounding box of the entire text block */
385
+ bounds: TextBounds;
322
386
  }
323
387
  /**
324
388
  * Configuration for creating text objects from a TTF font
@@ -326,10 +390,12 @@ interface TextObstacleResult {
326
390
  interface TTFTextObstacleConfig {
327
391
  /** Text to display (supports \n for multiline) */
328
392
  text: string;
329
- /** X position of the start of text */
393
+ /** X position (interpretation depends on align setting) */
330
394
  x: number;
331
395
  /** Y position of the text baseline */
332
396
  y: number;
397
+ /** Text alignment - 'left' (default), 'center', or 'right' */
398
+ align?: TextAlign;
333
399
  /** Font size in pixels */
334
400
  fontSize: number;
335
401
  /** URL path to the TTF/OTF font file */
@@ -353,41 +419,6 @@ interface TTFTextObstacleConfig {
353
419
  /** Click to fall config - when set, letters collapse after being clicked N times */
354
420
  clickToFall?: ClickToFallConfig;
355
421
  }
356
- /**
357
- * Configuration for attaching a DOM element to physics.
358
- * The element will follow the physics body and can have pressure/shadow/click behavior.
359
- */
360
- interface DOMObstacleConfig {
361
- /** The DOM element to attach to physics */
362
- element: HTMLElement;
363
- /** X position of the element center */
364
- x: number;
365
- /** Y position of the element center */
366
- y: number;
367
- /** Width of the collision body (defaults to element.offsetWidth) */
368
- width?: number;
369
- /** Height of the collision body (defaults to element.offsetHeight) */
370
- height?: number;
371
- /** Tags that define object behavior */
372
- tags?: string[];
373
- /** Pressure threshold config - when reached, element collapses */
374
- pressureThreshold?: PressureThresholdConfig;
375
- /** Weight for pressure calculation (default: 1) */
376
- weight?: number;
377
- /** Shadow config - when enabled, a cloned element remains after collapse */
378
- shadow?: ShadowConfig;
379
- /** Click to fall config - when set, element collapses after being clicked N times */
380
- clickToFall?: ClickToFallConfig;
381
- }
382
- /**
383
- * Result of attaching a DOM element to physics
384
- */
385
- interface DOMObstacleResult {
386
- /** ID of the created physics object */
387
- id: string;
388
- /** The shadow element if shadow was configured (null until collapse) */
389
- shadowElement: HTMLElement | null;
390
- }
391
422
  /**
392
423
  * Information about an available font
393
424
  */
@@ -451,6 +482,10 @@ declare class OverlayScene {
451
482
  private checkFloorSegmentThresholds;
452
483
  /** Collapse a single floor segment */
453
484
  private collapseFloorSegment;
485
+ /** Check if floor integrity requirement is violated and collapse all remaining if so */
486
+ private checkFloorIntegrity;
487
+ /** Check floor integrity on initialization (handles minIntegrity > segments) */
488
+ private checkInitialFloorIntegrity;
454
489
  /** Log a summary of pressure on all obstacles, grouped by word */
455
490
  private logPressureSummary;
456
491
  /** Calculate weighted pressure from a set of object IDs */
@@ -586,15 +621,10 @@ declare class OverlayScene {
586
621
  */
587
622
  areFontsInitialized(): boolean;
588
623
  /**
589
- * Attach a DOM element to physics. The element will follow the physics body
590
- * and can have pressure threshold, shadow, and click-to-fall behavior.
591
- *
592
- * When the element collapses (becomes dynamic), its CSS transform will be
593
- * updated each frame to match the physics body position and rotation.
594
- *
595
- * Shadow creates a cloned DOM element that stays at the original position.
624
+ * Internal: Attach a DOM element to physics.
625
+ * Called by spawnObject when element is provided.
596
626
  */
597
- addDOMObstacle(config: DOMObstacleConfig): DOMObstacleResult;
627
+ private addDOMObstacleInternal;
598
628
  /**
599
629
  * Get the shadow element for a DOM obstacle (available after collapse).
600
630
  */
@@ -750,4 +780,4 @@ declare function measureText(loadedFont: LoadedFont, text: string, fontSize: num
750
780
  */
751
781
  declare function clearFontCache(): void;
752
782
 
753
- export { type BaseEffectConfig, type Bounds, type BurstEffectConfig, type ClickToFallConfig, type ContainerOptions, type DOMObstacleConfig, type DOMObstacleResult, type DespawnEffectConfig, type DynamicObject, type EffectConfig, type EffectObjectConfig, type EffectType, type FloorConfig, type FontInfo, type FontManifest, type GlyphData, type LoadedFont, type ObjectConfig, OverlayScene, type OverlaySceneConfig, type PressureThresholdConfig, type RainEffectConfig, type ShadowConfig, type ShapeConfig, type ShapePreset, type StreamEffectConfig, type TTFTextObstacleConfig, type TextObstacleConfig, type TextObstacleResult, type UpdateCallback, type UpdateCallbackData, type WeightConfig, clearFontCache, getGlyphData, getKerning, getLogLevel, loadFont, logger, measureText, setLogLevel };
783
+ export { type BaseEffectConfig, type Bounds, type BurstEffectConfig, type ClickToFallConfig, type ContainerOptions, type DespawnEffectConfig, type DynamicObject, type EffectConfig, type EffectObjectConfig, type EffectType, type FloorConfig, type FontInfo, type FontManifest, type GlyphData, type LoadedFont, type ObjectConfig, OverlayScene, type OverlaySceneConfig, type PressureThresholdConfig, type RainEffectConfig, type ShadowConfig, type ShapeConfig, type ShapePreset, type StreamEffectConfig, type TTFTextObstacleConfig, type TextAlign, type TextBounds, type TextObstacleConfig, type TextObstacleResult, type UpdateCallback, type UpdateCallbackData, type WeightConfig, clearFontCache, getGlyphData, getKerning, getLogLevel, loadFont, logger, measureText, setLogLevel };