@lumino/coreutils
Version:
Lumino Core Utilities
2 lines • 8.23 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@lumino/algorithm")):"function"==typeof define&&define.amd?define(["exports","@lumino/algorithm"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).lumino_coreutils={},t.lumino_algorithm)}(this,(function(t,e){"use strict";t.JSONExt=void 0,function(t){function e(t){return null===t||"boolean"==typeof t||"number"==typeof t||"string"==typeof t}function i(t){return Array.isArray(t)}function r(t,n){if(t===n)return!0;if(e(t)||e(n))return!1;let s=i(t),o=i(n);return s===o&&(s&&o?function(t,e){if(t===e)return!0;if(t.length!==e.length)return!1;for(let i=0,n=t.length;i<n;++i)if(!r(t[i],e[i]))return!1;return!0}(t,n):function(t,e){if(t===e)return!0;for(let i in t)if(void 0!==t[i]&&!(i in e))return!1;for(let i in e)if(void 0!==e[i]&&!(i in t))return!1;for(let i in t){let n=t[i],s=e[i];if(void 0!==n||void 0!==s){if(void 0===n||void 0===s)return!1;if(!r(n,s))return!1}}return!0}(t,n))}function n(t){return e(t)?t:i(t)?function(t){let e=new Array(t.length);for(let i=0,r=t.length;i<r;++i)e[i]=n(t[i]);return e}(t):function(t){let e={};for(let i in t){let r=t[i];void 0!==r&&(e[i]=n(r))}return e}(t)}t.emptyObject=Object.freeze({}),t.emptyArray=Object.freeze([]),t.isPrimitive=e,t.isArray=i,t.isObject=function(t){return!e(t)&&!i(t)},t.deepEqual=r,t.deepCopy=n}(t.JSONExt||(t.JSONExt={}));var i;!function(t){class i{constructor(t){var e,i,r,n;this._activated=!1,this._promise=null,this._service=null,this.id=t.id,this.description=null!==(e=t.description)&&void 0!==e?e:"",this.activate=t.activate,this.deactivate=null!==(i=t.deactivate)&&void 0!==i?i:null,this.provides=null!==(r=t.provides)&&void 0!==r?r:null,this.autoStart=null!==(n=t.autoStart)&&void 0!==n&&n,this.requires=t.requires?t.requires.slice():[],this.optional=t.optional?t.optional.slice():[]}get activated(){return this._activated}set activated(t){this._activated=t}get service(){return this._service}set service(t){this._service=t}get promise(){return this._promise}set promise(t){this._promise=t}}t.createPluginData=function(t){return new i(t)},t.ensureNoCycle=function(t,e,i){const r=[...t.requires,...t.optional],n=r=>{if(r===t.provides)return!0;const o=i.get(r);if(!o)return!1;const a=e.get(o),l=[...a.requires,...a.optional];return 0!==l.length&&(s.push(o),!!l.some(n)||(s.pop(),!1))};if(!t.provides||0===r.length)return;const s=[t.id];if(r.some(n))throw new ReferenceError(`Cycle detected: ${s.join(" -> ")}.`)},t.findDependents=function(t,i,r){const n=new Array,s=t=>{const e=i.get(t),s=[...e.requires,...e.optional];n.push(...s.reduce(((e,i)=>{const n=r.get(i);return n&&e.push([t,n]),e}),[]))};for(const t of i.keys())s(t);const o=n.filter((e=>e[1]===t));let a=0;for(;o.length>a;){const t=o.length,e=new Set(o.map((t=>t[0])));for(const t of e)n.filter((e=>e[1]===t)).forEach((t=>{o.includes(t)||o.push(t)}));a=t}const l=e.topologicSort(o),u=l.findIndex((e=>e===t));return-1===u?[t]:l.slice(0,u+1)},t.collectStartupPlugins=function(t,e){const i=new Set;for(const e of t.keys())!0===t.get(e).autoStart&&i.add(e);if(e.startPlugins)for(const t of e.startPlugins)i.add(t);if(e.ignorePlugins)for(const t of e.ignorePlugins)i.delete(t);return Array.from(i)}}(i||(i={}));function r(t){let e=0;for(let i=0,r=t.length;i<r;++i)i%4==0&&(e=4294967295*Math.random()>>>0),t[i]=255&e,e>>>=8}t.Random=void 0,(t.Random||(t.Random={})).getRandomValues=(()=>{const t="undefined"!=typeof window&&(window.crypto||window.msCrypto)||null;return t&&"function"==typeof t.getRandomValues?function(e){return t.getRandomValues(e)}:r})(),t.UUID=void 0,(t.UUID||(t.UUID={})).uuid4=function(t){const e=new Uint8Array(16),i=new Array(256);for(let t=0;t<16;++t)i[t]="0"+t.toString(16);for(let t=16;t<256;++t)i[t]=t.toString(16);return function(){return t(e),e[6]=64|15&e[6],e[8]=128|63&e[8],i[e[0]]+i[e[1]]+i[e[2]]+i[e[3]]+"-"+i[e[4]]+i[e[5]]+"-"+i[e[6]]+i[e[7]]+"-"+i[e[8]]+i[e[9]]+"-"+i[e[10]]+i[e[11]]+i[e[12]]+i[e[13]]+i[e[14]]+i[e[15]]}}(t.Random.getRandomValues),t.MimeData=class{constructor(){this._types=[],this._values=[]}types(){return this._types.slice()}hasData(t){return-1!==this._types.indexOf(t)}getData(t){let e=this._types.indexOf(t);return-1!==e?this._values[e]:void 0}setData(t,e){this.clearData(t),this._types.push(t),this._values.push(e)}clearData(t){let e=this._types.indexOf(t);-1!==e&&(this._types.splice(e,1),this._values.splice(e,1))}clear(){this._types.length=0,this._values.length=0}},t.PluginRegistry=class{constructor(t={}){this._application=null,this._validatePlugin=()=>!0,this._plugins=new Map,this._services=new Map,t.validatePlugin&&(console.info("Plugins may be rejected by the custom validation plugin method."),this._validatePlugin=t.validatePlugin)}get application(){return this._application}set application(t){if(null!==this._application)throw Error("PluginRegistry.application is already set. It cannot be overridden.");this._application=t}get deferredPlugins(){return Array.from(this._plugins).filter((([t,e])=>"defer"===e.autoStart)).map((([t,e])=>t))}getPluginDescription(t){var e,i;return null!==(i=null===(e=this._plugins.get(t))||void 0===e?void 0:e.description)&&void 0!==i?i:""}hasPlugin(t){return this._plugins.has(t)}isPluginActivated(t){var e,i;return null!==(i=null===(e=this._plugins.get(t))||void 0===e?void 0:e.activated)&&void 0!==i&&i}listPlugins(){return Array.from(this._plugins.keys())}registerPlugin(t){if(this._plugins.has(t.id))throw new TypeError(`Plugin '${t.id}' is already registered.`);if(!this._validatePlugin(t))throw new Error(`Plugin '${t.id}' is not valid.`);const e=i.createPluginData(t);i.ensureNoCycle(e,this._plugins,this._services),e.provides&&this._services.set(e.provides,e.id),this._plugins.set(e.id,e)}registerPlugins(t){for(const e of t)this.registerPlugin(e)}deregisterPlugin(t,e){const i=this._plugins.get(t);if(i){if(i.activated&&!e)throw new Error(`Plugin '${t}' is still active.`);this._plugins.delete(t)}}async activatePlugin(t){const e=this._plugins.get(t);if(!e)throw new ReferenceError(`Plugin '${t}' is not registered.`);if(e.activated)return;if(e.promise)return e.promise;const i=e.requires.map((t=>this.resolveRequiredService(t))),r=e.optional.map((t=>this.resolveOptionalService(t)));return e.promise=Promise.all([...i,...r]).then((t=>e.activate.apply(void 0,[this.application,...t]))).then((t=>{e.service=t,e.activated=!0,e.promise=null})).catch((t=>{throw e.promise=null,t})),e.promise}async activatePlugins(t,e={}){switch(t){case"defer":{const t=this.deferredPlugins.filter((t=>this._plugins.get(t).autoStart)).map((t=>this.activatePlugin(t)));await Promise.all(t);break}case"startUp":{const t=i.collectStartupPlugins(this._plugins,e).map((async t=>{try{return await this.activatePlugin(t)}catch(e){console.error(`Plugin '${t}' failed to activate.`,e)}}));await Promise.all(t);break}}}async deactivatePlugin(t){const e=this._plugins.get(t);if(!e)throw new ReferenceError(`Plugin '${t}' is not registered.`);if(!e.activated)return[];if(!e.deactivate)throw new TypeError(`Plugin '${t}'#deactivate() method missing`);const r=i.findDependents(t,this._plugins,this._services),n=r.map((t=>this._plugins.get(t)));for(const e of n)if(!e.deactivate)throw new TypeError(`Plugin ${e.id}#deactivate() method missing (depends on ${t})`);for(const t of n){const e=[...t.requires,...t.optional].map((t=>{const e=this._services.get(t);return e?this._plugins.get(e).service:null}));await t.deactivate(this.application,...e),t.service=null,t.activated=!1}return r.pop(),r}async resolveRequiredService(t){const e=this._services.get(t);if(!e)throw new TypeError(`No provider for: ${t.name}.`);const i=this._plugins.get(e);return i.activated||await this.activatePlugin(e),i.service}async resolveOptionalService(t){const e=this._services.get(t);if(!e)return null;const i=this._plugins.get(e);if(!i.activated)try{await this.activatePlugin(e)}catch(t){return console.error(t),null}return i.service}},t.PromiseDelegate=class{constructor(){this.promise=new Promise(((t,e)=>{this._resolve=t,this._reject=e}))}resolve(t){(0,this._resolve)(t)}reject(t){(0,this._reject)(t)}},t.Token=class{constructor(t,e){this.name=t,this.description=null!=e?e:"",this._tokenStructuralPropertyT=null}}}));
//# sourceMappingURL=index.min.js.map