Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mastodon
GitHub Repository: mastodon/joinmastodon
Path: blob/main/donate/utils.ts
1006 views
1
import { z } from "zod"
2
import type { MessageData } from "./types"
3
4
export function isInIframe() {
5
return typeof window !== "undefined" && window.self !== window.top
6
}
7
8
export function sendMessage(action: string) {
9
if (isInIframe()) {
10
window.parent.postMessage({
11
source: "donate-widget",
12
action,
13
} satisfies MessageData)
14
}
15
}
16
17
export function isPopupMessage(data: unknown): data is MessageData {
18
return (
19
data &&
20
typeof data === "object" &&
21
"source" in data &&
22
data.source === "donate-widget" &&
23
"action" in data &&
24
typeof data.action === "string"
25
)
26
}
27
28
export const themeSchema = z.enum(["light", "dark", "auto"]).default("auto")
29
30