@gemx-dev/heatmap-react 3.5.42 → 3.5.43

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.
@@ -1 +1 @@
1
- {"version":3,"file":"VizLiveHeatmap.d.ts","sourceRoot":"","sources":["../../../src/components/VizLive/VizLiveHeatmap.tsx"],"names":[],"mappings":"AAUA,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAoBlC,CAAC"}
1
+ {"version":3,"file":"VizLiveHeatmap.d.ts","sourceRoot":"","sources":["../../../src/components/VizLive/VizLiveHeatmap.tsx"],"names":[],"mappings":"AAKA,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAqBlC,CAAC"}
@@ -2,11 +2,13 @@ import { DebugInfo, ViewportConfig } from '../types';
2
2
  export declare class ViewportUnitsFixer {
3
3
  private iframe;
4
4
  private config;
5
+ private replacer;
5
6
  constructor(config: ViewportConfig);
6
7
  private init;
7
- private injectScript;
8
- private handleMessage;
9
- recalculate(): void;
8
+ private process;
9
+ recalculate(): Promise<void>;
10
+ updateConfig(config: Partial<ViewportConfig>): void;
11
+ destroy(): void;
10
12
  }
11
13
  export declare function initViewportFixer(config: ViewportConfig): ViewportUnitsFixer;
12
14
  export declare function debugViewportUnits(): DebugInfo | null;
