Files
stats/packages/sdks/web/cdn.ts
Carl-Gerhard Lindesvärd 444e553b74 🧹 clean up duty 🧹
2024-03-28 10:40:49 +01:00

34 lines
695 B
TypeScript

/* eslint-disable @typescript-eslint/no-unsafe-call */
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);