@squadbase/vantage 0.2.1 → 0.2.2

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.
@@ -517,6 +517,45 @@ function sameChartTokens(a, b) {
517
517
  if (!a || !b) return false;
518
518
  return a.series.length === b.series.length && a.series.every((color, i) => color === b.series[i]) && a.foreground === b.foreground && a.mutedForeground === b.mutedForeground && a.border === b.border && a.popover === b.popover && a.popoverForeground === b.popoverForeground;
519
519
  }
520
+ function watchChartTokens(onChange) {
521
+ if (typeof document === "undefined") return () => {
522
+ };
523
+ let frame = 0;
524
+ const schedule = () => {
525
+ if (frame) return;
526
+ frame = requestAnimationFrame(() => {
527
+ frame = 0;
528
+ onChange();
529
+ });
530
+ };
531
+ const themeObserver = new MutationObserver(schedule);
532
+ const attributeFilter = ["class", "style", "data-theme"];
533
+ themeObserver.observe(document.documentElement, { attributes: true, attributeFilter });
534
+ if (document.body) themeObserver.observe(document.body, { attributes: true, attributeFilter });
535
+ const styleObserver = new MutationObserver(schedule);
536
+ if (document.head) {
537
+ styleObserver.observe(document.head, {
538
+ childList: true,
539
+ subtree: true,
540
+ characterData: true,
541
+ attributes: true,
542
+ attributeFilter: ["href", "media", "disabled"]
543
+ });
544
+ }
545
+ const onLoad = (event) => {
546
+ if (event.target instanceof HTMLLinkElement) schedule();
547
+ };
548
+ document.addEventListener("load", onLoad, true);
549
+ const media = window.matchMedia("(prefers-color-scheme: dark)");
550
+ media.addEventListener("change", schedule);
551
+ return () => {
552
+ if (frame) cancelAnimationFrame(frame);
553
+ themeObserver.disconnect();
554
+ styleObserver.disconnect();
555
+ document.removeEventListener("load", onLoad, true);
556
+ media.removeEventListener("change", schedule);
557
+ };
558
+ }
520
559
  function axisTheme(tokens, splitLine) {
521
560
  const line = tokens.border ?? void 0;
522
561
  return {
@@ -575,16 +614,7 @@ var EChart = forwardRef(function EChart2({
575
614
  });
576
615
  };
577
616
  sync();
578
- const observer = new MutationObserver(sync);
579
- const attributeFilter = ["class", "style", "data-theme"];
580
- observer.observe(document.documentElement, { attributes: true, attributeFilter });
581
- if (document.body) observer.observe(document.body, { attributes: true, attributeFilter });
582
- const media = window.matchMedia("(prefers-color-scheme: dark)");
583
- media.addEventListener("change", sync);
584
- return () => {
585
- observer.disconnect();
586
- media.removeEventListener("change", sync);
587
- };
617
+ return watchChartTokens(sync);
588
618
  }, [theme]);
589
619
  const autoTheme = useMemo(() => tokens ? buildChartTheme(tokens) : void 0, [tokens]);
590
620
  const resolvedTheme = theme ?? autoTheme;