@@ -1 +1 @@
1
- {"version":3,"file":"viewport-fixer.d.ts","sourceRoot":"","sources":["../../src/helpers/viewport-fixer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAyC,cAAc,EAAE,MAAM,UAAU,CAAC;AAmB5F,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAAkC;IAChD,OAAO,CAAC,MAAM,CAAiB;gBAEnB,MAAM,EAAE,cAAc;YAOpB,IAAI;YAgBJ,YAAY;IAiB1B,OAAO,CAAC,aAAa;IAMd,WAAW,IAAI,IAAI;CAG3B;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,cAAc,GAAG,kBAAkB,CAU5E;AAED,wBAAgB,kBAAkB,IAAI,SAAS,GAAG,IAAI,CA+BrD"}
1
+ {"version":3,"file":"viewport-fixer.d.ts","sourceRoot":"","sources":["../../src/helpers/viewport-fixer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAoB,cAAc,EAAE,MAAM,UAAU,CAAC;AAGvE,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,QAAQ,CAAsC;gBAE1C,MAAM,EAAE,cAAc;YAMpB,IAAI;YAcJ,OAAO;IAiCR,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAKlC,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,IAAI;IAOnD,OAAO,IAAI,IAAI;CAIvB;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,cAAc,GAAG,kBAAkB,CAS5E;AAED,wBAAgB,kBAAkB,IAAI,SAAS,GAAG,IAAI,CA+BrD"}
@@ -1,12 +1,10 @@
1
1
  import type { ViewportConfig } from '../types';
2
- declare global {
3
- interface Window {
4
- __viewportConfig?: ViewportConfig;
5
- }
6
- }
7
- declare class ViewportUnitsReplacer {
8
- regex(): RegExp;
9
- config(): ViewportConfig;
2
+ export declare class ViewportUnitsReplacer {
3
+ private doc;
4
+ private win;
5
+ private config;
6
+ private regex;
7
+ constructor(iframe: HTMLIFrameElement, config: ViewportConfig);
10
8
  private px;
11
9
  private convert;
12
10
  private replaceInText;
@@ -16,10 +14,12 @@ declare class ViewportUnitsReplacer {
16
14
  private processStylesheets;
17
15
  private processLinkedStylesheets;
18
16
  private getFinalHeight;
19
- private notifyParent;
17
+ private getFinalWidth;
20
18
  private waitForResources;
21
- private run;
22
- init(): void;
19
+ run(): Promise<{
20
+ height: number;
21
+ width: number;
22
+ }>;
23
+ updateConfig(config: Partial<ViewportConfig>): void;
23
24
  }
24
- export default ViewportUnitsReplacer;
25
25
  //# sourceMappingURL=viewport-replacer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"viewport-replacer.d.ts","sourceRoot":"","sources":["../../src/helpers/viewport-replacer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,gBAAgB,CAAC,EAAE,cAAc,CAAC;KACnC;CACF;AAED,cAAM,qBAAqB;IACzB,KAAK,IAAI,MAAM;IAIf,MAAM,IAAI,cAAc;IAIxB,OAAO,CAAC,EAAE;IAIV,OAAO,CAAC,OAAO;IAkBf,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,mBAAmB;IAa3B,OAAO,CAAC,gBAAgB;IAaxB,OAAO,CAAC,WAAW;IAyBnB,OAAO,CAAC,kBAAkB;YAwBZ,wBAAwB;IAkCtC,OAAO,CAAC,cAAc;IAatB,OAAO,CAAC,YAAY;YAYN,gBAAgB;YAkBhB,GAAG;IAmBjB,IAAI;CASL;AAED,eAAe,qBAAqB,CAAC"}
1
+ {"version":3,"file":"viewport-replacer.d.ts","sourceRoot":"","sources":["../../src/helpers/viewport-replacer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE/C,qBAAa,qBAAqB;IAChC,OAAO,CAAC,GAAG,CAAW;IACtB,OAAO,CAAC,GAAG,CAAS;IACpB,OAAO,CAAC,MAAM,CAAiB;IAC/B,OAAO,CAAC,KAAK,CAAgD;gBAEjD,MAAM,EAAE,iBAAiB,EAAE,MAAM,EAAE,cAAc;IAU7D,OAAO,CAAC,EAAE;IAIV,OAAO,CAAC,OAAO;IAkBf,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,mBAAmB;IAc3B,OAAO,CAAC,gBAAgB;IAcxB,OAAO,CAAC,WAAW;IA0BnB,OAAO,CAAC,kBAAkB;YAwBZ,wBAAwB;IAmCtC,OAAO,CAAC,cAAc;IAatB,OAAO,CAAC,aAAa;YAUP,gBAAgB;IAkBjB,GAAG,IAAI,OAAO,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IA6BvD,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,IAAI;CAG3D"}
package/dist/esm/index.js CHANGED
@@ -511,85 +511,18 @@ function isElementInViewport(elementRect, visualRef, scale) {
511
511
  return elementBottom > viewportTop && elementTop < viewportBottom;
512
512
  }
513
513
 
514
- const getScriptInjectCode = async () => {
515
- const moduleResult = (await Promise.resolve().then(function () { return viewportReplacer; }));
516
- const ActualClass = moduleResult.default;
517
- const classCode = ActualClass.toString();
518
- const classInstantiateCode = ActualClass.name;
519
- const scriptCode = `
520
- (function() {
521
- 'use strict';
522
- ${classCode}
523
- const replacer = new ${classInstantiateCode}();
524
- replacer.init();
525
- })();
526
- `;
527
- return scriptCode;
528
- };
529
- class ViewportUnitsFixer {
530
- iframe = null;
514
+ class ViewportUnitsReplacer {
515
+ doc;
516
+ win;
531
517
  config;
532
- constructor(config) {
533
- this.config = config;
534
- this.iframe = config.iframe;
535
- this.init();
536
- }
537
- async init() {
538
- if (!this.iframe) {
539
- console.error('[Parent] Required elements not found');
540
- return;
541
- }
542
- // this.injectScriptContent = await generateIframeInjectScript();
543
- window.addEventListener('message', this.handleMessage.bind(this));
544
- if (this.iframe.contentDocument?.readyState === 'complete') {
545
- await this.injectScript();
546
- }
547
- else {
548
- this.iframe.addEventListener('load', () => this.injectScript());
549
- }
550
- }
551
- async injectScript() {
552
- if (!this.iframe?.contentWindow || !this.iframe.contentDocument)
553
- return;
554
- const doc = this.iframe.contentDocument;
555
- const win = this.iframe.contentWindow;
556
- try {
557
- win.__viewportConfig = this.config;
558
- const script = doc.createElement('script');
559
- const scriptCode = await getScriptInjectCode();
560
- script.textContent = scriptCode;
561
- doc.head.appendChild(script);
518
+ regex = /([-.\d]+)(vh|svh|lvh|dvh|vw|svw|lvw|dvw)/gi;
519
+ constructor(iframe, config) {
520
+ if (!iframe.contentDocument || !iframe.contentWindow) {
521
+ throw new Error('Iframe document or window not accessible');
562
522
  }
563
- catch (error) {
564
- console.error('[Parent] Failed to inject script', error);
565
- }
566
- }
567
- handleMessage(event) {
568
- const data = event.data;
569
- if (!data || data.type !== 'IFRAME_HEIGHT_CALCULATED')
570
- return;
571
- this.config.onSuccess?.(data);
572
- }
573
- recalculate() {
574
- this.injectScript();
575
- }
576
- }
577
- function initViewportFixer(config) {
578
- const fixer = new ViewportUnitsFixer(config);
579
- window.viewportFixer = fixer;
580
- window.addEventListener('iframe-dimensions-applied', ((e) => {
581
- const ev = e;
582
- console.log('Iframe dimensions finalized:', ev.detail);
583
- }));
584
- return fixer;
585
- }
586
-
587
- class ViewportUnitsReplacer {
588
- regex() {
589
- return /([-.\d]+)(vh|svh|lvh|dvh|vw|svw|lvw|dvw)/gi;
590
- }
591
- config() {
592
- return window.__viewportConfig;
523
+ this.doc = iframe.contentDocument;
524
+ this.win = iframe.contentWindow;
525
+ this.config = config;
593
526
  }
594
527
  px(value) {
595
528
  return `${value.toFixed(2)}px`;
@@ -599,42 +532,44 @@ class ViewportUnitsReplacer {
599
532
  if (isNaN(num))
600
533
  return value;
601
534
  const map = {
602
- vh: this.config().targetHeight,
603
- svh: this.config().targetHeight,
604
- lvh: this.config().targetHeight,
605
- dvh: this.config().targetHeight,
606
- vw: this.config().targetWidth,
607
- svw: this.config().targetWidth,
608
- lvw: this.config().targetWidth,
609
- dvw: this.config().targetWidth,
535
+ vh: this.config.targetHeight,
536
+ svh: this.config.targetHeight,
537
+ lvh: this.config.targetHeight,
538
+ dvh: this.config.targetHeight,
539
+ vw: this.config.targetWidth,
540
+ svw: this.config.targetWidth,
541
+ lvw: this.config.targetWidth,
542
+ dvw: this.config.targetWidth,
610
543
  };
611
544
  return this.px((num / 100) * (map[unit.toLowerCase()] || 0));
612
545
  }
613
546
  replaceInText(cssText) {
614
- return cssText.replace(this.regex(), (_, value, unit) => this.convert(value, unit));
547
+ return cssText.replace(this.regex, (_, value, unit) => this.convert(value, unit));
615
548
  }
616
549
  processInlineStyles() {
617
550
  let count = 0;
618
- document.querySelectorAll('[style]').forEach((el) => {
551
+ this.doc.querySelectorAll('[style]').forEach((el) => {
619
552
  const style = el.getAttribute('style');
620
- if (style && this.regex().test(style)) {
553
+ if (style && this.regex.test(style)) {
554
+ this.regex.lastIndex = 0;
621
555
  el.setAttribute('style', this.replaceInText(style));
622
556
  count++;
623
557
  }
624
558
  });
625
- console.log(`[Iframe] Replaced ${count} inline style elements`);
559
+ console.log(`[ViewportReplacer] Replaced ${count} inline style elements`);
626
560
  return count;
627
561
  }
628
562
  processStyleTags() {
629
563
  let count = 0;
630
- document.querySelectorAll('style').forEach((tag) => {
564
+ this.doc.querySelectorAll('style').forEach((tag) => {
631
565
  const css = tag.textContent || '';
632
- if (this.regex().test(css)) {
566
+ if (this.regex.test(css)) {
567
+ this.regex.lastIndex = 0;
633
568
  tag.textContent = this.replaceInText(css);
634
569
  count++;
635
570
  }
636
571
  });
637
- console.log(`[Iframe] Replaced ${count} <style> tags`);
572
+ console.log(`[ViewportReplacer] Replaced ${count} <style> tags`);
638
573
  return count;
639
574
  }
640
575
  processRule(rule) {
@@ -644,7 +579,8 @@ class ViewportUnitsReplacer {
644
579
  for (let i = 0; i < style.length; i++) {
645
580
  const prop = style[i];
646
581
  const value = style.getPropertyValue(prop);
647
- if (value && this.regex().test(value)) {
582
+ if (value && this.regex.test(value)) {
583
+ this.regex.lastIndex = 0;
648
584
  style.setProperty(prop, this.replaceInText(value), style.getPropertyPriority(prop));
649
585
  count++;
650
586
  }
@@ -660,11 +596,11 @@ class ViewportUnitsReplacer {
660
596
  }
661
597
  processStylesheets() {
662
598
  let total = 0;
663
- Array.from(document.styleSheets).forEach((sheet) => {
599
+ Array.from(this.doc.styleSheets).forEach((sheet) => {
664
600
  try {
665
601
  // Bỏ qua external CSS (cross-origin)
666
- if (sheet.href && !sheet.href.startsWith(location.origin)) {
667
- console.log('[Iframe] Skipping external CSS:', sheet.href);
602
+ if (sheet.href && !sheet.href.startsWith(this.win.location.origin)) {
603
+ console.log('[ViewportReplacer] Skipping external CSS:', sheet.href);
668
604
  return;
669
605
  }
670
606
  const rules = sheet.cssRules || sheet.rules;
@@ -675,26 +611,27 @@ class ViewportUnitsReplacer {
675
611
  }
676
612
  }
677
613
  catch (e) {
678
- console.warn('[Iframe] Cannot read stylesheet (CORS?):', e.message);
614
+ console.warn('[ViewportReplacer] Cannot read stylesheet (CORS?):', e.message);
679
615
  }
680
616
  });
681
- console.log(`[Iframe] Replaced ${total} rules in stylesheets`);
617
+ console.log(`[ViewportReplacer] Replaced ${total} rules in stylesheets`);
682
618
  return total;
683
619
  }
684
620
  async processLinkedStylesheets() {
685
- const links = document.querySelectorAll('link[rel="stylesheet"]');
621
+ const links = this.doc.querySelectorAll('link[rel="stylesheet"]');
686
622
  let count = 0;
687
623
  for (const link of Array.from(links)) {
688
- if (!link.href.startsWith(location.origin)) {
689
- console.log('[Iframe] Skipping external CSS:', link.href);
624
+ if (!link.href.startsWith(this.win.location.origin)) {
625
+ console.log('[ViewportReplacer] Skipping external CSS:', link.href);
690
626
  continue;
691
627
  }
692
628
  try {
693
629
  const res = await fetch(link.href);
694
630
  let css = await res.text();
695
- if (this.regex().test(css)) {
631
+ if (this.regex.test(css)) {
632
+ this.regex.lastIndex = 0;
696
633
  css = this.replaceInText(css);
697
- const style = document.createElement('style');
634
+ const style = this.doc.createElement('style');
698
635
  style.textContent = css;
699
636
  style.dataset.originalHref = link.href;
700
637
  link.parentNode?.insertBefore(style, link);
@@ -703,30 +640,25 @@ class ViewportUnitsReplacer {
703
640
  }
704
641
  }
705
642
  catch (e) {
706
- console.warn('[Iframe] Cannot load CSS:', link.href, e);
643
+ console.warn('[ViewportReplacer] Cannot load CSS:', link.href, e);
707
644
  }
708
645
  }
709
- console.log(`[Iframe] Replaced ${count} linked CSS files`);
646
+ console.log(`[ViewportReplacer] Replaced ${count} linked CSS files`);
710
647
  return count;
711
648
  }
712
649
  getFinalHeight() {
713
650
  // Trigger reflow
714
- void document.body.offsetHeight;
715
- return Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight, document.documentElement.clientHeight);
651
+ void this.doc.body.offsetHeight;
652
+ return Math.max(this.doc.body.scrollHeight, this.doc.body.offsetHeight, this.doc.documentElement.scrollHeight, this.doc.documentElement.offsetHeight, this.doc.documentElement.clientHeight);
716
653
  }
717
- notifyParent(height) {
718
- window.parent.postMessage({
719
- type: 'IFRAME_HEIGHT_CALCULATED',
720
- height,
721
- width: document.body.scrollWidth,
722
- }, '*');
723
- console.log('[Iframe] Sent height to parent:', height);
654
+ getFinalWidth() {
655
+ return Math.max(this.doc.body.scrollWidth, this.doc.body.offsetWidth, this.doc.documentElement.scrollWidth, this.doc.documentElement.offsetWidth, this.doc.documentElement.clientWidth);
724
656
  }
725
657
  async waitForResources() {
726
- if ('fonts' in document) {
727
- await document.fonts.ready;
658
+ if ('fonts' in this.doc) {
659
+ await this.doc.fonts.ready;
728
660
  }
729
- const images = Array.from(document.images).filter((img) => !img.complete);
661
+ const images = Array.from(this.doc.images).filter((img) => !img.complete);
730
662
  if (images.length > 0) {
731
663
  await Promise.all(images.map((img) => new Promise((resolve) => {
732
664
  img.onload = img.onerror = resolve;
@@ -735,37 +667,104 @@ class ViewportUnitsReplacer {
735
667
  }
736
668
  async run() {
737
669
  try {
670
+ console.log('[ViewportReplacer] Starting viewport units replacement...');
738
671
  this.processInlineStyles();
739
672
  this.processStyleTags();
740
673
  this.processStylesheets();
741
674
  await this.processLinkedStylesheets();
742
675
  // await this.waitForResources();
743
- requestAnimationFrame(() => {
744
- const height = this.getFinalHeight();
745
- this.notifyParent(height);
676
+ return await new Promise((resolve) => {
677
+ requestAnimationFrame(() => {
678
+ const height = this.getFinalHeight();
679
+ const width = this.getFinalWidth();
680
+ console.log('[ViewportReplacer] Calculated dimensions:', { height, width });
681
+ resolve({ height, width });
682
+ });
746
683
  });
747
684
  }
748
685
  catch (err) {
749
- console.error('[Iframe] Critical error:', err);
750
- this.notifyParent(document.body.scrollHeight || 1000);
686
+ console.error('[ViewportReplacer] Critical error:', err);
687
+ return {
688
+ height: this.doc.body.scrollHeight || 1000,
689
+ width: this.doc.body.scrollWidth || 1000,
690
+ };
751
691
  }
752
692
  }
753
- init() {
754
- if (!window.__viewportConfig)
693
+ updateConfig(config) {
694
+ this.config = { ...this.config, ...config };
695
+ }
696
+ }
697
+
698
+ class ViewportUnitsFixer {
699
+ iframe;
700
+ config;
701
+ replacer = null;
702
+ constructor(config) {
703
+ this.config = config;
704
+ this.iframe = config.iframe;
705
+ this.init();
706
+ }
707
+ async init() {
708
+ if (!this.iframe) {
709
+ console.error('[ViewportFixer] iframe not found');
710
+ this.config.onError?.(new Error('iframe not found'));
755
711
  return;
756
- if (document.readyState === 'loading') {
757
- document.addEventListener('DOMContentLoaded', () => this.run());
712
+ }
713
+ if (this.iframe.contentDocument?.readyState === 'complete') {
714
+ await this.process();
758
715
  }
759
716
  else {
760
- this.run();
717
+ this.iframe.addEventListener('load', () => this.process());
761
718
  }
762
719
  }
720
+ async process() {
721
+ if (!this.iframe.contentDocument || !this.iframe.contentWindow) {
722
+ console.error('[ViewportFixer] Cannot access iframe document');
723
+ this.config.onError?.(new Error('Cannot access iframe document'));
724
+ return;
725
+ }
726
+ try {
727
+ console.log('[ViewportFixer] Processing viewport units...');
728
+ // Tạo replacer instance với iframe và config
729
+ this.replacer = new ViewportUnitsReplacer(this.iframe, this.config);
730
+ // Chạy replacement
731
+ const result = await this.replacer.run();
732
+ console.log('[ViewportFixer] Process completed:', result);
733
+ // Trigger success callback
734
+ this.config.onSuccess?.(result);
735
+ // Dispatch custom event
736
+ window.dispatchEvent(new CustomEvent('iframe-dimensions-applied', {
737
+ detail: result,
738
+ }));
739
+ }
740
+ catch (error) {
741
+ console.error('[ViewportFixer] Failed to process:', error);
742
+ this.config.onError?.(error);
743
+ }
744
+ }
745
+ async recalculate() {
746
+ console.log('[ViewportFixer] Recalculating...');
747
+ await this.process();
748
+ }
749
+ updateConfig(config) {
750
+ this.config = { ...this.config, ...config };
751
+ if (this.replacer) {
752
+ this.replacer.updateConfig(config);
753
+ }
754
+ }
755
+ destroy() {
756
+ this.replacer = null;
757
+ console.log('[ViewportFixer] Destroyed');
758
+ }
759
+ }
760
+ function initViewportFixer(config) {
761
+ const fixer = new ViewportUnitsFixer(config);
762
+ window.addEventListener('iframe-dimensions-applied', ((e) => {
763
+ const ev = e;
764
+ console.log('[ViewportFixer] Iframe dimensions finalized:', ev.detail);
765
+ }));
766
+ return fixer;
763
767
  }
764
-
765
- var viewportReplacer = /*#__PURE__*/Object.freeze({
766
- __proto__: null,
767
- default: ViewportUnitsReplacer
768
- });
769
768
 
770
769
  const scrollToElementIfNeeded = (visualRef, rect, scale) => {
771
770
  if (!visualRef.current)
@@ -2367,7 +2366,7 @@ const VizLiveRenderer = () => {
2367
2366
  const VizLiveHeatmap = () => {
2368
2367
  const controls = useHeatmapControlStore((state) => state.controls);
2369
2368
  const isRendering = useHeatmapDataStore((state) => state.isRendering);
2370
- const iframeHeight = useHeatmapSingleStore((state) => state.iframeHeight);
2369
+ const iframeHeight = useHeatmapLiveStore((state) => state.iframeHeight);
2371
2370
  const wrapperHeight = useHeatmapLiveStore((state) => state.wrapperHeight);
2372
2371
  const setWrapperHeight = useHeatmapLiveStore((state) => state.setWrapperHeight);
2373
2372
  const reset = useHeatmapLiveStore((state) => state.reset);