Files
stats/packages/sdks/web/cdn.ts
Carl-Gerhard Lindesvärd f9e5feb688 prepare sdk packages
2024-03-11 19:52:49 +01:00

32 lines
639 B
TypeScript

import { Openpanel } from './index';
declare global {
interface Window {
op: {
q?: [string, ...any[]];
(method: string, ...args: any[]): void;
};
}
}
((window) => {
if (window.op && 'q' in window.op) {
const queue = window.op.q || [];
const op = new Openpanel(queue.shift()[1]);
queue.forEach((item) => {
if (item[0] in op) {
// @ts-expect-error
op[item[0]](...item.slice(1));
}
});
window.op = (t, ...args) => {
// @ts-expect-error
const fn = op[t].bind(op);
if (typeof fn === 'function') {
fn(...args);
}
};
}
})(window);