/** * Bundle of @devexpress/dx-core * Generated: 2022-12-21 * Version: 4.0.1 * License: https://js.devexpress.com/Licensing */ (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : (global = global || self, factory((global.DevExpress = global.DevExpress || {}, global.DevExpress.DXCore = {}))); }(this, (function (exports) { 'use strict'; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ function __read(o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; } function __spreadArray(to, from) { for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) to[j] = from[i]; return to; } var DELAY = 200; var compare = function (a, b) { var aPosition = a.position(); var bPosition = b.position(); for (var i = 0; i < Math.min(aPosition.length, bPosition.length); i += 1) { if (aPosition[i] < bPosition[i]) return -1; if (aPosition[i] > bPosition[i]) return 1; } return aPosition.length - bPosition.length; }; /** @internal */ var insertPlugin = function (array, newItem) { var result = array.slice(); var nextItemIndex = array.findIndex(function (item) { return compare(newItem, item) <= 0; }); var targetIndex = nextItemIndex < 0 ? array.length : nextItemIndex; var alreadyExists = (targetIndex >= 0 && targetIndex < array.length) && compare(newItem, array[targetIndex]) === 0; var deletedItems = 0; if (alreadyExists) { deletedItems = 1; var targetItemPosition = result[targetIndex].position(); if (targetItemPosition.length > 1) { for (var i = targetIndex + 1; i < result.length; i += 1) { var itemPosition = result[i].position(); if (targetItemPosition.length === itemPosition.length && targetItemPosition[targetItemPosition.length - 2] === itemPosition[itemPosition.length - 2]) { deletedItems += 1; } else { break; } } } } result.splice(targetIndex, deletedItems, newItem); return result; }; /** @internal */ var removePlugin = function (array, item) { var itemIndex = array.indexOf(item); return itemIndex >= 0 ? __spreadArray(__spreadArray([], __read(array.slice(0, itemIndex))), __read(array.slice(itemIndex + 1))) : array; }; /** @internal */ var createClickHandlers = function (click, dblClick) { var timeoutId; var events = {}; if (click) { events.onClick = function (e) { if (!timeoutId) { timeoutId = setTimeout(function () { clearTimeout(timeoutId); click(e); }, DELAY); } }; } if (dblClick) { events.onDoubleClick = function (e) { clearTimeout(timeoutId); dblClick(e); }; } return events; }; /** @internal */ var slice = function (arr) { return Array.prototype.slice.call(arr); }; // slice can be renamed to copy as well /** @internal */ var hasWindow = function () { return typeof window !== 'undefined'; }; var getDependencyError = function (pluginName, dependencyName) { return new Error("The '".concat(pluginName, "' plugin requires '").concat(dependencyName, "' to be defined before it.")); }; /** @internal */ var PluginHost = /*#__PURE__*/ (function () { function PluginHost() { this.gettersCache = {}; this.knownKeysCache = {}; this.validationRequired = true; this.plugins = []; this.subscriptions = new Set(); } PluginHost.prototype.ensureDependencies = function () { var defined = new Set(); var knownOptionals = new Map(); this.plugins .filter(function (plugin) { return plugin.container; }) .forEach(function (plugin) { var pluginName = plugin.name || ''; if (knownOptionals.has(pluginName)) { throw (getDependencyError(knownOptionals.get(pluginName), pluginName)); } (plugin.dependencies || []) .forEach(function (dependency) { if (defined.has(dependency.name)) return; if (dependency.optional) { if (!knownOptionals.has(dependency.name)) { knownOptionals.set(dependency.name, pluginName); } return; } throw (getDependencyError(pluginName, dependency.name)); }); defined.add(pluginName); }); }; PluginHost.prototype.registerPlugin = function (plugin) { this.plugins = insertPlugin(this.plugins, plugin); this.cleanPluginsCache(); }; PluginHost.prototype.unregisterPlugin = function (plugin) { this.plugins = removePlugin(this.plugins, plugin); this.cleanPluginsCache(); }; PluginHost.prototype.knownKeys = function (postfix) { if (!this.knownKeysCache[postfix]) { this.knownKeysCache[postfix] = Array.from(this.plugins .map(function (plugin) { return Object.keys(plugin); }) .map(function (keys) { return keys.filter(function (key) { return key.endsWith(postfix); })[0]; }) .filter(function (key) { return !!key; }) .reduce(function (acc, key) { return acc.add(key); }, new Set())) .map(function (key) { return key.replace(postfix, ''); }); } return this.knownKeysCache[postfix]; }; PluginHost.prototype.collect = function (key, upTo) { if (this.validationRequired) { this.ensureDependencies(); this.validationRequired = false; } var res = this.gettersCache[key]; if (!res) { // Add cache for original plugin indexes var indexCache = this.plugins .map(function (plugin, index) { return ({ key: plugin[key], index: index }); }) .filter(function (plugin) { return !!plugin.key; }); this.gettersCache["".concat(key, "_i")] = indexCache; res = indexCache.map(function (item) { return item.key; }); this.gettersCache[key] = res; } if (!upTo) return res; var upToIndex = this.plugins.indexOf(upTo); // Try to get a result from upToIndex cache first. var upToIndexKey = key + upToIndex; var upToRes = this.gettersCache[upToIndexKey]; if (!upToRes) { var indexCache_1 = this.gettersCache["".concat(key, "_i")]; upToRes = this.gettersCache[key] .filter(function (getter, index) { return indexCache_1[index].index < upToIndex; }); this.gettersCache[upToIndexKey] = upToRes; } return upToRes; }; PluginHost.prototype.get = function (key, upTo) { var plugins = this.collect(key, upTo); if (!plugins.length) return undefined; var result; // slice creates shallow copy, when do it many times, it costs about 5% plugins.forEach(function (plugin) { result = plugin(result); }); return result; }; PluginHost.prototype.registerSubscription = function (subscription) { this.subscriptions.add(subscription); }; PluginHost.prototype.unregisterSubscription = function (subscription) { this.subscriptions.delete(subscription); }; PluginHost.prototype.broadcast = function (event, message) { this.subscriptions.forEach(function (subscription) { return subscription[event] && subscription[event](message); }); }; PluginHost.prototype.cleanPluginsCache = function () { this.validationRequired = true; this.gettersCache = {}; this.knownKeysCache = {}; }; return PluginHost; }()); /** @internal */ var EventEmitter = /*#__PURE__*/ (function () { function EventEmitter() { this.handlers = []; } EventEmitter.prototype.emit = function (e) { this.handlers.forEach(function (handler) { return handler(e); }); }; EventEmitter.prototype.subscribe = function (handler) { this.handlers.push(handler); }; EventEmitter.prototype.unsubscribe = function (handler) { this.handlers.splice(this.handlers.indexOf(handler), 1); }; return EventEmitter; }()); /** @internal */ var shallowEqual = function (objA, objB) { if (objA === objB) { return true; } var keysA = Object.keys(objA); var keysB = Object.keys(objB); if (keysA.length !== keysB.length) { return false; } // Test for A's keys different from B. var hasOwn = Object.prototype.hasOwnProperty; // tslint:disable-next-line: prefer-for-of for (var i = 0; i < keysA.length; i += 1) { if (!hasOwn.call(objB, keysA[i]) || objA[keysA[i]] !== objB[keysA[i]]) { return false; } var valA = objA[keysA[i]]; var valB = objB[keysA[i]]; if (valA !== valB) { return false; } } return true; }; /** @internal */ var argumentsShallowEqual = function (prev, next) { if (prev === null || next === null || prev.length !== next.length) { return false; } for (var i = 0; i < prev.length; i += 1) { if (prev[i] !== next[i]) { return false; } } return true; }; /** @internal */ var memoize = function (func) { var lastArgs = null; var lastResult = null; return function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } if (lastArgs === null || !argumentsShallowEqual(lastArgs, args)) { lastResult = func.apply(void 0, __spreadArray([], __read(args))); } lastArgs = args; return lastResult; }; }; /** @internal */ var easeInQuad = function (t) { return t * t; }; /** @internal */ var easeOutQuad = function (t) { return t * (2 - t); }; /** @internal */ var easeInOutQuad = function (t) { return (t < 0.5 ? 2 * t * t : -1 + ((4 - (2 * t)) * t)); }; /** @internal */ var easeInCubic = function (t) { return t * t * t; }; /** @internal */ var easeOutCubic = function (t) { return ((t - 1) * (t - 1) * (t - 1)) + 1; }; /** @internal */ var easeInOutCubic = function (t) { return (t < 0.5 ? 4 * t * t * t : ((t - 1) * ((2 * t) - 2) * ((2 * t) - 2)) + 1); }; /** @internal */ var easeInQuart = function (t) { return t * t * t * t; }; /** @internal */ var easeOutQuart = function (t) { return 1 - ((t - 1) * (t - 1) * (t - 1) * (t - 1)); }; /** @internal */ var easeInOutQuart = function (t) { return (t < 0.5 ? 8 * t * t * t * t : 1 - (8 * (t - 1) * (t - 1) * (t - 1) * (t - 1))); }; /** @internal */ var easeInQuint = function (t) { return t * t * t * t * t; }; /** @internal */ var easeOutQuint = function (t) { return 1 + ((t - 1) * (t - 1) * (t - 1) * (t - 1) * (t - 1)); }; /** @internal */ var easeInOutQuint = function (t) { return (t < 0.5 ? 16 * t * t * t * t * t : 1 + (16 * (t - 1) * (t - 1) * (t - 1) * (t - 1) * (t - 1))); }; var processPattern = function (pattern, params) { return Object.keys(params).reduce(function (msg, key) { return msg.replace("{".concat(key, "}"), params[key]); }, pattern); }; /** @internal */ var getMessagesFormatter = function (messages) { return function (key, params) { var message = messages[key]; if (typeof message === 'function') { return message(params); } if (params) { return processPattern(message, params); } return message !== null && message !== void 0 ? message : ''; }; }; exports.EventEmitter = EventEmitter; exports.PluginHost = PluginHost; exports.argumentsShallowEqual = argumentsShallowEqual; exports.createClickHandlers = createClickHandlers; exports.easeInCubic = easeInCubic; exports.easeInOutCubic = easeInOutCubic; exports.easeInOutQuad = easeInOutQuad; exports.easeInOutQuart = easeInOutQuart; exports.easeInOutQuint = easeInOutQuint; exports.easeInQuad = easeInQuad; exports.easeInQuart = easeInQuart; exports.easeInQuint = easeInQuint; exports.easeOutCubic = easeOutCubic; exports.easeOutQuad = easeOutQuad; exports.easeOutQuart = easeOutQuart; exports.easeOutQuint = easeOutQuint; exports.getMessagesFormatter = getMessagesFormatter; exports.hasWindow = hasWindow; exports.memoize = memoize; exports.shallowEqual = shallowEqual; exports.slice = slice; Object.defineProperty(exports, '__esModule', { value: true }); }))); //# sourceMappingURL=dx-core.umd.cjs.map