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

271 lines (270 loc) 11.4 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __reflectGet = Reflect.get; 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 __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj); var __async = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { step(generator.next(value)); } catch (e) { reject(e); } }; var rejected = (value) => { try { step(generator.throw(value)); } catch (e) { reject(e); } }; var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected); step((generator = generator.apply(__this, __arguments)).next()); }); }; var UIRootViewController_exports = {}; __export(UIRootViewController_exports, { UIRootViewController: () => UIRootViewController }); module.exports = __toCommonJS(UIRootViewController_exports); var import_UIColor = require("./UIColor"); var import_UICore = require("./UICore"); var import_UIDialogView = require("./UIDialogView"); var import_UIObject = require("./UIObject"); var import_UIRectangle = require("./UIRectangle"); var import_UIRoute = require("./UIRoute"); var import_UIView = require("./UIView"); var import_UIViewController = require("./UIViewController"); class UIRootViewController extends import_UIViewController.UIViewController { constructor(view) { super(view); this.backgroundView = new import_UIView.UIView(this.view.elementID + "BackgroundView").configuredWithObject({ style: { background: "linear-gradient(" + import_UIColor.UIColor.whiteColor.stringValue + ", " + import_UIColor.UIColor.blueColor.stringValue + ")", backgroundSize: "cover", backgroundRepeat: "no-repeat" } }); this.contentViewControllers = { mainViewController: this.lazyViewControllerObjectWithClass(import_UIViewController.UIViewController) }; this._detailsDialogView = new import_UIDialogView.UIDialogView(this.view.elementID + "DetailsDialogView").configuredWithObject({ dismiss: (0, import_UIObject.EXTEND)( () => { const route = import_UIRoute.UIRoute.currentRoute; this.detailsViewControllers.allValues.forEach( (value) => route.routeByRemovingComponentNamed(value.class.routeComponentName) ); route.apply(); } ) }); this.detailsViewControllers = {}; this.view.addSubview(this.backgroundView); } lazyViewControllerObjectWithClass(classObject, shouldShow = () => import_UIObject.YES) { const result = { class: classObject, instance: import_UIObject.nil, shouldShow, isInitialized: import_UIObject.NO }; import_UIObject.UIObject.configureWithObject(result, { instance: (0, import_UIObject.LAZY_VALUE)( () => { result.isInitialized = import_UIObject.YES; return new classObject( new import_UIView.UIView(classObject.name.replace("ViewController", "View")) ); } ) }); return result; } handleRoute(route) { return __async(this, null, function* () { yield __superGet(UIRootViewController.prototype, this, "handleRoute").call(this, route); import_UICore.UICore.languageService.updateCurrentLanguageKey(); yield this.setContentViewControllerForRoute(route); yield this.setDetailsViewControllerForRoute(route); }); } setContentViewControllerForRoute(route) { return __async(this, null, function* () { const contentViewControllerObject = (0, import_UIObject.FIRST)( yield this.contentViewControllers.allValues.findAsyncSequential( (value) => __async(this, null, function* () { return (0, import_UIObject.IS)(route.componentWithViewController(value.class)) && (yield value.shouldShow()); }) ), this.contentViewControllers.mainViewController ); this.contentViewController = contentViewControllerObject.instance; }); } setDetailsViewControllerForRoute(route) { return __async(this, null, function* () { const detailsViewControllerObject = (0, import_UIObject.FIRST_OR_NIL)( yield this.detailsViewControllers.allValues.findAsyncSequential( (value) => __async(this, null, function* () { return (0, import_UIObject.IS)(route.componentWithViewController(value.class)) && (yield value.shouldShow()); }) ) ); if ((0, import_UIObject.IS)(route) && (0, import_UIObject.IS)(this.detailsViewController) && (0, import_UIObject.IS_NOT)(detailsViewControllerObject)) { this.detailsViewController = void 0; this._detailsDialogView.dismiss(); this.view.setNeedsLayout(); return; } this.detailsViewController = detailsViewControllerObject.instance; }); } get contentViewController() { return this._contentViewController; } set contentViewController(controller) { if (this.contentViewController == controller) { return; } if (this.contentViewController) { this.removeChildViewController(this.contentViewController); } this._contentViewController = controller; this.addChildViewControllerInContainer(controller, this.backgroundView); this._triggerLayoutViewSubviews(); if (this.contentViewController) { this.contentViewController.view.style.boxShadow = "0 3px 6px 0 rgba(0, 0, 0, 0.1)"; } this.view.setNeedsLayout(); } get detailsViewController() { return this._detailsViewController; } set detailsViewController(controller) { if (this.detailsViewController == controller) { return; } if ((0, import_UIObject.IS)(this.detailsViewController)) { this.removeChildViewController(this.detailsViewController); } this._detailsViewController = controller; if (!(0, import_UIObject.IS)(controller)) { return; } this.addChildViewControllerInDialogView(controller, this._detailsDialogView); this._triggerLayoutViewSubviews(); (0, import_UIObject.FIRST_OR_NIL)(this.detailsViewController).view.style.borderRadius = "5px"; this._detailsDialogView.showInView(this.view, import_UIObject.YES); } updatePageScale({ minScaleWidth = 700, maxScaleWidth = 1500, minScale = 0.7, maxScale = 1 } = {}) { var _a; const actualPageWidth = (_a = window.innerWidth) != null ? _a : (import_UIView.UIView.pageWidth * import_UIView.UIView.pageScale).integerValue; let scale = minScale + (maxScale - minScale) * ((actualPageWidth - minScaleWidth) / (maxScaleWidth - minScaleWidth)); scale = Math.min(scale, maxScale); scale = Math.max(scale, minScale); import_UIView.UIView.pageScale = scale; } performDefaultLayout({ paddingLength = 20, contentViewMaxWidth = 1e3, topBarHeight = 65, bottomBarMinHeight = 100 } = {}) { var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k; const bounds = this.view.bounds; if (this.topBarView) { this.topBarView.frame = new import_UIRectangle.UIRectangle(0, 0, topBarHeight, bounds.width); } this.backgroundView.style.top = "" + ((_b = (_a = this.topBarView) == null ? void 0 : _a.frame.height.integerValue) != null ? _b : 0) + "px"; this.backgroundView.style.width = "100%"; this.backgroundView.style.height = "fit-content"; this.backgroundView.style.minHeight = "" + (bounds.height - ((_d = (_c = this.topBarView) == null ? void 0 : _c.frame.height) != null ? _d : 0) - ((_f = (_e = this.bottomBarView) == null ? void 0 : _e.frame.height) != null ? _f : 0)).integerValue + "px"; const contentView = (_h = (_g = this.contentViewController) == null ? void 0 : _g.view) != null ? _h : import_UIObject.nil; contentView.style.position = "relative"; contentView.style.bottom = "0"; contentView.style.top = "0"; contentView.style.width = "100%"; contentView.setPaddings(import_UIObject.nil, import_UIObject.nil, paddingLength, import_UIObject.nil); if (contentViewMaxWidth < this.backgroundView.bounds.width) { contentView.style.marginBottom = "" + Math.min( (this.backgroundView.bounds.width - contentViewMaxWidth) * 0.5, paddingLength ).integerValue + "px"; contentView.style.marginTop = "" + Math.min( (this.backgroundView.bounds.width - contentViewMaxWidth) * 0.5, paddingLength ).integerValue + "px"; contentView.style.maxWidth = contentViewMaxWidth + "px"; contentView.style.left = "" + ((this.backgroundView.bounds.width - contentView.bounds.width) * 0.5).integerValue + "px"; } else { contentView.style.margin = ""; contentView.style.left = ""; contentView.style.maxWidth = ""; } (_i = this.contentViewController) == null ? void 0 : _i._triggerLayoutViewSubviews(); let contentViewControllerViewHeight = contentView.intrinsicContentHeight( contentView.bounds.width ); const detailsViewControllerViewHeight = (0, import_UIObject.FIRST_OR_NIL)(this.detailsViewController).view.intrinsicContentHeight( contentView.bounds.width ); if (detailsViewControllerViewHeight > contentViewControllerViewHeight) { contentViewControllerViewHeight = detailsViewControllerViewHeight; } contentView.style.height = "" + contentViewControllerViewHeight.integerValue + "px"; if ((0, import_UIObject.IS)(this.detailsViewController)) { contentView.style.transform = "translateX(" + 0 + "px)"; this.detailsViewController.view.frame = this.backgroundView.frame.rectangleWithInset( paddingLength ).rectangleWithWidth( contentView.bounds.width, 0.5 ).rectangleWithHeight( Math.max( this.detailsViewController.view.intrinsicContentHeight( this.detailsViewController.view.bounds.width ), contentView.bounds.height ) ); } else { contentView.style.transform = "translateX(" + 0 + "px)"; } if (this.bottomBarView) { this.bottomBarView.frame = this.backgroundView.frame.rectangleWithY( this.backgroundView.frame.max.y ).rectangleWithHeight( Math.max(bottomBarMinHeight, this.bottomBarView.intrinsicContentHeight(this.backgroundView.frame.width)) ); } (0, import_UIObject.wrapInNil)(this._detailsDialogView).setMaxSizes((_k = (_j = this.bottomBarView) == null ? void 0 : _j.frame.max.y) != null ? _k : 0); } } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { UIRootViewController }); //# sourceMappingURL=UIRootViewController.js.map