@splunk/visualizations-shared 25.7.1 → 25.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Downloader.js +5 -60
- package/Downloader.js.map +1 -1
- package/FileDownloader.js +21 -95
- package/FileDownloader.js.map +1 -1
- package/JSONSchemaUtils.js +0 -5
- package/JSONSchemaUtils.js.map +1 -1
- package/Message.js +10 -21
- package/Message.js.map +1 -1
- package/RemoteIcon.js +33 -86
- package/RemoteIcon.js.map +1 -1
- package/RemoteImage.js +8 -44
- package/RemoteImage.js.map +1 -1
- package/SanitizeProps.js +14 -39
- package/SanitizeProps.js.map +1 -1
- package/SizeAwareWrapper.js +6 -34
- package/SizeAwareWrapper.js.map +1 -1
- package/VisualizationDocPage.js +18 -64
- package/VisualizationDocPage.js.map +1 -1
- package/colorConstants.js.map +1 -1
- package/colorUtils.js +14 -27
- package/colorUtils.js.map +1 -1
- package/configUtils.js +0 -2
- package/configUtils.js.map +1 -1
- package/console.js +0 -12
- package/console.js.map +1 -1
- package/dataSourceUtils.js +1 -10
- package/dataSourceUtils.js.map +1 -1
- package/domUtils.js.map +1 -1
- package/hocUtils.js +0 -14
- package/hocUtils.js.map +1 -1
- package/i18n.js +0 -2
- package/i18n.js.map +1 -1
- package/iconUtils.js +12 -11
- package/iconUtils.js.map +1 -1
- package/mapUtils.js +0 -4
- package/mapUtils.js.map +1 -1
- package/namedColors.js +2 -2
- package/namedColors.js.map +1 -1
- package/numberUtils.js +17 -27
- package/numberUtils.js.map +1 -1
- package/package.json +5 -5
- package/previewVizMessage.js.map +1 -1
- package/propUtils.js +5 -7
- package/propUtils.js.map +1 -1
- package/schemaUtils.js +10 -10
- package/schemaUtils.js.map +1 -1
- package/simpleXMLOptions.js +2 -2
- package/simpleXMLOptions.js.map +1 -1
- package/style.js +6 -11
- package/style.js.map +1 -1
- package/testHelper.js.map +1 -1
- package/themeUtils.js +7 -8
- package/themeUtils.js.map +1 -1
- package/trellisUtils.js +18 -62
- package/trellisUtils.js.map +1 -1
package/Downloader.js
CHANGED
|
@@ -113,20 +113,15 @@ module.exports = require("@babel/runtime/helpers/slicedToArray");
|
|
|
113
113
|
|
|
114
114
|
|
|
115
115
|
var _regeneratorRuntime = __webpack_require__(10);
|
|
116
|
-
|
|
117
116
|
var _slicedToArray = __webpack_require__(11);
|
|
118
|
-
|
|
119
117
|
var _classCallCheck = __webpack_require__(5);
|
|
120
|
-
|
|
121
118
|
var _createClass = __webpack_require__(6);
|
|
122
|
-
|
|
123
119
|
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
124
120
|
function adopt(value) {
|
|
125
121
|
return value instanceof P ? value : new P(function (resolve) {
|
|
126
122
|
resolve(value);
|
|
127
123
|
});
|
|
128
124
|
}
|
|
129
|
-
|
|
130
125
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
131
126
|
function fulfilled(value) {
|
|
132
127
|
try {
|
|
@@ -135,7 +130,6 @@ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, gene
|
|
|
135
130
|
reject(e);
|
|
136
131
|
}
|
|
137
132
|
}
|
|
138
|
-
|
|
139
133
|
function rejected(value) {
|
|
140
134
|
try {
|
|
141
135
|
step(generator["throw"](value));
|
|
@@ -143,79 +137,61 @@ var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, gene
|
|
|
143
137
|
reject(e);
|
|
144
138
|
}
|
|
145
139
|
}
|
|
146
|
-
|
|
147
140
|
function step(result) {
|
|
148
141
|
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
149
142
|
}
|
|
150
|
-
|
|
151
143
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
152
144
|
});
|
|
153
145
|
};
|
|
154
|
-
|
|
155
146
|
Object.defineProperty(exports, "__esModule", {
|
|
156
147
|
value: true
|
|
157
148
|
});
|
|
158
149
|
exports.URLDownloader = exports.ImageRegistryFetcher = exports.b64DecodeUnicode = void 0;
|
|
159
150
|
/* eslint-disable max-classes-per-file */
|
|
160
|
-
|
|
161
151
|
/* eslint-disable class-methods-use-this */
|
|
162
|
-
|
|
163
152
|
var i18n_1 = __webpack_require__(7);
|
|
164
|
-
|
|
165
153
|
var b64DecodeUnicode = function b64DecodeUnicode(base64Data) {
|
|
166
154
|
// from bytestream, to percent-encoding, to original string.
|
|
167
155
|
return decodeURIComponent(atob(base64Data).split('').map(function (c) {
|
|
168
156
|
return "%".concat("00".concat(c.charCodeAt(0).toString(16)).slice(-2));
|
|
169
157
|
}).join(''));
|
|
170
158
|
};
|
|
171
|
-
|
|
172
159
|
exports.b64DecodeUnicode = b64DecodeUnicode;
|
|
173
|
-
|
|
174
160
|
var ImageRegistryFetcher = /*#__PURE__*/function () {
|
|
175
161
|
function ImageRegistryFetcher(context) {
|
|
176
162
|
_classCallCheck(this, ImageRegistryFetcher);
|
|
177
|
-
|
|
178
163
|
this.context = context;
|
|
179
164
|
}
|
|
180
|
-
|
|
181
165
|
_createClass(ImageRegistryFetcher, [{
|
|
182
166
|
key: "downloadWithProgress",
|
|
183
167
|
value: function downloadWithProgress(url, complete, progress, error) {
|
|
184
168
|
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
185
169
|
var imageRegistry, imageData, _imageData$dataURI$sp, _imageData$dataURI$sp2, mime, svgBase64;
|
|
186
|
-
|
|
187
170
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
188
171
|
while (1) {
|
|
189
172
|
switch (_context.prev = _context.next) {
|
|
190
173
|
case 0:
|
|
191
174
|
imageRegistry = this.context;
|
|
192
|
-
|
|
193
175
|
if (!imageRegistry) {
|
|
194
176
|
error(i18n_1._('Missing Image Context'));
|
|
195
177
|
}
|
|
196
|
-
|
|
197
178
|
_context.prev = 2;
|
|
198
179
|
_context.next = 5;
|
|
199
180
|
return imageRegistry.getByURL(url);
|
|
200
|
-
|
|
201
181
|
case 5:
|
|
202
182
|
imageData = _context.sent;
|
|
203
183
|
_imageData$dataURI$sp = imageData.dataURI.split('base64,'), _imageData$dataURI$sp2 = _slicedToArray(_imageData$dataURI$sp, 2), mime = _imageData$dataURI$sp2[0], svgBase64 = _imageData$dataURI$sp2[1];
|
|
204
|
-
|
|
205
184
|
if (mime && mime.toLowerCase().indexOf('image/svg+xml') > -1) {
|
|
206
185
|
complete(exports.b64DecodeUnicode(svgBase64));
|
|
207
186
|
} else {
|
|
208
187
|
error(i18n_1._("Unsupported MIME type ".concat(mime, " for url ").concat(url)));
|
|
209
188
|
}
|
|
210
|
-
|
|
211
189
|
_context.next = 13;
|
|
212
190
|
break;
|
|
213
|
-
|
|
214
191
|
case 10:
|
|
215
192
|
_context.prev = 10;
|
|
216
193
|
_context.t0 = _context["catch"](2);
|
|
217
194
|
error(i18n_1._("Error retrieving ".concat(url, " from Image Registry, error was '").concat(_context.t0.message, "'")), _context.t0);
|
|
218
|
-
|
|
219
195
|
case 13:
|
|
220
196
|
case "end":
|
|
221
197
|
return _context.stop();
|
|
@@ -225,27 +201,21 @@ var ImageRegistryFetcher = /*#__PURE__*/function () {
|
|
|
225
201
|
}));
|
|
226
202
|
}
|
|
227
203
|
}]);
|
|
228
|
-
|
|
229
204
|
return ImageRegistryFetcher;
|
|
230
205
|
}();
|
|
231
|
-
|
|
232
206
|
exports.ImageRegistryFetcher = ImageRegistryFetcher;
|
|
233
|
-
|
|
234
207
|
var URLDownloader = /*#__PURE__*/function () {
|
|
235
208
|
function URLDownloader() {
|
|
236
209
|
_classCallCheck(this, URLDownloader);
|
|
237
210
|
}
|
|
238
|
-
|
|
239
211
|
_createClass(URLDownloader, [{
|
|
240
212
|
key: "downloadWithProgress",
|
|
241
213
|
value: function downloadWithProgress(url, complete, progress, error) {
|
|
242
214
|
var _this = this;
|
|
243
|
-
|
|
244
215
|
// Step 1: fetch content from URL, get reader
|
|
245
216
|
fetch(url).then(function (response) {
|
|
246
217
|
return __awaiter(_this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
247
218
|
var msg, reader, contentLength, bytesDownloaded, chunks, done, res, value, chunksAll, position, _i, _chunks, chunk, svg;
|
|
248
|
-
|
|
249
219
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
250
220
|
while (1) {
|
|
251
221
|
switch (_context2.prev = _context2.next) {
|
|
@@ -254,37 +224,27 @@ var URLDownloader = /*#__PURE__*/function () {
|
|
|
254
224
|
_context2.next = 5;
|
|
255
225
|
break;
|
|
256
226
|
}
|
|
257
|
-
|
|
258
227
|
msg = "Fetch not Ok for ".concat(url, ", status was '").concat(response.statusText, "'");
|
|
259
228
|
console.warn(msg);
|
|
260
229
|
error(msg);
|
|
261
230
|
return _context2.abrupt("return");
|
|
262
|
-
|
|
263
231
|
case 5:
|
|
264
232
|
reader = response.body.getReader(); // Step 2: get total length
|
|
265
|
-
|
|
266
233
|
contentLength = +response.headers.get('Content-Length'); // Step 3: read the data
|
|
267
|
-
|
|
268
234
|
bytesDownloaded = 0; // length at the moment
|
|
269
|
-
|
|
270
235
|
chunks = []; // array of received binary chunks (comprises the body)
|
|
271
|
-
|
|
272
236
|
done = false;
|
|
273
|
-
|
|
274
237
|
case 10:
|
|
275
238
|
if (done) {
|
|
276
239
|
_context2.next = 19;
|
|
277
240
|
break;
|
|
278
241
|
}
|
|
279
|
-
|
|
280
242
|
_context2.next = 13;
|
|
281
243
|
return reader.read();
|
|
282
|
-
|
|
283
244
|
case 13:
|
|
284
245
|
res = _context2.sent;
|
|
285
246
|
done = res.done;
|
|
286
247
|
value = res.value;
|
|
287
|
-
|
|
288
248
|
if (value) {
|
|
289
249
|
chunks.push(value);
|
|
290
250
|
bytesDownloaded += value.length;
|
|
@@ -295,30 +255,25 @@ var URLDownloader = /*#__PURE__*/function () {
|
|
|
295
255
|
message: "Received ".concat(bytesDownloaded, " bytes of ").concat(contentLength || 'unknown size')
|
|
296
256
|
});
|
|
297
257
|
}
|
|
298
|
-
|
|
299
258
|
_context2.next = 10;
|
|
300
259
|
break;
|
|
301
|
-
|
|
302
260
|
case 19:
|
|
303
261
|
// Step 4: concatenate chunks into single Uint8Array
|
|
304
262
|
chunksAll = new Uint8Array(bytesDownloaded);
|
|
305
263
|
position = 0; // eslint-disable-next-line no-restricted-syntax
|
|
306
|
-
|
|
307
264
|
for (_i = 0, _chunks = chunks; _i < _chunks.length; _i++) {
|
|
308
265
|
chunk = _chunks[_i];
|
|
309
266
|
chunksAll.set(chunk, position);
|
|
310
267
|
position += chunk.length;
|
|
311
268
|
}
|
|
312
|
-
|
|
313
269
|
progress({
|
|
314
270
|
bytesDownloaded: bytesDownloaded,
|
|
315
271
|
contentLength: contentLength,
|
|
316
272
|
message: 'decoding chunks'
|
|
317
|
-
});
|
|
318
|
-
|
|
273
|
+
});
|
|
274
|
+
// Step 5: decode into a string
|
|
319
275
|
svg = new TextDecoder('utf-8').decode(chunksAll);
|
|
320
276
|
complete(svg); // show the downloaded svg back to the caller via its completion callback
|
|
321
|
-
|
|
322
277
|
case 25:
|
|
323
278
|
case "end":
|
|
324
279
|
return _context2.stop();
|
|
@@ -332,20 +287,15 @@ var URLDownloader = /*#__PURE__*/function () {
|
|
|
332
287
|
});
|
|
333
288
|
}
|
|
334
289
|
}]);
|
|
335
|
-
|
|
336
290
|
return URLDownloader;
|
|
337
291
|
}();
|
|
338
|
-
|
|
339
292
|
exports.URLDownloader = URLDownloader;
|
|
340
|
-
|
|
341
293
|
var Downloader = /*#__PURE__*/function () {
|
|
342
294
|
function Downloader(downloaders) {
|
|
343
295
|
_classCallCheck(this, Downloader);
|
|
344
|
-
|
|
345
296
|
this.downloaders = {};
|
|
346
297
|
this.downloaders = downloaders;
|
|
347
298
|
}
|
|
348
|
-
|
|
349
299
|
_createClass(Downloader, [{
|
|
350
300
|
key: "downloadWithProgress",
|
|
351
301
|
value: function downloadWithProgress(url, complete, progress, error) {
|
|
@@ -357,20 +307,17 @@ var Downloader = /*#__PURE__*/function () {
|
|
|
357
307
|
// or otherwise return errors
|
|
358
308
|
var protocol = '';
|
|
359
309
|
var isUrl = true;
|
|
360
|
-
|
|
361
310
|
try {
|
|
362
311
|
protocol = new URL(url).protocol;
|
|
363
312
|
} catch (e) {
|
|
364
313
|
isUrl = false;
|
|
365
314
|
}
|
|
366
|
-
|
|
367
315
|
if (isUrl) {
|
|
368
316
|
try {
|
|
369
317
|
var _protocol$split = protocol.split(':'),
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
318
|
+
_protocol$split2 = _slicedToArray(_protocol$split, 1),
|
|
319
|
+
_protocol$split2$ = _protocol$split2[0],
|
|
320
|
+
type = _protocol$split2$ === void 0 ? '' : _protocol$split2$;
|
|
374
321
|
if (this.downloaders[type]) {
|
|
375
322
|
// data, http(s), local....
|
|
376
323
|
this.downloaders[type].downloadWithProgress(url, complete, progress, error);
|
|
@@ -388,10 +335,8 @@ var Downloader = /*#__PURE__*/function () {
|
|
|
388
335
|
}
|
|
389
336
|
}
|
|
390
337
|
}]);
|
|
391
|
-
|
|
392
338
|
return Downloader;
|
|
393
339
|
}();
|
|
394
|
-
|
|
395
340
|
exports.default = Downloader;
|
|
396
341
|
|
|
397
342
|
/***/ }),
|
package/Downloader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["webpack:///webpack/bootstrap","webpack:///external \"@babel/runtime/regenerator\"","webpack:///external \"@babel/runtime/helpers/slicedToArray\"","webpack:///./src/Downloader.ts","webpack:///external \"@babel/runtime/helpers/classCallCheck\"","webpack:///external \"@babel/runtime/helpers/createClass\"","webpack:///external \"@splunk/ui-utils/i18n\""],"names":[],"mappings":";;;;;;;QAAA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;;QAEA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;;;QAGA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA,0CAA0C,gCAAgC;QAC1E;QACA;;QAEA;QACA;QACA;QACA,wDA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GAAG,EAAf;AACA,UAAI,KAAK,GAAG,IAAZ;;AACA,UAAI;AACA,gBAAQ,GAAG,IAAI,GAAJ,CAAQ,GAAR,EAAa,QAAxB;AACH,OAFD,CAEE,OAAO,CAAP,EAAU;AACR,aAAK,GAAG,KAAR;AACH;;AAED,UAAI,KAAJ,EAAW;AACP,YAAI;AAAA,gCACoB,QAAQ,CAAC,KAAT,CAAe,GAAf,CADpB;AAAA;AAAA;AAAA,cACO,IADP,kCACc,EADd;;AAEA,cAAI,KAAK,WAAL,CAAiB,IAAjB,CAAJ,EAA4B;AACxB;AACA,iBAAK,WAAL,CAAiB,IAAjB,EAAuB,oBAAvB,CAA4C,GAA5C,EAAiD,QAAjD,EAA2D,QAA3D,EAAqE,KAArE;AACH,WAHD,MAGO;AACH;AACA,iBAAK,qCAA8B,IAA9B,iCAAyD,GAAzD,EAAL;AACH;AACJ,SATD,CASE,OAAO,CAAP,EAAU;AACR,eAAK,6CAAsC,CAAC,CAAC,OAAxC,EAAL;AACH;AACJ,OAbD,MAaO;AACH;AACA;AACA,gBAAQ,CAAC,GAAD,CAAR;AACH;AACJ;;;;;;AA9CL,6B;;;;;;;ACtIA,kE;;;;;;;ACAA,+D;;;;;;;ACAA,kD","file":"Downloader.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 26);\n","module.exports = require(\"@babel/runtime/regenerator\");","module.exports = require(\"@babel/runtime/helpers/slicedToArray\");","/* eslint-disable max-classes-per-file */\n/* eslint-disable class-methods-use-this */\nimport { _ } from '@splunk/ui-utils/i18n';\nimport ImageRegistry from '@splunk/visualization-context/ImageRegistry';\n\nexport interface DownloadProgress {\n bytesDownloaded: number;\n contentLength?: number;\n message: string;\n}\nexport interface IDownloader {\n downloadWithProgress(\n url: string,\n complete: (svg: string) => void,\n progress?: (p: DownloadProgress) => void,\n error?: (msg: string, error?: Error) => void\n ): void;\n}\n\nexport const b64DecodeUnicode = (base64Data: string): string => {\n // from bytestream, to percent-encoding, to original string.\n return decodeURIComponent(\n atob(base64Data)\n .split('')\n .map((c: string): string => {\n return `%${`00${c.charCodeAt(0).toString(16)}`.slice(-2)}`;\n })\n .join('')\n );\n};\n\nexport class ImageRegistryFetcher implements IDownloader {\n context: ImageRegistry;\n\n constructor(context?: ImageRegistry) {\n this.context = context;\n }\n\n async downloadWithProgress(\n url: string,\n complete: (svg: string) => void,\n progress?: (p: DownloadProgress) => void,\n error?: (msg: string, error?: Error) => void\n ): Promise<void> {\n const imageRegistry = this.context;\n if (!imageRegistry) {\n error(_('Missing Image Context'));\n }\n try {\n const imageData = await imageRegistry.getByURL(url);\n const [mime, svgBase64] = imageData.dataURI.split('base64,');\n if (mime && mime.toLowerCase().indexOf('image/svg+xml') > -1) {\n complete(b64DecodeUnicode(svgBase64));\n } else {\n error(_(`Unsupported MIME type ${mime} for url ${url}`));\n }\n } catch (e) {\n error(_(`Error retrieving ${url} from Image Registry, error was '${e.message}'`), e);\n }\n }\n}\n\nexport class URLDownloader implements IDownloader {\n downloadWithProgress(\n url: string,\n complete: (svg: string) => void,\n progress?: (p: DownloadProgress) => void,\n error?: (msg: string, error?: Error) => void\n ): void {\n // Step 1: fetch content from URL, get reader\n fetch(url)\n .then(\n async (response: Response): Promise<void> => {\n if (!response.ok) {\n const msg = `Fetch not Ok for ${url}, status was '${response.statusText}'`;\n console.warn(msg);\n error(msg);\n return;\n }\n const reader = response.body.getReader();\n\n // Step 2: get total length\n const contentLength = +response.headers.get('Content-Length');\n\n // Step 3: read the data\n let bytesDownloaded = 0; // length at the moment\n const chunks = []; // array of received binary chunks (comprises the body)\n let done = false;\n while (!done) {\n // eslint-disable-next-line no-await-in-loop\n const res = await reader.read();\n done = res.done;\n const { value } = res;\n if (value) {\n chunks.push(value);\n bytesDownloaded += value.length;\n progress({\n // call the progress callback...can enable the UI to show progress\n bytesDownloaded,\n contentLength,\n message: `Received ${bytesDownloaded} bytes of ${\n contentLength || 'unknown size'\n }`,\n });\n }\n }\n\n // Step 4: concatenate chunks into single Uint8Array\n const chunksAll = new Uint8Array(bytesDownloaded);\n let position = 0;\n // eslint-disable-next-line no-restricted-syntax\n for (const chunk of chunks) {\n chunksAll.set(chunk, position);\n position += chunk.length;\n }\n\n progress({\n bytesDownloaded,\n contentLength,\n message: 'decoding chunks',\n });\n\n // Step 5: decode into a string\n const svg = new TextDecoder('utf-8').decode(chunksAll);\n complete(svg); // show the downloaded svg back to the caller via its completion callback\n }\n )\n .catch((e: Error): void => {\n console.error(e.toString());\n error(`Fetch error for '${url}', error was '${e.toString()}'`, e); // call the supplied error handling function\n });\n }\n}\n\nexport default class Downloader {\n private downloaders = {};\n\n constructor(downloaders: { [protocol: string]: IDownloader }) {\n this.downloaders = downloaders;\n }\n\n downloadWithProgress(\n url: string,\n complete: (svg: string) => void,\n progress?: (p: DownloadProgress) => void,\n error?: (msg: string, error?: Error) => void\n ): void {\n // url is the following:\n // data:image/svg+xml;base64....\n // http://\n // https://\n // local://\n // or otherwise return errors\n\n let protocol = '';\n let isUrl = true;\n try {\n protocol = new URL(url).protocol;\n } catch (e) {\n isUrl = false;\n }\n\n if (isUrl) {\n try {\n const [type = ''] = protocol.split(':');\n if (this.downloaders[type]) {\n // data, http(s), local....\n this.downloaders[type].downloadWithProgress(url, complete, progress, error);\n } else {\n // unknown type\n error(`Unsupported URL protocol '${type}' for SVG download: ${url}`);\n }\n } catch (e) {\n error(`Unexpected error downloading SVG: ${e.message}`);\n }\n } else {\n // the url might be literal content. <svg>...</svg>. This is kindof a hack where if you pass the downloader something\n // that is literal content, it will just return the content. Makes the code flow cleaner in layers above.\n complete(url);\n }\n }\n}\n","module.exports = require(\"@babel/runtime/helpers/classCallCheck\");","module.exports = require(\"@babel/runtime/helpers/createClass\");","module.exports = require(\"@splunk/ui-utils/i18n\");"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"sources":["webpack:///webpack/bootstrap","webpack:///external \"@babel/runtime/regenerator\"","webpack:///external \"@babel/runtime/helpers/slicedToArray\"","webpack:///./src/Downloader.ts","webpack:///external \"@babel/runtime/helpers/classCallCheck\"","webpack:///external \"@babel/runtime/helpers/createClass\"","webpack:///external \"@splunk/ui-utils/i18n\""],"names":["i18n_1","require","b64DecodeUnicode","base64Data","decodeURIComponent","atob","split","map","c","concat","charCodeAt","toString","slice","join","exports","ImageRegistryFetcher","context","_classCallCheck","_createClass","key","value","downloadWithProgress","url","complete","progress","error","imageRegistry","_","_context","prev","next","getByURL","imageData","sent","_imageData$dataURI$sp","dataURI","_imageData$dataURI$sp2","_slicedToArray","mime","svgBase64","toLowerCase","indexOf","t0","message","stop","_callee","URLDownloader","_this","fetch","then","response","__awaiter","_regeneratorRuntime","mark","_callee2","msg","reader","contentLength","bytesDownloaded","chunks","done","res","chunksAll","position","_i","_chunks","chunk","svg","wrap","_callee2$","_context2","ok","statusText","console","warn","abrupt","body","getReader","headers","get","read","push","length","Uint8Array","set","TextDecoder","decode","catch","e","Downloader","downloaders","protocol","isUrl","URL","_protocol$split","_protocol$split2","_protocol$split2$","type","default"],"mappings":";;;;;;;QAAA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;QACA;;QAEA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;;;QAGA;QACA;;QAEA;QACA;;QAEA;QACA;QACA;QACA,0CAA0C,gCAAgC;QAC1E;QACA;;QAEA;QACA;QACA;QACA,wDAAwD,kBAAkB;QAC1E;QACA,iDAAiD,cAAc;QAC/D;;QAEA;QACA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CAA8BwF,IAAI,0BAAAxF,MAAA,CAAuBa,GAAG,EAAG;;SAE3E,CAAC,OAAOkE,CAAC,EAAE;UACR/D,KAAK,sCAAAhB,MAAA,CAAsC+E,CAAC,CAAC7C,OAAO,EAAG;;OAE9D,MAAM;QACH;QACA;QACApB,QAAQ,CAACD,GAAG,CAAC;;IAErB;EAAC;EAAA,OAAAmE,UAAA;AAAA;AA9CL3E,OAAA,CAAAoF,OAAA,GAAAT,UAAA,C;;;;;;;ACtIA,kE;;;;;;;ACAA,+D;;;;;;;ACAA,kD","file":"Downloader.js","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 26);\n","module.exports = require(\"@babel/runtime/regenerator\");","module.exports = require(\"@babel/runtime/helpers/slicedToArray\");","/* eslint-disable max-classes-per-file */\n/* eslint-disable class-methods-use-this */\nimport { _ } from '@splunk/ui-utils/i18n';\nimport ImageRegistry from '@splunk/visualization-context/ImageRegistry';\n\nexport interface DownloadProgress {\n bytesDownloaded: number;\n contentLength?: number;\n message: string;\n}\nexport interface IDownloader {\n downloadWithProgress(\n url: string,\n complete: (svg: string) => void,\n progress?: (p: DownloadProgress) => void,\n error?: (msg: string, error?: Error) => void\n ): void;\n}\n\nexport const b64DecodeUnicode = (base64Data: string): string => {\n // from bytestream, to percent-encoding, to original string.\n return decodeURIComponent(\n atob(base64Data)\n .split('')\n .map((c: string): string => {\n return `%${`00${c.charCodeAt(0).toString(16)}`.slice(-2)}`;\n })\n .join('')\n );\n};\n\nexport class ImageRegistryFetcher implements IDownloader {\n context: ImageRegistry;\n\n constructor(context?: ImageRegistry) {\n this.context = context;\n }\n\n async downloadWithProgress(\n url: string,\n complete: (svg: string) => void,\n progress?: (p: DownloadProgress) => void,\n error?: (msg: string, error?: Error) => void\n ): Promise<void> {\n const imageRegistry = this.context;\n if (!imageRegistry) {\n error(_('Missing Image Context'));\n }\n try {\n const imageData = await imageRegistry.getByURL(url);\n const [mime, svgBase64] = imageData.dataURI.split('base64,');\n if (mime && mime.toLowerCase().indexOf('image/svg+xml') > -1) {\n complete(b64DecodeUnicode(svgBase64));\n } else {\n error(_(`Unsupported MIME type ${mime} for url ${url}`));\n }\n } catch (e) {\n error(_(`Error retrieving ${url} from Image Registry, error was '${e.message}'`), e);\n }\n }\n}\n\nexport class URLDownloader implements IDownloader {\n downloadWithProgress(\n url: string,\n complete: (svg: string) => void,\n progress?: (p: DownloadProgress) => void,\n error?: (msg: string, error?: Error) => void\n ): void {\n // Step 1: fetch content from URL, get reader\n fetch(url)\n .then(\n async (response: Response): Promise<void> => {\n if (!response.ok) {\n const msg = `Fetch not Ok for ${url}, status was '${response.statusText}'`;\n console.warn(msg);\n error(msg);\n return;\n }\n const reader = response.body.getReader();\n\n // Step 2: get total length\n const contentLength = +response.headers.get('Content-Length');\n\n // Step 3: read the data\n let bytesDownloaded = 0; // length at the moment\n const chunks = []; // array of received binary chunks (comprises the body)\n let done = false;\n while (!done) {\n // eslint-disable-next-line no-await-in-loop\n const res = await reader.read();\n done = res.done;\n const { value } = res;\n if (value) {\n chunks.push(value);\n bytesDownloaded += value.length;\n progress({\n // call the progress callback...can enable the UI to show progress\n bytesDownloaded,\n contentLength,\n message: `Received ${bytesDownloaded} bytes of ${\n contentLength || 'unknown size'\n }`,\n });\n }\n }\n\n // Step 4: concatenate chunks into single Uint8Array\n const chunksAll = new Uint8Array(bytesDownloaded);\n let position = 0;\n // eslint-disable-next-line no-restricted-syntax\n for (const chunk of chunks) {\n chunksAll.set(chunk, position);\n position += chunk.length;\n }\n\n progress({\n bytesDownloaded,\n contentLength,\n message: 'decoding chunks',\n });\n\n // Step 5: decode into a string\n const svg = new TextDecoder('utf-8').decode(chunksAll);\n complete(svg); // show the downloaded svg back to the caller via its completion callback\n }\n )\n .catch((e: Error): void => {\n console.error(e.toString());\n error(`Fetch error for '${url}', error was '${e.toString()}'`, e); // call the supplied error handling function\n });\n }\n}\n\nexport default class Downloader {\n private downloaders = {};\n\n constructor(downloaders: { [protocol: string]: IDownloader }) {\n this.downloaders = downloaders;\n }\n\n downloadWithProgress(\n url: string,\n complete: (svg: string) => void,\n progress?: (p: DownloadProgress) => void,\n error?: (msg: string, error?: Error) => void\n ): void {\n // url is the following:\n // data:image/svg+xml;base64....\n // http://\n // https://\n // local://\n // or otherwise return errors\n\n let protocol = '';\n let isUrl = true;\n try {\n protocol = new URL(url).protocol;\n } catch (e) {\n isUrl = false;\n }\n\n if (isUrl) {\n try {\n const [type = ''] = protocol.split(':');\n if (this.downloaders[type]) {\n // data, http(s), local....\n this.downloaders[type].downloadWithProgress(url, complete, progress, error);\n } else {\n // unknown type\n error(`Unsupported URL protocol '${type}' for SVG download: ${url}`);\n }\n } catch (e) {\n error(`Unexpected error downloading SVG: ${e.message}`);\n }\n } else {\n // the url might be literal content. <svg>...</svg>. This is kindof a hack where if you pass the downloader something\n // that is literal content, it will just return the content. Makes the code flow cleaner in layers above.\n complete(url);\n }\n }\n}\n","module.exports = require(\"@babel/runtime/helpers/classCallCheck\");","module.exports = require(\"@babel/runtime/helpers/createClass\");","module.exports = require(\"@splunk/ui-utils/i18n\");"],"sourceRoot":""}
|