@splunk/visualizations-shared 26.4.0 → 27.0.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/.loki/reference/chrome_docker_SizeAwareWrapper_50_parent.png +0 -0
- package/.loki/reference/chrome_docker_SizeAwareWrapper_Fix_size_container.png +0 -0
- package/.loki/reference/chrome_docker_SizeAwareWrapper_Flex_layout_container.png +0 -0
- package/.loki/reference/chrome_docker_SizeAwareWrapper_Flex_layout_container_with_extra_wrapper.png +0 -0
- package/Downloader.js +164 -403
- package/Downloader.js.map +7 -1
- package/FileDownloader.js +121 -557
- package/FileDownloader.js.map +7 -1
- package/JSONSchemaUtils.js +58 -134
- package/JSONSchemaUtils.js.map +7 -1
- package/Message.js +105 -270
- package/Message.js.map +7 -1
- package/RemoteIcon.js +272 -736
- package/RemoteIcon.js.map +7 -1
- package/RemoteImage.js +190 -458
- package/RemoteImage.js.map +7 -1
- package/SanitizeProps.js +117 -238
- package/SanitizeProps.js.map +7 -1
- package/SizeAwareWrapper.js +108 -306
- package/SizeAwareWrapper.js.map +7 -1
- package/SizeAwareWrapperDeprecated.js +117 -326
- package/SizeAwareWrapperDeprecated.js.map +7 -1
- package/VisualizationDocPage.js +212 -461
- package/VisualizationDocPage.js.map +7 -1
- package/colorConstants.js +81 -132
- package/colorConstants.js.map +7 -1
- package/colorUtils.js +47 -134
- package/colorUtils.js.map +7 -1
- package/configUtils.js +28 -112
- package/configUtils.js.map +7 -1
- package/console.js +45 -183
- package/console.js.map +7 -1
- package/dataSourceUtils.js +45 -140
- package/dataSourceUtils.js.map +7 -1
- package/domUtils.js +58 -122
- package/domUtils.js.map +7 -1
- package/hocUtils.js +45 -122
- package/hocUtils.js.map +7 -1
- package/i18n.js +168 -323
- package/i18n.js.map +7 -1
- package/iconUtils.js +47 -178
- package/iconUtils.js.map +7 -1
- package/mapUtils.js +45 -122
- package/mapUtils.js.map +7 -1
- package/numberUtils.js +101 -275
- package/numberUtils.js.map +7 -1
- package/package.json +18 -22
- package/previewVizMessage.js +28 -108
- package/previewVizMessage.js.map +7 -1
- package/propUtils.js +88 -212
- package/propUtils.js.map +7 -1
- package/schemaUtils.js +58 -185
- package/schemaUtils.js.map +7 -1
- package/simpleXMLOptions.js +142 -225
- package/simpleXMLOptions.js.map +7 -1
- package/style.js +65 -168
- package/style.js.map +7 -1
- package/testHelper.js +247 -303
- package/testHelper.js.map +7 -1
- package/themeUtils.js +63 -142
- package/themeUtils.js.map +7 -1
- package/trellisUtils.js +108 -276
- package/trellisUtils.js.map +7 -1
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/.loki/reference/chrome_docker_SizeAwareWrapper_Flex_layout_container_with_extra_wrapper.png
CHANGED
|
Binary file
|
package/Downloader.js
CHANGED
|
@@ -1,430 +1,191 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
/******/ var module = installedModules[moduleId] = {
|
|
20
|
-
/******/ i: moduleId,
|
|
21
|
-
/******/ l: false,
|
|
22
|
-
/******/ exports: {}
|
|
23
|
-
/******/ };
|
|
24
|
-
/******/
|
|
25
|
-
/******/ // Execute the module function
|
|
26
|
-
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
|
27
|
-
/******/
|
|
28
|
-
/******/ // Flag the module as loaded
|
|
29
|
-
/******/ module.l = true;
|
|
30
|
-
/******/
|
|
31
|
-
/******/ // Return the exports of the module
|
|
32
|
-
/******/ return module.exports;
|
|
33
|
-
/******/ }
|
|
34
|
-
/******/
|
|
35
|
-
/******/
|
|
36
|
-
/******/ // expose the modules object (__webpack_modules__)
|
|
37
|
-
/******/ __webpack_require__.m = modules;
|
|
38
|
-
/******/
|
|
39
|
-
/******/ // expose the module cache
|
|
40
|
-
/******/ __webpack_require__.c = installedModules;
|
|
41
|
-
/******/
|
|
42
|
-
/******/ // define getter function for harmony exports
|
|
43
|
-
/******/ __webpack_require__.d = function(exports, name, getter) {
|
|
44
|
-
/******/ if(!__webpack_require__.o(exports, name)) {
|
|
45
|
-
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
|
|
46
|
-
/******/ }
|
|
47
|
-
/******/ };
|
|
48
|
-
/******/
|
|
49
|
-
/******/ // define __esModule on exports
|
|
50
|
-
/******/ __webpack_require__.r = function(exports) {
|
|
51
|
-
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
52
|
-
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
53
|
-
/******/ }
|
|
54
|
-
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
55
|
-
/******/ };
|
|
56
|
-
/******/
|
|
57
|
-
/******/ // create a fake namespace object
|
|
58
|
-
/******/ // mode & 1: value is a module id, require it
|
|
59
|
-
/******/ // mode & 2: merge all properties of value into the ns
|
|
60
|
-
/******/ // mode & 4: return value when already ns object
|
|
61
|
-
/******/ // mode & 8|1: behave like require
|
|
62
|
-
/******/ __webpack_require__.t = function(value, mode) {
|
|
63
|
-
/******/ if(mode & 1) value = __webpack_require__(value);
|
|
64
|
-
/******/ if(mode & 8) return value;
|
|
65
|
-
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
|
|
66
|
-
/******/ var ns = Object.create(null);
|
|
67
|
-
/******/ __webpack_require__.r(ns);
|
|
68
|
-
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
|
|
69
|
-
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
|
|
70
|
-
/******/ return ns;
|
|
71
|
-
/******/ };
|
|
72
|
-
/******/
|
|
73
|
-
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
74
|
-
/******/ __webpack_require__.n = function(module) {
|
|
75
|
-
/******/ var getter = module && module.__esModule ?
|
|
76
|
-
/******/ function getDefault() { return module['default']; } :
|
|
77
|
-
/******/ function getModuleExports() { return module; };
|
|
78
|
-
/******/ __webpack_require__.d(getter, 'a', getter);
|
|
79
|
-
/******/ return getter;
|
|
80
|
-
/******/ };
|
|
81
|
-
/******/
|
|
82
|
-
/******/ // Object.prototype.hasOwnProperty.call
|
|
83
|
-
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
|
84
|
-
/******/
|
|
85
|
-
/******/ // __webpack_public_path__
|
|
86
|
-
/******/ __webpack_require__.p = "";
|
|
87
|
-
/******/
|
|
88
|
-
/******/
|
|
89
|
-
/******/ // Load entry module and return exports
|
|
90
|
-
/******/ return __webpack_require__(__webpack_require__.s = 24);
|
|
91
|
-
/******/ })
|
|
92
|
-
/************************************************************************/
|
|
93
|
-
/******/ ({
|
|
94
|
-
|
|
95
|
-
/***/ 10:
|
|
96
|
-
/***/ (function(module, exports) {
|
|
97
|
-
|
|
98
|
-
module.exports = require("@babel/runtime/regenerator");
|
|
99
|
-
|
|
100
|
-
/***/ }),
|
|
101
|
-
|
|
102
|
-
/***/ 12:
|
|
103
|
-
/***/ (function(module, exports) {
|
|
104
|
-
|
|
105
|
-
module.exports = require("@babel/runtime/helpers/slicedToArray");
|
|
106
|
-
|
|
107
|
-
/***/ }),
|
|
108
|
-
|
|
109
|
-
/***/ 24:
|
|
110
|
-
/***/ (function(module, exports, __webpack_require__) {
|
|
111
|
-
|
|
112
|
-
"use strict";
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
var _regeneratorRuntime = __webpack_require__(10);
|
|
116
|
-
|
|
117
|
-
var _slicedToArray = __webpack_require__(12);
|
|
118
|
-
|
|
119
|
-
var _classCallCheck = __webpack_require__(5);
|
|
120
|
-
|
|
121
|
-
var _createClass = __webpack_require__(6);
|
|
122
|
-
|
|
123
|
-
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
124
|
-
function adopt(value) {
|
|
125
|
-
return value instanceof P ? value : new P(function (resolve) {
|
|
126
|
-
resolve(value);
|
|
127
|
-
});
|
|
1
|
+
/* Copyright © 2020 Splunk Inc.
|
|
2
|
+
SPLUNK CONFIDENTIAL – Use or disclosure of this material in whole or
|
|
3
|
+
in part without a valid written license from Splunk Inc. is PROHIBITED. */
|
|
4
|
+
var __create = Object.create;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __export = (target, all) => {
|
|
11
|
+
for (var name in all)
|
|
12
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
128
19
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
31
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
+
var __async = (__this, __arguments, generator) => {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
var fulfilled = (value) => {
|
|
132
35
|
try {
|
|
133
36
|
step(generator.next(value));
|
|
134
37
|
} catch (e) {
|
|
135
38
|
reject(e);
|
|
136
39
|
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function rejected(value) {
|
|
40
|
+
};
|
|
41
|
+
var rejected = (value) => {
|
|
140
42
|
try {
|
|
141
|
-
step(generator
|
|
43
|
+
step(generator.throw(value));
|
|
142
44
|
} catch (e) {
|
|
143
45
|
reject(e);
|
|
144
46
|
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
47
|
+
};
|
|
48
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
49
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
152
50
|
});
|
|
153
51
|
};
|
|
154
52
|
|
|
155
|
-
|
|
156
|
-
|
|
53
|
+
// src/Downloader.ts
|
|
54
|
+
var Downloader_exports = {};
|
|
55
|
+
__export(Downloader_exports, {
|
|
56
|
+
ImageRegistryFetcher: () => ImageRegistryFetcher,
|
|
57
|
+
URLDownloader: () => URLDownloader,
|
|
58
|
+
b64DecodeUnicode: () => b64DecodeUnicode,
|
|
59
|
+
default: () => Downloader
|
|
157
60
|
});
|
|
158
|
-
|
|
159
|
-
/* eslint-disable max-classes-per-file */
|
|
160
|
-
|
|
161
|
-
/* eslint-disable class-methods-use-this */
|
|
61
|
+
module.exports = __toCommonJS(Downloader_exports);
|
|
162
62
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
63
|
+
// esm-externals:@splunk/ui-utils/i18n
|
|
64
|
+
var i18n_exports = {};
|
|
65
|
+
__export(i18n_exports, {
|
|
66
|
+
default: () => i18n_default
|
|
67
|
+
});
|
|
68
|
+
var defaultImport = __toESM(require("@splunk/ui-utils/i18n"));
|
|
69
|
+
__reExport(i18n_exports, require("@splunk/ui-utils/i18n"));
|
|
70
|
+
var i18n_default = "default" in defaultImport ? defaultImport.default : defaultImport;
|
|
71
|
+
|
|
72
|
+
// src/Downloader.ts
|
|
73
|
+
var b64DecodeUnicode = (base64Data) => {
|
|
74
|
+
return decodeURIComponent(
|
|
75
|
+
atob(base64Data).split("").map((c) => {
|
|
76
|
+
return `%${`00${c.charCodeAt(0).toString(16)}`.slice(-2)}`;
|
|
77
|
+
}).join("")
|
|
78
|
+
);
|
|
170
79
|
};
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
var ImageRegistryFetcher = /*#__PURE__*/function () {
|
|
175
|
-
function ImageRegistryFetcher(context) {
|
|
176
|
-
_classCallCheck(this, ImageRegistryFetcher);
|
|
177
|
-
|
|
80
|
+
var ImageRegistryFetcher = class {
|
|
81
|
+
constructor(context) {
|
|
178
82
|
this.context = context;
|
|
179
83
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
imageRegistry = this.context;
|
|
192
|
-
|
|
193
|
-
if (!imageRegistry) {
|
|
194
|
-
error((0, i18n_1._)('Missing Image Context'));
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
_context.prev = 2;
|
|
198
|
-
_context.next = 5;
|
|
199
|
-
return imageRegistry.getByURL(url);
|
|
200
|
-
|
|
201
|
-
case 5:
|
|
202
|
-
imageData = _context.sent;
|
|
203
|
-
_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
|
-
if (mime && mime.toLowerCase().indexOf('image/svg+xml') > -1) {
|
|
206
|
-
complete((0, exports.b64DecodeUnicode)(svgBase64));
|
|
207
|
-
} else {
|
|
208
|
-
error((0, i18n_1._)("Unsupported MIME type ".concat(mime, " for url ").concat(url)));
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
_context.next = 13;
|
|
212
|
-
break;
|
|
213
|
-
|
|
214
|
-
case 10:
|
|
215
|
-
_context.prev = 10;
|
|
216
|
-
_context.t0 = _context["catch"](2);
|
|
217
|
-
error((0, i18n_1._)("Error retrieving ".concat(url, " from Image Registry, error was '").concat(_context.t0.message, "'")), _context.t0);
|
|
218
|
-
|
|
219
|
-
case 13:
|
|
220
|
-
case "end":
|
|
221
|
-
return _context.stop();
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
}, _callee, this, [[2, 10]]);
|
|
225
|
-
}));
|
|
226
|
-
}
|
|
227
|
-
}]);
|
|
228
|
-
|
|
229
|
-
return ImageRegistryFetcher;
|
|
230
|
-
}();
|
|
231
|
-
|
|
232
|
-
exports.ImageRegistryFetcher = ImageRegistryFetcher;
|
|
233
|
-
|
|
234
|
-
var URLDownloader = /*#__PURE__*/function () {
|
|
235
|
-
function URLDownloader() {
|
|
236
|
-
_classCallCheck(this, URLDownloader);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
_createClass(URLDownloader, [{
|
|
240
|
-
key: "downloadWithProgress",
|
|
241
|
-
value: function downloadWithProgress(url, complete, progress, error) {
|
|
242
|
-
var _this = this;
|
|
243
|
-
|
|
244
|
-
// Step 1: fetch content from URL, get reader
|
|
245
|
-
fetch(url).then(function (response) {
|
|
246
|
-
return __awaiter(_this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
247
|
-
var msg, reader, contentLength, bytesDownloaded, chunks, done, res, value, chunksAll, position, _i, _chunks, chunk, svg;
|
|
248
|
-
|
|
249
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
250
|
-
while (1) {
|
|
251
|
-
switch (_context2.prev = _context2.next) {
|
|
252
|
-
case 0:
|
|
253
|
-
if (response.ok) {
|
|
254
|
-
_context2.next = 5;
|
|
255
|
-
break;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
msg = "Fetch not Ok for ".concat(url, ", status was '").concat(response.statusText, "'");
|
|
259
|
-
console.warn(msg);
|
|
260
|
-
error(msg);
|
|
261
|
-
return _context2.abrupt("return");
|
|
262
|
-
|
|
263
|
-
case 5:
|
|
264
|
-
reader = response.body.getReader(); // Step 2: get total length
|
|
265
|
-
|
|
266
|
-
contentLength = +response.headers.get('Content-Length'); // Step 3: read the data
|
|
267
|
-
|
|
268
|
-
bytesDownloaded = 0; // length at the moment
|
|
269
|
-
|
|
270
|
-
chunks = []; // array of received binary chunks (comprises the body)
|
|
271
|
-
|
|
272
|
-
done = false;
|
|
273
|
-
|
|
274
|
-
case 10:
|
|
275
|
-
if (done) {
|
|
276
|
-
_context2.next = 19;
|
|
277
|
-
break;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
_context2.next = 13;
|
|
281
|
-
return reader.read();
|
|
282
|
-
|
|
283
|
-
case 13:
|
|
284
|
-
res = _context2.sent;
|
|
285
|
-
done = res.done;
|
|
286
|
-
value = res.value;
|
|
287
|
-
|
|
288
|
-
if (value) {
|
|
289
|
-
chunks.push(value);
|
|
290
|
-
bytesDownloaded += value.length;
|
|
291
|
-
progress({
|
|
292
|
-
// call the progress callback...can enable the UI to show progress
|
|
293
|
-
bytesDownloaded: bytesDownloaded,
|
|
294
|
-
contentLength: contentLength,
|
|
295
|
-
message: "Received ".concat(bytesDownloaded, " bytes of ").concat(contentLength || 'unknown size')
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
_context2.next = 10;
|
|
300
|
-
break;
|
|
301
|
-
|
|
302
|
-
case 19:
|
|
303
|
-
// Step 4: concatenate chunks into single Uint8Array
|
|
304
|
-
chunksAll = new Uint8Array(bytesDownloaded);
|
|
305
|
-
position = 0; // eslint-disable-next-line no-restricted-syntax
|
|
306
|
-
|
|
307
|
-
for (_i = 0, _chunks = chunks; _i < _chunks.length; _i++) {
|
|
308
|
-
chunk = _chunks[_i];
|
|
309
|
-
chunksAll.set(chunk, position);
|
|
310
|
-
position += chunk.length;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
progress({
|
|
314
|
-
bytesDownloaded: bytesDownloaded,
|
|
315
|
-
contentLength: contentLength,
|
|
316
|
-
message: 'decoding chunks'
|
|
317
|
-
}); // Step 5: decode into a string
|
|
318
|
-
|
|
319
|
-
svg = new TextDecoder('utf-8').decode(chunksAll);
|
|
320
|
-
complete(svg); // show the downloaded svg back to the caller via its completion callback
|
|
321
|
-
|
|
322
|
-
case 25:
|
|
323
|
-
case "end":
|
|
324
|
-
return _context2.stop();
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}, _callee2);
|
|
328
|
-
}));
|
|
329
|
-
}).catch(function (e) {
|
|
330
|
-
// Note: For CORS issue, fetch api call immediately fails without any status code or response and the error message says "Failed to fetch"
|
|
331
|
-
// but for other issues (invalid url, not found, etc), it returns with a certain status code (406, 404, etc)
|
|
332
|
-
// and empty response so further operation on the response data fails.
|
|
333
|
-
var stringifiedError = e.toString();
|
|
334
|
-
console.error(stringifiedError); // call the supplied error handling function
|
|
335
|
-
|
|
336
|
-
if (stringifiedError.includes('Failed to fetch')) {
|
|
337
|
-
error("Cannot fetch the image \"".concat(url, "\" due to a cross-origin resource sharing (CORS) policy"), e);
|
|
84
|
+
downloadWithProgress(url, complete, progress, error) {
|
|
85
|
+
return __async(this, null, function* () {
|
|
86
|
+
const imageRegistry = this.context;
|
|
87
|
+
if (!imageRegistry) {
|
|
88
|
+
error((0, i18n_exports._)("Missing Image Context"));
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
const imageData = yield imageRegistry.getByURL(url);
|
|
92
|
+
const [mime, svgBase64] = imageData.dataURI.split("base64,");
|
|
93
|
+
if (mime && mime.toLowerCase().indexOf("image/svg+xml") > -1) {
|
|
94
|
+
complete(b64DecodeUnicode(svgBase64));
|
|
338
95
|
} else {
|
|
339
|
-
error(
|
|
96
|
+
error((0, i18n_exports._)(`Unsupported MIME type ${mime} for url ${url}`));
|
|
340
97
|
}
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
}]);
|
|
344
|
-
|
|
345
|
-
return URLDownloader;
|
|
346
|
-
}();
|
|
347
|
-
|
|
348
|
-
exports.URLDownloader = URLDownloader;
|
|
349
|
-
|
|
350
|
-
var Downloader = /*#__PURE__*/function () {
|
|
351
|
-
function Downloader(downloaders) {
|
|
352
|
-
_classCallCheck(this, Downloader);
|
|
353
|
-
|
|
354
|
-
this.downloaders = {};
|
|
355
|
-
this.downloaders = downloaders;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
_createClass(Downloader, [{
|
|
359
|
-
key: "downloadWithProgress",
|
|
360
|
-
value: function downloadWithProgress(url, complete, progress, error) {
|
|
361
|
-
// url is the following:
|
|
362
|
-
// data:image/svg+xml;base64....
|
|
363
|
-
// http://
|
|
364
|
-
// https://
|
|
365
|
-
// local://
|
|
366
|
-
// or otherwise return errors
|
|
367
|
-
var protocol = '';
|
|
368
|
-
var isUrl = true;
|
|
369
|
-
|
|
370
|
-
try {
|
|
371
|
-
protocol = new URL(url).protocol;
|
|
372
98
|
} catch (e) {
|
|
373
|
-
|
|
99
|
+
error((0, i18n_exports._)(`Error retrieving ${url} from Image Registry, error was '${e.message}'`), e);
|
|
374
100
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
var URLDownloader = class {
|
|
105
|
+
downloadWithProgress(url, complete, progress, error) {
|
|
106
|
+
fetch(url).then(
|
|
107
|
+
(response) => __async(this, null, function* () {
|
|
108
|
+
if (!response.ok) {
|
|
109
|
+
const msg = `Fetch not Ok for ${url}, status was '${response.statusText}'`;
|
|
110
|
+
console.warn(msg);
|
|
111
|
+
error(msg);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const reader = response.body.getReader();
|
|
115
|
+
const contentLength = +response.headers.get("Content-Length");
|
|
116
|
+
let bytesDownloaded = 0;
|
|
117
|
+
const chunks = [];
|
|
118
|
+
let done = false;
|
|
119
|
+
while (!done) {
|
|
120
|
+
const res = yield reader.read();
|
|
121
|
+
done = res.done;
|
|
122
|
+
const { value } = res;
|
|
123
|
+
if (value) {
|
|
124
|
+
chunks.push(value);
|
|
125
|
+
bytesDownloaded += value.length;
|
|
126
|
+
progress({
|
|
127
|
+
// call the progress callback...can enable the UI to show progress
|
|
128
|
+
bytesDownloaded,
|
|
129
|
+
contentLength,
|
|
130
|
+
message: `Received ${bytesDownloaded} bytes of ${contentLength || "unknown size"}`
|
|
131
|
+
});
|
|
389
132
|
}
|
|
390
|
-
} catch (e) {
|
|
391
|
-
error("Unexpected error downloading SVG: ".concat(e.message));
|
|
392
133
|
}
|
|
134
|
+
const chunksAll = new Uint8Array(bytesDownloaded);
|
|
135
|
+
let position = 0;
|
|
136
|
+
for (const chunk of chunks) {
|
|
137
|
+
chunksAll.set(chunk, position);
|
|
138
|
+
position += chunk.length;
|
|
139
|
+
}
|
|
140
|
+
progress({
|
|
141
|
+
bytesDownloaded,
|
|
142
|
+
contentLength,
|
|
143
|
+
message: "decoding chunks"
|
|
144
|
+
});
|
|
145
|
+
const svg = new TextDecoder("utf-8").decode(chunksAll);
|
|
146
|
+
complete(svg);
|
|
147
|
+
})
|
|
148
|
+
).catch((e) => {
|
|
149
|
+
const stringifiedError = e.toString();
|
|
150
|
+
console.error(stringifiedError);
|
|
151
|
+
if (stringifiedError.includes("Failed to fetch")) {
|
|
152
|
+
error(
|
|
153
|
+
`Cannot fetch the image "${url}" due to a cross-origin resource sharing (CORS) policy`,
|
|
154
|
+
e
|
|
155
|
+
);
|
|
393
156
|
} else {
|
|
394
|
-
|
|
395
|
-
// that is literal content, it will just return the content. Makes the code flow cleaner in layers above.
|
|
396
|
-
complete(url);
|
|
157
|
+
error(`Fetch error for '${url}', error was '${e.toString()}'`, e);
|
|
397
158
|
}
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
var Downloader = class {
|
|
163
|
+
constructor(downloaders) {
|
|
164
|
+
this.downloaders = {};
|
|
165
|
+
this.downloaders = downloaders;
|
|
166
|
+
}
|
|
167
|
+
downloadWithProgress(url, complete, progress, error) {
|
|
168
|
+
let protocol = "";
|
|
169
|
+
let isUrl = true;
|
|
170
|
+
try {
|
|
171
|
+
protocol = new URL(url).protocol;
|
|
172
|
+
} catch (e) {
|
|
173
|
+
isUrl = false;
|
|
398
174
|
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
/***/ (function(module, exports) {
|
|
417
|
-
|
|
418
|
-
module.exports = require("@babel/runtime/helpers/createClass");
|
|
419
|
-
|
|
420
|
-
/***/ }),
|
|
421
|
-
|
|
422
|
-
/***/ 9:
|
|
423
|
-
/***/ (function(module, exports) {
|
|
424
|
-
|
|
425
|
-
module.exports = require("@splunk/ui-utils/i18n");
|
|
426
|
-
|
|
427
|
-
/***/ })
|
|
428
|
-
|
|
429
|
-
/******/ });
|
|
430
|
-
//# sourceMappingURL=Downloader.js.map
|
|
175
|
+
if (isUrl) {
|
|
176
|
+
try {
|
|
177
|
+
const [type = ""] = protocol.split(":");
|
|
178
|
+
if (this.downloaders[type]) {
|
|
179
|
+
this.downloaders[type].downloadWithProgress(url, complete, progress, error);
|
|
180
|
+
} else {
|
|
181
|
+
error(`Unsupported URL protocol '${type}' for SVG download: ${url}`);
|
|
182
|
+
}
|
|
183
|
+
} catch (e) {
|
|
184
|
+
error(`Unexpected error downloading SVG: ${e.message}`);
|
|
185
|
+
}
|
|
186
|
+
} else {
|
|
187
|
+
complete(url);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
//# sourceMappingURL=Downloader.js.map
|