@gemx-dev/heatmap-react 3.5.28 → 3.5.30

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/esm/index.js CHANGED
@@ -1,8 +1,9 @@
1
1
  "use client"
2
2
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
3
3
  import { useNodesState, ReactFlow, Controls, Background } from '@xyflow/react';
4
- import { useEffect, useMemo, useCallback } from 'react';
4
+ import { useEffect, useMemo, useState, useCallback, useRef, Fragment as Fragment$1 } from 'react';
5
5
  import { create } from 'zustand';
6
+ import { Visualizer } from '@gemx-dev/clarity-visualize';
6
7
 
7
8
  const initialNodes = { id: '1', position: { x: 0, y: 0 }, data: { label: '1' } };
8
9
  const GraphView = ({ children, width, height }) => {
@@ -92,6 +93,1183 @@ const BoxStack = ({ children, ...props }) => {
92
93
  return (jsx("div", { id: id, style: styleProps, children: children }));
93
94
  };
94
95
 
96
+ const ContentHeader = ({ children }) => {
97
+ return (jsx(BoxStack, { id: "gx-hm-content-header", flexDirection: "row", alignItems: "center", overflow: "auto", children: children }));
98
+ };
99
+
100
+ const HEATMAP_IFRAME = {
101
+ id: 'clarity-iframe',
102
+ title: 'Clarity Session Replay',
103
+ sandbox: 'allow-same-origin allow-scripts',
104
+ scrolling: 'no',
105
+ height: '100%',
106
+ };
107
+
108
+ const HEATMAP_CONFIG = {
109
+ paddingBlock: 0,
110
+ };
111
+ const HEATMAP_STYLE = {
112
+ wrapper: {
113
+ padding: `${HEATMAP_CONFIG.paddingBlock}px 0`,
114
+ },
115
+ };
116
+
117
+ const useClickedElement = ({ selectedElement, heatmapInfo, getRect }) => {
118
+ const [clickedElement, setClickedElement] = useState(null);
119
+ const [showMissingElement, setShowMissingElement] = useState(false);
120
+ const [shouldShowCallout, setShouldShowCallout] = useState(false);
121
+ useEffect(() => {
122
+ if (!selectedElement || !heatmapInfo?.elementMapInfo) {
123
+ setClickedElement(null);
124
+ setShowMissingElement(false);
125
+ setShouldShowCallout(false);
126
+ return;
127
+ }
128
+ const info = heatmapInfo.elementMapInfo[selectedElement];
129
+ if (!info) {
130
+ setClickedElement(null);
131
+ return;
132
+ }
133
+ const rect = getRect({ hash: selectedElement, selector: info.selector });
134
+ if (rect && heatmapInfo.sortedElements) {
135
+ const rank = heatmapInfo.sortedElements.findIndex((e) => e.hash === selectedElement) + 1;
136
+ setClickedElement({
137
+ ...rect,
138
+ hash: selectedElement,
139
+ clicks: info.totalclicks ?? 0,
140
+ rank,
141
+ selector: info.selector ?? '',
142
+ });
143
+ setShowMissingElement(false);
144
+ setShouldShowCallout(true);
145
+ }
146
+ else {
147
+ const rank = (heatmapInfo.sortedElements?.findIndex((e) => e.hash === selectedElement) ?? -1) + 1;
148
+ setClickedElement({
149
+ hash: selectedElement,
150
+ clicks: info.totalclicks ?? 0,
151
+ rank,
152
+ selector: info.selector ?? '',
153
+ left: 0,
154
+ top: 0,
155
+ width: 0,
156
+ height: 0,
157
+ });
158
+ setShowMissingElement(true);
159
+ setShouldShowCallout(false);
160
+ }
161
+ }, [selectedElement, heatmapInfo, getRect]);
162
+ return { clickedElement, showMissingElement, shouldShowCallout, setShouldShowCallout };
163
+ };
164
+
165
+ const useHeatmapEffects = ({ isVisible, isElementSidebarOpen, selectedElement, setShouldShowCallout, resetAll, }) => {
166
+ // Reset khi ẩn
167
+ useEffect(() => {
168
+ if (!isVisible)
169
+ resetAll();
170
+ }, [isVisible, resetAll]);
171
+ // Ẩn callout khi sidebar mở
172
+ useEffect(() => {
173
+ if (isElementSidebarOpen && selectedElement) {
174
+ setShouldShowCallout(false);
175
+ }
176
+ else if (!isElementSidebarOpen && selectedElement) {
177
+ setShouldShowCallout(true);
178
+ }
179
+ }, [isElementSidebarOpen, selectedElement, setShouldShowCallout]);
180
+ };
181
+
182
+ function getElementLayout(element) {
183
+ if (!element?.getBoundingClientRect)
184
+ return null;
185
+ const rect = element.getBoundingClientRect();
186
+ if (rect.width === 0 && rect.height === 0)
187
+ return null;
188
+ return {
189
+ top: rect.top,
190
+ left: rect.left,
191
+ width: rect.width,
192
+ height: rect.height,
193
+ };
194
+ }
195
+ function formatPercentage(value, decimals = 2) {
196
+ return value.toFixed(decimals);
197
+ }
198
+ function getSimpleSelector(selector) {
199
+ const parts = selector.split(' > ');
200
+ return parts[parts.length - 1] || selector;
201
+ }
202
+ function calculateRankPosition(rect, widthScale) {
203
+ const top = rect.top <= 18 ? rect.top + 3 : rect.top - 18;
204
+ const left = rect.left <= 18 ? rect.left + 3 : rect.left - 18;
205
+ return {
206
+ transform: `scale(${1.2 * widthScale})`,
207
+ top: Number.isNaN(top) ? undefined : top,
208
+ left: Number.isNaN(left) ? undefined : left,
209
+ };
210
+ }
211
+
212
+ const useHeatmapElementPosition = ({ iframeRef, parentRef, visualizer, heatmapWidth, iframeHeight, widthScale, projectId, }) => {
213
+ return useCallback((element) => {
214
+ const hash = element?.hash;
215
+ if (!iframeRef.current?.contentDocument || !hash || !visualizer)
216
+ return null;
217
+ let domElement = null;
218
+ try {
219
+ domElement = visualizer.get(hash);
220
+ }
221
+ catch (error) {
222
+ console.error('Visualizer error:', { projectId, hash, error });
223
+ return null;
224
+ }
225
+ if (!domElement)
226
+ return null;
227
+ const layout = getElementLayout(domElement);
228
+ if (!layout)
229
+ return null;
230
+ const parentEl = parentRef.current;
231
+ if (!parentEl)
232
+ return null;
233
+ const scrollOffset = parentEl.scrollTop / widthScale;
234
+ const adjustedTop = layout.top + scrollOffset;
235
+ const outOfBounds = adjustedTop < 0 ||
236
+ adjustedTop > (iframeHeight || Infinity) ||
237
+ layout.left < 0 ||
238
+ (typeof heatmapWidth === 'number' && layout.left > heatmapWidth);
239
+ if (outOfBounds)
240
+ return null;
241
+ return {
242
+ left: layout.left,
243
+ top: adjustedTop,
244
+ width: Math.min(layout.width, heatmapWidth || layout.width),
245
+ height: layout.height,
246
+ };
247
+ }, [iframeRef, parentRef, visualizer, heatmapWidth, iframeHeight, widthScale, projectId]);
248
+ };
249
+
250
+ const debounce = (fn, delay) => {
251
+ let timeout;
252
+ return (...args) => {
253
+ clearTimeout(timeout);
254
+ timeout = setTimeout(() => fn(...args), delay);
255
+ };
256
+ };
257
+ const useHoveredElement = ({ iframeRef, heatmapInfo, widthScale, getRect, onSelect, }) => {
258
+ const [hoveredElement, setHoveredElement] = useState(null);
259
+ const handleMouseMove = useCallback(debounce((event) => {
260
+ if (!iframeRef.current?.contentDocument || !heatmapInfo?.elementMapInfo) {
261
+ setHoveredElement(null);
262
+ return;
263
+ }
264
+ const iframe = iframeRef.current;
265
+ const iframeRect = iframe.getBoundingClientRect();
266
+ let x = event.clientX - iframeRect.left;
267
+ console.log(`🚀 🐥 ~ useHoveredElement ~ iframeRect.left:`, iframeRect.left);
268
+ console.log(`🚀 🐥 ~ useHoveredElement ~ event.clientX:`, event.clientX);
269
+ let y = event.clientY - iframeRect.top;
270
+ if (widthScale !== 1) {
271
+ x /= widthScale;
272
+ y /= widthScale;
273
+ }
274
+ const doc = iframe.contentDocument;
275
+ if (!doc) {
276
+ setHoveredElement(null);
277
+ return;
278
+ }
279
+ let targetElement = null;
280
+ // Best: dùng caretPositionFromPoint nếu có (Chrome, Safari)
281
+ targetElement = getElementAtPoint(doc, x, y);
282
+ if (!targetElement) {
283
+ targetElement = doc.elementFromPoint(x, y);
284
+ }
285
+ if (!targetElement) {
286
+ setHoveredElement(null);
287
+ return;
288
+ }
289
+ // Lấy hash từ nhiều attribute khả dĩ
290
+ const hash = targetElement.getAttribute('data-clarity-hash') ||
291
+ targetElement.getAttribute('data-clarity-hashalpha') ||
292
+ targetElement.getAttribute('data-clarity-hashbeta');
293
+ if (!hash || !heatmapInfo.elementMapInfo[hash]) {
294
+ setHoveredElement(null);
295
+ return;
296
+ }
297
+ const info = heatmapInfo.elementMapInfo[hash];
298
+ const position = getRect({ hash, selector: info.selector });
299
+ if (position && heatmapInfo.sortedElements) {
300
+ const rank = heatmapInfo.sortedElements.findIndex((e) => e.hash === hash) + 1;
301
+ setHoveredElement({
302
+ ...position,
303
+ hash,
304
+ clicks: info.totalclicks ?? 0,
305
+ rank,
306
+ selector: info.selector ?? '',
307
+ });
308
+ }
309
+ else {
310
+ setHoveredElement(null);
311
+ }
312
+ }, 16), // ~60fps
313
+ [iframeRef, heatmapInfo, getRect]);
314
+ const handleMouseLeave = useCallback(() => {
315
+ setHoveredElement(null);
316
+ }, []);
317
+ const handleClick = useCallback(() => {
318
+ if (hoveredElement?.hash && onSelect) {
319
+ onSelect(hoveredElement.hash);
320
+ }
321
+ }, [hoveredElement, onSelect]);
322
+ return {
323
+ hoveredElement,
324
+ handleMouseMove,
325
+ handleMouseLeave,
326
+ handleClick,
327
+ };
328
+ };
329
+ const getElementAtPoint = (doc, x, y) => {
330
+ let el = null;
331
+ if ('caretPositionFromPoint' in doc) {
332
+ el = doc.caretPositionFromPoint(x, y)?.offsetNode ?? null;
333
+ }
334
+ el = el ?? doc.elementFromPoint(x, y);
335
+ let element = el;
336
+ while (element && element.nodeType === Node.TEXT_NODE) {
337
+ element = element.parentElement;
338
+ }
339
+ return element;
340
+ };
341
+
342
+ const recreateIframe = (iframeRef, config) => {
343
+ const container = iframeRef.current?.parentElement;
344
+ if (!container)
345
+ return;
346
+ const oldIframe = iframeRef.current;
347
+ if (!oldIframe?.contentDocument?.body.innerHTML) {
348
+ return oldIframe;
349
+ }
350
+ if (oldIframe && oldIframe.parentElement) {
351
+ oldIframe.parentElement.removeChild(oldIframe);
352
+ }
353
+ const newIframe = document.createElement('iframe');
354
+ newIframe.id = HEATMAP_IFRAME.id;
355
+ newIframe.title = HEATMAP_IFRAME.title;
356
+ newIframe.sandbox = HEATMAP_IFRAME.sandbox;
357
+ newIframe.scrolling = HEATMAP_IFRAME.scrolling;
358
+ newIframe.width = config?.width ? `${config.width}px` : '100%';
359
+ // Append to container
360
+ container.appendChild(newIframe);
361
+ // Update ref
362
+ iframeRef.current = newIframe;
363
+ return newIframe;
364
+ };
365
+
366
+ function isMobileDevice(userAgent) {
367
+ if (!userAgent)
368
+ return false;
369
+ return /android|webos|iphone|ipad|ipod|blackberry|windows phone|opera mini|iemobile|mobile|silk|fennec|bada|tizen|symbian|nokia|palmsource|meego|sailfish|kindle|playbook|bb10|rim/i.test(userAgent);
370
+ }
371
+
372
+ const useHeatmapRender = () => {
373
+ const data = useHeatmapDataStore((state) => state.data);
374
+ const config = useHeatmapDataStore((state) => state.config);
375
+ const setConfig = useHeatmapDataStore((state) => state.setConfig);
376
+ const clickmap = useHeatmapDataStore((state) => state.clickmap);
377
+ const visualizerRef = useRef(null);
378
+ const iframeRef = useRef(null);
379
+ const initializeVisualizer = useCallback((envelope, userAgent) => {
380
+ const iframe = iframeRef.current;
381
+ if (!iframe?.contentWindow)
382
+ return null;
383
+ const visualizer = new Visualizer();
384
+ const mobile = isMobileDevice(userAgent);
385
+ visualizer.setup(iframe.contentWindow, {
386
+ version: envelope.version,
387
+ onresize: (width) => {
388
+ setConfig({ width });
389
+ },
390
+ mobile,
391
+ vNext: true,
392
+ locale: 'en-us',
393
+ });
394
+ return visualizer;
395
+ }, []);
396
+ // Process and render heatmap HTML
397
+ const renderHeatmap = useCallback(async (payloads) => {
398
+ if (!payloads || payloads.length === 0)
399
+ return;
400
+ let visualizer = new Visualizer();
401
+ const iframe = recreateIframe(iframeRef, config);
402
+ // const merged = visualizer.merge(payloads);
403
+ // setIframeHeight(Number(iframeRef.current?.height || 0));
404
+ // for (const decoded of payloads) {
405
+ // // Initialize on first sequence
406
+ // if (decoded.envelope.sequence === 1) {
407
+ // const userAgent = (decoded.dimension?.[0]?.data[0]?.[0] as string) || '';
408
+ // visualizer = initializeVisualizer(decoded.envelope as any, userAgent);
409
+ // if (!visualizer) return;
410
+ // visualizerRef.current = visualizer;
411
+ // }
412
+ // if (!visualizer) continue;
413
+ // // Merge and process DOM
414
+ // const merged = visualizer.merge([decoded]);
415
+ // visualizer.dom(merged.dom);
416
+ // }
417
+ // Render static HTML
418
+ if (visualizer && iframe?.contentWindow) {
419
+ await visualizer.html(payloads, iframe.contentWindow);
420
+ visualizerRef.current = visualizer;
421
+ }
422
+ }, [initializeVisualizer]);
423
+ useEffect(() => {
424
+ if (!data || data.length === 0)
425
+ return;
426
+ renderHeatmap(data);
427
+ return () => {
428
+ visualizerRef.current = null;
429
+ };
430
+ }, [config, data, renderHeatmap]);
431
+ useEffect(() => {
432
+ if (!visualizerRef.current || !clickmap || clickmap.length === 0)
433
+ return;
434
+ visualizerRef.current.clearmap();
435
+ visualizerRef.current?.clickmap(clickmap);
436
+ }, [clickmap]);
437
+ return {
438
+ iframeRef,
439
+ clarityVisualizer: visualizerRef.current,
440
+ };
441
+ };
442
+
443
+ function sortEvents(a, b) {
444
+ return a.time - b.time;
445
+ }
446
+
447
+ const useReplayRender = () => {
448
+ const data = useHeatmapDataStore((state) => state.data);
449
+ const setConfig = useHeatmapDataStore((state) => state.setConfig);
450
+ const visualizerRef = useRef(null);
451
+ const iframeRef = useRef(null);
452
+ const eventsRef = useRef([]);
453
+ const animationFrameRef = useRef(null);
454
+ const isPlayingRef = useRef(false);
455
+ // Initialize visualizer for replay
456
+ const initializeVisualizer = useCallback((envelope, userAgent) => {
457
+ const iframe = iframeRef.current;
458
+ if (!iframe?.contentWindow)
459
+ return null;
460
+ // Clear previous events
461
+ eventsRef.current = [];
462
+ const visualizer = new Visualizer();
463
+ const mobile = isMobileDevice(userAgent);
464
+ visualizer.setup(iframe.contentWindow, {
465
+ version: envelope.version,
466
+ onresize: (width) => {
467
+ setConfig({ width });
468
+ },
469
+ mobile,
470
+ vNext: true,
471
+ locale: 'en-us',
472
+ });
473
+ return visualizer;
474
+ }, [setConfig]);
475
+ // Animation loop for replay
476
+ const replayLoop = useCallback(() => {
477
+ if (!isPlayingRef.current)
478
+ return;
479
+ const events = eventsRef.current;
480
+ const visualizer = visualizerRef.current;
481
+ if (!visualizer || events.length === 0) {
482
+ animationFrameRef.current = requestAnimationFrame(replayLoop);
483
+ return;
484
+ }
485
+ const event = events[0];
486
+ const end = event.time + 16; // 60FPS => 16ms per frame
487
+ let index = 0;
488
+ // Get events within current frame
489
+ while (events[index] && events[index].time < end) {
490
+ index++;
491
+ }
492
+ // Render events for this frame
493
+ if (index > 0) {
494
+ visualizer.render(events.splice(0, index));
495
+ }
496
+ animationFrameRef.current = requestAnimationFrame(replayLoop);
497
+ }, []);
498
+ // Start replay
499
+ const startReplay = useCallback(async (payloads) => {
500
+ if (!payloads || payloads.length === 0)
501
+ return;
502
+ let visualizer = visualizerRef.current;
503
+ for (const decoded of payloads) {
504
+ // Initialize on first sequence
505
+ if (decoded.envelope.sequence === 1) {
506
+ const userAgent = decoded.dimension?.[0]?.data[0]?.[0] || '';
507
+ visualizer = initializeVisualizer(decoded.envelope, userAgent);
508
+ if (!visualizer)
509
+ return;
510
+ visualizerRef.current = visualizer;
511
+ }
512
+ if (!visualizer)
513
+ continue;
514
+ // Merge events and DOM
515
+ const merged = visualizer.merge([decoded]);
516
+ eventsRef.current = eventsRef.current.concat(merged.events).sort(sortEvents);
517
+ visualizer.dom(merged.dom);
518
+ }
519
+ // Render HTML
520
+ if (visualizer && iframeRef.current?.contentWindow) {
521
+ await visualizer.html(payloads, iframeRef.current.contentWindow);
522
+ }
523
+ // Auto-start replay
524
+ isPlayingRef.current = true;
525
+ animationFrameRef.current = requestAnimationFrame(replayLoop);
526
+ }, [initializeVisualizer, replayLoop]);
527
+ // Play control
528
+ const play = useCallback(() => {
529
+ if (!isPlayingRef.current) {
530
+ isPlayingRef.current = true;
531
+ animationFrameRef.current = requestAnimationFrame(replayLoop);
532
+ }
533
+ }, [replayLoop]);
534
+ // Pause control
535
+ const pause = useCallback(() => {
536
+ isPlayingRef.current = false;
537
+ if (animationFrameRef.current) {
538
+ cancelAnimationFrame(animationFrameRef.current);
539
+ animationFrameRef.current = null;
540
+ }
541
+ }, []);
542
+ // Main effect: Start replay when data changes
543
+ useEffect(() => {
544
+ if (!data || data.length === 0)
545
+ return;
546
+ startReplay(data);
547
+ // Cleanup
548
+ return () => {
549
+ isPlayingRef.current = false;
550
+ if (animationFrameRef.current) {
551
+ cancelAnimationFrame(animationFrameRef.current);
552
+ animationFrameRef.current = null;
553
+ }
554
+ eventsRef.current = [];
555
+ visualizerRef.current = null;
556
+ };
557
+ }, [data, startReplay]);
558
+ return {
559
+ iframeRef,
560
+ isPlaying: isPlayingRef.current,
561
+ clarityVisualizer: visualizerRef.current,
562
+ play,
563
+ pause,
564
+ };
565
+ };
566
+
567
+ const useHeatmapVizRender = (mode) => {
568
+ const heatmapResult = useMemo(() => {
569
+ switch (mode) {
570
+ case 'heatmap':
571
+ return useHeatmapRender;
572
+ case 'replay':
573
+ return useReplayRender;
574
+ }
575
+ }, [mode]);
576
+ return heatmapResult();
577
+ };
578
+
579
+ const useContainerDimensions = (props) => {
580
+ const { wrapperRef } = props;
581
+ const [containerWidth, setContainerWidth] = useState(0);
582
+ const [containerHeight, setContainerHeight] = useState(0);
583
+ const resizeObserverRef = useRef(null);
584
+ const updateDimensions = useCallback(() => {
585
+ const scrollContainer = wrapperRef.current?.parentElement?.parentElement;
586
+ if (scrollContainer) {
587
+ setContainerWidth(scrollContainer.clientWidth);
588
+ setContainerHeight(scrollContainer.clientHeight);
589
+ }
590
+ }, [wrapperRef]);
591
+ useEffect(() => {
592
+ const scrollContainer = wrapperRef.current?.parentElement?.parentElement;
593
+ if (!scrollContainer || typeof window.ResizeObserver === 'undefined') {
594
+ return;
595
+ }
596
+ resizeObserverRef.current = new ResizeObserver(updateDimensions);
597
+ resizeObserverRef.current.observe(scrollContainer);
598
+ updateDimensions();
599
+ return () => {
600
+ if (resizeObserverRef.current && scrollContainer) {
601
+ resizeObserverRef.current.unobserve(scrollContainer);
602
+ }
603
+ };
604
+ }, [wrapperRef, updateDimensions]);
605
+ return { containerWidth, containerHeight };
606
+ };
607
+
608
+ const useContentDimensions = (props) => {
609
+ const { iframeRef, config } = props;
610
+ const [contentWidth, setContentWidth] = useState(0);
611
+ useEffect(() => {
612
+ if (config?.width) {
613
+ if (iframeRef.current) {
614
+ iframeRef.current.width = `${config.width}px`;
615
+ }
616
+ setContentWidth(config.width);
617
+ }
618
+ }, [config?.width, iframeRef]);
619
+ return { contentWidth };
620
+ };
621
+
622
+ // Hook 3: Iframe Height Observer
623
+ const useIframeHeight = (props) => {
624
+ const { iframeRef, contentWidth } = props;
625
+ const iframeHeight = useHeatmapDataStore((state) => state.iframeHeight);
626
+ const setIframeHeight = useHeatmapDataStore((state) => state.setIframeHeight);
627
+ const resizeObserverRef = useRef(null);
628
+ const mutationObserverRef = useRef(null);
629
+ const updateIframeHeight = useCallback(() => {
630
+ const iframe = iframeRef.current;
631
+ if (!iframe)
632
+ return;
633
+ try {
634
+ const iframeDocument = iframe.contentDocument;
635
+ const iframeBody = iframeDocument?.body;
636
+ if (!iframeBody)
637
+ return;
638
+ const bodyHeight = Math.max(iframeBody.scrollHeight, iframeBody.offsetHeight, iframeBody.clientHeight);
639
+ if (bodyHeight > 0) {
640
+ iframe.height = `${bodyHeight}px`;
641
+ setIframeHeight(bodyHeight);
642
+ }
643
+ }
644
+ catch (error) {
645
+ console.warn('Cannot measure iframe content:', error);
646
+ }
647
+ }, [iframeRef, setIframeHeight]);
648
+ // Trigger height update when content width changes
649
+ useEffect(() => {
650
+ if (contentWidth > 0) {
651
+ // Delay to allow iframe content to reflow after width change
652
+ const timeoutId = setTimeout(() => {
653
+ updateIframeHeight();
654
+ }, 100);
655
+ return () => clearTimeout(timeoutId);
656
+ }
657
+ }, [contentWidth, updateIframeHeight]);
658
+ useEffect(() => {
659
+ const iframe = iframeRef.current;
660
+ if (!iframe)
661
+ return;
662
+ const setupObservers = () => {
663
+ try {
664
+ const iframeDocument = iframe.contentDocument;
665
+ const iframeBody = iframeDocument?.body;
666
+ if (!iframeBody)
667
+ return;
668
+ // Cleanup existing observers
669
+ if (resizeObserverRef.current) {
670
+ resizeObserverRef.current.disconnect();
671
+ }
672
+ if (mutationObserverRef.current) {
673
+ mutationObserverRef.current.disconnect();
674
+ }
675
+ // ResizeObserver for size changes
676
+ if (typeof window.ResizeObserver !== 'undefined') {
677
+ resizeObserverRef.current = new ResizeObserver(updateIframeHeight);
678
+ resizeObserverRef.current.observe(iframeBody);
679
+ }
680
+ // MutationObserver for DOM changes
681
+ if (typeof window.MutationObserver !== 'undefined') {
682
+ mutationObserverRef.current = new MutationObserver(updateIframeHeight);
683
+ mutationObserverRef.current.observe(iframeBody, {
684
+ childList: true,
685
+ subtree: true,
686
+ attributes: true,
687
+ characterData: true,
688
+ });
689
+ }
690
+ // Initial measurement
691
+ updateIframeHeight();
692
+ }
693
+ catch (error) {
694
+ console.warn('Cannot access iframe content:', error);
695
+ }
696
+ };
697
+ if (iframe.contentDocument?.readyState === 'complete') {
698
+ setupObservers();
699
+ }
700
+ else {
701
+ iframe.addEventListener('load', setupObservers, { once: true });
702
+ }
703
+ return () => {
704
+ if (resizeObserverRef.current) {
705
+ resizeObserverRef.current.disconnect();
706
+ }
707
+ if (mutationObserverRef.current) {
708
+ mutationObserverRef.current.disconnect();
709
+ }
710
+ iframe.removeEventListener('load', setupObservers);
711
+ };
712
+ }, [iframeRef, updateIframeHeight]);
713
+ return { iframeHeight };
714
+ };
715
+
716
+ const useScaleCalculation = (props) => {
717
+ const { containerWidth, contentWidth } = props;
718
+ const [scale, setScale] = useState(1);
719
+ useEffect(() => {
720
+ if (containerWidth > 0 && contentWidth > 0) {
721
+ const availableWidth = containerWidth - HEATMAP_CONFIG['paddingBlock'] * 2;
722
+ const calculatedScale = Math.min(availableWidth / contentWidth, 1);
723
+ setScale(calculatedScale);
724
+ }
725
+ }, [containerWidth, contentWidth]);
726
+ return { scale };
727
+ };
728
+
729
+ const useScrollSync = (props) => {
730
+ const { iframeRef, scale } = props;
731
+ const handleScroll = useCallback((scrollTop) => {
732
+ const iframe = iframeRef.current;
733
+ if (!iframe || scale <= 0)
734
+ return;
735
+ try {
736
+ const iframeWindow = iframe.contentWindow;
737
+ const iframeDocument = iframe.contentDocument;
738
+ if (iframeWindow && iframeDocument) {
739
+ const iframeScrollTop = scrollTop / scale;
740
+ iframe.style.top = `${iframeScrollTop}px`;
741
+ }
742
+ }
743
+ catch (error) {
744
+ console.warn('Cannot sync scroll to iframe:', error);
745
+ }
746
+ }, [iframeRef, scale]);
747
+ return { handleScroll };
748
+ };
749
+
750
+ const useHeatmapScale = (props) => {
751
+ const { wrapperRef, iframeRef, config } = props;
752
+ // 1. Observe container dimensions
753
+ const { containerWidth, containerHeight } = useContainerDimensions({ wrapperRef });
754
+ // 2. Get content dimensions from config
755
+ const { contentWidth } = useContentDimensions({ iframeRef, config });
756
+ // 3. Observe iframe height (now reacts to width changes)
757
+ const { iframeHeight } = useIframeHeight({ iframeRef, contentWidth });
758
+ // 4. Calculate scale
759
+ const { scale } = useScaleCalculation({ containerWidth, contentWidth });
760
+ // 5. Setup scroll sync
761
+ const { handleScroll } = useScrollSync({ iframeRef, scale });
762
+ return {
763
+ containerWidth,
764
+ containerHeight,
765
+ contentWidth,
766
+ iframeHeight,
767
+ scale,
768
+ scaledWidth: contentWidth * scale,
769
+ scaledHeight: iframeHeight * scale,
770
+ handleScroll,
771
+ };
772
+ };
773
+
774
+ const CLICKED_ELEMENT_ID = 'clickedElement';
775
+ const SECONDARY_CLICKED_ELEMENT_ID = 'secondaryClickedElementID';
776
+ const HOVERED_ELEMENT_ID = 'hoveredElement';
777
+ const SECONDARY_HOVERED_ELEMENT_ID = 'secondaryhoveredElementID';
778
+
779
+ const ElementCallout = ({ element, target, totalClicks, isSecondary, isRecordingView, isCompareMode, deviceType, heatmapType, language, widthScale, parentRef, }) => {
780
+ const calloutRef = useRef(null);
781
+ const [position, setPosition] = useState({
782
+ top: 0,
783
+ left: 0,
784
+ placement: 'top',
785
+ });
786
+ const percentage = formatPercentage(((element.clicks ?? 0) / totalClicks) * 100, 2);
787
+ // Calculate callout position
788
+ useEffect(() => {
789
+ const targetElement = document.querySelector(target);
790
+ const calloutElement = calloutRef.current;
791
+ if (!targetElement || !calloutElement)
792
+ return;
793
+ const calculatePosition = () => {
794
+ const targetRect = targetElement.getBoundingClientRect();
795
+ const calloutRect = calloutElement.getBoundingClientRect();
796
+ const viewportWidth = window.innerWidth;
797
+ const viewportHeight = window.innerHeight;
798
+ const padding = 12; // Space between target and callout
799
+ const arrowSize = 8;
800
+ let top = 0;
801
+ let left = 0;
802
+ let placement = 'top';
803
+ // Try positions in order: top, bottom, right, left
804
+ const positions = [
805
+ // Top
806
+ {
807
+ placement: 'top',
808
+ top: targetRect.top - calloutRect.height - padding - arrowSize,
809
+ left: targetRect.left + targetRect.width / 2 - calloutRect.width / 2,
810
+ valid: targetRect.top - calloutRect.height - padding - arrowSize > 0,
811
+ },
812
+ // Bottom
813
+ {
814
+ placement: 'bottom',
815
+ top: targetRect.bottom + padding + arrowSize,
816
+ left: targetRect.left + targetRect.width / 2 - calloutRect.width / 2,
817
+ valid: targetRect.bottom + calloutRect.height + padding + arrowSize < viewportHeight,
818
+ },
819
+ // Right
820
+ {
821
+ placement: 'right',
822
+ top: targetRect.top + targetRect.height / 2 - calloutRect.height / 2,
823
+ left: targetRect.right + padding + arrowSize,
824
+ valid: targetRect.right + calloutRect.width + padding + arrowSize < viewportWidth,
825
+ },
826
+ // Left
827
+ {
828
+ placement: 'left',
829
+ top: targetRect.top + targetRect.height / 2 - calloutRect.height / 2,
830
+ left: targetRect.left - calloutRect.width - padding - arrowSize,
831
+ valid: targetRect.left - calloutRect.width - padding - arrowSize > 0,
832
+ },
833
+ ];
834
+ // Find first valid position
835
+ const validPosition = positions.find((p) => p.valid) || positions[0];
836
+ top = validPosition.top;
837
+ left = validPosition.left;
838
+ placement = validPosition.placement;
839
+ // Keep within viewport bounds
840
+ left = Math.max(padding, Math.min(left, viewportWidth - calloutRect.width - padding));
841
+ top = Math.max(padding, Math.min(top, viewportHeight - calloutRect.height - padding));
842
+ setPosition({ top, left, placement });
843
+ };
844
+ // Initial calculation
845
+ calculatePosition();
846
+ // Recalculate on scroll/resize
847
+ const handleUpdate = () => {
848
+ requestAnimationFrame(calculatePosition);
849
+ };
850
+ window.addEventListener('scroll', handleUpdate, true);
851
+ window.addEventListener('resize', handleUpdate);
852
+ parentRef?.current?.addEventListener('scroll', handleUpdate);
853
+ return () => {
854
+ window.removeEventListener('scroll', handleUpdate, true);
855
+ window.removeEventListener('resize', handleUpdate);
856
+ parentRef?.current?.removeEventListener('scroll', handleUpdate);
857
+ };
858
+ }, [target, parentRef]);
859
+ (jsxs("div", { ref: calloutRef, className: `clarity-callout clarity-callout--${position.placement} ${isSecondary ? 'clarity-callout--secondary' : ''}`, style: {
860
+ position: 'fixed',
861
+ top: position.top,
862
+ left: position.left,
863
+ zIndex: 2147483647,
864
+ }, "aria-live": "assertive", role: "tooltip", children: [jsx("div", { className: "clarity-callout__arrow" }), jsxs("div", { className: "clarity-callout__content", children: [jsx("div", { className: "clarity-callout__rank", children: element.rank }), jsxs("div", { className: "clarity-callout__stats", children: [jsx("div", { className: "clarity-callout__label", children: "Clicks" }), jsxs("div", { className: "clarity-callout__value", children: [jsx("span", { className: "clarity-callout__count", children: element.clicks?.toLocaleString(language) }), jsxs("span", { className: "clarity-callout__percentage", children: ["(", percentage, "%)"] })] })] }), !isRecordingView && !isCompareMode && (jsxs("button", { className: "clarity-callout__button", "data-clarity-id": "viewRecordingClickedFromHeatmapIframe", "data-element-hash": element.hash, "data-selector": getSimpleSelector(element.selector), "data-device-type": deviceType, "data-heatmap-type": heatmapType, children: [jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", children: jsx("path", { d: "M5 3L11 8L5 13V3Z", fill: "currentColor" }) }), "View Recording"] }))] }), jsx("style", { children: `
865
+ .clarity-callout {
866
+ background: white;
867
+ border-radius: 8px;
868
+ box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
869
+ padding: 16px;
870
+ min-width: 200px;
871
+ max-width: 280px;
872
+ animation: clarity-callout-fade-in 0.2s ease-out;
873
+ pointer-events: auto;
874
+ }
875
+
876
+ @keyframes clarity-callout-fade-in {
877
+ from {
878
+ opacity: 0;
879
+ transform: scale(0.95);
880
+ }
881
+ to {
882
+ opacity: 1;
883
+ transform: scale(1);
884
+ }
885
+ }
886
+
887
+ .clarity-callout__arrow {
888
+ position: absolute;
889
+ width: 16px;
890
+ height: 16px;
891
+ background: white;
892
+ transform: rotate(45deg);
893
+ }
894
+
895
+ /* Arrow positions */
896
+ .clarity-callout--top .clarity-callout__arrow {
897
+ bottom: -8px;
898
+ left: 50%;
899
+ margin-left: -8px;
900
+ box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
901
+ }
902
+
903
+ .clarity-callout--bottom .clarity-callout__arrow {
904
+ top: -8px;
905
+ left: 50%;
906
+ margin-left: -8px;
907
+ box-shadow: -2px -2px 4px rgba(0, 0, 0, 0.1);
908
+ }
909
+
910
+ .clarity-callout--left .clarity-callout__arrow {
911
+ right: -8px;
912
+ top: 50%;
913
+ margin-top: -8px;
914
+ box-shadow: 2px -2px 4px rgba(0, 0, 0, 0.1);
915
+ }
916
+
917
+ .clarity-callout--right .clarity-callout__arrow {
918
+ left: -8px;
919
+ top: 50%;
920
+ margin-top: -8px;
921
+ box-shadow: -2px 2px 4px rgba(0, 0, 0, 0.1);
922
+ }
923
+
924
+ .clarity-callout__content {
925
+ position: relative;
926
+ z-index: 1;
927
+ }
928
+
929
+ .clarity-callout__rank {
930
+ display: inline-flex;
931
+ align-items: center;
932
+ justify-content: center;
933
+ width: 32px;
934
+ height: 32px;
935
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
936
+ color: white;
937
+ border-radius: 8px;
938
+ font-weight: 600;
939
+ font-size: 16px;
940
+ margin-bottom: 12px;
941
+ }
942
+
943
+ .clarity-callout--secondary .clarity-callout__rank {
944
+ background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
945
+ }
946
+
947
+ .clarity-callout__stats {
948
+ margin-bottom: 12px;
949
+ }
950
+
951
+ .clarity-callout__label {
952
+ font-size: 12px;
953
+ color: #6b7280;
954
+ margin-bottom: 4px;
955
+ font-weight: 500;
956
+ }
957
+
958
+ .clarity-callout__value {
959
+ display: flex;
960
+ align-items: baseline;
961
+ gap: 6px;
962
+ }
963
+
964
+ .clarity-callout__count {
965
+ font-size: 20px;
966
+ font-weight: 700;
967
+ color: #111827;
968
+ }
969
+
970
+ .clarity-callout__percentage {
971
+ font-size: 14px;
972
+ color: #6b7280;
973
+ font-weight: 500;
974
+ }
975
+
976
+ .clarity-callout__button {
977
+ display: flex;
978
+ align-items: center;
979
+ justify-content: center;
980
+ gap: 6px;
981
+ width: 100%;
982
+ padding: 8px 12px;
983
+ background: #667eea;
984
+ color: white;
985
+ border: none;
986
+ border-radius: 6px;
987
+ font-size: 13px;
988
+ font-weight: 600;
989
+ cursor: pointer;
990
+ transition: all 0.2s;
991
+ }
992
+
993
+ .clarity-callout__button:hover {
994
+ background: #5568d3;
995
+ transform: translateY(-1px);
996
+ box-shadow: 0 2px 8px rgba(102, 126, 234, 0.4);
997
+ }
998
+
999
+ .clarity-callout__button:active {
1000
+ transform: translateY(0);
1001
+ }
1002
+
1003
+ .clarity-callout__button svg {
1004
+ width: 14px;
1005
+ height: 14px;
1006
+ }
1007
+ ` })] }));
1008
+ const [portalContainer, setPortalContainer] = useState(null);
1009
+ useEffect(() => {
1010
+ const container = document.querySelector('#gx-hm-project-portal');
1011
+ if (container instanceof HTMLElement) {
1012
+ setPortalContainer(container);
1013
+ }
1014
+ else {
1015
+ console.warn('Portal container #gx-hm-project-portal not found!');
1016
+ }
1017
+ }, []);
1018
+ if (!portalContainer) {
1019
+ return jsx(Fragment, {});
1020
+ }
1021
+ // return createPortal(calloutContent, portalContainer);
1022
+ };
1023
+
1024
+ const RankBadge = ({ index, elementRect, widthScale, clickOnElement, }) => {
1025
+ const style = calculateRankPosition(elementRect, widthScale);
1026
+ return (jsx("div", { className: "rankBadge", style: style, onClick: clickOnElement, "data-testid": "elementRank", children: index }));
1027
+ };
1028
+
1029
+ const ClickedElementOverlay = ({ element, shouldShowCallout, isSecondary, targetId, totalClicks = 1, isRecordingView, isCompareMode, deviceType, heatmapType, widthScale, }) => {
1030
+ if (!element || (element.width === 0 && element.height === 0))
1031
+ return null;
1032
+ return (jsxs(Fragment$1, { children: [jsx("div", { className: "heatmapElement", id: targetId, style: {
1033
+ top: element.top,
1034
+ left: element.left,
1035
+ width: element.width,
1036
+ height: element.height,
1037
+ } }), jsx(RankBadge, { index: element.rank, elementRect: element, widthScale: widthScale }), shouldShowCallout && (jsx(ElementCallout, { element: element, target: `#${targetId}`, totalClicks: totalClicks, isSecondary: isSecondary, isRecordingView: isRecordingView, isCompareMode: isCompareMode, deviceType: deviceType, heatmapType: heatmapType, widthScale: widthScale }))] }));
1038
+ };
1039
+
1040
+ const DefaultRankBadges = ({ elements, getRect, widthScale, hidden }) => {
1041
+ if (hidden || elements.length === 0)
1042
+ return null;
1043
+ return (jsx(Fragment, { children: elements.map((element, index) => {
1044
+ const rect = getRect(element);
1045
+ if (!rect)
1046
+ return null;
1047
+ return (jsx(RankBadge, { index: index + 1, elementRect: rect, widthScale: widthScale }, element.hash));
1048
+ }) }));
1049
+ };
1050
+
1051
+ const HoveredElementOverlay = ({ element, onClick, isSecondary, targetId, totalClicks = 1, }) => {
1052
+ if (!element)
1053
+ return null;
1054
+ return (jsxs(Fragment$1, { children: [jsx("div", { onClick: onClick, className: "heatmapElement hovered", id: targetId, style: {
1055
+ top: element.top,
1056
+ left: element.left,
1057
+ width: element.width,
1058
+ height: element.height,
1059
+ cursor: 'pointer',
1060
+ } }), jsx(RankBadge, { index: element.rank, elementRect: element, widthScale: 1, clickOnElement: onClick })] }));
1061
+ };
1062
+
1063
+ const MissingElementMessage = ({ widthScale }) => {
1064
+ return (jsx("div", { className: "missingElement", style: {
1065
+ position: 'absolute',
1066
+ top: '50%',
1067
+ left: '50%',
1068
+ transform: `translate(-50%, -50%) scale(${1 / widthScale})`,
1069
+ background: 'rgba(0, 0, 0, 0.8)',
1070
+ color: 'white',
1071
+ padding: '12px 20px',
1072
+ borderRadius: '8px',
1073
+ fontSize: '14px',
1074
+ fontWeight: '500',
1075
+ zIndex: 9999,
1076
+ pointerEvents: 'none',
1077
+ whiteSpace: 'nowrap',
1078
+ }, "aria-live": "assertive", children: "Element not visible on current screen" }));
1079
+ };
1080
+
1081
+ const HeatmapElements = (props) => {
1082
+ const { iframeRef, parentRef, visualizer, heatmapInfo, widthScale, iframeHeight, iframeDimensions, selectedElement, isElementSidebarOpen, isVisible = true, selectElement, areDefaultRanksHidden, isSecondary, ...rest } = props;
1083
+ const getRect = useHeatmapElementPosition({
1084
+ iframeRef,
1085
+ parentRef,
1086
+ visualizer,
1087
+ heatmapWidth: heatmapInfo?.width,
1088
+ iframeHeight,
1089
+ widthScale,
1090
+ projectId: props.projectId,
1091
+ });
1092
+ const { clickedElement, showMissingElement, shouldShowCallout, setShouldShowCallout } = useClickedElement({
1093
+ selectedElement,
1094
+ heatmapInfo,
1095
+ getRect,
1096
+ });
1097
+ const { hoveredElement, handleMouseMove, handleMouseLeave, handleClick } = useHoveredElement({
1098
+ iframeRef,
1099
+ heatmapInfo,
1100
+ getRect,
1101
+ onSelect: selectElement,
1102
+ widthScale,
1103
+ });
1104
+ const resetAll = () => {
1105
+ // nếu cần reset thêm state ở đây
1106
+ // setShouldShowCallout(false);
1107
+ };
1108
+ useHeatmapEffects({
1109
+ isVisible,
1110
+ isElementSidebarOpen,
1111
+ selectedElement,
1112
+ setShouldShowCallout,
1113
+ resetAll,
1114
+ });
1115
+ if (!isVisible)
1116
+ return null;
1117
+ const top10 = heatmapInfo?.sortedElements?.slice(0, 10) ?? [];
1118
+ return (jsxs("div", { onMouseMove: handleMouseMove, onMouseLeave: handleMouseLeave, className: "heatmapElements gx-hm-elements", style: iframeDimensions, children: [jsx(DefaultRankBadges, { elements: top10, getRect: getRect, widthScale: widthScale, hidden: areDefaultRanksHidden }), jsx(ClickedElementOverlay, { widthScale: widthScale, element: clickedElement, shouldShowCallout: shouldShowCallout, isSecondary: isSecondary, targetId: isSecondary ? SECONDARY_CLICKED_ELEMENT_ID : CLICKED_ELEMENT_ID, ...rest }), showMissingElement && jsx(MissingElementMessage, { widthScale: widthScale }), jsx(HoveredElementOverlay, { element: hoveredElement, onClick: handleClick, isSecondary: isSecondary, targetId: isSecondary ? SECONDARY_HOVERED_ELEMENT_ID : HOVERED_ELEMENT_ID, totalClicks: heatmapInfo?.totalClicks ?? 1 }), hoveredElement !== clickedElement && hoveredElement && (jsx(ElementCallout, { element: hoveredElement, target: `#${props.isSecondary ? SECONDARY_HOVERED_ELEMENT_ID : HOVERED_ELEMENT_ID}`, totalClicks: props.heatmapInfo?.totalClicks ?? 1, isSecondary: props.isSecondary, parentRef: props.parentRef }))] }));
1119
+ };
1120
+
1121
+ const VizElements = ({ width, height, iframeRef, wrapperRef, widthScale, }) => {
1122
+ const heatmapInfo = {
1123
+ sortedElements: [
1124
+ {
1125
+ hash: '9ebwu6a3',
1126
+ selector: 'Join our email list',
1127
+ },
1128
+ {
1129
+ hash: '350hde5d4',
1130
+ selector: 'Products',
1131
+ },
1132
+ ],
1133
+ elementMapInfo: {
1134
+ '9ebwu6a3': {
1135
+ totalclicks: 4,
1136
+ hash: '9ebwu6a3',
1137
+ },
1138
+ '350hde5d4': {
1139
+ totalclicks: 4,
1140
+ hash: '350hde5d4',
1141
+ },
1142
+ },
1143
+ totalClicks: 8,
1144
+ };
1145
+ const visualizer = {
1146
+ get: (hash) => {
1147
+ const doc = iframeRef.current?.contentDocument;
1148
+ if (!doc)
1149
+ return null;
1150
+ // Find element by hash attribute
1151
+ return doc.querySelector(`[data-clarity-hashalpha="${hash}"]`);
1152
+ },
1153
+ };
1154
+ const [selectedElement, setSelectedElement] = useState(null);
1155
+ if (!iframeRef.current)
1156
+ return null;
1157
+ return (jsx(HeatmapElements, { visualizer: visualizer, iframeRef: iframeRef, parentRef: wrapperRef, iframeHeight: window.innerHeight, widthScale: widthScale, heatmapInfo: heatmapInfo, selectedElement: selectedElement, selectElement: setSelectedElement, isVisible: true, iframeDimensions: {
1158
+ width,
1159
+ height,
1160
+ position: 'absolute',
1161
+ top: 0,
1162
+ left: 0,
1163
+ // pointerEvents: 'none',
1164
+ } }));
1165
+ };
1166
+
1167
+ const ReplayControls = () => {
1168
+ const replayResult = useReplayRender();
1169
+ return (jsxs("div", { style: {
1170
+ position: 'absolute',
1171
+ bottom: 20,
1172
+ left: '50%',
1173
+ transform: 'translateX(-50%)',
1174
+ display: 'flex',
1175
+ gap: 10,
1176
+ backgroundColor: 'rgba(0, 0, 0, 0.7)',
1177
+ padding: '10px 20px',
1178
+ borderRadius: 8,
1179
+ }, children: [jsx("button", { onClick: replayResult.play, style: {
1180
+ padding: '8px 16px',
1181
+ backgroundColor: '#4CAF50',
1182
+ color: 'white',
1183
+ border: 'none',
1184
+ borderRadius: 4,
1185
+ cursor: 'pointer',
1186
+ }, children: "Play" }), jsx("button", { onClick: replayResult.pause, style: {
1187
+ padding: '8px 16px',
1188
+ backgroundColor: '#f44336',
1189
+ color: 'white',
1190
+ border: 'none',
1191
+ borderRadius: 4,
1192
+ cursor: 'pointer',
1193
+ }, children: "Pause" })] }));
1194
+ };
1195
+
1196
+ const VizDomRenderer = ({ mode = 'heatmap' }) => {
1197
+ const config = useHeatmapDataStore((state) => state.config);
1198
+ const wrapperRef = useRef(null);
1199
+ const visualRef = useRef(null);
1200
+ const { iframeRef } = useHeatmapVizRender(mode);
1201
+ const { contentWidth, iframeHeight, scale, scaledHeight, handleScroll } = useHeatmapScale({
1202
+ wrapperRef,
1203
+ iframeRef,
1204
+ config,
1205
+ });
1206
+ const onScroll = (e) => {
1207
+ const scrollTop = e.currentTarget.scrollTop;
1208
+ handleScroll(scrollTop);
1209
+ };
1210
+ return (jsxs("div", { ref: visualRef, className: "gx-hm-visual", onScroll: onScroll, style: {
1211
+ overflow: 'hidden auto',
1212
+ display: 'flex',
1213
+ position: 'relative',
1214
+ justifyContent: 'center',
1215
+ flex: 1,
1216
+ backgroundColor: '#fff',
1217
+ // borderRadius: '8px',
1218
+ }, children: [jsx("div", { className: "gx-hm-visual-unscaled", style: {
1219
+ width: '100%',
1220
+ display: 'flex',
1221
+ justifyContent: 'center',
1222
+ alignItems: 'flex-start',
1223
+ height: scaledHeight > 0 ? `${scaledHeight + HEATMAP_CONFIG['paddingBlock']}px` : 'auto',
1224
+ padding: HEATMAP_STYLE['wrapper']['padding'],
1225
+ }, children: jsxs("div", { className: "gx-hm-wrapper", ref: wrapperRef, style: {
1226
+ width: contentWidth,
1227
+ height: iframeHeight,
1228
+ transform: `scale(${scale})`,
1229
+ transformOrigin: 'top center',
1230
+ }, children: [jsx(VizElements, { width: contentWidth, height: iframeHeight, widthScale: scale, iframeRef: iframeRef, wrapperRef: wrapperRef }), jsx("iframe", {
1231
+ // key={iframeKey}
1232
+ ref: iframeRef, ...HEATMAP_IFRAME, width: contentWidth, height: iframeHeight, scrolling: "no" })] }) }), mode === 'replay' && jsx(ReplayControls, {})] }));
1233
+ };
1234
+
1235
+ const VizDomContainer = () => {
1236
+ return (jsx(BoxStack, { id: "gx-hm-viz-container", flexDirection: "column", flex: "1 1 auto", overflow: "auto", children: jsx(BoxStack, { id: "gx-hm-content", flexDirection: "column", flex: "1 1 auto", overflow: "hidden", style: {
1237
+ // margin: '0px 16px 0px 12px',
1238
+ // borderRadius: '8px 8px 0 0',
1239
+ // borderRadius: '8px',
1240
+ minWidth: '394px',
1241
+ padding: '12px',
1242
+ background: '#f1f1f1',
1243
+ }, children: jsx(VizDomRenderer, {}) }) }));
1244
+ };
1245
+
1246
+ const SIDEBAR_WIDTH = 280;
1247
+ const LeftSidebar = ({ children }) => {
1248
+ const isHideSidebar = useHeatmapDataStore((state) => state.state.hideSidebar);
1249
+ if (isHideSidebar) {
1250
+ return null;
1251
+ }
1252
+ return (jsx("div", { className: "gx-hm-sidebar", style: {
1253
+ height: '100%',
1254
+ display: 'flex',
1255
+ ...(isHideSidebar
1256
+ ? {
1257
+ width: '0',
1258
+ transform: 'translateX(-100%)',
1259
+ visibility: 'hidden',
1260
+ }
1261
+ : { width: `${SIDEBAR_WIDTH}px` }),
1262
+ }, children: jsx("div", { className: "gx-hm-sidebar-wrapper", style: { height: '100%', width: `${SIDEBAR_WIDTH}px` }, children: children }) }));
1263
+ };
1264
+
1265
+ const WrapperPreview = ({ children }) => {
1266
+ return (jsxs("div", { className: "gx-hm-container", style: { display: 'flex', overflowY: 'hidden', flex: '1', position: 'relative' }, children: [jsx(LeftSidebar, { children: children }), jsx(VizDomContainer, {})] }));
1267
+ };
1268
+
1269
+ const WrapperLayout = ({ header, toolbar, sidebar }) => {
1270
+ return (jsxs(BoxStack, { id: "gx-hm-layout", flexDirection: "column", flex: "1", children: [jsx(ContentHeader, { children: header }), jsx(ContentHeader, { children: toolbar }), jsx(WrapperPreview, { children: sidebar })] }));
1271
+ };
1272
+
95
1273
  const HeatmapLayout = ({ data, clickmap, header, toolbar, sidebar, }) => {
96
1274
  const setData = useHeatmapDataStore((state) => state.setData);
97
1275
  const setClickmap = useHeatmapDataStore((state) => state.setClickmap);
@@ -111,10 +1289,10 @@ const HeatmapLayout = ({ data, clickmap, header, toolbar, sidebar, }) => {
111
1289
  useEffect(() => {
112
1290
  handleSetClickmap(clickmap);
113
1291
  }, [clickmap]);
114
- return (jsx(BoxStack, { id: "gx-hm-project", flexDirection: "column", flex: "1", height: "100%", children: jsx(BoxStack, { id: "gx-hm-project-content", flexDirection: "column", flex: "1", children: jsx("div", { style: {
115
- minHeight: '100%',
116
- display: 'flex',
117
- } }) }) }));
1292
+ return (jsxs(Fragment, { children: [jsx(BoxStack, { id: "gx-hm-project", flexDirection: "column", flex: "1", height: "100%", children: jsx(BoxStack, { id: "gx-hm-project-content", flexDirection: "column", flex: "1", children: jsx("div", { style: {
1293
+ minHeight: '100%',
1294
+ display: 'flex',
1295
+ }, children: jsx(WrapperLayout, { header: header, toolbar: toolbar, sidebar: sidebar }) }) }) }), jsx("div", { id: "gx-hm-project-portal" })] }));
118
1296
  };
119
1297
 
120
1298
  var PanelContent;