UNPKG

@pisell/pisellos

Version:

一个可扩展的前端模块化SDK框架,支持插件系统

253 lines (251 loc) 6.58 kB
var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/plugins/window.ts var window_exports = {}; __export(window_exports, { default: () => window_default }); module.exports = __toCommonJS(window_exports); var SimpleStorage = class { constructor() { this.items = {}; } get length() { return Object.keys(this.items).length; } key(index) { const keys = Object.keys(this.items); return index >= 0 && index < keys.length ? keys[index] : null; } getItem(key) { return key in this.items ? this.items[key] : null; } setItem(key, value) { this.items[key] = value; } removeItem(key) { delete this.items[key]; } clear() { this.items = {}; } }; var SimpleLocation = class { constructor() { this.hash = ""; this.host = "localhost"; this.hostname = "localhost"; this.href = "https://localhost"; this.origin = "https://localhost"; this.pathname = "/"; this.port = ""; this.protocol = "https:"; this.search = ""; this.ancestorOrigins = {}; } assign(url) { } reload() { } replace(url) { } toString() { return this.href; } }; var SimpleNavigator = class { constructor() { this.userAgent = "PisellOS/1.0"; this.language = "zh-CN"; this.languages = ["zh-CN", "en-US"]; this.onLine = true; this.cookieEnabled = true; // 以下属性只提供必要实现 this.appCodeName = "PisellOS"; this.appName = "PisellOS"; this.appVersion = "1.0"; this.platform = "PisellOS"; this.product = "PisellOS"; } javaEnabled() { return false; } }; var SimpleHistory = class { constructor() { this.length = 0; this.scrollRestoration = "auto"; this.state = null; } back() { } forward() { } go() { } pushState() { } replaceState() { } }; var SimpleDocument = class { constructor() { // 仅实现基本功能 this.elements = {}; // Document 接口的必要属性 this.URL = "https://localhost"; this.documentURI = "https://localhost"; this.origin = "https://localhost"; this.characterSet = "UTF-8"; this.contentType = "text/html"; this.compatMode = "CSS1Compat"; } createElement(tagName) { const element = { tagName: tagName.toUpperCase(), id: "", className: "", innerHTML: "", style: {}, dataset: {}, attributes: {}, children: [], parentElement: null, addEventListener: () => { }, removeEventListener: () => { }, getAttribute: (name) => element.attributes[name], setAttribute: (name, value) => { element.attributes[name] = value; }, removeAttribute: (name) => { delete element.attributes[name]; }, appendChild: (child) => { element.children.push(child); return child; }, removeChild: (child) => { const index = element.children.indexOf(child); if (index !== -1) { element.children.splice(index, 1); } return child; } }; return element; } getElementById(id) { return this.elements[id] || null; } querySelector() { return null; } querySelectorAll() { return []; } getElementsByTagName() { return []; } getElementsByClassName() { return []; } }; var WindowPluginImpl = class { constructor() { this.name = "window"; this.version = "1.0.0"; // 定时器相关 this.setTimeout = Object.assign( function(handler, timeout, ...args) { if (typeof globalThis !== "undefined" && globalThis.setTimeout) { return globalThis.setTimeout(handler, timeout, ...args); } const timeoutId = Date.now(); Promise.resolve().then(() => { setTimeout(() => { if (typeof handler === "function") { handler(...args); } else { eval(handler); } }, timeout || 0); }); return timeoutId; }, { __promisify__: function(delay, value) { return new Promise((resolve) => setTimeout(resolve, delay, value)); } } ); this.clearTimeout = function(timeout2) { if (typeof globalThis !== "undefined" && globalThis.clearTimeout) { globalThis.clearTimeout(timeout2); } }; this.setInterval = Object.assign( function(handler, timeout, ...args) { if (typeof globalThis !== "undefined" && globalThis.setInterval) { return globalThis.setInterval(handler, timeout, ...args); } const intervalId = Date.now(); const recursiveTimeout = () => { this.setTimeout(() => { if (typeof handler === "function") { handler(...args); } else { eval(handler); } recursiveTimeout(); }, timeout || 0); }; recursiveTimeout(); return intervalId; }, { __promisify__: function(delay, value) { return new Promise((resolve) => setInterval(resolve, delay, value)); } } ); this.clearInterval = function(timeout2) { if (typeof globalThis !== "undefined" && globalThis.clearInterval) { globalThis.clearInterval(timeout2); } }; // 存储相关 this.localStorage = new SimpleStorage(); this.sessionStorage = new SimpleStorage(); // 浏览器环境对象 this.location = new SimpleLocation(); this.navigator = new SimpleNavigator(); this.document = new SimpleDocument(); this.history = new SimpleHistory(); } // 初始化方法 initialize() { console.log("[WindowPlugin] 初始化完成"); } // 销毁方法 destroy() { console.log("[WindowPlugin] 已销毁"); } }; var window_default = new WindowPluginImpl();