@pisell/pisellos
Version:
一个可扩展的前端模块化SDK框架,支持插件系统
116 lines (115 loc) • 3.08 kB
TypeScript
import { Plugin } from '../types';
/**
* WindowPlugin 接口定义
*/
export interface WindowPlugin extends Plugin {
setTimeout: typeof setTimeout;
clearTimeout: typeof clearTimeout;
setInterval: typeof setInterval;
clearInterval: typeof clearInterval;
localStorage: Storage;
sessionStorage: Storage;
location: Partial<Location>;
navigator: Partial<Navigator>;
document: Partial<Document>;
history: History;
}
/**
* 简单的 Storage 接口实现
*/
declare class SimpleStorage implements Storage {
private items;
get length(): number;
key(index: number): string | null;
getItem(key: string): string | null;
setItem(key: string, value: string): void;
removeItem(key: string): void;
clear(): void;
}
/**
* 简单的 Location 类实现
*/
declare class SimpleLocation implements Partial<Location> {
hash: string;
host: string;
hostname: string;
href: string;
origin: string;
pathname: string;
port: string;
protocol: string;
search: string;
ancestorOrigins: DOMStringList;
assign(url: string | URL): void;
reload(): void;
replace(url: string | URL): void;
toString(): string;
}
/**
* 简单的 Navigator 类实现
*/
declare class SimpleNavigator implements Partial<Navigator> {
userAgent: string;
language: string;
languages: string[];
onLine: boolean;
cookieEnabled: boolean;
readonly appCodeName: string;
readonly appName: string;
readonly appVersion: string;
readonly platform: string;
readonly product: string;
javaEnabled(): boolean;
}
/**
* 简单的 History 接口实现
*/
declare class SimpleHistory implements History {
length: number;
scrollRestoration: ScrollRestoration;
state: any;
back(): void;
forward(): void;
go(): void;
pushState(): void;
replaceState(): void;
}
/**
* 简单的 Document 类实现
*/
declare class SimpleDocument implements Partial<Document> {
private elements;
createElement(tagName: string): HTMLElement;
getElementById(id: string): HTMLElement | null;
readonly URL: string;
readonly documentURI: string;
readonly origin: string;
readonly characterSet: string;
readonly contentType: string;
readonly compatMode: string;
querySelector(): Element | null;
querySelectorAll(): NodeListOf<Element>;
getElementsByTagName(): HTMLCollectionOf<Element>;
getElementsByClassName(): HTMLCollectionOf<Element>;
}
/**
* Window 插件实现
*/
declare class WindowPluginImpl implements WindowPlugin {
name: string;
version: string;
setTimeout: typeof setTimeout;
clearTimeout: typeof clearTimeout;
setInterval: typeof setInterval;
clearInterval: typeof clearInterval;
localStorage: SimpleStorage;
sessionStorage: SimpleStorage;
location: SimpleLocation;
navigator: SimpleNavigator;
document: SimpleDocument;
history: SimpleHistory;
initialize(): void;
destroy(): void;
}
declare const _default: WindowPluginImpl;
export default _default;