social-masonry 1.0.0 → 1.0.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.ts CHANGED
@@ -1,72 +1,16 @@
1
1
  /**
2
2
  * Social Masonry - Type Definitions
3
- * Beautiful masonry layout for social media embeds
3
+ * Masonry layout for social media iframe embeds
4
4
  */
5
5
  type SocialPlatform = 'twitter' | 'instagram';
6
- interface TwitterPost {
7
- platform: 'twitter';
8
- id: string;
6
+ interface SocialPost {
7
+ /** Unique identifier (auto-generated from URL if not provided) */
8
+ id?: string;
9
+ /** Social media platform */
10
+ platform: SocialPlatform;
11
+ /** Post URL */
9
12
  url: string;
10
- author: {
11
- username: string;
12
- displayName: string;
13
- avatarUrl?: string;
14
- verified?: boolean;
15
- };
16
- content: {
17
- text: string;
18
- html?: string;
19
- };
20
- media?: {
21
- type: 'image' | 'video' | 'gif';
22
- url: string;
23
- thumbnailUrl?: string;
24
- aspectRatio?: number;
25
- width?: number;
26
- height?: number;
27
- }[];
28
- metrics?: {
29
- likes?: number;
30
- retweets?: number;
31
- replies?: number;
32
- views?: number;
33
- };
34
- createdAt: string | Date;
35
- quotedPost?: Omit<TwitterPost, 'quotedPost'>;
36
13
  }
37
- interface InstagramPost {
38
- platform: 'instagram';
39
- id: string;
40
- url: string;
41
- author: {
42
- username: string;
43
- displayName?: string;
44
- avatarUrl?: string;
45
- verified?: boolean;
46
- };
47
- content: {
48
- caption?: string;
49
- };
50
- media: {
51
- type: 'image' | 'video' | 'carousel';
52
- url: string;
53
- thumbnailUrl?: string;
54
- aspectRatio?: number;
55
- width?: number;
56
- height?: number;
57
- carouselItems?: {
58
- type: 'image' | 'video';
59
- url: string;
60
- thumbnailUrl?: string;
61
- }[];
62
- };
63
- metrics?: {
64
- likes?: number;
65
- comments?: number;
66
- };
67
- createdAt: string | Date;
68
- }
69
- type SocialPost = TwitterPost | InstagramPost;
70
14
  interface ColumnConfig {
71
15
  /** Number of columns at this breakpoint */
72
16
  columns: number;
@@ -74,74 +18,36 @@ interface ColumnConfig {
74
18
  minWidth: number;
75
19
  }
76
20
  interface MasonryConfig {
77
- /** Gap between items (px or CSS value) */
78
- gap?: number | string;
21
+ /** Gap between items (px) */
22
+ gap?: number;
79
23
  /** Responsive column configuration */
80
24
  columns?: number | ColumnConfig[];
81
- /** Default number of columns */
82
- defaultColumns?: number;
83
- /** Padding around the container */
84
- padding?: number | string;
25
+ /** Padding around the container (px) */
26
+ padding?: number;
85
27
  /** Animation duration for layout changes (ms) */
86
28
  animationDuration?: number;
87
29
  /** Enable/disable animations */
88
30
  animate?: boolean;
89
- /** Transition easing function */
90
- easing?: string;
91
31
  }
92
- interface VirtualizationConfig {
93
- /** Enable virtualization */
94
- enabled?: boolean;
95
- /** Number of items to render outside viewport */
96
- overscan?: number;
97
- /** Estimated item height for initial render */
98
- estimatedItemHeight?: number;
99
- /** Scroll container element (default: window) */
100
- scrollContainer?: HTMLElement | Window | null;
101
- }
102
- type CardVariant = 'default' | 'minimal' | 'elevated' | 'bordered' | 'glass';
103
- type CardTheme = 'light' | 'dark' | 'auto';
104
- interface CardConfig {
105
- /** Card visual variant */
106
- variant?: CardVariant;
107
- /** Color theme */
108
- theme?: CardTheme;
109
- /** Border radius (px or CSS value) */
110
- borderRadius?: number | string;
111
- /** Show platform icon */
112
- showPlatformIcon?: boolean;
113
- /** Show author info */
114
- showAuthor?: boolean;
115
- /** Show metrics (likes, comments, etc.) */
116
- showMetrics?: boolean;
117
- /** Show timestamp */
118
- showTimestamp?: boolean;
119
- /** Date format function */
120
- formatDate?: (date: Date) => string;
121
- /** Number format function */
122
- formatNumber?: (num: number) => string;
123
- /** Custom CSS class */
124
- className?: string;
125
- /** Enable hover effects */
126
- hoverEffect?: boolean;
127
- /** Image loading strategy */
128
- imageLoading?: 'lazy' | 'eager';
129
- /** Fallback image URL */
130
- fallbackImage?: string;
32
+ interface EmbedConfig {
33
+ /** Theme for embeds: 'light' or 'dark' */
34
+ theme?: 'light' | 'dark';
35
+ /** Default height for Twitter embeds (px) */
36
+ twitterHeight?: number;
37
+ /** Default height for Instagram embeds (px) */
38
+ instagramHeight?: number;
39
+ /** Hide Twitter card (show only text) */
40
+ twitterHideCard?: boolean;
41
+ /** Hide Twitter conversation thread */
42
+ twitterHideThread?: boolean;
131
43
  }
132
44
  interface MasonryEvents {
133
- /** Called when a post card is clicked */
134
- onPostClick?: (post: SocialPost, event: MouseEvent) => void;
135
- /** Called when author is clicked */
136
- onAuthorClick?: (post: SocialPost, event: MouseEvent) => void;
137
- /** Called when media is clicked */
138
- onMediaClick?: (post: SocialPost, mediaIndex: number, event: MouseEvent) => void;
139
45
  /** Called when layout is recalculated */
140
46
  onLayoutComplete?: (positions: ItemPosition[]) => void;
141
- /** Called when scrolling reaches near the end */
142
- onLoadMore?: () => void | Promise<void>;
143
- /** Called when an image fails to load */
144
- onImageError?: (post: SocialPost, error: Error) => void;
47
+ /** Called when an embed loads */
48
+ onEmbedLoad?: (post: SocialPost) => void;
49
+ /** Called when an embed fails to load */
50
+ onEmbedError?: (post: SocialPost, error: Error) => void;
145
51
  }
146
52
  interface ItemPosition {
147
53
  id: string;
@@ -157,152 +63,19 @@ interface LayoutState {
157
63
  containerHeight: number;
158
64
  columnWidth: number;
159
65
  }
160
- interface VirtualItem {
161
- index: number;
162
- post: SocialPost;
163
- position: ItemPosition;
164
- isVisible: boolean;
165
- }
166
- interface SocialMasonryOptions extends MasonryConfig, CardConfig, MasonryEvents {
66
+ interface SocialMasonryOptions extends MasonryConfig, EmbedConfig, MasonryEvents {
167
67
  /** Posts to display */
168
68
  posts: SocialPost[];
169
- /** Container element or selector */
170
- container: HTMLElement | string;
171
- /** Virtualization settings */
172
- virtualization?: VirtualizationConfig;
173
- /** Load more threshold (px from bottom) */
174
- loadMoreThreshold?: number;
175
- /** Show loading indicator */
176
- showLoading?: boolean;
177
- /** Custom loading element */
178
- loadingElement?: HTMLElement | string;
179
- /** Empty state message */
180
- emptyMessage?: string;
181
- /** Custom empty state element */
182
- emptyElement?: HTMLElement | string;
183
- /** Enable debug mode */
184
- debug?: boolean;
69
+ /** Container element or selector (for vanilla JS) */
70
+ container?: HTMLElement | string;
185
71
  }
186
72
  interface SocialMasonryProps extends Omit<SocialMasonryOptions, 'container'> {
187
73
  /** Additional CSS class for container */
188
74
  className?: string;
189
75
  /** Inline styles for container */
190
76
  style?: React.CSSProperties;
191
- /** Ref to container element */
192
- containerRef?: React.RefObject<HTMLDivElement>;
193
77
  }
194
78
 
195
- declare class SocialMasonry {
196
- private options;
197
- private container;
198
- private posts;
199
- private layoutEngine;
200
- private virtualizationEngine;
201
- private cardRenderer;
202
- private cards;
203
- private itemHeights;
204
- private resizeObserver;
205
- private isLoading;
206
- private instanceId;
207
- constructor(options: SocialMasonryOptions);
208
- /**
209
- * Setup container styles
210
- */
211
- private setupContainer;
212
- /**
213
- * Setup resize observer
214
- */
215
- private setupResizeObserver;
216
- /**
217
- * Handle container resize
218
- */
219
- private handleResize;
220
- /**
221
- * Initialize virtualization
222
- */
223
- private initVirtualization;
224
- /**
225
- * Handle visible items change (for virtualization)
226
- */
227
- private handleVisibleItemsChange;
228
- /**
229
- * Setup infinite scroll
230
- */
231
- private setupInfiniteScroll;
232
- /**
233
- * Load more posts
234
- */
235
- private loadMore;
236
- /**
237
- * Show loading indicator
238
- */
239
- private showLoadingIndicator;
240
- /**
241
- * Hide loading indicator
242
- */
243
- private hideLoadingIndicator;
244
- /**
245
- * Render all posts
246
- */
247
- private render;
248
- /**
249
- * Render a single card
250
- */
251
- private renderCard;
252
- /**
253
- * Recalculate layout
254
- */
255
- private recalculateLayout;
256
- /**
257
- * Show empty state
258
- */
259
- private showEmptyState;
260
- /**
261
- * Hide empty state
262
- */
263
- private hideEmptyState;
264
- /**
265
- * Add posts
266
- */
267
- addPosts(posts: SocialPost[]): void;
268
- /**
269
- * Set posts (replace all)
270
- */
271
- setPosts(posts: SocialPost[]): void;
272
- /**
273
- * Remove post
274
- */
275
- removePost(id: string): void;
276
- /**
277
- * Update options
278
- */
279
- setOptions(options: Partial<SocialMasonryOptions>): void;
280
- /**
281
- * Get layout state
282
- */
283
- getLayoutState(): LayoutState;
284
- /**
285
- * Get posts
286
- */
287
- getPosts(): SocialPost[];
288
- /**
289
- * Scroll to post
290
- */
291
- scrollToPost(id: string, behavior?: ScrollBehavior): void;
292
- /**
293
- * Refresh layout
294
- */
295
- refresh(): void;
296
- /**
297
- * Destroy instance
298
- */
299
- destroy(): void;
300
- }
301
- /**
302
- * Create a new SocialMasonry instance
303
- */
304
- declare function createSocialMasonry(options: SocialMasonryOptions): SocialMasonry;
305
-
306
79
  /**
307
80
  * Social Masonry - Layout Engine
308
81
  * Calculates positions for masonry grid items
@@ -311,6 +84,8 @@ declare function createSocialMasonry(options: SocialMasonryOptions): SocialMason
311
84
  interface LayoutEngineOptions extends MasonryConfig {
312
85
  containerWidth: number;
313
86
  itemHeights: Map<string, number>;
87
+ twitterHeight?: number;
88
+ instagramHeight?: number;
314
89
  }
315
90
  declare class LayoutEngine {
316
91
  private options;
@@ -321,11 +96,11 @@ declare class LayoutEngine {
321
96
  */
322
97
  calculate(posts: SocialPost[]): LayoutState;
323
98
  /**
324
- * Estimate item height based on content
99
+ * Get default height for embed based on platform
325
100
  */
326
- private estimateHeight;
101
+ private getDefaultHeight;
327
102
  /**
328
- * Update single item height and recalculate affected items
103
+ * Update single item height
329
104
  */
330
105
  updateItemHeight(id: string, height: number): void;
331
106
  /**
@@ -344,10 +119,6 @@ declare class LayoutEngine {
344
119
  * Get current column count
345
120
  */
346
121
  getColumnCount(): number;
347
- /**
348
- * Get CSS variables for animations
349
- */
350
- getCSSVariables(): Record<string, string>;
351
122
  }
352
123
  /**
353
124
  * Create a new layout engine instance
@@ -355,196 +126,50 @@ declare class LayoutEngine {
355
126
  declare function createLayoutEngine(options: LayoutEngineOptions): LayoutEngine;
356
127
 
357
128
  /**
358
- * Social Masonry - Virtualization Engine
359
- * Handles virtual scrolling for large lists
129
+ * Social Masonry - Utility Functions
360
130
  */
361
131
 
362
- interface VirtualizationEngineOptions extends VirtualizationConfig {
363
- posts: SocialPost[];
364
- positions: Map<string, ItemPosition>;
365
- onVisibleItemsChange?: (items: VirtualItem[]) => void;
366
- }
367
- declare class VirtualizationEngine {
368
- private options;
369
- private posts;
370
- private positions;
371
- private visibleItems;
372
- private scrollHandler;
373
- private rafId;
374
- private lastScrollTop;
375
- private isScrolling;
376
- private scrollEndTimeout;
377
- private onVisibleItemsChange?;
378
- constructor(options: VirtualizationEngineOptions);
379
- /**
380
- * Initialize scroll listener
381
- */
382
- init(): void;
383
- /**
384
- * Destroy and cleanup
385
- */
386
- destroy(): void;
387
- /**
388
- * Handle scroll event
389
- */
390
- private handleScroll;
391
- /**
392
- * Calculate which items are visible
393
- */
394
- calculateVisibleItems(): VirtualItem[];
395
- /**
396
- * Check if visible items have changed
397
- */
398
- private hasVisibleItemsChanged;
399
- /**
400
- * Update posts and positions
401
- */
402
- update(posts: SocialPost[], positions: Map<string, ItemPosition>): void;
403
- /**
404
- * Get visible items
405
- */
406
- getVisibleItems(): VirtualItem[];
407
- /**
408
- * Get all items (for non-virtualized mode)
409
- */
410
- getAllItems(): VirtualItem[];
411
- /**
412
- * Check if scrolling
413
- */
414
- getIsScrolling(): boolean;
415
- /**
416
- * Get scroll direction
417
- */
418
- getScrollDirection(): 'up' | 'down' | 'none';
419
- /**
420
- * Check if near bottom (for infinite scroll)
421
- */
422
- isNearBottom(threshold?: number): boolean;
423
- /**
424
- * Scroll to item
425
- */
426
- scrollToItem(id: string, behavior?: ScrollBehavior): void;
427
- /**
428
- * Get render range for optimization
429
- */
430
- getRenderRange(): {
431
- start: number;
432
- end: number;
433
- };
434
- }
435
132
  /**
436
- * Create a new virtualization engine instance
133
+ * Extract tweet ID from Twitter/X URL
437
134
  */
438
- declare function createVirtualizationEngine(options: VirtualizationEngineOptions): VirtualizationEngine;
439
-
135
+ declare function extractTweetId(url: string): string | null;
440
136
  /**
441
- * Social Masonry - Card Renderer
442
- * Renders social media post cards with proper styling
137
+ * Extract post ID from Instagram URL
443
138
  */
444
-
445
- interface CardRendererOptions extends CardConfig {
446
- onPostClick?: (post: SocialPost, event: MouseEvent) => void;
447
- onAuthorClick?: (post: SocialPost, event: MouseEvent) => void;
448
- onMediaClick?: (post: SocialPost, mediaIndex: number, event: MouseEvent) => void;
449
- onImageError?: (post: SocialPost, error: Error) => void;
450
- }
451
- declare class CardRenderer {
452
- private options;
453
- constructor(options?: CardRendererOptions);
454
- /**
455
- * Render a single card
456
- */
457
- render(post: SocialPost, position: ItemPosition): HTMLElement;
458
- /**
459
- * Get CSS classes for card
460
- */
461
- private getCardClasses;
462
- /**
463
- * Build card HTML
464
- */
465
- private buildCardHTML;
466
- /**
467
- * Render platform icon
468
- */
469
- private renderPlatformIcon;
470
- /**
471
- * Render card header
472
- */
473
- private renderHeader;
474
- /**
475
- * Render card content
476
- */
477
- private renderContent;
478
- /**
479
- * Render Twitter content
480
- */
481
- private renderTwitterContent;
482
- /**
483
- * Render Instagram content
484
- */
485
- private renderInstagramContent;
486
- /**
487
- * Render media
488
- */
489
- private renderMedia;
490
- /**
491
- * Render Twitter media
492
- */
493
- private renderTwitterMedia;
494
- /**
495
- * Render Instagram media
496
- */
497
- private renderInstagramMedia;
498
- /**
499
- * Render footer with metrics
500
- */
501
- private renderFooter;
502
- /**
503
- * Render metrics
504
- */
505
- private renderMetrics;
506
- /**
507
- * Linkify text (URLs, mentions, hashtags)
508
- */
509
- private linkifyText;
510
- /**
511
- * Attach event listeners
512
- */
513
- private attachEventListeners;
514
- /**
515
- * Update card position
516
- */
517
- updatePosition(card: HTMLElement, position: ItemPosition): void;
518
- /**
519
- * Update options
520
- */
521
- setOptions(options: Partial<CardRendererOptions>): void;
522
- }
139
+ declare function extractInstagramId(url: string): string | null;
523
140
  /**
524
- * Create a new card renderer instance
141
+ * Detect platform from URL
525
142
  */
526
- declare function createCardRenderer(options?: CardRendererOptions): CardRenderer;
527
-
143
+ declare function detectPlatform(url: string): SocialPlatform | null;
528
144
  /**
529
- * Default responsive column configuration
145
+ * Generate embed URL for Twitter
530
146
  */
531
- declare const defaultColumnConfig: ColumnConfig[];
147
+ declare function getTwitterEmbedUrl(tweetId: string, options?: {
148
+ theme?: 'light' | 'dark';
149
+ hideCard?: boolean;
150
+ hideThread?: boolean;
151
+ }): string;
532
152
  /**
533
- * Format number with abbreviations (1K, 1M, etc.)
153
+ * Generate embed URL for Instagram
534
154
  */
535
- declare function formatNumber(num: number): string;
155
+ declare function getInstagramEmbedUrl(postId: string): string;
536
156
  /**
537
- * Format relative time
157
+ * Generate unique ID from post URL
538
158
  */
539
- declare function formatRelativeTime(date: Date): string;
159
+ declare function generatePostId(post: SocialPost): string;
540
160
  /**
541
- * Type guard for Twitter posts
161
+ * Get number of columns based on viewport width
542
162
  */
543
- declare function isTwitterPost(post: SocialPost): post is TwitterPost;
163
+ declare function getColumnCount(columns: number | ColumnConfig[], containerWidth: number): number;
164
+ /**
165
+ * Default responsive column configuration
166
+ */
167
+ declare const defaultColumnConfig: ColumnConfig[];
544
168
  /**
545
- * Type guard for Instagram posts
169
+ * Default embed heights
546
170
  */
547
- declare function isInstagramPost(post: SocialPost): post is InstagramPost;
171
+ declare const DEFAULT_TWITTER_HEIGHT = 500;
172
+ declare const DEFAULT_INSTAGRAM_HEIGHT = 600;
548
173
 
549
- export { CardRenderer, LayoutEngine, SocialMasonry, VirtualizationEngine, createCardRenderer, createLayoutEngine, createSocialMasonry, createVirtualizationEngine, SocialMasonry as default, defaultColumnConfig, formatNumber, formatRelativeTime, isInstagramPost, isTwitterPost };
550
- export type { CardConfig, CardTheme, CardVariant, ColumnConfig, InstagramPost, ItemPosition, LayoutState, MasonryConfig, MasonryEvents, SocialMasonryOptions, SocialMasonryProps, SocialPlatform, SocialPost, TwitterPost, VirtualItem, VirtualizationConfig };
174
+ export { DEFAULT_INSTAGRAM_HEIGHT, DEFAULT_TWITTER_HEIGHT, LayoutEngine, createLayoutEngine, defaultColumnConfig, detectPlatform, extractInstagramId, extractTweetId, generatePostId, getColumnCount, getInstagramEmbedUrl, getTwitterEmbedUrl };
175
+ export type { ColumnConfig, EmbedConfig, ItemPosition, LayoutState, MasonryConfig, MasonryEvents, SocialMasonryOptions, SocialMasonryProps, SocialPlatform, SocialPost };