@katajere/recap 2.1.6 → 2.1.7
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/RecapStory.css +288 -0
- package/dist/slides/Slide6Customer.css +30 -28
- package/dist/slides/Slide7Products.css +3 -3
- package/dist/utils/slideScreenshot.d.ts +1 -0
- package/dist/utils/slideScreenshot.d.ts.map +1 -1
- package/dist/utils/slideScreenshot.js +100 -89
- package/package.json +1 -1
- package/src/App.tsx +0 -2
- package/src/RecapStory.css +288 -0
- package/src/slides/Slide6Customer.css +30 -28
- package/src/slides/Slide7Products.css +3 -3
- package/src/utils/slideScreenshot.ts +119 -96
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
left: 50%;
|
|
24
24
|
top: 16px;
|
|
25
25
|
transform: translateX(-50%);
|
|
26
|
-
/* Height
|
|
27
|
-
height: clamp(280px,
|
|
26
|
+
/* Height: ~41% of container height */
|
|
27
|
+
height: clamp(280px, 41%, 348px);
|
|
28
28
|
animation: rectBounce1 3s ease-in-out infinite;
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
width: calc(100% - 64px);
|
|
33
33
|
max-width: 334px;
|
|
34
34
|
left: 50%;
|
|
35
|
-
top: clamp(80px,
|
|
35
|
+
top: clamp(80px, 12%, 108px);
|
|
36
36
|
transform: translateX(-50%);
|
|
37
|
-
/* Height
|
|
38
|
-
height: clamp(220px,
|
|
37
|
+
/* Height: ~32% of container height */
|
|
38
|
+
height: clamp(220px, 32%, 272px);
|
|
39
39
|
animation: rectBounce2 3s ease-in-out infinite;
|
|
40
40
|
}
|
|
41
41
|
|
|
@@ -53,12 +53,10 @@
|
|
|
53
53
|
/* Globe icon wrapper */
|
|
54
54
|
.slide6-customer__globe-wrapper {
|
|
55
55
|
position: absolute;
|
|
56
|
-
width:
|
|
57
|
-
max-width: 94px;
|
|
58
|
-
min-width: 60px;
|
|
56
|
+
width: clamp(60px, 24%, 94px);
|
|
59
57
|
aspect-ratio: 94 / 100;
|
|
60
58
|
left: 50%;
|
|
61
|
-
top: 18.
|
|
59
|
+
top: 18.5%;
|
|
62
60
|
transform: translateX(-50%);
|
|
63
61
|
display: flex;
|
|
64
62
|
align-items: center;
|
|
@@ -79,13 +77,13 @@
|
|
|
79
77
|
max-width: 302px;
|
|
80
78
|
height: 36px;
|
|
81
79
|
left: 50%;
|
|
82
|
-
top: clamp(260px,
|
|
80
|
+
top: clamp(260px, 37%, 312px);
|
|
83
81
|
transform: translateX(-50%);
|
|
84
82
|
display: flex;
|
|
85
83
|
flex-direction: row;
|
|
86
84
|
align-items: center;
|
|
87
85
|
justify-content: space-evenly;
|
|
88
|
-
padding: 8px;
|
|
86
|
+
/* padding: 8px; */
|
|
89
87
|
gap: 8px;
|
|
90
88
|
background: #FCFCFC;
|
|
91
89
|
border: 1px solid #CDCCF4;
|
|
@@ -96,6 +94,7 @@
|
|
|
96
94
|
width: 20px;
|
|
97
95
|
height: 20px;
|
|
98
96
|
flex-shrink: 0;
|
|
97
|
+
align-self: center;
|
|
99
98
|
}
|
|
100
99
|
|
|
101
100
|
.slide6-customer__link-text {
|
|
@@ -103,12 +102,13 @@
|
|
|
103
102
|
font-style: normal;
|
|
104
103
|
font-weight: 600;
|
|
105
104
|
font-size: 12px;
|
|
106
|
-
line-height:
|
|
105
|
+
line-height: 36px; /* Match link-bar height for vertical centering */
|
|
107
106
|
text-align: center;
|
|
108
107
|
color: #4F4CD8;
|
|
109
108
|
white-space: nowrap;
|
|
110
109
|
overflow: hidden;
|
|
111
110
|
text-overflow: ellipsis;
|
|
111
|
+
align-self: center;
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
/* Stats content */
|
|
@@ -139,8 +139,8 @@
|
|
|
139
139
|
font-family: 'Lora', serif;
|
|
140
140
|
font-style: normal;
|
|
141
141
|
font-weight: 700;
|
|
142
|
-
font-size: clamp(60px,
|
|
143
|
-
line-height: 1;
|
|
142
|
+
font-size: clamp(60px, 10%, 80px);
|
|
143
|
+
/* line-height: 1; */
|
|
144
144
|
text-align: center;
|
|
145
145
|
color: #4F4CD8;
|
|
146
146
|
margin: 0;
|
|
@@ -148,7 +148,7 @@
|
|
|
148
148
|
|
|
149
149
|
/* Secondary number styling - like repeat buyers in Slide5 */
|
|
150
150
|
.slide6-customer__number--secondary {
|
|
151
|
-
font-size: clamp(50px,
|
|
151
|
+
font-size: clamp(50px, 8%, 70px);
|
|
152
152
|
color: #FFFFFF;
|
|
153
153
|
-webkit-text-stroke: 1.5px #4F4CD8;
|
|
154
154
|
paint-order: stroke fill;
|
|
@@ -160,7 +160,7 @@
|
|
|
160
160
|
font-style: normal;
|
|
161
161
|
font-weight: 400;
|
|
162
162
|
font-size: clamp(14px, 4.1vw, 16px);
|
|
163
|
-
line-height: 1.5;
|
|
163
|
+
/* line-height: 1.5; */
|
|
164
164
|
text-align: center;
|
|
165
165
|
color: #3734D3;
|
|
166
166
|
margin: 0;
|
|
@@ -177,7 +177,7 @@
|
|
|
177
177
|
font-style: normal;
|
|
178
178
|
font-weight: 400;
|
|
179
179
|
font-size: clamp(14px, 4.1vw, 16px);
|
|
180
|
-
line-height: 1.5;
|
|
180
|
+
/* line-height: 1.5; */
|
|
181
181
|
text-align: center;
|
|
182
182
|
color: #3734D3;
|
|
183
183
|
}
|
|
@@ -197,7 +197,7 @@
|
|
|
197
197
|
.slide6-customer__globe-wrapper {
|
|
198
198
|
width: 70px;
|
|
199
199
|
min-width: 70px;
|
|
200
|
-
top:
|
|
200
|
+
top: 16%;
|
|
201
201
|
}
|
|
202
202
|
|
|
203
203
|
.slide6-customer__link-bar {
|
|
@@ -210,11 +210,11 @@
|
|
|
210
210
|
}
|
|
211
211
|
|
|
212
212
|
.slide6-customer__number {
|
|
213
|
-
font-size: clamp(50px,
|
|
213
|
+
font-size: clamp(50px, 10%, 70px);
|
|
214
214
|
}
|
|
215
215
|
|
|
216
216
|
.slide6-customer__number--secondary {
|
|
217
|
-
font-size: clamp(42px,
|
|
217
|
+
font-size: clamp(42px, 8%, 60px);
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
|
|
@@ -233,17 +233,18 @@
|
|
|
233
233
|
.slide6-customer__globe-wrapper {
|
|
234
234
|
width: 60px;
|
|
235
235
|
min-width: 60px;
|
|
236
|
-
top:
|
|
236
|
+
top: 14%;
|
|
237
237
|
}
|
|
238
238
|
|
|
239
239
|
.slide6-customer__link-bar {
|
|
240
240
|
height: 32px;
|
|
241
|
-
padding: 6px;
|
|
241
|
+
/* padding: 6px; */
|
|
242
242
|
top: 220px;
|
|
243
243
|
}
|
|
244
244
|
|
|
245
245
|
.slide6-customer__link-text {
|
|
246
246
|
font-size: 11px;
|
|
247
|
+
line-height: 32px; /* Match link-bar height */
|
|
247
248
|
}
|
|
248
249
|
|
|
249
250
|
.slide6-customer__content {
|
|
@@ -256,11 +257,11 @@
|
|
|
256
257
|
}
|
|
257
258
|
|
|
258
259
|
.slide6-customer__number {
|
|
259
|
-
font-size: clamp(44px,
|
|
260
|
+
font-size: clamp(44px, 9%, 60px);
|
|
260
261
|
}
|
|
261
262
|
|
|
262
263
|
.slide6-customer__number--secondary {
|
|
263
|
-
font-size: clamp(36px,
|
|
264
|
+
font-size: clamp(36px, 7%, 52px);
|
|
264
265
|
}
|
|
265
266
|
|
|
266
267
|
.slide6-customer__label {
|
|
@@ -288,17 +289,18 @@
|
|
|
288
289
|
.slide6-customer__globe-wrapper {
|
|
289
290
|
width: 50px;
|
|
290
291
|
min-width: 50px;
|
|
291
|
-
top:
|
|
292
|
+
top: 12%;
|
|
292
293
|
}
|
|
293
294
|
|
|
294
295
|
.slide6-customer__link-bar {
|
|
295
296
|
height: 28px;
|
|
296
|
-
padding: 4px 6px;
|
|
297
|
+
/* padding: 4px 6px; */
|
|
297
298
|
top: 180px;
|
|
298
299
|
}
|
|
299
300
|
|
|
300
301
|
.slide6-customer__link-text {
|
|
301
302
|
font-size: 10px;
|
|
303
|
+
line-height: 28px; /* Match link-bar height */
|
|
302
304
|
}
|
|
303
305
|
|
|
304
306
|
.slide6-customer__search-icon {
|
|
@@ -316,11 +318,11 @@
|
|
|
316
318
|
}
|
|
317
319
|
|
|
318
320
|
.slide6-customer__number {
|
|
319
|
-
font-size: clamp(38px,
|
|
321
|
+
font-size: clamp(38px, 8%, 52px);
|
|
320
322
|
}
|
|
321
323
|
|
|
322
324
|
.slide6-customer__number--secondary {
|
|
323
|
-
font-size: clamp(30px,
|
|
325
|
+
font-size: clamp(30px, 6%, 44px);
|
|
324
326
|
}
|
|
325
327
|
|
|
326
328
|
.slide6-customer__label {
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
font-family: 'Lora', serif;
|
|
49
49
|
font-size: clamp(18px, 6.15vw, 24px);
|
|
50
50
|
font-weight: 700;
|
|
51
|
-
line-height: 1.3;
|
|
51
|
+
/* line-height: 1.3; */
|
|
52
52
|
background: var(--bg-gradient);
|
|
53
53
|
-webkit-background-clip: text;
|
|
54
54
|
-webkit-text-fill-color: transparent;
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
.slide7-products__text {
|
|
90
90
|
display: flex;
|
|
91
91
|
flex-direction: column;
|
|
92
|
-
gap: 0.83%;
|
|
92
|
+
/* gap: 0.83%; */
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
.slide7-products__title,
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
.slide7-products__title {
|
|
107
107
|
font-size: clamp(16px, 5.13vw, 20px);
|
|
108
108
|
font-weight: 700;
|
|
109
|
-
line-height: 1.3;
|
|
109
|
+
/* line-height: 1.3; */
|
|
110
110
|
display: -webkit-box;
|
|
111
111
|
-webkit-box-orient: vertical;
|
|
112
112
|
-webkit-line-clamp: 2;
|
|
@@ -9,6 +9,12 @@ export interface ScreenshotOptions {
|
|
|
9
9
|
// Cache for pre-captured screenshots
|
|
10
10
|
const screenshotCache = new Map<string, File>();
|
|
11
11
|
|
|
12
|
+
// Fixed screenshot dimensions (9:16 aspect ratio)
|
|
13
|
+
// Base size: 390x692, with scale 3 = 1170x2076 (close to Instagram Story standard)
|
|
14
|
+
const SCREENSHOT_WIDTH = 390;
|
|
15
|
+
const SCREENSHOT_HEIGHT = 692;
|
|
16
|
+
const SCREENSHOT_SCALE = 3; // Output: 1170x2076
|
|
17
|
+
|
|
12
18
|
/**
|
|
13
19
|
* Detects if the device is mobile
|
|
14
20
|
*/
|
|
@@ -17,9 +23,67 @@ function isMobileDevice(): boolean {
|
|
|
17
23
|
(navigator.maxTouchPoints > 0 && window.innerWidth < 768);
|
|
18
24
|
}
|
|
19
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Creates a fixed-size off-screen container with cloned content for consistent screenshots.
|
|
28
|
+
* This ensures all screenshots are 1080x1920 regardless of user's screen size.
|
|
29
|
+
*/
|
|
30
|
+
function createFixedSizeContainer(storyContainer: HTMLElement): HTMLElement {
|
|
31
|
+
// Create off-screen container
|
|
32
|
+
const captureContainer = document.createElement('div');
|
|
33
|
+
captureContainer.className = 'screenshot-capture-container';
|
|
34
|
+
|
|
35
|
+
// Clone the story container
|
|
36
|
+
const clonedStory = storyContainer.cloneNode(true) as HTMLElement;
|
|
37
|
+
clonedStory.classList.add('screenshot-mode');
|
|
38
|
+
|
|
39
|
+
// Remove buttons and progress bar from clone
|
|
40
|
+
const elementsToRemove = clonedStory.querySelectorAll(
|
|
41
|
+
'.recap-story__sound-btn, .recap-story__share-btn, .recap-story__progress-wrap'
|
|
42
|
+
);
|
|
43
|
+
elementsToRemove.forEach(el => el.remove());
|
|
44
|
+
|
|
45
|
+
captureContainer.appendChild(clonedStory);
|
|
46
|
+
document.body.appendChild(captureContainer);
|
|
47
|
+
|
|
48
|
+
return captureContainer;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Captures a screenshot from the fixed-size container
|
|
53
|
+
*/
|
|
54
|
+
async function captureFixedSizeScreenshot(captureContainer: HTMLElement): Promise<Blob> {
|
|
55
|
+
const clonedStory = captureContainer.querySelector('.recap-story') as HTMLElement;
|
|
56
|
+
|
|
57
|
+
const canvas = await html2canvas(clonedStory, {
|
|
58
|
+
scale: SCREENSHOT_SCALE,
|
|
59
|
+
useCORS: true,
|
|
60
|
+
allowTaint: true,
|
|
61
|
+
backgroundColor: '#FCFCFC',
|
|
62
|
+
logging: false,
|
|
63
|
+
width: SCREENSHOT_WIDTH,
|
|
64
|
+
height: SCREENSHOT_HEIGHT,
|
|
65
|
+
windowWidth: SCREENSHOT_WIDTH,
|
|
66
|
+
windowHeight: SCREENSHOT_HEIGHT,
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const blob = await new Promise<Blob>((resolve, reject) => {
|
|
70
|
+
canvas.toBlob(
|
|
71
|
+
(b) => {
|
|
72
|
+
if (b) resolve(b);
|
|
73
|
+
else reject(new Error('Failed to create blob'));
|
|
74
|
+
},
|
|
75
|
+
'image/png',
|
|
76
|
+
1.0
|
|
77
|
+
);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
return blob;
|
|
81
|
+
}
|
|
82
|
+
|
|
20
83
|
/**
|
|
21
84
|
* Pre-captures a screenshot of the slide and caches it.
|
|
22
85
|
* Call this when a slide becomes active so the image is ready for instant sharing.
|
|
86
|
+
* Uses fixed 1080x1920 dimensions for consistent output across all devices.
|
|
23
87
|
*/
|
|
24
88
|
export async function preCaptureSlide(
|
|
25
89
|
containerRef: HTMLElement | null,
|
|
@@ -32,62 +96,44 @@ export async function preCaptureSlide(
|
|
|
32
96
|
|
|
33
97
|
// Skip if already cached
|
|
34
98
|
if (screenshotCache.has(cacheKey)) {
|
|
35
|
-
console.log('[Screenshot] Using cached screenshot for:', cacheKey);
|
|
99
|
+
// console.log('[Screenshot] Using cached screenshot for:', cacheKey);
|
|
36
100
|
return;
|
|
37
101
|
}
|
|
38
102
|
|
|
39
103
|
const storyContainer = containerRef.closest('.recap-story') as HTMLElement;
|
|
40
104
|
if (!storyContainer) return;
|
|
41
105
|
|
|
106
|
+
let captureContainer: HTMLElement | null = null;
|
|
107
|
+
|
|
42
108
|
try {
|
|
43
|
-
console.log('[Screenshot] Pre-capturing slide:', slideId);
|
|
44
|
-
|
|
45
|
-
const canvas = await html2canvas(storyContainer, {
|
|
46
|
-
scale: 3, // Higher scale for better image quality
|
|
47
|
-
useCORS: true,
|
|
48
|
-
allowTaint: true,
|
|
49
|
-
backgroundColor: '#FCFCFC',
|
|
50
|
-
logging: false,
|
|
51
|
-
windowWidth: storyContainer.scrollWidth,
|
|
52
|
-
windowHeight: storyContainer.scrollHeight,
|
|
53
|
-
ignoreElements: (element) => {
|
|
54
|
-
// Ignore buttons and progress bar - they're excluded from screenshot
|
|
55
|
-
return element.classList.contains('recap-story__sound-btn') ||
|
|
56
|
-
element.classList.contains('recap-story__share-btn') ||
|
|
57
|
-
element.classList.contains('recap-story__progress-wrap');
|
|
58
|
-
},
|
|
59
|
-
// Apply screenshot-mode to cloned DOM only (not visible to user)
|
|
60
|
-
onclone: (clonedDoc) => {
|
|
61
|
-
const clonedContainer = clonedDoc.querySelector('.recap-story');
|
|
62
|
-
if (clonedContainer) {
|
|
63
|
-
clonedContainer.classList.add('screenshot-mode');
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
});
|
|
109
|
+
// console.log('[Screenshot] Pre-capturing slide at fixed 1080x1920:', slideId);
|
|
67
110
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
});
|
|
111
|
+
// Create fixed-size off-screen container with cloned content
|
|
112
|
+
captureContainer = createFixedSizeContainer(storyContainer);
|
|
113
|
+
|
|
114
|
+
// Small delay (~1 frame at 60fps) so the browser can complete style recalculation
|
|
115
|
+
// and layout for the cloned DOM elements before capturing the screenshot.
|
|
116
|
+
await new Promise(resolve => setTimeout(resolve, 50));
|
|
117
|
+
|
|
118
|
+
// Capture from the fixed-size container
|
|
119
|
+
const blob = await captureFixedSizeScreenshot(captureContainer);
|
|
78
120
|
|
|
79
|
-
const mimeType = 'image/png';
|
|
80
121
|
const fileName = `${businessName.replace(/\s+/g, '-')}-recap-${year}-${slideId}.png`;
|
|
81
122
|
const file = new File([blob], fileName, {
|
|
82
|
-
type:
|
|
123
|
+
type: 'image/png',
|
|
83
124
|
lastModified: Date.now()
|
|
84
125
|
});
|
|
85
126
|
|
|
86
127
|
screenshotCache.set(cacheKey, file);
|
|
87
|
-
console.log('[Screenshot] Pre-capture complete:', cacheKey, file.size, 'bytes');
|
|
128
|
+
// console.log('[Screenshot] Pre-capture complete:', cacheKey, file.size, 'bytes', '(1080x1920)');
|
|
88
129
|
|
|
89
130
|
} catch (error) {
|
|
90
131
|
console.error('[Screenshot] Pre-capture failed:', error);
|
|
132
|
+
} finally {
|
|
133
|
+
// Clean up off-screen container (skip in debug mode)
|
|
134
|
+
if (captureContainer && captureContainer.parentNode) {
|
|
135
|
+
captureContainer.parentNode.removeChild(captureContainer);
|
|
136
|
+
}
|
|
91
137
|
}
|
|
92
138
|
}
|
|
93
139
|
|
|
@@ -96,7 +142,7 @@ export async function preCaptureSlide(
|
|
|
96
142
|
*/
|
|
97
143
|
export function clearScreenshotCache(): void {
|
|
98
144
|
screenshotCache.clear();
|
|
99
|
-
console.log('[Screenshot] Cache cleared');
|
|
145
|
+
// console.log('[Screenshot] Cache cleared');
|
|
100
146
|
}
|
|
101
147
|
|
|
102
148
|
/**
|
|
@@ -128,21 +174,21 @@ export async function captureAndShareSlide(
|
|
|
128
174
|
const cacheKey = `${businessName}-${year}-${slideId}`;
|
|
129
175
|
const isMobile = isMobileDevice();
|
|
130
176
|
|
|
131
|
-
console.log('[Screenshot] Device type:', isMobile ? 'mobile' : 'desktop');
|
|
132
|
-
console.log('[Screenshot] Cache key:', cacheKey);
|
|
177
|
+
// console.log('[Screenshot] Device type:', isMobile ? 'mobile' : 'desktop');
|
|
178
|
+
// console.log('[Screenshot] Cache key:', cacheKey);
|
|
133
179
|
|
|
134
180
|
// Check for cached screenshot (enables instant sharing on mobile)
|
|
135
181
|
const cachedFile = screenshotCache.get(cacheKey);
|
|
136
|
-
console.log('[Screenshot] Cache available:', !!cachedFile);
|
|
182
|
+
// console.log('[Screenshot] Cache available:', !!cachedFile);
|
|
137
183
|
|
|
138
184
|
// MOBILE: Must use cached file for instant share (user gesture chain)
|
|
139
185
|
if (isMobile) {
|
|
140
186
|
if (cachedFile) {
|
|
141
|
-
console.log('[Screenshot] Using cached file for instant share');
|
|
187
|
+
// console.log('[Screenshot] Using cached file for instant share');
|
|
142
188
|
// CRITICAL: Call navigator.share() directly without any await before it
|
|
143
189
|
// to maintain the user gesture chain on mobile browsers (especially Edge)
|
|
144
190
|
const canShareFiles = navigator.canShare && navigator.canShare({ files: [cachedFile] });
|
|
145
|
-
console.log('[Screenshot] Can share files:', canShareFiles);
|
|
191
|
+
// console.log('[Screenshot] Can share files:', canShareFiles);
|
|
146
192
|
|
|
147
193
|
if (canShareFiles) {
|
|
148
194
|
// Call share synchronously - no try/catch wrapper that could break gesture chain
|
|
@@ -151,7 +197,7 @@ export async function captureAndShareSlide(
|
|
|
151
197
|
title: 'My Huxxle Recap',
|
|
152
198
|
text: `Check out ${businessName}'s Wrapped ${year} highlights! 🎉`
|
|
153
199
|
}).then(() => {
|
|
154
|
-
console.log('[Screenshot] Share successful!');
|
|
200
|
+
// console.log('[Screenshot] Share successful!');
|
|
155
201
|
}).catch((err) => {
|
|
156
202
|
console.error('[Screenshot] Share failed:', err);
|
|
157
203
|
// If user cancelled (AbortError), don't download
|
|
@@ -165,7 +211,7 @@ export async function captureAndShareSlide(
|
|
|
165
211
|
}
|
|
166
212
|
|
|
167
213
|
// Mobile browser doesn't support file sharing - download instead
|
|
168
|
-
console.log('[Screenshot] File sharing not supported, downloading...');
|
|
214
|
+
// console.log('[Screenshot] File sharing not supported, downloading...');
|
|
169
215
|
const blob = new Blob([cachedFile], { type: cachedFile.type });
|
|
170
216
|
downloadImage(blob, cachedFile.name);
|
|
171
217
|
return;
|
|
@@ -177,67 +223,41 @@ export async function captureAndShareSlide(
|
|
|
177
223
|
// Continue to fresh capture below, but it will download instead of share
|
|
178
224
|
}
|
|
179
225
|
|
|
180
|
-
// DESKTOP or MOBILE-FALLBACK: Capture fresh screenshot
|
|
226
|
+
// DESKTOP or MOBILE-FALLBACK: Capture fresh screenshot with fixed dimensions
|
|
181
227
|
const storyContainer = containerRef.closest('.recap-story') as HTMLElement;
|
|
182
228
|
if (!storyContainer) {
|
|
183
229
|
console.error('[Screenshot] Could not find .recap-story container');
|
|
184
230
|
return;
|
|
185
231
|
}
|
|
186
232
|
|
|
233
|
+
let captureContainer: HTMLElement | null = null;
|
|
234
|
+
|
|
187
235
|
try {
|
|
188
|
-
console.log('[Screenshot] Starting capture...');
|
|
189
|
-
|
|
190
|
-
const canvas = await html2canvas(storyContainer, {
|
|
191
|
-
scale: 3, // Higher scale for better image quality
|
|
192
|
-
useCORS: true,
|
|
193
|
-
allowTaint: true,
|
|
194
|
-
backgroundColor: '#FCFCFC',
|
|
195
|
-
logging: false,
|
|
196
|
-
windowWidth: storyContainer.scrollWidth,
|
|
197
|
-
windowHeight: storyContainer.scrollHeight,
|
|
198
|
-
ignoreElements: (element) => {
|
|
199
|
-
// Ignore buttons and progress bar - they're excluded from screenshot
|
|
200
|
-
return element.classList.contains('recap-story__sound-btn') ||
|
|
201
|
-
element.classList.contains('recap-story__share-btn') ||
|
|
202
|
-
element.classList.contains('recap-story__progress-wrap');
|
|
203
|
-
},
|
|
204
|
-
// Apply screenshot-mode to cloned DOM only (not visible to user)
|
|
205
|
-
onclone: (clonedDoc) => {
|
|
206
|
-
const clonedContainer = clonedDoc.querySelector('.recap-story');
|
|
207
|
-
if (clonedContainer) {
|
|
208
|
-
clonedContainer.classList.add('screenshot-mode');
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
});
|
|
236
|
+
// console.log('[Screenshot] Starting fixed-size capture (1080x1920)...');
|
|
212
237
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
'image/png',
|
|
222
|
-
1.0
|
|
223
|
-
);
|
|
224
|
-
});
|
|
238
|
+
// Create fixed-size off-screen container with cloned content
|
|
239
|
+
captureContainer = createFixedSizeContainer(storyContainer);
|
|
240
|
+
|
|
241
|
+
// Small delay to allow styles to apply to cloned content
|
|
242
|
+
await new Promise(resolve => setTimeout(resolve, 50));
|
|
243
|
+
|
|
244
|
+
// Capture from the fixed-size container
|
|
245
|
+
const blob = await captureFixedSizeScreenshot(captureContainer);
|
|
225
246
|
|
|
226
|
-
console.log('[Screenshot] Blob created:', blob.size, 'bytes');
|
|
247
|
+
// console.log('[Screenshot] Blob created:', blob.size, 'bytes', '(1080x1920)');
|
|
227
248
|
|
|
228
|
-
const mimeType = 'image/png';
|
|
229
249
|
const fileName = `${businessName.replace(/\s+/g, '-')}-recap-${year}-${slideId}.png`;
|
|
230
250
|
|
|
231
251
|
// DESKTOP: Always download
|
|
232
252
|
if (!isMobile) {
|
|
233
|
-
console.log('[Screenshot] Desktop - downloading...');
|
|
253
|
+
// console.log('[Screenshot] Desktop - downloading...');
|
|
234
254
|
downloadImage(blob, fileName);
|
|
235
255
|
return;
|
|
236
256
|
}
|
|
237
257
|
|
|
238
258
|
// MOBILE (no cache): Try to share, likely will fail due to user gesture timing
|
|
239
259
|
const file = new File([blob], fileName, {
|
|
240
|
-
type:
|
|
260
|
+
type: 'image/png',
|
|
241
261
|
lastModified: Date.now()
|
|
242
262
|
});
|
|
243
263
|
|
|
@@ -249,7 +269,10 @@ export async function captureAndShareSlide(
|
|
|
249
269
|
} catch (error) {
|
|
250
270
|
console.error('[Screenshot] Capture failed:', error);
|
|
251
271
|
} finally {
|
|
252
|
-
|
|
272
|
+
// Clean up off-screen container
|
|
273
|
+
if (captureContainer && captureContainer.parentNode) {
|
|
274
|
+
captureContainer.parentNode.removeChild(captureContainer);
|
|
275
|
+
}
|
|
253
276
|
}
|
|
254
277
|
}
|
|
255
278
|
|
|
@@ -257,7 +280,7 @@ export async function captureAndShareSlide(
|
|
|
257
280
|
* Shares a file using Web Share API with fallbacks
|
|
258
281
|
*/
|
|
259
282
|
async function shareFile(file: File, businessName: string, year: number): Promise<void> {
|
|
260
|
-
console.log('[Screenshot] File to share:', file.name, file.type, file.size, 'bytes');
|
|
283
|
+
// console.log('[Screenshot] File to share:', file.name, file.type, file.size, 'bytes');
|
|
261
284
|
|
|
262
285
|
// Validate file size (WhatsApp limit: 5MB for images)
|
|
263
286
|
const maxSize = 5 * 1024 * 1024;
|
|
@@ -268,18 +291,18 @@ async function shareFile(file: File, businessName: string, year: number): Promis
|
|
|
268
291
|
|
|
269
292
|
// Check if Web Share API with files is supported
|
|
270
293
|
const canShareFiles = navigator.canShare && navigator.canShare({ files: [file] });
|
|
271
|
-
console.log('[Screenshot] Can share files:', canShareFiles);
|
|
294
|
+
// console.log('[Screenshot] Can share files:', canShareFiles);
|
|
272
295
|
|
|
273
296
|
// Try sharing with file
|
|
274
297
|
if (canShareFiles) {
|
|
275
|
-
console.log('[Screenshot] Sharing file...');
|
|
298
|
+
// console.log('[Screenshot] Sharing file...');
|
|
276
299
|
try {
|
|
277
300
|
await navigator.share({
|
|
278
301
|
files: [file],
|
|
279
302
|
title: 'My Huxxle Recap',
|
|
280
303
|
text: `Check out ${businessName}'s Wrapped ${year} highlights! 🎉`
|
|
281
304
|
});
|
|
282
|
-
console.log('[Screenshot] Share successful!');
|
|
305
|
+
// console.log('[Screenshot] Share successful!');
|
|
283
306
|
return;
|
|
284
307
|
} catch (shareError) {
|
|
285
308
|
console.error('[Screenshot] File share failed:', shareError);
|
|
@@ -288,7 +311,7 @@ async function shareFile(file: File, businessName: string, year: number): Promis
|
|
|
288
311
|
|
|
289
312
|
// Fallback: share URL only
|
|
290
313
|
if (navigator.share) {
|
|
291
|
-
console.log('[Screenshot] Sharing URL fallback...');
|
|
314
|
+
// console.log('[Screenshot] Sharing URL fallback...');
|
|
292
315
|
try {
|
|
293
316
|
await navigator.share({
|
|
294
317
|
title: 'My Huxxle Recap',
|
|
@@ -302,7 +325,7 @@ async function shareFile(file: File, businessName: string, year: number): Promis
|
|
|
302
325
|
}
|
|
303
326
|
|
|
304
327
|
// Final fallback: download
|
|
305
|
-
console.log('[Screenshot] Download fallback...');
|
|
328
|
+
// console.log('[Screenshot] Download fallback...');
|
|
306
329
|
const blob = new Blob([await file.arrayBuffer()], { type: file.type });
|
|
307
330
|
downloadImage(blob, file.name);
|
|
308
331
|
}
|
|
@@ -311,7 +334,7 @@ async function shareFile(file: File, businessName: string, year: number): Promis
|
|
|
311
334
|
* Downloads an image blob
|
|
312
335
|
*/
|
|
313
336
|
function downloadImage(blob: Blob, fileName: string): void {
|
|
314
|
-
console.log('[Screenshot] Downloading:', fileName);
|
|
337
|
+
// console.log('[Screenshot] Downloading:', fileName);
|
|
315
338
|
const url = URL.createObjectURL(blob);
|
|
316
339
|
const a = document.createElement('a');
|
|
317
340
|
a.href = url;
|
|
@@ -320,5 +343,5 @@ function downloadImage(blob: Blob, fileName: string): void {
|
|
|
320
343
|
a.click();
|
|
321
344
|
document.body.removeChild(a);
|
|
322
345
|
URL.revokeObjectURL(url);
|
|
323
|
-
console.log('[Screenshot] Download complete');
|
|
346
|
+
// console.log('[Screenshot] Download complete');
|
|
324
347
|
}
|