UNPKG

@soil/arch

Version:

Architectural constructs for web applications.

297 lines 10 kB
var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); System.register("arch/src/assert", [], function (exports_1, context_1) { "use strict"; var AssertionError; var __moduleName = context_1 && context_1.id; /** * Ensure that a given condition is true, adding basic support for design-by- * contract programming. * * When providing a function as opposed to a boolean as the first argument, the * source code of the function will be included as part of the error message in * case of failure, providing immediate feedback to help determine the reason * why the assertion did not hold true. */ function assert(assertion, message) { if (message === void 0) { message = ''; } var assertionIsFunction = typeof assertion === 'function'; var ok = assertionIsFunction ? assertion() : assertion; if (!ok) { if (assertionIsFunction) { if (message) { message += ' // '; } message += 'Assertion was: ' + assertion.toString(); } throw new AssertionError(message); } } exports_1("assert", assert); return { setters: [], execute: function () { /** * Specialized type of error to easily identify exceptions originated in * `assert()` expressions. */ AssertionError = /** @class */ (function (_super) { __extends(AssertionError, _super); function AssertionError() { return _super !== null && _super.apply(this, arguments) || this; } return AssertionError; }(Error)); } }; }); System.register("arch/src/chan", [], function (exports_2, context_2) { "use strict"; var __moduleName = context_2 && context_2.id; /** * Type-safe event mini-bus, or publisher/subscriber system. Useful for * communicating distant components. */ function chan() { var listeners = []; /** * Unsubscribe a listener from the channel. */ function unsub(listener) { listeners = listeners.filter(function (l) { return l !== listener; }); } return { /** * Subscribe a listener to the channel. A function is returned which can * be called to unsubscribe that same listener. An optional second * argument may be passed to specify the maximum number of times the * listener will be notified before automatically unsubscribing it. */ sub: function (listener, times) { var timesIsDefined = times !== undefined; var listenerWrapper = function (msg) { if (timesIsDefined && --times === 0) { unsub(listenerWrapper); } listener(msg); }; listeners.push(listenerWrapper); return function () { return unsub(listenerWrapper); }; }, /** * Send an event to all listeners, with a payload. */ pub: function (msg) { listeners.slice().forEach(function (l) { return l(msg); }); }, /** * Return the number of listeners on the channel. */ get size() { return listeners.length; }, /** * Unsubscribe all listeners from the channel. */ clear: function () { listeners.length = 0; } }; } exports_2("chan", chan); return { setters: [], execute: function () { } }; }); System.register("arch/src/extend", [], function (exports_3, context_3) { "use strict"; var __moduleName = context_3 && context_3.id; /** * Extend `target` with the enumerable own properties in `source`. Similar to * `Object.assign()`, but including getters and setters. */ function extend(target, source) { for (var prop in source) { if (source.hasOwnProperty(prop)) { Object.defineProperty(target, prop, Object.getOwnPropertyDescriptor(source, prop)); } } return target; } exports_3("extend", extend); return { setters: [], execute: function () { } }; }); System.register("shared/types/Types", [], function (exports_4, context_4) { "use strict"; var __moduleName = context_4 && context_4.id; return { setters: [], execute: function () { } }; }); /// Script-generated. System.register("shared/types/AriaAttributes", [], function (exports_5, context_5) { "use strict"; var __moduleName = context_5 && context_5.id; return { setters: [], execute: function () { } }; }); System.register("shared/types/Props", [], function (exports_6, context_6) { "use strict"; var __moduleName = context_6 && context_6.id; return { setters: [], execute: function () { } }; }); System.register("shared/functions/isPlainObject", [], function (exports_7, context_7) { "use strict"; var __moduleName = context_7 && context_7.id; function isPlainObject(o) { return o instanceof Object && o.constructor === Object; } exports_7("isPlainObject", isPlainObject); return { setters: [], execute: function () { } }; }); System.register("shared/functions/assignProps", ["shared/functions/isPlainObject"], function (exports_8, context_8) { "use strict"; var isPlainObject_1; var __moduleName = context_8 && context_8.id; /** * Assign properties from an object literal to an object of type `HTMLElement` * or `SVGElement`. */ function assignProps(elem, props) { for (var p in props) { if (props.hasOwnProperty(p)) { if (p === 'role' || p.startsWith('aria-')) { // First-class support for accessibility attributes. elem.setAttribute(p, props[p] || ''); } else if (isPlainObject_1.isPlainObject(props[p])) { // Go deeper for properties such as `style` or SVG-specific properties. assignNestedProps(elem[p], props[p]); } else { elem[p] = props[p]; } } } } exports_8("assignProps", assignProps); function assignNestedProps(target, props) { for (var p in props) { if (props.hasOwnProperty(p)) { if (isPlainObject_1.isPlainObject(props[p])) { if (target[p] === undefined) { target[p] = {}; } assignNestedProps(target[p], props[p]); } else { target[p] = props[p]; } } } } return { setters: [ function (isPlainObject_1_1) { isPlainObject_1 = isPlainObject_1_1; } ], execute: function () { } }; }); System.register("arch/src/element", ["arch/src/extend", "shared/functions/assignProps"], function (exports_9, context_9) { "use strict"; var extend_1, assignProps_1; var __moduleName = context_9 && context_9.id; /** * Define a custom UI component, i.e. a piece of code whose (only) purpose is to * render HTML and/or SVG elements on the screen and manage the user interaction * with these. * * Components created with this function will behave very similarly to native * HTML and SVG elements – custom elements can be considered special cases of * native ones (as in Web Components). */ function element(definition) { return function (props, children) { var _a = definition(children), elem = _a[0], api = _a[1]; extend_1.extend(elem, api); if (props !== undefined) { assignProps_1.assignProps(elem, props); } return elem; }; } exports_9("element", element); return { setters: [ function (extend_1_1) { extend_1 = extend_1_1; }, function (assignProps_1_1) { assignProps_1 = assignProps_1_1; } ], execute: function () { } }; }); System.register("arch/src/index", ["arch/src/element", "arch/src/chan", "arch/src/assert"], function (exports_10, context_10) { "use strict"; var __moduleName = context_10 && context_10.id; return { setters: [ function (element_1_1) { exports_10({ "element": element_1_1["element"] }); }, function (chan_1_1) { exports_10({ "chan": chan_1_1["chan"] }); }, function (assert_1_1) { exports_10({ "assert": assert_1_1["assert"] }); } ], execute: function () { } }; }); //# sourceMappingURL=system.js.map