@jupyterlite/pyodide-kernel 0.7.0-rc.0 → 0.7.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_pypi.d.ts +2 -2
- package/lib/_pypi.js +2 -2
- package/lib/coincident.worker.d.ts +3 -2
- package/lib/coincident.worker.js.map +2 -2
- package/lib/comlink.worker.d.ts +1 -1
- package/lib/comlink.worker.js +4 -4
- package/lib/comlink.worker.js.map +2 -2
- package/lib/kernel.d.ts +3 -2
- package/lib/kernel.js +1 -1
- package/lib/tokens.d.ts +1 -1
- package/lib/worker.d.ts +1 -1
- package/package.json +4 -4
- package/pypi/all.json +33 -33
- package/pypi/ipykernel-6.9.2-py3-none-any.whl +0 -0
- package/pypi/{piplite-0.7.0rc0-py3-none-any.whl → piplite-0.7.0rc1-py3-none-any.whl} +0 -0
- package/pypi/{pyodide_kernel-0.7.0rc0-py3-none-any.whl → pyodide_kernel-0.7.0rc1-py3-none-any.whl} +0 -0
- package/pypi/widgetsnbextension-3.6.999-py3-none-any.whl +0 -0
- package/pypi/widgetsnbextension-4.0.999-py3-none-any.whl +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../node_modules/@lumino/algorithm/src/array.ts", "../../../node_modules/@lumino/algorithm/src/chain.ts", "../../../node_modules/@lumino/algorithm/src/empty.ts", "../../../node_modules/@lumino/algorithm/src/enumerate.ts", "../../../node_modules/@lumino/algorithm/src/filter.ts", "../../../node_modules/@lumino/algorithm/src/find.ts", "../../../node_modules/@lumino/algorithm/src/iter.ts", "../../../node_modules/@lumino/algorithm/src/map.ts", "../../../node_modules/@lumino/algorithm/src/range.ts", "../../../node_modules/@lumino/algorithm/src/reduce.ts", "../../../node_modules/@lumino/algorithm/src/repeat.ts", "../../../node_modules/@lumino/algorithm/src/retro.ts", "../../../node_modules/@lumino/algorithm/src/sort.ts", "../../../node_modules/@lumino/algorithm/src/stride.ts", "../../../node_modules/@lumino/algorithm/src/string.ts", "../../../node_modules/@lumino/algorithm/src/take.ts", "../../../node_modules/@lumino/algorithm/src/zip.ts", "../../../node_modules/@lumino/coreutils/src/json.ts", "../../../node_modules/@lumino/coreutils/src/mime.ts", "../../../node_modules/@lumino/coreutils/src/plugins.ts", "../../../node_modules/@lumino/coreutils/src/promise.ts", "../../../node_modules/@lumino/coreutils/src/token.ts", "../../../node_modules/@lumino/coreutils/src/random.ts", "../../../node_modules/@lumino/coreutils/src/random.browser.ts", "../../../node_modules/@lumino/coreutils/src/uuid.ts", "../../../node_modules/@lumino/coreutils/src/uuid.browser.ts", "../../../node_modules/@jupyterlite/services/src/contents/emscripten.ts", "../../../node_modules/@jupyterlite/services/src/contents/drivefs.ts", "../../../node_modules/proxy-target/esm/types.js", "../../../node_modules/coincident/esm/channel.js", "../../../node_modules/proxy-target/esm/traps.js", "../../../node_modules/coincident/esm/bridge.js", "../../../node_modules/coincident/esm/index.js", "../src/coincident.worker.ts", "../src/worker.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * The namespace for array-specific algorithms.\n */\nexport namespace ArrayExt {\n /**\n * Find the index of the first occurrence of a value in an array.\n *\n * @param array - The array-like object to search.\n *\n * @param value - The value to locate in the array. Values are\n * compared using strict `===` equality.\n *\n * @param start - The index of the first element in the range to be\n * searched, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * searched, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @returns The index of the first occurrence of the value, or `-1`\n * if the value is not found.\n *\n * #### Notes\n * If `stop < start` the search will wrap at the end of the array.\n *\n * #### Complexity\n * Linear.\n *\n * #### Undefined Behavior\n * A `start` or `stop` which is non-integral.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * let data = ['one', 'two', 'three', 'four', 'one'];\n * ArrayExt.firstIndexOf(data, 'red'); // -1\n * ArrayExt.firstIndexOf(data, 'one'); // 0\n * ArrayExt.firstIndexOf(data, 'one', 1); // 4\n * ArrayExt.firstIndexOf(data, 'two', 2); // -1\n * ArrayExt.firstIndexOf(data, 'two', 2, 1); // 1\n * ```\n */\n export function firstIndexOf<T>(\n array: ArrayLike<T>,\n value: T,\n start = 0,\n stop = -1\n ): number {\n let n = array.length;\n if (n === 0) {\n return -1;\n }\n if (start < 0) {\n start = Math.max(0, start + n);\n } else {\n start = Math.min(start, n - 1);\n }\n if (stop < 0) {\n stop = Math.max(0, stop + n);\n } else {\n stop = Math.min(stop, n - 1);\n }\n let span: number;\n if (stop < start) {\n span = stop + 1 + (n - start);\n } else {\n span = stop - start + 1;\n }\n for (let i = 0; i < span; ++i) {\n let j = (start + i) % n;\n if (array[j] === value) {\n return j;\n }\n }\n return -1;\n }\n\n /**\n * Find the index of the last occurrence of a value in an array.\n *\n * @param array - The array-like object to search.\n *\n * @param value - The value to locate in the array. Values are\n * compared using strict `===` equality.\n *\n * @param start - The index of the first element in the range to be\n * searched, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * searched, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @returns The index of the last occurrence of the value, or `-1`\n * if the value is not found.\n *\n * #### Notes\n * If `start < stop` the search will wrap at the front of the array.\n *\n * #### Complexity\n * Linear.\n *\n * #### Undefined Behavior\n * A `start` or `stop` which is non-integral.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * let data = ['one', 'two', 'three', 'four', 'one'];\n * ArrayExt.lastIndexOf(data, 'red'); // -1\n * ArrayExt.lastIndexOf(data, 'one'); // 4\n * ArrayExt.lastIndexOf(data, 'one', 1); // 0\n * ArrayExt.lastIndexOf(data, 'two', 0); // -1\n * ArrayExt.lastIndexOf(data, 'two', 0, 1); // 1\n * ```\n */\n export function lastIndexOf<T>(\n array: ArrayLike<T>,\n value: T,\n start = -1,\n stop = 0\n ): number {\n let n = array.length;\n if (n === 0) {\n return -1;\n }\n if (start < 0) {\n start = Math.max(0, start + n);\n } else {\n start = Math.min(start, n - 1);\n }\n if (stop < 0) {\n stop = Math.max(0, stop + n);\n } else {\n stop = Math.min(stop, n - 1);\n }\n let span: number;\n if (start < stop) {\n span = start + 1 + (n - stop);\n } else {\n span = start - stop + 1;\n }\n for (let i = 0; i < span; ++i) {\n let j = (start - i + n) % n;\n if (array[j] === value) {\n return j;\n }\n }\n return -1;\n }\n\n /**\n * Find the index of the first value which matches a predicate.\n *\n * @param array - The array-like object to search.\n *\n * @param fn - The predicate function to apply to the values.\n *\n * @param start - The index of the first element in the range to be\n * searched, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * searched, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @returns The index of the first matching value, or `-1` if no\n * matching value is found.\n *\n * #### Notes\n * If `stop < start` the search will wrap at the end of the array.\n *\n * #### Complexity\n * Linear.\n *\n * #### Undefined Behavior\n * A `start` or `stop` which is non-integral.\n *\n * Modifying the length of the array while searching.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * function isEven(value: number): boolean {\n * return value % 2 === 0;\n * }\n *\n * let data = [1, 2, 3, 4, 3, 2, 1];\n * ArrayExt.findFirstIndex(data, isEven); // 1\n * ArrayExt.findFirstIndex(data, isEven, 4); // 5\n * ArrayExt.findFirstIndex(data, isEven, 6); // -1\n * ArrayExt.findFirstIndex(data, isEven, 6, 5); // 1\n * ```\n */\n export function findFirstIndex<T>(\n array: ArrayLike<T>,\n fn: (value: T, index: number) => boolean,\n start = 0,\n stop = -1\n ): number {\n let n = array.length;\n if (n === 0) {\n return -1;\n }\n if (start < 0) {\n start = Math.max(0, start + n);\n } else {\n start = Math.min(start, n - 1);\n }\n if (stop < 0) {\n stop = Math.max(0, stop + n);\n } else {\n stop = Math.min(stop, n - 1);\n }\n let span: number;\n if (stop < start) {\n span = stop + 1 + (n - start);\n } else {\n span = stop - start + 1;\n }\n for (let i = 0; i < span; ++i) {\n let j = (start + i) % n;\n if (fn(array[j], j)) {\n return j;\n }\n }\n return -1;\n }\n\n /**\n * Find the index of the last value which matches a predicate.\n *\n * @param array - The array-like object to search.\n *\n * @param fn - The predicate function to apply to the values.\n *\n * @param start - The index of the first element in the range to be\n * searched, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * searched, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @returns The index of the last matching value, or `-1` if no\n * matching value is found.\n *\n * #### Notes\n * If `start < stop` the search will wrap at the front of the array.\n *\n * #### Complexity\n * Linear.\n *\n * #### Undefined Behavior\n * A `start` or `stop` which is non-integral.\n *\n * Modifying the length of the array while searching.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * function isEven(value: number): boolean {\n * return value % 2 === 0;\n * }\n *\n * let data = [1, 2, 3, 4, 3, 2, 1];\n * ArrayExt.findLastIndex(data, isEven); // 5\n * ArrayExt.findLastIndex(data, isEven, 4); // 3\n * ArrayExt.findLastIndex(data, isEven, 0); // -1\n * ArrayExt.findLastIndex(data, isEven, 0, 1); // 5\n * ```\n */\n export function findLastIndex<T>(\n array: ArrayLike<T>,\n fn: (value: T, index: number) => boolean,\n start = -1,\n stop = 0\n ): number {\n let n = array.length;\n if (n === 0) {\n return -1;\n }\n if (start < 0) {\n start = Math.max(0, start + n);\n } else {\n start = Math.min(start, n - 1);\n }\n if (stop < 0) {\n stop = Math.max(0, stop + n);\n } else {\n stop = Math.min(stop, n - 1);\n }\n let d: number;\n if (start < stop) {\n d = start + 1 + (n - stop);\n } else {\n d = start - stop + 1;\n }\n for (let i = 0; i < d; ++i) {\n let j = (start - i + n) % n;\n if (fn(array[j], j)) {\n return j;\n }\n }\n return -1;\n }\n\n /**\n * Find the first value which matches a predicate.\n *\n * @param array - The array-like object to search.\n *\n * @param fn - The predicate function to apply to the values.\n *\n * @param start - The index of the first element in the range to be\n * searched, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * searched, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @returns The first matching value, or `undefined` if no matching\n * value is found.\n *\n * #### Notes\n * If `stop < start` the search will wrap at the end of the array.\n *\n * #### Complexity\n * Linear.\n *\n * #### Undefined Behavior\n * A `start` or `stop` which is non-integral.\n *\n * Modifying the length of the array while searching.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * function isEven(value: number): boolean {\n * return value % 2 === 0;\n * }\n *\n * let data = [1, 2, 3, 4, 3, 2, 1];\n * ArrayExt.findFirstValue(data, isEven); // 2\n * ArrayExt.findFirstValue(data, isEven, 2); // 4\n * ArrayExt.findFirstValue(data, isEven, 6); // undefined\n * ArrayExt.findFirstValue(data, isEven, 6, 5); // 2\n * ```\n */\n export function findFirstValue<T>(\n array: ArrayLike<T>,\n fn: (value: T, index: number) => boolean,\n start = 0,\n stop = -1\n ): T | undefined {\n let index = findFirstIndex(array, fn, start, stop);\n return index !== -1 ? array[index] : undefined;\n }\n\n /**\n * Find the last value which matches a predicate.\n *\n * @param object - The array-like object to search.\n *\n * @param fn - The predicate function to apply to the values.\n *\n * @param start - The index of the first element in the range to be\n * searched, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * searched, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @returns The last matching value, or `undefined` if no matching\n * value is found.\n *\n * #### Notes\n * If `start < stop` the search will wrap at the front of the array.\n *\n * #### Complexity\n * Linear.\n *\n * #### Undefined Behavior\n * A `start` or `stop` which is non-integral.\n *\n * Modifying the length of the array while searching.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * function isEven(value: number): boolean {\n * return value % 2 === 0;\n * }\n *\n * let data = [1, 2, 3, 4, 3, 2, 1];\n * ArrayExt.findLastValue(data, isEven); // 2\n * ArrayExt.findLastValue(data, isEven, 4); // 4\n * ArrayExt.findLastValue(data, isEven, 0); // undefined\n * ArrayExt.findLastValue(data, isEven, 0, 1); // 2\n * ```\n */\n export function findLastValue<T>(\n array: ArrayLike<T>,\n fn: (value: T, index: number) => boolean,\n start = -1,\n stop = 0\n ): T | undefined {\n let index = findLastIndex(array, fn, start, stop);\n return index !== -1 ? array[index] : undefined;\n }\n\n /**\n * Find the index of the first element which compares `>=` to a value.\n *\n * @param array - The sorted array-like object to search.\n *\n * @param value - The value to locate in the array.\n *\n * @param fn - The 3-way comparison function to apply to the values.\n * It should return `< 0` if an element is less than a value, `0` if\n * an element is equal to a value, or `> 0` if an element is greater\n * than a value.\n *\n * @param start - The index of the first element in the range to be\n * searched, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * searched, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @returns The index of the first element which compares `>=` to the\n * value, or `length` if there is no such element. If the computed\n * index for `stop` is less than `start`, then the computed index\n * for `start` is returned.\n *\n * #### Notes\n * The array must already be sorted in ascending order according to\n * the comparison function.\n *\n * #### Complexity\n * Logarithmic.\n *\n * #### Undefined Behavior\n * Searching a range which is not sorted in ascending order.\n *\n * A `start` or `stop` which is non-integral.\n *\n * Modifying the length of the array while searching.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * function numberCmp(a: number, b: number): number {\n * return a - b;\n * }\n *\n * let data = [0, 3, 4, 7, 7, 9];\n * ArrayExt.lowerBound(data, 0, numberCmp); // 0\n * ArrayExt.lowerBound(data, 6, numberCmp); // 3\n * ArrayExt.lowerBound(data, 7, numberCmp); // 3\n * ArrayExt.lowerBound(data, -1, numberCmp); // 0\n * ArrayExt.lowerBound(data, 10, numberCmp); // 6\n * ```\n */\n export function lowerBound<T, U>(\n array: ArrayLike<T>,\n value: U,\n fn: (element: T, value: U) => number,\n start = 0,\n stop = -1\n ): number {\n let n = array.length;\n if (n === 0) {\n return 0;\n }\n if (start < 0) {\n start = Math.max(0, start + n);\n } else {\n start = Math.min(start, n - 1);\n }\n if (stop < 0) {\n stop = Math.max(0, stop + n);\n } else {\n stop = Math.min(stop, n - 1);\n }\n let begin = start;\n let span = stop - start + 1;\n while (span > 0) {\n let half = span >> 1;\n let middle = begin + half;\n if (fn(array[middle], value) < 0) {\n begin = middle + 1;\n span -= half + 1;\n } else {\n span = half;\n }\n }\n return begin;\n }\n\n /**\n * Find the index of the first element which compares `>` than a value.\n *\n * @param array - The sorted array-like object to search.\n *\n * @param value - The value to locate in the array.\n *\n * @param fn - The 3-way comparison function to apply to the values.\n * It should return `< 0` if an element is less than a value, `0` if\n * an element is equal to a value, or `> 0` if an element is greater\n * than a value.\n *\n * @param start - The index of the first element in the range to be\n * searched, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * searched, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @returns The index of the first element which compares `>` than the\n * value, or `length` if there is no such element. If the computed\n * index for `stop` is less than `start`, then the computed index\n * for `start` is returned.\n *\n * #### Notes\n * The array must already be sorted in ascending order according to\n * the comparison function.\n *\n * #### Complexity\n * Logarithmic.\n *\n * #### Undefined Behavior\n * Searching a range which is not sorted in ascending order.\n *\n * A `start` or `stop` which is non-integral.\n *\n * Modifying the length of the array while searching.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * function numberCmp(a: number, b: number): number {\n * return a - b;\n * }\n *\n * let data = [0, 3, 4, 7, 7, 9];\n * ArrayExt.upperBound(data, 0, numberCmp); // 1\n * ArrayExt.upperBound(data, 6, numberCmp); // 3\n * ArrayExt.upperBound(data, 7, numberCmp); // 5\n * ArrayExt.upperBound(data, -1, numberCmp); // 0\n * ArrayExt.upperBound(data, 10, numberCmp); // 6\n * ```\n */\n export function upperBound<T, U>(\n array: ArrayLike<T>,\n value: U,\n fn: (element: T, value: U) => number,\n start = 0,\n stop = -1\n ): number {\n let n = array.length;\n if (n === 0) {\n return 0;\n }\n if (start < 0) {\n start = Math.max(0, start + n);\n } else {\n start = Math.min(start, n - 1);\n }\n if (stop < 0) {\n stop = Math.max(0, stop + n);\n } else {\n stop = Math.min(stop, n - 1);\n }\n let begin = start;\n let span = stop - start + 1;\n while (span > 0) {\n let half = span >> 1;\n let middle = begin + half;\n if (fn(array[middle], value) > 0) {\n span = half;\n } else {\n begin = middle + 1;\n span -= half + 1;\n }\n }\n return begin;\n }\n\n /**\n * Test whether two arrays are shallowly equal.\n *\n * @param a - The first array-like object to compare.\n *\n * @param b - The second array-like object to compare.\n *\n * @param fn - The comparison function to apply to the elements. It\n * should return `true` if the elements are \"equal\". The default\n * compares elements using strict `===` equality.\n *\n * @returns Whether the two arrays are shallowly equal.\n *\n * #### Complexity\n * Linear.\n *\n * #### Undefined Behavior\n * Modifying the length of the arrays while comparing.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * let d1 = [0, 3, 4, 7, 7, 9];\n * let d2 = [0, 3, 4, 7, 7, 9];\n * let d3 = [42];\n * ArrayExt.shallowEqual(d1, d2); // true\n * ArrayExt.shallowEqual(d2, d3); // false\n * ```\n */\n export function shallowEqual<T>(\n a: ArrayLike<T>,\n b: ArrayLike<T>,\n fn?: (a: T, b: T) => boolean\n ): boolean {\n // Check for object identity first.\n if (a === b) {\n return true;\n }\n\n // Bail early if the lengths are different.\n if (a.length !== b.length) {\n return false;\n }\n\n // Compare each element for equality.\n for (let i = 0, n = a.length; i < n; ++i) {\n if (fn ? !fn(a[i], b[i]) : a[i] !== b[i]) {\n return false;\n }\n }\n\n // The array are shallowly equal.\n return true;\n }\n\n /**\n * Create a slice of an array subject to an optional step.\n *\n * @param array - The array-like object of interest.\n *\n * @param options - The options for configuring the slice.\n *\n * @returns A new array with the specified values.\n *\n * @throws An exception if the slice `step` is `0`.\n *\n * #### Complexity\n * Linear.\n *\n * #### Undefined Behavior\n * A `start`, `stop`, or `step` which is non-integral.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * let data = [0, 3, 4, 7, 7, 9];\n * ArrayExt.slice(data); // [0, 3, 4, 7, 7, 9]\n * ArrayExt.slice(data, { start: 2 }); // [4, 7, 7, 9]\n * ArrayExt.slice(data, { start: 0, stop: 4 }); // [0, 3, 4, 7]\n * ArrayExt.slice(data, { step: 2 }); // [0, 4, 7]\n * ArrayExt.slice(data, { step: -1 }); // [9, 7, 7, 4, 3, 0]\n * ```\n */\n export function slice<T>(\n array: ArrayLike<T>,\n options: slice.IOptions = {}\n ): T[] {\n // Extract the options.\n let { start, stop, step } = options;\n\n // Set up the `step` value.\n if (step === undefined) {\n step = 1;\n }\n\n // Validate the step size.\n if (step === 0) {\n throw new Error('Slice `step` cannot be zero.');\n }\n\n // Look up the length of the array.\n let n = array.length;\n\n // Set up the `start` value.\n if (start === undefined) {\n start = step < 0 ? n - 1 : 0;\n } else if (start < 0) {\n start = Math.max(start + n, step < 0 ? -1 : 0);\n } else if (start >= n) {\n start = step < 0 ? n - 1 : n;\n }\n\n // Set up the `stop` value.\n if (stop === undefined) {\n stop = step < 0 ? -1 : n;\n } else if (stop < 0) {\n stop = Math.max(stop + n, step < 0 ? -1 : 0);\n } else if (stop >= n) {\n stop = step < 0 ? n - 1 : n;\n }\n\n // Compute the slice length.\n let length;\n if ((step < 0 && stop >= start) || (step > 0 && start >= stop)) {\n length = 0;\n } else if (step < 0) {\n length = Math.floor((stop - start + 1) / step + 1);\n } else {\n length = Math.floor((stop - start - 1) / step + 1);\n }\n\n // Compute the sliced result.\n let result: T[] = [];\n for (let i = 0; i < length; ++i) {\n result[i] = array[start + i * step];\n }\n\n // Return the result.\n return result;\n }\n\n /**\n * The namespace for the `slice` function statics.\n */\n export namespace slice {\n /**\n * The options for the `slice` function.\n */\n export interface IOptions {\n /**\n * The starting index of the slice, inclusive.\n *\n * Negative values are taken as an offset from the end\n * of the array.\n *\n * The default is `0` if `step > 0` else `n - 1`.\n */\n start?: number;\n\n /**\n * The stopping index of the slice, exclusive.\n *\n * Negative values are taken as an offset from the end\n * of the array.\n *\n * The default is `n` if `step > 0` else `-n - 1`.\n */\n stop?: number;\n\n /**\n * The step value for the slice.\n *\n * This must not be `0`.\n *\n * The default is `1`.\n */\n step?: number;\n }\n }\n\n /**\n * An array-like object which supports item assignment.\n */\n export type MutableArrayLike<T> = {\n readonly length: number;\n [index: number]: T;\n };\n\n /**\n * Move an element in an array from one index to another.\n *\n * @param array - The mutable array-like object of interest.\n *\n * @param fromIndex - The index of the element to move. Negative\n * values are taken as an offset from the end of the array.\n *\n * @param toIndex - The target index of the element. Negative\n * values are taken as an offset from the end of the array.\n *\n * #### Complexity\n * Linear.\n *\n * #### Undefined Behavior\n * A `fromIndex` or `toIndex` which is non-integral.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * let data = [0, 1, 2, 3, 4];\n * ArrayExt.move(data, 1, 2); // [0, 2, 1, 3, 4]\n * ArrayExt.move(data, 4, 2); // [0, 2, 4, 1, 3]\n * ```\n */\n export function move<T>(\n array: MutableArrayLike<T>,\n fromIndex: number,\n toIndex: number\n ): void {\n let n = array.length;\n if (n <= 1) {\n return;\n }\n if (fromIndex < 0) {\n fromIndex = Math.max(0, fromIndex + n);\n } else {\n fromIndex = Math.min(fromIndex, n - 1);\n }\n if (toIndex < 0) {\n toIndex = Math.max(0, toIndex + n);\n } else {\n toIndex = Math.min(toIndex, n - 1);\n }\n if (fromIndex === toIndex) {\n return;\n }\n let value = array[fromIndex];\n let d = fromIndex < toIndex ? 1 : -1;\n for (let i = fromIndex; i !== toIndex; i += d) {\n array[i] = array[i + d];\n }\n array[toIndex] = value;\n }\n\n /**\n * Reverse an array in-place.\n *\n * @param array - The mutable array-like object of interest.\n *\n * @param start - The index of the first element in the range to be\n * reversed, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * reversed, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * #### Complexity\n * Linear.\n *\n * #### Undefined Behavior\n * A `start` or `stop` index which is non-integral.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * let data = [0, 1, 2, 3, 4];\n * ArrayExt.reverse(data, 1, 3); // [0, 3, 2, 1, 4]\n * ArrayExt.reverse(data, 3); // [0, 3, 2, 4, 1]\n * ArrayExt.reverse(data); // [1, 4, 2, 3, 0]\n * ```\n */\n export function reverse<T>(\n array: MutableArrayLike<T>,\n start = 0,\n stop = -1\n ): void {\n let n = array.length;\n if (n <= 1) {\n return;\n }\n if (start < 0) {\n start = Math.max(0, start + n);\n } else {\n start = Math.min(start, n - 1);\n }\n if (stop < 0) {\n stop = Math.max(0, stop + n);\n } else {\n stop = Math.min(stop, n - 1);\n }\n while (start < stop) {\n let a = array[start];\n let b = array[stop];\n array[start++] = b;\n array[stop--] = a;\n }\n }\n\n /**\n * Rotate the elements of an array in-place.\n *\n * @param array - The mutable array-like object of interest.\n *\n * @param delta - The amount of rotation to apply to the elements. A\n * positive value will rotate the elements to the left. A negative\n * value will rotate the elements to the right.\n *\n * @param start - The index of the first element in the range to be\n * rotated, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * rotated, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * #### Complexity\n * Linear.\n *\n * #### Undefined Behavior\n * A `delta`, `start`, or `stop` which is non-integral.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * let data = [0, 1, 2, 3, 4];\n * ArrayExt.rotate(data, 2); // [2, 3, 4, 0, 1]\n * ArrayExt.rotate(data, -2); // [0, 1, 2, 3, 4]\n * ArrayExt.rotate(data, 10); // [0, 1, 2, 3, 4]\n * ArrayExt.rotate(data, 9); // [4, 0, 1, 2, 3]\n * ArrayExt.rotate(data, 2, 1, 3); // [4, 2, 0, 1, 3]\n * ```\n */\n export function rotate<T>(\n array: MutableArrayLike<T>,\n delta: number,\n start = 0,\n stop = -1\n ): void {\n let n = array.length;\n if (n <= 1) {\n return;\n }\n if (start < 0) {\n start = Math.max(0, start + n);\n } else {\n start = Math.min(start, n - 1);\n }\n if (stop < 0) {\n stop = Math.max(0, stop + n);\n } else {\n stop = Math.min(stop, n - 1);\n }\n if (start >= stop) {\n return;\n }\n let length = stop - start + 1;\n if (delta > 0) {\n delta = delta % length;\n } else if (delta < 0) {\n delta = ((delta % length) + length) % length;\n }\n if (delta === 0) {\n return;\n }\n let pivot = start + delta;\n reverse(array, start, pivot - 1);\n reverse(array, pivot, stop);\n reverse(array, start, stop);\n }\n\n /**\n * Fill an array with a static value.\n *\n * @param array - The mutable array-like object to fill.\n *\n * @param value - The static value to use to fill the array.\n *\n * @param start - The index of the first element in the range to be\n * filled, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * filled, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * #### Notes\n * If `stop < start` the fill will wrap at the end of the array.\n *\n * #### Complexity\n * Linear.\n *\n * #### Undefined Behavior\n * A `start` or `stop` which is non-integral.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * let data = ['one', 'two', 'three', 'four'];\n * ArrayExt.fill(data, 'r'); // ['r', 'r', 'r', 'r']\n * ArrayExt.fill(data, 'g', 1); // ['r', 'g', 'g', 'g']\n * ArrayExt.fill(data, 'b', 2, 3); // ['r', 'g', 'b', 'b']\n * ArrayExt.fill(data, 'z', 3, 1); // ['z', 'z', 'b', 'z']\n * ```\n */\n export function fill<T>(\n array: MutableArrayLike<T>,\n value: T,\n start = 0,\n stop = -1\n ): void {\n let n = array.length;\n if (n === 0) {\n return;\n }\n if (start < 0) {\n start = Math.max(0, start + n);\n } else {\n start = Math.min(start, n - 1);\n }\n if (stop < 0) {\n stop = Math.max(0, stop + n);\n } else {\n stop = Math.min(stop, n - 1);\n }\n let span: number;\n if (stop < start) {\n span = stop + 1 + (n - start);\n } else {\n span = stop - start + 1;\n }\n for (let i = 0; i < span; ++i) {\n array[(start + i) % n] = value;\n }\n }\n\n /**\n * Insert a value into an array at a specific index.\n *\n * @param array - The array of interest.\n *\n * @param index - The index at which to insert the value. Negative\n * values are taken as an offset from the end of the array.\n *\n * @param value - The value to set at the specified index.\n *\n * #### Complexity\n * Linear.\n *\n * #### Undefined Behavior\n * An `index` which is non-integral.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * let data = [0, 1, 2];\n * ArrayExt.insert(data, 0, -1); // [-1, 0, 1, 2]\n * ArrayExt.insert(data, 2, 12); // [-1, 0, 12, 1, 2]\n * ArrayExt.insert(data, -1, 7); // [-1, 0, 12, 1, 7, 2]\n * ArrayExt.insert(data, 6, 19); // [-1, 0, 12, 1, 7, 2, 19]\n * ```\n */\n export function insert<T>(array: Array<T>, index: number, value: T): void {\n let n = array.length;\n if (index < 0) {\n index = Math.max(0, index + n);\n } else {\n index = Math.min(index, n);\n }\n for (let i = n; i > index; --i) {\n array[i] = array[i - 1];\n }\n array[index] = value;\n }\n\n /**\n * Remove and return a value at a specific index in an array.\n *\n * @param array - The array of interest.\n *\n * @param index - The index of the value to remove. Negative values\n * are taken as an offset from the end of the array.\n *\n * @returns The value at the specified index, or `undefined` if the\n * index is out of range.\n *\n * #### Complexity\n * Linear.\n *\n * #### Undefined Behavior\n * An `index` which is non-integral.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * let data = [0, 12, 23, 39, 14, 12, 75];\n * ArrayExt.removeAt(data, 2); // 23\n * ArrayExt.removeAt(data, -2); // 12\n * ArrayExt.removeAt(data, 10); // undefined;\n * ```\n */\n export function removeAt<T>(array: Array<T>, index: number): T | undefined {\n let n = array.length;\n if (index < 0) {\n index += n;\n }\n if (index < 0 || index >= n) {\n return undefined;\n }\n let value = array[index];\n for (let i = index + 1; i < n; ++i) {\n array[i - 1] = array[i];\n }\n array.length = n - 1;\n return value;\n }\n\n /**\n * Remove the first occurrence of a value from an array.\n *\n * @param array - The array of interest.\n *\n * @param value - The value to remove from the array. Values are\n * compared using strict `===` equality.\n *\n * @param start - The index of the first element in the range to be\n * searched, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * searched, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @returns The index of the removed value, or `-1` if the value\n * is not contained in the array.\n *\n * #### Notes\n * If `stop < start` the search will wrap at the end of the array.\n *\n * #### Complexity\n * Linear.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * let data = [0, 12, 23, 39, 14, 12, 75];\n * ArrayExt.removeFirstOf(data, 12); // 1\n * ArrayExt.removeFirstOf(data, 17); // -1\n * ArrayExt.removeFirstOf(data, 39, 3); // -1\n * ArrayExt.removeFirstOf(data, 39, 3, 2); // 2\n * ```\n */\n export function removeFirstOf<T>(\n array: Array<T>,\n value: T,\n start = 0,\n stop = -1\n ): number {\n let index = firstIndexOf(array, value, start, stop);\n if (index !== -1) {\n removeAt(array, index);\n }\n return index;\n }\n\n /**\n * Remove the last occurrence of a value from an array.\n *\n * @param array - The array of interest.\n *\n * @param value - The value to remove from the array. Values are\n * compared using strict `===` equality.\n *\n * @param start - The index of the first element in the range to be\n * searched, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * searched, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @returns The index of the removed value, or `-1` if the value\n * is not contained in the array.\n *\n * #### Notes\n * If `start < stop` the search will wrap at the end of the array.\n *\n * #### Complexity\n * Linear.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * let data = [0, 12, 23, 39, 14, 12, 75];\n * ArrayExt.removeLastOf(data, 12); // 5\n * ArrayExt.removeLastOf(data, 17); // -1\n * ArrayExt.removeLastOf(data, 39, 2); // -1\n * ArrayExt.removeLastOf(data, 39, 2, 3); // 3\n * ```\n */\n export function removeLastOf<T>(\n array: Array<T>,\n value: T,\n start = -1,\n stop = 0\n ): number {\n let index = lastIndexOf(array, value, start, stop);\n if (index !== -1) {\n removeAt(array, index);\n }\n return index;\n }\n\n /**\n * Remove all occurrences of a value from an array.\n *\n * @param array - The array of interest.\n *\n * @param value - The value to remove from the array. Values are\n * compared using strict `===` equality.\n *\n * @param start - The index of the first element in the range to be\n * searched, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * searched, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @returns The number of elements removed from the array.\n *\n * #### Notes\n * If `stop < start` the search will conceptually wrap at the end of\n * the array, however the array will be traversed front-to-back.\n *\n * #### Complexity\n * Linear.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * let data = [14, 12, 23, 39, 14, 12, 19, 14];\n * ArrayExt.removeAllOf(data, 12); // 2\n * ArrayExt.removeAllOf(data, 17); // 0\n * ArrayExt.removeAllOf(data, 14, 1, 4); // 1\n * ```\n */\n export function removeAllOf<T>(\n array: Array<T>,\n value: T,\n start = 0,\n stop = -1\n ): number {\n let n = array.length;\n if (n === 0) {\n return 0;\n }\n if (start < 0) {\n start = Math.max(0, start + n);\n } else {\n start = Math.min(start, n - 1);\n }\n if (stop < 0) {\n stop = Math.max(0, stop + n);\n } else {\n stop = Math.min(stop, n - 1);\n }\n let count = 0;\n for (let i = 0; i < n; ++i) {\n if (start <= stop && i >= start && i <= stop && array[i] === value) {\n count++;\n } else if (\n stop < start &&\n (i <= stop || i >= start) &&\n array[i] === value\n ) {\n count++;\n } else if (count > 0) {\n array[i - count] = array[i];\n }\n }\n if (count > 0) {\n array.length = n - count;\n }\n return count;\n }\n\n /**\n * Remove the first occurrence of a value which matches a predicate.\n *\n * @param array - The array of interest.\n *\n * @param fn - The predicate function to apply to the values.\n *\n * @param start - The index of the first element in the range to be\n * searched, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * searched, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @returns The removed `{ index, value }`, which will be `-1` and\n * `undefined` if the value is not contained in the array.\n *\n * #### Notes\n * If `stop < start` the search will wrap at the end of the array.\n *\n * #### Complexity\n * Linear.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * function isEven(value: number): boolean {\n * return value % 2 === 0;\n * }\n *\n * let data = [0, 12, 23, 39, 14, 12, 75];\n * ArrayExt.removeFirstWhere(data, isEven); // { index: 0, value: 0 }\n * ArrayExt.removeFirstWhere(data, isEven, 2); // { index: 3, value: 14 }\n * ArrayExt.removeFirstWhere(data, isEven, 4); // { index: -1, value: undefined }\n * ```\n */\n export function removeFirstWhere<T>(\n array: Array<T>,\n fn: (value: T, index: number) => boolean,\n start = 0,\n stop = -1\n ): { index: number; value: T | undefined } {\n let value: T | undefined;\n let index = findFirstIndex(array, fn, start, stop);\n if (index !== -1) {\n value = removeAt(array, index);\n }\n return { index, value };\n }\n\n /**\n * Remove the last occurrence of a value which matches a predicate.\n *\n * @param array - The array of interest.\n *\n * @param fn - The predicate function to apply to the values.\n *\n * @param start - The index of the first element in the range to be\n * searched, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * searched, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @returns The removed `{ index, value }`, which will be `-1` and\n * `undefined` if the value is not contained in the array.\n *\n * #### Notes\n * If `start < stop` the search will wrap at the end of the array.\n *\n * #### Complexity\n * Linear.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * function isEven(value: number): boolean {\n * return value % 2 === 0;\n * }\n *\n * let data = [0, 12, 23, 39, 14, 12, 75];\n * ArrayExt.removeLastWhere(data, isEven); // { index: 5, value: 12 }\n * ArrayExt.removeLastWhere(data, isEven, 2); // { index: 1, value: 12 }\n * ArrayExt.removeLastWhere(data, isEven, 2, 1); // { index: -1, value: undefined }\n * ```\n */\n export function removeLastWhere<T>(\n array: Array<T>,\n fn: (value: T, index: number) => boolean,\n start = -1,\n stop = 0\n ): { index: number; value: T | undefined } {\n let value: T | undefined;\n let index = findLastIndex(array, fn, start, stop);\n if (index !== -1) {\n value = removeAt(array, index);\n }\n return { index, value };\n }\n\n /**\n * Remove all occurrences of values which match a predicate.\n *\n * @param array - The array of interest.\n *\n * @param fn - The predicate function to apply to the values.\n *\n * @param start - The index of the first element in the range to be\n * searched, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * searched, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @returns The number of elements removed from the array.\n *\n * #### Notes\n * If `stop < start` the search will conceptually wrap at the end of\n * the array, however the array will be traversed front-to-back.\n *\n * #### Complexity\n * Linear.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * function isEven(value: number): boolean {\n * return value % 2 === 0;\n * }\n *\n * function isNegative(value: number): boolean {\n * return value < 0;\n * }\n *\n * let data = [0, 12, -13, -9, 23, 39, 14, -15, 12, 75];\n * ArrayExt.removeAllWhere(data, isEven); // 4\n * ArrayExt.removeAllWhere(data, isNegative, 0, 3); // 2\n * ```\n */\n export function removeAllWhere<T>(\n array: Array<T>,\n fn: (value: T, index: number) => boolean,\n start = 0,\n stop = -1\n ): number {\n let n = array.length;\n if (n === 0) {\n return 0;\n }\n if (start < 0) {\n start = Math.max(0, start + n);\n } else {\n start = Math.min(start, n - 1);\n }\n if (stop < 0) {\n stop = Math.max(0, stop + n);\n } else {\n stop = Math.min(stop, n - 1);\n }\n let count = 0;\n for (let i = 0; i < n; ++i) {\n if (start <= stop && i >= start && i <= stop && fn(array[i], i)) {\n count++;\n } else if (stop < start && (i <= stop || i >= start) && fn(array[i], i)) {\n count++;\n } else if (count > 0) {\n array[i - count] = array[i];\n }\n }\n if (count > 0) {\n array.length = n - count;\n }\n return count;\n }\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * Chain together several iterables.\n *\n * @deprecated\n *\n * @param objects - The iterable objects of interest.\n *\n * @returns An iterator which yields the values of the iterables\n * in the order in which they are supplied.\n *\n * #### Example\n * ```typescript\n * import { chain } from '@lumino/algorithm';\n *\n * let data1 = [1, 2, 3];\n * let data2 = [4, 5, 6];\n *\n * let stream = chain(data1, data2);\n *\n * Array.from(stream); // [1, 2, 3, 4, 5, 6]\n * ```\n */\nexport function* chain<T>(...objects: Iterable<T>[]): IterableIterator<T> {\n for (const object of objects) {\n yield* object;\n }\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * Create an empty iterator.\n *\n * @returns A new iterator which yields nothing.\n *\n * #### Example\n * ```typescript\n * import { empty } from '@lumino/algorithm';\n *\n * let stream = empty<number>();\n *\n * Array.from(stream); // []\n * ```\n */\n// eslint-disable-next-line require-yield\nexport function* empty<T>(): IterableIterator<T> {\n return;\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * Enumerate an iterable object.\n *\n * @param object - The iterable object of interest.\n *\n * @param start - The starting enum value. The default is `0`.\n *\n * @returns An iterator which yields the enumerated values.\n *\n * #### Example\n * ```typescript\n * import { enumerate } from '@lumino/algorithm';\n *\n * let data = ['foo', 'bar', 'baz'];\n *\n * let stream = enumerate(data, 1);\n *\n * Array.from(stream); // [[1, 'foo'], [2, 'bar'], [3, 'baz']]\n * ```\n */\nexport function* enumerate<T>(\n object: Iterable<T>,\n start = 0\n): IterableIterator<[number, T]> {\n for (const value of object) {\n yield [start++, value];\n }\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * Filter an iterable for values which pass a test.\n *\n * @param object - The iterable object of interest.\n *\n * @param fn - The predicate function to invoke for each value.\n *\n * @returns An iterator which yields the values which pass the test.\n *\n * #### Example\n * ```typescript\n * import { filter } from '@lumino/algorithm';\n *\n * let data = [1, 2, 3, 4, 5, 6];\n *\n * let stream = filter(data, value => value % 2 === 0);\n *\n * Array.from(stream); // [2, 4, 6]\n * ```\n */\nexport function* filter<T>(\n object: Iterable<T>,\n fn: (value: T, index: number) => boolean\n): IterableIterator<T> {\n let index = 0;\n for (const value of object) {\n if (fn(value, index++)) {\n yield value;\n }\n }\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * Find the first value in an iterable which matches a predicate.\n *\n * @param object - The iterable object to search.\n *\n * @param fn - The predicate function to apply to the values.\n *\n * @returns The first matching value, or `undefined` if no matching\n * value is found.\n *\n * #### Complexity\n * Linear.\n *\n * #### Example\n * ```typescript\n * import { find } from '@lumino/algorithm';\n *\n * interface IAnimal { species: string, name: string };\n *\n * function isCat(value: IAnimal): boolean {\n * return value.species === 'cat';\n * }\n *\n * let data: IAnimal[] = [\n * { species: 'dog', name: 'spot' },\n * { species: 'cat', name: 'fluffy' },\n * { species: 'alligator', name: 'pocho' }\n * ];\n *\n * find(data, isCat).name; // 'fluffy'\n * ```\n */\nexport function find<T>(\n object: Iterable<T>,\n fn: (value: T, index: number) => boolean\n): T | undefined {\n let index = 0;\n for (const value of object) {\n if (fn(value, index++)) {\n return value;\n }\n }\n return undefined;\n}\n\n/**\n * Find the index of the first value which matches a predicate.\n *\n * @param object - The iterable object to search.\n *\n * @param fn - The predicate function to apply to the values.\n *\n * @returns The index of the first matching value, or `-1` if no\n * matching value is found.\n *\n * #### Complexity\n * Linear.\n *\n * #### Example\n * ```typescript\n * import { findIndex } from '@lumino/algorithm';\n *\n * interface IAnimal { species: string, name: string };\n *\n * function isCat(value: IAnimal): boolean {\n * return value.species === 'cat';\n * }\n *\n * let data: IAnimal[] = [\n * { species: 'dog', name: 'spot' },\n * { species: 'cat', name: 'fluffy' },\n * { species: 'alligator', name: 'pocho' }\n * ];\n *\n * findIndex(data, isCat); // 1\n * ```\n */\nexport function findIndex<T>(\n object: Iterable<T>,\n fn: (value: T, index: number) => boolean\n): number {\n let index = 0;\n for (const value of object) {\n if (fn(value, index++)) {\n return index - 1;\n }\n }\n return -1;\n}\n\n/**\n * Find the minimum value in an iterable.\n *\n * @param object - The iterable object to search.\n *\n * @param fn - The 3-way comparison function to apply to the values.\n * It should return `< 0` if the first value is less than the second.\n * `0` if the values are equivalent, or `> 0` if the first value is\n * greater than the second.\n *\n * @returns The minimum value in the iterable. If multiple values are\n * equivalent to the minimum, the left-most value is returned. If\n * the iterable is empty, this returns `undefined`.\n *\n * #### Complexity\n * Linear.\n *\n * #### Example\n * ```typescript\n * import { min } from '@lumino/algorithm';\n *\n * function numberCmp(a: number, b: number): number {\n * return a - b;\n * }\n *\n * min([7, 4, 0, 3, 9, 4], numberCmp); // 0\n * ```\n */\nexport function min<T>(\n object: Iterable<T>,\n fn: (first: T, second: T) => number\n): T | undefined {\n let result: T | undefined = undefined;\n for (const value of object) {\n if (result === undefined) {\n result = value;\n continue;\n }\n if (fn(value, result) < 0) {\n result = value;\n }\n }\n return result;\n}\n\n/**\n * Find the maximum value in an iterable.\n *\n * @param object - The iterable object to search.\n *\n * @param fn - The 3-way comparison function to apply to the values.\n * It should return `< 0` if the first value is less than the second.\n * `0` if the values are equivalent, or `> 0` if the first value is\n * greater than the second.\n *\n * @returns The maximum value in the iterable. If multiple values are\n * equivalent to the maximum, the left-most value is returned. If\n * the iterable is empty, this returns `undefined`.\n *\n * #### Complexity\n * Linear.\n *\n * #### Example\n * ```typescript\n * import { max } from '@lumino/algorithm';\n *\n * function numberCmp(a: number, b: number): number {\n * return a - b;\n * }\n *\n * max([7, 4, 0, 3, 9, 4], numberCmp); // 9\n * ```\n */\nexport function max<T>(\n object: Iterable<T>,\n fn: (first: T, second: T) => number\n): T | undefined {\n let result: T | undefined = undefined;\n for (const value of object) {\n if (result === undefined) {\n result = value;\n continue;\n }\n if (fn(value, result) > 0) {\n result = value;\n }\n }\n return result;\n}\n\n/**\n * Find the minimum and maximum values in an iterable.\n *\n * @param object - The iterable object to search.\n *\n * @param fn - The 3-way comparison function to apply to the values.\n * It should return `< 0` if the first value is less than the second.\n * `0` if the values are equivalent, or `> 0` if the first value is\n * greater than the second.\n *\n * @returns A 2-tuple of the `[min, max]` values in the iterable. If\n * multiple values are equivalent, the left-most values are returned.\n * If the iterable is empty, this returns `undefined`.\n *\n * #### Complexity\n * Linear.\n *\n * #### Example\n * ```typescript\n * import { minmax } from '@lumino/algorithm';\n *\n * function numberCmp(a: number, b: number): number {\n * return a - b;\n * }\n *\n * minmax([7, 4, 0, 3, 9, 4], numberCmp); // [0, 9]\n * ```\n */\nexport function minmax<T>(\n object: Iterable<T>,\n fn: (first: T, second: T) => number\n): [T, T] | undefined {\n let empty = true;\n let vmin: T;\n let vmax: T;\n for (const value of object) {\n if (empty) {\n vmin = value;\n vmax = value;\n empty = false;\n } else if (fn(value, vmin!) < 0) {\n vmin = value;\n } else if (fn(value, vmax!) > 0) {\n vmax = value;\n }\n }\n return empty ? undefined : [vmin!, vmax!];\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * Create an array from an iterable of values.\n *\n * @deprecated\n *\n * @param object - The iterable object of interest.\n *\n * @returns A new array of values from the given object.\n *\n * #### Example\n * ```typescript\n * import { toArray } from '@lumino/algorithm';\n *\n * let stream = [1, 2, 3, 4, 5, 6][Symbol.iterator]();\n *\n * toArray(stream); // [1, 2, 3, 4, 5, 6];\n * ```\n */\nexport function toArray<T>(object: Iterable<T>): T[] {\n return Array.from(object);\n}\n\n/**\n * Create an object from an iterable of key/value pairs.\n *\n * @param object - The iterable object of interest.\n *\n * @returns A new object mapping keys to values.\n *\n * #### Example\n * ```typescript\n * import { toObject } from '@lumino/algorithm';\n *\n * let data: [string, number][] = [['one', 1], ['two', 2], ['three', 3]];\n *\n * toObject(data); // { one: 1, two: 2, three: 3 }\n * ```\n */\nexport function toObject<T>(object: Iterable<[string, T]>): {\n [key: string]: T;\n} {\n const result: { [key: string]: T } = {};\n for (const [key, value] of object) {\n result[key] = value;\n }\n return result;\n}\n\n/**\n * Invoke a function for each value in an iterable.\n *\n * @deprecated\n *\n * @param object - The iterable object of interest.\n *\n * @param fn - The callback function to invoke for each value.\n *\n * #### Notes\n * Iteration can be terminated early by returning `false` from the\n * callback function.\n *\n * #### Complexity\n * Linear.\n *\n * #### Example\n * ```typescript\n * import { each } from '@lumino/algorithm';\n *\n * let data = [5, 7, 0, -2, 9];\n *\n * each(data, value => { console.log(value); });\n * ```\n */\nexport function each<T>(\n object: Iterable<T>,\n fn: (value: T, index: number) => boolean | void\n): void {\n let index = 0;\n for (const value of object) {\n if (false === fn(value, index++)) {\n return;\n }\n }\n}\n\n/**\n * Test whether all values in an iterable satisfy a predicate.\n *\n * @param object - The iterable object of interest.\n *\n * @param fn - The predicate function to invoke for each value.\n *\n * @returns `true` if all values pass the test, `false` otherwise.\n *\n * #### Notes\n * Iteration terminates on the first `false` predicate result.\n *\n * #### Complexity\n * Linear.\n *\n * #### Example\n * ```typescript\n * import { every } from '@lumino/algorithm';\n *\n * let data = [5, 7, 1];\n *\n * every(data, value => value % 2 === 0); // false\n * every(data, value => value % 2 === 1); // true\n * ```\n */\nexport function every<T>(\n object: Iterable<T>,\n fn: (value: T, index: number) => boolean\n): boolean {\n let index = 0;\n for (const value of object) {\n if (false === fn(value, index++)) {\n return false;\n }\n }\n return true;\n}\n\n/**\n * Test whether any value in an iterable satisfies a predicate.\n *\n * @param object - The iterable object of interest.\n *\n * @param fn - The predicate function to invoke for each value.\n *\n * @returns `true` if any value passes the test, `false` otherwise.\n *\n * #### Notes\n * Iteration terminates on the first `true` predicate result.\n *\n * #### Complexity\n * Linear.\n *\n * #### Example\n * ```typescript\n * import { some } from '@lumino/algorithm';\n *\n * let data = [5, 7, 1];\n *\n * some(data, value => value === 7); // true\n * some(data, value => value === 3); // false\n * ```\n */\nexport function some<T>(\n object: Iterable<T>,\n fn: (value: T, index: number) => boolean\n): boolean {\n let index = 0;\n for (const value of object) {\n if (fn(value, index++)) {\n return true;\n }\n }\n return false;\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n/**\n * Transform the values of an iterable with a mapping function.\n *\n * @param object - The iterable object of interest.\n *\n * @param fn - The mapping function to invoke for each value.\n *\n * @returns An iterator which yields the transformed values.\n *\n * #### Example\n * ```typescript\n * import { map } from '@lumino/algorithm';\n *\n * let data = [1, 2, 3];\n *\n * let stream = map(data, value => value * 2);\n *\n * Array.from(stream); // [2, 4, 6]\n * ```\n */\nexport function* map<T, U>(\n object: Iterable<T>,\n fn: (value: T, index: number) => U\n): IterableIterator<U> {\n let index = 0;\n for (const value of object) {\n yield fn(value, index++);\n }\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n/**\n * Create an iterator of evenly spaced values.\n *\n * @param start - The starting value for the range, inclusive.\n *\n * @param stop - The stopping value for the range, exclusive.\n *\n * @param step - The distance between each value.\n *\n * @returns An iterator which produces evenly spaced values.\n *\n * #### Notes\n * In the single argument form of `range(stop)`, `start` defaults to\n * `0` and `step` defaults to `1`.\n *\n * In the two argument form of `range(start, stop)`, `step` defaults\n * to `1`.\n *\n * #### Example\n * ```typescript\n * import { range } from '@lumino/algorithm';\n *\n * let stream = range(2, 4);\n *\n * Array.from(stream); // [2, 3]\n * ```\n */\nexport function* range(\n start: number,\n stop?: number,\n step?: number\n): IterableIterator<number> {\n if (stop === undefined) {\n stop = start;\n start = 0;\n step = 1;\n } else if (step === undefined) {\n step = 1;\n }\n const length = Private.rangeLength(start, stop, step);\n for (let index = 0; index < length; index++) {\n yield start + step * index;\n }\n}\n\n/**\n * The namespace for the module implementation details.\n */\nnamespace Private {\n /**\n * Compute the effective length of a range.\n *\n * @param start - The starting value for the range, inclusive.\n *\n * @param stop - The stopping value for the range, exclusive.\n *\n * @param step - The distance between each value.\n *\n * @returns The number of steps need to traverse the range.\n */\n export function rangeLength(\n start: number,\n stop: number,\n step: number\n ): number {\n if (step === 0) {\n return Infinity;\n }\n if (start > stop && step > 0) {\n return 0;\n }\n if (start < stop && step < 0) {\n return 0;\n }\n return Math.ceil((stop - start) / step);\n }\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * Summarize all values in an iterable using a reducer function.\n *\n * @param object - The iterable object of interest.\n *\n * @param fn - The reducer function to invoke for each value.\n *\n * @param initial - The initial value to start accumulation.\n *\n * @returns The final accumulated value.\n *\n * #### Notes\n * The `reduce` function follows the conventions of `Array#reduce`.\n *\n * If the iterator is empty, an initial value is required. That value\n * will be used as the return value. If no initial value is provided,\n * an error will be thrown.\n *\n * If the iterator contains a single item and no initial value is\n * provided, the single item is used as the return value.\n *\n * Otherwise, the reducer is invoked for each element in the iterable.\n * If an initial value is not provided, the first element will be used\n * as the initial accumulated value.\n *\n * #### Complexity\n * Linear.\n *\n * #### Example\n * ```typescript\n * import { reduce } from '@lumino/algorithm';\n *\n * let data = [1, 2, 3, 4, 5];\n *\n * let sum = reduce(data, (a, value) => a + value); // 15\n * ```\n */\nexport function reduce<T>(\n object: Iterable<T>,\n fn: (accumulator: T, value: T, index: number) => T\n): T;\nexport function reduce<T, U>(\n object: Iterable<T>,\n fn: (accumulator: U, value: T, index: number) => U,\n initial: U\n): U;\nexport function reduce<T>(\n object: Iterable<T>,\n fn: (accumulator: any, value: T, index: number) => any,\n initial?: unknown\n): any {\n // Setup the iterator and fetch the first value.\n const it = object[Symbol.iterator]();\n let index = 0;\n let first = it.next();\n\n // An empty iterator and no initial value is an error.\n if (first.done && initial === undefined) {\n throw new TypeError('Reduce of empty iterable with no initial value.');\n }\n\n // If the iterator is empty, return the initial value.\n if (first.done) {\n return initial;\n }\n\n // If the iterator has a single item and no initial value, the\n // reducer is not invoked and the first item is the return value.\n let second = it.next();\n if (second.done && initial === undefined) {\n return first.value;\n }\n\n // If iterator has a single item and an initial value is provided,\n // the reducer is invoked and that result is the return value.\n if (second.done) {\n return fn(initial, first.value, index++);\n }\n\n // Setup the initial accumlated value.\n let accumulator: any;\n if (initial === undefined) {\n accumulator = fn(first.value, second.value, index++);\n } else {\n accumulator = fn(fn(initial, first.value, index++), second.value, index++);\n }\n\n // Iterate the rest of the values, updating the accumulator.\n let next: IteratorResult<T>;\n while (!(next = it.next()).done) {\n accumulator = fn(accumulator, next.value, index++);\n }\n\n // Return the final accumulated value.\n return accumulator;\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * Create an iterator which repeats a value a number of times.\n *\n * @deprecated\n *\n * @param value - The value to repeat.\n *\n * @param count - The number of times to repeat the value.\n *\n * @returns A new iterator which repeats the specified value.\n *\n * #### Example\n * ```typescript\n * import { repeat } from '@lumino/algorithm';\n *\n * let stream = repeat(7, 3);\n *\n * Array.from(stream); // [7, 7, 7]\n * ```\n */\nexport function* repeat<T>(value: T, count: number): IterableIterator<T> {\n while (0 < count--) {\n yield value;\n }\n}\n\n/**\n * Create an iterator which yields a value a single time.\n *\n * @deprecated\n *\n * @param value - The value to wrap in an iterator.\n *\n * @returns A new iterator which yields the value a single time.\n *\n * #### Example\n * ```typescript\n * import { once } from '@lumino/algorithm';\n *\n * let stream = once(7);\n *\n * Array.from(stream); // [7]\n * ```\n */\nexport function* once<T>(value: T): IterableIterator<T> {\n yield value;\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * An object which can produce a reverse iterator over its values.\n */\nexport interface IRetroable<T> {\n /**\n * Get a reverse iterator over the object's values.\n *\n * @returns An iterator which yields the object's values in reverse.\n */\n retro(): IterableIterator<T>;\n}\n\n/**\n * Create an iterator for a retroable object.\n *\n * @param object - The retroable or array-like object of interest.\n *\n * @returns An iterator which traverses the object's values in reverse.\n *\n * #### Example\n * ```typescript\n * import { retro } from '@lumino/algorithm';\n *\n * let data = [1, 2, 3, 4, 5, 6];\n *\n * let stream = retro(data);\n *\n * Array.from(stream); // [6, 5, 4, 3, 2, 1]\n * ```\n */\nexport function* retro<T>(\n object: IRetroable<T> | ArrayLike<T>\n): IterableIterator<T> {\n if (typeof (object as IRetroable<T>).retro === 'function') {\n yield* (object as IRetroable<T>).retro();\n } else {\n for (let index = (object as ArrayLike<T>).length - 1; index > -1; index--) {\n yield (object as ArrayLike<T>)[index];\n }\n }\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * Topologically sort an iterable of edges.\n *\n * @param edges - The iterable object of edges to sort.\n * An edge is represented as a 2-tuple of `[fromNode, toNode]`.\n *\n * @returns The topologically sorted array of nodes.\n *\n * #### Notes\n * If a cycle is present in the graph, the cycle will be ignored and\n * the return value will be only approximately sorted.\n *\n * #### Example\n * ```typescript\n * import { topologicSort } from '@lumino/algorithm';\n *\n * let data = [\n * ['d', 'e'],\n * ['c', 'd'],\n * ['a', 'b'],\n * ['b', 'c']\n * ];\n *\n * topologicSort(data); // ['a', 'b', 'c', 'd', 'e']\n * ```\n */\nexport function topologicSort<T>(edges: Iterable<[T, T]>): T[] {\n // Setup the shared sorting state.\n let sorted: T[] = [];\n let visited = new Set<T>();\n let graph = new Map<T, T[]>();\n\n // Add the edges to the graph.\n for (const edge of edges) {\n addEdge(edge);\n }\n\n // Visit each node in the graph.\n for (const [k] of graph) {\n visit(k);\n }\n\n // Return the sorted results.\n return sorted;\n\n // Add an edge to the graph.\n function addEdge(edge: [T, T]): void {\n let [fromNode, toNode] = edge;\n let children = graph.get(toNode);\n if (children) {\n children.push(fromNode);\n } else {\n graph.set(toNode, [fromNode]);\n }\n }\n\n // Recursively visit the node.\n function visit(node: T): void {\n if (visited.has(node)) {\n return;\n }\n visited.add(node);\n let children = graph.get(node);\n if (children) {\n for (const child of children) {\n visit(child);\n }\n }\n sorted.push(node);\n }\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * Iterate over an iterable using a stepped increment.\n *\n * @param object - The iterable object of interest.\n *\n * @param step - The distance to step on each iteration. A value\n * of less than `1` will behave the same as a value of `1`.\n *\n * @returns An iterator which traverses the iterable step-wise.\n *\n * #### Example\n * ```typescript\n * import { stride } from '@lumino/algorithm';\n *\n * let data = [1, 2, 3, 4, 5, 6];\n *\n * let stream = stride(data, 2);\n *\n * Array.from(stream); // [1, 3, 5];\n * ```\n */\nexport function* stride<T>(\n object: Iterable<T>,\n step: number\n): IterableIterator<T> {\n let count = 0;\n for (const value of object) {\n if (0 === count++ % step) {\n yield value;\n }\n }\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * The namespace for string-specific algorithms.\n */\nexport namespace StringExt {\n /**\n * Find the indices of characters in a source text.\n *\n * @param source - The source text which should be searched.\n *\n * @param query - The characters to locate in the source text.\n *\n * @param start - The index to start the search.\n *\n * @returns The matched indices, or `null` if there is no match.\n *\n * #### Complexity\n * Linear on `sourceText`.\n *\n * #### Notes\n * In order for there to be a match, all of the characters in `query`\n * **must** appear in `source` in the order given by `query`.\n *\n * Characters are matched using strict `===` equality.\n */\n export function findIndices(\n source: string,\n query: string,\n start = 0\n ): number[] | null {\n let indices = new Array<number>(query.length);\n for (let i = 0, j = start, n = query.length; i < n; ++i, ++j) {\n j = source.indexOf(query[i], j);\n if (j === -1) {\n return null;\n }\n indices[i] = j;\n }\n return indices;\n }\n\n /**\n * The result of a string match function.\n */\n export interface IMatchResult {\n /**\n * A score which indicates the strength of the match.\n *\n * The documentation of a given match function should specify\n * whether a lower or higher score is a stronger match.\n */\n score: number;\n\n /**\n * The indices of the matched characters in the source text.\n *\n * The indices will appear in increasing order.\n */\n indices: number[];\n }\n\n /**\n * A string matcher which uses a sum-of-squares algorithm.\n *\n * @param source - The source text which should be searched.\n *\n * @param query - The characters to locate in the source text.\n *\n * @param start - The index to start the search.\n *\n * @returns The match result, or `null` if there is no match.\n * A lower `score` represents a stronger match.\n *\n * #### Complexity\n * Linear on `sourceText`.\n *\n * #### Notes\n * This scoring algorithm uses a sum-of-squares approach to determine\n * the score. In order for there to be a match, all of the characters\n * in `query` **must** appear in `source` in order. The index of each\n * matching character is squared and added to the score. This means\n * that early and consecutive character matches are preferred, while\n * late matches are heavily penalized.\n */\n export function matchSumOfSquares(\n source: string,\n query: string,\n start = 0\n ): IMatchResult | null {\n let indices = findIndices(source, query, start);\n if (!indices) {\n return null;\n }\n let score = 0;\n for (let i = 0, n = indices.length; i < n; ++i) {\n let j = indices[i] - start;\n score += j * j;\n }\n return { score, indices };\n }\n\n /**\n * A string matcher which uses a sum-of-deltas algorithm.\n *\n * @param source - The source text which should be searched.\n *\n * @param query - The characters to locate in the source text.\n *\n * @param start - The index to start the search.\n *\n * @returns The match result, or `null` if there is no match.\n * A lower `score` represents a stronger match.\n *\n * #### Complexity\n * Linear on `sourceText`.\n *\n * #### Notes\n * This scoring algorithm uses a sum-of-deltas approach to determine\n * the score. In order for there to be a match, all of the characters\n * in `query` **must** appear in `source` in order. The delta between\n * the indices are summed to create the score. This means that groups\n * of matched characters are preferred, while fragmented matches are\n * penalized.\n */\n export function matchSumOfDeltas(\n source: string,\n query: string,\n start = 0\n ): IMatchResult | null {\n let indices = findIndices(source, query, start);\n if (!indices) {\n return null;\n }\n let score = 0;\n let last = start - 1;\n for (let i = 0, n = indices.length; i < n; ++i) {\n let j = indices[i];\n score += j - last - 1;\n last = j;\n }\n return { score, indices };\n }\n\n /**\n * Highlight the matched characters of a source text.\n *\n * @param source - The text which should be highlighted.\n *\n * @param indices - The indices of the matched characters. They must\n * appear in increasing order and must be in bounds of the source.\n *\n * @param fn - The function to apply to the matched chunks.\n *\n * @returns An array of unmatched and highlighted chunks.\n */\n export function highlight<T>(\n source: string,\n indices: ReadonlyArray<number>,\n fn: (chunk: string) => T\n ): Array<string | T> {\n // Set up the result array.\n let result: Array<string | T> = [];\n\n // Set up the counter variables.\n let k = 0;\n let last = 0;\n let n = indices.length;\n\n // Iterator over each index.\n while (k < n) {\n // Set up the chunk indices.\n let i = indices[k];\n let j = indices[k];\n\n // Advance the right chunk index until it's non-contiguous.\n while (++k < n && indices[k] === j + 1) {\n j++;\n }\n\n // Extract the unmatched text.\n if (last < i) {\n result.push(source.slice(last, i));\n }\n\n // Extract and highlight the matched text.\n if (i < j + 1) {\n result.push(fn(source.slice(i, j + 1)));\n }\n\n // Update the last visited index.\n last = j + 1;\n }\n\n // Extract any remaining unmatched text.\n if (last < source.length) {\n result.push(source.slice(last));\n }\n\n // Return the highlighted result.\n return result;\n }\n\n /**\n * A 3-way string comparison function.\n *\n * @param a - The first string of interest.\n *\n * @param b - The second string of interest.\n *\n * @returns `-1` if `a < b`, else `1` if `a > b`, else `0`.\n */\n export function cmp(a: string, b: string): number {\n return a < b ? -1 : a > b ? 1 : 0;\n }\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * Take a fixed number of items from an iterable.\n *\n * @param object - The iterable object of interest.\n *\n * @param count - The number of items to take from the iterable.\n *\n * @returns An iterator which yields the specified number of items\n * from the source iterable.\n *\n * #### Notes\n * The returned iterator will exhaust early if the source iterable\n * contains an insufficient number of items.\n *\n * #### Example\n * ```typescript\n * import { take } from '@lumino/algorithm';\n *\n * let stream = take([5, 4, 3, 2, 1, 0, -1], 3);\n *\n * Array.from(stream); // [5, 4, 3]\n * ```\n */\nexport function* take<T>(\n object: Iterable<T>,\n count: number\n): IterableIterator<T> {\n if (count < 1) {\n return;\n }\n const it = object[Symbol.iterator]();\n let item: IteratorResult<T>;\n while (0 < count-- && !(item = it.next()).done) {\n yield item.value;\n }\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\nimport { every } from './iter';\n\n/**\n * Iterate several iterables in lockstep.\n *\n * @param objects - The iterable objects of interest.\n *\n * @returns An iterator which yields successive tuples of values where\n * each value is taken in turn from the provided iterables. It will\n * be as long as the shortest provided iterable.\n *\n * #### Example\n * ```typescript\n * import { zip } from '@lumino/algorithm';\n *\n * let data1 = [1, 2, 3];\n * let data2 = [4, 5, 6];\n *\n * let stream = zip(data1, data2);\n *\n * Array.from(stream); // [[1, 4], [2, 5], [3, 6]]\n * ```\n */\nexport function* zip<T>(...objects: Iterable<T>[]): IterableIterator<T[]> {\n const iters = objects.map(obj => obj[Symbol.iterator]());\n let tuple = iters.map(it => it.next());\n for (; every(tuple, item => !item.done); tuple = iters.map(it => it.next())) {\n yield tuple.map(item => item.value);\n }\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * A type alias for a JSON primitive.\n */\nexport type JSONPrimitive = boolean | number | string | null;\n\n/**\n * A type alias for a JSON value.\n */\nexport type JSONValue = JSONPrimitive | JSONObject | JSONArray;\n\n/**\n * A type definition for a JSON object.\n */\nexport interface JSONObject {\n [key: string]: JSONValue;\n}\n\n/**\n * A type definition for a JSON array.\n */\nexport interface JSONArray extends Array<JSONValue> {}\n\n/**\n * A type definition for a readonly JSON object.\n */\nexport interface ReadonlyJSONObject {\n readonly [key: string]: ReadonlyJSONValue;\n}\n\n/**\n * A type definition for a readonly JSON array.\n */\nexport interface ReadonlyJSONArray extends ReadonlyArray<ReadonlyJSONValue> {}\n\n/**\n * A type alias for a readonly JSON value.\n */\nexport type ReadonlyJSONValue =\n | JSONPrimitive\n | ReadonlyJSONObject\n | ReadonlyJSONArray;\n\n/**\n * A type alias for a partial JSON value.\n *\n * Note: Partial here means that JSON object attributes can be `undefined`.\n */\nexport type PartialJSONValue =\n | JSONPrimitive\n | PartialJSONObject\n | PartialJSONArray;\n\n/**\n * A type definition for a partial JSON object.\n *\n * Note: Partial here means that the JSON object attributes can be `undefined`.\n */\nexport interface PartialJSONObject {\n [key: string]: PartialJSONValue | undefined;\n}\n\n/**\n * A type definition for a partial JSON array.\n *\n * Note: Partial here means that JSON object attributes can be `undefined`.\n */\nexport interface PartialJSONArray extends Array<PartialJSONValue> {}\n\n/**\n * A type definition for a readonly partial JSON object.\n *\n * Note: Partial here means that JSON object attributes can be `undefined`.\n */\nexport interface ReadonlyPartialJSONObject {\n readonly [key: string]: ReadonlyPartialJSONValue | undefined;\n}\n\n/**\n * A type definition for a readonly partial JSON array.\n *\n * Note: Partial here means that JSON object attributes can be `undefined`.\n */\nexport interface ReadonlyPartialJSONArray\n extends ReadonlyArray<ReadonlyPartialJSONValue> {}\n\n/**\n * A type alias for a readonly partial JSON value.\n *\n * Note: Partial here means that JSON object attributes can be `undefined`.\n */\nexport type ReadonlyPartialJSONValue =\n | JSONPrimitive\n | ReadonlyPartialJSONObject\n | ReadonlyPartialJSONArray;\n\n/**\n * The namespace for JSON-specific functions.\n */\nexport namespace JSONExt {\n /**\n * A shared frozen empty JSONObject\n */\n export const emptyObject = Object.freeze({}) as ReadonlyJSONObject;\n\n /**\n * A shared frozen empty JSONArray\n */\n export const emptyArray = Object.freeze([]) as ReadonlyJSONArray;\n\n /**\n * Test whether a JSON value is a primitive.\n *\n * @param value - The JSON value of interest.\n *\n * @returns `true` if the value is a primitive,`false` otherwise.\n */\n export function isPrimitive(\n value: ReadonlyPartialJSONValue\n ): value is JSONPrimitive {\n return (\n value === null ||\n typeof value === 'boolean' ||\n typeof value === 'number' ||\n typeof value === 'string'\n );\n }\n\n /**\n * Test whether a JSON value is an array.\n *\n * @param value - The JSON value of interest.\n *\n * @returns `true` if the value is a an array, `false` otherwise.\n */\n export function isArray(value: JSONValue): value is JSONArray;\n export function isArray(value: ReadonlyJSONValue): value is ReadonlyJSONArray;\n export function isArray(value: PartialJSONValue): value is PartialJSONArray;\n export function isArray(\n value: ReadonlyPartialJSONValue\n ): value is ReadonlyPartialJSONArray;\n export function isArray(value: ReadonlyPartialJSONValue): boolean {\n return Array.isArray(value);\n }\n\n /**\n * Test whether a JSON value is an object.\n *\n * @param value - The JSON value of interest.\n *\n * @returns `true` if the value is a an object, `false` otherwise.\n */\n export function isObject(value: JSONValue): value is JSONObject;\n export function isObject(\n value: ReadonlyJSONValue\n ): value is ReadonlyJSONObject;\n export function isObject(value: PartialJSONValue): value is PartialJSONObject;\n export function isObject(\n value: ReadonlyPartialJSONValue\n ): value is ReadonlyPartialJSONObject;\n export function isObject(value: ReadonlyPartialJSONValue): boolean {\n return !isPrimitive(value) && !isArray(value);\n }\n\n /**\n * Compare two JSON values for deep equality.\n *\n * @param first - The first JSON value of interest.\n *\n * @param second - The second JSON value of interest.\n *\n * @returns `true` if the values are equivalent, `false` otherwise.\n */\n export function deepEqual(\n first: ReadonlyPartialJSONValue,\n second: ReadonlyPartialJSONValue\n ): boolean {\n // Check referential and primitive equality first.\n if (first === second) {\n return true;\n }\n\n // If one is a primitive, the `===` check ruled out the other.\n if (isPrimitive(first) || isPrimitive(second)) {\n return false;\n }\n\n // Test whether they are arrays.\n let a1 = isArray(first);\n let a2 = isArray(second);\n\n // Bail if the types are different.\n if (a1 !== a2) {\n return false;\n }\n\n // If they are both arrays, compare them.\n if (a1 && a2) {\n return deepArrayEqual(\n first as ReadonlyPartialJSONArray,\n second as ReadonlyPartialJSONArray\n );\n }\n\n // At this point, they must both be objects.\n return deepObjectEqual(\n first as ReadonlyPartialJSONObject,\n second as ReadonlyPartialJSONObject\n );\n }\n\n /**\n * Create a deep copy of a JSON value.\n *\n * @param value - The JSON value to copy.\n *\n * @returns A deep copy of the given JSON value.\n */\n export function deepCopy<T extends ReadonlyPartialJSONValue>(value: T): T {\n // Do nothing for primitive values.\n if (isPrimitive(value)) {\n return value;\n }\n\n // Deep copy an array.\n if (isArray(value)) {\n return deepArrayCopy(value);\n }\n\n // Deep copy an object.\n return deepObjectCopy(value);\n }\n\n /**\n * Compare two JSON arrays for deep equality.\n */\n function deepArrayEqual(\n first: ReadonlyPartialJSONArray,\n second: ReadonlyPartialJSONArray\n ): boolean {\n // Check referential equality first.\n if (first === second) {\n return true;\n }\n\n // Test the arrays for equal length.\n if (first.length !== second.length) {\n return false;\n }\n\n // Compare the values for equality.\n for (let i = 0, n = first.length; i < n; ++i) {\n if (!deepEqual(first[i], second[i])) {\n return false;\n }\n }\n\n // At this point, the arrays are equal.\n return true;\n }\n\n /**\n * Compare two JSON objects for deep equality.\n */\n function deepObjectEqual(\n first: ReadonlyPartialJSONObject,\n second: ReadonlyPartialJSONObject\n ): boolean {\n // Check referential equality first.\n if (first === second) {\n return true;\n }\n\n // Check for the first object's keys in the second object.\n for (let key in first) {\n if (first[key] !== undefined && !(key in second)) {\n return false;\n }\n }\n\n // Check for the second object's keys in the first object.\n for (let key in second) {\n if (second[key] !== undefined && !(key in first)) {\n return false;\n }\n }\n\n // Compare the values for equality.\n for (let key in first) {\n // Get the values.\n let firstValue = first[key];\n let secondValue = second[key];\n\n // If both are undefined, ignore the key.\n if (firstValue === undefined && secondValue === undefined) {\n continue;\n }\n\n // If only one value is undefined, the objects are not equal.\n if (firstValue === undefined || secondValue === undefined) {\n return false;\n }\n\n // Compare the values.\n if (!deepEqual(firstValue, secondValue)) {\n return false;\n }\n }\n\n // At this point, the objects are equal.\n return true;\n }\n\n /**\n * Create a deep copy of a JSON array.\n */\n function deepArrayCopy(value: any): any {\n let result = new Array<any>(value.length);\n for (let i = 0, n = value.length; i < n; ++i) {\n result[i] = deepCopy(value[i]);\n }\n return result;\n }\n\n /**\n * Create a deep copy of a JSON object.\n */\n function deepObjectCopy(value: any): any {\n let result: any = {};\n for (let key in value) {\n // Ignore undefined values.\n let subvalue = value[key];\n if (subvalue === undefined) {\n continue;\n }\n result[key] = deepCopy(subvalue);\n }\n return result;\n }\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * An object which stores MIME data for general application use.\n *\n * #### Notes\n * This class does not attempt to enforce \"correctness\" of MIME types\n * and their associated data. Since this class is designed to transfer\n * arbitrary data and objects within the same application, it assumes\n * that the user provides correct and accurate data.\n */\nexport class MimeData {\n /**\n * Get an array of the MIME types contained within the dataset.\n *\n * @returns A new array of the MIME types, in order of insertion.\n */\n types(): string[] {\n return this._types.slice();\n }\n\n /**\n * Test whether the dataset has an entry for the given type.\n *\n * @param mime - The MIME type of interest.\n *\n * @returns `true` if the dataset contains a value for the given\n * MIME type, `false` otherwise.\n */\n hasData(mime: string): boolean {\n return this._types.indexOf(mime) !== -1;\n }\n\n /**\n * Get the data value for the given MIME type.\n *\n * @param mime - The MIME type of interest.\n *\n * @returns The value for the given MIME type, or `undefined` if\n * the dataset does not contain a value for the type.\n */\n getData(mime: string): any | undefined {\n let i = this._types.indexOf(mime);\n return i !== -1 ? this._values[i] : undefined;\n }\n\n /**\n * Set the data value for the given MIME type.\n *\n * @param mime - The MIME type of interest.\n *\n * @param data - The data value for the given MIME type.\n *\n * #### Notes\n * This will overwrite any previous entry for the MIME type.\n */\n setData(mime: string, data: unknown): void {\n this.clearData(mime);\n this._types.push(mime);\n this._values.push(data);\n }\n\n /**\n * Remove the data entry for the given MIME type.\n *\n * @param mime - The MIME type of interest.\n *\n * #### Notes\n * This is a no-op if there is no entry for the given MIME type.\n */\n clearData(mime: string): void {\n let i = this._types.indexOf(mime);\n if (i !== -1) {\n this._types.splice(i, 1);\n this._values.splice(i, 1);\n }\n }\n\n /**\n * Remove all data entries from the dataset.\n */\n clear(): void {\n this._types.length = 0;\n this._values.length = 0;\n }\n\n private _types: string[] = [];\n private _values: any[] = [];\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\nimport { topologicSort } from '@lumino/algorithm';\n\nimport { Token } from './token';\n\n/**\n * A user-defined application plugin.\n *\n * @typeParam T - The type for the application.\n *\n * @typeParam U - The service type, if the plugin `provides` one.\n *\n * #### Notes\n * Plugins are the foundation for building an extensible application.\n *\n * Plugins consume and provide \"services\", which are nothing more than\n * concrete implementations of interfaces and/or abstract types.\n *\n * Unlike regular imports and exports, which tie the service consumer\n * to a particular implementation of the service, plugins decouple the\n * service producer from the service consumer, allowing an application\n * to be easily customized by third parties in a type-safe fashion.\n */\nexport interface IPlugin<T, U> {\n /**\n * The human readable ID of the plugin.\n *\n * #### Notes\n * This must be unique within an application.\n */\n id: string;\n\n /**\n * Plugin description.\n *\n * #### Notes\n * This can be used to provide user documentation on the feature\n * brought by a plugin.\n */\n description?: string;\n\n /**\n * Whether the plugin should be activated on application start or waiting for being\n * required. If the value is 'defer' then the plugin should be activated only after\n * the application is started.\n *\n * #### Notes\n * The default is `false`.\n */\n autoStart?: boolean | 'defer';\n\n /**\n * The types of required services for the plugin, if any.\n *\n * #### Notes\n * These tokens correspond to the services that are required by\n * the plugin for correct operation.\n *\n * When the plugin is activated, a concrete instance of each type\n * will be passed to the `activate()` function, in the order they\n * are specified in the `requires` array.\n */\n requires?: Token<any>[];\n\n /**\n * The types of optional services for the plugin, if any.\n *\n * #### Notes\n * These tokens correspond to the services that can be used by the\n * plugin if available, but are not necessarily required.\n *\n * The optional services will be passed to the `activate()` function\n * following all required services. If an optional service cannot be\n * resolved, `null` will be passed in its place.\n */\n optional?: Token<any>[];\n\n /**\n * The type of service provided by the plugin, if any.\n *\n * #### Notes\n * This token corresponds to the service exported by the plugin.\n *\n * When the plugin is activated, the return value of `activate()`\n * is used as the concrete instance of the type.\n */\n provides?: Token<U> | null;\n\n /**\n * A function invoked to activate the plugin.\n *\n * @param app - The application provided by {@link PluginRegistry.application} .\n *\n * @param args - The services specified by the `requires` property.\n *\n * @returns The provided service, or a promise to the service.\n *\n * #### Notes\n * This function will be called whenever the plugin is manually\n * activated, or when another plugin being activated requires\n * the service it provides.\n *\n * This function will not be called unless all of its required\n * services can be fulfilled.\n */\n activate: (app: T, ...args: any[]) => U | Promise<U>;\n\n /**\n * A function invoked to deactivate the plugin.\n *\n * @param app - The application {@link PluginRegistry.application} .\n *\n * @param args - The services specified by the `requires` property.\n */\n deactivate?: ((app: T, ...args: any[]) => void | Promise<void>) | null;\n}\n\n/**\n * Plugin registry.\n */\nexport class PluginRegistry<T = any> {\n constructor(options: PluginRegistry.IOptions = {}) {\n if (options.validatePlugin) {\n console.info(\n 'Plugins may be rejected by the custom validation plugin method.'\n );\n this._validatePlugin = options.validatePlugin;\n }\n }\n\n /**\n * The application object.\n *\n * It will be provided as first argument to the\n * plugins activation and deactivation functions.\n *\n * It can only be set once.\n *\n * By default, it is `null`.\n */\n get application(): T {\n return this._application;\n }\n set application(v: T) {\n if (this._application !== null) {\n throw Error(\n 'PluginRegistry.application is already set. It cannot be overridden.'\n );\n }\n\n this._application = v;\n }\n\n /**\n * The list of all the deferred plugins.\n */\n get deferredPlugins(): string[] {\n return Array.from(this._plugins)\n .filter(([id, plugin]) => plugin.autoStart === 'defer')\n .map(([id, plugin]) => id);\n }\n\n /**\n * Get a plugin description.\n *\n * @param id - The ID of the plugin of interest.\n *\n * @returns The plugin description.\n */\n getPluginDescription(id: string): string {\n return this._plugins.get(id)?.description ?? '';\n }\n\n /**\n * Test whether a plugin is registered with the application.\n *\n * @param id - The ID of the plugin of interest.\n *\n * @returns `true` if the plugin is registered, `false` otherwise.\n */\n hasPlugin(id: string): boolean {\n return this._plugins.has(id);\n }\n\n /**\n * Test whether a plugin is activated with the application.\n *\n * @param id - The ID of the plugin of interest.\n *\n * @returns `true` if the plugin is activated, `false` otherwise.\n */\n isPluginActivated(id: string): boolean {\n return this._plugins.get(id)?.activated ?? false;\n }\n\n /**\n * List the IDs of the plugins registered with the application.\n *\n * @returns A new array of the registered plugin IDs.\n */\n listPlugins(): string[] {\n return Array.from(this._plugins.keys());\n }\n\n /**\n * Register a plugin with the application.\n *\n * @param plugin - The plugin to register.\n *\n * #### Notes\n * An error will be thrown if a plugin with the same ID is already\n * registered, or if the plugin has a circular dependency.\n *\n * If the plugin provides a service which has already been provided\n * by another plugin, the new service will override the old service.\n */\n registerPlugin(plugin: IPlugin<T, any>): void {\n // Throw an error if the plugin ID is already registered.\n if (this._plugins.has(plugin.id)) {\n throw new TypeError(`Plugin '${plugin.id}' is already registered.`);\n }\n\n if (!this._validatePlugin(plugin)) {\n throw new Error(`Plugin '${plugin.id}' is not valid.`);\n }\n\n // Create the normalized plugin data.\n const data = Private.createPluginData(plugin);\n\n // Ensure the plugin does not cause a cyclic dependency.\n Private.ensureNoCycle(data, this._plugins, this._services);\n\n // Add the service token to the service map.\n if (data.provides) {\n this._services.set(data.provides, data.id);\n }\n\n // Add the plugin to the plugin map.\n this._plugins.set(data.id, data);\n }\n\n /**\n * Register multiple plugins with the application.\n *\n * @param plugins - The plugins to register.\n *\n * #### Notes\n * This calls `registerPlugin()` for each of the given plugins.\n */\n registerPlugins(plugins: IPlugin<T, any>[]): void {\n for (const plugin of plugins) {\n this.registerPlugin(plugin);\n }\n }\n\n /**\n * Deregister a plugin with the application.\n *\n * @param id - The ID of the plugin of interest.\n *\n * @param force - Whether to deregister the plugin even if it is active.\n */\n deregisterPlugin(id: string, force?: boolean): void {\n const plugin = this._plugins.get(id);\n if (!plugin) {\n return;\n }\n\n if (plugin.activated && !force) {\n throw new Error(`Plugin '${id}' is still active.`);\n }\n\n this._plugins.delete(id);\n }\n\n /**\n * Activate the plugin with the given ID.\n *\n * @param id - The ID of the plugin of interest.\n *\n * @returns A promise which resolves when the plugin is activated\n * or rejects with an error if it cannot be activated.\n */\n async activatePlugin(id: string): Promise<void> {\n // Reject the promise if the plugin is not registered.\n const plugin = this._plugins.get(id);\n if (!plugin) {\n throw new ReferenceError(`Plugin '${id}' is not registered.`);\n }\n\n // Resolve immediately if the plugin is already activated.\n if (plugin.activated) {\n return;\n }\n\n // Return the pending resolver promise if it exists.\n if (plugin.promise) {\n return plugin.promise;\n }\n\n // Resolve the required services for the plugin.\n const required = plugin.requires.map(t => this.resolveRequiredService(t));\n\n // Resolve the optional services for the plugin.\n const optional = plugin.optional.map(t => this.resolveOptionalService(t));\n\n // Setup the resolver promise for the plugin.\n plugin.promise = Promise.all([...required, ...optional])\n .then(services =>\n plugin!.activate.apply(undefined, [this.application, ...services])\n )\n .then(service => {\n plugin!.service = service;\n plugin!.activated = true;\n plugin!.promise = null;\n })\n .catch(error => {\n plugin!.promise = null;\n throw error;\n });\n\n // Return the pending resolver promise.\n return plugin.promise;\n }\n\n /**\n * Activate all the deferred plugins.\n *\n * @returns A promise which will resolve when each plugin is activated\n * or rejects with an error if one cannot be activated.\n */\n async activatePlugins(\n kind: 'startUp' | 'defer',\n options: PluginRegistry.IStartOptions = {}\n ): Promise<void> {\n switch (kind) {\n case 'defer': {\n const promises = this.deferredPlugins\n .filter(pluginId => this._plugins.get(pluginId)!.autoStart)\n .map(pluginId => {\n return this.activatePlugin(pluginId);\n });\n await Promise.all(promises);\n break;\n }\n case 'startUp': {\n // Collect the ids of the startup plugins.\n const startups = Private.collectStartupPlugins(this._plugins, options);\n\n // Generate the activation promises.\n const promises = startups.map(async id => {\n try {\n return await this.activatePlugin(id);\n } catch (error) {\n console.error(`Plugin '${id}' failed to activate.`, error);\n }\n });\n await Promise.all(promises);\n break;\n }\n }\n }\n\n /**\n * Deactivate the plugin and its downstream dependents if and only if the\n * plugin and its dependents all support `deactivate`.\n *\n * @param id - The ID of the plugin of interest.\n *\n * @returns A list of IDs of downstream plugins deactivated with this one.\n */\n async deactivatePlugin(id: string): Promise<string[]> {\n // Reject the promise if the plugin is not registered.\n const plugin = this._plugins.get(id);\n if (!plugin) {\n throw new ReferenceError(`Plugin '${id}' is not registered.`);\n }\n\n // Bail early if the plugin is not activated.\n if (!plugin.activated) {\n return [];\n }\n\n // Check that this plugin can deactivate.\n if (!plugin.deactivate) {\n throw new TypeError(`Plugin '${id}'#deactivate() method missing`);\n }\n\n // Find the optimal deactivation order for plugins downstream of this one.\n const manifest = Private.findDependents(id, this._plugins, this._services);\n const downstream = manifest.map(id => this._plugins.get(id)!);\n\n // Check that all downstream plugins can deactivate.\n for (const plugin of downstream) {\n if (!plugin.deactivate) {\n throw new TypeError(\n `Plugin ${plugin.id}#deactivate() method missing (depends on ${id})`\n );\n }\n }\n\n // Deactivate all downstream plugins.\n for (const plugin of downstream) {\n const services = [...plugin.requires, ...plugin.optional].map(service => {\n const id = this._services.get(service);\n return id ? this._plugins.get(id)!.service : null;\n });\n\n // Await deactivation so the next plugins only receive active services.\n await plugin.deactivate!(this.application, ...services);\n plugin.service = null;\n plugin.activated = false;\n }\n\n // Remove plugin ID and return manifest of deactivated plugins.\n manifest.pop();\n return manifest;\n }\n\n /**\n * Resolve a required service of a given type.\n *\n * @param token - The token for the service type of interest.\n *\n * @returns A promise which resolves to an instance of the requested\n * service, or rejects with an error if it cannot be resolved.\n *\n * #### Notes\n * Services are singletons. The same instance will be returned each\n * time a given service token is resolved.\n *\n * If the plugin which provides the service has not been activated,\n * resolving the service will automatically activate the plugin.\n *\n * User code will not typically call this method directly. Instead,\n * the required services for the user's plugins will be resolved\n * automatically when the plugin is activated.\n */\n async resolveRequiredService<U>(token: Token<U>): Promise<U> {\n // Reject the promise if there is no provider for the type.\n const id = this._services.get(token);\n if (!id) {\n throw new TypeError(`No provider for: ${token.name}.`);\n }\n\n // Activate the plugin if necessary.\n const plugin = this._plugins.get(id)!;\n if (!plugin.activated) {\n await this.activatePlugin(id);\n }\n\n return plugin.service;\n }\n\n /**\n * Resolve an optional service of a given type.\n *\n * @param token - The token for the service type of interest.\n *\n * @returns A promise which resolves to an instance of the requested\n * service, or `null` if it cannot be resolved.\n *\n * #### Notes\n * Services are singletons. The same instance will be returned each\n * time a given service token is resolved.\n *\n * If the plugin which provides the service has not been activated,\n * resolving the service will automatically activate the plugin.\n *\n * User code will not typically call this method directly. Instead,\n * the optional services for the user's plugins will be resolved\n * automatically when the plugin is activated.\n */\n async resolveOptionalService<U>(token: Token<U>): Promise<U | null> {\n // Resolve with `null` if there is no provider for the type.\n const id = this._services.get(token);\n if (!id) {\n return null;\n }\n\n // Activate the plugin if necessary.\n const plugin = this._plugins.get(id)!;\n if (!plugin.activated) {\n try {\n await this.activatePlugin(id);\n } catch (reason) {\n console.error(reason);\n return null;\n }\n }\n\n return plugin.service;\n }\n\n private _application: any = null;\n private _validatePlugin: (plugin: IPlugin<any, any>) => boolean = () => true;\n private _plugins = new Map<string, Private.IPluginData<T>>();\n private _services = new Map<Token<any>, string>();\n}\n\n/**\n * PluginRegistry namespace\n */\nexport namespace PluginRegistry {\n /**\n * PluginRegistry constructor options.\n */\n export interface IOptions {\n /**\n * Validate that a plugin is allowed to be registered.\n *\n * Default is `() => true`.\n *\n * @param plugin The plugin to validate\n * @returns Whether the plugin can be registered or not.\n *\n * #### Notes\n * We recommend you print a console message with the reason\n * a plugin is invalid.\n */\n validatePlugin?: (plugin: IPlugin<any, any>) => boolean;\n }\n\n /**\n * An options object for application startup.\n */\n export interface IStartOptions {\n /**\n * The plugins to activate on startup.\n *\n * #### Notes\n * These will be *in addition* to any `autoStart` plugins.\n */\n startPlugins?: string[];\n\n /**\n * The plugins to **not** activate on startup.\n *\n * #### Notes\n * This will override `startPlugins` and any `autoStart` plugins.\n */\n ignorePlugins?: string[];\n }\n}\n\n/**\n * The namespace for the module implementation details.\n */\nnamespace Private {\n /**\n * An object which holds the full application state for a plugin.\n */\n export interface IPluginData<T = any> {\n /**\n * The human readable ID of the plugin.\n */\n readonly id: string;\n\n /**\n * The description of the plugin.\n */\n readonly description: string;\n\n /**\n * Whether the plugin should be activated on application start or waiting for being\n * required. If the value is 'defer' then the plugin should be activated only after\n * the application is started.\n */\n readonly autoStart: boolean | 'defer';\n\n /**\n * The types of required services for the plugin, or `[]`.\n */\n readonly requires: Token<any>[];\n\n /**\n * The types of optional services for the the plugin, or `[]`.\n */\n readonly optional: Token<any>[];\n\n /**\n * The type of service provided by the plugin, or `null`.\n */\n readonly provides: Token<any> | null;\n\n /**\n * The function which activates the plugin.\n */\n readonly activate: (app: T, ...args: any[]) => any;\n\n /**\n * The optional function which deactivates the plugin.\n */\n readonly deactivate:\n | ((app: T, ...args: any[]) => void | Promise<void>)\n | null;\n\n /**\n * Whether the plugin has been activated.\n */\n activated: boolean;\n\n /**\n * The resolved service for the plugin, or `null`.\n */\n service: any | null;\n\n /**\n * The pending resolver promise, or `null`.\n */\n promise: Promise<void> | null;\n }\n\n class PluginData<T = any, U = any> implements IPluginData<T> {\n private _activated = false;\n private _promise: Promise<void> | null = null;\n private _service: U | null = null;\n\n constructor(plugin: IPlugin<T, U>) {\n this.id = plugin.id;\n this.description = plugin.description ?? '';\n this.activate = plugin.activate;\n this.deactivate = plugin.deactivate ?? null;\n this.provides = plugin.provides ?? null;\n this.autoStart = plugin.autoStart ?? false;\n this.requires = plugin.requires ? plugin.requires.slice() : [];\n this.optional = plugin.optional ? plugin.optional.slice() : [];\n }\n\n /**\n * The human readable ID of the plugin.\n */\n readonly id: string;\n\n /**\n * The description of the plugin.\n */\n readonly description: string;\n\n /**\n * Whether the plugin should be activated on application start or waiting for being\n * required. If the value is 'defer' then the plugin should be activated only after\n * the application is started.\n */\n readonly autoStart: boolean | 'defer';\n\n /**\n * The types of required services for the plugin, or `[]`.\n */\n readonly requires: Token<any>[];\n\n /**\n * The types of optional services for the the plugin, or `[]`.\n */\n readonly optional: Token<any>[];\n\n /**\n * The type of service provided by the plugin, or `null`.\n */\n readonly provides: Token<any> | null;\n\n /**\n * The function which activates the plugin.\n */\n readonly activate: (app: T, ...args: any[]) => any;\n\n /**\n * The optional function which deactivates the plugin.\n */\n readonly deactivate:\n | ((app: T, ...args: any[]) => void | Promise<void>)\n | null;\n\n /**\n * Whether the plugin has been activated.\n */\n get activated(): boolean {\n return this._activated;\n }\n set activated(a: boolean) {\n this._activated = a;\n }\n\n /**\n * The resolved service for the plugin, or `null`.\n */\n get service(): U | null {\n return this._service;\n }\n set service(s: U | null) {\n this._service = s;\n }\n\n /**\n * The pending resolver promise, or `null`.\n */\n get promise(): Promise<void> | null {\n return this._promise;\n }\n set promise(p: Promise<void> | null) {\n this._promise = p;\n }\n }\n\n /**\n * Create a normalized plugin data object for the given plugin.\n */\n export function createPluginData<T>(\n plugin: IPlugin<any, any>\n ): IPluginData<T> {\n return new PluginData(plugin);\n }\n\n /**\n * Ensure no cycle is present in the plugin resolution graph.\n *\n * If a cycle is detected, an error will be thrown.\n */\n export function ensureNoCycle(\n plugin: IPluginData,\n plugins: Map<string, IPluginData>,\n services: Map<Token<any>, string>\n ): void {\n const dependencies = [...plugin.requires, ...plugin.optional];\n const visit = (token: Token<any>): boolean => {\n if (token === plugin.provides) {\n return true;\n }\n const id = services.get(token);\n if (!id) {\n return false;\n }\n const visited = plugins.get(id)!;\n const dependencies = [...visited.requires, ...visited.optional];\n if (dependencies.length === 0) {\n return false;\n }\n trace.push(id);\n if (dependencies.some(visit)) {\n return true;\n }\n trace.pop();\n return false;\n };\n\n // Bail early if there cannot be a cycle.\n if (!plugin.provides || dependencies.length === 0) {\n return;\n }\n\n // Setup a stack to trace service resolution.\n const trace = [plugin.id];\n\n // Throw an exception if a cycle is present.\n if (dependencies.some(visit)) {\n throw new ReferenceError(`Cycle detected: ${trace.join(' -> ')}.`);\n }\n }\n\n /**\n * Find dependents in deactivation order.\n *\n * @param id - The ID of the plugin of interest.\n *\n * @param plugins - The map containing all plugins.\n *\n * @param services - The map containing all services.\n *\n * @returns A list of dependent plugin IDs in order of deactivation\n *\n * #### Notes\n * The final item of the returned list is always the plugin of interest.\n */\n export function findDependents(\n id: string,\n plugins: Map<string, IPluginData>,\n services: Map<Token<any>, string>\n ): string[] {\n const edges = new Array<[string, string]>();\n const add = (id: string): void => {\n const plugin = plugins.get(id)!;\n // FIXME In the case of missing optional dependencies, we may consider\n // deactivating and reactivating the plugin without the missing service.\n const dependencies = [...plugin.requires, ...plugin.optional];\n edges.push(\n ...dependencies.reduce<[string, string][]>((acc, dep) => {\n const service = services.get(dep);\n if (service) {\n // An edge is oriented from dependent to provider.\n acc.push([id, service]);\n }\n return acc;\n }, [])\n );\n };\n\n for (const id of plugins.keys()) {\n add(id);\n }\n\n // Filter edges\n // - Get all packages that dependent on the package to be deactivated\n const newEdges = edges.filter(edge => edge[1] === id);\n let oldSize = 0;\n while (newEdges.length > oldSize) {\n const previousSize = newEdges.length;\n // Get all packages that dependent on packages that will be deactivated\n const packagesOfInterest = new Set(newEdges.map(edge => edge[0]));\n for (const poi of packagesOfInterest) {\n edges\n .filter(edge => edge[1] === poi)\n .forEach(edge => {\n // We check it is not already included to deal with circular dependencies\n if (!newEdges.includes(edge)) {\n newEdges.push(edge);\n }\n });\n }\n oldSize = previousSize;\n }\n\n const sorted = topologicSort(newEdges);\n const index = sorted.findIndex(candidate => candidate === id);\n\n if (index === -1) {\n return [id];\n }\n\n return sorted.slice(0, index + 1);\n }\n\n /**\n * Collect the IDs of the plugins to activate on startup.\n */\n export function collectStartupPlugins(\n plugins: Map<string, IPluginData>,\n options: PluginRegistry.IStartOptions\n ): string[] {\n // Create a set to hold the plugin IDs.\n const collection = new Set<string>();\n\n // Collect the auto-start (non deferred) plugins.\n for (const id of plugins.keys()) {\n if (plugins.get(id)!.autoStart === true) {\n collection.add(id);\n }\n }\n\n // Add the startup plugins.\n if (options.startPlugins) {\n for (const id of options.startPlugins) {\n collection.add(id);\n }\n }\n\n // Remove the ignored plugins.\n if (options.ignorePlugins) {\n for (const id of options.ignorePlugins) {\n collection.delete(id);\n }\n }\n\n // Return the collected startup plugins.\n return Array.from(collection);\n }\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * A class which wraps a promise into a delegate object.\n *\n * #### Notes\n * This class is useful when the logic to resolve or reject a promise\n * cannot be defined at the point where the promise is created.\n */\nexport class PromiseDelegate<T> {\n /**\n * Construct a new promise delegate.\n */\n constructor() {\n this.promise = new Promise<T>((resolve, reject) => {\n this._resolve = resolve;\n this._reject = reject;\n });\n }\n\n /**\n * The promise wrapped by the delegate.\n */\n readonly promise: Promise<T>;\n\n /**\n * Resolve the wrapped promise with the given value.\n *\n * @param value - The value to use for resolving the promise.\n */\n resolve(value: T | PromiseLike<T>): void {\n let resolve = this._resolve;\n resolve(value);\n }\n\n /**\n * Reject the wrapped promise with the given value.\n *\n * @reason - The reason for rejecting the promise.\n */\n reject(reason: unknown): void {\n let reject = this._reject;\n reject(reason);\n }\n\n private _resolve: (value: T | PromiseLike<T>) => void;\n private _reject: (reason: any) => void;\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * A runtime object which captures compile-time type information.\n *\n * #### Notes\n * A token captures the compile-time type of an interface or class in\n * an object which can be used at runtime in a type-safe fashion.\n */\nexport class Token<T> {\n /**\n * Construct a new token.\n *\n * @param name - A human readable name for the token.\n * @param description - Token purpose description for documentation.\n */\n constructor(name: string, description?: string) {\n this.name = name;\n this.description = description ?? '';\n this._tokenStructuralPropertyT = null!;\n }\n\n /**\n * Token purpose description.\n */\n readonly description?: string; // FIXME remove `?` for the next major version\n\n /**\n * The human readable name for the token.\n *\n * #### Notes\n * This can be useful for debugging and logging.\n */\n readonly name: string;\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n private _tokenStructuralPropertyT: T;\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n// Fallback\nexport function fallbackRandomValues(buffer: Uint8Array): void {\n let value = 0;\n for (let i = 0, n = buffer.length; i < n; ++i) {\n if (i % 4 === 0) {\n value = (Math.random() * 0xffffffff) >>> 0;\n }\n buffer[i] = value & 0xff;\n value >>>= 8;\n }\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\nimport { fallbackRandomValues } from './random';\n\n// Declare ambient variables for `window` and `require` to avoid a\n// hard dependency on both. This package must run on node.\ndeclare let window: any;\n\n/**\n * The namespace for random number related functionality.\n */\nexport namespace Random {\n /**\n * A function which generates random bytes.\n *\n * @param buffer - The `Uint8Array` to fill with random bytes.\n *\n * #### Notes\n * A cryptographically strong random number generator will be used if\n * available. Otherwise, `Math.random` will be used as a fallback for\n * randomness.\n *\n * The following RNGs are supported, listed in order of precedence:\n * - `window.crypto.getRandomValues`\n * - `window.msCrypto.getRandomValues`\n * - `require('crypto').randomFillSync\n * - `require('crypto').randomBytes\n * - `Math.random`\n */\n export const getRandomValues = (() => {\n // Look up the crypto module if available.\n const crypto: any =\n (typeof window !== 'undefined' && (window.crypto || window.msCrypto)) ||\n null;\n\n // Modern browsers and IE 11\n if (crypto && typeof crypto.getRandomValues === 'function') {\n return function getRandomValues(buffer: Uint8Array): void {\n return crypto.getRandomValues(buffer);\n };\n }\n\n // Fallback\n return fallbackRandomValues;\n })();\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n/**\n * A function which creates a function that generates UUID v4 identifiers.\n *\n * @returns A new function that creates a UUID v4 string.\n *\n * #### Notes\n * This implementation complies with RFC 4122.\n *\n * This uses `Random.getRandomValues()` for random bytes, which in\n * turn will use the underlying `crypto` module of the platform if\n * it is available. The fallback for randomness is `Math.random`.\n */\nexport function uuid4Factory(\n getRandomValues: (bytes: Uint8Array) => void\n): () => string {\n // Create a 16 byte array to hold the random values.\n const bytes = new Uint8Array(16);\n\n // Create a look up table from bytes to hex strings.\n const lut = new Array<string>(256);\n\n // Pad the single character hex digits with a leading zero.\n for (let i = 0; i < 16; ++i) {\n lut[i] = '0' + i.toString(16);\n }\n\n // Populate the rest of the hex digits.\n for (let i = 16; i < 256; ++i) {\n lut[i] = i.toString(16);\n }\n\n // Return a function which generates the UUID.\n return function uuid4(): string {\n // Get a new batch of random values.\n getRandomValues(bytes);\n\n // Set the UUID version number to 4.\n bytes[6] = 0x40 | (bytes[6] & 0x0f);\n\n // Set the clock sequence bit to the RFC spec.\n bytes[8] = 0x80 | (bytes[8] & 0x3f);\n\n // Assemble the UUID string.\n return (\n lut[bytes[0]] +\n lut[bytes[1]] +\n lut[bytes[2]] +\n lut[bytes[3]] +\n '-' +\n lut[bytes[4]] +\n lut[bytes[5]] +\n '-' +\n lut[bytes[6]] +\n lut[bytes[7]] +\n '-' +\n lut[bytes[8]] +\n lut[bytes[9]] +\n '-' +\n lut[bytes[10]] +\n lut[bytes[11]] +\n lut[bytes[12]] +\n lut[bytes[13]] +\n lut[bytes[14]] +\n lut[bytes[15]]\n );\n };\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\nimport { Random } from './random.browser';\nimport { uuid4Factory } from './uuid';\n\n/**\n * The namespace for UUID related functionality.\n */\nexport namespace UUID {\n /**\n * A function which generates UUID v4 identifiers.\n *\n * @returns A new UUID v4 string.\n *\n * #### Notes\n * This implementation complies with RFC 4122.\n *\n * This uses `Random.getRandomValues()` for random bytes, which in\n * turn will use the underlying `crypto` module of the platform if\n * it is available. The fallback for randomness is `Math.random`.\n */\n export const uuid4 = uuid4Factory(Random.getRandomValues);\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\n// Types and implementation inspired from https://github.com/jvilk/BrowserFS\n// LICENSE: https://github.com/jvilk/BrowserFS/blob/8977a704ea469d05daf857e4818bef1f4f498326/LICENSE\n// And from https://github.com/gzuidhof/starboard-notebook\n\n// LICENSE: https://github.com/gzuidhof/starboard-notebook/blob/cd8d3fc30af4bd29cdd8f6b8c207df8138f5d5dd/LICENSE\n\n/**\n * Types for Emscripten primitives.\n *\n * Ideally, much more of these would be taken from `@types/emscripten`.\n */\n\ntype EmscriptenFS = typeof FS;\n\nexport const DIR_MODE = 16895; // 040777\nexport const FILE_MODE = 33206; // 100666\nexport const SEEK_CUR = 1;\nexport const SEEK_END = 2;\n\nexport interface IStats {\n dev: number;\n ino?: number;\n mode?: number;\n nlink: number;\n uid: number;\n gid: number;\n rdev: number;\n size: number;\n blksize: number;\n blocks: number;\n atime: Date | string;\n mtime: Date | string;\n ctime: Date | string;\n timestamp?: number;\n}\n\nexport interface IEmscriptenFSNode {\n id: number;\n name: string;\n mode: number;\n parent: IEmscriptenFSNode;\n mount: { opts: { root: string } };\n stream_ops: IEmscriptenStreamOps;\n node_ops: IEmscriptenNodeOps;\n timestamp: number;\n atime: number;\n mtime: number;\n ctime: number;\n}\n\nexport interface IEmscriptenStream {\n node: IEmscriptenFSNode;\n nfd: any;\n flags?: number;\n position?: number;\n shared: {\n flags: number;\n position: number;\n };\n}\n\nexport function instanceOfStream(\n nodeOrStream: IEmscriptenFSNode | IEmscriptenStream,\n): nodeOrStream is IEmscriptenStream {\n return 'node' in nodeOrStream;\n}\n\nexport interface IEmscriptenNodeOps {\n getattr(node: IEmscriptenFSNode | IEmscriptenStream): IStats;\n setattr(node: IEmscriptenFSNode | IEmscriptenStream, attr: IStats): void;\n lookup(\n parent: IEmscriptenFSNode | IEmscriptenStream,\n name: string,\n ): IEmscriptenFSNode;\n mknod(\n parent: IEmscriptenFSNode | IEmscriptenStream,\n name: string,\n mode: number,\n dev: number,\n ): IEmscriptenFSNode;\n rename(\n oldNode: IEmscriptenFSNode | IEmscriptenStream,\n newDir: IEmscriptenFSNode | IEmscriptenStream,\n newName: string,\n ): void;\n unlink(parent: IEmscriptenFSNode | IEmscriptenStream, name: string): void;\n rmdir(parent: IEmscriptenFSNode | IEmscriptenStream, name: string): void;\n readdir(node: IEmscriptenFSNode | IEmscriptenStream): string[];\n symlink(\n parent: IEmscriptenFSNode | IEmscriptenStream,\n newName: string,\n oldPath: string,\n ): void;\n readlink(node: IEmscriptenFSNode | IEmscriptenStream): string;\n}\n\nexport interface IEmscriptenStreamOps {\n open(stream: IEmscriptenStream): void;\n close(stream: IEmscriptenStream): void;\n read(\n stream: IEmscriptenStream,\n buffer: Uint8Array,\n offset: number,\n length: number,\n position: number,\n ): number;\n write(\n stream: IEmscriptenStream,\n buffer: Uint8Array,\n offset: number,\n length: number,\n position: number,\n ): number;\n llseek(stream: IEmscriptenStream, offset: number, whence: number): number;\n}\n\n/**\n * The emscripten filesystem module API.\n */\nexport type FS = EmscriptenFS & {\n ErrnoError: any;\n createNode: (\n parent: IEmscriptenFSNode | null,\n name: string,\n mode: number,\n dev: number,\n ) => IEmscriptenFSNode;\n};\n\n/**\n * The emscripten filesystem error codes.\n */\nexport type ERRNO_CODES = any;\n\n/**\n * The emscripten FS Path API.\n */\nexport type PATH = {\n basename: (path: string) => string;\n dirname: (path: string) => string;\n join: (...parts: string[]) => string;\n join2: (l: string, r: string) => string;\n normalize: (path: string) => string;\n splitPath: (filename: string) => string;\n};\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\n// Types and implementation inspired from https://github.com/jvilk/BrowserFS\n// LICENSE: https://github.com/jvilk/BrowserFS/blob/8977a704ea469d05daf857e4818bef1f4f498326/LICENSE\n// And from https://github.com/gzuidhof/starboard-notebook\n\n// LICENSE: https://github.com/gzuidhof/starboard-notebook/blob/cd8d3fc30af4bd29cdd8f6b8c207df8138f5d5dd/LICENSE\nimport { Contents } from '@jupyterlab/services';\n\nimport { UUID } from '@lumino/coreutils';\n\nimport {\n FS,\n ERRNO_CODES,\n PATH,\n DIR_MODE,\n SEEK_CUR,\n SEEK_END,\n IEmscriptenStream,\n instanceOfStream,\n IEmscriptenStreamOps,\n IEmscriptenNodeOps,\n IEmscriptenFSNode,\n IStats,\n} from './emscripten';\n\nexport const DRIVE_SEPARATOR = ':';\n\nexport const BLOCK_SIZE = 4096;\n\nconst encoder = new TextEncoder();\nconst decoder = new TextDecoder('utf-8');\n\nexport type TDriveMethod =\n | 'readdir'\n | 'rmdir'\n | 'rename'\n | 'getmode'\n | 'lookup'\n | 'mknod'\n | 'getattr'\n | 'get'\n | 'put';\n\n/**\n * Type of the data argument for the drive request, based on the request name\n */\nexport type TDriveData = {\n rename: {\n /**\n * The new path for the file\n */\n newPath: string;\n };\n mknod: {\n /**\n * The mode of the file to create\n */\n mode: number;\n };\n put: {\n /**\n * The file content to write\n */\n data: any;\n\n /**\n * The file content format\n */\n format: Contents.FileFormat;\n };\n};\n\n/**\n * Drive request\n */\nexport type TDriveRequest<T extends TDriveMethod> = {\n /**\n * The method of the request (rmdir, readdir etc)\n */\n method: T;\n\n /**\n * A unique ID to identify the origin of this request\n */\n browsingContextId?: string;\n\n /**\n * A unique ID to correlate this specific request with its response\n */\n requestId?: string;\n\n /**\n * The path to the file/directory for which the request was sent\n */\n path: string;\n} & (T extends keyof TDriveData ? { data: TDriveData[T] } : object);\n\ntype TDriveResponses = {\n readdir: string[];\n rmdir: null;\n rename: null;\n getmode: number;\n lookup: DriveFS.ILookup;\n mknod: null;\n getattr: IStats;\n get: {\n /**\n * The returned file content\n */\n content: any;\n\n /**\n * The content format\n */\n format: Contents.FileFormat;\n } | null;\n put: null;\n};\n\n/**\n * Drive response\n */\nexport type TDriveResponse<T extends TDriveMethod> = TDriveResponses[T];\n\n// Mapping flag -> do we need to overwrite the file upon closing it\nconst flagNeedsWrite: { [flag: number]: boolean } = {\n 0 /*O_RDONLY*/: false,\n 1 /*O_WRONLY*/: true,\n 2 /*O_RDWR*/: true,\n 64 /*O_CREAT*/: true,\n 65 /*O_WRONLY|O_CREAT*/: true,\n 66 /*O_RDWR|O_CREAT*/: true,\n 129 /*O_WRONLY|O_EXCL*/: true,\n 193 /*O_WRONLY|O_CREAT|O_EXCL*/: true,\n 514 /*O_RDWR|O_TRUNC*/: true,\n 577 /*O_WRONLY|O_CREAT|O_TRUNC*/: true,\n 578 /*O_CREAT|O_RDWR|O_TRUNC*/: true,\n 705 /*O_WRONLY|O_CREAT|O_EXCL|O_TRUNC*/: true,\n 706 /*O_RDWR|O_CREAT|O_EXCL|O_TRUNC*/: true,\n 1024 /*O_APPEND*/: true,\n 1025 /*O_WRONLY|O_APPEND*/: true,\n 1026 /*O_RDWR|O_APPEND*/: true,\n 1089 /*O_WRONLY|O_CREAT|O_APPEND*/: true,\n 1090 /*O_RDWR|O_CREAT|O_APPEND*/: true,\n 1153 /*O_WRONLY|O_EXCL|O_APPEND*/: true,\n 1154 /*O_RDWR|O_EXCL|O_APPEND*/: true,\n 1217 /*O_WRONLY|O_CREAT|O_EXCL|O_APPEND*/: true,\n 1218 /*O_RDWR|O_CREAT|O_EXCL|O_APPEND*/: true,\n 4096 /*O_RDONLY|O_DSYNC*/: true,\n 4098 /*O_RDWR|O_DSYNC*/: true,\n};\n\n/** Implementation-specifc extension of an open stream, adding the file. */\nexport interface IDriveStream extends IEmscriptenStream {\n file?: DriveFS.IFile;\n}\n\nexport class DriveFSEmscriptenStreamOps implements IEmscriptenStreamOps {\n private fs: DriveFS;\n\n constructor(fs: DriveFS) {\n this.fs = fs;\n }\n\n open(stream: IDriveStream): void {\n const path = this.fs.realPath(stream.node);\n\n if (this.fs.FS.isFile(stream.node.mode)) {\n try {\n const file = this.fs.API.get(path);\n stream.file = file;\n } catch (e) {\n // If we're opening a file for writing and the file does not exist, create it! Otherwise, throw the proper error\n // We need to do this because the current thread is thinking a file exist (isFile returns true)\n // whilst it was actually deleted in the main thread\n\n // if writing\n const flags = stream.flags ?? stream.shared.flags;\n let parsedFlags = typeof flags === 'string' ? parseInt(flags, 10) : flags;\n parsedFlags &= 0x1fff;\n\n let needsWrite = true;\n if (parsedFlags in flagNeedsWrite) {\n needsWrite = flagNeedsWrite[parsedFlags];\n }\n if (needsWrite) {\n stream.node = this.fs.node_ops.mknod(\n stream.node.parent,\n stream.node.name,\n stream.node.mode,\n 0, // dev should be 0 for regular files\n );\n const file = this.fs.API.get(path);\n stream.file = file;\n } else {\n throw new this.fs.FS.ErrnoError(this.fs.ERRNO_CODES['ENOENT']);\n }\n }\n }\n }\n\n close(stream: IDriveStream): void {\n if (!this.fs.FS.isFile(stream.node.mode) || !stream.file) {\n return;\n }\n\n const path = this.fs.realPath(stream.node);\n\n const flags = stream.flags ?? stream.shared.flags;\n let parsedFlags = typeof flags === 'string' ? parseInt(flags, 10) : flags;\n parsedFlags &= 0x1fff;\n\n let needsWrite = true;\n if (parsedFlags in flagNeedsWrite) {\n needsWrite = flagNeedsWrite[parsedFlags];\n }\n\n if (needsWrite) {\n this.fs.API.put(path, stream.file);\n }\n\n stream.file = undefined;\n }\n\n read(\n stream: IDriveStream,\n buffer: Uint8Array,\n offset: number,\n length: number,\n position: number,\n ): number {\n if (\n length <= 0 ||\n stream.file === undefined ||\n position >= (stream.file.data.length || 0)\n ) {\n return 0;\n }\n\n const size = Math.min(stream.file.data.length - position, length);\n buffer.set(stream.file.data.subarray(position, position + size), offset);\n return size;\n }\n\n write(\n stream: IDriveStream,\n buffer: Uint8Array,\n offset: number,\n length: number,\n position: number,\n ): number {\n if (length <= 0 || stream.file === undefined) {\n return 0;\n }\n\n const now = Date.now();\n stream.node.timestamp = now;\n stream.node.atime = now;\n stream.node.mtime = now;\n stream.node.ctime = now;\n\n if (position + length > (stream.file?.data.length || 0)) {\n const oldData = stream.file.data ? stream.file.data : new Uint8Array();\n stream.file.data = new Uint8Array(position + length);\n stream.file.data.set(oldData);\n }\n\n stream.file.data.set(buffer.subarray(offset, offset + length), position);\n\n return length;\n }\n\n llseek(stream: IDriveStream, offset: number, whence: number): number {\n let position = offset;\n if (whence === SEEK_CUR) {\n position += stream.position ?? stream.shared.position;\n } else if (whence === SEEK_END) {\n if (this.fs.FS.isFile(stream.node.mode)) {\n if (stream.file !== undefined) {\n position += stream.file.data.length;\n } else {\n throw new this.fs.FS.ErrnoError(this.fs.ERRNO_CODES.EPERM);\n }\n }\n }\n\n if (position < 0) {\n throw new this.fs.FS.ErrnoError(this.fs.ERRNO_CODES.EINVAL);\n }\n\n return position;\n }\n}\n\nexport class DriveFSEmscriptenNodeOps implements IEmscriptenNodeOps {\n private fs: DriveFS;\n\n constructor(fs: DriveFS) {\n this.fs = fs;\n }\n\n protected node = (\n nodeOrStream: IEmscriptenFSNode | IEmscriptenStream,\n ): IEmscriptenFSNode => {\n if (instanceOfStream(nodeOrStream)) {\n return nodeOrStream.node;\n }\n return nodeOrStream;\n };\n\n getattr = (value: IEmscriptenFSNode | IEmscriptenStream): IStats => {\n const node = this.node(value);\n return {\n ...this.fs.API.getattr(this.fs.realPath(node)),\n mode: node.mode,\n ino: node.id,\n };\n };\n\n setattr = (value: IEmscriptenFSNode | IEmscriptenStream, attr: IStats): void => {\n const node = this.node(value);\n for (const [key, value] of Object.entries(attr)) {\n switch (key) {\n case 'mode':\n node.mode = value;\n break;\n case 'timestamp':\n node.timestamp = value;\n break;\n case 'atime':\n node.atime = value;\n break;\n case 'mtime':\n node.mtime = value;\n break;\n case 'ctime':\n node.ctime = value;\n break;\n case 'size': {\n const size = value;\n const path = this.fs.realPath(node);\n if (this.fs.FS.isFile(node.mode) && size >= 0) {\n let file;\n try {\n file = this.fs.API.get(path);\n } catch (e) {\n // TODO: Should do anything here? Should we create the file?\n break;\n }\n\n const oldData = file.data ? file.data : new Uint8Array();\n if (size !== oldData.length) {\n if (size < oldData.length) {\n file.data = file.data.slice(0, size);\n } else {\n file.data = new Uint8Array(size);\n file.data.set(oldData);\n }\n this.fs.API.put(path, file);\n }\n } else {\n console.warn('setattr size of', size, 'on', node, 'not yet implemented');\n }\n break;\n }\n case 'dontFollow':\n // Ignore for now\n break;\n default:\n console.warn('setattr', key, 'of', value, 'on', node, 'not yet implemented');\n break;\n }\n }\n };\n\n lookup = (\n parent: IEmscriptenFSNode | IEmscriptenStream,\n name: string,\n ): IEmscriptenFSNode => {\n const node = this.node(parent);\n const path = this.fs.PATH.join2(this.fs.realPath(node), name);\n const result = this.fs.API.lookup(path);\n if (!result.ok) {\n throw new this.fs.FS.ErrnoError(this.fs.ERRNO_CODES['ENOENT']);\n }\n return this.fs.createNode(node, name, result.mode!, 0);\n };\n\n mknod = (\n parent: IEmscriptenFSNode | IEmscriptenStream,\n name: string,\n mode: number,\n dev: number,\n ): IEmscriptenFSNode => {\n const node = this.node(parent);\n const path = this.fs.PATH.join2(this.fs.realPath(node), name);\n this.fs.API.mknod(path, mode);\n return this.fs.createNode(node, name, mode, dev);\n };\n\n rename = (\n value: IEmscriptenFSNode | IEmscriptenStream,\n newDir: IEmscriptenFSNode | IEmscriptenStream,\n newName: string,\n ): void => {\n const oldNode = this.node(value);\n const newDirNode = this.node(newDir);\n this.fs.API.rename(\n oldNode.parent\n ? this.fs.PATH.join2(this.fs.realPath(oldNode.parent), oldNode.name)\n : oldNode.name,\n this.fs.PATH.join2(this.fs.realPath(newDirNode), newName),\n );\n\n // Updating the in-memory node\n oldNode.name = newName;\n oldNode.parent = newDirNode;\n };\n\n unlink = (parent: IEmscriptenFSNode | IEmscriptenStream, name: string): null => {\n return this.fs.API.rmdir(\n this.fs.PATH.join2(this.fs.realPath(this.node(parent)), name),\n );\n };\n\n rmdir = (parent: IEmscriptenFSNode | IEmscriptenStream, name: string): null => {\n return this.fs.API.rmdir(\n this.fs.PATH.join2(this.fs.realPath(this.node(parent)), name),\n );\n };\n\n readdir = (value: IEmscriptenFSNode | IEmscriptenStream): string[] => {\n return this.fs.API.readdir(this.fs.realPath(this.node(value)));\n };\n\n symlink = (\n parent: IEmscriptenFSNode | IEmscriptenStream,\n newName: string,\n oldPath: string,\n ): void => {\n throw new this.fs.FS.ErrnoError(this.fs.ERRNO_CODES['EPERM']);\n };\n\n readlink = (node: IEmscriptenFSNode | IEmscriptenStream): string => {\n throw new this.fs.FS.ErrnoError(this.fs.ERRNO_CODES['EINVAL']);\n };\n}\n\n/**\n * ContentsAPI base class\n */\nexport abstract class ContentsAPI {\n constructor(options: ContentsAPI.IOptions) {\n this._driveName = options.driveName;\n this._mountpoint = options.mountpoint;\n\n this.FS = options.FS;\n this.ERRNO_CODES = options.ERRNO_CODES;\n }\n\n lookup(path: string): DriveFS.ILookup {\n return this.request({ method: 'lookup', path: this.normalizePath(path) });\n }\n\n getmode(path: string): number {\n return this.request({ method: 'getmode', path: this.normalizePath(path) });\n }\n\n mknod(path: string, mode: number): null {\n return this.request({\n method: 'mknod',\n path: this.normalizePath(path),\n data: { mode },\n });\n }\n\n rename(oldPath: string, newPath: string): null {\n return this.request({\n method: 'rename',\n path: this.normalizePath(oldPath),\n data: { newPath: this.normalizePath(newPath) },\n });\n }\n\n readdir(path: string): string[] {\n const dirlist = this.request({\n method: 'readdir',\n path: this.normalizePath(path),\n });\n dirlist.push('.');\n dirlist.push('..');\n return dirlist;\n }\n\n rmdir(path: string): null {\n return this.request({ method: 'rmdir', path: this.normalizePath(path) });\n }\n\n get(path: string): DriveFS.IFile {\n const response = this.request({\n method: 'get',\n path: this.normalizePath(path),\n });\n\n if (!response) {\n throw new this.FS.ErrnoError(this.ERRNO_CODES['ENOENT']);\n }\n\n const serializedContent = response.content;\n const format: 'json' | 'text' | 'base64' | null = response.format;\n\n switch (format) {\n case 'json':\n case 'text':\n return {\n data: encoder.encode(serializedContent),\n format,\n };\n case 'base64': {\n const binString = atob(serializedContent);\n const len = binString.length;\n const data = new Uint8Array(len);\n for (let i = 0; i < len; i++) {\n data[i] = binString.charCodeAt(i);\n }\n return {\n data,\n format,\n };\n }\n default:\n throw new this.FS.ErrnoError(this.ERRNO_CODES['ENOENT']);\n }\n }\n\n put(path: string, value: DriveFS.IFile): null {\n switch (value.format) {\n case 'json':\n case 'text':\n return this.request({\n method: 'put',\n path: this.normalizePath(path),\n data: {\n format: value.format,\n data: decoder.decode(value.data),\n },\n });\n case 'base64': {\n let binary = '';\n for (let i = 0; i < value.data.byteLength; i++) {\n binary += String.fromCharCode(value.data[i]);\n }\n return this.request({\n method: 'put',\n path: this.normalizePath(path),\n data: {\n format: value.format,\n data: btoa(binary),\n },\n });\n }\n }\n }\n\n getattr(path: string): IStats {\n const stats = this.request({\n method: 'getattr',\n path: this.normalizePath(path),\n });\n\n // Emscripten 4.0.9+ (used by Pyodide 0.28+) requires all three timestamps\n // to be valid Date objects with .getTime() method (see https://github.com/emscripten-core/emscripten/pull/22998).\n // Fallback to epoch if any timestamp is missing/null/undefined.\n const defaultDate = new Date(0);\n stats.atime = stats.atime ? new Date(stats.atime) : defaultDate;\n stats.mtime = stats.mtime ? new Date(stats.mtime) : defaultDate;\n stats.ctime = stats.ctime ? new Date(stats.ctime) : defaultDate;\n\n // ensure a non-undefined size (0 isn't great, though)\n stats.size = stats.size || 0;\n return stats;\n }\n\n /**\n * Normalize a Path by making it compliant for the content manager\n *\n * @param path: the path relatively to the Emscripten drive\n */\n normalizePath(path: string): string {\n // Remove mountpoint prefix\n if (path.startsWith(this._mountpoint)) {\n path = path.slice(this._mountpoint.length);\n }\n\n // Add JupyterLab drive name\n if (this._driveName) {\n path = `${this._driveName}${DRIVE_SEPARATOR}${path}`;\n }\n\n return path;\n }\n\n abstract request<T extends TDriveMethod>(data: TDriveRequest<T>): TDriveResponse<T>;\n\n private _driveName: string;\n private _mountpoint: string;\n\n protected FS: FS;\n protected ERRNO_CODES: ERRNO_CODES;\n}\n\n/**\n * An Emscripten-compatible synchronous Contents API using the service worker.\n */\nexport class ServiceWorkerContentsAPI extends ContentsAPI {\n /**\n * Construct a new ServiceWorkerContentsAPI.\n */\n constructor(options: ServiceWorkerContentsAPI.IOptions) {\n super(options);\n\n this._baseUrl = options.baseUrl;\n this._browsingContextId = options.browsingContextId || '';\n }\n\n request<T extends TDriveMethod>(data: TDriveRequest<T>): TDriveResponse<T> {\n const xhr = new XMLHttpRequest();\n xhr.open('POST', encodeURI(this.endpoint), false);\n\n // Generate unique request ID for correlation\n const requestId = UUID.uuid4();\n\n // Add the origin browsing context ID and request ID to the request\n const requestWithMetadata = {\n data: { ...data, requestId },\n browsingContextId: this._browsingContextId,\n requestId,\n };\n\n try {\n xhr.send(JSON.stringify(requestWithMetadata));\n } catch (e) {\n console.error(e);\n }\n\n if (xhr.status >= 400) {\n throw new this.FS.ErrnoError(this.ERRNO_CODES['EINVAL']);\n }\n\n return JSON.parse(xhr.responseText);\n }\n\n /**\n * Get the api/drive endpoint\n */\n get endpoint(): string {\n return `${this._baseUrl}api/drive`;\n }\n\n private _baseUrl: string;\n private _browsingContextId: string;\n}\n\nexport class DriveFS {\n FS: FS;\n API: ContentsAPI;\n PATH: PATH;\n ERRNO_CODES: ERRNO_CODES;\n driveName: string;\n\n constructor(options: DriveFS.IOptions) {\n this.FS = options.FS;\n this.PATH = options.PATH;\n this.ERRNO_CODES = options.ERRNO_CODES;\n this.API = this.createAPI(options);\n\n this.driveName = options.driveName;\n\n this.node_ops = new DriveFSEmscriptenNodeOps(this);\n this.stream_ops = new DriveFSEmscriptenStreamOps(this);\n }\n\n node_ops: IEmscriptenNodeOps;\n stream_ops: IEmscriptenStreamOps;\n\n /**\n * Create the ContentsAPI.\n *\n * This is supposed to be overwritten if needed.\n */\n createAPI(options: DriveFS.IOptions): ContentsAPI {\n if (!options.browsingContextId || !options.baseUrl) {\n throw new Error(\n 'Cannot create service-worker API without current browsingContextId',\n );\n }\n\n return new ServiceWorkerContentsAPI(options as ServiceWorkerContentsAPI.IOptions);\n }\n\n mount(mount: any): IEmscriptenFSNode {\n return this.createNode(null, mount.mountpoint, DIR_MODE | 511, 0);\n }\n\n createNode(\n parent: IEmscriptenFSNode | null,\n name: string,\n mode: number,\n dev: number,\n ): IEmscriptenFSNode {\n const FS = this.FS;\n if (!FS.isDir(mode) && !FS.isFile(mode)) {\n throw new FS.ErrnoError(this.ERRNO_CODES['EINVAL']);\n }\n const node = FS.createNode(parent, name, mode, dev);\n node.node_ops = this.node_ops;\n node.stream_ops = this.stream_ops;\n return node;\n }\n\n getMode(path: string): number {\n return this.API.getmode(path);\n }\n\n realPath(node: IEmscriptenFSNode): string {\n const parts: string[] = [];\n let currentNode: IEmscriptenFSNode = node;\n\n parts.push(currentNode.name);\n while (currentNode.parent !== currentNode) {\n currentNode = currentNode.parent;\n parts.push(currentNode.name);\n }\n parts.reverse();\n\n return this.PATH.join.apply(null, parts);\n }\n}\n\n/**\n * A namespace for ContentsAPI configurations, etc.\n */\nexport namespace ContentsAPI {\n /**\n * Initialization options for a contents API;\n */\n export interface IOptions {\n /**\n * The name of the drive to use for the contents API request.\n */\n driveName: string;\n\n /**\n * Where to mount files in the kernel.\n */\n mountpoint: string;\n\n /**\n * The filesystem module API.\n */\n FS: FS;\n\n /**\n * The filesystem error codes.\n */\n ERRNO_CODES: ERRNO_CODES;\n }\n}\n\n/**\n * A namespace for ServiceWorkerContentsAPI configurations, etc.\n */\nexport namespace ServiceWorkerContentsAPI {\n /**\n * Initialization options for a service worker contents API\n */\n export interface IOptions extends ContentsAPI.IOptions {\n /**\n * The base URL.\n */\n baseUrl: string;\n\n /**\n * The ID of the browsing context where the request originated.\n */\n browsingContextId: string;\n }\n}\n\n/**\n * A namespace for DriveFS configurations, etc.\n */\nexport namespace DriveFS {\n /**\n * A file representation;\n */\n export interface IFile {\n data: Uint8Array;\n format: 'json' | 'text' | 'base64';\n }\n\n /**\n * The response to a lookup request;\n */\n export interface ILookup {\n ok: boolean;\n mode?: number;\n }\n\n /**\n * Initialization options for a drive;\n */\n export interface IOptions {\n FS: FS;\n PATH: PATH;\n ERRNO_CODES: ERRNO_CODES;\n baseUrl: string;\n driveName: string;\n mountpoint: string;\n browsingContextId?: string;\n }\n}\n", "export const ARRAY = 'array';\nexport const BIGINT = 'bigint';\nexport const BOOLEAN = 'boolean';\nexport const FUNCTION = 'function';\nexport const NULL = 'null';\nexport const NUMBER = 'number';\nexport const OBJECT = 'object';\nexport const STRING = 'string';\nexport const SYMBOL = 'symbol';\nexport const UNDEFINED = 'undefined';\n", "// \u26A0\uFE0F AUTOMATICALLY GENERATED - DO NOT CHANGE\nexport const CHANNEL = '64e10b34-2bf7-4616-9668-f99de5aa046e';\n\nexport const MAIN = 'M' + CHANNEL;\nexport const THREAD = 'T' + CHANNEL;\n", "export const APPLY = 'apply';\nexport const CONSTRUCT = 'construct';\nexport const DEFINE_PROPERTY = 'defineProperty';\nexport const DELETE_PROPERTY = 'deleteProperty';\nexport const GET = 'get';\nexport const GET_OWN_PROPERTY_DESCRIPTOR = 'getOwnPropertyDescriptor';\nexport const GET_PROTOTYPE_OF = 'getPrototypeOf';\nexport const HAS = 'has';\nexport const IS_EXTENSIBLE = 'isExtensible';\nexport const OWN_KEYS = 'ownKeys';\nexport const PREVENT_EXTENSION = 'preventExtensions';\nexport const SET = 'set';\nexport const SET_PROTOTYPE_OF = 'setPrototypeOf';\n", "// The goal of this file is to normalize SAB\n// at least in main -> worker() use cases.\n// This still cannot possibly solve the sync\n// worker -> main() use case if SharedArrayBuffer\n// is not available or usable.\n\nimport {CHANNEL} from './channel.js';\n\nconst {isArray} = Array;\n\nlet {SharedArrayBuffer, window} = globalThis;\nlet {notify, wait, waitAsync} = Atomics;\nlet postPatched = null;\n\n// This is needed for some version of Firefox\nif (!waitAsync) {\n waitAsync = buffer => ({\n value: new Promise(onmessage => {\n // encodeURIComponent('onmessage=({data:b})=>(Atomics.wait(b,0),postMessage(0))')\n let w = new Worker('data:application/javascript,onmessage%3D(%7Bdata%3Ab%7D)%3D%3E(Atomics.wait(b%2C0)%2CpostMessage(0))');\n w.onmessage = onmessage;\n w.postMessage(buffer);\n })\n });\n}\n\n// Monkey-patch SharedArrayBuffer if needed\ntry {\n new SharedArrayBuffer(4);\n}\ncatch (_) {\n SharedArrayBuffer = ArrayBuffer;\n\n const ids = new WeakMap;\n // patch only main -> worker():async use case\n if (window) {\n const resolvers = new Map;\n const {prototype: {postMessage}} = Worker;\n\n const listener = event => {\n const details = event.data?.[CHANNEL];\n if (!isArray(details)) {\n event.stopImmediatePropagation();\n const { id, sb } = details;\n resolvers.get(id)(sb);\n }\n };\n\n postPatched = function (data, ...rest) {\n const details = data?.[CHANNEL];\n if (isArray(details)) {\n const [id, sb] = details;\n ids.set(sb, id);\n this.addEventListener('message', listener);\n }\n return postMessage.call(this, data, ...rest);\n };\n\n waitAsync = sb => ({\n value: new Promise(resolve => {\n resolvers.set(ids.get(sb), resolve);\n }).then(buff => {\n resolvers.delete(ids.get(sb));\n ids.delete(sb);\n for (let i = 0; i < buff.length; i++) sb[i] = buff[i];\n return 'ok';\n })\n });\n }\n else {\n const as = (id, sb) => ({[CHANNEL]: { id, sb }});\n\n notify = sb => {\n postMessage(as(ids.get(sb), sb));\n };\n\n addEventListener('message', event => {\n const details = event.data?.[CHANNEL];\n if (isArray(details)) {\n const [id, sb] = details;\n ids.set(sb, id);\n }\n });\n }\n}\n\nexport {SharedArrayBuffer, isArray, notify, postPatched, wait, waitAsync};\n", "/*! (c) Andrea Giammarchi - ISC */\n\nimport {FUNCTION} from 'proxy-target/types';\n\nimport {CHANNEL} from './channel.js';\nimport {GET, HAS, SET} from './shared/traps.js';\n\nimport {SharedArrayBuffer, isArray, notify, postPatched, wait, waitAsync} from './bridge.js';\n\n// just minifier friendly for Blob Workers' cases\nconst {Int32Array, Map, Uint16Array} = globalThis;\n\n// common constants / utilities for repeated operations\nconst {BYTES_PER_ELEMENT: I32_BYTES} = Int32Array;\nconst {BYTES_PER_ELEMENT: UI16_BYTES} = Uint16Array;\n\nconst waitInterrupt = (sb, delay, handler) => {\n while (wait(sb, 0, 0, delay) === 'timed-out')\n handler();\n};\n\n// retain buffers to transfer\nconst buffers = new WeakSet;\n\n// retain either main threads or workers global context\nconst context = new WeakMap;\n\nconst syncResult = {value: {then: fn => fn()}};\n\n// used to generate a unique `id` per each worker `postMessage` \"transaction\"\nlet uid = 0;\n\n/**\n * @typedef {Object} Interrupt used to sanity-check interrupts while waiting synchronously.\n * @prop {function} [handler] a callback invoked every `delay` milliseconds.\n * @prop {number} [delay=42] define `handler` invokes in terms of milliseconds.\n */\n\n/**\n * Create once a `Proxy` able to orchestrate synchronous `postMessage` out of the box.\n * @param {globalThis | Worker} self the context in which code should run\n * @param {{parse: (serialized: string) => any, stringify: (serializable: any) => string, transform?: (value:any) => any, interrupt?: () => void | Interrupt}} [JSON] an optional `JSON` like interface to `parse` or `stringify` content with extra `transform` ability.\n * @returns {ProxyHandler<globalThis> | ProxyHandler<Worker>}\n */\nconst coincident = (self, {parse = JSON.parse, stringify = JSON.stringify, transform, interrupt} = JSON) => {\n // create a Proxy once for the given context (globalThis or Worker instance)\n if (!context.has(self)) {\n // ensure no SAB gets a chance to pass through this call\n const sendMessage = postPatched || self.postMessage;\n // ensure the CHANNEL and data are posted correctly\n const post = (transfer, ...args) => sendMessage.call(self, {[CHANNEL]: args}, {transfer});\n\n const handler = typeof interrupt === FUNCTION ? interrupt : interrupt?.handler;\n const delay = interrupt?.delay || 42;\n const decoder = new TextDecoder('utf-16');\n\n // automatically uses sync wait (worker -> main)\n // or fallback to async wait (main -> worker)\n const waitFor = (isAsync, sb) => isAsync ?\n waitAsync(sb, 0) :\n ((handler ? waitInterrupt(sb, delay, handler) : wait(sb, 0)), syncResult);\n\n // prevent Harakiri https://github.com/WebReflection/coincident/issues/18\n let seppuku = false;\n\n context.set(self, new Proxy(new Map, {\n // there is very little point in checking prop in proxy for this very specific case\n // and I don't want to orchestrate a whole roundtrip neither, as stuff would fail\n // regardless if from Worker we access non existent Main callback, and vice-versa.\n // This is here mostly to guarantee that if such check is performed, at least the\n // get trap goes through and then it's up to developers guarantee they are accessing\n // stuff that actually exists elsewhere.\n [HAS]: (_, action) => typeof action === 'string' && !action.startsWith('_'),\n\n // worker related: get any utility that should be available on the main thread\n [GET]: (_, action) => action === 'then' ? null : ((...args) => {\n // transaction id\n const id = uid++;\n\n // first contact: just ask for how big the buffer should be\n // the value would be stored at index [1] while [0] is just control\n let sb = new Int32Array(new SharedArrayBuffer(I32_BYTES * 2));\n\n // if a transfer list has been passed, drop it from args\n let transfer = [];\n if (buffers.has(args.at(-1) || transfer))\n buffers.delete(transfer = args.pop());\n\n // ask for invoke with arguments and wait for it\n post(transfer, id, sb, action, transform ? args.map(transform) : args);\n\n // helps deciding how to wait for results\n const isAsync = self !== globalThis;\n\n // warn users about possible deadlock still allowing them\n // to explicitly `proxy.invoke().then(...)` without blocking\n let deadlock = 0;\n if (seppuku && isAsync)\n deadlock = setTimeout(console.warn, 1000, `\uD83D\uDC80\uD83D\uDD12 - Possible deadlock if proxy.${action}(...args) is awaited`);\n\n return waitFor(isAsync, sb).value.then(() => {\n clearTimeout(deadlock);\n\n // commit transaction using the returned / needed buffer length\n const length = sb[1];\n\n // filter undefined results\n if (!length) return;\n\n // calculate the needed ui16 bytes length to store the result string\n const bytes = UI16_BYTES * length;\n\n // round up to the next amount of bytes divided by 4 to allow i32 operations\n sb = new Int32Array(new SharedArrayBuffer(bytes + (bytes % I32_BYTES)));\n\n // ask for results and wait for it\n post([], id, sb);\n return waitFor(isAsync, sb).value.then(() => parse(\n decoder.decode(new Uint16Array(sb.buffer).slice(0, length)))\n );\n });\n }),\n\n // main thread related: react to any utility a worker is asking for\n [SET](actions, action, callback) {\n const type = typeof callback;\n if (type !== FUNCTION)\n throw new Error(`Unable to assign ${action} as ${type}`);\n // lazy event listener and logic handling, triggered once by setters actions\n if (!actions.size) {\n // maps results by `id` as they are asked for\n const results = new Map;\n // add the event listener once (first defined setter, all others work the same)\n self.addEventListener('message', async (event) => {\n // grub the very same library CHANNEL; ignore otherwise\n const details = event.data?.[CHANNEL];\n if (isArray(details)) {\n // if early enough, avoid leaking data to other listeners\n event.stopImmediatePropagation();\n const [id, sb, ...rest] = details;\n let error;\n // action available: it must be defined/known on the main thread\n if (rest.length) {\n const [action, args] = rest;\n if (actions.has(action)) {\n seppuku = true;\n try {\n // await for result either sync or async and serialize it\n const result = await actions.get(action)(...args);\n if (result !== void 0) {\n const serialized = stringify(transform ? transform(result) : result);\n // store the result for \"the very next\" event listener call\n results.set(id, serialized);\n // communicate the required SharedArrayBuffer length out of the\n // resulting serialized string\n sb[1] = serialized.length;\n }\n }\n catch (_) {\n error = _;\n }\n finally {\n seppuku = false;\n }\n }\n // unknown action should be notified as missing on the main thread\n else {\n error = new Error(`Unsupported action: ${action}`);\n }\n // unlock the wait lock later on\n sb[0] = 1;\n }\n // no action means: get results out of the well known `id`\n // wait lock automatically unlocked here as no `0` value would\n // possibly ever land at index `0`\n else {\n const result = results.get(id);\n results.delete(id);\n // populate the SharedArrayBuffer with utf-16 chars code\n for (let ui16a = new Uint16Array(sb.buffer), i = 0; i < result.length; i++)\n ui16a[i] = result.charCodeAt(i);\n }\n // release te worker waiting either the length or the result\n notify(sb, 0);\n if (error) throw error;\n }\n });\n }\n // store this action callback allowing the setter in the process\n return !!actions.set(action, callback);\n }\n }));\n }\n return context.get(self);\n};\n\ncoincident.transfer = (...args) => (buffers.add(args), args);\n\nexport default coincident;\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\n/**\n * A WebWorker entrypoint that uses coincident to handle postMessage details\n */\nimport coincident from 'coincident';\n\nimport {\n ContentsAPI,\n DriveFS,\n TDriveMethod,\n TDriveRequest,\n TDriveResponse,\n} from '@jupyterlite/services/lib/contents/drivefs';\n\nimport { ICoincidentPyodideWorkerKernel, IPyodideWorkerKernel } from './tokens';\n\nimport { PyodideRemoteKernel } from './worker';\n\nconst workerAPI = coincident(self) as ICoincidentPyodideWorkerKernel;\n\n/**\n * An Emscripten-compatible synchronous Contents API using shared array buffers.\n */\nexport class SharedBufferContentsAPI extends ContentsAPI {\n request<T extends TDriveMethod>(data: TDriveRequest<T>): TDriveResponse<T> {\n return workerAPI.processDriveRequest(data);\n }\n}\n\n/**\n * A custom drive implementation which uses shared array buffers (via coincident) if available\n */\nclass PyodideDriveFS extends DriveFS {\n createAPI(options: DriveFS.IOptions): ContentsAPI {\n return new SharedBufferContentsAPI(options);\n }\n}\n\nexport class PyodideCoincidentKernel extends PyodideRemoteKernel {\n /**\n * Setup custom Emscripten FileSystem\n */\n protected async initFilesystem(\n options: IPyodideWorkerKernel.IOptions,\n ): Promise<void> {\n if (options.mountDrive) {\n const mountpoint = '/drive';\n const { FS, PATH, ERRNO_CODES } = this._pyodide;\n const { baseUrl } = options;\n\n const driveFS = new PyodideDriveFS({\n FS: FS as any,\n PATH,\n ERRNO_CODES,\n baseUrl,\n driveName: this._driveName,\n mountpoint,\n });\n FS.mkdirTree(mountpoint);\n FS.mount(driveFS, {}, mountpoint);\n FS.chdir(mountpoint);\n this._driveFS = driveFS;\n }\n }\n\n protected sendInputRequest(prompt: string, password: boolean): string | undefined {\n // Input request via SharedArrayBuffer.\n return workerAPI.processStdinRequest({ prompt, password });\n }\n}\n\nconst worker = new PyodideCoincidentKernel();\n\nconst sendWorkerMessage = workerAPI.processWorkerMessage.bind(workerAPI);\nworker.registerWorkerMessageCallback(sendWorkerMessage);\n\nconst logMessage = workerAPI.processLogMessage.bind(workerAPI);\nworker.registerLogMessageCallback(logMessage);\n\nworkerAPI.initialize = worker.initialize.bind(worker);\nworkerAPI.execute = worker.execute.bind(worker);\nworkerAPI.complete = worker.complete.bind(worker);\nworkerAPI.inspect = worker.inspect.bind(worker);\nworkerAPI.isComplete = worker.isComplete.bind(worker);\nworkerAPI.commInfo = worker.commInfo.bind(worker);\nworkerAPI.commOpen = worker.commOpen.bind(worker);\nworkerAPI.commMsg = worker.commMsg.bind(worker);\nworkerAPI.commClose = worker.commClose.bind(worker);\nworkerAPI.inputReply = worker.inputReply.bind(worker);\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\nimport type Pyodide from 'pyodide';\n\nimport type { ILogPayload } from '@jupyterlab/logconsole';\n\nimport { KernelMessage } from '@jupyterlab/services';\n\nimport type { DriveFS } from '@jupyterlite/services/lib/contents/drivefs';\n\nimport type { IPyodideWorkerKernel } from './tokens';\n\nexport abstract class PyodideRemoteKernel {\n constructor() {\n this._initialized = new Promise((resolve, reject) => {\n this._initializer = { resolve, reject };\n });\n }\n\n /**\n * Accept the URLs from the host\n **/\n async initialize(options: IPyodideWorkerKernel.IOptions): Promise<void> {\n this._options = options;\n\n if (options.location.includes(':')) {\n const parts = options.location.split(':');\n this._driveName = parts[0];\n this._localPath = parts[1];\n } else {\n this._driveName = '';\n this._localPath = options.location;\n }\n\n await this.initRuntime(options);\n await this.initFilesystem(options);\n await this.initPackageManager(options);\n await this.initKernel(options);\n await this.initGlobals(options);\n this._initializer?.resolve();\n }\n\n protected async initRuntime(options: IPyodideWorkerKernel.IOptions): Promise<void> {\n const { pyodideUrl, indexUrl } = options;\n let loadPyodide: typeof Pyodide.loadPyodide;\n if (pyodideUrl.endsWith('.mjs')) {\n // note: this does not work at all in firefox\n const pyodideModule: typeof Pyodide = await import(\n /* webpackIgnore: true */ pyodideUrl\n );\n loadPyodide = pyodideModule.loadPyodide;\n } else {\n importScripts(pyodideUrl);\n loadPyodide = (self as any).loadPyodide;\n }\n this._pyodide = await loadPyodide({\n indexURL: indexUrl,\n stdout: (text: string) => {\n console.log(text);\n this._logMessage({ type: 'text', level: 'info', data: text });\n },\n stderr: (text: string) => {\n console.error(text);\n this._logMessage({ type: 'text', level: 'critical', data: text });\n },\n ...options.loadPyodideOptions,\n });\n // @ts-expect-error: pyodide._api is private\n this._pyodide._api.on_fatal = async (e: any) => {\n let error = '';\n if (e.name === 'Exit') {\n error = 'Pyodide has exited and can no longer be used.';\n } else {\n error = `Pyodide has suffered a fatal error. Please report this to the Pyodide maintainers.\nThe cause of the error was: ${e.name}\n${e.message}\nStack trace:\n${e.stack}`;\n }\n this._logMessage({\n type: 'text',\n level: 'critical',\n data: error,\n });\n };\n }\n\n protected async initPackageManager(\n options: IPyodideWorkerKernel.IOptions,\n ): Promise<void> {\n if (!this._options) {\n throw new Error('Uninitialized');\n }\n\n const { pipliteWheelUrl, disablePyPIFallback, pipliteUrls, loadPyodideOptions } =\n this._options;\n\n const preloaded = (loadPyodideOptions || {}).packages || [];\n\n if (!preloaded.includes('micropip')) {\n await this._pyodide.loadPackage(['micropip']);\n }\n\n if (!preloaded.includes('piplite')) {\n await this._pyodide.runPythonAsync(`\n import micropip\n await micropip.install('${pipliteWheelUrl}', keep_going=True)\n `);\n }\n\n // get piplite early enough to impact pyodide-kernel dependencies\n await this._pyodide.runPythonAsync(`\n import piplite.piplite\n piplite.piplite._PIPLITE_DISABLE_PYPI = ${disablePyPIFallback ? 'True' : 'False'}\n piplite.piplite._PIPLITE_URLS = ${JSON.stringify(pipliteUrls)}\n `);\n }\n\n protected async initKernel(options: IPyodideWorkerKernel.IOptions): Promise<void> {\n const preloaded = (options.loadPyodideOptions || {}).packages || [];\n\n const toLoad = [\n 'sqlite3',\n 'ipykernel',\n 'comm',\n 'pyodide_kernel',\n 'jedi',\n 'ipython',\n ];\n\n const scriptLines: string[] = [];\n\n // use piplite for packages that weren't pre-loaded\n for (const pkgName of toLoad) {\n if (!preloaded.includes(pkgName)) {\n scriptLines.push(`await piplite.install('${pkgName}', keep_going=True)`);\n }\n }\n\n // import the kernel\n scriptLines.push('import pyodide_kernel');\n\n // cd to the kernel location\n if (options.mountDrive && this._localPath) {\n scriptLines.push('import os', `os.chdir(\"${this._localPath}\")`);\n }\n\n // from this point forward, only use piplite (but not %pip)\n await this._pyodide.runPythonAsync(scriptLines.join('\\n'));\n }\n\n protected async initGlobals(options: IPyodideWorkerKernel.IOptions): Promise<void> {\n const { globals } = this._pyodide;\n this._kernel = globals.get('pyodide_kernel').kernel_instance.copy();\n this._stdout_stream = globals.get('pyodide_kernel').stdout_stream.copy();\n this._stderr_stream = globals.get('pyodide_kernel').stderr_stream.copy();\n this._interpreter = this._kernel.interpreter.copy();\n this._interpreter.send_comm = this.sendComm.bind(this);\n }\n\n /**\n * Setup custom Emscripten FileSystem\n */\n protected async initFilesystem(\n options: IPyodideWorkerKernel.IOptions,\n ): Promise<void> {\n if (options.mountDrive) {\n const mountpoint = '/drive';\n const { FS, PATH, ERRNO_CODES } = this._pyodide;\n const { baseUrl } = options;\n // Use direct submodule import for tree-shaking\n const { DriveFS } = await import('@jupyterlite/services/lib/contents/drivefs');\n\n const driveFS = new DriveFS({\n FS: FS as any,\n PATH,\n ERRNO_CODES,\n baseUrl,\n driveName: this._driveName,\n mountpoint,\n browsingContextId: this._browsingContextId,\n });\n FS.mkdirTree(mountpoint);\n FS.mount(driveFS, {}, mountpoint);\n FS.chdir(mountpoint);\n this._driveFS = driveFS;\n }\n }\n\n /**\n * Recursively convert a Map to a JavaScript object\n * @param obj A Map, Array, or other object to convert\n */\n mapToObject(obj: any) {\n const out: any = obj instanceof Array ? [] : {};\n const entries = obj instanceof Map ? obj.entries() : Object.entries(obj);\n for (const [key, value] of entries) {\n out[key] =\n value instanceof Map || value instanceof Array\n ? this.mapToObject(value)\n : value;\n }\n return out;\n }\n\n /**\n * Format the response from the Pyodide evaluation.\n *\n * @param res The result object from the Pyodide evaluation\n */\n formatResult(res: any): any {\n if (!(res instanceof this._pyodide.ffi.PyProxy)) {\n return res;\n }\n // TODO: this is a bit brittle\n const m = res.toJs();\n const results = this.mapToObject(m);\n return results;\n }\n\n /**\n * Register the callback function to send messages from the worker back to the main thread.\n *\n * @param callback the callback to register\n */\n registerWorkerMessageCallback(callback: (msg: any) => void): void {\n this._sendWorkerMessage = callback;\n }\n\n /**\n * Register the callback function to log messages from the worker back to the main thread.\n *\n * @param callback the callback to register\n */\n registerLogMessageCallback(callback: (msg: any) => void): void {\n this._logMessage = callback;\n }\n\n /**\n * Makes sure pyodide is ready before continuing, and cache the parent message.\n */\n async setup(parent: any): Promise<void> {\n await this._initialized;\n this._kernel._parent_header = this._pyodide.toPy(parent);\n }\n\n /**\n * Execute code with the interpreter.\n *\n * @param content The incoming message with the code to execute.\n */\n async execute(content: any, parent: any) {\n await this.setup(parent);\n\n const publishExecutionResult = (\n prompt_count: any,\n data: any,\n metadata: any,\n ): void => {\n const bundle = {\n execution_count: prompt_count,\n data: this.formatResult(data),\n metadata: this.formatResult(metadata),\n };\n\n this._sendWorkerMessage({\n parentHeader: this.formatResult(this._kernel._parent_header)['header'],\n bundle,\n type: 'execute_result',\n });\n };\n\n const publishExecutionError = (ename: any, evalue: any, traceback: any): void => {\n const bundle = {\n ename: ename,\n evalue: evalue,\n traceback: traceback,\n };\n\n this._sendWorkerMessage({\n parentHeader: this.formatResult(this._kernel._parent_header)['header'],\n bundle,\n type: 'execute_error',\n });\n };\n\n const clearOutputCallback = (wait: boolean): void => {\n const bundle = {\n wait: this.formatResult(wait),\n };\n\n this._sendWorkerMessage({\n parentHeader: this.formatResult(this._kernel._parent_header)['header'],\n bundle,\n type: 'clear_output',\n });\n };\n\n const displayDataCallback = (data: any, metadata: any, transient: any): void => {\n const bundle = {\n data: this.formatResult(data),\n metadata: this.formatResult(metadata),\n transient: this.formatResult(transient),\n };\n\n this._sendWorkerMessage({\n parentHeader: this.formatResult(this._kernel._parent_header)['header'],\n bundle,\n type: 'display_data',\n });\n };\n\n const updateDisplayDataCallback = (\n data: any,\n metadata: any,\n transient: any,\n ): void => {\n const bundle = {\n data: this.formatResult(data),\n metadata: this.formatResult(metadata),\n transient: this.formatResult(transient),\n };\n\n this._sendWorkerMessage({\n parentHeader: this.formatResult(this._kernel._parent_header)['header'],\n bundle,\n type: 'update_display_data',\n });\n };\n\n const publishStreamCallback = (name: any, text: any): void => {\n const bundle = {\n name: this.formatResult(name),\n text: this.formatResult(text),\n };\n\n this._sendWorkerMessage({\n parentHeader: this.formatResult(this._kernel._parent_header)['header'],\n bundle,\n type: 'stream',\n });\n };\n\n this._stdout_stream.publish_stream_callback = publishStreamCallback;\n this._stderr_stream.publish_stream_callback = publishStreamCallback;\n this._interpreter.display_pub.clear_output_callback = clearOutputCallback;\n this._interpreter.display_pub.display_data_callback = displayDataCallback;\n this._interpreter.display_pub.update_display_data_callback =\n updateDisplayDataCallback;\n this._interpreter.displayhook.publish_execution_result = publishExecutionResult;\n this._interpreter.input = this.input.bind(this);\n this._interpreter.getpass = this.getpass.bind(this);\n\n const res = await this._kernel.run(content.code);\n const results = this.formatResult(res);\n\n if (results['status'] === 'error') {\n publishExecutionError(results['ename'], results['evalue'], results['traceback']);\n }\n\n return results;\n }\n\n /**\n * Complete the code submitted by a user.\n *\n * @param content The incoming message with the code to complete.\n */\n async complete(content: any, parent: any) {\n await this.setup(parent);\n\n const res = this._kernel.complete(content.code, content.cursor_pos);\n const results = this.formatResult(res);\n return results;\n }\n\n /**\n * Inspect the code submitted by a user.\n *\n * @param content The incoming message with the code to inspect.\n */\n async inspect(\n content: { code: string; cursor_pos: number; detail_level: 0 | 1 },\n parent: any,\n ) {\n await this.setup(parent);\n\n const res = this._kernel.inspect(\n content.code,\n content.cursor_pos,\n content.detail_level,\n );\n const results = this.formatResult(res);\n return results;\n }\n\n /**\n * Check code for completeness submitted by a user.\n *\n * @param content The incoming message with the code to check.\n */\n async isComplete(content: { code: string }, parent: any) {\n await this.setup(parent);\n\n const res = this._kernel.is_complete(content.code);\n const results = this.formatResult(res);\n return results;\n }\n\n /**\n * Respond to the commInfoRequest.\n *\n * @param content The incoming message with the comm target name.\n */\n async commInfo(\n content: any,\n parent: any,\n ): Promise<KernelMessage.ICommInfoReplyMsg['content']> {\n await this.setup(parent);\n\n const res = this._kernel.comm_info(content.target_name);\n const results = this.formatResult(res);\n\n return {\n comms: results,\n status: 'ok',\n };\n }\n\n /**\n * Respond to the commOpen.\n *\n * @param content The incoming message with the comm open.\n */\n async commOpen(content: any, parent: any) {\n await this.setup(parent);\n\n const res = this._kernel.comm_manager.comm_open(\n this._pyodide.toPy(null),\n this._pyodide.toPy(null),\n this._pyodide.toPy(content),\n );\n const results = this.formatResult(res);\n\n return results;\n }\n\n /**\n * Respond to the commMsg.\n *\n * @param content The incoming message with the comm msg.\n */\n async commMsg(content: any, parent: any) {\n await this.setup(parent);\n\n const res = this._kernel.comm_manager.comm_msg(\n this._pyodide.toPy(null),\n this._pyodide.toPy(null),\n this._pyodide.toPy(content),\n );\n const results = this.formatResult(res);\n\n return results;\n }\n\n /**\n * Respond to the commClose.\n *\n * @param content The incoming message with the comm close.\n */\n async commClose(content: any, parent: any) {\n await this.setup(parent);\n\n const res = this._kernel.comm_manager.comm_close(\n this._pyodide.toPy(null),\n this._pyodide.toPy(null),\n this._pyodide.toPy(content),\n );\n const results = this.formatResult(res);\n\n return results;\n }\n\n /**\n * Resolve the input request by getting back the reply from the main thread\n *\n * @param content The incoming message with the reply\n */\n async inputReply(content: any, parent: any) {\n // Should never be called as input_reply messages are returned via service worker\n // or SharedArrayBuffer.\n }\n\n /**\n * Send a input request to the front-end and block until the reply is received.\n *\n * @param prompt the text to show at the prompt\n * @param password Is the request for a password?\n * @returns String value from the input reply message, or undefined if there is none.\n */\n protected abstract sendInputRequest(\n prompt: string,\n password: boolean,\n ): string | undefined;\n\n getpass(prompt: string): string | undefined {\n prompt = typeof prompt === 'undefined' ? '' : prompt;\n return this.sendInputRequest(prompt, true);\n }\n\n input(prompt: string): string | undefined {\n prompt = typeof prompt === 'undefined' ? '' : prompt;\n return this.sendInputRequest(prompt, false);\n }\n\n /**\n * Send a comm message to the front-end.\n *\n * @param type The type of the comm message.\n * @param content The content.\n * @param metadata The metadata.\n * @param ident The ident.\n * @param buffers The binary buffers.\n */\n async sendComm(type: string, content: any, metadata: any, ident: any, buffers: any) {\n this._sendWorkerMessage({\n type: type,\n content: this.formatResult(content),\n metadata: this.formatResult(metadata),\n ident: this.formatResult(ident),\n buffers: this.formatResult(buffers),\n parentHeader: this.formatResult(this._kernel._parent_header)['header'],\n });\n }\n\n /**\n * Initialization options.\n */\n protected _options: IPyodideWorkerKernel.IOptions | null = null;\n /**\n * A promise that resolves when all initiaization is complete.\n */\n protected _initialized: Promise<void>;\n private _initializer: {\n reject: () => void;\n resolve: () => void;\n } | null = null;\n protected _pyodide: Pyodide.PyodideAPI = null as any;\n /** TODO: real typing */\n protected _localPath = '';\n protected _driveName = '';\n protected _browsingContextId: string | undefined;\n protected _kernel: any;\n protected _interpreter: any;\n protected _stdout_stream: any;\n protected _stderr_stream: any;\n protected _driveFS: DriveFS | null = null;\n protected _sendWorkerMessage: (msg: any) => void = () => {};\n protected _logMessage: (msg: ILogPayload) => void = () => {};\n}\n"],
|
|
5
|
-
"mappings": "o3BAaiBA,EAAAA,SAAAA,OAAjB,SAAiBA,EAAQ,CAyCvB,SAAgBC,EACdC,EACAC,EACAC,EAAQ,EACRC,EAAO,GAAE,CAET,IAAIC,EAAIJ,EAAM,OACd,GAAII,IAAM,EACR,MAAO,GAELF,EAAQ,EACVA,EAAQ,KAAK,IAAI,EAAGA,EAAQE,CAAC,EAE7BF,EAAQ,KAAK,IAAIA,EAAOE,EAAI,CAAC,EAE3BD,EAAO,EACTA,EAAO,KAAK,IAAI,EAAGA,EAAO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,GAEbW,GAAoBnB,EAAU,qBAAqB,KAAKA,CAAS,EACvEkB,EAAO,8BAA8BC,EAAiB,EAEtD,IAAMC,GAAapB,EAAU,kBAAkB,KAAKA,CAAS,EAC7DkB,EAAO,2BAA2BE,EAAU,EAE5CpB,EAAU,WAAakB,EAAO,WAAW,KAAKA,CAAM,EACpDlB,EAAU,QAAUkB,EAAO,QAAQ,KAAKA,CAAM,EAC9ClB,EAAU,SAAWkB,EAAO,SAAS,KAAKA,CAAM,EAChDlB,EAAU,QAAUkB,EAAO,QAAQ,KAAKA,CAAM,EAC9ClB,EAAU,WAAakB,EAAO,WAAW,KAAKA,CAAM,EACpDlB,EAAU,SAAWkB,EAAO,SAAS,KAAKA,CAAM,EAChDlB,EAAU,SAAWkB,EAAO,SAAS,KAAKA,CAAM,EAChDlB,EAAU,QAAUkB,EAAO,QAAQ,KAAKA,CAAM,EAC9ClB,EAAU,UAAYkB,EAAO,UAAU,KAAKA,CAAM,EAClDlB,EAAU,WAAakB,EAAO,WAAW,KAAKA,CAAM",
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * The namespace for array-specific algorithms.\n */\nexport namespace ArrayExt {\n /**\n * Find the index of the first occurrence of a value in an array.\n *\n * @param array - The array-like object to search.\n *\n * @param value - The value to locate in the array. Values are\n * compared using strict `===` equality.\n *\n * @param start - The index of the first element in the range to be\n * searched, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * searched, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @returns The index of the first occurrence of the value, or `-1`\n * if the value is not found.\n *\n * #### Notes\n * If `stop < start` the search will wrap at the end of the array.\n *\n * #### Complexity\n * Linear.\n *\n * #### Undefined Behavior\n * A `start` or `stop` which is non-integral.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * let data = ['one', 'two', 'three', 'four', 'one'];\n * ArrayExt.firstIndexOf(data, 'red'); // -1\n * ArrayExt.firstIndexOf(data, 'one'); // 0\n * ArrayExt.firstIndexOf(data, 'one', 1); // 4\n * ArrayExt.firstIndexOf(data, 'two', 2); // -1\n * ArrayExt.firstIndexOf(data, 'two', 2, 1); // 1\n * ```\n */\n export function firstIndexOf<T>(\n array: ArrayLike<T>,\n value: T,\n start = 0,\n stop = -1\n ): number {\n let n = array.length;\n if (n === 0) {\n return -1;\n }\n if (start < 0) {\n start = Math.max(0, start + n);\n } else {\n start = Math.min(start, n - 1);\n }\n if (stop < 0) {\n stop = Math.max(0, stop + n);\n } else {\n stop = Math.min(stop, n - 1);\n }\n let span: number;\n if (stop < start) {\n span = stop + 1 + (n - start);\n } else {\n span = stop - start + 1;\n }\n for (let i = 0; i < span; ++i) {\n let j = (start + i) % n;\n if (array[j] === value) {\n return j;\n }\n }\n return -1;\n }\n\n /**\n * Find the index of the last occurrence of a value in an array.\n *\n * @param array - The array-like object to search.\n *\n * @param value - The value to locate in the array. Values are\n * compared using strict `===` equality.\n *\n * @param start - The index of the first element in the range to be\n * searched, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * searched, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @returns The index of the last occurrence of the value, or `-1`\n * if the value is not found.\n *\n * #### Notes\n * If `start < stop` the search will wrap at the front of the array.\n *\n * #### Complexity\n * Linear.\n *\n * #### Undefined Behavior\n * A `start` or `stop` which is non-integral.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * let data = ['one', 'two', 'three', 'four', 'one'];\n * ArrayExt.lastIndexOf(data, 'red'); // -1\n * ArrayExt.lastIndexOf(data, 'one'); // 4\n * ArrayExt.lastIndexOf(data, 'one', 1); // 0\n * ArrayExt.lastIndexOf(data, 'two', 0); // -1\n * ArrayExt.lastIndexOf(data, 'two', 0, 1); // 1\n * ```\n */\n export function lastIndexOf<T>(\n array: ArrayLike<T>,\n value: T,\n start = -1,\n stop = 0\n ): number {\n let n = array.length;\n if (n === 0) {\n return -1;\n }\n if (start < 0) {\n start = Math.max(0, start + n);\n } else {\n start = Math.min(start, n - 1);\n }\n if (stop < 0) {\n stop = Math.max(0, stop + n);\n } else {\n stop = Math.min(stop, n - 1);\n }\n let span: number;\n if (start < stop) {\n span = start + 1 + (n - stop);\n } else {\n span = start - stop + 1;\n }\n for (let i = 0; i < span; ++i) {\n let j = (start - i + n) % n;\n if (array[j] === value) {\n return j;\n }\n }\n return -1;\n }\n\n /**\n * Find the index of the first value which matches a predicate.\n *\n * @param array - The array-like object to search.\n *\n * @param fn - The predicate function to apply to the values.\n *\n * @param start - The index of the first element in the range to be\n * searched, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * searched, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @returns The index of the first matching value, or `-1` if no\n * matching value is found.\n *\n * #### Notes\n * If `stop < start` the search will wrap at the end of the array.\n *\n * #### Complexity\n * Linear.\n *\n * #### Undefined Behavior\n * A `start` or `stop` which is non-integral.\n *\n * Modifying the length of the array while searching.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * function isEven(value: number): boolean {\n * return value % 2 === 0;\n * }\n *\n * let data = [1, 2, 3, 4, 3, 2, 1];\n * ArrayExt.findFirstIndex(data, isEven); // 1\n * ArrayExt.findFirstIndex(data, isEven, 4); // 5\n * ArrayExt.findFirstIndex(data, isEven, 6); // -1\n * ArrayExt.findFirstIndex(data, isEven, 6, 5); // 1\n * ```\n */\n export function findFirstIndex<T>(\n array: ArrayLike<T>,\n fn: (value: T, index: number) => boolean,\n start = 0,\n stop = -1\n ): number {\n let n = array.length;\n if (n === 0) {\n return -1;\n }\n if (start < 0) {\n start = Math.max(0, start + n);\n } else {\n start = Math.min(start, n - 1);\n }\n if (stop < 0) {\n stop = Math.max(0, stop + n);\n } else {\n stop = Math.min(stop, n - 1);\n }\n let span: number;\n if (stop < start) {\n span = stop + 1 + (n - start);\n } else {\n span = stop - start + 1;\n }\n for (let i = 0; i < span; ++i) {\n let j = (start + i) % n;\n if (fn(array[j], j)) {\n return j;\n }\n }\n return -1;\n }\n\n /**\n * Find the index of the last value which matches a predicate.\n *\n * @param array - The array-like object to search.\n *\n * @param fn - The predicate function to apply to the values.\n *\n * @param start - The index of the first element in the range to be\n * searched, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * searched, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @returns The index of the last matching value, or `-1` if no\n * matching value is found.\n *\n * #### Notes\n * If `start < stop` the search will wrap at the front of the array.\n *\n * #### Complexity\n * Linear.\n *\n * #### Undefined Behavior\n * A `start` or `stop` which is non-integral.\n *\n * Modifying the length of the array while searching.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * function isEven(value: number): boolean {\n * return value % 2 === 0;\n * }\n *\n * let data = [1, 2, 3, 4, 3, 2, 1];\n * ArrayExt.findLastIndex(data, isEven); // 5\n * ArrayExt.findLastIndex(data, isEven, 4); // 3\n * ArrayExt.findLastIndex(data, isEven, 0); // -1\n * ArrayExt.findLastIndex(data, isEven, 0, 1); // 5\n * ```\n */\n export function findLastIndex<T>(\n array: ArrayLike<T>,\n fn: (value: T, index: number) => boolean,\n start = -1,\n stop = 0\n ): number {\n let n = array.length;\n if (n === 0) {\n return -1;\n }\n if (start < 0) {\n start = Math.max(0, start + n);\n } else {\n start = Math.min(start, n - 1);\n }\n if (stop < 0) {\n stop = Math.max(0, stop + n);\n } else {\n stop = Math.min(stop, n - 1);\n }\n let d: number;\n if (start < stop) {\n d = start + 1 + (n - stop);\n } else {\n d = start - stop + 1;\n }\n for (let i = 0; i < d; ++i) {\n let j = (start - i + n) % n;\n if (fn(array[j], j)) {\n return j;\n }\n }\n return -1;\n }\n\n /**\n * Find the first value which matches a predicate.\n *\n * @param array - The array-like object to search.\n *\n * @param fn - The predicate function to apply to the values.\n *\n * @param start - The index of the first element in the range to be\n * searched, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * searched, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @returns The first matching value, or `undefined` if no matching\n * value is found.\n *\n * #### Notes\n * If `stop < start` the search will wrap at the end of the array.\n *\n * #### Complexity\n * Linear.\n *\n * #### Undefined Behavior\n * A `start` or `stop` which is non-integral.\n *\n * Modifying the length of the array while searching.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * function isEven(value: number): boolean {\n * return value % 2 === 0;\n * }\n *\n * let data = [1, 2, 3, 4, 3, 2, 1];\n * ArrayExt.findFirstValue(data, isEven); // 2\n * ArrayExt.findFirstValue(data, isEven, 2); // 4\n * ArrayExt.findFirstValue(data, isEven, 6); // undefined\n * ArrayExt.findFirstValue(data, isEven, 6, 5); // 2\n * ```\n */\n export function findFirstValue<T>(\n array: ArrayLike<T>,\n fn: (value: T, index: number) => boolean,\n start = 0,\n stop = -1\n ): T | undefined {\n let index = findFirstIndex(array, fn, start, stop);\n return index !== -1 ? array[index] : undefined;\n }\n\n /**\n * Find the last value which matches a predicate.\n *\n * @param object - The array-like object to search.\n *\n * @param fn - The predicate function to apply to the values.\n *\n * @param start - The index of the first element in the range to be\n * searched, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * searched, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @returns The last matching value, or `undefined` if no matching\n * value is found.\n *\n * #### Notes\n * If `start < stop` the search will wrap at the front of the array.\n *\n * #### Complexity\n * Linear.\n *\n * #### Undefined Behavior\n * A `start` or `stop` which is non-integral.\n *\n * Modifying the length of the array while searching.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * function isEven(value: number): boolean {\n * return value % 2 === 0;\n * }\n *\n * let data = [1, 2, 3, 4, 3, 2, 1];\n * ArrayExt.findLastValue(data, isEven); // 2\n * ArrayExt.findLastValue(data, isEven, 4); // 4\n * ArrayExt.findLastValue(data, isEven, 0); // undefined\n * ArrayExt.findLastValue(data, isEven, 0, 1); // 2\n * ```\n */\n export function findLastValue<T>(\n array: ArrayLike<T>,\n fn: (value: T, index: number) => boolean,\n start = -1,\n stop = 0\n ): T | undefined {\n let index = findLastIndex(array, fn, start, stop);\n return index !== -1 ? array[index] : undefined;\n }\n\n /**\n * Find the index of the first element which compares `>=` to a value.\n *\n * @param array - The sorted array-like object to search.\n *\n * @param value - The value to locate in the array.\n *\n * @param fn - The 3-way comparison function to apply to the values.\n * It should return `< 0` if an element is less than a value, `0` if\n * an element is equal to a value, or `> 0` if an element is greater\n * than a value.\n *\n * @param start - The index of the first element in the range to be\n * searched, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * searched, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @returns The index of the first element which compares `>=` to the\n * value, or `length` if there is no such element. If the computed\n * index for `stop` is less than `start`, then the computed index\n * for `start` is returned.\n *\n * #### Notes\n * The array must already be sorted in ascending order according to\n * the comparison function.\n *\n * #### Complexity\n * Logarithmic.\n *\n * #### Undefined Behavior\n * Searching a range which is not sorted in ascending order.\n *\n * A `start` or `stop` which is non-integral.\n *\n * Modifying the length of the array while searching.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * function numberCmp(a: number, b: number): number {\n * return a - b;\n * }\n *\n * let data = [0, 3, 4, 7, 7, 9];\n * ArrayExt.lowerBound(data, 0, numberCmp); // 0\n * ArrayExt.lowerBound(data, 6, numberCmp); // 3\n * ArrayExt.lowerBound(data, 7, numberCmp); // 3\n * ArrayExt.lowerBound(data, -1, numberCmp); // 0\n * ArrayExt.lowerBound(data, 10, numberCmp); // 6\n * ```\n */\n export function lowerBound<T, U>(\n array: ArrayLike<T>,\n value: U,\n fn: (element: T, value: U) => number,\n start = 0,\n stop = -1\n ): number {\n let n = array.length;\n if (n === 0) {\n return 0;\n }\n if (start < 0) {\n start = Math.max(0, start + n);\n } else {\n start = Math.min(start, n - 1);\n }\n if (stop < 0) {\n stop = Math.max(0, stop + n);\n } else {\n stop = Math.min(stop, n - 1);\n }\n let begin = start;\n let span = stop - start + 1;\n while (span > 0) {\n let half = span >> 1;\n let middle = begin + half;\n if (fn(array[middle], value) < 0) {\n begin = middle + 1;\n span -= half + 1;\n } else {\n span = half;\n }\n }\n return begin;\n }\n\n /**\n * Find the index of the first element which compares `>` than a value.\n *\n * @param array - The sorted array-like object to search.\n *\n * @param value - The value to locate in the array.\n *\n * @param fn - The 3-way comparison function to apply to the values.\n * It should return `< 0` if an element is less than a value, `0` if\n * an element is equal to a value, or `> 0` if an element is greater\n * than a value.\n *\n * @param start - The index of the first element in the range to be\n * searched, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * searched, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @returns The index of the first element which compares `>` than the\n * value, or `length` if there is no such element. If the computed\n * index for `stop` is less than `start`, then the computed index\n * for `start` is returned.\n *\n * #### Notes\n * The array must already be sorted in ascending order according to\n * the comparison function.\n *\n * #### Complexity\n * Logarithmic.\n *\n * #### Undefined Behavior\n * Searching a range which is not sorted in ascending order.\n *\n * A `start` or `stop` which is non-integral.\n *\n * Modifying the length of the array while searching.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * function numberCmp(a: number, b: number): number {\n * return a - b;\n * }\n *\n * let data = [0, 3, 4, 7, 7, 9];\n * ArrayExt.upperBound(data, 0, numberCmp); // 1\n * ArrayExt.upperBound(data, 6, numberCmp); // 3\n * ArrayExt.upperBound(data, 7, numberCmp); // 5\n * ArrayExt.upperBound(data, -1, numberCmp); // 0\n * ArrayExt.upperBound(data, 10, numberCmp); // 6\n * ```\n */\n export function upperBound<T, U>(\n array: ArrayLike<T>,\n value: U,\n fn: (element: T, value: U) => number,\n start = 0,\n stop = -1\n ): number {\n let n = array.length;\n if (n === 0) {\n return 0;\n }\n if (start < 0) {\n start = Math.max(0, start + n);\n } else {\n start = Math.min(start, n - 1);\n }\n if (stop < 0) {\n stop = Math.max(0, stop + n);\n } else {\n stop = Math.min(stop, n - 1);\n }\n let begin = start;\n let span = stop - start + 1;\n while (span > 0) {\n let half = span >> 1;\n let middle = begin + half;\n if (fn(array[middle], value) > 0) {\n span = half;\n } else {\n begin = middle + 1;\n span -= half + 1;\n }\n }\n return begin;\n }\n\n /**\n * Test whether two arrays are shallowly equal.\n *\n * @param a - The first array-like object to compare.\n *\n * @param b - The second array-like object to compare.\n *\n * @param fn - The comparison function to apply to the elements. It\n * should return `true` if the elements are \"equal\". The default\n * compares elements using strict `===` equality.\n *\n * @returns Whether the two arrays are shallowly equal.\n *\n * #### Complexity\n * Linear.\n *\n * #### Undefined Behavior\n * Modifying the length of the arrays while comparing.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * let d1 = [0, 3, 4, 7, 7, 9];\n * let d2 = [0, 3, 4, 7, 7, 9];\n * let d3 = [42];\n * ArrayExt.shallowEqual(d1, d2); // true\n * ArrayExt.shallowEqual(d2, d3); // false\n * ```\n */\n export function shallowEqual<T>(\n a: ArrayLike<T>,\n b: ArrayLike<T>,\n fn?: (a: T, b: T) => boolean\n ): boolean {\n // Check for object identity first.\n if (a === b) {\n return true;\n }\n\n // Bail early if the lengths are different.\n if (a.length !== b.length) {\n return false;\n }\n\n // Compare each element for equality.\n for (let i = 0, n = a.length; i < n; ++i) {\n if (fn ? !fn(a[i], b[i]) : a[i] !== b[i]) {\n return false;\n }\n }\n\n // The array are shallowly equal.\n return true;\n }\n\n /**\n * Create a slice of an array subject to an optional step.\n *\n * @param array - The array-like object of interest.\n *\n * @param options - The options for configuring the slice.\n *\n * @returns A new array with the specified values.\n *\n * @throws An exception if the slice `step` is `0`.\n *\n * #### Complexity\n * Linear.\n *\n * #### Undefined Behavior\n * A `start`, `stop`, or `step` which is non-integral.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * let data = [0, 3, 4, 7, 7, 9];\n * ArrayExt.slice(data); // [0, 3, 4, 7, 7, 9]\n * ArrayExt.slice(data, { start: 2 }); // [4, 7, 7, 9]\n * ArrayExt.slice(data, { start: 0, stop: 4 }); // [0, 3, 4, 7]\n * ArrayExt.slice(data, { step: 2 }); // [0, 4, 7]\n * ArrayExt.slice(data, { step: -1 }); // [9, 7, 7, 4, 3, 0]\n * ```\n */\n export function slice<T>(\n array: ArrayLike<T>,\n options: slice.IOptions = {}\n ): T[] {\n // Extract the options.\n let { start, stop, step } = options;\n\n // Set up the `step` value.\n if (step === undefined) {\n step = 1;\n }\n\n // Validate the step size.\n if (step === 0) {\n throw new Error('Slice `step` cannot be zero.');\n }\n\n // Look up the length of the array.\n let n = array.length;\n\n // Set up the `start` value.\n if (start === undefined) {\n start = step < 0 ? n - 1 : 0;\n } else if (start < 0) {\n start = Math.max(start + n, step < 0 ? -1 : 0);\n } else if (start >= n) {\n start = step < 0 ? n - 1 : n;\n }\n\n // Set up the `stop` value.\n if (stop === undefined) {\n stop = step < 0 ? -1 : n;\n } else if (stop < 0) {\n stop = Math.max(stop + n, step < 0 ? -1 : 0);\n } else if (stop >= n) {\n stop = step < 0 ? n - 1 : n;\n }\n\n // Compute the slice length.\n let length;\n if ((step < 0 && stop >= start) || (step > 0 && start >= stop)) {\n length = 0;\n } else if (step < 0) {\n length = Math.floor((stop - start + 1) / step + 1);\n } else {\n length = Math.floor((stop - start - 1) / step + 1);\n }\n\n // Compute the sliced result.\n let result: T[] = [];\n for (let i = 0; i < length; ++i) {\n result[i] = array[start + i * step];\n }\n\n // Return the result.\n return result;\n }\n\n /**\n * The namespace for the `slice` function statics.\n */\n export namespace slice {\n /**\n * The options for the `slice` function.\n */\n export interface IOptions {\n /**\n * The starting index of the slice, inclusive.\n *\n * Negative values are taken as an offset from the end\n * of the array.\n *\n * The default is `0` if `step > 0` else `n - 1`.\n */\n start?: number;\n\n /**\n * The stopping index of the slice, exclusive.\n *\n * Negative values are taken as an offset from the end\n * of the array.\n *\n * The default is `n` if `step > 0` else `-n - 1`.\n */\n stop?: number;\n\n /**\n * The step value for the slice.\n *\n * This must not be `0`.\n *\n * The default is `1`.\n */\n step?: number;\n }\n }\n\n /**\n * An array-like object which supports item assignment.\n */\n export type MutableArrayLike<T> = {\n readonly length: number;\n [index: number]: T;\n };\n\n /**\n * Move an element in an array from one index to another.\n *\n * @param array - The mutable array-like object of interest.\n *\n * @param fromIndex - The index of the element to move. Negative\n * values are taken as an offset from the end of the array.\n *\n * @param toIndex - The target index of the element. Negative\n * values are taken as an offset from the end of the array.\n *\n * #### Complexity\n * Linear.\n *\n * #### Undefined Behavior\n * A `fromIndex` or `toIndex` which is non-integral.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * let data = [0, 1, 2, 3, 4];\n * ArrayExt.move(data, 1, 2); // [0, 2, 1, 3, 4]\n * ArrayExt.move(data, 4, 2); // [0, 2, 4, 1, 3]\n * ```\n */\n export function move<T>(\n array: MutableArrayLike<T>,\n fromIndex: number,\n toIndex: number\n ): void {\n let n = array.length;\n if (n <= 1) {\n return;\n }\n if (fromIndex < 0) {\n fromIndex = Math.max(0, fromIndex + n);\n } else {\n fromIndex = Math.min(fromIndex, n - 1);\n }\n if (toIndex < 0) {\n toIndex = Math.max(0, toIndex + n);\n } else {\n toIndex = Math.min(toIndex, n - 1);\n }\n if (fromIndex === toIndex) {\n return;\n }\n let value = array[fromIndex];\n let d = fromIndex < toIndex ? 1 : -1;\n for (let i = fromIndex; i !== toIndex; i += d) {\n array[i] = array[i + d];\n }\n array[toIndex] = value;\n }\n\n /**\n * Reverse an array in-place.\n *\n * @param array - The mutable array-like object of interest.\n *\n * @param start - The index of the first element in the range to be\n * reversed, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * reversed, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * #### Complexity\n * Linear.\n *\n * #### Undefined Behavior\n * A `start` or `stop` index which is non-integral.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * let data = [0, 1, 2, 3, 4];\n * ArrayExt.reverse(data, 1, 3); // [0, 3, 2, 1, 4]\n * ArrayExt.reverse(data, 3); // [0, 3, 2, 4, 1]\n * ArrayExt.reverse(data); // [1, 4, 2, 3, 0]\n * ```\n */\n export function reverse<T>(\n array: MutableArrayLike<T>,\n start = 0,\n stop = -1\n ): void {\n let n = array.length;\n if (n <= 1) {\n return;\n }\n if (start < 0) {\n start = Math.max(0, start + n);\n } else {\n start = Math.min(start, n - 1);\n }\n if (stop < 0) {\n stop = Math.max(0, stop + n);\n } else {\n stop = Math.min(stop, n - 1);\n }\n while (start < stop) {\n let a = array[start];\n let b = array[stop];\n array[start++] = b;\n array[stop--] = a;\n }\n }\n\n /**\n * Rotate the elements of an array in-place.\n *\n * @param array - The mutable array-like object of interest.\n *\n * @param delta - The amount of rotation to apply to the elements. A\n * positive value will rotate the elements to the left. A negative\n * value will rotate the elements to the right.\n *\n * @param start - The index of the first element in the range to be\n * rotated, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * rotated, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * #### Complexity\n * Linear.\n *\n * #### Undefined Behavior\n * A `delta`, `start`, or `stop` which is non-integral.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * let data = [0, 1, 2, 3, 4];\n * ArrayExt.rotate(data, 2); // [2, 3, 4, 0, 1]\n * ArrayExt.rotate(data, -2); // [0, 1, 2, 3, 4]\n * ArrayExt.rotate(data, 10); // [0, 1, 2, 3, 4]\n * ArrayExt.rotate(data, 9); // [4, 0, 1, 2, 3]\n * ArrayExt.rotate(data, 2, 1, 3); // [4, 2, 0, 1, 3]\n * ```\n */\n export function rotate<T>(\n array: MutableArrayLike<T>,\n delta: number,\n start = 0,\n stop = -1\n ): void {\n let n = array.length;\n if (n <= 1) {\n return;\n }\n if (start < 0) {\n start = Math.max(0, start + n);\n } else {\n start = Math.min(start, n - 1);\n }\n if (stop < 0) {\n stop = Math.max(0, stop + n);\n } else {\n stop = Math.min(stop, n - 1);\n }\n if (start >= stop) {\n return;\n }\n let length = stop - start + 1;\n if (delta > 0) {\n delta = delta % length;\n } else if (delta < 0) {\n delta = ((delta % length) + length) % length;\n }\n if (delta === 0) {\n return;\n }\n let pivot = start + delta;\n reverse(array, start, pivot - 1);\n reverse(array, pivot, stop);\n reverse(array, start, stop);\n }\n\n /**\n * Fill an array with a static value.\n *\n * @param array - The mutable array-like object to fill.\n *\n * @param value - The static value to use to fill the array.\n *\n * @param start - The index of the first element in the range to be\n * filled, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * filled, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * #### Notes\n * If `stop < start` the fill will wrap at the end of the array.\n *\n * #### Complexity\n * Linear.\n *\n * #### Undefined Behavior\n * A `start` or `stop` which is non-integral.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * let data = ['one', 'two', 'three', 'four'];\n * ArrayExt.fill(data, 'r'); // ['r', 'r', 'r', 'r']\n * ArrayExt.fill(data, 'g', 1); // ['r', 'g', 'g', 'g']\n * ArrayExt.fill(data, 'b', 2, 3); // ['r', 'g', 'b', 'b']\n * ArrayExt.fill(data, 'z', 3, 1); // ['z', 'z', 'b', 'z']\n * ```\n */\n export function fill<T>(\n array: MutableArrayLike<T>,\n value: T,\n start = 0,\n stop = -1\n ): void {\n let n = array.length;\n if (n === 0) {\n return;\n }\n if (start < 0) {\n start = Math.max(0, start + n);\n } else {\n start = Math.min(start, n - 1);\n }\n if (stop < 0) {\n stop = Math.max(0, stop + n);\n } else {\n stop = Math.min(stop, n - 1);\n }\n let span: number;\n if (stop < start) {\n span = stop + 1 + (n - start);\n } else {\n span = stop - start + 1;\n }\n for (let i = 0; i < span; ++i) {\n array[(start + i) % n] = value;\n }\n }\n\n /**\n * Insert a value into an array at a specific index.\n *\n * @param array - The array of interest.\n *\n * @param index - The index at which to insert the value. Negative\n * values are taken as an offset from the end of the array.\n *\n * @param value - The value to set at the specified index.\n *\n * #### Complexity\n * Linear.\n *\n * #### Undefined Behavior\n * An `index` which is non-integral.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * let data = [0, 1, 2];\n * ArrayExt.insert(data, 0, -1); // [-1, 0, 1, 2]\n * ArrayExt.insert(data, 2, 12); // [-1, 0, 12, 1, 2]\n * ArrayExt.insert(data, -1, 7); // [-1, 0, 12, 1, 7, 2]\n * ArrayExt.insert(data, 6, 19); // [-1, 0, 12, 1, 7, 2, 19]\n * ```\n */\n export function insert<T>(array: Array<T>, index: number, value: T): void {\n let n = array.length;\n if (index < 0) {\n index = Math.max(0, index + n);\n } else {\n index = Math.min(index, n);\n }\n for (let i = n; i > index; --i) {\n array[i] = array[i - 1];\n }\n array[index] = value;\n }\n\n /**\n * Remove and return a value at a specific index in an array.\n *\n * @param array - The array of interest.\n *\n * @param index - The index of the value to remove. Negative values\n * are taken as an offset from the end of the array.\n *\n * @returns The value at the specified index, or `undefined` if the\n * index is out of range.\n *\n * #### Complexity\n * Linear.\n *\n * #### Undefined Behavior\n * An `index` which is non-integral.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * let data = [0, 12, 23, 39, 14, 12, 75];\n * ArrayExt.removeAt(data, 2); // 23\n * ArrayExt.removeAt(data, -2); // 12\n * ArrayExt.removeAt(data, 10); // undefined;\n * ```\n */\n export function removeAt<T>(array: Array<T>, index: number): T | undefined {\n let n = array.length;\n if (index < 0) {\n index += n;\n }\n if (index < 0 || index >= n) {\n return undefined;\n }\n let value = array[index];\n for (let i = index + 1; i < n; ++i) {\n array[i - 1] = array[i];\n }\n array.length = n - 1;\n return value;\n }\n\n /**\n * Remove the first occurrence of a value from an array.\n *\n * @param array - The array of interest.\n *\n * @param value - The value to remove from the array. Values are\n * compared using strict `===` equality.\n *\n * @param start - The index of the first element in the range to be\n * searched, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * searched, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @returns The index of the removed value, or `-1` if the value\n * is not contained in the array.\n *\n * #### Notes\n * If `stop < start` the search will wrap at the end of the array.\n *\n * #### Complexity\n * Linear.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * let data = [0, 12, 23, 39, 14, 12, 75];\n * ArrayExt.removeFirstOf(data, 12); // 1\n * ArrayExt.removeFirstOf(data, 17); // -1\n * ArrayExt.removeFirstOf(data, 39, 3); // -1\n * ArrayExt.removeFirstOf(data, 39, 3, 2); // 2\n * ```\n */\n export function removeFirstOf<T>(\n array: Array<T>,\n value: T,\n start = 0,\n stop = -1\n ): number {\n let index = firstIndexOf(array, value, start, stop);\n if (index !== -1) {\n removeAt(array, index);\n }\n return index;\n }\n\n /**\n * Remove the last occurrence of a value from an array.\n *\n * @param array - The array of interest.\n *\n * @param value - The value to remove from the array. Values are\n * compared using strict `===` equality.\n *\n * @param start - The index of the first element in the range to be\n * searched, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * searched, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @returns The index of the removed value, or `-1` if the value\n * is not contained in the array.\n *\n * #### Notes\n * If `start < stop` the search will wrap at the end of the array.\n *\n * #### Complexity\n * Linear.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * let data = [0, 12, 23, 39, 14, 12, 75];\n * ArrayExt.removeLastOf(data, 12); // 5\n * ArrayExt.removeLastOf(data, 17); // -1\n * ArrayExt.removeLastOf(data, 39, 2); // -1\n * ArrayExt.removeLastOf(data, 39, 2, 3); // 3\n * ```\n */\n export function removeLastOf<T>(\n array: Array<T>,\n value: T,\n start = -1,\n stop = 0\n ): number {\n let index = lastIndexOf(array, value, start, stop);\n if (index !== -1) {\n removeAt(array, index);\n }\n return index;\n }\n\n /**\n * Remove all occurrences of a value from an array.\n *\n * @param array - The array of interest.\n *\n * @param value - The value to remove from the array. Values are\n * compared using strict `===` equality.\n *\n * @param start - The index of the first element in the range to be\n * searched, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * searched, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @returns The number of elements removed from the array.\n *\n * #### Notes\n * If `stop < start` the search will conceptually wrap at the end of\n * the array, however the array will be traversed front-to-back.\n *\n * #### Complexity\n * Linear.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * let data = [14, 12, 23, 39, 14, 12, 19, 14];\n * ArrayExt.removeAllOf(data, 12); // 2\n * ArrayExt.removeAllOf(data, 17); // 0\n * ArrayExt.removeAllOf(data, 14, 1, 4); // 1\n * ```\n */\n export function removeAllOf<T>(\n array: Array<T>,\n value: T,\n start = 0,\n stop = -1\n ): number {\n let n = array.length;\n if (n === 0) {\n return 0;\n }\n if (start < 0) {\n start = Math.max(0, start + n);\n } else {\n start = Math.min(start, n - 1);\n }\n if (stop < 0) {\n stop = Math.max(0, stop + n);\n } else {\n stop = Math.min(stop, n - 1);\n }\n let count = 0;\n for (let i = 0; i < n; ++i) {\n if (start <= stop && i >= start && i <= stop && array[i] === value) {\n count++;\n } else if (\n stop < start &&\n (i <= stop || i >= start) &&\n array[i] === value\n ) {\n count++;\n } else if (count > 0) {\n array[i - count] = array[i];\n }\n }\n if (count > 0) {\n array.length = n - count;\n }\n return count;\n }\n\n /**\n * Remove the first occurrence of a value which matches a predicate.\n *\n * @param array - The array of interest.\n *\n * @param fn - The predicate function to apply to the values.\n *\n * @param start - The index of the first element in the range to be\n * searched, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * searched, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @returns The removed `{ index, value }`, which will be `-1` and\n * `undefined` if the value is not contained in the array.\n *\n * #### Notes\n * If `stop < start` the search will wrap at the end of the array.\n *\n * #### Complexity\n * Linear.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * function isEven(value: number): boolean {\n * return value % 2 === 0;\n * }\n *\n * let data = [0, 12, 23, 39, 14, 12, 75];\n * ArrayExt.removeFirstWhere(data, isEven); // { index: 0, value: 0 }\n * ArrayExt.removeFirstWhere(data, isEven, 2); // { index: 3, value: 14 }\n * ArrayExt.removeFirstWhere(data, isEven, 4); // { index: -1, value: undefined }\n * ```\n */\n export function removeFirstWhere<T>(\n array: Array<T>,\n fn: (value: T, index: number) => boolean,\n start = 0,\n stop = -1\n ): { index: number; value: T | undefined } {\n let value: T | undefined;\n let index = findFirstIndex(array, fn, start, stop);\n if (index !== -1) {\n value = removeAt(array, index);\n }\n return { index, value };\n }\n\n /**\n * Remove the last occurrence of a value which matches a predicate.\n *\n * @param array - The array of interest.\n *\n * @param fn - The predicate function to apply to the values.\n *\n * @param start - The index of the first element in the range to be\n * searched, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * searched, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @returns The removed `{ index, value }`, which will be `-1` and\n * `undefined` if the value is not contained in the array.\n *\n * #### Notes\n * If `start < stop` the search will wrap at the end of the array.\n *\n * #### Complexity\n * Linear.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * function isEven(value: number): boolean {\n * return value % 2 === 0;\n * }\n *\n * let data = [0, 12, 23, 39, 14, 12, 75];\n * ArrayExt.removeLastWhere(data, isEven); // { index: 5, value: 12 }\n * ArrayExt.removeLastWhere(data, isEven, 2); // { index: 1, value: 12 }\n * ArrayExt.removeLastWhere(data, isEven, 2, 1); // { index: -1, value: undefined }\n * ```\n */\n export function removeLastWhere<T>(\n array: Array<T>,\n fn: (value: T, index: number) => boolean,\n start = -1,\n stop = 0\n ): { index: number; value: T | undefined } {\n let value: T | undefined;\n let index = findLastIndex(array, fn, start, stop);\n if (index !== -1) {\n value = removeAt(array, index);\n }\n return { index, value };\n }\n\n /**\n * Remove all occurrences of values which match a predicate.\n *\n * @param array - The array of interest.\n *\n * @param fn - The predicate function to apply to the values.\n *\n * @param start - The index of the first element in the range to be\n * searched, inclusive. The default value is `0`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @param stop - The index of the last element in the range to be\n * searched, inclusive. The default value is `-1`. Negative values\n * are taken as an offset from the end of the array.\n *\n * @returns The number of elements removed from the array.\n *\n * #### Notes\n * If `stop < start` the search will conceptually wrap at the end of\n * the array, however the array will be traversed front-to-back.\n *\n * #### Complexity\n * Linear.\n *\n * #### Example\n * ```typescript\n * import { ArrayExt } from '@lumino/algorithm';\n *\n * function isEven(value: number): boolean {\n * return value % 2 === 0;\n * }\n *\n * function isNegative(value: number): boolean {\n * return value < 0;\n * }\n *\n * let data = [0, 12, -13, -9, 23, 39, 14, -15, 12, 75];\n * ArrayExt.removeAllWhere(data, isEven); // 4\n * ArrayExt.removeAllWhere(data, isNegative, 0, 3); // 2\n * ```\n */\n export function removeAllWhere<T>(\n array: Array<T>,\n fn: (value: T, index: number) => boolean,\n start = 0,\n stop = -1\n ): number {\n let n = array.length;\n if (n === 0) {\n return 0;\n }\n if (start < 0) {\n start = Math.max(0, start + n);\n } else {\n start = Math.min(start, n - 1);\n }\n if (stop < 0) {\n stop = Math.max(0, stop + n);\n } else {\n stop = Math.min(stop, n - 1);\n }\n let count = 0;\n for (let i = 0; i < n; ++i) {\n if (start <= stop && i >= start && i <= stop && fn(array[i], i)) {\n count++;\n } else if (stop < start && (i <= stop || i >= start) && fn(array[i], i)) {\n count++;\n } else if (count > 0) {\n array[i - count] = array[i];\n }\n }\n if (count > 0) {\n array.length = n - count;\n }\n return count;\n }\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * Chain together several iterables.\n *\n * @deprecated\n *\n * @param objects - The iterable objects of interest.\n *\n * @returns An iterator which yields the values of the iterables\n * in the order in which they are supplied.\n *\n * #### Example\n * ```typescript\n * import { chain } from '@lumino/algorithm';\n *\n * let data1 = [1, 2, 3];\n * let data2 = [4, 5, 6];\n *\n * let stream = chain(data1, data2);\n *\n * Array.from(stream); // [1, 2, 3, 4, 5, 6]\n * ```\n */\nexport function* chain<T>(...objects: Iterable<T>[]): IterableIterator<T> {\n for (const object of objects) {\n yield* object;\n }\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * Create an empty iterator.\n *\n * @returns A new iterator which yields nothing.\n *\n * #### Example\n * ```typescript\n * import { empty } from '@lumino/algorithm';\n *\n * let stream = empty<number>();\n *\n * Array.from(stream); // []\n * ```\n */\n// eslint-disable-next-line require-yield\nexport function* empty<T>(): IterableIterator<T> {\n return;\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * Enumerate an iterable object.\n *\n * @param object - The iterable object of interest.\n *\n * @param start - The starting enum value. The default is `0`.\n *\n * @returns An iterator which yields the enumerated values.\n *\n * #### Example\n * ```typescript\n * import { enumerate } from '@lumino/algorithm';\n *\n * let data = ['foo', 'bar', 'baz'];\n *\n * let stream = enumerate(data, 1);\n *\n * Array.from(stream); // [[1, 'foo'], [2, 'bar'], [3, 'baz']]\n * ```\n */\nexport function* enumerate<T>(\n object: Iterable<T>,\n start = 0\n): IterableIterator<[number, T]> {\n for (const value of object) {\n yield [start++, value];\n }\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * Filter an iterable for values which pass a test.\n *\n * @param object - The iterable object of interest.\n *\n * @param fn - The predicate function to invoke for each value.\n *\n * @returns An iterator which yields the values which pass the test.\n *\n * #### Example\n * ```typescript\n * import { filter } from '@lumino/algorithm';\n *\n * let data = [1, 2, 3, 4, 5, 6];\n *\n * let stream = filter(data, value => value % 2 === 0);\n *\n * Array.from(stream); // [2, 4, 6]\n * ```\n */\nexport function* filter<T>(\n object: Iterable<T>,\n fn: (value: T, index: number) => boolean\n): IterableIterator<T> {\n let index = 0;\n for (const value of object) {\n if (fn(value, index++)) {\n yield value;\n }\n }\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * Find the first value in an iterable which matches a predicate.\n *\n * @param object - The iterable object to search.\n *\n * @param fn - The predicate function to apply to the values.\n *\n * @returns The first matching value, or `undefined` if no matching\n * value is found.\n *\n * #### Complexity\n * Linear.\n *\n * #### Example\n * ```typescript\n * import { find } from '@lumino/algorithm';\n *\n * interface IAnimal { species: string, name: string };\n *\n * function isCat(value: IAnimal): boolean {\n * return value.species === 'cat';\n * }\n *\n * let data: IAnimal[] = [\n * { species: 'dog', name: 'spot' },\n * { species: 'cat', name: 'fluffy' },\n * { species: 'alligator', name: 'pocho' }\n * ];\n *\n * find(data, isCat).name; // 'fluffy'\n * ```\n */\nexport function find<T>(\n object: Iterable<T>,\n fn: (value: T, index: number) => boolean\n): T | undefined {\n let index = 0;\n for (const value of object) {\n if (fn(value, index++)) {\n return value;\n }\n }\n return undefined;\n}\n\n/**\n * Find the index of the first value which matches a predicate.\n *\n * @param object - The iterable object to search.\n *\n * @param fn - The predicate function to apply to the values.\n *\n * @returns The index of the first matching value, or `-1` if no\n * matching value is found.\n *\n * #### Complexity\n * Linear.\n *\n * #### Example\n * ```typescript\n * import { findIndex } from '@lumino/algorithm';\n *\n * interface IAnimal { species: string, name: string };\n *\n * function isCat(value: IAnimal): boolean {\n * return value.species === 'cat';\n * }\n *\n * let data: IAnimal[] = [\n * { species: 'dog', name: 'spot' },\n * { species: 'cat', name: 'fluffy' },\n * { species: 'alligator', name: 'pocho' }\n * ];\n *\n * findIndex(data, isCat); // 1\n * ```\n */\nexport function findIndex<T>(\n object: Iterable<T>,\n fn: (value: T, index: number) => boolean\n): number {\n let index = 0;\n for (const value of object) {\n if (fn(value, index++)) {\n return index - 1;\n }\n }\n return -1;\n}\n\n/**\n * Find the minimum value in an iterable.\n *\n * @param object - The iterable object to search.\n *\n * @param fn - The 3-way comparison function to apply to the values.\n * It should return `< 0` if the first value is less than the second.\n * `0` if the values are equivalent, or `> 0` if the first value is\n * greater than the second.\n *\n * @returns The minimum value in the iterable. If multiple values are\n * equivalent to the minimum, the left-most value is returned. If\n * the iterable is empty, this returns `undefined`.\n *\n * #### Complexity\n * Linear.\n *\n * #### Example\n * ```typescript\n * import { min } from '@lumino/algorithm';\n *\n * function numberCmp(a: number, b: number): number {\n * return a - b;\n * }\n *\n * min([7, 4, 0, 3, 9, 4], numberCmp); // 0\n * ```\n */\nexport function min<T>(\n object: Iterable<T>,\n fn: (first: T, second: T) => number\n): T | undefined {\n let result: T | undefined = undefined;\n for (const value of object) {\n if (result === undefined) {\n result = value;\n continue;\n }\n if (fn(value, result) < 0) {\n result = value;\n }\n }\n return result;\n}\n\n/**\n * Find the maximum value in an iterable.\n *\n * @param object - The iterable object to search.\n *\n * @param fn - The 3-way comparison function to apply to the values.\n * It should return `< 0` if the first value is less than the second.\n * `0` if the values are equivalent, or `> 0` if the first value is\n * greater than the second.\n *\n * @returns The maximum value in the iterable. If multiple values are\n * equivalent to the maximum, the left-most value is returned. If\n * the iterable is empty, this returns `undefined`.\n *\n * #### Complexity\n * Linear.\n *\n * #### Example\n * ```typescript\n * import { max } from '@lumino/algorithm';\n *\n * function numberCmp(a: number, b: number): number {\n * return a - b;\n * }\n *\n * max([7, 4, 0, 3, 9, 4], numberCmp); // 9\n * ```\n */\nexport function max<T>(\n object: Iterable<T>,\n fn: (first: T, second: T) => number\n): T | undefined {\n let result: T | undefined = undefined;\n for (const value of object) {\n if (result === undefined) {\n result = value;\n continue;\n }\n if (fn(value, result) > 0) {\n result = value;\n }\n }\n return result;\n}\n\n/**\n * Find the minimum and maximum values in an iterable.\n *\n * @param object - The iterable object to search.\n *\n * @param fn - The 3-way comparison function to apply to the values.\n * It should return `< 0` if the first value is less than the second.\n * `0` if the values are equivalent, or `> 0` if the first value is\n * greater than the second.\n *\n * @returns A 2-tuple of the `[min, max]` values in the iterable. If\n * multiple values are equivalent, the left-most values are returned.\n * If the iterable is empty, this returns `undefined`.\n *\n * #### Complexity\n * Linear.\n *\n * #### Example\n * ```typescript\n * import { minmax } from '@lumino/algorithm';\n *\n * function numberCmp(a: number, b: number): number {\n * return a - b;\n * }\n *\n * minmax([7, 4, 0, 3, 9, 4], numberCmp); // [0, 9]\n * ```\n */\nexport function minmax<T>(\n object: Iterable<T>,\n fn: (first: T, second: T) => number\n): [T, T] | undefined {\n let empty = true;\n let vmin: T;\n let vmax: T;\n for (const value of object) {\n if (empty) {\n vmin = value;\n vmax = value;\n empty = false;\n } else if (fn(value, vmin!) < 0) {\n vmin = value;\n } else if (fn(value, vmax!) > 0) {\n vmax = value;\n }\n }\n return empty ? undefined : [vmin!, vmax!];\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * Create an array from an iterable of values.\n *\n * @deprecated\n *\n * @param object - The iterable object of interest.\n *\n * @returns A new array of values from the given object.\n *\n * #### Example\n * ```typescript\n * import { toArray } from '@lumino/algorithm';\n *\n * let stream = [1, 2, 3, 4, 5, 6][Symbol.iterator]();\n *\n * toArray(stream); // [1, 2, 3, 4, 5, 6];\n * ```\n */\nexport function toArray<T>(object: Iterable<T>): T[] {\n return Array.from(object);\n}\n\n/**\n * Create an object from an iterable of key/value pairs.\n *\n * @param object - The iterable object of interest.\n *\n * @returns A new object mapping keys to values.\n *\n * #### Example\n * ```typescript\n * import { toObject } from '@lumino/algorithm';\n *\n * let data: [string, number][] = [['one', 1], ['two', 2], ['three', 3]];\n *\n * toObject(data); // { one: 1, two: 2, three: 3 }\n * ```\n */\nexport function toObject<T>(object: Iterable<[string, T]>): {\n [key: string]: T;\n} {\n const result: { [key: string]: T } = {};\n for (const [key, value] of object) {\n result[key] = value;\n }\n return result;\n}\n\n/**\n * Invoke a function for each value in an iterable.\n *\n * @deprecated\n *\n * @param object - The iterable object of interest.\n *\n * @param fn - The callback function to invoke for each value.\n *\n * #### Notes\n * Iteration can be terminated early by returning `false` from the\n * callback function.\n *\n * #### Complexity\n * Linear.\n *\n * #### Example\n * ```typescript\n * import { each } from '@lumino/algorithm';\n *\n * let data = [5, 7, 0, -2, 9];\n *\n * each(data, value => { console.log(value); });\n * ```\n */\nexport function each<T>(\n object: Iterable<T>,\n fn: (value: T, index: number) => boolean | void\n): void {\n let index = 0;\n for (const value of object) {\n if (false === fn(value, index++)) {\n return;\n }\n }\n}\n\n/**\n * Test whether all values in an iterable satisfy a predicate.\n *\n * @param object - The iterable object of interest.\n *\n * @param fn - The predicate function to invoke for each value.\n *\n * @returns `true` if all values pass the test, `false` otherwise.\n *\n * #### Notes\n * Iteration terminates on the first `false` predicate result.\n *\n * #### Complexity\n * Linear.\n *\n * #### Example\n * ```typescript\n * import { every } from '@lumino/algorithm';\n *\n * let data = [5, 7, 1];\n *\n * every(data, value => value % 2 === 0); // false\n * every(data, value => value % 2 === 1); // true\n * ```\n */\nexport function every<T>(\n object: Iterable<T>,\n fn: (value: T, index: number) => boolean\n): boolean {\n let index = 0;\n for (const value of object) {\n if (false === fn(value, index++)) {\n return false;\n }\n }\n return true;\n}\n\n/**\n * Test whether any value in an iterable satisfies a predicate.\n *\n * @param object - The iterable object of interest.\n *\n * @param fn - The predicate function to invoke for each value.\n *\n * @returns `true` if any value passes the test, `false` otherwise.\n *\n * #### Notes\n * Iteration terminates on the first `true` predicate result.\n *\n * #### Complexity\n * Linear.\n *\n * #### Example\n * ```typescript\n * import { some } from '@lumino/algorithm';\n *\n * let data = [5, 7, 1];\n *\n * some(data, value => value === 7); // true\n * some(data, value => value === 3); // false\n * ```\n */\nexport function some<T>(\n object: Iterable<T>,\n fn: (value: T, index: number) => boolean\n): boolean {\n let index = 0;\n for (const value of object) {\n if (fn(value, index++)) {\n return true;\n }\n }\n return false;\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n/**\n * Transform the values of an iterable with a mapping function.\n *\n * @param object - The iterable object of interest.\n *\n * @param fn - The mapping function to invoke for each value.\n *\n * @returns An iterator which yields the transformed values.\n *\n * #### Example\n * ```typescript\n * import { map } from '@lumino/algorithm';\n *\n * let data = [1, 2, 3];\n *\n * let stream = map(data, value => value * 2);\n *\n * Array.from(stream); // [2, 4, 6]\n * ```\n */\nexport function* map<T, U>(\n object: Iterable<T>,\n fn: (value: T, index: number) => U\n): IterableIterator<U> {\n let index = 0;\n for (const value of object) {\n yield fn(value, index++);\n }\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n/**\n * Create an iterator of evenly spaced values.\n *\n * @param start - The starting value for the range, inclusive.\n *\n * @param stop - The stopping value for the range, exclusive.\n *\n * @param step - The distance between each value.\n *\n * @returns An iterator which produces evenly spaced values.\n *\n * #### Notes\n * In the single argument form of `range(stop)`, `start` defaults to\n * `0` and `step` defaults to `1`.\n *\n * In the two argument form of `range(start, stop)`, `step` defaults\n * to `1`.\n *\n * #### Example\n * ```typescript\n * import { range } from '@lumino/algorithm';\n *\n * let stream = range(2, 4);\n *\n * Array.from(stream); // [2, 3]\n * ```\n */\nexport function* range(\n start: number,\n stop?: number,\n step?: number\n): IterableIterator<number> {\n if (stop === undefined) {\n stop = start;\n start = 0;\n step = 1;\n } else if (step === undefined) {\n step = 1;\n }\n const length = Private.rangeLength(start, stop, step);\n for (let index = 0; index < length; index++) {\n yield start + step * index;\n }\n}\n\n/**\n * The namespace for the module implementation details.\n */\nnamespace Private {\n /**\n * Compute the effective length of a range.\n *\n * @param start - The starting value for the range, inclusive.\n *\n * @param stop - The stopping value for the range, exclusive.\n *\n * @param step - The distance between each value.\n *\n * @returns The number of steps need to traverse the range.\n */\n export function rangeLength(\n start: number,\n stop: number,\n step: number\n ): number {\n if (step === 0) {\n return Infinity;\n }\n if (start > stop && step > 0) {\n return 0;\n }\n if (start < stop && step < 0) {\n return 0;\n }\n return Math.ceil((stop - start) / step);\n }\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * Summarize all values in an iterable using a reducer function.\n *\n * @param object - The iterable object of interest.\n *\n * @param fn - The reducer function to invoke for each value.\n *\n * @param initial - The initial value to start accumulation.\n *\n * @returns The final accumulated value.\n *\n * #### Notes\n * The `reduce` function follows the conventions of `Array#reduce`.\n *\n * If the iterator is empty, an initial value is required. That value\n * will be used as the return value. If no initial value is provided,\n * an error will be thrown.\n *\n * If the iterator contains a single item and no initial value is\n * provided, the single item is used as the return value.\n *\n * Otherwise, the reducer is invoked for each element in the iterable.\n * If an initial value is not provided, the first element will be used\n * as the initial accumulated value.\n *\n * #### Complexity\n * Linear.\n *\n * #### Example\n * ```typescript\n * import { reduce } from '@lumino/algorithm';\n *\n * let data = [1, 2, 3, 4, 5];\n *\n * let sum = reduce(data, (a, value) => a + value); // 15\n * ```\n */\nexport function reduce<T>(\n object: Iterable<T>,\n fn: (accumulator: T, value: T, index: number) => T\n): T;\nexport function reduce<T, U>(\n object: Iterable<T>,\n fn: (accumulator: U, value: T, index: number) => U,\n initial: U\n): U;\nexport function reduce<T>(\n object: Iterable<T>,\n fn: (accumulator: any, value: T, index: number) => any,\n initial?: unknown\n): any {\n // Setup the iterator and fetch the first value.\n const it = object[Symbol.iterator]();\n let index = 0;\n let first = it.next();\n\n // An empty iterator and no initial value is an error.\n if (first.done && initial === undefined) {\n throw new TypeError('Reduce of empty iterable with no initial value.');\n }\n\n // If the iterator is empty, return the initial value.\n if (first.done) {\n return initial;\n }\n\n // If the iterator has a single item and no initial value, the\n // reducer is not invoked and the first item is the return value.\n let second = it.next();\n if (second.done && initial === undefined) {\n return first.value;\n }\n\n // If iterator has a single item and an initial value is provided,\n // the reducer is invoked and that result is the return value.\n if (second.done) {\n return fn(initial, first.value, index++);\n }\n\n // Setup the initial accumlated value.\n let accumulator: any;\n if (initial === undefined) {\n accumulator = fn(first.value, second.value, index++);\n } else {\n accumulator = fn(fn(initial, first.value, index++), second.value, index++);\n }\n\n // Iterate the rest of the values, updating the accumulator.\n let next: IteratorResult<T>;\n while (!(next = it.next()).done) {\n accumulator = fn(accumulator, next.value, index++);\n }\n\n // Return the final accumulated value.\n return accumulator;\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * Create an iterator which repeats a value a number of times.\n *\n * @deprecated\n *\n * @param value - The value to repeat.\n *\n * @param count - The number of times to repeat the value.\n *\n * @returns A new iterator which repeats the specified value.\n *\n * #### Example\n * ```typescript\n * import { repeat } from '@lumino/algorithm';\n *\n * let stream = repeat(7, 3);\n *\n * Array.from(stream); // [7, 7, 7]\n * ```\n */\nexport function* repeat<T>(value: T, count: number): IterableIterator<T> {\n while (0 < count--) {\n yield value;\n }\n}\n\n/**\n * Create an iterator which yields a value a single time.\n *\n * @deprecated\n *\n * @param value - The value to wrap in an iterator.\n *\n * @returns A new iterator which yields the value a single time.\n *\n * #### Example\n * ```typescript\n * import { once } from '@lumino/algorithm';\n *\n * let stream = once(7);\n *\n * Array.from(stream); // [7]\n * ```\n */\nexport function* once<T>(value: T): IterableIterator<T> {\n yield value;\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * An object which can produce a reverse iterator over its values.\n */\nexport interface IRetroable<T> {\n /**\n * Get a reverse iterator over the object's values.\n *\n * @returns An iterator which yields the object's values in reverse.\n */\n retro(): IterableIterator<T>;\n}\n\n/**\n * Create an iterator for a retroable object.\n *\n * @param object - The retroable or array-like object of interest.\n *\n * @returns An iterator which traverses the object's values in reverse.\n *\n * #### Example\n * ```typescript\n * import { retro } from '@lumino/algorithm';\n *\n * let data = [1, 2, 3, 4, 5, 6];\n *\n * let stream = retro(data);\n *\n * Array.from(stream); // [6, 5, 4, 3, 2, 1]\n * ```\n */\nexport function* retro<T>(\n object: IRetroable<T> | ArrayLike<T>\n): IterableIterator<T> {\n if (typeof (object as IRetroable<T>).retro === 'function') {\n yield* (object as IRetroable<T>).retro();\n } else {\n for (let index = (object as ArrayLike<T>).length - 1; index > -1; index--) {\n yield (object as ArrayLike<T>)[index];\n }\n }\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * Topologically sort an iterable of edges.\n *\n * @param edges - The iterable object of edges to sort.\n * An edge is represented as a 2-tuple of `[fromNode, toNode]`.\n *\n * @returns The topologically sorted array of nodes.\n *\n * #### Notes\n * If a cycle is present in the graph, the cycle will be ignored and\n * the return value will be only approximately sorted.\n *\n * #### Example\n * ```typescript\n * import { topologicSort } from '@lumino/algorithm';\n *\n * let data = [\n * ['d', 'e'],\n * ['c', 'd'],\n * ['a', 'b'],\n * ['b', 'c']\n * ];\n *\n * topologicSort(data); // ['a', 'b', 'c', 'd', 'e']\n * ```\n */\nexport function topologicSort<T>(edges: Iterable<[T, T]>): T[] {\n // Setup the shared sorting state.\n let sorted: T[] = [];\n let visited = new Set<T>();\n let graph = new Map<T, T[]>();\n\n // Add the edges to the graph.\n for (const edge of edges) {\n addEdge(edge);\n }\n\n // Visit each node in the graph.\n for (const [k] of graph) {\n visit(k);\n }\n\n // Return the sorted results.\n return sorted;\n\n // Add an edge to the graph.\n function addEdge(edge: [T, T]): void {\n let [fromNode, toNode] = edge;\n let children = graph.get(toNode);\n if (children) {\n children.push(fromNode);\n } else {\n graph.set(toNode, [fromNode]);\n }\n }\n\n // Recursively visit the node.\n function visit(node: T): void {\n if (visited.has(node)) {\n return;\n }\n visited.add(node);\n let children = graph.get(node);\n if (children) {\n for (const child of children) {\n visit(child);\n }\n }\n sorted.push(node);\n }\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * Iterate over an iterable using a stepped increment.\n *\n * @param object - The iterable object of interest.\n *\n * @param step - The distance to step on each iteration. A value\n * of less than `1` will behave the same as a value of `1`.\n *\n * @returns An iterator which traverses the iterable step-wise.\n *\n * #### Example\n * ```typescript\n * import { stride } from '@lumino/algorithm';\n *\n * let data = [1, 2, 3, 4, 5, 6];\n *\n * let stream = stride(data, 2);\n *\n * Array.from(stream); // [1, 3, 5];\n * ```\n */\nexport function* stride<T>(\n object: Iterable<T>,\n step: number\n): IterableIterator<T> {\n let count = 0;\n for (const value of object) {\n if (0 === count++ % step) {\n yield value;\n }\n }\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * The namespace for string-specific algorithms.\n */\nexport namespace StringExt {\n /**\n * Find the indices of characters in a source text.\n *\n * @param source - The source text which should be searched.\n *\n * @param query - The characters to locate in the source text.\n *\n * @param start - The index to start the search.\n *\n * @returns The matched indices, or `null` if there is no match.\n *\n * #### Complexity\n * Linear on `sourceText`.\n *\n * #### Notes\n * In order for there to be a match, all of the characters in `query`\n * **must** appear in `source` in the order given by `query`.\n *\n * Characters are matched using strict `===` equality.\n */\n export function findIndices(\n source: string,\n query: string,\n start = 0\n ): number[] | null {\n let indices = new Array<number>(query.length);\n for (let i = 0, j = start, n = query.length; i < n; ++i, ++j) {\n j = source.indexOf(query[i], j);\n if (j === -1) {\n return null;\n }\n indices[i] = j;\n }\n return indices;\n }\n\n /**\n * The result of a string match function.\n */\n export interface IMatchResult {\n /**\n * A score which indicates the strength of the match.\n *\n * The documentation of a given match function should specify\n * whether a lower or higher score is a stronger match.\n */\n score: number;\n\n /**\n * The indices of the matched characters in the source text.\n *\n * The indices will appear in increasing order.\n */\n indices: number[];\n }\n\n /**\n * A string matcher which uses a sum-of-squares algorithm.\n *\n * @param source - The source text which should be searched.\n *\n * @param query - The characters to locate in the source text.\n *\n * @param start - The index to start the search.\n *\n * @returns The match result, or `null` if there is no match.\n * A lower `score` represents a stronger match.\n *\n * #### Complexity\n * Linear on `sourceText`.\n *\n * #### Notes\n * This scoring algorithm uses a sum-of-squares approach to determine\n * the score. In order for there to be a match, all of the characters\n * in `query` **must** appear in `source` in order. The index of each\n * matching character is squared and added to the score. This means\n * that early and consecutive character matches are preferred, while\n * late matches are heavily penalized.\n */\n export function matchSumOfSquares(\n source: string,\n query: string,\n start = 0\n ): IMatchResult | null {\n let indices = findIndices(source, query, start);\n if (!indices) {\n return null;\n }\n let score = 0;\n for (let i = 0, n = indices.length; i < n; ++i) {\n let j = indices[i] - start;\n score += j * j;\n }\n return { score, indices };\n }\n\n /**\n * A string matcher which uses a sum-of-deltas algorithm.\n *\n * @param source - The source text which should be searched.\n *\n * @param query - The characters to locate in the source text.\n *\n * @param start - The index to start the search.\n *\n * @returns The match result, or `null` if there is no match.\n * A lower `score` represents a stronger match.\n *\n * #### Complexity\n * Linear on `sourceText`.\n *\n * #### Notes\n * This scoring algorithm uses a sum-of-deltas approach to determine\n * the score. In order for there to be a match, all of the characters\n * in `query` **must** appear in `source` in order. The delta between\n * the indices are summed to create the score. This means that groups\n * of matched characters are preferred, while fragmented matches are\n * penalized.\n */\n export function matchSumOfDeltas(\n source: string,\n query: string,\n start = 0\n ): IMatchResult | null {\n let indices = findIndices(source, query, start);\n if (!indices) {\n return null;\n }\n let score = 0;\n let last = start - 1;\n for (let i = 0, n = indices.length; i < n; ++i) {\n let j = indices[i];\n score += j - last - 1;\n last = j;\n }\n return { score, indices };\n }\n\n /**\n * Highlight the matched characters of a source text.\n *\n * @param source - The text which should be highlighted.\n *\n * @param indices - The indices of the matched characters. They must\n * appear in increasing order and must be in bounds of the source.\n *\n * @param fn - The function to apply to the matched chunks.\n *\n * @returns An array of unmatched and highlighted chunks.\n */\n export function highlight<T>(\n source: string,\n indices: ReadonlyArray<number>,\n fn: (chunk: string) => T\n ): Array<string | T> {\n // Set up the result array.\n let result: Array<string | T> = [];\n\n // Set up the counter variables.\n let k = 0;\n let last = 0;\n let n = indices.length;\n\n // Iterator over each index.\n while (k < n) {\n // Set up the chunk indices.\n let i = indices[k];\n let j = indices[k];\n\n // Advance the right chunk index until it's non-contiguous.\n while (++k < n && indices[k] === j + 1) {\n j++;\n }\n\n // Extract the unmatched text.\n if (last < i) {\n result.push(source.slice(last, i));\n }\n\n // Extract and highlight the matched text.\n if (i < j + 1) {\n result.push(fn(source.slice(i, j + 1)));\n }\n\n // Update the last visited index.\n last = j + 1;\n }\n\n // Extract any remaining unmatched text.\n if (last < source.length) {\n result.push(source.slice(last));\n }\n\n // Return the highlighted result.\n return result;\n }\n\n /**\n * A 3-way string comparison function.\n *\n * @param a - The first string of interest.\n *\n * @param b - The second string of interest.\n *\n * @returns `-1` if `a < b`, else `1` if `a > b`, else `0`.\n */\n export function cmp(a: string, b: string): number {\n return a < b ? -1 : a > b ? 1 : 0;\n }\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * Take a fixed number of items from an iterable.\n *\n * @param object - The iterable object of interest.\n *\n * @param count - The number of items to take from the iterable.\n *\n * @returns An iterator which yields the specified number of items\n * from the source iterable.\n *\n * #### Notes\n * The returned iterator will exhaust early if the source iterable\n * contains an insufficient number of items.\n *\n * #### Example\n * ```typescript\n * import { take } from '@lumino/algorithm';\n *\n * let stream = take([5, 4, 3, 2, 1, 0, -1], 3);\n *\n * Array.from(stream); // [5, 4, 3]\n * ```\n */\nexport function* take<T>(\n object: Iterable<T>,\n count: number\n): IterableIterator<T> {\n if (count < 1) {\n return;\n }\n const it = object[Symbol.iterator]();\n let item: IteratorResult<T>;\n while (0 < count-- && !(item = it.next()).done) {\n yield item.value;\n }\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\nimport { every } from './iter';\n\n/**\n * Iterate several iterables in lockstep.\n *\n * @param objects - The iterable objects of interest.\n *\n * @returns An iterator which yields successive tuples of values where\n * each value is taken in turn from the provided iterables. It will\n * be as long as the shortest provided iterable.\n *\n * #### Example\n * ```typescript\n * import { zip } from '@lumino/algorithm';\n *\n * let data1 = [1, 2, 3];\n * let data2 = [4, 5, 6];\n *\n * let stream = zip(data1, data2);\n *\n * Array.from(stream); // [[1, 4], [2, 5], [3, 6]]\n * ```\n */\nexport function* zip<T>(...objects: Iterable<T>[]): IterableIterator<T[]> {\n const iters = objects.map(obj => obj[Symbol.iterator]());\n let tuple = iters.map(it => it.next());\n for (; every(tuple, item => !item.done); tuple = iters.map(it => it.next())) {\n yield tuple.map(item => item.value);\n }\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * A type alias for a JSON primitive.\n */\nexport type JSONPrimitive = boolean | number | string | null;\n\n/**\n * A type alias for a JSON value.\n */\nexport type JSONValue = JSONPrimitive | JSONObject | JSONArray;\n\n/**\n * A type definition for a JSON object.\n */\nexport interface JSONObject {\n [key: string]: JSONValue;\n}\n\n/**\n * A type definition for a JSON array.\n */\nexport interface JSONArray extends Array<JSONValue> {}\n\n/**\n * A type definition for a readonly JSON object.\n */\nexport interface ReadonlyJSONObject {\n readonly [key: string]: ReadonlyJSONValue;\n}\n\n/**\n * A type definition for a readonly JSON array.\n */\nexport interface ReadonlyJSONArray extends ReadonlyArray<ReadonlyJSONValue> {}\n\n/**\n * A type alias for a readonly JSON value.\n */\nexport type ReadonlyJSONValue =\n | JSONPrimitive\n | ReadonlyJSONObject\n | ReadonlyJSONArray;\n\n/**\n * A type alias for a partial JSON value.\n *\n * Note: Partial here means that JSON object attributes can be `undefined`.\n */\nexport type PartialJSONValue =\n | JSONPrimitive\n | PartialJSONObject\n | PartialJSONArray;\n\n/**\n * A type definition for a partial JSON object.\n *\n * Note: Partial here means that the JSON object attributes can be `undefined`.\n */\nexport interface PartialJSONObject {\n [key: string]: PartialJSONValue | undefined;\n}\n\n/**\n * A type definition for a partial JSON array.\n *\n * Note: Partial here means that JSON object attributes can be `undefined`.\n */\nexport interface PartialJSONArray extends Array<PartialJSONValue> {}\n\n/**\n * A type definition for a readonly partial JSON object.\n *\n * Note: Partial here means that JSON object attributes can be `undefined`.\n */\nexport interface ReadonlyPartialJSONObject {\n readonly [key: string]: ReadonlyPartialJSONValue | undefined;\n}\n\n/**\n * A type definition for a readonly partial JSON array.\n *\n * Note: Partial here means that JSON object attributes can be `undefined`.\n */\nexport interface ReadonlyPartialJSONArray\n extends ReadonlyArray<ReadonlyPartialJSONValue> {}\n\n/**\n * A type alias for a readonly partial JSON value.\n *\n * Note: Partial here means that JSON object attributes can be `undefined`.\n */\nexport type ReadonlyPartialJSONValue =\n | JSONPrimitive\n | ReadonlyPartialJSONObject\n | ReadonlyPartialJSONArray;\n\n/**\n * The namespace for JSON-specific functions.\n */\nexport namespace JSONExt {\n /**\n * A shared frozen empty JSONObject\n */\n export const emptyObject = Object.freeze({}) as ReadonlyJSONObject;\n\n /**\n * A shared frozen empty JSONArray\n */\n export const emptyArray = Object.freeze([]) as ReadonlyJSONArray;\n\n /**\n * Test whether a JSON value is a primitive.\n *\n * @param value - The JSON value of interest.\n *\n * @returns `true` if the value is a primitive,`false` otherwise.\n */\n export function isPrimitive(\n value: ReadonlyPartialJSONValue\n ): value is JSONPrimitive {\n return (\n value === null ||\n typeof value === 'boolean' ||\n typeof value === 'number' ||\n typeof value === 'string'\n );\n }\n\n /**\n * Test whether a JSON value is an array.\n *\n * @param value - The JSON value of interest.\n *\n * @returns `true` if the value is a an array, `false` otherwise.\n */\n export function isArray(value: JSONValue): value is JSONArray;\n export function isArray(value: ReadonlyJSONValue): value is ReadonlyJSONArray;\n export function isArray(value: PartialJSONValue): value is PartialJSONArray;\n export function isArray(\n value: ReadonlyPartialJSONValue\n ): value is ReadonlyPartialJSONArray;\n export function isArray(value: ReadonlyPartialJSONValue): boolean {\n return Array.isArray(value);\n }\n\n /**\n * Test whether a JSON value is an object.\n *\n * @param value - The JSON value of interest.\n *\n * @returns `true` if the value is a an object, `false` otherwise.\n */\n export function isObject(value: JSONValue): value is JSONObject;\n export function isObject(\n value: ReadonlyJSONValue\n ): value is ReadonlyJSONObject;\n export function isObject(value: PartialJSONValue): value is PartialJSONObject;\n export function isObject(\n value: ReadonlyPartialJSONValue\n ): value is ReadonlyPartialJSONObject;\n export function isObject(value: ReadonlyPartialJSONValue): boolean {\n return !isPrimitive(value) && !isArray(value);\n }\n\n /**\n * Compare two JSON values for deep equality.\n *\n * @param first - The first JSON value of interest.\n *\n * @param second - The second JSON value of interest.\n *\n * @returns `true` if the values are equivalent, `false` otherwise.\n */\n export function deepEqual(\n first: ReadonlyPartialJSONValue,\n second: ReadonlyPartialJSONValue\n ): boolean {\n // Check referential and primitive equality first.\n if (first === second) {\n return true;\n }\n\n // If one is a primitive, the `===` check ruled out the other.\n if (isPrimitive(first) || isPrimitive(second)) {\n return false;\n }\n\n // Test whether they are arrays.\n let a1 = isArray(first);\n let a2 = isArray(second);\n\n // Bail if the types are different.\n if (a1 !== a2) {\n return false;\n }\n\n // If they are both arrays, compare them.\n if (a1 && a2) {\n return deepArrayEqual(\n first as ReadonlyPartialJSONArray,\n second as ReadonlyPartialJSONArray\n );\n }\n\n // At this point, they must both be objects.\n return deepObjectEqual(\n first as ReadonlyPartialJSONObject,\n second as ReadonlyPartialJSONObject\n );\n }\n\n /**\n * Create a deep copy of a JSON value.\n *\n * @param value - The JSON value to copy.\n *\n * @returns A deep copy of the given JSON value.\n */\n export function deepCopy<T extends ReadonlyPartialJSONValue>(value: T): T {\n // Do nothing for primitive values.\n if (isPrimitive(value)) {\n return value;\n }\n\n // Deep copy an array.\n if (isArray(value)) {\n return deepArrayCopy(value);\n }\n\n // Deep copy an object.\n return deepObjectCopy(value);\n }\n\n /**\n * Compare two JSON arrays for deep equality.\n */\n function deepArrayEqual(\n first: ReadonlyPartialJSONArray,\n second: ReadonlyPartialJSONArray\n ): boolean {\n // Check referential equality first.\n if (first === second) {\n return true;\n }\n\n // Test the arrays for equal length.\n if (first.length !== second.length) {\n return false;\n }\n\n // Compare the values for equality.\n for (let i = 0, n = first.length; i < n; ++i) {\n if (!deepEqual(first[i], second[i])) {\n return false;\n }\n }\n\n // At this point, the arrays are equal.\n return true;\n }\n\n /**\n * Compare two JSON objects for deep equality.\n */\n function deepObjectEqual(\n first: ReadonlyPartialJSONObject,\n second: ReadonlyPartialJSONObject\n ): boolean {\n // Check referential equality first.\n if (first === second) {\n return true;\n }\n\n // Check for the first object's keys in the second object.\n for (let key in first) {\n if (first[key] !== undefined && !(key in second)) {\n return false;\n }\n }\n\n // Check for the second object's keys in the first object.\n for (let key in second) {\n if (second[key] !== undefined && !(key in first)) {\n return false;\n }\n }\n\n // Compare the values for equality.\n for (let key in first) {\n // Get the values.\n let firstValue = first[key];\n let secondValue = second[key];\n\n // If both are undefined, ignore the key.\n if (firstValue === undefined && secondValue === undefined) {\n continue;\n }\n\n // If only one value is undefined, the objects are not equal.\n if (firstValue === undefined || secondValue === undefined) {\n return false;\n }\n\n // Compare the values.\n if (!deepEqual(firstValue, secondValue)) {\n return false;\n }\n }\n\n // At this point, the objects are equal.\n return true;\n }\n\n /**\n * Create a deep copy of a JSON array.\n */\n function deepArrayCopy(value: any): any {\n let result = new Array<any>(value.length);\n for (let i = 0, n = value.length; i < n; ++i) {\n result[i] = deepCopy(value[i]);\n }\n return result;\n }\n\n /**\n * Create a deep copy of a JSON object.\n */\n function deepObjectCopy(value: any): any {\n let result: any = {};\n for (let key in value) {\n // Ignore undefined values.\n let subvalue = value[key];\n if (subvalue === undefined) {\n continue;\n }\n result[key] = deepCopy(subvalue);\n }\n return result;\n }\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * An object which stores MIME data for general application use.\n *\n * #### Notes\n * This class does not attempt to enforce \"correctness\" of MIME types\n * and their associated data. Since this class is designed to transfer\n * arbitrary data and objects within the same application, it assumes\n * that the user provides correct and accurate data.\n */\nexport class MimeData {\n /**\n * Get an array of the MIME types contained within the dataset.\n *\n * @returns A new array of the MIME types, in order of insertion.\n */\n types(): string[] {\n return this._types.slice();\n }\n\n /**\n * Test whether the dataset has an entry for the given type.\n *\n * @param mime - The MIME type of interest.\n *\n * @returns `true` if the dataset contains a value for the given\n * MIME type, `false` otherwise.\n */\n hasData(mime: string): boolean {\n return this._types.indexOf(mime) !== -1;\n }\n\n /**\n * Get the data value for the given MIME type.\n *\n * @param mime - The MIME type of interest.\n *\n * @returns The value for the given MIME type, or `undefined` if\n * the dataset does not contain a value for the type.\n */\n getData(mime: string): any | undefined {\n let i = this._types.indexOf(mime);\n return i !== -1 ? this._values[i] : undefined;\n }\n\n /**\n * Set the data value for the given MIME type.\n *\n * @param mime - The MIME type of interest.\n *\n * @param data - The data value for the given MIME type.\n *\n * #### Notes\n * This will overwrite any previous entry for the MIME type.\n */\n setData(mime: string, data: unknown): void {\n this.clearData(mime);\n this._types.push(mime);\n this._values.push(data);\n }\n\n /**\n * Remove the data entry for the given MIME type.\n *\n * @param mime - The MIME type of interest.\n *\n * #### Notes\n * This is a no-op if there is no entry for the given MIME type.\n */\n clearData(mime: string): void {\n let i = this._types.indexOf(mime);\n if (i !== -1) {\n this._types.splice(i, 1);\n this._values.splice(i, 1);\n }\n }\n\n /**\n * Remove all data entries from the dataset.\n */\n clear(): void {\n this._types.length = 0;\n this._values.length = 0;\n }\n\n private _types: string[] = [];\n private _values: any[] = [];\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\nimport { topologicSort } from '@lumino/algorithm';\n\nimport { Token } from './token';\n\n/**\n * A user-defined application plugin.\n *\n * @typeParam T - The type for the application.\n *\n * @typeParam U - The service type, if the plugin `provides` one.\n *\n * #### Notes\n * Plugins are the foundation for building an extensible application.\n *\n * Plugins consume and provide \"services\", which are nothing more than\n * concrete implementations of interfaces and/or abstract types.\n *\n * Unlike regular imports and exports, which tie the service consumer\n * to a particular implementation of the service, plugins decouple the\n * service producer from the service consumer, allowing an application\n * to be easily customized by third parties in a type-safe fashion.\n */\nexport interface IPlugin<T, U> {\n /**\n * The human readable ID of the plugin.\n *\n * #### Notes\n * This must be unique within an application.\n */\n id: string;\n\n /**\n * Plugin description.\n *\n * #### Notes\n * This can be used to provide user documentation on the feature\n * brought by a plugin.\n */\n description?: string;\n\n /**\n * Whether the plugin should be activated on application start or waiting for being\n * required. If the value is 'defer' then the plugin should be activated only after\n * the application is started.\n *\n * #### Notes\n * The default is `false`.\n */\n autoStart?: boolean | 'defer';\n\n /**\n * The types of required services for the plugin, if any.\n *\n * #### Notes\n * These tokens correspond to the services that are required by\n * the plugin for correct operation.\n *\n * When the plugin is activated, a concrete instance of each type\n * will be passed to the `activate()` function, in the order they\n * are specified in the `requires` array.\n */\n requires?: Token<any>[];\n\n /**\n * The types of optional services for the plugin, if any.\n *\n * #### Notes\n * These tokens correspond to the services that can be used by the\n * plugin if available, but are not necessarily required.\n *\n * The optional services will be passed to the `activate()` function\n * following all required services. If an optional service cannot be\n * resolved, `null` will be passed in its place.\n */\n optional?: Token<any>[];\n\n /**\n * The type of service provided by the plugin, if any.\n *\n * #### Notes\n * This token corresponds to the service exported by the plugin.\n *\n * When the plugin is activated, the return value of `activate()`\n * is used as the concrete instance of the type.\n */\n provides?: Token<U> | null;\n\n /**\n * A function invoked to activate the plugin.\n *\n * @param app - The application provided by {@link PluginRegistry.application} .\n *\n * @param args - The services specified by the `requires` property.\n *\n * @returns The provided service, or a promise to the service.\n *\n * #### Notes\n * This function will be called whenever the plugin is manually\n * activated, or when another plugin being activated requires\n * the service it provides.\n *\n * This function will not be called unless all of its required\n * services can be fulfilled.\n */\n activate: (app: T, ...args: any[]) => U | Promise<U>;\n\n /**\n * A function invoked to deactivate the plugin.\n *\n * @param app - The application {@link PluginRegistry.application} .\n *\n * @param args - The services specified by the `requires` property.\n */\n deactivate?: ((app: T, ...args: any[]) => void | Promise<void>) | null;\n}\n\n/**\n * Plugin registry.\n */\nexport class PluginRegistry<T = any> {\n constructor(options: PluginRegistry.IOptions = {}) {\n if (options.validatePlugin) {\n console.info(\n 'Plugins may be rejected by the custom validation plugin method.'\n );\n this._validatePlugin = options.validatePlugin;\n }\n }\n\n /**\n * The application object.\n *\n * It will be provided as first argument to the\n * plugins activation and deactivation functions.\n *\n * It can only be set once.\n *\n * By default, it is `null`.\n */\n get application(): T {\n return this._application;\n }\n set application(v: T) {\n if (this._application !== null) {\n throw Error(\n 'PluginRegistry.application is already set. It cannot be overridden.'\n );\n }\n\n this._application = v;\n }\n\n /**\n * The list of all the deferred plugins.\n */\n get deferredPlugins(): string[] {\n return Array.from(this._plugins)\n .filter(([id, plugin]) => plugin.autoStart === 'defer')\n .map(([id, plugin]) => id);\n }\n\n /**\n * Get a plugin description.\n *\n * @param id - The ID of the plugin of interest.\n *\n * @returns The plugin description.\n */\n getPluginDescription(id: string): string {\n return this._plugins.get(id)?.description ?? '';\n }\n\n /**\n * Test whether a plugin is registered with the application.\n *\n * @param id - The ID of the plugin of interest.\n *\n * @returns `true` if the plugin is registered, `false` otherwise.\n */\n hasPlugin(id: string): boolean {\n return this._plugins.has(id);\n }\n\n /**\n * Test whether a plugin is activated with the application.\n *\n * @param id - The ID of the plugin of interest.\n *\n * @returns `true` if the plugin is activated, `false` otherwise.\n */\n isPluginActivated(id: string): boolean {\n return this._plugins.get(id)?.activated ?? false;\n }\n\n /**\n * List the IDs of the plugins registered with the application.\n *\n * @returns A new array of the registered plugin IDs.\n */\n listPlugins(): string[] {\n return Array.from(this._plugins.keys());\n }\n\n /**\n * Register a plugin with the application.\n *\n * @param plugin - The plugin to register.\n *\n * #### Notes\n * An error will be thrown if a plugin with the same ID is already\n * registered, or if the plugin has a circular dependency.\n *\n * If the plugin provides a service which has already been provided\n * by another plugin, the new service will override the old service.\n */\n registerPlugin(plugin: IPlugin<T, any>): void {\n // Throw an error if the plugin ID is already registered.\n if (this._plugins.has(plugin.id)) {\n throw new TypeError(`Plugin '${plugin.id}' is already registered.`);\n }\n\n if (!this._validatePlugin(plugin)) {\n throw new Error(`Plugin '${plugin.id}' is not valid.`);\n }\n\n // Create the normalized plugin data.\n const data = Private.createPluginData(plugin);\n\n // Ensure the plugin does not cause a cyclic dependency.\n Private.ensureNoCycle(data, this._plugins, this._services);\n\n // Add the service token to the service map.\n if (data.provides) {\n this._services.set(data.provides, data.id);\n }\n\n // Add the plugin to the plugin map.\n this._plugins.set(data.id, data);\n }\n\n /**\n * Register multiple plugins with the application.\n *\n * @param plugins - The plugins to register.\n *\n * #### Notes\n * This calls `registerPlugin()` for each of the given plugins.\n */\n registerPlugins(plugins: IPlugin<T, any>[]): void {\n for (const plugin of plugins) {\n this.registerPlugin(plugin);\n }\n }\n\n /**\n * Deregister a plugin with the application.\n *\n * @param id - The ID of the plugin of interest.\n *\n * @param force - Whether to deregister the plugin even if it is active.\n */\n deregisterPlugin(id: string, force?: boolean): void {\n const plugin = this._plugins.get(id);\n if (!plugin) {\n return;\n }\n\n if (plugin.activated && !force) {\n throw new Error(`Plugin '${id}' is still active.`);\n }\n\n this._plugins.delete(id);\n }\n\n /**\n * Activate the plugin with the given ID.\n *\n * @param id - The ID of the plugin of interest.\n *\n * @returns A promise which resolves when the plugin is activated\n * or rejects with an error if it cannot be activated.\n */\n async activatePlugin(id: string): Promise<void> {\n // Reject the promise if the plugin is not registered.\n const plugin = this._plugins.get(id);\n if (!plugin) {\n throw new ReferenceError(`Plugin '${id}' is not registered.`);\n }\n\n // Resolve immediately if the plugin is already activated.\n if (plugin.activated) {\n return;\n }\n\n // Return the pending resolver promise if it exists.\n if (plugin.promise) {\n return plugin.promise;\n }\n\n // Resolve the required services for the plugin.\n const required = plugin.requires.map(t => this.resolveRequiredService(t));\n\n // Resolve the optional services for the plugin.\n const optional = plugin.optional.map(t => this.resolveOptionalService(t));\n\n // Setup the resolver promise for the plugin.\n plugin.promise = Promise.all([...required, ...optional])\n .then(services =>\n plugin!.activate.apply(undefined, [this.application, ...services])\n )\n .then(service => {\n plugin!.service = service;\n plugin!.activated = true;\n plugin!.promise = null;\n })\n .catch(error => {\n plugin!.promise = null;\n throw error;\n });\n\n // Return the pending resolver promise.\n return plugin.promise;\n }\n\n /**\n * Activate all the deferred plugins.\n *\n * @returns A promise which will resolve when each plugin is activated\n * or rejects with an error if one cannot be activated.\n */\n async activatePlugins(\n kind: 'startUp' | 'defer',\n options: PluginRegistry.IStartOptions = {}\n ): Promise<void> {\n switch (kind) {\n case 'defer': {\n const promises = this.deferredPlugins\n .filter(pluginId => this._plugins.get(pluginId)!.autoStart)\n .map(pluginId => {\n return this.activatePlugin(pluginId);\n });\n await Promise.all(promises);\n break;\n }\n case 'startUp': {\n // Collect the ids of the startup plugins.\n const startups = Private.collectStartupPlugins(this._plugins, options);\n\n // Generate the activation promises.\n const promises = startups.map(async id => {\n try {\n return await this.activatePlugin(id);\n } catch (error) {\n console.error(`Plugin '${id}' failed to activate.`, error);\n }\n });\n await Promise.all(promises);\n break;\n }\n }\n }\n\n /**\n * Deactivate the plugin and its downstream dependents if and only if the\n * plugin and its dependents all support `deactivate`.\n *\n * @param id - The ID of the plugin of interest.\n *\n * @returns A list of IDs of downstream plugins deactivated with this one.\n */\n async deactivatePlugin(id: string): Promise<string[]> {\n // Reject the promise if the plugin is not registered.\n const plugin = this._plugins.get(id);\n if (!plugin) {\n throw new ReferenceError(`Plugin '${id}' is not registered.`);\n }\n\n // Bail early if the plugin is not activated.\n if (!plugin.activated) {\n return [];\n }\n\n // Check that this plugin can deactivate.\n if (!plugin.deactivate) {\n throw new TypeError(`Plugin '${id}'#deactivate() method missing`);\n }\n\n // Find the optimal deactivation order for plugins downstream of this one.\n const manifest = Private.findDependents(id, this._plugins, this._services);\n const downstream = manifest.map(id => this._plugins.get(id)!);\n\n // Check that all downstream plugins can deactivate.\n for (const plugin of downstream) {\n if (!plugin.deactivate) {\n throw new TypeError(\n `Plugin ${plugin.id}#deactivate() method missing (depends on ${id})`\n );\n }\n }\n\n // Deactivate all downstream plugins.\n for (const plugin of downstream) {\n const services = [...plugin.requires, ...plugin.optional].map(service => {\n const id = this._services.get(service);\n return id ? this._plugins.get(id)!.service : null;\n });\n\n // Await deactivation so the next plugins only receive active services.\n await plugin.deactivate!(this.application, ...services);\n plugin.service = null;\n plugin.activated = false;\n }\n\n // Remove plugin ID and return manifest of deactivated plugins.\n manifest.pop();\n return manifest;\n }\n\n /**\n * Resolve a required service of a given type.\n *\n * @param token - The token for the service type of interest.\n *\n * @returns A promise which resolves to an instance of the requested\n * service, or rejects with an error if it cannot be resolved.\n *\n * #### Notes\n * Services are singletons. The same instance will be returned each\n * time a given service token is resolved.\n *\n * If the plugin which provides the service has not been activated,\n * resolving the service will automatically activate the plugin.\n *\n * User code will not typically call this method directly. Instead,\n * the required services for the user's plugins will be resolved\n * automatically when the plugin is activated.\n */\n async resolveRequiredService<U>(token: Token<U>): Promise<U> {\n // Reject the promise if there is no provider for the type.\n const id = this._services.get(token);\n if (!id) {\n throw new TypeError(`No provider for: ${token.name}.`);\n }\n\n // Activate the plugin if necessary.\n const plugin = this._plugins.get(id)!;\n if (!plugin.activated) {\n await this.activatePlugin(id);\n }\n\n return plugin.service;\n }\n\n /**\n * Resolve an optional service of a given type.\n *\n * @param token - The token for the service type of interest.\n *\n * @returns A promise which resolves to an instance of the requested\n * service, or `null` if it cannot be resolved.\n *\n * #### Notes\n * Services are singletons. The same instance will be returned each\n * time a given service token is resolved.\n *\n * If the plugin which provides the service has not been activated,\n * resolving the service will automatically activate the plugin.\n *\n * User code will not typically call this method directly. Instead,\n * the optional services for the user's plugins will be resolved\n * automatically when the plugin is activated.\n */\n async resolveOptionalService<U>(token: Token<U>): Promise<U | null> {\n // Resolve with `null` if there is no provider for the type.\n const id = this._services.get(token);\n if (!id) {\n return null;\n }\n\n // Activate the plugin if necessary.\n const plugin = this._plugins.get(id)!;\n if (!plugin.activated) {\n try {\n await this.activatePlugin(id);\n } catch (reason) {\n console.error(reason);\n return null;\n }\n }\n\n return plugin.service;\n }\n\n private _application: any = null;\n private _validatePlugin: (plugin: IPlugin<any, any>) => boolean = () => true;\n private _plugins = new Map<string, Private.IPluginData<T>>();\n private _services = new Map<Token<any>, string>();\n}\n\n/**\n * PluginRegistry namespace\n */\nexport namespace PluginRegistry {\n /**\n * PluginRegistry constructor options.\n */\n export interface IOptions {\n /**\n * Validate that a plugin is allowed to be registered.\n *\n * Default is `() => true`.\n *\n * @param plugin The plugin to validate\n * @returns Whether the plugin can be registered or not.\n *\n * #### Notes\n * We recommend you print a console message with the reason\n * a plugin is invalid.\n */\n validatePlugin?: (plugin: IPlugin<any, any>) => boolean;\n }\n\n /**\n * An options object for application startup.\n */\n export interface IStartOptions {\n /**\n * The plugins to activate on startup.\n *\n * #### Notes\n * These will be *in addition* to any `autoStart` plugins.\n */\n startPlugins?: string[];\n\n /**\n * The plugins to **not** activate on startup.\n *\n * #### Notes\n * This will override `startPlugins` and any `autoStart` plugins.\n */\n ignorePlugins?: string[];\n }\n}\n\n/**\n * The namespace for the module implementation details.\n */\nnamespace Private {\n /**\n * An object which holds the full application state for a plugin.\n */\n export interface IPluginData<T = any> {\n /**\n * The human readable ID of the plugin.\n */\n readonly id: string;\n\n /**\n * The description of the plugin.\n */\n readonly description: string;\n\n /**\n * Whether the plugin should be activated on application start or waiting for being\n * required. If the value is 'defer' then the plugin should be activated only after\n * the application is started.\n */\n readonly autoStart: boolean | 'defer';\n\n /**\n * The types of required services for the plugin, or `[]`.\n */\n readonly requires: Token<any>[];\n\n /**\n * The types of optional services for the the plugin, or `[]`.\n */\n readonly optional: Token<any>[];\n\n /**\n * The type of service provided by the plugin, or `null`.\n */\n readonly provides: Token<any> | null;\n\n /**\n * The function which activates the plugin.\n */\n readonly activate: (app: T, ...args: any[]) => any;\n\n /**\n * The optional function which deactivates the plugin.\n */\n readonly deactivate:\n | ((app: T, ...args: any[]) => void | Promise<void>)\n | null;\n\n /**\n * Whether the plugin has been activated.\n */\n activated: boolean;\n\n /**\n * The resolved service for the plugin, or `null`.\n */\n service: any | null;\n\n /**\n * The pending resolver promise, or `null`.\n */\n promise: Promise<void> | null;\n }\n\n class PluginData<T = any, U = any> implements IPluginData<T> {\n private _activated = false;\n private _promise: Promise<void> | null = null;\n private _service: U | null = null;\n\n constructor(plugin: IPlugin<T, U>) {\n this.id = plugin.id;\n this.description = plugin.description ?? '';\n this.activate = plugin.activate;\n this.deactivate = plugin.deactivate ?? null;\n this.provides = plugin.provides ?? null;\n this.autoStart = plugin.autoStart ?? false;\n this.requires = plugin.requires ? plugin.requires.slice() : [];\n this.optional = plugin.optional ? plugin.optional.slice() : [];\n }\n\n /**\n * The human readable ID of the plugin.\n */\n readonly id: string;\n\n /**\n * The description of the plugin.\n */\n readonly description: string;\n\n /**\n * Whether the plugin should be activated on application start or waiting for being\n * required. If the value is 'defer' then the plugin should be activated only after\n * the application is started.\n */\n readonly autoStart: boolean | 'defer';\n\n /**\n * The types of required services for the plugin, or `[]`.\n */\n readonly requires: Token<any>[];\n\n /**\n * The types of optional services for the the plugin, or `[]`.\n */\n readonly optional: Token<any>[];\n\n /**\n * The type of service provided by the plugin, or `null`.\n */\n readonly provides: Token<any> | null;\n\n /**\n * The function which activates the plugin.\n */\n readonly activate: (app: T, ...args: any[]) => any;\n\n /**\n * The optional function which deactivates the plugin.\n */\n readonly deactivate:\n | ((app: T, ...args: any[]) => void | Promise<void>)\n | null;\n\n /**\n * Whether the plugin has been activated.\n */\n get activated(): boolean {\n return this._activated;\n }\n set activated(a: boolean) {\n this._activated = a;\n }\n\n /**\n * The resolved service for the plugin, or `null`.\n */\n get service(): U | null {\n return this._service;\n }\n set service(s: U | null) {\n this._service = s;\n }\n\n /**\n * The pending resolver promise, or `null`.\n */\n get promise(): Promise<void> | null {\n return this._promise;\n }\n set promise(p: Promise<void> | null) {\n this._promise = p;\n }\n }\n\n /**\n * Create a normalized plugin data object for the given plugin.\n */\n export function createPluginData<T>(\n plugin: IPlugin<any, any>\n ): IPluginData<T> {\n return new PluginData(plugin);\n }\n\n /**\n * Ensure no cycle is present in the plugin resolution graph.\n *\n * If a cycle is detected, an error will be thrown.\n */\n export function ensureNoCycle(\n plugin: IPluginData,\n plugins: Map<string, IPluginData>,\n services: Map<Token<any>, string>\n ): void {\n const dependencies = [...plugin.requires, ...plugin.optional];\n const visit = (token: Token<any>): boolean => {\n if (token === plugin.provides) {\n return true;\n }\n const id = services.get(token);\n if (!id) {\n return false;\n }\n const visited = plugins.get(id)!;\n const dependencies = [...visited.requires, ...visited.optional];\n if (dependencies.length === 0) {\n return false;\n }\n trace.push(id);\n if (dependencies.some(visit)) {\n return true;\n }\n trace.pop();\n return false;\n };\n\n // Bail early if there cannot be a cycle.\n if (!plugin.provides || dependencies.length === 0) {\n return;\n }\n\n // Setup a stack to trace service resolution.\n const trace = [plugin.id];\n\n // Throw an exception if a cycle is present.\n if (dependencies.some(visit)) {\n throw new ReferenceError(`Cycle detected: ${trace.join(' -> ')}.`);\n }\n }\n\n /**\n * Find dependents in deactivation order.\n *\n * @param id - The ID of the plugin of interest.\n *\n * @param plugins - The map containing all plugins.\n *\n * @param services - The map containing all services.\n *\n * @returns A list of dependent plugin IDs in order of deactivation\n *\n * #### Notes\n * The final item of the returned list is always the plugin of interest.\n */\n export function findDependents(\n id: string,\n plugins: Map<string, IPluginData>,\n services: Map<Token<any>, string>\n ): string[] {\n const edges = new Array<[string, string]>();\n const add = (id: string): void => {\n const plugin = plugins.get(id)!;\n // FIXME In the case of missing optional dependencies, we may consider\n // deactivating and reactivating the plugin without the missing service.\n const dependencies = [...plugin.requires, ...plugin.optional];\n edges.push(\n ...dependencies.reduce<[string, string][]>((acc, dep) => {\n const service = services.get(dep);\n if (service) {\n // An edge is oriented from dependent to provider.\n acc.push([id, service]);\n }\n return acc;\n }, [])\n );\n };\n\n for (const id of plugins.keys()) {\n add(id);\n }\n\n // Filter edges\n // - Get all packages that dependent on the package to be deactivated\n const newEdges = edges.filter(edge => edge[1] === id);\n let oldSize = 0;\n while (newEdges.length > oldSize) {\n const previousSize = newEdges.length;\n // Get all packages that dependent on packages that will be deactivated\n const packagesOfInterest = new Set(newEdges.map(edge => edge[0]));\n for (const poi of packagesOfInterest) {\n edges\n .filter(edge => edge[1] === poi)\n .forEach(edge => {\n // We check it is not already included to deal with circular dependencies\n if (!newEdges.includes(edge)) {\n newEdges.push(edge);\n }\n });\n }\n oldSize = previousSize;\n }\n\n const sorted = topologicSort(newEdges);\n const index = sorted.findIndex(candidate => candidate === id);\n\n if (index === -1) {\n return [id];\n }\n\n return sorted.slice(0, index + 1);\n }\n\n /**\n * Collect the IDs of the plugins to activate on startup.\n */\n export function collectStartupPlugins(\n plugins: Map<string, IPluginData>,\n options: PluginRegistry.IStartOptions\n ): string[] {\n // Create a set to hold the plugin IDs.\n const collection = new Set<string>();\n\n // Collect the auto-start (non deferred) plugins.\n for (const id of plugins.keys()) {\n if (plugins.get(id)!.autoStart === true) {\n collection.add(id);\n }\n }\n\n // Add the startup plugins.\n if (options.startPlugins) {\n for (const id of options.startPlugins) {\n collection.add(id);\n }\n }\n\n // Remove the ignored plugins.\n if (options.ignorePlugins) {\n for (const id of options.ignorePlugins) {\n collection.delete(id);\n }\n }\n\n // Return the collected startup plugins.\n return Array.from(collection);\n }\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * A class which wraps a promise into a delegate object.\n *\n * #### Notes\n * This class is useful when the logic to resolve or reject a promise\n * cannot be defined at the point where the promise is created.\n */\nexport class PromiseDelegate<T> {\n /**\n * Construct a new promise delegate.\n */\n constructor() {\n this.promise = new Promise<T>((resolve, reject) => {\n this._resolve = resolve;\n this._reject = reject;\n });\n }\n\n /**\n * The promise wrapped by the delegate.\n */\n readonly promise: Promise<T>;\n\n /**\n * Resolve the wrapped promise with the given value.\n *\n * @param value - The value to use for resolving the promise.\n */\n resolve(value: T | PromiseLike<T>): void {\n let resolve = this._resolve;\n resolve(value);\n }\n\n /**\n * Reject the wrapped promise with the given value.\n *\n * @reason - The reason for rejecting the promise.\n */\n reject(reason: unknown): void {\n let reject = this._reject;\n reject(reason);\n }\n\n private _resolve: (value: T | PromiseLike<T>) => void;\n private _reject: (reason: any) => void;\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n/**\n * A runtime object which captures compile-time type information.\n *\n * #### Notes\n * A token captures the compile-time type of an interface or class in\n * an object which can be used at runtime in a type-safe fashion.\n */\nexport class Token<T> {\n /**\n * Construct a new token.\n *\n * @param name - A human readable name for the token.\n * @param description - Token purpose description for documentation.\n */\n constructor(name: string, description?: string) {\n this.name = name;\n this.description = description ?? '';\n this._tokenStructuralPropertyT = null!;\n }\n\n /**\n * Token purpose description.\n */\n readonly description?: string; // FIXME remove `?` for the next major version\n\n /**\n * The human readable name for the token.\n *\n * #### Notes\n * This can be useful for debugging and logging.\n */\n readonly name: string;\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n private _tokenStructuralPropertyT: T;\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\n// Fallback\nexport function fallbackRandomValues(buffer: Uint8Array): void {\n let value = 0;\n for (let i = 0, n = buffer.length; i < n; ++i) {\n if (i % 4 === 0) {\n value = (Math.random() * 0xffffffff) >>> 0;\n }\n buffer[i] = value & 0xff;\n value >>>= 8;\n }\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n\nimport { fallbackRandomValues } from './random';\n\n// Declare ambient variables for `window` and `require` to avoid a\n// hard dependency on both. This package must run on node.\ndeclare let window: any;\n\n/**\n * The namespace for random number related functionality.\n */\nexport namespace Random {\n /**\n * A function which generates random bytes.\n *\n * @param buffer - The `Uint8Array` to fill with random bytes.\n *\n * #### Notes\n * A cryptographically strong random number generator will be used if\n * available. Otherwise, `Math.random` will be used as a fallback for\n * randomness.\n *\n * The following RNGs are supported, listed in order of precedence:\n * - `window.crypto.getRandomValues`\n * - `window.msCrypto.getRandomValues`\n * - `require('crypto').randomFillSync\n * - `require('crypto').randomBytes\n * - `Math.random`\n */\n export const getRandomValues = (() => {\n // Look up the crypto module if available.\n const crypto: any =\n (typeof window !== 'undefined' && (window.crypto || window.msCrypto)) ||\n null;\n\n // Modern browsers and IE 11\n if (crypto && typeof crypto.getRandomValues === 'function') {\n return function getRandomValues(buffer: Uint8Array): void {\n return crypto.getRandomValues(buffer);\n };\n }\n\n // Fallback\n return fallbackRandomValues;\n })();\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\n/**\n * A function which creates a function that generates UUID v4 identifiers.\n *\n * @returns A new function that creates a UUID v4 string.\n *\n * #### Notes\n * This implementation complies with RFC 4122.\n *\n * This uses `Random.getRandomValues()` for random bytes, which in\n * turn will use the underlying `crypto` module of the platform if\n * it is available. The fallback for randomness is `Math.random`.\n */\nexport function uuid4Factory(\n getRandomValues: (bytes: Uint8Array) => void\n): () => string {\n // Create a 16 byte array to hold the random values.\n const bytes = new Uint8Array(16);\n\n // Create a look up table from bytes to hex strings.\n const lut = new Array<string>(256);\n\n // Pad the single character hex digits with a leading zero.\n for (let i = 0; i < 16; ++i) {\n lut[i] = '0' + i.toString(16);\n }\n\n // Populate the rest of the hex digits.\n for (let i = 16; i < 256; ++i) {\n lut[i] = i.toString(16);\n }\n\n // Return a function which generates the UUID.\n return function uuid4(): string {\n // Get a new batch of random values.\n getRandomValues(bytes);\n\n // Set the UUID version number to 4.\n bytes[6] = 0x40 | (bytes[6] & 0x0f);\n\n // Set the clock sequence bit to the RFC spec.\n bytes[8] = 0x80 | (bytes[8] & 0x3f);\n\n // Assemble the UUID string.\n return (\n lut[bytes[0]] +\n lut[bytes[1]] +\n lut[bytes[2]] +\n lut[bytes[3]] +\n '-' +\n lut[bytes[4]] +\n lut[bytes[5]] +\n '-' +\n lut[bytes[6]] +\n lut[bytes[7]] +\n '-' +\n lut[bytes[8]] +\n lut[bytes[9]] +\n '-' +\n lut[bytes[10]] +\n lut[bytes[11]] +\n lut[bytes[12]] +\n lut[bytes[13]] +\n lut[bytes[14]] +\n lut[bytes[15]]\n );\n };\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n/*-----------------------------------------------------------------------------\n| Copyright (c) 2014-2017, PhosphorJS Contributors\n|\n| Distributed under the terms of the BSD 3-Clause License.\n|\n| The full license is in the file LICENSE, distributed with this software.\n|----------------------------------------------------------------------------*/\nimport { Random } from './random.browser';\nimport { uuid4Factory } from './uuid';\n\n/**\n * The namespace for UUID related functionality.\n */\nexport namespace UUID {\n /**\n * A function which generates UUID v4 identifiers.\n *\n * @returns A new UUID v4 string.\n *\n * #### Notes\n * This implementation complies with RFC 4122.\n *\n * This uses `Random.getRandomValues()` for random bytes, which in\n * turn will use the underlying `crypto` module of the platform if\n * it is available. The fallback for randomness is `Math.random`.\n */\n export const uuid4 = uuid4Factory(Random.getRandomValues);\n}\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\n// Types and implementation inspired from https://github.com/jvilk/BrowserFS\n// LICENSE: https://github.com/jvilk/BrowserFS/blob/8977a704ea469d05daf857e4818bef1f4f498326/LICENSE\n// And from https://github.com/gzuidhof/starboard-notebook\n\n// LICENSE: https://github.com/gzuidhof/starboard-notebook/blob/cd8d3fc30af4bd29cdd8f6b8c207df8138f5d5dd/LICENSE\n\n/**\n * Types for Emscripten primitives.\n *\n * Ideally, much more of these would be taken from `@types/emscripten`.\n */\n\ntype EmscriptenFS = typeof FS;\n\nexport const DIR_MODE = 16895; // 040777\nexport const FILE_MODE = 33206; // 100666\nexport const SEEK_CUR = 1;\nexport const SEEK_END = 2;\n\nexport interface IStats {\n dev: number;\n ino?: number;\n mode?: number;\n nlink: number;\n uid: number;\n gid: number;\n rdev: number;\n size: number;\n blksize: number;\n blocks: number;\n atime: Date | string;\n mtime: Date | string;\n ctime: Date | string;\n timestamp?: number;\n}\n\nexport interface IEmscriptenFSNode {\n id: number;\n name: string;\n mode: number;\n parent: IEmscriptenFSNode;\n mount: { opts: { root: string } };\n stream_ops: IEmscriptenStreamOps;\n node_ops: IEmscriptenNodeOps;\n timestamp: number;\n atime: number;\n mtime: number;\n ctime: number;\n}\n\nexport interface IEmscriptenStream {\n node: IEmscriptenFSNode;\n nfd: any;\n flags?: number;\n position?: number;\n shared: {\n flags: number;\n position: number;\n };\n}\n\nexport function instanceOfStream(\n nodeOrStream: IEmscriptenFSNode | IEmscriptenStream,\n): nodeOrStream is IEmscriptenStream {\n return 'node' in nodeOrStream;\n}\n\nexport interface IEmscriptenNodeOps {\n getattr(node: IEmscriptenFSNode | IEmscriptenStream): IStats;\n setattr(node: IEmscriptenFSNode | IEmscriptenStream, attr: IStats): void;\n lookup(\n parent: IEmscriptenFSNode | IEmscriptenStream,\n name: string,\n ): IEmscriptenFSNode;\n mknod(\n parent: IEmscriptenFSNode | IEmscriptenStream,\n name: string,\n mode: number,\n dev: number,\n ): IEmscriptenFSNode;\n rename(\n oldNode: IEmscriptenFSNode | IEmscriptenStream,\n newDir: IEmscriptenFSNode | IEmscriptenStream,\n newName: string,\n ): void;\n unlink(parent: IEmscriptenFSNode | IEmscriptenStream, name: string): void;\n rmdir(parent: IEmscriptenFSNode | IEmscriptenStream, name: string): void;\n readdir(node: IEmscriptenFSNode | IEmscriptenStream): string[];\n symlink(\n parent: IEmscriptenFSNode | IEmscriptenStream,\n newName: string,\n oldPath: string,\n ): void;\n readlink(node: IEmscriptenFSNode | IEmscriptenStream): string;\n}\n\nexport interface IEmscriptenStreamOps {\n open(stream: IEmscriptenStream): void;\n close(stream: IEmscriptenStream): void;\n read(\n stream: IEmscriptenStream,\n buffer: Uint8Array,\n offset: number,\n length: number,\n position: number,\n ): number;\n write(\n stream: IEmscriptenStream,\n buffer: Uint8Array,\n offset: number,\n length: number,\n position: number,\n ): number;\n llseek(stream: IEmscriptenStream, offset: number, whence: number): number;\n}\n\n/**\n * The emscripten filesystem module API.\n */\nexport type FS = EmscriptenFS & {\n ErrnoError: any;\n createNode: (\n parent: IEmscriptenFSNode | null,\n name: string,\n mode: number,\n dev: number,\n ) => IEmscriptenFSNode;\n};\n\n/**\n * The emscripten filesystem error codes.\n */\nexport type ERRNO_CODES = any;\n\n/**\n * The emscripten FS Path API.\n */\nexport type PATH = {\n basename: (path: string) => string;\n dirname: (path: string) => string;\n join: (...parts: string[]) => string;\n join2: (l: string, r: string) => string;\n normalize: (path: string) => string;\n splitPath: (filename: string) => string;\n};\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\n// Types and implementation inspired from https://github.com/jvilk/BrowserFS\n// LICENSE: https://github.com/jvilk/BrowserFS/blob/8977a704ea469d05daf857e4818bef1f4f498326/LICENSE\n// And from https://github.com/gzuidhof/starboard-notebook\n\n// LICENSE: https://github.com/gzuidhof/starboard-notebook/blob/cd8d3fc30af4bd29cdd8f6b8c207df8138f5d5dd/LICENSE\nimport type { Contents } from '@jupyterlab/services';\n\nimport { UUID } from '@lumino/coreutils';\n\nimport type {\n FS,\n ERRNO_CODES,\n PATH,\n IEmscriptenStream,\n IEmscriptenStreamOps,\n IEmscriptenNodeOps,\n IEmscriptenFSNode,\n IStats,\n} from './emscripten';\nimport { DIR_MODE, SEEK_CUR, SEEK_END, instanceOfStream } from './emscripten';\n\nexport const DRIVE_SEPARATOR = ':';\n\nexport const BLOCK_SIZE = 4096;\n\nconst encoder = new TextEncoder();\nconst decoder = new TextDecoder('utf-8');\n\nexport type TDriveMethod =\n | 'readdir'\n | 'rmdir'\n | 'rename'\n | 'getmode'\n | 'lookup'\n | 'mknod'\n | 'getattr'\n | 'get'\n | 'put';\n\n/**\n * Type of the data argument for the drive request, based on the request name\n */\nexport type TDriveData = {\n rename: {\n /**\n * The new path for the file\n */\n newPath: string;\n };\n mknod: {\n /**\n * The mode of the file to create\n */\n mode: number;\n };\n put: {\n /**\n * The file content to write\n */\n data: any;\n\n /**\n * The file content format\n */\n format: Contents.FileFormat;\n };\n};\n\n/**\n * Drive request\n */\nexport type TDriveRequest<T extends TDriveMethod> = {\n /**\n * The method of the request (rmdir, readdir etc)\n */\n method: T;\n\n /**\n * A unique ID to identify the origin of this request\n */\n browsingContextId?: string;\n\n /**\n * A unique ID to correlate this specific request with its response\n */\n requestId?: string;\n\n /**\n * The path to the file/directory for which the request was sent\n */\n path: string;\n} & (T extends keyof TDriveData ? { data: TDriveData[T] } : object);\n\ntype TDriveResponses = {\n readdir: string[];\n rmdir: null;\n rename: null;\n getmode: number;\n lookup: DriveFS.ILookup;\n mknod: null;\n getattr: IStats;\n get: {\n /**\n * The returned file content\n */\n content: any;\n\n /**\n * The content format\n */\n format: Contents.FileFormat;\n } | null;\n put: null;\n};\n\n/**\n * Drive response\n */\nexport type TDriveResponse<T extends TDriveMethod> = TDriveResponses[T];\n\n// Mapping flag -> do we need to overwrite the file upon closing it\nconst flagNeedsWrite: { [flag: number]: boolean } = {\n 0 /*O_RDONLY*/: false,\n 1 /*O_WRONLY*/: true,\n 2 /*O_RDWR*/: true,\n 64 /*O_CREAT*/: true,\n 65 /*O_WRONLY|O_CREAT*/: true,\n 66 /*O_RDWR|O_CREAT*/: true,\n 129 /*O_WRONLY|O_EXCL*/: true,\n 193 /*O_WRONLY|O_CREAT|O_EXCL*/: true,\n 514 /*O_RDWR|O_TRUNC*/: true,\n 577 /*O_WRONLY|O_CREAT|O_TRUNC*/: true,\n 578 /*O_CREAT|O_RDWR|O_TRUNC*/: true,\n 705 /*O_WRONLY|O_CREAT|O_EXCL|O_TRUNC*/: true,\n 706 /*O_RDWR|O_CREAT|O_EXCL|O_TRUNC*/: true,\n 1024 /*O_APPEND*/: true,\n 1025 /*O_WRONLY|O_APPEND*/: true,\n 1026 /*O_RDWR|O_APPEND*/: true,\n 1089 /*O_WRONLY|O_CREAT|O_APPEND*/: true,\n 1090 /*O_RDWR|O_CREAT|O_APPEND*/: true,\n 1153 /*O_WRONLY|O_EXCL|O_APPEND*/: true,\n 1154 /*O_RDWR|O_EXCL|O_APPEND*/: true,\n 1217 /*O_WRONLY|O_CREAT|O_EXCL|O_APPEND*/: true,\n 1218 /*O_RDWR|O_CREAT|O_EXCL|O_APPEND*/: true,\n 4096 /*O_RDONLY|O_DSYNC*/: true,\n 4098 /*O_RDWR|O_DSYNC*/: true,\n};\n\n/** Implementation-specifc extension of an open stream, adding the file. */\nexport interface IDriveStream extends IEmscriptenStream {\n file?: DriveFS.IFile;\n}\n\nexport class DriveFSEmscriptenStreamOps implements IEmscriptenStreamOps {\n private fs: DriveFS;\n\n constructor(fs: DriveFS) {\n this.fs = fs;\n }\n\n open(stream: IDriveStream): void {\n const path = this.fs.realPath(stream.node);\n\n if (this.fs.FS.isFile(stream.node.mode)) {\n try {\n const file = this.fs.API.get(path);\n stream.file = file;\n } catch (e) {\n // If we're opening a file for writing and the file does not exist, create it! Otherwise, throw the proper error\n // We need to do this because the current thread is thinking a file exist (isFile returns true)\n // whilst it was actually deleted in the main thread\n\n // if writing\n const flags = stream.flags ?? stream.shared.flags;\n let parsedFlags = typeof flags === 'string' ? parseInt(flags, 10) : flags;\n parsedFlags &= 0x1fff;\n\n let needsWrite = true;\n if (parsedFlags in flagNeedsWrite) {\n needsWrite = flagNeedsWrite[parsedFlags];\n }\n if (needsWrite) {\n stream.node = this.fs.node_ops.mknod(\n stream.node.parent,\n stream.node.name,\n stream.node.mode,\n 0, // dev should be 0 for regular files\n );\n const file = this.fs.API.get(path);\n stream.file = file;\n } else {\n throw new this.fs.FS.ErrnoError(this.fs.ERRNO_CODES['ENOENT']);\n }\n }\n }\n }\n\n close(stream: IDriveStream): void {\n if (!this.fs.FS.isFile(stream.node.mode) || !stream.file) {\n return;\n }\n\n const path = this.fs.realPath(stream.node);\n\n const flags = stream.flags ?? stream.shared.flags;\n let parsedFlags = typeof flags === 'string' ? parseInt(flags, 10) : flags;\n parsedFlags &= 0x1fff;\n\n let needsWrite = true;\n if (parsedFlags in flagNeedsWrite) {\n needsWrite = flagNeedsWrite[parsedFlags];\n }\n\n if (needsWrite) {\n this.fs.API.put(path, stream.file);\n }\n\n stream.file = undefined;\n }\n\n read(\n stream: IDriveStream,\n buffer: Uint8Array,\n offset: number,\n length: number,\n position: number,\n ): number {\n if (\n length <= 0 ||\n stream.file === undefined ||\n position >= (stream.file.data.length || 0)\n ) {\n return 0;\n }\n\n const size = Math.min(stream.file.data.length - position, length);\n buffer.set(stream.file.data.subarray(position, position + size), offset);\n return size;\n }\n\n write(\n stream: IDriveStream,\n buffer: Uint8Array,\n offset: number,\n length: number,\n position: number,\n ): number {\n if (length <= 0 || stream.file === undefined) {\n return 0;\n }\n\n const now = Date.now();\n stream.node.timestamp = now;\n stream.node.atime = now;\n stream.node.mtime = now;\n stream.node.ctime = now;\n\n if (position + length > (stream.file?.data.length || 0)) {\n const oldData = stream.file.data ? stream.file.data : new Uint8Array();\n stream.file.data = new Uint8Array(position + length);\n stream.file.data.set(oldData);\n }\n\n stream.file.data.set(buffer.subarray(offset, offset + length), position);\n\n return length;\n }\n\n llseek(stream: IDriveStream, offset: number, whence: number): number {\n let position = offset;\n if (whence === SEEK_CUR) {\n position += stream.position ?? stream.shared.position;\n } else if (whence === SEEK_END) {\n if (this.fs.FS.isFile(stream.node.mode)) {\n if (stream.file !== undefined) {\n position += stream.file.data.length;\n } else {\n throw new this.fs.FS.ErrnoError(this.fs.ERRNO_CODES.EPERM);\n }\n }\n }\n\n if (position < 0) {\n throw new this.fs.FS.ErrnoError(this.fs.ERRNO_CODES.EINVAL);\n }\n\n return position;\n }\n}\n\nexport class DriveFSEmscriptenNodeOps implements IEmscriptenNodeOps {\n private fs: DriveFS;\n\n constructor(fs: DriveFS) {\n this.fs = fs;\n }\n\n protected node = (\n nodeOrStream: IEmscriptenFSNode | IEmscriptenStream,\n ): IEmscriptenFSNode => {\n if (instanceOfStream(nodeOrStream)) {\n return nodeOrStream.node;\n }\n return nodeOrStream;\n };\n\n getattr = (value: IEmscriptenFSNode | IEmscriptenStream): IStats => {\n const node = this.node(value);\n return {\n ...this.fs.API.getattr(this.fs.realPath(node)),\n mode: node.mode,\n ino: node.id,\n };\n };\n\n setattr = (value: IEmscriptenFSNode | IEmscriptenStream, attr: IStats): void => {\n const node = this.node(value);\n for (const [key, value] of Object.entries(attr)) {\n switch (key) {\n case 'mode':\n node.mode = value;\n break;\n case 'timestamp':\n node.timestamp = value;\n break;\n case 'atime':\n node.atime = value;\n break;\n case 'mtime':\n node.mtime = value;\n break;\n case 'ctime':\n node.ctime = value;\n break;\n case 'size': {\n const size = value;\n const path = this.fs.realPath(node);\n if (this.fs.FS.isFile(node.mode) && size >= 0) {\n let file;\n try {\n file = this.fs.API.get(path);\n } catch (e) {\n // TODO: Should do anything here? Should we create the file?\n break;\n }\n\n const oldData = file.data ? file.data : new Uint8Array();\n if (size !== oldData.length) {\n if (size < oldData.length) {\n file.data = file.data.slice(0, size);\n } else {\n file.data = new Uint8Array(size);\n file.data.set(oldData);\n }\n this.fs.API.put(path, file);\n }\n } else {\n console.warn('setattr size of', size, 'on', node, 'not yet implemented');\n }\n break;\n }\n case 'dontFollow':\n // Ignore for now\n break;\n default:\n console.warn('setattr', key, 'of', value, 'on', node, 'not yet implemented');\n break;\n }\n }\n };\n\n lookup = (\n parent: IEmscriptenFSNode | IEmscriptenStream,\n name: string,\n ): IEmscriptenFSNode => {\n const node = this.node(parent);\n const path = this.fs.PATH.join2(this.fs.realPath(node), name);\n const result = this.fs.API.lookup(path);\n if (!result.ok) {\n throw new this.fs.FS.ErrnoError(this.fs.ERRNO_CODES['ENOENT']);\n }\n return this.fs.createNode(node, name, result.mode!, 0);\n };\n\n mknod = (\n parent: IEmscriptenFSNode | IEmscriptenStream,\n name: string,\n mode: number,\n dev: number,\n ): IEmscriptenFSNode => {\n const node = this.node(parent);\n const path = this.fs.PATH.join2(this.fs.realPath(node), name);\n this.fs.API.mknod(path, mode);\n return this.fs.createNode(node, name, mode, dev);\n };\n\n rename = (\n value: IEmscriptenFSNode | IEmscriptenStream,\n newDir: IEmscriptenFSNode | IEmscriptenStream,\n newName: string,\n ): void => {\n const oldNode = this.node(value);\n const newDirNode = this.node(newDir);\n this.fs.API.rename(\n oldNode.parent\n ? this.fs.PATH.join2(this.fs.realPath(oldNode.parent), oldNode.name)\n : oldNode.name,\n this.fs.PATH.join2(this.fs.realPath(newDirNode), newName),\n );\n\n // Updating the in-memory node\n oldNode.name = newName;\n oldNode.parent = newDirNode;\n };\n\n unlink = (parent: IEmscriptenFSNode | IEmscriptenStream, name: string): null => {\n return this.fs.API.rmdir(\n this.fs.PATH.join2(this.fs.realPath(this.node(parent)), name),\n );\n };\n\n rmdir = (parent: IEmscriptenFSNode | IEmscriptenStream, name: string): null => {\n return this.fs.API.rmdir(\n this.fs.PATH.join2(this.fs.realPath(this.node(parent)), name),\n );\n };\n\n readdir = (value: IEmscriptenFSNode | IEmscriptenStream): string[] => {\n return this.fs.API.readdir(this.fs.realPath(this.node(value)));\n };\n\n symlink = (\n parent: IEmscriptenFSNode | IEmscriptenStream,\n newName: string,\n oldPath: string,\n ): void => {\n throw new this.fs.FS.ErrnoError(this.fs.ERRNO_CODES['EPERM']);\n };\n\n readlink = (node: IEmscriptenFSNode | IEmscriptenStream): string => {\n throw new this.fs.FS.ErrnoError(this.fs.ERRNO_CODES['EINVAL']);\n };\n}\n\n/**\n * ContentsAPI base class\n */\nexport abstract class ContentsAPI {\n constructor(options: ContentsAPI.IOptions) {\n this._driveName = options.driveName;\n this._mountpoint = options.mountpoint;\n\n this.FS = options.FS;\n this.ERRNO_CODES = options.ERRNO_CODES;\n }\n\n lookup(path: string): DriveFS.ILookup {\n return this.request({ method: 'lookup', path: this.normalizePath(path) });\n }\n\n getmode(path: string): number {\n return this.request({ method: 'getmode', path: this.normalizePath(path) });\n }\n\n mknod(path: string, mode: number): null {\n return this.request({\n method: 'mknod',\n path: this.normalizePath(path),\n data: { mode },\n });\n }\n\n rename(oldPath: string, newPath: string): null {\n return this.request({\n method: 'rename',\n path: this.normalizePath(oldPath),\n data: { newPath: this.normalizePath(newPath) },\n });\n }\n\n readdir(path: string): string[] {\n const dirlist = this.request({\n method: 'readdir',\n path: this.normalizePath(path),\n });\n dirlist.push('.');\n dirlist.push('..');\n return dirlist;\n }\n\n rmdir(path: string): null {\n return this.request({ method: 'rmdir', path: this.normalizePath(path) });\n }\n\n get(path: string): DriveFS.IFile {\n const response = this.request({\n method: 'get',\n path: this.normalizePath(path),\n });\n\n if (!response) {\n throw new this.FS.ErrnoError(this.ERRNO_CODES['ENOENT']);\n }\n\n const serializedContent = response.content;\n const format: 'json' | 'text' | 'base64' | null = response.format;\n\n switch (format) {\n case 'json':\n case 'text':\n return {\n data: encoder.encode(serializedContent),\n format,\n };\n case 'base64': {\n const binString = atob(serializedContent);\n const len = binString.length;\n const data = new Uint8Array(len);\n for (let i = 0; i < len; i++) {\n data[i] = binString.charCodeAt(i);\n }\n return {\n data,\n format,\n };\n }\n default:\n throw new this.FS.ErrnoError(this.ERRNO_CODES['ENOENT']);\n }\n }\n\n put(path: string, value: DriveFS.IFile): null {\n switch (value.format) {\n case 'json':\n case 'text':\n return this.request({\n method: 'put',\n path: this.normalizePath(path),\n data: {\n format: value.format,\n data: decoder.decode(value.data),\n },\n });\n case 'base64': {\n let binary = '';\n for (let i = 0; i < value.data.byteLength; i++) {\n binary += String.fromCharCode(value.data[i]);\n }\n return this.request({\n method: 'put',\n path: this.normalizePath(path),\n data: {\n format: value.format,\n data: btoa(binary),\n },\n });\n }\n }\n }\n\n getattr(path: string): IStats {\n const stats = this.request({\n method: 'getattr',\n path: this.normalizePath(path),\n });\n\n // Emscripten 4.0.9+ (used by Pyodide 0.28+) requires all three timestamps\n // to be valid Date objects with .getTime() method (see https://github.com/emscripten-core/emscripten/pull/22998).\n // Fallback to epoch if any timestamp is missing/null/undefined.\n const defaultDate = new Date(0);\n stats.atime = stats.atime ? new Date(stats.atime) : defaultDate;\n stats.mtime = stats.mtime ? new Date(stats.mtime) : defaultDate;\n stats.ctime = stats.ctime ? new Date(stats.ctime) : defaultDate;\n\n // ensure a non-undefined size (0 isn't great, though)\n stats.size = stats.size || 0;\n return stats;\n }\n\n /**\n * Normalize a Path by making it compliant for the content manager\n *\n * @param path: the path relatively to the Emscripten drive\n */\n normalizePath(path: string): string {\n // Remove mountpoint prefix\n if (path.startsWith(this._mountpoint)) {\n path = path.slice(this._mountpoint.length);\n }\n\n // Add JupyterLab drive name\n if (this._driveName) {\n path = `${this._driveName}${DRIVE_SEPARATOR}${path}`;\n }\n\n return path;\n }\n\n abstract request<T extends TDriveMethod>(data: TDriveRequest<T>): TDriveResponse<T>;\n\n private _driveName: string;\n private _mountpoint: string;\n\n protected FS: FS;\n protected ERRNO_CODES: ERRNO_CODES;\n}\n\n/**\n * An Emscripten-compatible synchronous Contents API using the service worker.\n */\nexport class ServiceWorkerContentsAPI extends ContentsAPI {\n /**\n * Construct a new ServiceWorkerContentsAPI.\n */\n constructor(options: ServiceWorkerContentsAPI.IOptions) {\n super(options);\n\n this._baseUrl = options.baseUrl;\n this._browsingContextId = options.browsingContextId || '';\n }\n\n request<T extends TDriveMethod>(data: TDriveRequest<T>): TDriveResponse<T> {\n const xhr = new XMLHttpRequest();\n xhr.open('POST', encodeURI(this.endpoint), false);\n\n // Generate unique request ID for correlation\n const requestId = UUID.uuid4();\n\n // Add the origin browsing context ID and request ID to the request\n const requestWithMetadata = {\n data: { ...data, requestId },\n browsingContextId: this._browsingContextId,\n requestId,\n };\n\n try {\n xhr.send(JSON.stringify(requestWithMetadata));\n } catch (e) {\n console.error(e);\n }\n\n if (xhr.status >= 400) {\n throw new this.FS.ErrnoError(this.ERRNO_CODES['EINVAL']);\n }\n\n return JSON.parse(xhr.responseText);\n }\n\n /**\n * Get the api/drive endpoint\n */\n get endpoint(): string {\n return `${this._baseUrl}api/drive`;\n }\n\n private _baseUrl: string;\n private _browsingContextId: string;\n}\n\nexport class DriveFS {\n FS: FS;\n API: ContentsAPI;\n PATH: PATH;\n ERRNO_CODES: ERRNO_CODES;\n driveName: string;\n\n constructor(options: DriveFS.IOptions) {\n this.FS = options.FS;\n this.PATH = options.PATH;\n this.ERRNO_CODES = options.ERRNO_CODES;\n this.API = this.createAPI(options);\n\n this.driveName = options.driveName;\n\n this.node_ops = new DriveFSEmscriptenNodeOps(this);\n this.stream_ops = new DriveFSEmscriptenStreamOps(this);\n }\n\n node_ops: IEmscriptenNodeOps;\n stream_ops: IEmscriptenStreamOps;\n\n /**\n * Create the ContentsAPI.\n *\n * This is supposed to be overwritten if needed.\n */\n createAPI(options: DriveFS.IOptions): ContentsAPI {\n if (!options.browsingContextId || !options.baseUrl) {\n throw new Error(\n 'Cannot create service-worker API without current browsingContextId',\n );\n }\n\n return new ServiceWorkerContentsAPI(options as ServiceWorkerContentsAPI.IOptions);\n }\n\n mount(mount: any): IEmscriptenFSNode {\n return this.createNode(null, mount.mountpoint, DIR_MODE | 511, 0);\n }\n\n createNode(\n parent: IEmscriptenFSNode | null,\n name: string,\n mode: number,\n dev: number,\n ): IEmscriptenFSNode {\n const FS = this.FS;\n if (!FS.isDir(mode) && !FS.isFile(mode)) {\n throw new FS.ErrnoError(this.ERRNO_CODES['EINVAL']);\n }\n const node = FS.createNode(parent, name, mode, dev);\n node.node_ops = this.node_ops;\n node.stream_ops = this.stream_ops;\n return node;\n }\n\n getMode(path: string): number {\n return this.API.getmode(path);\n }\n\n realPath(node: IEmscriptenFSNode): string {\n const parts: string[] = [];\n let currentNode: IEmscriptenFSNode = node;\n\n parts.push(currentNode.name);\n while (currentNode.parent !== currentNode) {\n currentNode = currentNode.parent;\n parts.push(currentNode.name);\n }\n parts.reverse();\n\n return this.PATH.join.apply(null, parts);\n }\n}\n\n/**\n * A namespace for ContentsAPI configurations, etc.\n */\nexport namespace ContentsAPI {\n /**\n * Initialization options for a contents API;\n */\n export interface IOptions {\n /**\n * The name of the drive to use for the contents API request.\n */\n driveName: string;\n\n /**\n * Where to mount files in the kernel.\n */\n mountpoint: string;\n\n /**\n * The filesystem module API.\n */\n FS: FS;\n\n /**\n * The filesystem error codes.\n */\n ERRNO_CODES: ERRNO_CODES;\n }\n}\n\n/**\n * A namespace for ServiceWorkerContentsAPI configurations, etc.\n */\nexport namespace ServiceWorkerContentsAPI {\n /**\n * Initialization options for a service worker contents API\n */\n export interface IOptions extends ContentsAPI.IOptions {\n /**\n * The base URL.\n */\n baseUrl: string;\n\n /**\n * The ID of the browsing context where the request originated.\n */\n browsingContextId: string;\n }\n}\n\n/**\n * A namespace for DriveFS configurations, etc.\n */\nexport namespace DriveFS {\n /**\n * A file representation;\n */\n export interface IFile {\n data: Uint8Array;\n format: 'json' | 'text' | 'base64';\n }\n\n /**\n * The response to a lookup request;\n */\n export interface ILookup {\n ok: boolean;\n mode?: number;\n }\n\n /**\n * Initialization options for a drive;\n */\n export interface IOptions {\n FS: FS;\n PATH: PATH;\n ERRNO_CODES: ERRNO_CODES;\n baseUrl: string;\n driveName: string;\n mountpoint: string;\n browsingContextId?: string;\n }\n}\n", "export const ARRAY = 'array';\nexport const BIGINT = 'bigint';\nexport const BOOLEAN = 'boolean';\nexport const FUNCTION = 'function';\nexport const NULL = 'null';\nexport const NUMBER = 'number';\nexport const OBJECT = 'object';\nexport const STRING = 'string';\nexport const SYMBOL = 'symbol';\nexport const UNDEFINED = 'undefined';\n", "// \u26A0\uFE0F AUTOMATICALLY GENERATED - DO NOT CHANGE\nexport const CHANNEL = '64e10b34-2bf7-4616-9668-f99de5aa046e';\n\nexport const MAIN = 'M' + CHANNEL;\nexport const THREAD = 'T' + CHANNEL;\n", "export const APPLY = 'apply';\nexport const CONSTRUCT = 'construct';\nexport const DEFINE_PROPERTY = 'defineProperty';\nexport const DELETE_PROPERTY = 'deleteProperty';\nexport const GET = 'get';\nexport const GET_OWN_PROPERTY_DESCRIPTOR = 'getOwnPropertyDescriptor';\nexport const GET_PROTOTYPE_OF = 'getPrototypeOf';\nexport const HAS = 'has';\nexport const IS_EXTENSIBLE = 'isExtensible';\nexport const OWN_KEYS = 'ownKeys';\nexport const PREVENT_EXTENSION = 'preventExtensions';\nexport const SET = 'set';\nexport const SET_PROTOTYPE_OF = 'setPrototypeOf';\n", "// The goal of this file is to normalize SAB\n// at least in main -> worker() use cases.\n// This still cannot possibly solve the sync\n// worker -> main() use case if SharedArrayBuffer\n// is not available or usable.\n\nimport {CHANNEL} from './channel.js';\n\nconst {isArray} = Array;\n\nlet {SharedArrayBuffer, window} = globalThis;\nlet {notify, wait, waitAsync} = Atomics;\nlet postPatched = null;\n\n// This is needed for some version of Firefox\nif (!waitAsync) {\n waitAsync = buffer => ({\n value: new Promise(onmessage => {\n // encodeURIComponent('onmessage=({data:b})=>(Atomics.wait(b,0),postMessage(0))')\n let w = new Worker('data:application/javascript,onmessage%3D(%7Bdata%3Ab%7D)%3D%3E(Atomics.wait(b%2C0)%2CpostMessage(0))');\n w.onmessage = onmessage;\n w.postMessage(buffer);\n })\n });\n}\n\n// Monkey-patch SharedArrayBuffer if needed\ntry {\n new SharedArrayBuffer(4);\n}\ncatch (_) {\n SharedArrayBuffer = ArrayBuffer;\n\n const ids = new WeakMap;\n // patch only main -> worker():async use case\n if (window) {\n const resolvers = new Map;\n const {prototype: {postMessage}} = Worker;\n\n const listener = event => {\n const details = event.data?.[CHANNEL];\n if (!isArray(details)) {\n event.stopImmediatePropagation();\n const { id, sb } = details;\n resolvers.get(id)(sb);\n }\n };\n\n postPatched = function (data, ...rest) {\n const details = data?.[CHANNEL];\n if (isArray(details)) {\n const [id, sb] = details;\n ids.set(sb, id);\n this.addEventListener('message', listener);\n }\n return postMessage.call(this, data, ...rest);\n };\n\n waitAsync = sb => ({\n value: new Promise(resolve => {\n resolvers.set(ids.get(sb), resolve);\n }).then(buff => {\n resolvers.delete(ids.get(sb));\n ids.delete(sb);\n for (let i = 0; i < buff.length; i++) sb[i] = buff[i];\n return 'ok';\n })\n });\n }\n else {\n const as = (id, sb) => ({[CHANNEL]: { id, sb }});\n\n notify = sb => {\n postMessage(as(ids.get(sb), sb));\n };\n\n addEventListener('message', event => {\n const details = event.data?.[CHANNEL];\n if (isArray(details)) {\n const [id, sb] = details;\n ids.set(sb, id);\n }\n });\n }\n}\n\nexport {SharedArrayBuffer, isArray, notify, postPatched, wait, waitAsync};\n", "/*! (c) Andrea Giammarchi - ISC */\n\nimport {FUNCTION} from 'proxy-target/types';\n\nimport {CHANNEL} from './channel.js';\nimport {GET, HAS, SET} from './shared/traps.js';\n\nimport {SharedArrayBuffer, isArray, notify, postPatched, wait, waitAsync} from './bridge.js';\n\n// just minifier friendly for Blob Workers' cases\nconst {Int32Array, Map, Uint16Array} = globalThis;\n\n// common constants / utilities for repeated operations\nconst {BYTES_PER_ELEMENT: I32_BYTES} = Int32Array;\nconst {BYTES_PER_ELEMENT: UI16_BYTES} = Uint16Array;\n\nconst waitInterrupt = (sb, delay, handler) => {\n while (wait(sb, 0, 0, delay) === 'timed-out')\n handler();\n};\n\n// retain buffers to transfer\nconst buffers = new WeakSet;\n\n// retain either main threads or workers global context\nconst context = new WeakMap;\n\nconst syncResult = {value: {then: fn => fn()}};\n\n// used to generate a unique `id` per each worker `postMessage` \"transaction\"\nlet uid = 0;\n\n/**\n * @typedef {Object} Interrupt used to sanity-check interrupts while waiting synchronously.\n * @prop {function} [handler] a callback invoked every `delay` milliseconds.\n * @prop {number} [delay=42] define `handler` invokes in terms of milliseconds.\n */\n\n/**\n * Create once a `Proxy` able to orchestrate synchronous `postMessage` out of the box.\n * @param {globalThis | Worker} self the context in which code should run\n * @param {{parse: (serialized: string) => any, stringify: (serializable: any) => string, transform?: (value:any) => any, interrupt?: () => void | Interrupt}} [JSON] an optional `JSON` like interface to `parse` or `stringify` content with extra `transform` ability.\n * @returns {ProxyHandler<globalThis> | ProxyHandler<Worker>}\n */\nconst coincident = (self, {parse = JSON.parse, stringify = JSON.stringify, transform, interrupt} = JSON) => {\n // create a Proxy once for the given context (globalThis or Worker instance)\n if (!context.has(self)) {\n // ensure no SAB gets a chance to pass through this call\n const sendMessage = postPatched || self.postMessage;\n // ensure the CHANNEL and data are posted correctly\n const post = (transfer, ...args) => sendMessage.call(self, {[CHANNEL]: args}, {transfer});\n\n const handler = typeof interrupt === FUNCTION ? interrupt : interrupt?.handler;\n const delay = interrupt?.delay || 42;\n const decoder = new TextDecoder('utf-16');\n\n // automatically uses sync wait (worker -> main)\n // or fallback to async wait (main -> worker)\n const waitFor = (isAsync, sb) => isAsync ?\n waitAsync(sb, 0) :\n ((handler ? waitInterrupt(sb, delay, handler) : wait(sb, 0)), syncResult);\n\n // prevent Harakiri https://github.com/WebReflection/coincident/issues/18\n let seppuku = false;\n\n context.set(self, new Proxy(new Map, {\n // there is very little point in checking prop in proxy for this very specific case\n // and I don't want to orchestrate a whole roundtrip neither, as stuff would fail\n // regardless if from Worker we access non existent Main callback, and vice-versa.\n // This is here mostly to guarantee that if such check is performed, at least the\n // get trap goes through and then it's up to developers guarantee they are accessing\n // stuff that actually exists elsewhere.\n [HAS]: (_, action) => typeof action === 'string' && !action.startsWith('_'),\n\n // worker related: get any utility that should be available on the main thread\n [GET]: (_, action) => action === 'then' ? null : ((...args) => {\n // transaction id\n const id = uid++;\n\n // first contact: just ask for how big the buffer should be\n // the value would be stored at index [1] while [0] is just control\n let sb = new Int32Array(new SharedArrayBuffer(I32_BYTES * 2));\n\n // if a transfer list has been passed, drop it from args\n let transfer = [];\n if (buffers.has(args.at(-1) || transfer))\n buffers.delete(transfer = args.pop());\n\n // ask for invoke with arguments and wait for it\n post(transfer, id, sb, action, transform ? args.map(transform) : args);\n\n // helps deciding how to wait for results\n const isAsync = self !== globalThis;\n\n // warn users about possible deadlock still allowing them\n // to explicitly `proxy.invoke().then(...)` without blocking\n let deadlock = 0;\n if (seppuku && isAsync)\n deadlock = setTimeout(console.warn, 1000, `\uD83D\uDC80\uD83D\uDD12 - Possible deadlock if proxy.${action}(...args) is awaited`);\n\n return waitFor(isAsync, sb).value.then(() => {\n clearTimeout(deadlock);\n\n // commit transaction using the returned / needed buffer length\n const length = sb[1];\n\n // filter undefined results\n if (!length) return;\n\n // calculate the needed ui16 bytes length to store the result string\n const bytes = UI16_BYTES * length;\n\n // round up to the next amount of bytes divided by 4 to allow i32 operations\n sb = new Int32Array(new SharedArrayBuffer(bytes + (bytes % I32_BYTES)));\n\n // ask for results and wait for it\n post([], id, sb);\n return waitFor(isAsync, sb).value.then(() => parse(\n decoder.decode(new Uint16Array(sb.buffer).slice(0, length)))\n );\n });\n }),\n\n // main thread related: react to any utility a worker is asking for\n [SET](actions, action, callback) {\n const type = typeof callback;\n if (type !== FUNCTION)\n throw new Error(`Unable to assign ${action} as ${type}`);\n // lazy event listener and logic handling, triggered once by setters actions\n if (!actions.size) {\n // maps results by `id` as they are asked for\n const results = new Map;\n // add the event listener once (first defined setter, all others work the same)\n self.addEventListener('message', async (event) => {\n // grub the very same library CHANNEL; ignore otherwise\n const details = event.data?.[CHANNEL];\n if (isArray(details)) {\n // if early enough, avoid leaking data to other listeners\n event.stopImmediatePropagation();\n const [id, sb, ...rest] = details;\n let error;\n // action available: it must be defined/known on the main thread\n if (rest.length) {\n const [action, args] = rest;\n if (actions.has(action)) {\n seppuku = true;\n try {\n // await for result either sync or async and serialize it\n const result = await actions.get(action)(...args);\n if (result !== void 0) {\n const serialized = stringify(transform ? transform(result) : result);\n // store the result for \"the very next\" event listener call\n results.set(id, serialized);\n // communicate the required SharedArrayBuffer length out of the\n // resulting serialized string\n sb[1] = serialized.length;\n }\n }\n catch (_) {\n error = _;\n }\n finally {\n seppuku = false;\n }\n }\n // unknown action should be notified as missing on the main thread\n else {\n error = new Error(`Unsupported action: ${action}`);\n }\n // unlock the wait lock later on\n sb[0] = 1;\n }\n // no action means: get results out of the well known `id`\n // wait lock automatically unlocked here as no `0` value would\n // possibly ever land at index `0`\n else {\n const result = results.get(id);\n results.delete(id);\n // populate the SharedArrayBuffer with utf-16 chars code\n for (let ui16a = new Uint16Array(sb.buffer), i = 0; i < result.length; i++)\n ui16a[i] = result.charCodeAt(i);\n }\n // release te worker waiting either the length or the result\n notify(sb, 0);\n if (error) throw error;\n }\n });\n }\n // store this action callback allowing the setter in the process\n return !!actions.set(action, callback);\n }\n }));\n }\n return context.get(self);\n};\n\ncoincident.transfer = (...args) => (buffers.add(args), args);\n\nexport default coincident;\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\n/**\n * A WebWorker entrypoint that uses coincident to handle postMessage details\n */\nimport coincident from 'coincident';\n\nimport type {\n TDriveMethod,\n TDriveRequest,\n TDriveResponse,\n} from '@jupyterlite/services/lib/contents/drivefs';\nimport { ContentsAPI, DriveFS } from '@jupyterlite/services/lib/contents/drivefs';\n\nimport type { ICoincidentPyodideWorkerKernel, IPyodideWorkerKernel } from './tokens';\n\nimport { PyodideRemoteKernel } from './worker';\n\nconst workerAPI = coincident(self) as ICoincidentPyodideWorkerKernel;\n\n/**\n * An Emscripten-compatible synchronous Contents API using shared array buffers.\n */\nexport class SharedBufferContentsAPI extends ContentsAPI {\n request<T extends TDriveMethod>(data: TDriveRequest<T>): TDriveResponse<T> {\n return workerAPI.processDriveRequest(data);\n }\n}\n\n/**\n * A custom drive implementation which uses shared array buffers (via coincident) if available\n */\nclass PyodideDriveFS extends DriveFS {\n createAPI(options: DriveFS.IOptions): ContentsAPI {\n return new SharedBufferContentsAPI(options);\n }\n}\n\nexport class PyodideCoincidentKernel extends PyodideRemoteKernel {\n /**\n * Setup custom Emscripten FileSystem\n */\n protected async initFilesystem(\n options: IPyodideWorkerKernel.IOptions,\n ): Promise<void> {\n if (options.mountDrive) {\n const mountpoint = '/drive';\n const { FS, PATH, ERRNO_CODES } = this._pyodide;\n const { baseUrl } = options;\n\n const driveFS = new PyodideDriveFS({\n FS: FS as any,\n PATH,\n ERRNO_CODES,\n baseUrl,\n driveName: this._driveName,\n mountpoint,\n });\n FS.mkdirTree(mountpoint);\n FS.mount(driveFS, {}, mountpoint);\n FS.chdir(mountpoint);\n this._driveFS = driveFS;\n }\n }\n\n protected sendInputRequest(prompt: string, password: boolean): string | undefined {\n // Input request via SharedArrayBuffer.\n return workerAPI.processStdinRequest({ prompt, password });\n }\n}\n\nconst worker = new PyodideCoincidentKernel();\n\nconst sendWorkerMessage = workerAPI.processWorkerMessage.bind(workerAPI);\nworker.registerWorkerMessageCallback(sendWorkerMessage);\n\nconst logMessage = workerAPI.processLogMessage.bind(workerAPI);\nworker.registerLogMessageCallback(logMessage);\n\nworkerAPI.initialize = worker.initialize.bind(worker);\nworkerAPI.execute = worker.execute.bind(worker);\nworkerAPI.complete = worker.complete.bind(worker);\nworkerAPI.inspect = worker.inspect.bind(worker);\nworkerAPI.isComplete = worker.isComplete.bind(worker);\nworkerAPI.commInfo = worker.commInfo.bind(worker);\nworkerAPI.commOpen = worker.commOpen.bind(worker);\nworkerAPI.commMsg = worker.commMsg.bind(worker);\nworkerAPI.commClose = worker.commClose.bind(worker);\nworkerAPI.inputReply = worker.inputReply.bind(worker);\n", "// Copyright (c) Jupyter Development Team.\n// Distributed under the terms of the Modified BSD License.\n\nimport type Pyodide from 'pyodide';\n\nimport type { ILogPayload } from '@jupyterlab/logconsole';\n\nimport type { KernelMessage } from '@jupyterlab/services';\n\nimport type { DriveFS } from '@jupyterlite/services/lib/contents/drivefs';\n\nimport type { IPyodideWorkerKernel } from './tokens';\n\nexport abstract class PyodideRemoteKernel {\n constructor() {\n this._initialized = new Promise((resolve, reject) => {\n this._initializer = { resolve, reject };\n });\n }\n\n /**\n * Accept the URLs from the host\n **/\n async initialize(options: IPyodideWorkerKernel.IOptions): Promise<void> {\n this._options = options;\n\n if (options.location.includes(':')) {\n const parts = options.location.split(':');\n this._driveName = parts[0];\n this._localPath = parts[1];\n } else {\n this._driveName = '';\n this._localPath = options.location;\n }\n\n await this.initRuntime(options);\n await this.initFilesystem(options);\n await this.initPackageManager(options);\n await this.initKernel(options);\n await this.initGlobals(options);\n this._initializer?.resolve();\n }\n\n protected async initRuntime(options: IPyodideWorkerKernel.IOptions): Promise<void> {\n const { pyodideUrl, indexUrl } = options;\n let loadPyodide: typeof Pyodide.loadPyodide;\n if (pyodideUrl.endsWith('.mjs')) {\n // note: this does not work at all in firefox\n const pyodideModule: typeof Pyodide = await import(\n /* webpackIgnore: true */ pyodideUrl\n );\n loadPyodide = pyodideModule.loadPyodide;\n } else {\n importScripts(pyodideUrl);\n loadPyodide = (self as any).loadPyodide;\n }\n this._pyodide = await loadPyodide({\n indexURL: indexUrl,\n stdout: (text: string) => {\n console.log(text);\n this._logMessage({ type: 'text', level: 'info', data: text });\n },\n stderr: (text: string) => {\n console.error(text);\n this._logMessage({ type: 'text', level: 'critical', data: text });\n },\n ...options.loadPyodideOptions,\n });\n // @ts-expect-error: pyodide._api is private\n this._pyodide._api.on_fatal = async (e: any) => {\n let error = '';\n if (e.name === 'Exit') {\n error = 'Pyodide has exited and can no longer be used.';\n } else {\n error = `Pyodide has suffered a fatal error. Please report this to the Pyodide maintainers.\nThe cause of the error was: ${e.name}\n${e.message}\nStack trace:\n${e.stack}`;\n }\n this._logMessage({\n type: 'text',\n level: 'critical',\n data: error,\n });\n };\n }\n\n protected async initPackageManager(\n options: IPyodideWorkerKernel.IOptions,\n ): Promise<void> {\n if (!this._options) {\n throw new Error('Uninitialized');\n }\n\n const { pipliteWheelUrl, disablePyPIFallback, pipliteUrls, loadPyodideOptions } =\n this._options;\n\n const preloaded = (loadPyodideOptions || {}).packages || [];\n\n if (!preloaded.includes('micropip')) {\n await this._pyodide.loadPackage(['micropip']);\n }\n\n if (!preloaded.includes('piplite')) {\n await this._pyodide.runPythonAsync(`\n import micropip\n await micropip.install('${pipliteWheelUrl}', keep_going=True)\n `);\n }\n\n // get piplite early enough to impact pyodide-kernel dependencies\n await this._pyodide.runPythonAsync(`\n import piplite.piplite\n piplite.piplite._PIPLITE_DISABLE_PYPI = ${disablePyPIFallback ? 'True' : 'False'}\n piplite.piplite._PIPLITE_URLS = ${JSON.stringify(pipliteUrls)}\n `);\n }\n\n protected async initKernel(options: IPyodideWorkerKernel.IOptions): Promise<void> {\n const preloaded = (options.loadPyodideOptions || {}).packages || [];\n\n const toLoad = [\n 'sqlite3',\n 'ipykernel',\n 'comm',\n 'pyodide_kernel',\n 'jedi',\n 'ipython',\n ];\n\n const scriptLines: string[] = [];\n\n // use piplite for packages that weren't pre-loaded\n for (const pkgName of toLoad) {\n if (!preloaded.includes(pkgName)) {\n scriptLines.push(`await piplite.install('${pkgName}', keep_going=True)`);\n }\n }\n\n // import the kernel\n scriptLines.push('import pyodide_kernel');\n\n // cd to the kernel location\n if (options.mountDrive && this._localPath) {\n scriptLines.push('import os', `os.chdir(\"${this._localPath}\")`);\n }\n\n // from this point forward, only use piplite (but not %pip)\n await this._pyodide.runPythonAsync(scriptLines.join('\\n'));\n }\n\n protected async initGlobals(options: IPyodideWorkerKernel.IOptions): Promise<void> {\n const { globals } = this._pyodide;\n this._kernel = globals.get('pyodide_kernel').kernel_instance.copy();\n this._stdout_stream = globals.get('pyodide_kernel').stdout_stream.copy();\n this._stderr_stream = globals.get('pyodide_kernel').stderr_stream.copy();\n this._interpreter = this._kernel.interpreter.copy();\n this._interpreter.send_comm = this.sendComm.bind(this);\n }\n\n /**\n * Setup custom Emscripten FileSystem\n */\n protected async initFilesystem(\n options: IPyodideWorkerKernel.IOptions,\n ): Promise<void> {\n if (options.mountDrive) {\n const mountpoint = '/drive';\n const { FS, PATH, ERRNO_CODES } = this._pyodide;\n const { baseUrl } = options;\n // Use direct submodule import for tree-shaking\n const { DriveFS } = await import('@jupyterlite/services/lib/contents/drivefs');\n\n const driveFS = new DriveFS({\n FS: FS as any,\n PATH,\n ERRNO_CODES,\n baseUrl,\n driveName: this._driveName,\n mountpoint,\n browsingContextId: this._browsingContextId,\n });\n FS.mkdirTree(mountpoint);\n FS.mount(driveFS, {}, mountpoint);\n FS.chdir(mountpoint);\n this._driveFS = driveFS;\n }\n }\n\n /**\n * Recursively convert a Map to a JavaScript object\n * @param obj A Map, Array, or other object to convert\n */\n mapToObject(obj: any) {\n const out: any = obj instanceof Array ? [] : {};\n const entries = obj instanceof Map ? obj.entries() : Object.entries(obj);\n for (const [key, value] of entries) {\n out[key] =\n value instanceof Map || value instanceof Array\n ? this.mapToObject(value)\n : value;\n }\n return out;\n }\n\n /**\n * Format the response from the Pyodide evaluation.\n *\n * @param res The result object from the Pyodide evaluation\n */\n formatResult(res: any): any {\n if (!(res instanceof this._pyodide.ffi.PyProxy)) {\n return res;\n }\n // TODO: this is a bit brittle\n const m = res.toJs();\n const results = this.mapToObject(m);\n return results;\n }\n\n /**\n * Register the callback function to send messages from the worker back to the main thread.\n *\n * @param callback the callback to register\n */\n registerWorkerMessageCallback(callback: (msg: any) => void): void {\n this._sendWorkerMessage = callback;\n }\n\n /**\n * Register the callback function to log messages from the worker back to the main thread.\n *\n * @param callback the callback to register\n */\n registerLogMessageCallback(callback: (msg: any) => void): void {\n this._logMessage = callback;\n }\n\n /**\n * Makes sure pyodide is ready before continuing, and cache the parent message.\n */\n async setup(parent: any): Promise<void> {\n await this._initialized;\n this._kernel._parent_header = this._pyodide.toPy(parent);\n }\n\n /**\n * Execute code with the interpreter.\n *\n * @param content The incoming message with the code to execute.\n */\n async execute(content: any, parent: any) {\n await this.setup(parent);\n\n const publishExecutionResult = (\n prompt_count: any,\n data: any,\n metadata: any,\n ): void => {\n const bundle = {\n execution_count: prompt_count,\n data: this.formatResult(data),\n metadata: this.formatResult(metadata),\n };\n\n this._sendWorkerMessage({\n parentHeader: this.formatResult(this._kernel._parent_header)['header'],\n bundle,\n type: 'execute_result',\n });\n };\n\n const publishExecutionError = (ename: any, evalue: any, traceback: any): void => {\n const bundle = {\n ename: ename,\n evalue: evalue,\n traceback: traceback,\n };\n\n this._sendWorkerMessage({\n parentHeader: this.formatResult(this._kernel._parent_header)['header'],\n bundle,\n type: 'execute_error',\n });\n };\n\n const clearOutputCallback = (wait: boolean): void => {\n const bundle = {\n wait: this.formatResult(wait),\n };\n\n this._sendWorkerMessage({\n parentHeader: this.formatResult(this._kernel._parent_header)['header'],\n bundle,\n type: 'clear_output',\n });\n };\n\n const displayDataCallback = (data: any, metadata: any, transient: any): void => {\n const bundle = {\n data: this.formatResult(data),\n metadata: this.formatResult(metadata),\n transient: this.formatResult(transient),\n };\n\n this._sendWorkerMessage({\n parentHeader: this.formatResult(this._kernel._parent_header)['header'],\n bundle,\n type: 'display_data',\n });\n };\n\n const updateDisplayDataCallback = (\n data: any,\n metadata: any,\n transient: any,\n ): void => {\n const bundle = {\n data: this.formatResult(data),\n metadata: this.formatResult(metadata),\n transient: this.formatResult(transient),\n };\n\n this._sendWorkerMessage({\n parentHeader: this.formatResult(this._kernel._parent_header)['header'],\n bundle,\n type: 'update_display_data',\n });\n };\n\n const publishStreamCallback = (name: any, text: any): void => {\n const bundle = {\n name: this.formatResult(name),\n text: this.formatResult(text),\n };\n\n this._sendWorkerMessage({\n parentHeader: this.formatResult(this._kernel._parent_header)['header'],\n bundle,\n type: 'stream',\n });\n };\n\n this._stdout_stream.publish_stream_callback = publishStreamCallback;\n this._stderr_stream.publish_stream_callback = publishStreamCallback;\n this._interpreter.display_pub.clear_output_callback = clearOutputCallback;\n this._interpreter.display_pub.display_data_callback = displayDataCallback;\n this._interpreter.display_pub.update_display_data_callback =\n updateDisplayDataCallback;\n this._interpreter.displayhook.publish_execution_result = publishExecutionResult;\n this._interpreter.input = this.input.bind(this);\n this._interpreter.getpass = this.getpass.bind(this);\n\n const res = await this._kernel.run(content.code);\n const results = this.formatResult(res);\n\n if (results['status'] === 'error') {\n publishExecutionError(results['ename'], results['evalue'], results['traceback']);\n }\n\n return results;\n }\n\n /**\n * Complete the code submitted by a user.\n *\n * @param content The incoming message with the code to complete.\n */\n async complete(content: any, parent: any) {\n await this.setup(parent);\n\n const res = this._kernel.complete(content.code, content.cursor_pos);\n const results = this.formatResult(res);\n return results;\n }\n\n /**\n * Inspect the code submitted by a user.\n *\n * @param content The incoming message with the code to inspect.\n */\n async inspect(\n content: { code: string; cursor_pos: number; detail_level: 0 | 1 },\n parent: any,\n ) {\n await this.setup(parent);\n\n const res = this._kernel.inspect(\n content.code,\n content.cursor_pos,\n content.detail_level,\n );\n const results = this.formatResult(res);\n return results;\n }\n\n /**\n * Check code for completeness submitted by a user.\n *\n * @param content The incoming message with the code to check.\n */\n async isComplete(content: { code: string }, parent: any) {\n await this.setup(parent);\n\n const res = this._kernel.is_complete(content.code);\n const results = this.formatResult(res);\n return results;\n }\n\n /**\n * Respond to the commInfoRequest.\n *\n * @param content The incoming message with the comm target name.\n */\n async commInfo(\n content: any,\n parent: any,\n ): Promise<KernelMessage.ICommInfoReplyMsg['content']> {\n await this.setup(parent);\n\n const res = this._kernel.comm_info(content.target_name);\n const results = this.formatResult(res);\n\n return {\n comms: results,\n status: 'ok',\n };\n }\n\n /**\n * Respond to the commOpen.\n *\n * @param content The incoming message with the comm open.\n */\n async commOpen(content: any, parent: any) {\n await this.setup(parent);\n\n const res = this._kernel.comm_manager.comm_open(\n this._pyodide.toPy(null),\n this._pyodide.toPy(null),\n this._pyodide.toPy(content),\n );\n const results = this.formatResult(res);\n\n return results;\n }\n\n /**\n * Respond to the commMsg.\n *\n * @param content The incoming message with the comm msg.\n */\n async commMsg(content: any, parent: any) {\n await this.setup(parent);\n\n const res = this._kernel.comm_manager.comm_msg(\n this._pyodide.toPy(null),\n this._pyodide.toPy(null),\n this._pyodide.toPy(content),\n );\n const results = this.formatResult(res);\n\n return results;\n }\n\n /**\n * Respond to the commClose.\n *\n * @param content The incoming message with the comm close.\n */\n async commClose(content: any, parent: any) {\n await this.setup(parent);\n\n const res = this._kernel.comm_manager.comm_close(\n this._pyodide.toPy(null),\n this._pyodide.toPy(null),\n this._pyodide.toPy(content),\n );\n const results = this.formatResult(res);\n\n return results;\n }\n\n /**\n * Resolve the input request by getting back the reply from the main thread\n *\n * @param content The incoming message with the reply\n */\n async inputReply(content: any, parent: any) {\n // Should never be called as input_reply messages are returned via service worker\n // or SharedArrayBuffer.\n }\n\n /**\n * Send a input request to the front-end and block until the reply is received.\n *\n * @param prompt the text to show at the prompt\n * @param password Is the request for a password?\n * @returns String value from the input reply message, or undefined if there is none.\n */\n protected abstract sendInputRequest(\n prompt: string,\n password: boolean,\n ): string | undefined;\n\n getpass(prompt: string): string | undefined {\n prompt = typeof prompt === 'undefined' ? '' : prompt;\n return this.sendInputRequest(prompt, true);\n }\n\n input(prompt: string): string | undefined {\n prompt = typeof prompt === 'undefined' ? '' : prompt;\n return this.sendInputRequest(prompt, false);\n }\n\n /**\n * Send a comm message to the front-end.\n *\n * @param type The type of the comm message.\n * @param content The content.\n * @param metadata The metadata.\n * @param ident The ident.\n * @param buffers The binary buffers.\n */\n async sendComm(type: string, content: any, metadata: any, ident: any, buffers: any) {\n this._sendWorkerMessage({\n type: type,\n content: this.formatResult(content),\n metadata: this.formatResult(metadata),\n ident: this.formatResult(ident),\n buffers: this.formatResult(buffers),\n parentHeader: this.formatResult(this._kernel._parent_header)['header'],\n });\n }\n\n /**\n * Initialization options.\n */\n protected _options: IPyodideWorkerKernel.IOptions | null = null;\n /**\n * A promise that resolves when all initiaization is complete.\n */\n protected _initialized: Promise<void>;\n private _initializer: {\n reject: () => void;\n resolve: () => void;\n } | null = null;\n protected _pyodide: Pyodide.PyodideAPI = null as any;\n /** TODO: real typing */\n protected _localPath = '';\n protected _driveName = '';\n protected _browsingContextId: string | undefined;\n protected _kernel: any;\n protected _interpreter: any;\n protected _stdout_stream: any;\n protected _stderr_stream: any;\n protected _driveFS: DriveFS | null = null;\n protected _sendWorkerMessage: (msg: any) => void = () => {};\n protected _logMessage: (msg: ILogPayload) => void = () => {};\n}\n"],
|
|
5
|
+
"mappings": "o3BAaiBA,EAAAA,SAAAA,OAAjB,SAAiBA,EAAQ,CAyCvB,SAAgBC,EACdC,EACAC,EACAC,EAAQ,EACRC,EAAO,GAAE,CAET,IAAIC,EAAIJ,EAAM,OACd,GAAII,IAAM,EACR,MAAO,GAELF,EAAQ,EACVA,EAAQ,KAAK,IAAI,EAAGA,EAAQE,CAAC,EAE7BF,EAAQ,KAAK,IAAIA,EAAOE,EAAI,CAAC,EAE3BD,EAAO,EACTA,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C3D,CACF,EAEMC,EAAS,IAAIV,GAEbW,GAAoBnB,EAAU,qBAAqB,KAAKA,CAAS,EACvEkB,EAAO,8BAA8BC,EAAiB,EAEtD,IAAMC,GAAapB,EAAU,kBAAkB,KAAKA,CAAS,EAC7DkB,EAAO,2BAA2BE,EAAU,EAE5CpB,EAAU,WAAakB,EAAO,WAAW,KAAKA,CAAM,EACpDlB,EAAU,QAAUkB,EAAO,QAAQ,KAAKA,CAAM,EAC9ClB,EAAU,SAAWkB,EAAO,SAAS,KAAKA,CAAM,EAChDlB,EAAU,QAAUkB,EAAO,QAAQ,KAAKA,CAAM,EAC9ClB,EAAU,WAAakB,EAAO,WAAW,KAAKA,CAAM,EACpDlB,EAAU,SAAWkB,EAAO,SAAS,KAAKA,CAAM,EAChDlB,EAAU,SAAWkB,EAAO,SAAS,KAAKA,CAAM,EAChDlB,EAAU,QAAUkB,EAAO,QAAQ,KAAKA,CAAM,EAC9ClB,EAAU,UAAYkB,EAAO,UAAU,KAAKA,CAAM,EAClDlB,EAAU,WAAakB,EAAO,WAAW,KAAKA,CAAM",
|
|
6
6
|
"names": ["ArrayExt", "firstIndexOf", "array", "value", "start", "stop", "n", "span", "i", "j", "lastIndexOf", "findFirstIndex", "fn", "findLastIndex", "d", "findFirstValue", "index", "findLastValue", "lowerBound", "begin", "half", "middle", "upperBound", "shallowEqual", "a", "b", "slice", "options", "step", "length", "result", "move", "fromIndex", "toIndex", "reverse", "rotate", "delta", "pivot", "fill", "insert", "removeAt", "removeFirstOf", "removeLastOf", "removeAllOf", "count", "removeFirstWhere", "removeLastWhere", "removeAllWhere", "chain", "objects", "object", "empty", "enumerate", "filter", "find", "findIndex", "min", "max", "minmax", "vmin", "vmax", "toArray", "toObject", "key", "each", "every", "some", "map", "range", "Private", "rangeLength", "reduce", "initial", "it", "first", "second", "accumulator", "next", "repeat", "once", "retro", "topologicSort", "edges", "sorted", "visited", "graph", "edge", "addEdge", "k", "visit", "fromNode", "toNode", "children", "node", "child", "stride", "StringExt", "findIndices", "source", "query", "indices", "matchSumOfSquares", "score", "matchSumOfDeltas", "last", "highlight", "cmp", "take", "item", "zip", "iters", "obj", "tuple", "JSONExt", "isPrimitive", "value", "isArray", "isObject", "deepEqual", "first", "second", "a1", "a2", "deepArrayEqual", "deepObjectEqual", "deepCopy", "deepArrayCopy", "deepObjectCopy", "i", "n", "key", "firstValue", "secondValue", "result", "subvalue", "MimeData", "mime", "data", "PluginRegistry", "options", "v", "id", "plugin", "_b", "_a", "Private", "plugins", "force", "required", "t", "optional", "services", "service", "error", "kind", "promises", "pluginId", "manifest", "downstream", "token", "reason", "PluginData", "_c", "_d", "a", "s", "p", "createPluginData", "ensureNoCycle", "dependencies", "visit", "visited", "trace", "findDependents", "edges", "add", "acc", "dep", "newEdges", "edge", "oldSize", "previousSize", "packagesOfInterest", "poi", "sorted", "topologicSort", "index", "candidate", "collectStartupPlugins", "collection", "PromiseDelegate", "resolve", "reject", "Token", "name", "description", "fallbackRandomValues", "buffer", "Random", "crypto", "uuid4Factory", "getRandomValues", "bytes", "lut", "UUID", "instanceOfStream", "nodeOrStream", "init_emscripten", "__esmMin", "drivefs_exports", "__export", "BLOCK_SIZE", "ContentsAPI", "DRIVE_SEPARATOR", "DriveFS", "DriveFSEmscriptenNodeOps", "DriveFSEmscriptenStreamOps", "ServiceWorkerContentsAPI", "import_coreutils", "encoder", "decoder", "flagNeedsWrite", "init_drivefs", "__esmMin", "init_emscripten", "fs", "stream", "path", "file", "flags", "_a", "parsedFlags", "needsWrite", "buffer", "offset", "length", "position", "size", "now", "oldData", "whence", "nodeOrStream", "instanceOfStream", "value", "node", "attr", "key", "parent", "name", "result", "mode", "dev", "newDir", "newName", "oldNode", "newDirNode", "oldPath", "options", "newPath", "dirlist", "response", "serializedContent", "format", "binString", "len", "data", "i", "binary", "stats", "defaultDate", "xhr", "requestId", "requestWithMetadata", "e", "mount", "FS", "parts", "currentNode", "FUNCTION", "CHANNEL", "MAIN", "THREAD", "GET", "HAS", "SET", "isArray", "SharedArrayBuffer", "window", "notify", "wait", "waitAsync", "postPatched", "buffer", "onmessage", "w", "ids", "resolvers", "postMessage", "listener", "event", "_a", "details", "CHANNEL", "id", "sb", "data", "rest", "resolve", "buff", "i", "as", "Int32Array", "Map", "Uint16Array", "I32_BYTES", "UI16_BYTES", "waitInterrupt", "sb", "delay", "handler", "wait", "buffers", "context", "syncResult", "fn", "uid", "coincident", "self", "parse", "stringify", "transform", "interrupt", "sendMessage", "postPatched", "post", "transfer", "args", "CHANNEL", "FUNCTION", "decoder", "waitFor", "isAsync", "waitAsync", "seppuku", "HAS", "action", "GET", "id", "SharedArrayBuffer", "deadlock", "length", "bytes", "SET", "actions", "callback", "type", "results", "event", "_a", "details", "isArray", "rest", "error", "result", "serialized", "_", "ui16a", "i", "notify", "esm_default", "init_drivefs", "PyodideRemoteKernel", "resolve", "reject", "options", "_a", "parts", "pyodideUrl", "indexUrl", "loadPyodide", "text", "e", "error", "pipliteWheelUrl", "disablePyPIFallback", "pipliteUrls", "loadPyodideOptions", "preloaded", "toLoad", "scriptLines", "pkgName", "globals", "mountpoint", "FS", "PATH", "ERRNO_CODES", "baseUrl", "DriveFS", "driveFS", "obj", "out", "entries", "key", "value", "res", "m", "callback", "parent", "content", "publishExecutionResult", "prompt_count", "data", "metadata", "bundle", "publishExecutionError", "ename", "evalue", "traceback", "clearOutputCallback", "wait", "displayDataCallback", "transient", "updateDisplayDataCallback", "publishStreamCallback", "name", "results", "prompt", "type", "ident", "buffers", "workerAPI", "esm_default", "SharedBufferContentsAPI", "ContentsAPI", "data", "PyodideDriveFS", "DriveFS", "options", "PyodideCoincidentKernel", "PyodideRemoteKernel", "mountpoint", "FS", "PATH", "ERRNO_CODES", "baseUrl", "driveFS", "prompt", "password", "worker", "sendWorkerMessage", "logMessage"]
|
|
7
7
|
}
|