UNPKG

js-worker-search-x

Version:

JavaScript client-side search API with web-worker support

1,572 lines (1,230 loc) 66.3 kB
module.exports = /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) /******/ return installedModules[moduleId].exports; /******/ /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ exports: {}, /******/ id: moduleId, /******/ loaded: false /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.loaded = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(0); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.INDEX_MODES = undefined; var _SearchApi = __webpack_require__(1); var _SearchApi2 = _interopRequireDefault(_SearchApi); var _util = __webpack_require__(2); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } exports.default = _SearchApi2.default; exports.INDEX_MODES = _util.INDEX_MODES; /***/ }, /* 1 */ /***/ function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _util = __webpack_require__(2); var _worker = __webpack_require__(6); var _worker2 = _interopRequireDefault(_worker); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * Search API that uses web workers when available. * Indexing and searching is performed in the UI thread as a fallback when web workers aren't supported. */ var SearchApi = // TODO function SearchApi() { var _this = this; var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, caseSensitive = _ref.caseSensitive, indexMode = _ref.indexMode, matchAnyToken = _ref.matchAnyToken, tokenizePattern = _ref.tokenizePattern; _classCallCheck(this, SearchApi); this.indexDocument = function (uid, text) { _this._search.indexDocument(uid, text); return _this; }; this.search = function (query) { // Promise.resolve handles both synchronous and web-worker Search utilities return _this._search.search(query); }; this.terminate = function () { _this._search.terminate(); }; // Based on https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers // But with added check for Node environment if (typeof window !== "undefined" && window.Worker) { this._search = new _worker2.default({ indexMode: indexMode, matchAnyToken: matchAnyToken, tokenizePattern: tokenizePattern, caseSensitive: caseSensitive }); } else { this._search = new _util.SearchUtility({ indexMode: indexMode, matchAnyToken: matchAnyToken, tokenizePattern: tokenizePattern, caseSensitive: caseSensitive }); } } /** * Adds or updates a uid in the search index and associates it with the specified text. * Note that at this time uids can only be added or updated in the index, not removed. * * @param uid Uniquely identifies a searchable object * @param text Text to associate with uid */ /** * Searches the current index for the specified query text. * Only uids matching all of the words within the text will be accepted. * If an empty query string is provided all indexed uids will be returned. * * Document searches are case-insensitive (e.g. "search" will match "Search"). * Document searches use substring matching (e.g. "na" and "me" will both match "name"). * * @param query Searchable query text * @return Promise to be resolved with an Array of matching uids */ /** * Stops and retires the worker in the search API. Used for cleanup. */ ; exports.default = SearchApi; /***/ }, /* 2 */ /***/ function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SearchUtility = exports.INDEX_MODES = undefined; var _SearchUtility = __webpack_require__(3); var _SearchUtility2 = _interopRequireDefault(_SearchUtility); var _constants = __webpack_require__(4); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } exports.default = _SearchUtility2.default; exports.INDEX_MODES = _constants.INDEX_MODES; exports.SearchUtility = _SearchUtility2.default; /***/ }, /* 3 */ /***/ function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _constants = __webpack_require__(4); var _SearchIndex = __webpack_require__(5); var _SearchIndex2 = _interopRequireDefault(_SearchIndex); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * Synchronous client-side full-text search utility. * Forked from JS search (github.com/bvaughn/js-search). */ var SearchUtility = function () { /** * Constructor. * * @param indexMode See #setIndexMode * @param tokenizePattern See #setTokenizePattern * @param caseSensitive See #setCaseSensitive * @param matchAnyToken See #setMatchAnyToken */ function SearchUtility() { var _this = this; var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, _ref$caseSensitive = _ref.caseSensitive, caseSensitive = _ref$caseSensitive === undefined ? false : _ref$caseSensitive, _ref$indexMode = _ref.indexMode, indexMode = _ref$indexMode === undefined ? _constants.INDEX_MODES.ALL_SUBSTRINGS : _ref$indexMode, _ref$matchAnyToken = _ref.matchAnyToken, matchAnyToken = _ref$matchAnyToken === undefined ? false : _ref$matchAnyToken, _ref$tokenizePattern = _ref.tokenizePattern, tokenizePattern = _ref$tokenizePattern === undefined ? /\s+/ : _ref$tokenizePattern; _classCallCheck(this, SearchUtility); this.indexDocument = function (uid, text) { _this._uids[uid] = true; var fieldTokens = _this._tokenize(_this._sanitize(text)); fieldTokens.forEach(function (fieldToken) { var expandedTokens = _this._expandToken(fieldToken); expandedTokens.forEach(function (expandedToken) { _this._searchIndex.indexDocument(expandedToken, uid); }); }); return _this; }; this.search = function (query) { if (!query) { return Object.keys(_this._uids); } else { var tokens = _this._tokenize(_this._sanitize(query)); return _this._searchIndex.search(tokens, _this._matchAnyToken); } }; this.terminate = function () {}; this._caseSensitive = caseSensitive; this._indexMode = indexMode; this._matchAnyToken = matchAnyToken; this._tokenizePattern = tokenizePattern; this._searchIndex = new _SearchIndex2.default(); this._uids = {}; } /** * Returns a constant representing the current case-sensitive bit. */ _createClass(SearchUtility, [{ key: "getCaseSensitive", value: function getCaseSensitive() { return this._caseSensitive; } /** * Returns a constant representing the current index mode. */ }, { key: "getIndexMode", value: function getIndexMode() { return this._indexMode; } /** * Returns a constant representing the current match-any-token bit. */ }, { key: "getMatchAnyToken", value: function getMatchAnyToken() { return this._matchAnyToken; } /** * Returns a constant representing the current tokenize pattern. */ }, { key: "getTokenizePattern", value: function getTokenizePattern() { return this._tokenizePattern; } /** * Adds or updates a uid in the search index and associates it with the specified text. * Note that at this time uids can only be added or updated in the index, not removed. * * @param uid Uniquely identifies a searchable object * @param text Text to associate with uid */ /** * Searches the current index for the specified query text. * Only uids matching all of the words within the text will be accepted, * unless matchAny is set to true. * If an empty query string is provided all indexed uids will be returned. * * Document searches are case-insensitive by default (e.g. "search" will match "Search"). * Document searches use substring matching by default (e.g. "na" and "me" will both match "name"). * * @param query Searchable query text * @return Array of uids */ }, { key: "setCaseSensitive", /** * Sets a new case-sensitive bit */ value: function setCaseSensitive(caseSensitive) { this._caseSensitive = caseSensitive; } /** * Sets a new index mode. * See util/constants/INDEX_MODES */ }, { key: "setIndexMode", value: function setIndexMode(indexMode) { if (Object.keys(this._uids).length > 0) { throw Error("indexMode cannot be changed once documents have been indexed"); } this._indexMode = indexMode; } /** * Sets a new match-any-token bit */ }, { key: "setMatchAnyToken", value: function setMatchAnyToken(matchAnyToken) { this._matchAnyToken = matchAnyToken; } /** * Sets a new tokenize pattern (regular expression) */ }, { key: "setTokenizePattern", value: function setTokenizePattern(pattern) { this._tokenizePattern = pattern; } /** * Added to make class adhere to interface. Add cleanup code as needed. */ }, { key: "_expandToken", /** * Index strategy based on 'all-substrings-index-strategy.ts' in github.com/bvaughn/js-search/ * * @private */ value: function _expandToken(token) { switch (this._indexMode) { case _constants.INDEX_MODES.EXACT_WORDS: return [token]; case _constants.INDEX_MODES.PREFIXES: return this._expandPrefixTokens(token); case _constants.INDEX_MODES.ALL_SUBSTRINGS: default: return this._expandAllSubstringTokens(token); } } }, { key: "_expandAllSubstringTokens", value: function _expandAllSubstringTokens(token) { var expandedTokens = []; // String.prototype.charAt() may return surrogate halves instead of whole characters. // When this happens in the context of a web-worker it can cause Chrome to crash. // Catching the error is a simple solution for now; in the future I may try to better support non-BMP characters. // Resources: // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt // https://mathiasbynens.be/notes/javascript-unicode try { for (var i = 0, length = token.length; i < length; ++i) { var substring = ""; for (var j = i; j < length; ++j) { substring += token.charAt(j); expandedTokens.push(substring); } } } catch (error) { console.error("Unable to parse token \"" + token + "\" " + error); } return expandedTokens; } }, { key: "_expandPrefixTokens", value: function _expandPrefixTokens(token) { var expandedTokens = []; // String.prototype.charAt() may return surrogate halves instead of whole characters. // When this happens in the context of a web-worker it can cause Chrome to crash. // Catching the error is a simple solution for now; in the future I may try to better support non-BMP characters. // Resources: // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charAt // https://mathiasbynens.be/notes/javascript-unicode try { for (var i = 0, length = token.length; i < length; ++i) { expandedTokens.push(token.substr(0, i + 1)); } } catch (error) { console.error("Unable to parse token \"" + token + "\" " + error); } return expandedTokens; } /** * @private */ }, { key: "_sanitize", value: function _sanitize(string) { return this._caseSensitive ? string.trim() : string.trim().toLocaleLowerCase(); } /** * @private */ }, { key: "_tokenize", value: function _tokenize(text) { return text.split(this._tokenizePattern).filter(function (text) { return text; }); // Remove empty tokens } }]); return SearchUtility; }(); exports.default = SearchUtility; /***/ }, /* 4 */ /***/ function(module, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var INDEX_MODES = exports.INDEX_MODES = { // Indexes for all substring searches (e.g. the term "cat" is indexed as "c", "ca", "cat", "a", "at", and "t"). // Based on 'all-substrings-index-strategy' from js-search; // github.com/bvaughn/js-search/blob/master/source/index-strategy/all-substrings-index-strategy.ts ALL_SUBSTRINGS: "ALL_SUBSTRINGS", // Indexes for exact word matches only. // Based on 'exact-word-index-strategy' from js-search; // github.com/bvaughn/js-search/blob/master/source/index-strategy/exact-word-index-strategy.ts EXACT_WORDS: "EXACT_WORDS", // Indexes for prefix searches (e.g. the term "cat" is indexed as "c", "ca", and "cat" allowing prefix search lookups). // Based on 'prefix-index-strategy' from js-search; // github.com/bvaughn/js-search/blob/master/source/index-strategy/prefix-index-strategy.ts PREFIXES: "PREFIXES" }; /***/ }, /* 5 */ /***/ function(module, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * Maps search tokens to uids using a trie structure. */ var SearchIndex = function () { function SearchIndex() { _classCallCheck(this, SearchIndex); this.tokenToUidMap = {}; } /** * Maps the specified token to a uid. * * @param token Searchable token (e.g. "road") * @param uid Identifies a document within the searchable corpus */ _createClass(SearchIndex, [{ key: "indexDocument", value: function indexDocument(token, uid) { if (!this.tokenToUidMap[token]) { this.tokenToUidMap[token] = {}; } this.tokenToUidMap[token][uid] = uid; } /** * Finds uids that have been mapped to the set of tokens specified. * Only uids that have been mapped to all tokens will be returned. * * @param tokens Array of searchable tokens (e.g. ["long", "road"]) * @param matchAnyToken Whether to match any token. Default is false. * @return Array of uids that have been associated with the set of search tokens */ }, { key: "search", value: function search(tokens, matchAnyToken) { var _this = this; var uidMap = {}; var uidMatches = {}; var initialized = false; tokens.forEach(function (token) { var currentUidMap = _this.tokenToUidMap[token] || {}; if (!initialized) { initialized = true; for (var _uid in currentUidMap) { uidMap[_uid] = currentUidMap[_uid]; uidMatches[_uid] = 1; } } else { // Delete existing matches if using and AND query (the default) // Otherwise add new results to the matches if (!matchAnyToken) { for (var _uid2 in uidMap) { if (!currentUidMap[_uid2]) { delete uidMap[_uid2]; } } } else { for (var _uid3 in currentUidMap) { uidMap[_uid3] = currentUidMap[_uid3]; uidMatches[_uid3] = (uidMatches[_uid3] || 0) + 1; } } } }); var uids = []; for (var _uid4 in uidMap) { uids.push(uidMap[_uid4]); } // Sort according to most matches, if match any token is set. if (matchAnyToken) { uids.sort(function (a, b) { return uidMatches[b] - uidMatches[a]; }); } return uids; } }]); return SearchIndex; }(); exports.default = SearchIndex; /***/ }, /* 6 */ /***/ function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _SearchWorkerLoader = __webpack_require__(7); var _SearchWorkerLoader2 = _interopRequireDefault(_SearchWorkerLoader); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } exports.default = _SearchWorkerLoader2.default; /***/ }, /* 7 */ /***/ function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _uuid = __webpack_require__(8); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } // TODO /** * Client side, full text search utility. * This interface exposes web worker search capabilities to the UI thread. */ var SearchWorkerLoader = function () { /** * Constructor. */ function SearchWorkerLoader() { var _this = this; var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, caseSensitive = _ref.caseSensitive, indexMode = _ref.indexMode, matchAnyToken = _ref.matchAnyToken, tokenizePattern = _ref.tokenizePattern, WorkerClass = _ref.WorkerClass; _classCallCheck(this, SearchWorkerLoader); this.indexDocument = function (uid, text) { _this._worker.postMessage({ method: "indexDocument", text: text, uid: uid }); return _this; }; this.search = function (query) { return new Promise(function (resolve, reject) { var callbackId = (0, _uuid.v4)(); var data = { callbackId: callbackId, complete: false, error: null, reject: reject, resolve: resolve, results: null }; _this._worker.postMessage({ method: "search", query: query, callbackId: callbackId }); _this._callbackQueue.push(data); _this._callbackIdMap[callbackId] = data; }); }; this.terminate = function () { _this._worker.terminate(); }; // Defer worker import until construction to avoid testing error: // Error: Cannot find module 'worker!./[workername]' if (!WorkerClass) { // $FlowFixMe eslint-disable-next-line WorkerClass = __webpack_require__(18); } this._callbackQueue = []; this._callbackIdMap = {}; this._worker = new WorkerClass(); this._worker.onerror = function (event) { if (event.data) { var _event$data = event.data, _callbackId = _event$data.callbackId, _error = _event$data.error; _this._updateQueue({ callbackId: _callbackId, error: _error }); } else { console.error(event); } }; this._worker.onmessage = function (event) { var _event$data2 = event.data, callbackId = _event$data2.callbackId, results = _event$data2.results; _this._updateQueue({ callbackId: callbackId, results: results }); }; // Override default :caseSensitive bit if a specific one has been requested if (caseSensitive) { this._worker.postMessage({ method: "setCaseSensitive", caseSensitive: caseSensitive }); } // Override default :indexMode if a specific one has been requested if (indexMode) { this._worker.postMessage({ method: "setIndexMode", indexMode: indexMode }); } // Override default :matchAnyToken bit if a specific one has been requested if (matchAnyToken) { this._worker.postMessage({ method: "setMatchAnyToken", matchAnyToken: matchAnyToken }); } // Override default :tokenizePattern if a specific one has been requested if (tokenizePattern) { this._worker.postMessage({ method: "setTokenizePattern", tokenizePattern: tokenizePattern }); } } /** * Adds or updates a uid in the search index and associates it with the specified text. * Note that at this time uids can only be added or updated in the index, not removed. * * @param uid Uniquely identifies a searchable object * @param text Text to associate with uid */ /** * Searches the current index for the specified query text. * Only uids matching all of the words within the text will be accepted. * If an empty query string is provided all indexed uids will be returned. * * Document searches are case-insensitive (e.g. "search" will match "Search"). * Document searches use substring matching (e.g. "na" and "me" will both match "name"). * * @param query Searchable query text * @return Promise to be resolved with an array of uids */ /** * Stops and retires the worker. Used for cleanup. */ _createClass(SearchWorkerLoader, [{ key: "_updateQueue", /** * Updates the queue and flushes any completed promises that are ready. */ value: function _updateQueue(_ref2) { var callbackId = _ref2.callbackId, error = _ref2.error, results = _ref2.results; var target = this._callbackIdMap[callbackId]; target.complete = true; target.error = error; target.results = results; while (this._callbackQueue.length) { var data = this._callbackQueue[0]; if (!data.complete) { break; } this._callbackQueue.shift(); delete this._callbackIdMap[data.callbackId]; if (data.error) { data.reject(data.error); } else { // This type will always be defined in this case; // This casting lets Flow know it's safe. data.resolve(data.results); } } } }]); return SearchWorkerLoader; }(); exports.default = SearchWorkerLoader; /***/ }, /* 8 */ /***/ function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "v1", { enumerable: true, get: function () { return _v.default; } }); Object.defineProperty(exports, "v3", { enumerable: true, get: function () { return _v2.default; } }); Object.defineProperty(exports, "v4", { enumerable: true, get: function () { return _v3.default; } }); Object.defineProperty(exports, "v5", { enumerable: true, get: function () { return _v4.default; } }); var _v = _interopRequireDefault(__webpack_require__(9)); var _v2 = _interopRequireDefault(__webpack_require__(12)); var _v3 = _interopRequireDefault(__webpack_require__(15)); var _v4 = _interopRequireDefault(__webpack_require__(16)); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /***/ }, /* 9 */ /***/ function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _rng = _interopRequireDefault(__webpack_require__(10)); var _bytesToUuid = _interopRequireDefault(__webpack_require__(11)); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } // **`v1()` - Generate time-based UUID** // // Inspired by https://github.com/LiosK/UUID.js // and http://docs.python.org/library/uuid.html let _nodeId; let _clockseq; // Previous uuid creation time let _lastMSecs = 0; let _lastNSecs = 0; // See https://github.com/uuidjs/uuid for API details function v1(options, buf, offset) { let i = buf && offset || 0; const b = buf || []; options = options || {}; let node = options.node || _nodeId; let clockseq = options.clockseq !== undefined ? options.clockseq : _clockseq; // node and clockseq need to be initialized to random values if they're not // specified. We do this lazily to minimize issues related to insufficient // system entropy. See #189 if (node == null || clockseq == null) { const seedBytes = options.random || (options.rng || _rng.default)(); if (node == null) { // Per 4.5, create and 48-bit node id, (47 random bits + multicast bit = 1) node = _nodeId = [seedBytes[0] | 0x01, seedBytes[1], seedBytes[2], seedBytes[3], seedBytes[4], seedBytes[5]]; } if (clockseq == null) { // Per 4.2.2, randomize (14 bit) clockseq clockseq = _clockseq = (seedBytes[6] << 8 | seedBytes[7]) & 0x3fff; } } // UUID timestamps are 100 nano-second units since the Gregorian epoch, // (1582-10-15 00:00). JSNumbers aren't precise enough for this, so // time is handled internally as 'msecs' (integer milliseconds) and 'nsecs' // (100-nanoseconds offset from msecs) since unix epoch, 1970-01-01 00:00. let msecs = options.msecs !== undefined ? options.msecs : Date.now(); // Per 4.2.1.2, use count of uuid's generated during the current clock // cycle to simulate higher resolution clock let nsecs = options.nsecs !== undefined ? options.nsecs : _lastNSecs + 1; // Time since last uuid creation (in msecs) const dt = msecs - _lastMSecs + (nsecs - _lastNSecs) / 10000; // Per 4.2.1.2, Bump clockseq on clock regression if (dt < 0 && options.clockseq === undefined) { clockseq = clockseq + 1 & 0x3fff; } // Reset nsecs if clock regresses (new clockseq) or we've moved onto a new // time interval if ((dt < 0 || msecs > _lastMSecs) && options.nsecs === undefined) { nsecs = 0; } // Per 4.2.1.2 Throw error if too many uuids are requested if (nsecs >= 10000) { throw new Error("uuid.v1(): Can't create more than 10M uuids/sec"); } _lastMSecs = msecs; _lastNSecs = nsecs; _clockseq = clockseq; // Per 4.1.4 - Convert from unix epoch to Gregorian epoch msecs += 12219292800000; // `time_low` const tl = ((msecs & 0xfffffff) * 10000 + nsecs) % 0x100000000; b[i++] = tl >>> 24 & 0xff; b[i++] = tl >>> 16 & 0xff; b[i++] = tl >>> 8 & 0xff; b[i++] = tl & 0xff; // `time_mid` const tmh = msecs / 0x100000000 * 10000 & 0xfffffff; b[i++] = tmh >>> 8 & 0xff; b[i++] = tmh & 0xff; // `time_high_and_version` b[i++] = tmh >>> 24 & 0xf | 0x10; // include version b[i++] = tmh >>> 16 & 0xff; // `clock_seq_hi_and_reserved` (Per 4.2.2 - include variant) b[i++] = clockseq >>> 8 | 0x80; // `clock_seq_low` b[i++] = clockseq & 0xff; // `node` for (let n = 0; n < 6; ++n) { b[i + n] = node[n]; } return buf || (0, _bytesToUuid.default)(b); } var _default = v1; exports.default = _default; /***/ }, /* 10 */ /***/ function(module, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = rng; // Unique ID creation requires a high quality random # generator. In the browser we therefore // require the crypto API and do not support built-in fallback to lower quality random number // generators (like Math.random()). // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. Also, // find the complete implementation of crypto (msCrypto) on IE11. const getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto); const rnds8 = new Uint8Array(16); function rng() { if (!getRandomValues) { throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported'); } return getRandomValues(rnds8); } /***/ }, /* 11 */ /***/ function(module, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; /** * Convert array of 16 byte values to UUID string format of the form: * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX */ const byteToHex = []; for (let i = 0; i < 256; ++i) { byteToHex.push((i + 0x100).toString(16).substr(1)); } function bytesToUuid(buf, offset) { const i = offset || 0; const bth = byteToHex; // Note: Be careful editing this code! It's been tuned for performance // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434 return (bth[buf[i + 0]] + bth[buf[i + 1]] + bth[buf[i + 2]] + bth[buf[i + 3]] + '-' + bth[buf[i + 4]] + bth[buf[i + 5]] + '-' + bth[buf[i + 6]] + bth[buf[i + 7]] + '-' + bth[buf[i + 8]] + bth[buf[i + 9]] + '-' + bth[buf[i + 10]] + bth[buf[i + 11]] + bth[buf[i + 12]] + bth[buf[i + 13]] + bth[buf[i + 14]] + bth[buf[i + 15]]).toLowerCase(); } var _default = bytesToUuid; exports.default = _default; /***/ }, /* 12 */ /***/ function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _v = _interopRequireDefault(__webpack_require__(13)); var _md = _interopRequireDefault(__webpack_require__(14)); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const v3 = (0, _v.default)('v3', 0x30, _md.default); var _default = v3; exports.default = _default; /***/ }, /* 13 */ /***/ function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = _default; exports.URL = exports.DNS = void 0; var _bytesToUuid = _interopRequireDefault(__webpack_require__(11)); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function uuidToBytes(uuid) { // Note: We assume we're being passed a valid uuid string const bytes = []; uuid.replace(/[a-fA-F0-9]{2}/g, function (hex) { bytes.push(parseInt(hex, 16)); }); return bytes; } function stringToBytes(str) { str = unescape(encodeURIComponent(str)); // UTF8 escape const bytes = []; for (let i = 0; i < str.length; ++i) { bytes.push(str.charCodeAt(i)); } return bytes; } const DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8'; exports.DNS = DNS; const URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8'; exports.URL = URL; function _default(name, version, hashfunc) { function generateUUID(value, namespace, buf, offset) { const off = buf && offset || 0; if (typeof value === 'string') value = stringToBytes(value); if (typeof namespace === 'string') namespace = uuidToBytes(namespace); if (!Array.isArray(value)) { throw TypeError('value must be an array of bytes'); } if (!Array.isArray(namespace) || namespace.length !== 16) { throw TypeError('namespace must be uuid string or an Array of 16 byte values'); } // Per 4.3 const bytes = hashfunc(namespace.concat(value)); bytes[6] = bytes[6] & 0x0f | version; bytes[8] = bytes[8] & 0x3f | 0x80; if (buf) { for (let idx = 0; idx < 16; ++idx) { buf[off + idx] = bytes[idx]; } } return buf || (0, _bytesToUuid.default)(bytes); } // Function#name is not settable on some platforms (#270) try { generateUUID.name = name; // eslint-disable-next-line no-empty } catch (err) {} // For CommonJS default export support generateUUID.DNS = DNS; generateUUID.URL = URL; return generateUUID; } /***/ }, /* 14 */ /***/ function(module, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; /* * Browser-compatible JavaScript MD5 * * Modification of JavaScript MD5 * https://github.com/blueimp/JavaScript-MD5 * * Copyright 2011, Sebastian Tschan * https://blueimp.net * * Licensed under the MIT license: * https://opensource.org/licenses/MIT * * Based on * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message * Digest Algorithm, as defined in RFC 1321. * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet * Distributed under the BSD License * See http://pajhome.org.uk/crypt/md5 for more info. */ function md5(bytes) { if (typeof bytes === 'string') { const msg = unescape(encodeURIComponent(bytes)); // UTF8 escape bytes = new Uint8Array(msg.length); for (let i = 0; i < msg.length; ++i) { bytes[i] = msg.charCodeAt(i); } } return md5ToHexEncodedArray(wordsToMd5(bytesToWords(bytes), bytes.length * 8)); } /* * Convert an array of little-endian words to an array of bytes */ function md5ToHexEncodedArray(input) { const output = []; const length32 = input.length * 32; const hexTab = '0123456789abcdef'; for (let i = 0; i < length32; i += 8) { const x = input[i >> 5] >>> i % 32 & 0xff; const hex = parseInt(hexTab.charAt(x >>> 4 & 0x0f) + hexTab.charAt(x & 0x0f), 16); output.push(hex); } return output; } /** * Calculate output length with padding and bit length */ function getOutputLength(inputLength8) { return (inputLength8 + 64 >>> 9 << 4) + 14 + 1; } /* * Calculate the MD5 of an array of little-endian words, and a bit length. */ function wordsToMd5(x, len) { /* append padding */ x[len >> 5] |= 0x80 << len % 32; x[getOutputLength(len) - 1] = len; let a = 1732584193; let b = -271733879; let c = -1732584194; let d = 271733878; for (let i = 0; i < x.length; i += 16) { const olda = a; const oldb = b; const oldc = c; const oldd = d; a = md5ff(a, b, c, d, x[i], 7, -680876936); d = md5ff(d, a, b, c, x[i + 1], 12, -389564586); c = md5ff(c, d, a, b, x[i + 2], 17, 606105819); b = md5ff(b, c, d, a, x[i + 3], 22, -1044525330); a = md5ff(a, b, c, d, x[i + 4], 7, -176418897); d = md5ff(d, a, b, c, x[i + 5], 12, 1200080426); c = md5ff(c, d, a, b, x[i + 6], 17, -1473231341); b = md5ff(b, c, d, a, x[i + 7], 22, -45705983); a = md5ff(a, b, c, d, x[i + 8], 7, 1770035416); d = md5ff(d, a, b, c, x[i + 9], 12, -1958414417); c = md5ff(c, d, a, b, x[i + 10], 17, -42063); b = md5ff(b, c, d, a, x[i + 11], 22, -1990404162); a = md5ff(a, b, c, d, x[i + 12], 7, 1804603682); d = md5ff(d, a, b, c, x[i + 13], 12, -40341101); c = md5ff(c, d, a, b, x[i + 14], 17, -1502002290); b = md5ff(b, c, d, a, x[i + 15], 22, 1236535329); a = md5gg(a, b, c, d, x[i + 1], 5, -165796510); d = md5gg(d, a, b, c, x[i + 6], 9, -1069501632); c = md5gg(c, d, a, b, x[i + 11], 14, 643717713); b = md5gg(b, c, d, a, x[i], 20, -373897302); a = md5gg(a, b, c, d, x[i + 5], 5, -701558691); d = md5gg(d, a, b, c, x[i + 10], 9, 38016083); c = md5gg(c, d, a, b, x[i + 15], 14, -660478335); b = md5gg(b, c, d, a, x[i + 4], 20, -405537848); a = md5gg(a, b, c, d, x[i + 9], 5, 568446438); d = md5gg(d, a, b, c, x[i + 14], 9, -1019803690); c = md5gg(c, d, a, b, x[i + 3], 14, -187363961); b = md5gg(b, c, d, a, x[i + 8], 20, 1163531501); a = md5gg(a, b, c, d, x[i + 13], 5, -1444681467); d = md5gg(d, a, b, c, x[i + 2], 9, -51403784); c = md5gg(c, d, a, b, x[i + 7], 14, 1735328473); b = md5gg(b, c, d, a, x[i + 12], 20, -1926607734); a = md5hh(a, b, c, d, x[i + 5], 4, -378558); d = md5hh(d, a, b, c, x[i + 8], 11, -2022574463); c = md5hh(c, d, a, b, x[i + 11], 16, 1839030562); b = md5hh(b, c, d, a, x[i + 14], 23, -35309556); a = md5hh(a, b, c, d, x[i + 1], 4, -1530992060); d = md5hh(d, a, b, c, x[i + 4], 11, 1272893353); c = md5hh(c, d, a, b, x[i + 7], 16, -155497632); b = md5hh(b, c, d, a, x[i + 10], 23, -1094730640); a = md5hh(a, b, c, d, x[i + 13], 4, 681279174); d = md5hh(d, a, b, c, x[i], 11, -358537222); c = md5hh(c, d, a, b, x[i + 3], 16, -722521979); b = md5hh(b, c, d, a, x[i + 6], 23, 76029189); a = md5hh(a, b, c, d, x[i + 9], 4, -640364487); d = md5hh(d, a, b, c, x[i + 12], 11, -421815835); c = md5hh(c, d, a, b, x[i + 15], 16, 530742520); b = md5hh(b, c, d, a, x[i + 2], 23, -995338651); a = md5ii(a, b, c, d, x[i], 6, -198630844); d = md5ii(d, a, b, c, x[i + 7], 10, 1126891415); c = md5ii(c, d, a, b, x[i + 14], 15, -1416354905); b = md5ii(b, c, d, a, x[i + 5], 21, -57434055); a = md5ii(a, b, c, d, x[i + 12], 6, 1700485571); d = md5ii(d, a, b, c, x[i + 3], 10, -1894986606); c = md5ii(c, d, a, b, x[i + 10], 15, -1051523); b = md5ii(b, c, d, a, x[i + 1], 21, -2054922799); a = md5ii(a, b, c, d, x[i + 8], 6, 1873313359); d = md5ii(d, a, b, c, x[i + 15], 10, -30611744); c = md5ii(c, d, a, b, x[i + 6], 15, -1560198380); b = md5ii(b, c, d, a, x[i + 13], 21, 1309151649); a = md5ii(a, b, c, d, x[i + 4], 6, -145523070); d = md5ii(d, a, b, c, x[i + 11], 10, -1120210379); c = md5ii(c, d, a, b, x[i + 2], 15, 718787259); b = md5ii(b, c, d, a, x[i + 9], 21, -343485551); a = safeAdd(a, olda); b = safeAdd(b, oldb); c = safeAdd(c, oldc); d = safeAdd(d, oldd); } return [a, b, c, d]; } /* * Convert an array bytes to an array of little-endian words * Characters >255 have their high-byte silently ignored. */ function bytesToWords(input) { if (input.length === 0) { return []; } const length8 = input.length * 8; const output = new Uint32Array(getOutputLength(length8)); for (let i = 0; i < length8; i += 8) { output[i >> 5] |= (input[i / 8] & 0xff) << i % 32; } return output; } /* * Add integers, wrapping at 2^32. This uses 16-bit operations internally * to work around bugs in some JS interpreters. */ function safeAdd(x, y) { const lsw = (x & 0xffff) + (y & 0xffff); const msw = (x >> 16) + (y >> 16) + (lsw >> 16); return msw << 16 | lsw & 0xffff; } /* * Bitwise rotate a 32-bit number to the left. */ function bitRotateLeft(num, cnt) { return num << cnt | num >>> 32 - cnt; } /* * These functions implement the four basic operations the algorithm uses. */ function md5cmn(q, a, b, x, s, t) { return safeAdd(bitRotateLeft(safeAdd(safeAdd(a, q), safeAdd(x, t)), s), b); } function md5ff(a, b, c, d, x, s, t) { return md5cmn(b & c | ~b & d, a, b, x, s, t); } function md5gg(a, b, c, d, x, s, t) { return md5cmn(b & d | c & ~d, a, b, x, s, t); } function md5hh(a, b, c, d, x, s, t) { return md5cmn(b ^ c ^ d, a, b, x, s, t); } function md5ii(a, b, c, d, x, s, t) { return md5cmn(c ^ (b | ~d), a, b, x, s, t); } var _default = md5; exports.default = _default; /***/ }, /* 15 */ /***/ function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _rng = _interopRequireDefault(__webpack_require__(10)); var _bytesToUuid = _interopRequireDefault(__webpack_require__(11)); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function v4(options, buf, offset) { if (typeof options === 'string') { buf = options === 'binary' ? new Uint8Array(16) : null; options = null; } options = options || {}; const rnds = options.random || (options.rng || _rng.default)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved` rnds[6] = rnds[6] & 0x0f | 0x40; rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided if (buf) { const start = offset || 0; for (let i = 0; i < 16; ++i) { buf[start + i] = rnds[i]; } return buf; } return (0, _bytesToUuid.default)(rnds); } var _default = v4; exports.default = _default; /***/ }, /* 16 */ /***/ function(module, exports, __webpack_require__) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _v = _interopRequireDefault(__webpack_require__(13)); var _sha = _interopRequireDefault(__webpack_require__(17)); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } const v5 = (0, _v.default)('v5', 0x50, _sha.default); var _default = v5; exports.default = _default; /***/ }, /* 17 */ /***/ function(module, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; // Adapted from Chris Veness' SHA1 code at // http://www.movable-type.co.uk/scripts/sha1.html function f(s, x, y, z) { switch (s) { case 0: return x & y ^ ~x & z; case 1: return x ^ y ^ z; case 2: return x & y ^ x & z ^ y & z; case 3: return x ^ y ^ z; } } function ROTL(x, n) { return x << n | x >>> 32 - n; } function sha1(bytes) { const K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6]; const H = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0]; if (typeof bytes === 'string') { const msg = unescape(encodeURIComponent(bytes)); // UTF8 escape bytes = []; for (let i = 0; i < msg.length; ++i) { bytes.push(msg.charCodeAt(i)); } } bytes.push(0x80); const l = bytes.length / 4 + 2; const N = Math.ceil(l / 16); const M = new Array(N); for (let i = 0; i < N; ++i) { const arr = new Uint32Array(16); for (let j = 0; j < 16; ++j) { arr[j] = bytes[i * 64 + j * 4] << 24 | bytes[i * 64 + j * 4 + 1] << 16 | bytes[i * 64 + j * 4 + 2] << 8 | bytes[i * 64 + j * 4 + 3]; } M[i] = arr; } M[N - 1][14] = (bytes.length - 1) * 8 / Math.pow(2, 32); M[N - 1][14] = Math.floor(M[N - 1][14]); M[N - 1][15] = (bytes.length - 1) * 8 & 0xffffffff; for (let i = 0; i < N; ++i) { const W = new Uint32Array(80); for (let t = 0; t < 16; ++t) { W[t] = M[i][t]; } for (let t = 16; t < 80; ++t) { W[t] = ROTL(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1); } let a = H[0]; let b = H[1]; let c = H[2]; let d = H[3]; let e = H[4]; for (let t = 0; t < 80; ++t) { const s = Math.floor(t / 20); const T = ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[t] >>> 0; e = d; d = c; c = ROTL(b, 30) >>> 0; b = a; a = T; } H[0] = H[0] + a >>> 0; H[1] = H[1] + b >>> 0; H[2] = H[2] + c >>> 0; H[3] = H[3] + d >>> 0; H[4] = H[4] + e >>> 0; } return [H[0] >> 24 & 0xff, H[0] >> 16 & 0xff, H[0] >> 8 & 0xff, H[0] & 0xff, H[1] >> 24 & 0xff, H[1] >> 16 & 0xff, H[1] >> 8 & 0xff, H[1] & 0xff, H[2] >> 24 & 0xff, H[2] >> 16 & 0xff, H[2] >> 8 & 0xff, H[2] & 0xff, H[3] >> 24 & 0xff, H[3] >> 16 & 0xff, H[3] >> 8 & 0xff, H[3] & 0xff, H[4] >> 24 & 0xff, H[4] >> 16 & 0xff, H[4] >> 8 & 0xff, H[4] & 0xff]; } var _default = sha1; exports.default = _default; /***/ }, /* 18 */ /***/ function(module, exports, __webpack_require__) { module.exports = function() { return __webpack_require__(19)("/******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId])\n/******/ \t\t\treturn installedModules[moduleId].exports;\n\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\texports: {},\n/******/ \t\t\tid: moduleId,\n/******/ \t\t\tloaded: false\n/******/ \t\t};\n\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.loaded = true;\n\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n\n\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(0);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ function(module, exports, __webpack_require__) {\n\n\t\"use strict\";\n\n\tvar _util = __webpack_require__(1);\n\n\t/**\n\t * Search entry point to web worker.\n\t * Builds search index and performs searches on separate thread from the ui.\n\t */\n\n\tvar searchUtility = new _util.SearchUtility();\n\n\tself.addEventListener(\"message\", function (event) {\n\t var data = event.data;\n\t var method = data.method;\n\n\n\t switch (method) {\n\t case \"indexDocument\":\n\t var uid = data.uid,\n\t text = data.text;\n\n\n\t searchUtility.indexDocument(uid, text);\n\t break;\n\t case \"search\":\n\t var callbackId = data.callbackId,\n\t query = data.query;\n\n\n\t var results = searchUtility.search(query);\n\n\t self.postMessage({ callbackId: callbackId, results: results });\n\t break;\n\t case \"setCaseSensitive\":\n\t var caseSensitive = data.caseSensitive;\n\n\n\t searchUtility.setCaseSensitive(caseSensitive);\n\t break;\n\t case \"setIndexMode\":\n\t var indexMode = data.indexMode;\n\n\n\t searchUtility.setIndexMode(indexMode);\n\t break;\n\t case \"setMatchAnyToken\":\n\t var matchAnyToken = data.matchAnyToken;\n\n\n\t searchUtility.setMatchAnyToken(matchAnyToken);\n\t break;\n\t case \"setTokenizePattern\":\n\t var tokenizePattern = data.tokenizePattern;\