@botiverse/porthole 0.1.4 → 0.1.6

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.
@@ -622,15 +622,22 @@ function Mount({ frame, page, initialHeightPx, placeholder, run }: MountProps):
622
622
  attempt(() => display.annotations.focus(id), latest());
623
623
  }
624
624
  }, [annotates, focusToken]);
625
+ // A flip or a restyle after the display was made: its first scheme and values went with it.
626
+ const [mountScheme] = useState(scheme);
627
+ const flipped = useRef(false);
625
628
  useEffect(() => {
626
- handle.current?.setTheme(scheme);
627
- }, [scheme]);
629
+ if (flipped.current || scheme !== mountScheme) {
630
+ flipped.current = true;
631
+ handle.current?.setTheme(scheme);
632
+ }
633
+ }, [scheme, mountScheme]);
628
634
  const { themeKey } = frame;
635
+ const [mountThemeKey] = useState(themeKey);
629
636
  useEffect(() => {
630
- if (themeKey !== undefined) {
637
+ if (themeKey !== undefined && themeKey !== mountThemeKey) {
631
638
  handle.current?.refreshTheme();
632
639
  }
633
- }, [themeKey]);
640
+ }, [themeKey, mountThemeKey]);
634
641
 
635
642
  return (
636
643
  <div
@@ -92,6 +92,10 @@ function mergeEgress(base: EgressConfig, extra: EgressConfig | undefined): Egres
92
92
  merged[kind] = origins;
93
93
  }
94
94
  }
95
+ // What the host's config opens to any https site stays; a view can't ask for it (P059).
96
+ if (base.anyHttps !== undefined) {
97
+ merged.anyHttps = base.anyHttps;
98
+ }
95
99
  return merged;
96
100
  }
97
101
 
@@ -607,12 +607,16 @@ export const SHELL_RUNTIME = String.raw`(() => {
607
607
  const notify = (method, params) => send({ method, params });
608
608
 
609
609
  const themeNames = new Set(plan.themeVariables);
610
+ // What the content was last told of (its scheme and values): the theme it starts with is no
611
+ // change, and a host context that changes neither (a host re-sending it) is none either.
612
+ let announced = null;
610
613
  const applyTheme = (context) => {
611
614
  if (context === null || typeof context !== "object") {
612
615
  return;
613
616
  }
614
617
  // The spec's variables, and Porthole's own beside them (its own-prefixed field).
615
618
  const own = context["porthole/styles"];
619
+ const applied = [];
616
620
  for (const variables of [context.styles && context.styles.variables, own && own.variables]) {
617
621
  if (variables === null || typeof variables !== "object") {
618
622
  continue;
@@ -621,12 +625,21 @@ export const SHELL_RUNTIME = String.raw`(() => {
621
625
  const value = variables[name];
622
626
  if (themeNames.has(name) && typeof value === "string") {
623
627
  document.documentElement.style.setProperty(name, value);
628
+ applied.push(name + ":" + value);
624
629
  }
625
630
  }
626
631
  }
627
632
  lastContext = context;
628
633
  schemeFollows();
629
- window.dispatchEvent(new CustomEvent(plan.themeEvent, { detail: { theme: context.theme } }));
634
+ const now = JSON.stringify([context.theme, applied.sort()]);
635
+ if (announced === null) {
636
+ announced = now;
637
+ return;
638
+ }
639
+ if (now !== announced) {
640
+ announced = now;
641
+ window.dispatchEvent(new CustomEvent(plan.themeEvent, { detail: { theme: context.theme } }));
642
+ }
630
643
  };
631
644
 
632
645
  // No size before there is something to size: an empty shell's height would make the host