@botiverse/porthole 0.1.0 → 0.1.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.
- package/dist/bridge/bridge.js +20 -6
- package/dist/bridge/types.d.ts +19 -3
- package/dist/compile/policy.d.ts +6 -5
- package/dist/compile/policy.js +10 -12
- package/dist/config/schema.d.ts +29 -0
- package/dist/config/schema.js +16 -1
- package/dist/config/validate.d.ts +3 -1
- package/dist/config/validate.js +55 -10
- package/dist/conformance/behavior.js +50 -0
- package/dist/conformance/index.d.ts +11 -5
- package/dist/conformance/index.js +2 -2
- package/dist/conformance/probes.d.ts +26 -2
- package/dist/conformance/probes.js +51 -40
- package/dist/conformance/served.d.ts +7 -0
- package/dist/conformance/served.js +31 -7
- package/dist/guide/guide.js +6 -2
- package/dist/host/create-host.js +46 -2
- package/dist/host/locate.js +6 -1
- package/dist/host/outcome.d.ts +25 -0
- package/dist/host/outcome.js +147 -0
- package/dist/host/types.d.ts +39 -2
- package/dist/index.d.ts +6 -3
- package/dist/index.js +4 -1
- package/dist/isolation/served.d.ts +3 -0
- package/dist/isolation/served.js +20 -0
- package/dist/isolation/types.d.ts +9 -0
- package/dist/isolation/types.js +2 -1
- package/dist/platform/types.d.ts +7 -0
- package/dist/platform/web.js +15 -2
- package/dist/presets/presets.d.ts +11 -3
- package/dist/presets/presets.js +17 -1
- package/dist/react/frame.d.ts +16 -0
- package/dist/react/frame.js +44 -10
- package/dist/server/crypto.d.ts +19 -0
- package/dist/server/crypto.js +144 -0
- package/dist/server/index.d.ts +12 -4
- package/dist/server/index.js +11 -3
- package/dist/server/keys.js +12 -9
- package/dist/server/naming.d.ts +17 -0
- package/dist/server/naming.js +34 -0
- package/dist/server/pages.d.ts +11 -6
- package/dist/server/pages.js +86 -12
- package/dist/server/server.js +191 -23
- package/dist/server/tickets.d.ts +24 -0
- package/dist/server/tickets.js +46 -0
- package/dist/server/types.d.ts +76 -5
- package/dist/shell/document.d.ts +3 -2
- package/dist/shell/document.js +4 -3
- package/dist/shell/plan.d.ts +2 -0
- package/dist/shell/plan.js +1 -0
- package/dist/shell/runtime.js +20 -4
- package/package.json +2 -9
- package/src/bridge/bridge.ts +28 -6
- package/src/bridge/types.ts +21 -3
- package/src/compile/policy.ts +10 -12
- package/src/config/schema.ts +38 -0
- package/src/config/validate.ts +63 -14
- package/src/conformance/behavior.ts +55 -0
- package/src/conformance/index.ts +18 -4
- package/src/conformance/probes.ts +88 -52
- package/src/conformance/served.ts +37 -8
- package/src/guide/guide.ts +8 -2
- package/src/host/create-host.ts +47 -2
- package/src/host/locate.ts +6 -1
- package/src/host/outcome.ts +177 -0
- package/src/host/types.ts +42 -2
- package/src/index.ts +19 -1
- package/src/isolation/served.ts +24 -0
- package/src/isolation/types.ts +15 -1
- package/src/platform/types.ts +7 -0
- package/src/platform/web.ts +15 -2
- package/src/presets/presets.ts +31 -3
- package/src/react/frame.tsx +78 -14
- package/src/server/crypto.ts +166 -0
- package/src/server/index.ts +20 -3
- package/src/server/keys.ts +21 -13
- package/src/server/naming.ts +42 -0
- package/src/server/pages.ts +106 -11
- package/src/server/server.ts +233 -23
- package/src/server/tickets.ts +65 -0
- package/src/server/types.ts +84 -7
- package/src/shell/document.ts +7 -6
- package/src/shell/plan.ts +3 -0
- package/src/shell/runtime.ts +20 -4
package/src/shell/plan.ts
CHANGED
|
@@ -25,6 +25,8 @@ export interface ShellPlan {
|
|
|
25
25
|
readonly themeVariables: readonly string[];
|
|
26
26
|
/** The window event fired after a theme change. */
|
|
27
27
|
readonly themeEvent: string;
|
|
28
|
+
/** Whether a whole document takes the person's scheme: when it declares it, or always. */
|
|
29
|
+
readonly themeDocuments: "declared" | "always";
|
|
28
30
|
/** `memory`: an opaque origin has no storage, so a map stands in for the frame's life. */
|
|
29
31
|
readonly storage: "memory" | "native";
|
|
30
32
|
readonly maxErrorReports: number;
|
|
@@ -58,6 +60,7 @@ export function shellPlan(config: PortholeConfig): ShellPlan | null {
|
|
|
58
60
|
globals,
|
|
59
61
|
themeVariables: Object.keys(config.theme.variables),
|
|
60
62
|
themeEvent: config.theme.event,
|
|
63
|
+
themeDocuments: config.theme.documents ?? "declared",
|
|
61
64
|
storage: config.isolation === "opaque" ? "memory" : "native",
|
|
62
65
|
maxErrorReports: config.limits.maxErrorReports,
|
|
63
66
|
maxPromptChars: config.limits.maxPromptChars,
|
package/src/shell/runtime.ts
CHANGED
|
@@ -487,6 +487,21 @@ export const SHELL_RUNTIME = String.raw`(() => {
|
|
|
487
487
|
window.dispatchEvent(new Event("load"));
|
|
488
488
|
};
|
|
489
489
|
|
|
490
|
+
// A fragment takes the person's scheme; a whole document only if it declares that it supports
|
|
491
|
+
// both (or the config says always), else it shows as its author styled it (P039).
|
|
492
|
+
let lastContext = null;
|
|
493
|
+
let themed = plan.content !== "document";
|
|
494
|
+
const schemeFollows = () => {
|
|
495
|
+
const root = document.documentElement;
|
|
496
|
+
const theme = lastContext && lastContext.theme;
|
|
497
|
+
if (themed && (theme === "light" || theme === "dark")) {
|
|
498
|
+
root.style.colorScheme = theme;
|
|
499
|
+
root.setAttribute("data-theme", theme);
|
|
500
|
+
} else {
|
|
501
|
+
root.style.removeProperty("color-scheme");
|
|
502
|
+
root.removeAttribute("data-theme");
|
|
503
|
+
}
|
|
504
|
+
};
|
|
490
505
|
// A whole document, parsed inert (no scripts run, no declarative shadow roots built), guarded,
|
|
491
506
|
// imported in place of the shell's, then its scripts run in order. The theme on the root stays.
|
|
492
507
|
const renderDocument = async (html) => {
|
|
@@ -502,6 +517,9 @@ export const SHELL_RUNTIME = String.raw`(() => {
|
|
|
502
517
|
document.head.replaceChildren(...Array.from(parsed.head.childNodes, (node) => document.importNode(node, true)));
|
|
503
518
|
document.body.replaceWith(document.importNode(parsed.body, true));
|
|
504
519
|
root = null;
|
|
520
|
+
const declaredScheme = parsed.querySelector('meta[name="color-scheme" i]');
|
|
521
|
+
themed = plan.themeDocuments === "always" || (declaredScheme !== null && /\bdark\b/i.test(declaredScheme.getAttribute("content") || ""));
|
|
522
|
+
schemeFollows();
|
|
505
523
|
await runScripts(scripts);
|
|
506
524
|
announceLoaded();
|
|
507
525
|
};
|
|
@@ -554,10 +572,8 @@ export const SHELL_RUNTIME = String.raw`(() => {
|
|
|
554
572
|
}
|
|
555
573
|
}
|
|
556
574
|
}
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
document.documentElement.setAttribute("data-theme", context.theme);
|
|
560
|
-
}
|
|
575
|
+
lastContext = context;
|
|
576
|
+
schemeFollows();
|
|
561
577
|
window.dispatchEvent(new CustomEvent(plan.themeEvent, { detail: { theme: context.theme } }));
|
|
562
578
|
};
|
|
563
579
|
|