From 4056aa3d9b24c3d36632fb6c4d2c2ddacbf613a2 Mon Sep 17 00:00:00 2001 From: Binnette Date: Mon, 8 Jul 2024 21:22:38 +0200 Subject: [PATCH] Use osm-request 2.0.0 from npm repo --- package-lock.json | 289 +- package.json | 9 +- public/OsmRequest.js | 10787 ------------------------------------- public/OsmRequest.js.map | 1 - src/main.js | 1 + 5 files changed, 292 insertions(+), 10795 deletions(-) delete mode 100644 public/OsmRequest.js delete mode 100644 public/OsmRequest.js.map diff --git a/package-lock.json b/package-lock.json index 0ef7d22..e263b5b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "jquery-toast-plugin": "^1.3.2", "leaflet": "^1.9.4", "osm-auth": "^2.5.0", + "osm-request": "^2.0.0", "remodal": "^1.1.1" }, "devDependencies": { @@ -22,7 +23,7 @@ "vite": "^5.3.3" }, "optionalDependencies": { - "@rollup/rollup-linux-x64-gnu": "4.18.0" + "@rollup/rollup-linux-x64-gnu": "^4.18.1" } }, "node_modules/@esbuild/win32-x64": { @@ -87,18 +88,200 @@ } } }, + "node_modules/@rollup/rollup-android-arm-eabi": { + "version": "4.18.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.18.0.tgz", + "integrity": "sha512-Tya6xypR10giZV1XzxmH5wr25VcZSncG0pZIjfePT0OVBvqNEurzValetGNarVrGiq66EBVAFn15iYX4w6FKgQ==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-android-arm64": { + "version": "4.18.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.18.0.tgz", + "integrity": "sha512-avCea0RAP03lTsDhEyfy+hpfr85KfyTctMADqHVhLAF3MlIkq83CP8UfAHUssgXTYd+6er6PaAhx/QGv4L1EiA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "android" + ] + }, + "node_modules/@rollup/rollup-darwin-arm64": { + "version": "4.18.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.18.0.tgz", + "integrity": "sha512-IWfdwU7KDSm07Ty0PuA/W2JYoZ4iTj3TUQjkVsO/6U+4I1jN5lcR71ZEvRh52sDOERdnNhhHU57UITXz5jC1/w==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-darwin-x64": { + "version": "4.18.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.18.0.tgz", + "integrity": "sha512-n2LMsUz7Ynu7DoQrSQkBf8iNrjOGyPLrdSg802vk6XT3FtsgX6JbE8IHRvposskFm9SNxzkLYGSq9QdpLYpRNA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/@rollup/rollup-linux-arm-gnueabihf": { + "version": "4.18.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.18.0.tgz", + "integrity": "sha512-C/zbRYRXFjWvz9Z4haRxcTdnkPt1BtCkz+7RtBSuNmKzMzp3ZxdM28Mpccn6pt28/UWUCTXa+b0Mx1k3g6NOMA==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm-musleabihf": { + "version": "4.18.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-musleabihf/-/rollup-linux-arm-musleabihf-4.18.0.tgz", + "integrity": "sha512-l3m9ewPgjQSXrUMHg93vt0hYCGnrMOcUpTz6FLtbwljo2HluS4zTXFy2571YQbisTnfTKPZ01u/ukJdQTLGh9A==", + "cpu": [ + "arm" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-gnu": { + "version": "4.18.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.18.0.tgz", + "integrity": "sha512-rJ5D47d8WD7J+7STKdCUAgmQk49xuFrRi9pZkWoRD1UeSMakbcepWXPF8ycChBoAqs1pb2wzvbY6Q33WmN2ftw==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-arm64-musl": { + "version": "4.18.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.18.0.tgz", + "integrity": "sha512-be6Yx37b24ZwxQ+wOQXXLZqpq4jTckJhtGlWGZs68TgdKXJgw54lUUoFYrg6Zs/kjzAQwEwYbp8JxZVzZLRepQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-powerpc64le-gnu": { + "version": "4.18.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-powerpc64le-gnu/-/rollup-linux-powerpc64le-gnu-4.18.0.tgz", + "integrity": "sha512-hNVMQK+qrA9Todu9+wqrXOHxFiD5YmdEi3paj6vP02Kx1hjd2LLYR2eaN7DsEshg09+9uzWi2W18MJDlG0cxJA==", + "cpu": [ + "ppc64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-riscv64-gnu": { + "version": "4.18.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.18.0.tgz", + "integrity": "sha512-ROCM7i+m1NfdrsmvwSzoxp9HFtmKGHEqu5NNDiZWQtXLA8S5HBCkVvKAxJ8U+CVctHwV2Gb5VUaK7UAkzhDjlg==", + "cpu": [ + "riscv64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-s390x-gnu": { + "version": "4.18.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-s390x-gnu/-/rollup-linux-s390x-gnu-4.18.0.tgz", + "integrity": "sha512-0UyyRHyDN42QL+NbqevXIIUnKA47A+45WyasO+y2bGJ1mhQrfrtXUpTxCOrfxCR4esV3/RLYyucGVPiUsO8xjg==", + "cpu": [ + "s390x" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, "node_modules/@rollup/rollup-linux-x64-gnu": { + "version": "4.18.1", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.18.1.tgz", + "integrity": "sha512-7O5u/p6oKUFYjRbZkL2FLbwsyoJAjyeXHCU3O4ndvzg2OFO2GinFPSJFGbiwFDaCFc+k7gs9CF243PwdPQFh5g==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/@rollup/rollup-linux-x64-musl": { "version": "4.18.0", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.18.0.tgz", - "integrity": "sha512-xuglR2rBVHA5UsI8h8UbX4VJ470PtGCf5Vpswh7p2ukaqBGFTnsfzxUBetoWBWymHMxbIG0Cmx7Y9qDZzr648w==", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.18.0.tgz", + "integrity": "sha512-LKaqQL9osY/ir2geuLVvRRs+utWUNilzdE90TpyoX0eNqPzWjRm14oMEE+YLve4k/NAqCdPkGYDaDF5Sw+xBfg==", "cpu": [ "x64" ], + "dev": true, "optional": true, "os": [ "linux" ] }, + "node_modules/@rollup/rollup-win32-arm64-msvc": { + "version": "4.18.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.18.0.tgz", + "integrity": "sha512-7J6TkZQFGo9qBKH0pk2cEVSRhJbL6MtfWxth7Y5YmZs57Pi+4x6c2dStAUvaQkHQLnEQv1jzBUW43GvZW8OFqA==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/@rollup/rollup-win32-ia32-msvc": { + "version": "4.18.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.18.0.tgz", + "integrity": "sha512-Txjh+IxBPbkUB9+SXZMpv+b/vnTEtFyfWZgJ6iyCmt2tdx0OF5WhFowLmnh8ENGNpfUlUZkdI//4IEmhwPieNg==", + "cpu": [ + "ia32" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ] + }, "node_modules/@rollup/rollup-win32-x64-msvc": { "version": "4.18.0", "cpu": [ @@ -183,6 +366,14 @@ "dev": true, "license": "MIT" }, + "node_modules/cross-fetch": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-4.0.0.tgz", + "integrity": "sha512-e4a5N8lVvuLgAWgnCrLr2PP0YyDOTHa9H/Rj54dirp61qXnNq46m82bRhNqIA5VccJtWBvPTFRV3TtvHUKPB1g==", + "dependencies": { + "node-fetch": "^2.6.12" + } + }, "node_modules/email-addresses": { "version": "5.0.0", "dev": true, @@ -480,6 +671,25 @@ "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" } }, + "node_modules/node-fetch": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, "node_modules/object-assign": { "version": "4.1.1", "dev": true, @@ -503,6 +713,17 @@ "node": ">=18.18" } }, + "node_modules/osm-request": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/osm-request/-/osm-request-2.0.0.tgz", + "integrity": "sha512-WCxfbvVgbPKiMtLoPRmH2qbCHxH53RhFVJoSxTflzxvgUTloP9KOFnOCGrip+INuxi6ErmnSK11atndY8iyj5Q==", + "dependencies": { + "cross-fetch": "^4.0.0", + "osm-auth": "^2.5.0", + "xml2js": "^0.6.2", + "xmlserializer": "^0.6.1" + } + }, "node_modules/p-limit": { "version": "2.3.0", "dev": true, @@ -676,6 +897,24 @@ "fsevents": "~2.3.2" } }, + "node_modules/rollup/node_modules/@rollup/rollup-linux-x64-gnu": { + "version": "4.18.0", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.18.0.tgz", + "integrity": "sha512-xuglR2rBVHA5UsI8h8UbX4VJ470PtGCf5Vpswh7p2ukaqBGFTnsfzxUBetoWBWymHMxbIG0Cmx7Y9qDZzr648w==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/sax": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.4.1.tgz", + "integrity": "sha512-+aWOz7yVScEGoKNd4PA10LZ8sk0A/z5+nXQG5giUO5rprX9jgYsTdov9qCchZiPIZezbZH+jRut8nPodFAX4Jg==" + }, "node_modules/semver": { "version": "6.3.1", "dev": true, @@ -704,6 +943,11 @@ "node": ">=0.10.0" } }, + "node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" + }, "node_modules/trim-repeated": { "version": "1.0.0", "dev": true, @@ -778,10 +1022,49 @@ } } }, + "node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" + }, + "node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, "node_modules/wrappy": { "version": "1.0.2", "dev": true, "license": "ISC" + }, + "node_modules/xml2js": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.6.2.tgz", + "integrity": "sha512-T4rieHaC1EXcES0Kxxj4JWgaUQHDk+qwHcYOCFHfiwKz7tOVPLq7Hjq9dM1WCMhylqMEfP7hMcOIChvotiZegA==", + "dependencies": { + "sax": ">=0.6.0", + "xmlbuilder": "~11.0.0" + }, + "engines": { + "node": ">=4.0.0" + } + }, + "node_modules/xmlbuilder": { + "version": "11.0.1", + "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz", + "integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==", + "engines": { + "node": ">=4.0" + } + }, + "node_modules/xmlserializer": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/xmlserializer/-/xmlserializer-0.6.1.tgz", + "integrity": "sha512-FNb0eEqqUUbnuvxuHqNuKH8qCGKqxu+558Zi8UzOoQk8Z9LdvpONK+v7m3gpKVHrk5Aq+0nNLsKxu/6OYh7Umw==" } } } diff --git a/package.json b/package.json index 1d3f97c..a439362 100644 --- a/package.json +++ b/package.json @@ -16,15 +16,16 @@ "jquery-toast-plugin": "^1.3.2", "leaflet": "^1.9.4", "osm-auth": "^2.5.0", + "osm-request": "^2.0.0", "remodal": "^1.1.1" }, "optionalDependencies": { - "@rollup/rollup-linux-x64-gnu": "4.18.0" + "@rollup/rollup-linux-x64-gnu": "^4.18.1" }, "devDependencies": { - "vite": "^5.3.3", - "@vitejs/plugin-basic-ssl": "^1.1.0", "@rollup/plugin-inject": "^5.0.5", - "gh-pages": "^6.1.1" + "@vitejs/plugin-basic-ssl": "^1.1.0", + "gh-pages": "^6.1.1", + "vite": "^5.3.3" } } diff --git a/public/OsmRequest.js b/public/OsmRequest.js deleted file mode 100644 index 5281885..0000000 --- a/public/OsmRequest.js +++ /dev/null @@ -1,10787 +0,0 @@ -(function webpackUniversalModuleDefinition(root, factory) { - if(typeof exports === 'object' && typeof module === 'object') - module.exports = factory(); - else if(typeof define === 'function' && define.amd) - define([], factory); - else if(typeof exports === 'object') - exports["OsmRequest"] = factory(); - else - root["OsmRequest"] = factory(); -})(self, () => { -return /******/ (() => { // webpackBootstrap -/******/ var __webpack_modules__ = ({ - -/***/ "./src/exceptions/request.js": -/*!***********************************!*\ - !*** ./src/exceptions/request.js ***! - \***********************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony export */ __webpack_require__.d(__webpack_exports__, { -/* harmony export */ RequestException: () => (/* binding */ RequestException) -/* harmony export */ }); -class RequestException extends Error { - constructor(message) { - super(message); - if (Error.captureStackTrace) { - Error.captureStackTrace(this, RequestException); - } - this.name = 'RequestException'; - } -} - -/***/ }), - -/***/ "./src/helpers/time.js": -/*!*****************************!*\ - !*** ./src/helpers/time.js ***! - \*****************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony export */ __webpack_require__.d(__webpack_exports__, { -/* harmony export */ getCurrentIsoTimestamp: () => (/* binding */ getCurrentIsoTimestamp) -/* harmony export */ }); -/** - * Get the current timestamp (for testing purpose) - * @return {string} - */ -function getCurrentIsoTimestamp() { - return new Date().toISOString(); -} - -/***/ }), - -/***/ "./src/helpers/utils.js": -/*!******************************!*\ - !*** ./src/helpers/utils.js ***! - \******************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony export */ __webpack_require__.d(__webpack_exports__, { -/* harmony export */ buildApiUrl: () => (/* binding */ buildApiUrl), -/* harmony export */ buildQueryString: () => (/* binding */ buildQueryString), -/* harmony export */ checkIdIsNegative: () => (/* binding */ checkIdIsNegative), -/* harmony export */ findElementId: () => (/* binding */ findElementId), -/* harmony export */ findElementType: () => (/* binding */ findElementType), -/* harmony export */ removeTrailingSlashes: () => (/* binding */ removeTrailingSlashes), -/* harmony export */ simpleObjectDeepClone: () => (/* binding */ simpleObjectDeepClone) -/* harmony export */ }); -/** - * Remove the trailing slashes from an URL and return it - * @param {string} url - * @return {string} - The cleaned URL - */ -function removeTrailingSlashes(url) { - return url.replace(/\/*$/, ''); -} - -/** - * Return a deep clone of an object. - * - * The object has to be a simple object notation. Not a Map, a Set or anything else. - * - * Object.assign and the spread operators can not be used as they do not replace children objects - * by copies of themselves. - * - * Eg: If you use Object.assign or the rest operator on that object: { items: [{ childrenItem: 1 }] } - * All the objects contained in the items array will be references to the first objects - * @param {Object} object - A simple object notation. No Map, Set or anything - * @return {Object} - */ -function simpleObjectDeepClone(object) { - return JSON.parse(JSON.stringify(object)); -} - -/** - * Return the type of an element based on the full OSM ID - * @param {string} osmId - * @return {string} - */ -function findElementType(osmId) { - return /^(\w+)\//.exec(osmId)[1]; -} - -/** - * Return the ID of an element based on the full OSM ID - * @param {string} osmId - * @return {string} - */ -function findElementId(osmId) { - return /\/(\d+)$/.exec(osmId)[1]; -} - -/** - * Check the OSM ID e.g -12 is negative - * @param {string} id The ID (without type) - * @return {boolean} - */ -function checkIdIsNegative(id) { - return /^[-]\d+$/.test(id); -} - -/** - * @param {Object} params - * @return {string} - */ -function buildQueryString(params) { - if (params === null || typeof params === 'undefined') { - return ''; - } - const builtParams = []; - for (const paramName of Object.keys(params)) { - const encodedName = encodeURIComponent(paramName); - const encodedvalue = encodeURIComponent(params[paramName]); - builtParams.push(`${encodedName}=${encodedvalue}`); - } - const questionMark = builtParams.length > 0 ? '?' : ''; - const queryString = builtParams.join('&'); - return `${questionMark}${queryString}`; -} - -/** - * Constructs complete API URL - * @param {string} apiUrl The apiUrl URL - * @param {string} path The method you want to use (example: /node/1234) - * @param {Object} [params] The URL parameters - * @return {string} The complete URL - */ -function buildApiUrl(apiUrl, path, params) { - return `${removeTrailingSlashes(apiUrl)}/api/0.6${path}${buildQueryString(params)}`; -} - -/***/ }), - -/***/ "./src/helpers/xhr.js": -/*!****************************!*\ - !*** ./src/helpers/xhr.js ***! - \****************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony export */ __webpack_require__.d(__webpack_exports__, { -/* harmony export */ authxhr: () => (/* binding */ authxhr), -/* harmony export */ fetch: () => (/* binding */ fetch) -/* harmony export */ }); -/* harmony import */ var cross_fetch__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! cross-fetch */ "./node_modules/cross-fetch/dist/browser-ponyfill.js"); -/* harmony import */ var cross_fetch__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(cross_fetch__WEBPACK_IMPORTED_MODULE_0__); -/* harmony import */ var xmlserializer__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! xmlserializer */ "./node_modules/xmlserializer/xmlserializer.js"); -/* harmony import */ var xmlserializer__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(xmlserializer__WEBPACK_IMPORTED_MODULE_1__); -/* harmony import */ var _exceptions_request__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../exceptions/request */ "./src/exceptions/request.js"); - - - - -/** - * Wrapper for fetching data from a given URL. - * Uses either simple fetch or authenticated xhr according to specified options. - * @param {string} url The URL to call - * @param {Object} [options] Options object - * @param {boolean} [options.auth] If auth XHR object is passed, it will be used instead of a simple fetch - * @return {Promise} Resolves on response text, or rejects if any HTTP error occurs - */ -function fetch(url, options = {}) { - if (options.auth) { - return new Promise((resolve, reject) => { - options.auth.xhr({ - method: 'GET', - prefix: false, - path: url - }, (err, res) => { - if (err) { - return reject(new _exceptions_request__WEBPACK_IMPORTED_MODULE_2__.RequestException(JSON.stringify({ - message: `Request failed`, - status: err.status, - statusText: err.statusText - }))); - } else { - if (res instanceof XMLDocument) { - return resolve(xmlserializer__WEBPACK_IMPORTED_MODULE_1___default().serializeToString(res)); - } else { - return resolve(res); - } - } - }); - }); - } else { - return cross_fetch__WEBPACK_IMPORTED_MODULE_0___default()(url).then(response => { - if (response.status !== 200) { - return response.text().then(message => Promise.reject(JSON.stringify({ - message, - status: response.status, - statusText: response.statusText - }))); - } - return response; - }).catch(error => { - throw new _exceptions_request__WEBPACK_IMPORTED_MODULE_2__.RequestException(error); - }).then(response => response.text()); - } -} - -/** - * Wrapper for authenticated XmlHttpRequest - * Uses osm-auth xhr function - * @param {Object} opts Options object - * @param {Object} auth Auth module to use - * @return {Promise} Resolves on response text, or rejects if any HTTP error occurs - */ -function authxhr(opts, auth) { - if (auth.xhr) { - return new Promise((resolve, reject) => { - auth.xhr(opts, (err, res) => { - if (err) { - return reject(new _exceptions_request__WEBPACK_IMPORTED_MODULE_2__.RequestException(JSON.stringify({ - message: `Request failed`, - status: err.status, - statusText: err.statusText - }))); - } else { - if (res instanceof XMLDocument) { - return resolve(xmlserializer__WEBPACK_IMPORTED_MODULE_1___default().serializeToString(res)); - } else { - return resolve(res); - } - } - }); - }); - } else if (auth.skip) { - if (opts.content) { - opts.body = opts.content; - } - opts.headers = {}; - if (opts.options && opts.options.header) { - opts.headers = opts.options.header; - } - return cross_fetch__WEBPACK_IMPORTED_MODULE_0___default()(opts.path, opts).then(response => { - if (response.status !== 200) { - return response.text().then(message => Promise.reject(JSON.stringify({ - message: message, - status: response.status, - statusText: response.statusText - }))); - } - return response; - }).catch(error => { - throw new _exceptions_request__WEBPACK_IMPORTED_MODULE_2__.RequestException(error); - }).then(response => response.text()); - } else { - throw new Error('Authenticated XHR needs OAuth information'); - } -} - -/***/ }), - -/***/ "./src/helpers/xml.js": -/*!****************************!*\ - !*** ./src/helpers/xml.js ***! - \****************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony export */ __webpack_require__.d(__webpack_exports__, { -/* harmony export */ buildChangesetFromObjectXml: () => (/* binding */ buildChangesetFromObjectXml), -/* harmony export */ buildChangesetXml: () => (/* binding */ buildChangesetXml), -/* harmony export */ buildPreferencesFromObjectXml: () => (/* binding */ buildPreferencesFromObjectXml), -/* harmony export */ cleanMapJson: () => (/* binding */ cleanMapJson), -/* harmony export */ convertElementXmlToJson: () => (/* binding */ convertElementXmlToJson), -/* harmony export */ convertElementsListXmlToJson: () => (/* binding */ convertElementsListXmlToJson), -/* harmony export */ convertNotesXmlToJson: () => (/* binding */ convertNotesXmlToJson), -/* harmony export */ convertUserXmlToJson: () => (/* binding */ convertUserXmlToJson), -/* harmony export */ encodeXML: () => (/* binding */ encodeXML), -/* harmony export */ flattenAttributes: () => (/* binding */ flattenAttributes), -/* harmony export */ jsonToXml: () => (/* binding */ jsonToXml), -/* harmony export */ xmlToJson: () => (/* binding */ xmlToJson) -/* harmony export */ }); -/* harmony import */ var xml2js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! xml2js */ "./node_modules/xml2js/lib/xml2js.js"); -/* harmony import */ var xml2js__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(xml2js__WEBPACK_IMPORTED_MODULE_0__); -/* harmony import */ var _package_json__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../package.json */ "./package.json"); - - -const osmRequestVersion = _package_json__WEBPACK_IMPORTED_MODULE_1__.version; - -/** - * Escape a string to make it XML parameter-safe - * @param {string} str - * @return {string} - */ -function encodeXML(str = '') { - return str.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"').replace(/'/g, '''); -} - -/** - * Build a stringified OSM changeset - * @param {string} [createdBy] - * @param {string} [comment] - * @param {string} [optionalTags] Keys values to set tags - * @return {string} - */ -function buildChangesetXml(createdBy = '', comment = '', optionalTags = {}) { - const tags = Object.entries(optionalTags).map(entry => { - return ``; - }); - return ` - - - - - - ${tags.join(`\n `)} - - - `; -} - -/** - * Build an OSM changeset from keys values, intended for update - * @param {Object} tags To set tags - * @param {string} [createdBy] - * @param {string} [comment] - * @return {string} - */ -function buildChangesetFromObjectXml(tags = {}, createdBy = '', comment = '') { - const tagsArray = Object.entries(tags).map(entry => { - return ``; - }); - return ` - - - - - - ${tagsArray.join(`\n `)} - - - `; -} - -/** - * Build an OSM preferences XML from object keys values - * @param {Object} prefs The preferences values - * @return {string} - */ -function buildPreferencesFromObjectXml(prefs) { - const preferences = Object.entries(prefs).map(entry => { - return ``; - }); - return ` - - - ${preferences.join(`\n `)} - - - `; -} - -/** - * Convert a raw Element API response into a well formatted JSON object - * @param {string} xml - The raw API response - * @param {string} elementType - The type of the concerned OSM element (eg: node, way, relation) - * @param {string} elementId - The ID of the concerned OSM element - * @return {Promise} - */ -function convertElementXmlToJson(xml, elementType, elementId) { - return xmlToJson(xml).then(result => { - const element = result.osm[elementType][0]; - element._id = elementId; - element._type = elementType; - return element; - }); -} - -/** - * Convert a JSON object with OSM map features into a well formatted JSON object - * @param {Object} osmMapJson - The raw API response - * @return {Array} - */ -function cleanMapJson(osmMapJson) { - const { - bounds - } = osmMapJson.osm; - const mapper = type => e => ({ - ...e, - _id: e['$'].id, - _type: type - }); - let way = []; - if (osmMapJson.osm.way) { - way = osmMapJson.osm.way.map(mapper('way')); - } - let node = []; - if (osmMapJson.osm.node) { - node = osmMapJson.osm.node.map(mapper('node')); - } - let relation = []; - if (osmMapJson.osm.relation) { - relation = osmMapJson.osm.relation.map(mapper('relation')); - } - const newOsmObject = {}; - Object.entries({ - node: node, - way: way, - relation: relation - }).map(entry => { - if (entry[0] in osmMapJson.osm) { - newOsmObject[entry[0]] = entry[1]; - } - }); - if (bounds) { - newOsmObject.bounds = bounds; - } - return newOsmObject; -} - -/** - * Convert a raw list of elements API response into a well formatted JSON object - * @param {string} xml - The raw API response - * @param {string} type The OSM element type (node, way, relation) - * @return {Promise} - */ -function convertElementsListXmlToJson(xml, type) { - return xmlToJson(xml).then(result => { - return result.osm[type] ? result.osm[type].map(e => { - e._id = e.$.id; - e._type = type; - return e; - }) : []; - }); -} - -/** - * Convert a raw Notes API response into a well formatted JSON object - * @param {string} xml - The raw API response - * @return {Promise} - */ -function convertNotesXmlToJson(xml) { - return xmlToJson(xml).then(result => { - if (result.osm.note) { - return result.osm.note; - } else { - return []; - } - }).then(notes => notes.map(note => { - const returnedNote = flattenAttributes(note); - returnedNote.comments = [...returnedNote.comments.comment.map(comment => flattenAttributes(comment))]; - return returnedNote; - })); -} - -/** - * Convert a raw User API response into a well formatted JSON object - * @param {string} xml - The raw API response - * @return {Promise} - */ -function convertUserXmlToJson(xml) { - return xmlToJson(xml).then(result => { - const user = flattenAttributes(result.osm.user[0]); - Object.entries(user).filter(e => e[1].$).forEach(e => { - user[e[0]] = flattenAttributes(e[1]); - }); - if (user.blocks.received) { - user.blocks.received = user.blocks.received.map(b => flattenAttributes(b)); - } - return user; - }); -} - -/** - * XML converted with the xmlToJson function contain some weird objects - * Eg: - * { - * $: { - * attribute1: 'value1', - * attribute2: 'value2' - * }, - * attribute3: ['value3'], - * attribute4: ['value4'], - * } - * - * That function flatten them - * Eg: - * { - * attribute1: 'value1', - * attribute2: 'value2', - * attribute3: 'value3', - * attribute4: 'value4', - * } - * - * @param {Object} object - * @return {Object} - */ -function flattenAttributes(object) { - const flatObject = { - ...object.$ - }; - Object.keys(object).forEach(key => { - if (key === '$') return; - if (!object[key]) return; - if (object[key].length === 0) return; - flatObject[key] = object[key][0]; - }); - return flatObject; -} - -/** - * Convert a stringified XML into a JSON object - * @param {string} xml - * @return {Promise} - */ -function xmlToJson(xml) { - return new Promise((resolve, reject) => { - (0,xml2js__WEBPACK_IMPORTED_MODULE_0__.parseString)(xml, (err, result) => { - if (err) reject(err); - resolve(result); - }); - }); -} - -/** - * Convert a JSON object into a stringified XML - * @param {Object} json - * @return {string} - */ -function jsonToXml(json) { - const builder = new xml2js__WEBPACK_IMPORTED_MODULE_0__.Builder({ - xmldec: { - version: '1.0', - encoding: 'UTF-8', - standalone: null - } - }); - return builder.buildObject(json); -} - -/***/ }), - -/***/ "./src/requests.js": -/*!*************************!*\ - !*** ./src/requests.js ***! - \*************************/ -/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => { - -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony export */ __webpack_require__.d(__webpack_exports__, { -/* harmony export */ changesetCheckRequest: () => (/* binding */ changesetCheckRequest), -/* harmony export */ changesetGetRequest: () => (/* binding */ changesetGetRequest), -/* harmony export */ closeChangesetRequest: () => (/* binding */ closeChangesetRequest), -/* harmony export */ createChangesetRequest: () => (/* binding */ createChangesetRequest), -/* harmony export */ createNoteRequest: () => (/* binding */ createNoteRequest), -/* harmony export */ deleteElementRequest: () => (/* binding */ deleteElementRequest), -/* harmony export */ deleteUserPreferenceRequest: () => (/* binding */ deleteUserPreferenceRequest), -/* harmony export */ fetchChangesetsRequest: () => (/* binding */ fetchChangesetsRequest), -/* harmony export */ fetchElementRequest: () => (/* binding */ fetchElementRequest), -/* harmony export */ fetchElementRequestFull: () => (/* binding */ fetchElementRequestFull), -/* harmony export */ fetchMapByBboxRequest: () => (/* binding */ fetchMapByBboxRequest), -/* harmony export */ fetchNoteByIdRequest: () => (/* binding */ fetchNoteByIdRequest), -/* harmony export */ fetchNotesRequest: () => (/* binding */ fetchNotesRequest), -/* harmony export */ fetchNotesSearchRequest: () => (/* binding */ fetchNotesSearchRequest), -/* harmony export */ fetchRelationsForElementRequest: () => (/* binding */ fetchRelationsForElementRequest), -/* harmony export */ fetchUserRequest: () => (/* binding */ fetchUserRequest), -/* harmony export */ fetchWaysForNodeRequest: () => (/* binding */ fetchWaysForNodeRequest), -/* harmony export */ genericPostNoteRequest: () => (/* binding */ genericPostNoteRequest), -/* harmony export */ getUserPreferenceByKeyRequest: () => (/* binding */ getUserPreferenceByKeyRequest), -/* harmony export */ getUserPreferencesRequest: () => (/* binding */ getUserPreferencesRequest), -/* harmony export */ multiFetchElementsByTypeRequest: () => (/* binding */ multiFetchElementsByTypeRequest), -/* harmony export */ sendElementRequest: () => (/* binding */ sendElementRequest), -/* harmony export */ setUserPreferenceByKeyRequest: () => (/* binding */ setUserPreferenceByKeyRequest), -/* harmony export */ setUserPreferencesRequest: () => (/* binding */ setUserPreferencesRequest), -/* harmony export */ updateChangesetTagsRequest: () => (/* binding */ updateChangesetTagsRequest), -/* harmony export */ uploadChangesetOscRequest: () => (/* binding */ uploadChangesetOscRequest) -/* harmony export */ }); -/* harmony import */ var helpers_xhr__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! helpers/xhr */ "./src/helpers/xhr.js"); -/* harmony import */ var helpers_utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! helpers/utils */ "./src/helpers/utils.js"); -/* harmony import */ var helpers_xml__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! helpers/xml */ "./src/helpers/xml.js"); -/* harmony import */ var exceptions_request__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! exceptions/request */ "./src/exceptions/request.js"); - - - - - -/** - * Request to fetch an OSM element - * @param {string} apiUrl The API URL - * @param {string} osmId - * @param {Object} [options] Options - * @param {Object} [options.auth] Auth XHR object to use instead of unauthenticated call - * @return {Object} - */ -function fetchElementRequest(apiUrl, osmId, options = {}) { - const elementType = (0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.findElementType)(osmId); - const elementId = (0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.findElementId)(osmId); - return (0,helpers_xhr__WEBPACK_IMPORTED_MODULE_0__.fetch)((0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.buildApiUrl)(apiUrl, `/${osmId}`), options).then(response => (0,helpers_xml__WEBPACK_IMPORTED_MODULE_2__.convertElementXmlToJson)(response, elementType, elementId)); -} - -/** - * Request to fetch way or relation and all other elements referenced by it - * @param {string} apiUrl The API URL - * @param {string} osmId Can only contain either a way or a relation - * @param {Object} [options] Options - * @param {Object} [options.auth] Auth XHR object to use instead of unauthenticated call - * @return {Promise} Promise with well formatted JSON content - */ -function fetchElementRequestFull(apiUrl, osmId, options = {}) { - return (0,helpers_xhr__WEBPACK_IMPORTED_MODULE_0__.fetch)((0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.buildApiUrl)(apiUrl, `/${osmId}/full`), options).then(response => (0,helpers_xml__WEBPACK_IMPORTED_MODULE_2__.xmlToJson)(response).then(json => Promise.resolve((0,helpers_xml__WEBPACK_IMPORTED_MODULE_2__.cleanMapJson)(json))).catch(error => { - throw new exceptions_request__WEBPACK_IMPORTED_MODULE_3__.RequestException(error); - })); -} - -/** - * Request to fetch an OSM element - * @param {string} apiUrl The API URL - * @param {Array} osmIds Eg: ['node/12345', 'node/6789']. We do not support optional version e.g 'node/12345v2' - * @param {Object} [options] Options - * @param {Object} [options.auth] Auth XHR object to use instead of unauthenticated call - * @return {Promise} - */ -function multiFetchElementsByTypeRequest(apiUrl, osmIds, options = {}) { - const elementType = (0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.findElementType)(osmIds[0]); - const ids = osmIds.map(osmId => (0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.findElementId)(osmId)); - return (0,helpers_xhr__WEBPACK_IMPORTED_MODULE_0__.fetch)((0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.buildApiUrl)(apiUrl, `/${elementType}s?${elementType}s=${ids.join(',')}`), options).then(response => (0,helpers_xml__WEBPACK_IMPORTED_MODULE_2__.xmlToJson)(response).then(json => Promise.resolve((0,helpers_xml__WEBPACK_IMPORTED_MODULE_2__.cleanMapJson)(json))).catch(error => { - throw new exceptions_request__WEBPACK_IMPORTED_MODULE_3__.RequestException(error); - })); -} - -/** - * Request to fetch ways using the given OSM node - * @param {string} apiUrl The API URL - * @param {string} osmId - * @param {Object} [options] Options - * @param {Object} [options.auth] Auth XHR object to use instead of unauthenticated call - * @return {Object} - */ -function fetchWaysForNodeRequest(apiUrl, osmId, options = {}) { - return (0,helpers_xhr__WEBPACK_IMPORTED_MODULE_0__.fetch)((0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.buildApiUrl)(apiUrl, `/${osmId}/ways`), options).then(response => (0,helpers_xml__WEBPACK_IMPORTED_MODULE_2__.convertElementsListXmlToJson)(response, 'way')); -} - -/** - * Send an element to OSM - * @param {osmAuth} auth An instance of osm-auth - * @param {string} apiUrl The API URL - * @param {Object} element - * @param {number} changesetId - * @return {Promise} - */ -function sendElementRequest(auth, apiUrl, element, changesetId) { - const copiedElement = (0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.simpleObjectDeepClone)(element); - const { - _id: elementId, - _type: elementType - } = copiedElement; - delete copiedElement._id; - delete copiedElement._type; - copiedElement.$.changeset = changesetId; - const osmContent = { - osm: { - $: {} - } - }; - osmContent.osm[elementType] = [copiedElement]; - const elementXml = (0,helpers_xml__WEBPACK_IMPORTED_MODULE_2__.jsonToXml)(osmContent); - const path = elementId && !(0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.checkIdIsNegative)(elementId) ? `/${elementType}/${elementId}` : `/${elementType}/create`; - return (0,helpers_xhr__WEBPACK_IMPORTED_MODULE_0__.authxhr)({ - method: 'PUT', - prefix: false, - path: (0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.buildApiUrl)(apiUrl, path), - options: { - header: { - 'Content-Type': 'text/xml' - } - }, - content: elementXml - }, auth).then(version => parseInt(version, 10)); -} - -/** - * Request to fetch OSM notes - * @param {string} apiUrl The API URL - * @param {number} left The minimal longitude (X) - * @param {number} bottom The minimal latitude (Y) - * @param {number} right The maximal longitude (X) - * @param {number} top The maximal latitude (Y) - * @param {number} [limit] The maximal amount of notes to retrieve (between 1 and 10000, defaults to 100) - * @param {number} [closedDays] The amount of days a note needs to be closed to no longer be returned (defaults to 7, 0 means only opened notes are returned, and -1 means all notes are returned) - * @param {Object} [options] Options - * @param {Object} [options.auth] Auth XHR object to use instead of unauthenticated call - * @return {Object} - */ -function fetchNotesRequest(apiUrl, left, bottom, right, top, limit = null, closedDays = null, options = {}) { - const params = { - bbox: `${left.toString()},${bottom.toString()},${right.toString()},${top.toString()}` - }; - if (limit) { - params.limit = limit; - } - if (closedDays !== null && typeof closedDays !== 'undefined') { - params.closed = closedDays; - } - return (0,helpers_xhr__WEBPACK_IMPORTED_MODULE_0__.fetch)((0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.buildApiUrl)(apiUrl, '/notes', params), options).then(response => (0,helpers_xml__WEBPACK_IMPORTED_MODULE_2__.convertNotesXmlToJson)(response)); -} - -/** - * Request to get OSM notes with textual search - * @param {string} apiUrl The API URL - * @param {string} q Specifies the search query - * @param {string} [format] It can be 'xml' (default) to get OSM - * and convert to JSON, 'raw' to return raw OSM XML, 'json' to - * return GeoJSON, 'gpx' to return GPX and 'rss' to return GeoRSS - * @param {number} [limit] The maximal amount of notes to retrieve (between 1 and 10000, defaults to 100) - * @param {number} [closed] The amount of days a note needs to be closed to no longer be returned (defaults to 7, 0 means only opened notes are returned, and -1 means all notes are returned) - * @param {string} [display_name] Specifies the creator of the returned notes by using a valid display name. Does not work together with the user parameter - * @param {number} [user] Specifies the creator of the returned notes by using a valid id of the user. Does not work together with the display_name parameter - * @param {number} [from] Specifies the beginning of a date range to search in for a note - * @param {number} [to] Specifies the end of a date range to search in for a note. Today date is the default - * @param {Object} [options] Options - * @param {Object} [options.auth] Auth XHR object to use instead of unauthenticated call - * @return {Promise} - */ -function fetchNotesSearchRequest(apiUrl, q, format = 'xml', limit = null, closed = null, display_name = null, user = null, from = null, to = null, options = {}) { - const params = { - q - }; - let path = `/notes/search.${format}`; - if (format === 'raw') { - path = `/notes/search`; - } - const objectOptionalArgs = { - limit, - closed, - display_name, - user, - from, - to - }; - Object.entries(objectOptionalArgs).forEach(optional => { - if (optional[1]) { - params[optional[0]] = optional[1]; - } - }); - return (0,helpers_xhr__WEBPACK_IMPORTED_MODULE_0__.fetch)((0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.buildApiUrl)(apiUrl, path, params), options).then(text => { - if (format === 'xml') { - return (0,helpers_xml__WEBPACK_IMPORTED_MODULE_2__.convertNotesXmlToJson)(text); - } else { - return text; - } - }); -} - -/** - * Request to fetch OSM note by id - * @param {string} apiUrl The API URL - * param {number} noteId Identifier for the note - * @param {string} format It can be 'xml' (default) to get OSM - * and convert to JSON, 'raw' to return raw OSM XML, 'json' to - * return GeoJSON, 'gpx' to return GPX and 'rss' to return GeoRSS - * @param {Object} [options] Options - * @param {Object} [options.auth] Auth XHR object to use instead of unauthenticated call - * @return {Promise} - */ -function fetchNoteByIdRequest(apiUrl, noteId, format = 'xml', options = {}) { - let path = `/notes/${noteId.toString()}.${format}`; - if (format === 'raw') { - path = `/notes/${noteId.toString()}`; - } - return (0,helpers_xhr__WEBPACK_IMPORTED_MODULE_0__.fetch)((0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.buildApiUrl)(apiUrl, path), options).then(text => { - if (format === 'xml') { - return (0,helpers_xml__WEBPACK_IMPORTED_MODULE_2__.convertNotesXmlToJson)(text); - } else { - return text; - } - }); -} - -/** - * Request generic enough to manage all POST request for a particular note - * @param {osmAuth} auth An instance of osm-auth - * @param {string} apiUrl The API URL - * param {number} noteId Identifier for the note - * @param {string} text A mandatory text field with arbitrary text containing the note - * @param {string} type Mandatory type. It can be 'comment', 'close' or 'reopen' - * @return {Promise} - */ -function genericPostNoteRequest(auth, apiUrl, noteId, text, type) { - return (0,helpers_xhr__WEBPACK_IMPORTED_MODULE_0__.authxhr)({ - method: 'POST', - prefix: false, - path: (0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.buildApiUrl)(apiUrl, `/notes/${noteId}/${type}`, { - text - }), - options: { - header: { - 'Content-Type': 'text/xml' - } - } - }, auth).then(txt => (0,helpers_xml__WEBPACK_IMPORTED_MODULE_2__.convertNotesXmlToJson)(txt)).then(arr => arr.find(() => true)); -} - -/** - * Request to create a note - * @param {osmAuth} auth An instance of osm-auth - * @param {string} apiUrl The API URL - * @param {number} lat Specifies the latitude of the note - * @param {number} lon Specifies the longitude of the note - * @param {string} text A mandatory text field with arbitrary text containing the note - * @return {Promise} - */ -function createNoteRequest(auth, apiUrl, lat, lon, text) { - const params = { - lat, - lon, - text - }; - return (0,helpers_xhr__WEBPACK_IMPORTED_MODULE_0__.authxhr)({ - method: 'POST', - prefix: false, - path: (0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.buildApiUrl)(apiUrl, '/notes', params), - options: { - header: { - 'Content-Type': 'text/xml' - } - } - }, auth).then(txt => (0,helpers_xml__WEBPACK_IMPORTED_MODULE_2__.convertNotesXmlToJson)(txt)).then(arr => arr.find(() => true)); -} - -/** - * Request to create OSM changeset - * @param {osmAuth} auth An instance of osm-auth - * @param {string} apiUrl The API URL - * @param {string} [createdBy] - * @param {string} [comment] - * @param {string} [tags] An object with keys values to set to tags - * @return {Promise} - */ -function createChangesetRequest(auth, apiUrl, createdBy = '', comment = '', tags = {}) { - const changesetXml = (0,helpers_xml__WEBPACK_IMPORTED_MODULE_2__.buildChangesetXml)(createdBy, comment, tags); - return (0,helpers_xhr__WEBPACK_IMPORTED_MODULE_0__.authxhr)({ - method: 'PUT', - prefix: false, - path: (0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.buildApiUrl)(apiUrl, '/changeset/create'), - options: { - header: { - 'Content-Type': 'text/xml' - } - }, - content: changesetXml - }, auth).then(changesetId => parseInt(changesetId, 10)); -} - -/** - * Checks if a given changeset is still opened at OSM. - * @param {string} apiUrl The API URL - * @param {number} changesetId - * @param {Object} [options] Options - * @param {Object} [options.auth] Auth XHR object to use instead of unauthenticated call - * @return {Promise} - */ -function changesetCheckRequest(apiUrl, changesetId, options = {}) { - return changesetGetRequest(apiUrl, changesetId, options).then(res => { - let isOpened; - try { - isOpened = res.osm.changeset[0].$.open === 'true'; - } catch (e) { - isOpened = false; - } - if (!isOpened) { - throw new Error('Changeset not opened'); - } - return changesetId; - }); -} - -/** - * Get a changeset for a given id at OSM. - * @param {string} apiUrl The API URL - * @param {number} changesetId - * @param {Object} [options] Options - * @param {Object} [options.auth] Auth XHR object to use instead of unauthenticated call - * @return {Promise} - */ -function changesetGetRequest(apiUrl, changesetId, options = {}) { - return (0,helpers_xhr__WEBPACK_IMPORTED_MODULE_0__.fetch)((0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.buildApiUrl)(apiUrl, `/changeset/${changesetId.toString()}`), options).then(response => (0,helpers_xml__WEBPACK_IMPORTED_MODULE_2__.xmlToJson)(response)); -} -/** - * Update tags if a given changeset is still opened at OSM. - * @param {osmAuth} auth An instance of osm-auth - * @param {string} apiUrl The API URL - * @param {number} changesetId - * @param {string} [createdBy] - * @param {string} [comment] - * @param {Object} [tags] Use to set multiples tags - * @throws Will throw an error for any request with http code 40x. - * @return {Promise} - */ -function updateChangesetTagsRequest(auth, apiUrl, changesetId, createdBy = '', comment = '', tags = {}) { - const changesetXml = (0,helpers_xml__WEBPACK_IMPORTED_MODULE_2__.buildChangesetFromObjectXml)(tags, createdBy, comment); - return (0,helpers_xhr__WEBPACK_IMPORTED_MODULE_0__.authxhr)({ - method: 'PUT', - prefix: false, - path: (0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.buildApiUrl)(apiUrl, `/changeset/${changesetId.toString()}`), - options: { - header: { - 'Content-Type': 'text/xml' - } - }, - content: changesetXml - }, auth).then(txt => (0,helpers_xml__WEBPACK_IMPORTED_MODULE_2__.xmlToJson)(txt)); -} - -/** - * Request to close changeset for a given id if still opened - * @param {osmAuth} auth An instance of osm-auth - * @param {string} apiUrl The API URL - * @param {number} changesetId - * @throws Will throw an error for any request with http code 40x. - * @return {Promise} Empty string if it works - */ -function closeChangesetRequest(auth, apiUrl, changesetId) { - return (0,helpers_xhr__WEBPACK_IMPORTED_MODULE_0__.authxhr)({ - method: 'PUT', - prefix: false, - path: (0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.buildApiUrl)(apiUrl, `/changeset/${changesetId.toString()}/close`), - options: { - header: { - 'Content-Type': 'text/plain' - } - } - }, auth); -} - -/** - * Request to upload an OSC file content conforming to the OsmChange specification OSM changeset - * @param {osmAuth} auth An instance of osm-auth - * @param {string} apiUrl The API URL - * @param {string} changesetId - * @param {string} osmChangeContent OSC file content text - * @return {Promise} - */ -function uploadChangesetOscRequest(auth, apiUrl, changesetId, osmChangeContent) { - return (0,helpers_xhr__WEBPACK_IMPORTED_MODULE_0__.authxhr)({ - method: 'POST', - prefix: false, - path: (0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.buildApiUrl)(apiUrl, `/changeset/create`), - options: { - header: { - 'Content-Type': 'text/xml' - } - }, - content: osmChangeContent - }, auth).then(txt => (0,helpers_xml__WEBPACK_IMPORTED_MODULE_2__.xmlToJson)(txt)); -} - -/** - * Request to get changesets from OSM API - * @param {string} apiUrl The API URL - * @param {Object} options Optional parameters - * @param {number} [options.left] The minimal longitude (X) - * @param {number} [options.bottom] The minimal latitude (Y) - * @param {number} [options.right] The maximal longitude (X) - * @param {number} [options.top] The maximal latitude (Y) - * @param {string} [options.display_name] Specifies the creator of the returned notes by using a valid display name. Does not work together with the user parameter - * @param {number} [options.user] Specifies the creator of the returned notes by using a valid id of the user. Does not work together with the display_name parameter - * @param {string} [options.time] Can be a unique value T1 or two values T1, T2 comma separated. Find changesets closed after value T1 or find changesets that were closed after T1 and created before T2. In other words, any changesets that were open at some time during the given time range T1 to T2. Time format is anything that http://ruby-doc.org/stdlib-2.6.3/libdoc/date/rdoc/DateTime.html#method-c-parse can parse. - * @param {number} [options.open] Only finds changesets that are still open but excludes changesets that are closed or have reached the element limit for a changeset (50.000 at the moment). Can be set to true - * @param {number} [options.closed] Only finds changesets that are closed or have reached the element limit. Can be set to true - * @param {number} [options.changesets] Finds changesets with the specified ids - * @param {Object} [options.auth] Auth XHR object to use instead of unauthenticated call - * @return {Promise} - */ -function fetchChangesetsRequest(apiUrl, options = {}) { - const keys = ['left', 'bottom', 'right', 'top', 'display_name', 'user', 'time', 'open', 'closed', 'changesets']; - const params = {}; - keys.forEach(key => { - if (key in options && options[key]) { - params[key] = options[key].toString(); - } - }); - if (params.left && params.bottom && params.right && params.top) { - params.bbox = `${params.left.toString()},${params.bottom.toString()},${params.right.toString()},${params.top.toString()}`; - delete params.left; - delete params.bottom; - delete params.right; - delete params.top; - } - return (0,helpers_xhr__WEBPACK_IMPORTED_MODULE_0__.fetch)((0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.buildApiUrl)(apiUrl, '/changesets', params), { - auth: options.auth - }).then(text => (0,helpers_xml__WEBPACK_IMPORTED_MODULE_2__.xmlToJson)(text)); -} - -/** - * Request to fetch all OSM elements within a bbox extent - * @param {string} apiUrl The API URL - * @param {number} left The minimal longitude (X) - * @param {number} bottom The minimal latitude (Y) - * @param {number} right The maximal longitude (X) - * @param {number} top The maximal latitude (Y) - * @param {string} mode The mode is json so output in the promise will be an object, otherwise, it will be an object and a XML string - * @param {Object} [options] Options - * @param {Object} [options.auth] Auth XHR object to use instead of unauthenticated call - * @return {Promise} - */ -function fetchMapByBboxRequest(apiUrl, left, bottom, right, top, mode = 'json', options = {}) { - const args = Array.from(arguments); - if (args.length < 5 && args.some(arg => typeof arg === 'undefined')) { - throw new Error("You didn't provide all arguments to the function"); - } else { - const params = { - bbox: `${left.toString()},${bottom.toString()},${right.toString()},${top.toString()}` - }; - return (0,helpers_xhr__WEBPACK_IMPORTED_MODULE_0__.fetch)((0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.buildApiUrl)(apiUrl, '/map', params), options).then(response => { - if (mode !== 'json') { - return Promise.all([(0,helpers_xml__WEBPACK_IMPORTED_MODULE_2__.xmlToJson)(response).then(json => Promise.resolve((0,helpers_xml__WEBPACK_IMPORTED_MODULE_2__.cleanMapJson)(json))).catch(error => { - throw new exceptions_request__WEBPACK_IMPORTED_MODULE_3__.RequestException(error); - }), response]); - } else { - return (0,helpers_xml__WEBPACK_IMPORTED_MODULE_2__.xmlToJson)(response).then(json => Promise.resolve((0,helpers_xml__WEBPACK_IMPORTED_MODULE_2__.cleanMapJson)(json))).catch(error => { - throw new exceptions_request__WEBPACK_IMPORTED_MODULE_3__.RequestException(error); - }); - } - }); - } -} - -/** - * Delete an OSM element - * @param {osmAuth} auth An instance of osm-auth - * @param {string} apiUrl The API URL - * @param {Object} element - * @param {number} changesetId - * @return {Promise} Promise with the new version number due to deletion - */ -function deleteElementRequest(auth, apiUrl, element, changesetId) { - const copiedElement = (0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.simpleObjectDeepClone)(element); - const { - _id: elementId, - _type: elementType - } = copiedElement; - delete copiedElement._id; - delete copiedElement._type; - copiedElement.$.changeset = changesetId; - const osmContent = { - osm: { - $: {} - } - }; - osmContent.osm[elementType] = [copiedElement]; - const elementXml = (0,helpers_xml__WEBPACK_IMPORTED_MODULE_2__.jsonToXml)(osmContent); - const path = `/${elementType}/${elementId}`; - return (0,helpers_xhr__WEBPACK_IMPORTED_MODULE_0__.authxhr)({ - method: 'DELETE', - prefix: false, - path: (0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.buildApiUrl)(apiUrl, path), - options: { - header: { - 'Content-Type': 'text/xml' - } - }, - content: elementXml - }, auth).then(version => parseInt(version, 10)); -} - -/** Request to fetch relation(s) from an OSM element - * @param {string} apiUrl The API URL - * @param {string} osmId - * @param {Object} [options] Options - * @param {Object} [options.auth] Auth XHR object to use instead of unauthenticated call - * @return {Promise} - */ -function fetchRelationsForElementRequest(apiUrl, osmId, options = {}) { - return (0,helpers_xhr__WEBPACK_IMPORTED_MODULE_0__.fetch)((0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.buildApiUrl)(apiUrl, `/${osmId}/relations`), options).then(response => (0,helpers_xml__WEBPACK_IMPORTED_MODULE_2__.convertElementsListXmlToJson)(response, 'relation')); -} - -/** - * Request to fetch an OSM user details - * @param {string} apiUrl The API URL - * @param {string} userId The user ID - * @param {Object} [options] Options - * @param {Object} [options.auth] Auth XHR object to use instead of unauthenticated call - * @return {Object} - */ -function fetchUserRequest(apiUrl, userId, options = {}) { - return (0,helpers_xhr__WEBPACK_IMPORTED_MODULE_0__.fetch)((0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.buildApiUrl)(apiUrl, `/user/${userId}`), options).then(response => (0,helpers_xml__WEBPACK_IMPORTED_MODULE_2__.convertUserXmlToJson)(response)); -} - -/** - * Request to fetch preferences for the connected user - * @param {osmAuth} auth An instance of osm-auth - * @param {string} apiUrl The API URL - * @throws Will throw an error for any request with http code 40x. - * @return {Promise} Promise with the value for the key - */ -function getUserPreferencesRequest(auth, apiUrl) { - return (0,helpers_xhr__WEBPACK_IMPORTED_MODULE_0__.authxhr)({ - method: 'GET', - prefix: false, - path: (0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.buildApiUrl)(apiUrl, '/user/preferences'), - options: { - header: { - 'Content-Type': 'text/xml' - } - } - }, auth).then(txt => (0,helpers_xml__WEBPACK_IMPORTED_MODULE_2__.xmlToJson)(txt)); -} - -/** - * Request to set all preferences for a connected user - * @param {osmAuth} auth An instance of osm-auth - * @param {string} apiUrl The API URL - * @param {Object} object An object to provide keys values to create XML preferences - * @return {Promise} Promise - */ -function setUserPreferencesRequest(auth, apiUrl, object) { - const preferencesXml = (0,helpers_xml__WEBPACK_IMPORTED_MODULE_2__.buildPreferencesFromObjectXml)(object); - return (0,helpers_xhr__WEBPACK_IMPORTED_MODULE_0__.authxhr)({ - method: 'PUT', - prefix: false, - path: (0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.buildApiUrl)(apiUrl, '/user/preferences'), - options: { - header: { - 'Content-Type': 'text/xml' - } - }, - content: preferencesXml - }, auth); -} - -/** - * Request to fetch a preference from a key for the connected user - * @param {osmAuth} auth An instance of osm-auth - * @param {string} apiUrl The API URL - * @param {string} key The key to retrieve - * @throws Will throw an error for any request with http code 40x. - * @return {Promise} Promise with the value for the key - */ -function getUserPreferenceByKeyRequest(auth, apiUrl, key) { - return (0,helpers_xhr__WEBPACK_IMPORTED_MODULE_0__.authxhr)({ - method: 'GET', - prefix: false, - path: (0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.buildApiUrl)(apiUrl, `/user/preferences/${key}`) - }, auth); -} - -/** - * Request to set a preference from a key for the connected user - * @param {osmAuth} auth An instance of osm-auth - * @param {string} apiUrl The API URL - * @param {string} key The key to set - * @param {string} value The value to set. Overwrite existing value if key exists - * @return {Promise} Promise - */ -function setUserPreferenceByKeyRequest(auth, apiUrl, key, value) { - return (0,helpers_xhr__WEBPACK_IMPORTED_MODULE_0__.authxhr)({ - method: 'PUT', - prefix: false, - path: (0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.buildApiUrl)(apiUrl, `/user/preferences/${key}`), - options: { - header: { - 'Content-Type': 'text/plain' - } - }, - content: value - }, auth); -} - -/** - * Request to delete a preference from a key for the connected user - * @param {osmAuth} auth An instance of osm-auth - * @param {string} apiUrl The API URL - * @param {string} key The key to use - * @return {Promise} Promise - */ -function deleteUserPreferenceRequest(auth, apiUrl, key) { - return (0,helpers_xhr__WEBPACK_IMPORTED_MODULE_0__.authxhr)({ - method: 'DELETE', - prefix: false, - path: (0,helpers_utils__WEBPACK_IMPORTED_MODULE_1__.buildApiUrl)(apiUrl, `/user/preferences/${key}`) - }, auth); -} - -/***/ }), - -/***/ "./node_modules/cross-fetch/dist/browser-ponyfill.js": -/*!***********************************************************!*\ - !*** ./node_modules/cross-fetch/dist/browser-ponyfill.js ***! - \***********************************************************/ -/***/ ((module, exports, __webpack_require__) => { - -// Save global object in a variable -var __global__ = -(typeof globalThis !== 'undefined' && globalThis) || -(typeof self !== 'undefined' && self) || -(typeof __webpack_require__.g !== 'undefined' && __webpack_require__.g); -// Create an object that extends from __global__ without the fetch function -var __globalThis__ = (function () { -function F() { -this.fetch = false; -this.DOMException = __global__.DOMException -} -F.prototype = __global__; // Needed for feature detection on whatwg-fetch's code -return new F(); -})(); -// Wraps whatwg-fetch with a function scope to hijack the global object -// "globalThis" that's going to be patched -(function(globalThis) { - -var irrelevant = (function (exports) { - - var global = - (typeof globalThis !== 'undefined' && globalThis) || - (typeof self !== 'undefined' && self) || - (typeof global !== 'undefined' && global); - - var support = { - searchParams: 'URLSearchParams' in global, - iterable: 'Symbol' in global && 'iterator' in Symbol, - blob: - 'FileReader' in global && - 'Blob' in global && - (function() { - try { - new Blob(); - return true - } catch (e) { - return false - } - })(), - formData: 'FormData' in global, - arrayBuffer: 'ArrayBuffer' in global - }; - - function isDataView(obj) { - return obj && DataView.prototype.isPrototypeOf(obj) - } - - if (support.arrayBuffer) { - var viewClasses = [ - '[object Int8Array]', - '[object Uint8Array]', - '[object Uint8ClampedArray]', - '[object Int16Array]', - '[object Uint16Array]', - '[object Int32Array]', - '[object Uint32Array]', - '[object Float32Array]', - '[object Float64Array]' - ]; - - var isArrayBufferView = - ArrayBuffer.isView || - function(obj) { - return obj && viewClasses.indexOf(Object.prototype.toString.call(obj)) > -1 - }; - } - - function normalizeName(name) { - if (typeof name !== 'string') { - name = String(name); - } - if (/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(name) || name === '') { - throw new TypeError('Invalid character in header field name: "' + name + '"') - } - return name.toLowerCase() - } - - function normalizeValue(value) { - if (typeof value !== 'string') { - value = String(value); - } - return value - } - - // Build a destructive iterator for the value list - function iteratorFor(items) { - var iterator = { - next: function() { - var value = items.shift(); - return {done: value === undefined, value: value} - } - }; - - if (support.iterable) { - iterator[Symbol.iterator] = function() { - return iterator - }; - } - - return iterator - } - - function Headers(headers) { - this.map = {}; - - if (headers instanceof Headers) { - headers.forEach(function(value, name) { - this.append(name, value); - }, this); - } else if (Array.isArray(headers)) { - headers.forEach(function(header) { - this.append(header[0], header[1]); - }, this); - } else if (headers) { - Object.getOwnPropertyNames(headers).forEach(function(name) { - this.append(name, headers[name]); - }, this); - } - } - - Headers.prototype.append = function(name, value) { - name = normalizeName(name); - value = normalizeValue(value); - var oldValue = this.map[name]; - this.map[name] = oldValue ? oldValue + ', ' + value : value; - }; - - Headers.prototype['delete'] = function(name) { - delete this.map[normalizeName(name)]; - }; - - Headers.prototype.get = function(name) { - name = normalizeName(name); - return this.has(name) ? this.map[name] : null - }; - - Headers.prototype.has = function(name) { - return this.map.hasOwnProperty(normalizeName(name)) - }; - - Headers.prototype.set = function(name, value) { - this.map[normalizeName(name)] = normalizeValue(value); - }; - - Headers.prototype.forEach = function(callback, thisArg) { - for (var name in this.map) { - if (this.map.hasOwnProperty(name)) { - callback.call(thisArg, this.map[name], name, this); - } - } - }; - - Headers.prototype.keys = function() { - var items = []; - this.forEach(function(value, name) { - items.push(name); - }); - return iteratorFor(items) - }; - - Headers.prototype.values = function() { - var items = []; - this.forEach(function(value) { - items.push(value); - }); - return iteratorFor(items) - }; - - Headers.prototype.entries = function() { - var items = []; - this.forEach(function(value, name) { - items.push([name, value]); - }); - return iteratorFor(items) - }; - - if (support.iterable) { - Headers.prototype[Symbol.iterator] = Headers.prototype.entries; - } - - function consumed(body) { - if (body.bodyUsed) { - return Promise.reject(new TypeError('Already read')) - } - body.bodyUsed = true; - } - - function fileReaderReady(reader) { - return new Promise(function(resolve, reject) { - reader.onload = function() { - resolve(reader.result); - }; - reader.onerror = function() { - reject(reader.error); - }; - }) - } - - function readBlobAsArrayBuffer(blob) { - var reader = new FileReader(); - var promise = fileReaderReady(reader); - reader.readAsArrayBuffer(blob); - return promise - } - - function readBlobAsText(blob) { - var reader = new FileReader(); - var promise = fileReaderReady(reader); - reader.readAsText(blob); - return promise - } - - function readArrayBufferAsText(buf) { - var view = new Uint8Array(buf); - var chars = new Array(view.length); - - for (var i = 0; i < view.length; i++) { - chars[i] = String.fromCharCode(view[i]); - } - return chars.join('') - } - - function bufferClone(buf) { - if (buf.slice) { - return buf.slice(0) - } else { - var view = new Uint8Array(buf.byteLength); - view.set(new Uint8Array(buf)); - return view.buffer - } - } - - function Body() { - this.bodyUsed = false; - - this._initBody = function(body) { - /* - fetch-mock wraps the Response object in an ES6 Proxy to - provide useful test harness features such as flush. However, on - ES5 browsers without fetch or Proxy support pollyfills must be used; - the proxy-pollyfill is unable to proxy an attribute unless it exists - on the object before the Proxy is created. This change ensures - Response.bodyUsed exists on the instance, while maintaining the - semantic of setting Request.bodyUsed in the constructor before - _initBody is called. - */ - this.bodyUsed = this.bodyUsed; - this._bodyInit = body; - if (!body) { - this._bodyText = ''; - } else if (typeof body === 'string') { - this._bodyText = body; - } else if (support.blob && Blob.prototype.isPrototypeOf(body)) { - this._bodyBlob = body; - } else if (support.formData && FormData.prototype.isPrototypeOf(body)) { - this._bodyFormData = body; - } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) { - this._bodyText = body.toString(); - } else if (support.arrayBuffer && support.blob && isDataView(body)) { - this._bodyArrayBuffer = bufferClone(body.buffer); - // IE 10-11 can't handle a DataView body. - this._bodyInit = new Blob([this._bodyArrayBuffer]); - } else if (support.arrayBuffer && (ArrayBuffer.prototype.isPrototypeOf(body) || isArrayBufferView(body))) { - this._bodyArrayBuffer = bufferClone(body); - } else { - this._bodyText = body = Object.prototype.toString.call(body); - } - - if (!this.headers.get('content-type')) { - if (typeof body === 'string') { - this.headers.set('content-type', 'text/plain;charset=UTF-8'); - } else if (this._bodyBlob && this._bodyBlob.type) { - this.headers.set('content-type', this._bodyBlob.type); - } else if (support.searchParams && URLSearchParams.prototype.isPrototypeOf(body)) { - this.headers.set('content-type', 'application/x-www-form-urlencoded;charset=UTF-8'); - } - } - }; - - if (support.blob) { - this.blob = function() { - var rejected = consumed(this); - if (rejected) { - return rejected - } - - if (this._bodyBlob) { - return Promise.resolve(this._bodyBlob) - } else if (this._bodyArrayBuffer) { - return Promise.resolve(new Blob([this._bodyArrayBuffer])) - } else if (this._bodyFormData) { - throw new Error('could not read FormData body as blob') - } else { - return Promise.resolve(new Blob([this._bodyText])) - } - }; - - this.arrayBuffer = function() { - if (this._bodyArrayBuffer) { - var isConsumed = consumed(this); - if (isConsumed) { - return isConsumed - } - if (ArrayBuffer.isView(this._bodyArrayBuffer)) { - return Promise.resolve( - this._bodyArrayBuffer.buffer.slice( - this._bodyArrayBuffer.byteOffset, - this._bodyArrayBuffer.byteOffset + this._bodyArrayBuffer.byteLength - ) - ) - } else { - return Promise.resolve(this._bodyArrayBuffer) - } - } else { - return this.blob().then(readBlobAsArrayBuffer) - } - }; - } - - this.text = function() { - var rejected = consumed(this); - if (rejected) { - return rejected - } - - if (this._bodyBlob) { - return readBlobAsText(this._bodyBlob) - } else if (this._bodyArrayBuffer) { - return Promise.resolve(readArrayBufferAsText(this._bodyArrayBuffer)) - } else if (this._bodyFormData) { - throw new Error('could not read FormData body as text') - } else { - return Promise.resolve(this._bodyText) - } - }; - - if (support.formData) { - this.formData = function() { - return this.text().then(decode) - }; - } - - this.json = function() { - return this.text().then(JSON.parse) - }; - - return this - } - - // HTTP methods whose capitalization should be normalized - var methods = ['DELETE', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT']; - - function normalizeMethod(method) { - var upcased = method.toUpperCase(); - return methods.indexOf(upcased) > -1 ? upcased : method - } - - function Request(input, options) { - if (!(this instanceof Request)) { - throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.') - } - - options = options || {}; - var body = options.body; - - if (input instanceof Request) { - if (input.bodyUsed) { - throw new TypeError('Already read') - } - this.url = input.url; - this.credentials = input.credentials; - if (!options.headers) { - this.headers = new Headers(input.headers); - } - this.method = input.method; - this.mode = input.mode; - this.signal = input.signal; - if (!body && input._bodyInit != null) { - body = input._bodyInit; - input.bodyUsed = true; - } - } else { - this.url = String(input); - } - - this.credentials = options.credentials || this.credentials || 'same-origin'; - if (options.headers || !this.headers) { - this.headers = new Headers(options.headers); - } - this.method = normalizeMethod(options.method || this.method || 'GET'); - this.mode = options.mode || this.mode || null; - this.signal = options.signal || this.signal; - this.referrer = null; - - if ((this.method === 'GET' || this.method === 'HEAD') && body) { - throw new TypeError('Body not allowed for GET or HEAD requests') - } - this._initBody(body); - - if (this.method === 'GET' || this.method === 'HEAD') { - if (options.cache === 'no-store' || options.cache === 'no-cache') { - // Search for a '_' parameter in the query string - var reParamSearch = /([?&])_=[^&]*/; - if (reParamSearch.test(this.url)) { - // If it already exists then set the value with the current time - this.url = this.url.replace(reParamSearch, '$1_=' + new Date().getTime()); - } else { - // Otherwise add a new '_' parameter to the end with the current time - var reQueryString = /\?/; - this.url += (reQueryString.test(this.url) ? '&' : '?') + '_=' + new Date().getTime(); - } - } - } - } - - Request.prototype.clone = function() { - return new Request(this, {body: this._bodyInit}) - }; - - function decode(body) { - var form = new FormData(); - body - .trim() - .split('&') - .forEach(function(bytes) { - if (bytes) { - var split = bytes.split('='); - var name = split.shift().replace(/\+/g, ' '); - var value = split.join('=').replace(/\+/g, ' '); - form.append(decodeURIComponent(name), decodeURIComponent(value)); - } - }); - return form - } - - function parseHeaders(rawHeaders) { - var headers = new Headers(); - // Replace instances of \r\n and \n followed by at least one space or horizontal tab with a space - // https://tools.ietf.org/html/rfc7230#section-3.2 - var preProcessedHeaders = rawHeaders.replace(/\r?\n[\t ]+/g, ' '); - // Avoiding split via regex to work around a common IE11 bug with the core-js 3.6.0 regex polyfill - // https://github.com/github/fetch/issues/748 - // https://github.com/zloirock/core-js/issues/751 - preProcessedHeaders - .split('\r') - .map(function(header) { - return header.indexOf('\n') === 0 ? header.substr(1, header.length) : header - }) - .forEach(function(line) { - var parts = line.split(':'); - var key = parts.shift().trim(); - if (key) { - var value = parts.join(':').trim(); - headers.append(key, value); - } - }); - return headers - } - - Body.call(Request.prototype); - - function Response(bodyInit, options) { - if (!(this instanceof Response)) { - throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.') - } - if (!options) { - options = {}; - } - - this.type = 'default'; - this.status = options.status === undefined ? 200 : options.status; - this.ok = this.status >= 200 && this.status < 300; - this.statusText = options.statusText === undefined ? '' : '' + options.statusText; - this.headers = new Headers(options.headers); - this.url = options.url || ''; - this._initBody(bodyInit); - } - - Body.call(Response.prototype); - - Response.prototype.clone = function() { - return new Response(this._bodyInit, { - status: this.status, - statusText: this.statusText, - headers: new Headers(this.headers), - url: this.url - }) - }; - - Response.error = function() { - var response = new Response(null, {status: 0, statusText: ''}); - response.type = 'error'; - return response - }; - - var redirectStatuses = [301, 302, 303, 307, 308]; - - Response.redirect = function(url, status) { - if (redirectStatuses.indexOf(status) === -1) { - throw new RangeError('Invalid status code') - } - - return new Response(null, {status: status, headers: {location: url}}) - }; - - exports.DOMException = global.DOMException; - try { - new exports.DOMException(); - } catch (err) { - exports.DOMException = function(message, name) { - this.message = message; - this.name = name; - var error = Error(message); - this.stack = error.stack; - }; - exports.DOMException.prototype = Object.create(Error.prototype); - exports.DOMException.prototype.constructor = exports.DOMException; - } - - function fetch(input, init) { - return new Promise(function(resolve, reject) { - var request = new Request(input, init); - - if (request.signal && request.signal.aborted) { - return reject(new exports.DOMException('Aborted', 'AbortError')) - } - - var xhr = new XMLHttpRequest(); - - function abortXhr() { - xhr.abort(); - } - - xhr.onload = function() { - var options = { - status: xhr.status, - statusText: xhr.statusText, - headers: parseHeaders(xhr.getAllResponseHeaders() || '') - }; - options.url = 'responseURL' in xhr ? xhr.responseURL : options.headers.get('X-Request-URL'); - var body = 'response' in xhr ? xhr.response : xhr.responseText; - setTimeout(function() { - resolve(new Response(body, options)); - }, 0); - }; - - xhr.onerror = function() { - setTimeout(function() { - reject(new TypeError('Network request failed')); - }, 0); - }; - - xhr.ontimeout = function() { - setTimeout(function() { - reject(new TypeError('Network request failed')); - }, 0); - }; - - xhr.onabort = function() { - setTimeout(function() { - reject(new exports.DOMException('Aborted', 'AbortError')); - }, 0); - }; - - function fixUrl(url) { - try { - return url === '' && global.location.href ? global.location.href : url - } catch (e) { - return url - } - } - - xhr.open(request.method, fixUrl(request.url), true); - - if (request.credentials === 'include') { - xhr.withCredentials = true; - } else if (request.credentials === 'omit') { - xhr.withCredentials = false; - } - - if ('responseType' in xhr) { - if (support.blob) { - xhr.responseType = 'blob'; - } else if ( - support.arrayBuffer && - request.headers.get('Content-Type') && - request.headers.get('Content-Type').indexOf('application/octet-stream') !== -1 - ) { - xhr.responseType = 'arraybuffer'; - } - } - - if (init && typeof init.headers === 'object' && !(init.headers instanceof Headers)) { - Object.getOwnPropertyNames(init.headers).forEach(function(name) { - xhr.setRequestHeader(name, normalizeValue(init.headers[name])); - }); - } else { - request.headers.forEach(function(value, name) { - xhr.setRequestHeader(name, value); - }); - } - - if (request.signal) { - request.signal.addEventListener('abort', abortXhr); - - xhr.onreadystatechange = function() { - // DONE (success or failure) - if (xhr.readyState === 4) { - request.signal.removeEventListener('abort', abortXhr); - } - }; - } - - xhr.send(typeof request._bodyInit === 'undefined' ? null : request._bodyInit); - }) - } - - fetch.polyfill = true; - - if (!global.fetch) { - global.fetch = fetch; - global.Headers = Headers; - global.Request = Request; - global.Response = Response; - } - - exports.Headers = Headers; - exports.Request = Request; - exports.Response = Response; - exports.fetch = fetch; - - return exports; - -})({}); -})(__globalThis__); -// This is a ponyfill, so... -__globalThis__.fetch.ponyfill = true; -delete __globalThis__.fetch.polyfill; -// Choose between native implementation (__global__) or custom implementation (__globalThis__) -var ctx = __global__.fetch ? __global__ : __globalThis__; -exports = ctx.fetch // To enable: import fetch from 'cross-fetch' -exports["default"] = ctx.fetch // For TypeScript consumers without esModuleInterop. -exports.fetch = ctx.fetch // To enable: import {fetch} from 'cross-fetch' -exports.Headers = ctx.Headers -exports.Request = ctx.Request -exports.Response = ctx.Response -module.exports = exports - - -/***/ }), - -/***/ "./node_modules/events/events.js": -/*!***************************************!*\ - !*** ./node_modules/events/events.js ***! - \***************************************/ -/***/ ((module) => { - -"use strict"; -// Copyright Joyent, Inc. and other Node contributors. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to permit -// persons to whom the Software is furnished to do so, subject to the -// following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN -// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR -// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE -// USE OR OTHER DEALINGS IN THE SOFTWARE. - - - -var R = typeof Reflect === 'object' ? Reflect : null -var ReflectApply = R && typeof R.apply === 'function' - ? R.apply - : function ReflectApply(target, receiver, args) { - return Function.prototype.apply.call(target, receiver, args); - } - -var ReflectOwnKeys -if (R && typeof R.ownKeys === 'function') { - ReflectOwnKeys = R.ownKeys -} else if (Object.getOwnPropertySymbols) { - ReflectOwnKeys = function ReflectOwnKeys(target) { - return Object.getOwnPropertyNames(target) - .concat(Object.getOwnPropertySymbols(target)); - }; -} else { - ReflectOwnKeys = function ReflectOwnKeys(target) { - return Object.getOwnPropertyNames(target); - }; -} - -function ProcessEmitWarning(warning) { - if (console && console.warn) console.warn(warning); -} - -var NumberIsNaN = Number.isNaN || function NumberIsNaN(value) { - return value !== value; -} - -function EventEmitter() { - EventEmitter.init.call(this); -} -module.exports = EventEmitter; -module.exports.once = once; - -// Backwards-compat with node 0.10.x -EventEmitter.EventEmitter = EventEmitter; - -EventEmitter.prototype._events = undefined; -EventEmitter.prototype._eventsCount = 0; -EventEmitter.prototype._maxListeners = undefined; - -// By default EventEmitters will print a warning if more than 10 listeners are -// added to it. This is a useful default which helps finding memory leaks. -var defaultMaxListeners = 10; - -function checkListener(listener) { - if (typeof listener !== 'function') { - throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener); - } -} - -Object.defineProperty(EventEmitter, 'defaultMaxListeners', { - enumerable: true, - get: function() { - return defaultMaxListeners; - }, - set: function(arg) { - if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) { - throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + '.'); - } - defaultMaxListeners = arg; - } -}); - -EventEmitter.init = function() { - - if (this._events === undefined || - this._events === Object.getPrototypeOf(this)._events) { - this._events = Object.create(null); - this._eventsCount = 0; - } - - this._maxListeners = this._maxListeners || undefined; -}; - -// Obviously not all Emitters should be limited to 10. This function allows -// that to be increased. Set to zero for unlimited. -EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) { - if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) { - throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + '.'); - } - this._maxListeners = n; - return this; -}; - -function _getMaxListeners(that) { - if (that._maxListeners === undefined) - return EventEmitter.defaultMaxListeners; - return that._maxListeners; -} - -EventEmitter.prototype.getMaxListeners = function getMaxListeners() { - return _getMaxListeners(this); -}; - -EventEmitter.prototype.emit = function emit(type) { - var args = []; - for (var i = 1; i < arguments.length; i++) args.push(arguments[i]); - var doError = (type === 'error'); - - var events = this._events; - if (events !== undefined) - doError = (doError && events.error === undefined); - else if (!doError) - return false; - - // If there is no 'error' event listener then throw. - if (doError) { - var er; - if (args.length > 0) - er = args[0]; - if (er instanceof Error) { - // Note: The comments on the `throw` lines are intentional, they show - // up in Node's output if this results in an unhandled exception. - throw er; // Unhandled 'error' event - } - // At least give some kind of context to the user - var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : '')); - err.context = er; - throw err; // Unhandled 'error' event - } - - var handler = events[type]; - - if (handler === undefined) - return false; - - if (typeof handler === 'function') { - ReflectApply(handler, this, args); - } else { - var len = handler.length; - var listeners = arrayClone(handler, len); - for (var i = 0; i < len; ++i) - ReflectApply(listeners[i], this, args); - } - - return true; -}; - -function _addListener(target, type, listener, prepend) { - var m; - var events; - var existing; - - checkListener(listener); - - events = target._events; - if (events === undefined) { - events = target._events = Object.create(null); - target._eventsCount = 0; - } else { - // To avoid recursion in the case that type === "newListener"! Before - // adding it to the listeners, first emit "newListener". - if (events.newListener !== undefined) { - target.emit('newListener', type, - listener.listener ? listener.listener : listener); - - // Re-assign `events` because a newListener handler could have caused the - // this._events to be assigned to a new object - events = target._events; - } - existing = events[type]; - } - - if (existing === undefined) { - // Optimize the case of one listener. Don't need the extra array object. - existing = events[type] = listener; - ++target._eventsCount; - } else { - if (typeof existing === 'function') { - // Adding the second element, need to change to array. - existing = events[type] = - prepend ? [listener, existing] : [existing, listener]; - // If we've already got an array, just append. - } else if (prepend) { - existing.unshift(listener); - } else { - existing.push(listener); - } - - // Check for listener leak - m = _getMaxListeners(target); - if (m > 0 && existing.length > m && !existing.warned) { - existing.warned = true; - // No error code for this since it is a Warning - // eslint-disable-next-line no-restricted-syntax - var w = new Error('Possible EventEmitter memory leak detected. ' + - existing.length + ' ' + String(type) + ' listeners ' + - 'added. Use emitter.setMaxListeners() to ' + - 'increase limit'); - w.name = 'MaxListenersExceededWarning'; - w.emitter = target; - w.type = type; - w.count = existing.length; - ProcessEmitWarning(w); - } - } - - return target; -} - -EventEmitter.prototype.addListener = function addListener(type, listener) { - return _addListener(this, type, listener, false); -}; - -EventEmitter.prototype.on = EventEmitter.prototype.addListener; - -EventEmitter.prototype.prependListener = - function prependListener(type, listener) { - return _addListener(this, type, listener, true); - }; - -function onceWrapper() { - if (!this.fired) { - this.target.removeListener(this.type, this.wrapFn); - this.fired = true; - if (arguments.length === 0) - return this.listener.call(this.target); - return this.listener.apply(this.target, arguments); - } -} - -function _onceWrap(target, type, listener) { - var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener }; - var wrapped = onceWrapper.bind(state); - wrapped.listener = listener; - state.wrapFn = wrapped; - return wrapped; -} - -EventEmitter.prototype.once = function once(type, listener) { - checkListener(listener); - this.on(type, _onceWrap(this, type, listener)); - return this; -}; - -EventEmitter.prototype.prependOnceListener = - function prependOnceListener(type, listener) { - checkListener(listener); - this.prependListener(type, _onceWrap(this, type, listener)); - return this; - }; - -// Emits a 'removeListener' event if and only if the listener was removed. -EventEmitter.prototype.removeListener = - function removeListener(type, listener) { - var list, events, position, i, originalListener; - - checkListener(listener); - - events = this._events; - if (events === undefined) - return this; - - list = events[type]; - if (list === undefined) - return this; - - if (list === listener || list.listener === listener) { - if (--this._eventsCount === 0) - this._events = Object.create(null); - else { - delete events[type]; - if (events.removeListener) - this.emit('removeListener', type, list.listener || listener); - } - } else if (typeof list !== 'function') { - position = -1; - - for (i = list.length - 1; i >= 0; i--) { - if (list[i] === listener || list[i].listener === listener) { - originalListener = list[i].listener; - position = i; - break; - } - } - - if (position < 0) - return this; - - if (position === 0) - list.shift(); - else { - spliceOne(list, position); - } - - if (list.length === 1) - events[type] = list[0]; - - if (events.removeListener !== undefined) - this.emit('removeListener', type, originalListener || listener); - } - - return this; - }; - -EventEmitter.prototype.off = EventEmitter.prototype.removeListener; - -EventEmitter.prototype.removeAllListeners = - function removeAllListeners(type) { - var listeners, events, i; - - events = this._events; - if (events === undefined) - return this; - - // not listening for removeListener, no need to emit - if (events.removeListener === undefined) { - if (arguments.length === 0) { - this._events = Object.create(null); - this._eventsCount = 0; - } else if (events[type] !== undefined) { - if (--this._eventsCount === 0) - this._events = Object.create(null); - else - delete events[type]; - } - return this; - } - - // emit removeListener for all listeners on all events - if (arguments.length === 0) { - var keys = Object.keys(events); - var key; - for (i = 0; i < keys.length; ++i) { - key = keys[i]; - if (key === 'removeListener') continue; - this.removeAllListeners(key); - } - this.removeAllListeners('removeListener'); - this._events = Object.create(null); - this._eventsCount = 0; - return this; - } - - listeners = events[type]; - - if (typeof listeners === 'function') { - this.removeListener(type, listeners); - } else if (listeners !== undefined) { - // LIFO order - for (i = listeners.length - 1; i >= 0; i--) { - this.removeListener(type, listeners[i]); - } - } - - return this; - }; - -function _listeners(target, type, unwrap) { - var events = target._events; - - if (events === undefined) - return []; - - var evlistener = events[type]; - if (evlistener === undefined) - return []; - - if (typeof evlistener === 'function') - return unwrap ? [evlistener.listener || evlistener] : [evlistener]; - - return unwrap ? - unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length); -} - -EventEmitter.prototype.listeners = function listeners(type) { - return _listeners(this, type, true); -}; - -EventEmitter.prototype.rawListeners = function rawListeners(type) { - return _listeners(this, type, false); -}; - -EventEmitter.listenerCount = function(emitter, type) { - if (typeof emitter.listenerCount === 'function') { - return emitter.listenerCount(type); - } else { - return listenerCount.call(emitter, type); - } -}; - -EventEmitter.prototype.listenerCount = listenerCount; -function listenerCount(type) { - var events = this._events; - - if (events !== undefined) { - var evlistener = events[type]; - - if (typeof evlistener === 'function') { - return 1; - } else if (evlistener !== undefined) { - return evlistener.length; - } - } - - return 0; -} - -EventEmitter.prototype.eventNames = function eventNames() { - return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : []; -}; - -function arrayClone(arr, n) { - var copy = new Array(n); - for (var i = 0; i < n; ++i) - copy[i] = arr[i]; - return copy; -} - -function spliceOne(list, index) { - for (; index + 1 < list.length; index++) - list[index] = list[index + 1]; - list.pop(); -} - -function unwrapListeners(arr) { - var ret = new Array(arr.length); - for (var i = 0; i < ret.length; ++i) { - ret[i] = arr[i].listener || arr[i]; - } - return ret; -} - -function once(emitter, name) { - return new Promise(function (resolve, reject) { - function errorListener(err) { - emitter.removeListener(name, resolver); - reject(err); - } - - function resolver() { - if (typeof emitter.removeListener === 'function') { - emitter.removeListener('error', errorListener); - } - resolve([].slice.call(arguments)); - }; - - eventTargetAgnosticAddListener(emitter, name, resolver, { once: true }); - if (name !== 'error') { - addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true }); - } - }); -} - -function addErrorHandlerIfEventEmitter(emitter, handler, flags) { - if (typeof emitter.on === 'function') { - eventTargetAgnosticAddListener(emitter, 'error', handler, flags); - } -} - -function eventTargetAgnosticAddListener(emitter, name, listener, flags) { - if (typeof emitter.on === 'function') { - if (flags.once) { - emitter.once(name, listener); - } else { - emitter.on(name, listener); - } - } else if (typeof emitter.addEventListener === 'function') { - // EventTarget does not have `error` event semantics like Node - // EventEmitters, we do not listen for `error` events here. - emitter.addEventListener(name, function wrapListener(arg) { - // IE does not have builtin `{ once: true }` support so we - // have to do it manually. - if (flags.once) { - emitter.removeEventListener(name, wrapListener); - } - listener(arg); - }); - } else { - throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter); - } -} - - -/***/ }), - -/***/ "./node_modules/sax/lib/sax.js": -/*!*************************************!*\ - !*** ./node_modules/sax/lib/sax.js ***! - \*************************************/ -/***/ ((__unused_webpack_module, exports, __webpack_require__) => { - -;(function (sax) { // wrapper for non-node envs - sax.parser = function (strict, opt) { return new SAXParser(strict, opt) } - sax.SAXParser = SAXParser - sax.SAXStream = SAXStream - sax.createStream = createStream - - // When we pass the MAX_BUFFER_LENGTH position, start checking for buffer overruns. - // When we check, schedule the next check for MAX_BUFFER_LENGTH - (max(buffer lengths)), - // since that's the earliest that a buffer overrun could occur. This way, checks are - // as rare as required, but as often as necessary to ensure never crossing this bound. - // Furthermore, buffers are only tested at most once per write(), so passing a very - // large string into write() might have undesirable effects, but this is manageable by - // the caller, so it is assumed to be safe. Thus, a call to write() may, in the extreme - // edge case, result in creating at most one complete copy of the string passed in. - // Set to Infinity to have unlimited buffers. - sax.MAX_BUFFER_LENGTH = 64 * 1024 - - var buffers = [ - 'comment', 'sgmlDecl', 'textNode', 'tagName', 'doctype', - 'procInstName', 'procInstBody', 'entity', 'attribName', - 'attribValue', 'cdata', 'script' - ] - - sax.EVENTS = [ - 'text', - 'processinginstruction', - 'sgmldeclaration', - 'doctype', - 'comment', - 'opentagstart', - 'attribute', - 'opentag', - 'closetag', - 'opencdata', - 'cdata', - 'closecdata', - 'error', - 'end', - 'ready', - 'script', - 'opennamespace', - 'closenamespace' - ] - - function SAXParser (strict, opt) { - if (!(this instanceof SAXParser)) { - return new SAXParser(strict, opt) - } - - var parser = this - clearBuffers(parser) - parser.q = parser.c = '' - parser.bufferCheckPosition = sax.MAX_BUFFER_LENGTH - parser.opt = opt || {} - parser.opt.lowercase = parser.opt.lowercase || parser.opt.lowercasetags - parser.looseCase = parser.opt.lowercase ? 'toLowerCase' : 'toUpperCase' - parser.tags = [] - parser.closed = parser.closedRoot = parser.sawRoot = false - parser.tag = parser.error = null - parser.strict = !!strict - parser.noscript = !!(strict || parser.opt.noscript) - parser.state = S.BEGIN - parser.strictEntities = parser.opt.strictEntities - parser.ENTITIES = parser.strictEntities ? Object.create(sax.XML_ENTITIES) : Object.create(sax.ENTITIES) - parser.attribList = [] - - // namespaces form a prototype chain. - // it always points at the current tag, - // which protos to its parent tag. - if (parser.opt.xmlns) { - parser.ns = Object.create(rootNS) - } - - // disallow unquoted attribute values if not otherwise configured - // and strict mode is true - if (parser.opt.unquotedAttributeValues === undefined) { - parser.opt.unquotedAttributeValues = !strict; - } - - // mostly just for error reporting - parser.trackPosition = parser.opt.position !== false - if (parser.trackPosition) { - parser.position = parser.line = parser.column = 0 - } - emit(parser, 'onready') - } - - if (!Object.create) { - Object.create = function (o) { - function F () {} - F.prototype = o - var newf = new F() - return newf - } - } - - if (!Object.keys) { - Object.keys = function (o) { - var a = [] - for (var i in o) if (o.hasOwnProperty(i)) a.push(i) - return a - } - } - - function checkBufferLength (parser) { - var maxAllowed = Math.max(sax.MAX_BUFFER_LENGTH, 10) - var maxActual = 0 - for (var i = 0, l = buffers.length; i < l; i++) { - var len = parser[buffers[i]].length - if (len > maxAllowed) { - // Text/cdata nodes can get big, and since they're buffered, - // we can get here under normal conditions. - // Avoid issues by emitting the text node now, - // so at least it won't get any bigger. - switch (buffers[i]) { - case 'textNode': - closeText(parser) - break - - case 'cdata': - emitNode(parser, 'oncdata', parser.cdata) - parser.cdata = '' - break - - case 'script': - emitNode(parser, 'onscript', parser.script) - parser.script = '' - break - - default: - error(parser, 'Max buffer length exceeded: ' + buffers[i]) - } - } - maxActual = Math.max(maxActual, len) - } - // schedule the next check for the earliest possible buffer overrun. - var m = sax.MAX_BUFFER_LENGTH - maxActual - parser.bufferCheckPosition = m + parser.position - } - - function clearBuffers (parser) { - for (var i = 0, l = buffers.length; i < l; i++) { - parser[buffers[i]] = '' - } - } - - function flushBuffers (parser) { - closeText(parser) - if (parser.cdata !== '') { - emitNode(parser, 'oncdata', parser.cdata) - parser.cdata = '' - } - if (parser.script !== '') { - emitNode(parser, 'onscript', parser.script) - parser.script = '' - } - } - - SAXParser.prototype = { - end: function () { end(this) }, - write: write, - resume: function () { this.error = null; return this }, - close: function () { return this.write(null) }, - flush: function () { flushBuffers(this) } - } - - var Stream - try { - Stream = (__webpack_require__(/*! stream */ "?37ae").Stream) - } catch (ex) { - Stream = function () {} - } - if (!Stream) Stream = function () {} - - var streamWraps = sax.EVENTS.filter(function (ev) { - return ev !== 'error' && ev !== 'end' - }) - - function createStream (strict, opt) { - return new SAXStream(strict, opt) - } - - function SAXStream (strict, opt) { - if (!(this instanceof SAXStream)) { - return new SAXStream(strict, opt) - } - - Stream.apply(this) - - this._parser = new SAXParser(strict, opt) - this.writable = true - this.readable = true - - var me = this - - this._parser.onend = function () { - me.emit('end') - } - - this._parser.onerror = function (er) { - me.emit('error', er) - - // if didn't throw, then means error was handled. - // go ahead and clear error, so we can write again. - me._parser.error = null - } - - this._decoder = null - - streamWraps.forEach(function (ev) { - Object.defineProperty(me, 'on' + ev, { - get: function () { - return me._parser['on' + ev] - }, - set: function (h) { - if (!h) { - me.removeAllListeners(ev) - me._parser['on' + ev] = h - return h - } - me.on(ev, h) - }, - enumerable: true, - configurable: false - }) - }) - } - - SAXStream.prototype = Object.create(Stream.prototype, { - constructor: { - value: SAXStream - } - }) - - SAXStream.prototype.write = function (data) { - if (typeof Buffer === 'function' && - typeof Buffer.isBuffer === 'function' && - Buffer.isBuffer(data)) { - if (!this._decoder) { - var SD = (__webpack_require__(/*! string_decoder */ "?5bcd").StringDecoder) - this._decoder = new SD('utf8') - } - data = this._decoder.write(data) - } - - this._parser.write(data.toString()) - this.emit('data', data) - return true - } - - SAXStream.prototype.end = function (chunk) { - if (chunk && chunk.length) { - this.write(chunk) - } - this._parser.end() - return true - } - - SAXStream.prototype.on = function (ev, handler) { - var me = this - if (!me._parser['on' + ev] && streamWraps.indexOf(ev) !== -1) { - me._parser['on' + ev] = function () { - var args = arguments.length === 1 ? [arguments[0]] : Array.apply(null, arguments) - args.splice(0, 0, ev) - me.emit.apply(me, args) - } - } - - return Stream.prototype.on.call(me, ev, handler) - } - - // this really needs to be replaced with character classes. - // XML allows all manner of ridiculous numbers and digits. - var CDATA = '[CDATA[' - var DOCTYPE = 'DOCTYPE' - var XML_NAMESPACE = 'http://www.w3.org/XML/1998/namespace' - var XMLNS_NAMESPACE = 'http://www.w3.org/2000/xmlns/' - var rootNS = { xml: XML_NAMESPACE, xmlns: XMLNS_NAMESPACE } - - // http://www.w3.org/TR/REC-xml/#NT-NameStartChar - // This implementation works on strings, a single character at a time - // as such, it cannot ever support astral-plane characters (10000-EFFFF) - // without a significant breaking change to either this parser, or the - // JavaScript language. Implementation of an emoji-capable xml parser - // is left as an exercise for the reader. - var nameStart = /[:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/ - - var nameBody = /[:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u00B7\u0300-\u036F\u203F-\u2040.\d-]/ - - var entityStart = /[#:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/ - var entityBody = /[#:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u00B7\u0300-\u036F\u203F-\u2040.\d-]/ - - function isWhitespace (c) { - return c === ' ' || c === '\n' || c === '\r' || c === '\t' - } - - function isQuote (c) { - return c === '"' || c === '\'' - } - - function isAttribEnd (c) { - return c === '>' || isWhitespace(c) - } - - function isMatch (regex, c) { - return regex.test(c) - } - - function notMatch (regex, c) { - return !isMatch(regex, c) - } - - var S = 0 - sax.STATE = { - BEGIN: S++, // leading byte order mark or whitespace - BEGIN_WHITESPACE: S++, // leading whitespace - TEXT: S++, // general stuff - TEXT_ENTITY: S++, // & and such. - OPEN_WAKA: S++, // < - SGML_DECL: S++, // - SCRIPT: S++, //