@blorkfield/overlay-core 0.4.3 → 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 */
@@ -416,6 +482,10 @@ declare class OverlayScene {
416
482
  private checkFloorSegmentThresholds;
417
483
  /** Collapse a single floor segment */
418
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;
419
489
  /** Log a summary of pressure on all obstacles, grouped by word */
420
490
  private logPressureSummary;
421
491
  /** Calculate weighted pressure from a set of object IDs */
@@ -550,6 +620,15 @@ declare class OverlayScene {
550
620
  * Check if fonts have been initialized.
551
621
  */
552
622
  areFontsInitialized(): boolean;
623
+ /**
624
+ * Internal: Attach a DOM element to physics.
625
+ * Called by spawnObject when element is provided.
626
+ */
627
+ private addDOMObstacleInternal;
628
+ /**
629
+ * Get the shadow element for a DOM obstacle (available after collapse).
630
+ */
631
+ getDOMObstacleShadow(id: string): HTMLElement | null;
553
632
  /**
554
633
  * Create text obstacles from a string. Each character becomes an individual obstacle
555
634
  * with shape extracted from the corresponding letter PNG image.
@@ -639,6 +718,10 @@ declare class OverlayScene {
639
718
  * Draw TTF glyphs using canvas fillText for clean text rendering
640
719
  */
641
720
  private drawTTFGlyphs;
721
+ /**
722
+ * Update a DOM element's CSS transform to match its physics body position and rotation.
723
+ */
724
+ private updateDOMElementTransform;
642
725
  private checkTTLExpiration;
643
726
  /** Despawn objects that have fallen below the floor by the configured distance */
644
727
  private checkDespawnBelowFloor;
@@ -697,4 +780,4 @@ declare function measureText(loadedFont: LoadedFont, text: string, fontSize: num
697
780
  */
698
781
  declare function clearFontCache(): void;
699
782
 
700
- 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 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 */
@@ -416,6 +482,10 @@ declare class OverlayScene {
416
482
  private checkFloorSegmentThresholds;
417
483
  /** Collapse a single floor segment */
418
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;
419
489
  /** Log a summary of pressure on all obstacles, grouped by word */
420
490
  private logPressureSummary;
421
491
  /** Calculate weighted pressure from a set of object IDs */
@@ -550,6 +620,15 @@ declare class OverlayScene {
550
620
  * Check if fonts have been initialized.
551
621
  */
552
622
  areFontsInitialized(): boolean;
623
+ /**
624
+ * Internal: Attach a DOM element to physics.
625
+ * Called by spawnObject when element is provided.
626
+ */
627
+ private addDOMObstacleInternal;
628
+ /**
629
+ * Get the shadow element for a DOM obstacle (available after collapse).
630
+ */
631
+ getDOMObstacleShadow(id: string): HTMLElement | null;
553
632
  /**
554
633
  * Create text obstacles from a string. Each character becomes an individual obstacle
555
634
  * with shape extracted from the corresponding letter PNG image.
@@ -639,6 +718,10 @@ declare class OverlayScene {
639
718
  * Draw TTF glyphs using canvas fillText for clean text rendering
640
719
  */
641
720
  private drawTTFGlyphs;
721
+ /**
722
+ * Update a DOM element's CSS transform to match its physics body position and rotation.
723
+ */
724
+ private updateDOMElementTransform;
642
725
  private checkTTLExpiration;
643
726
  /** Despawn objects that have fallen below the floor by the configured distance */
644
727
  private checkDespawnBelowFloor;
@@ -697,4 +780,4 @@ declare function measureText(loadedFont: LoadedFont, text: string, fontSize: num
697
780
  */
698
781
  declare function clearFontCache(): void;
699
782
 
700
- 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 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 };