UNPKG

uicore-ts

Version:

UICore is a library to build native-like user interfaces using pure Typescript. No HTML is needed at all. Components are described as TS classes and all user interactions are handled explicitly. This library is strongly inspired by the UIKit framework tha

122 lines (121 loc) 4.69 kB
"use strict"; 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); var UICore_exports = {}; __export(UICore_exports, { UICore: () => UICore }); module.exports = __toCommonJS(UICore_exports); var import_UICoreExtensions = require("./UICoreExtensions"); var import_UIObject = require("./UIObject"); var import_UIRoute = require("./UIRoute"); var import_UIView = require("./UIView"); var import_UIViewController = require("./UIViewController"); const _UICore = class extends import_UIObject.UIObject { constructor(rootDivElementID, rootViewControllerClass) { super(); this.paddingLength = 20; _UICore.RootViewControllerClass = rootViewControllerClass; _UICore.main = _UICore.main || this; const rootViewElement = document.getElementById(rootDivElementID); const rootView = new import_UIView.UIView(rootDivElementID, rootViewElement); rootView.pausesPointerEvents = import_UIObject.NO; rootView.core = this; if (_UICore.RootViewControllerClass) { if (!(_UICore.RootViewControllerClass.prototype instanceof import_UIViewController.UIViewController) || _UICore.RootViewControllerClass === import_UIViewController.UIViewController) { console.log( "Error, UICore.RootViewControllerClass must be UIViewController or a subclass of UIViewController, falling back to UIViewController." ); _UICore.RootViewControllerClass = import_UIViewController.UIViewController; } this.rootViewController = new _UICore.RootViewControllerClass(rootView); } else { this.rootViewController = new import_UIViewController.UIViewController(rootView); } this.rootViewController.viewWillAppear().then( () => this.rootViewController.viewDidAppear() ); this.rootViewController.view.addTargetForControlEvent( import_UIView.UIView.controlEvent.PointerUpInside, () => { var _a, _b; (_b = (_a = document.activeElement) == null ? void 0 : _a.blur) == null ? void 0 : _b.call(_a); } ); const windowDidResize = () => { this.rootViewController.view.setNeedsLayout(); this.rootViewController._triggerLayoutViewSubviews(); import_UIView.UIView.layoutViewsIfNeeded(); this.rootViewController._triggerLayoutViewSubviews(); this.rootViewController.view.broadcastEventInSubtree({ name: _UICore.broadcastEventName.WindowDidResize, parameters: import_UIObject.nil }); }; window.addEventListener("resize", windowDidResize); const didScroll = () => { this.rootViewController.view.broadcastEventInSubtree({ name: import_UIView.UIView.broadcastEventName.PageDidScroll, parameters: import_UIObject.nil }); }; window.addEventListener("scroll", didScroll, false); const hashDidChange = () => { this.rootViewController.handleRouteRecursively(import_UIRoute.UIRoute.currentRoute); this.rootViewController.view.broadcastEventInSubtree({ name: _UICore.broadcastEventName.RouteDidChange, parameters: import_UIObject.nil }); }; window.addEventListener("hashchange", hashDidChange, false); hashDidChange(); } }; let UICore = _UICore; UICore.languageService = import_UIObject.nil; UICore.broadcastEventName = { "RouteDidChange": "RouteDidChange", "WindowDidResize": "WindowDidResize" }; Array.prototype.indexOf || (Array.prototype.indexOf = function(d, e) { let a; if (null == this) { throw new TypeError('"this" is null or not defined'); } const c = Object(this), b = c.length >>> 0; if (0 === b) { return -1; } a = +e || 0; Infinity === Math.abs(a) && (a = 0); if (a >= b) { return -1; } for (a = Math.max(0 <= a ? a : b - Math.abs(a), 0); a < b; ) { if (a in c && c[a] === d) { return a; } a++; } return -1; }); // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { UICore }); //# sourceMappingURL=UICore.js.map