UNPKG

1.93 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright 2020 Google LLC.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17declare namespace gapi {
18 type LoadCallback = () => void;
19 interface LoadConfig {
20 }
21 interface LoadOptions {
22 callback?: LoadCallback;
23 timeout?: number;
24 ontimeout?: LoadCallback;
25 }
26 function load(features: 'gapi.iframes', options?: LoadOptions | LoadCallback): void;
27}
28declare namespace gapi.iframes {
29 interface Message {
30 type: string;
31 }
32 type IframesFilter = (iframe: Iframe) => boolean;
33 type MessageHandler<T extends Message> = (message: T) => unknown | Promise<void>;
34 type SendCallback = () => void;
35 type Callback = (iframe: Iframe) => void;
36 class Context {
37 open(options: Record<string, unknown>, callback?: Callback): Promise<Iframe>;
38 }
39 class Iframe {
40 register<T extends Message>(message: string, handler: MessageHandler<T>, filter?: IframesFilter): void;
41 send<T extends Message, U extends Message>(type: string, data: T, callback?: MessageHandler<U>, filter?: IframesFilter): void;
42 ping(callback: SendCallback, data?: unknown): Promise<unknown[]>;
43 restyle(style: Record<string, string | boolean>, callback?: SendCallback): Promise<unknown[]>;
44 }
45 const CROSS_ORIGIN_IFRAMES_FILTER: IframesFilter;
46 function getContext(): Context;
47}