UNPKG

wndkit

Version:

Native Windows desktop apps in Node.js

138 lines (137 loc) 4.44 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.Application = exports.CheckBox = exports.TextBox = exports.Label = exports.Button = exports.Window = void 0; const events_1 = require("events"); const path = __importStar(require("path")); const fs = __importStar(require("fs")); // Try prebuilt first, fall back to build directory const prebuiltPath = path.join(__dirname, "../prebuilt/win32-x64/wndkit.node"); const buildPath = path.join(__dirname, "../build/Release/wndkit.node"); const native = require(fs.existsSync(prebuiltPath) ? prebuiltPath : buildPath); class Control extends events_1.EventEmitter { constructor(nativeClass, ...args) { super(); this.native = new nativeClass(); this.handle = this.native.create(...args); this.native.setEventCallback?.((eventType, handle) => { this.emit(eventType, { handle }); }); } get text() { return this.native.getText(); } set text(value) { this.native.setText(value); } } class Window extends Control { constructor(title = "Window", width = 800, height = 600) { super(native.Window, title, width, height); } show() { this.native.show(); } hide() { this.native.hide(); } destroy() { this.native.destroy(); } get title() { return this.native.getTitle(); } set title(value) { this.native.setTitle(value); } get size() { return this.native.getSize(); } set size({ width, height }) { this.native.setSize(width, height); } get position() { return this.native.getPosition(); } set position({ x, y }) { this.native.setPosition(x, y); } } exports.Window = Window; class Button extends Control { constructor(parent, text, x, y, width = 100, height = 30) { super(native.Button, parent.handle, text, x, y, width, height); } } exports.Button = Button; class Label extends Control { constructor(parent, text, x, y, width = 200, height = 20) { super(native.Label, parent.handle, text, x, y, width, height); } } exports.Label = Label; class TextBox extends Control { constructor(parent, text = "", x, y, width = 200, height = 25) { super(native.TextBox, parent.handle, text, x, y, width, height); } get multiline() { return this.native.getMultiline(); } set multiline(value) { this.native.setMultiline(value); } } exports.TextBox = TextBox; class CheckBox extends Control { constructor(parent, text, x, y, width = 150, height = 20) { super(native.CheckBox, parent.handle, text, x, y, width, height); } get checked() { return this.native.getChecked(); } set checked(value) { this.native.setChecked(value); } } exports.CheckBox = CheckBox; class Application { static run() { native.runMessageLoop(); } static processMessages() { return native.processMessages(); } } exports.Application = Application;