@jbrowse/core 1.7.11 → 2.1.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.
Files changed (204) hide show
  1. package/BaseFeatureWidget/BaseFeatureDetail.d.ts +20 -4
  2. package/BaseFeatureWidget/BaseFeatureDetail.js +313 -558
  3. package/BaseFeatureWidget/SequenceFeatureDetails.js +213 -473
  4. package/BaseFeatureWidget/index.d.ts +2 -2
  5. package/BaseFeatureWidget/index.js +88 -124
  6. package/BaseFeatureWidget/types.d.ts +1 -0
  7. package/BaseFeatureWidget/types.js +1 -4
  8. package/BaseFeatureWidget/util.js +40 -75
  9. package/CorePlugin.js +55 -94
  10. package/Plugin.js +9 -34
  11. package/PluginLoader.js +153 -422
  12. package/PluginManager.d.ts +84 -117
  13. package/PluginManager.js +377 -666
  14. package/ReExports/Attributes.d.ts +2 -0
  15. package/ReExports/Attributes.js +5 -0
  16. package/ReExports/BaseCard.d.ts +2 -0
  17. package/ReExports/BaseCard.js +5 -0
  18. package/ReExports/DataGrid.d.ts +2 -0
  19. package/ReExports/DataGrid.js +6 -0
  20. package/ReExports/FeatureDetails.d.ts +2 -0
  21. package/ReExports/FeatureDetails.js +5 -0
  22. package/ReExports/index.js +6 -12
  23. package/ReExports/list.d.ts +5 -0
  24. package/ReExports/list.js +271 -7
  25. package/ReExports/material-ui-colors.d.ts +1 -19
  26. package/ReExports/material-ui-colors.js +16 -158
  27. package/ReExports/modules.d.ts +68 -109
  28. package/ReExports/modules.js +455 -244
  29. package/TextSearch/BaseResults.js +51 -123
  30. package/TextSearch/TextSearchManager.d.ts +3 -1
  31. package/TextSearch/TextSearchManager.js +66 -144
  32. package/assemblyManager/assembly.js +280 -554
  33. package/assemblyManager/assemblyConfigSchema.js +47 -64
  34. package/assemblyManager/assemblyManager.d.ts +12 -10
  35. package/assemblyManager/assemblyManager.js +126 -270
  36. package/assemblyManager/index.js +9 -22
  37. package/configuration/configurationSchema.js +167 -203
  38. package/configuration/configurationSlot.js +248 -326
  39. package/configuration/index.js +19 -35
  40. package/configuration/util.d.ts +1 -1
  41. package/configuration/util.js +131 -173
  42. package/data_adapters/BaseAdapter.d.ts +2 -2
  43. package/data_adapters/BaseAdapter.js +132 -521
  44. package/data_adapters/CytobandAdapter.js +40 -126
  45. package/data_adapters/dataAdapterCache.js +77 -158
  46. package/package.json +16 -18
  47. package/pluggableElementTypes/AdapterType.js +24 -79
  48. package/pluggableElementTypes/AddTrackWorkflowType.d.ts +17 -0
  49. package/pluggableElementTypes/AddTrackWorkflowType.js +20 -0
  50. package/pluggableElementTypes/ConnectionType.js +22 -65
  51. package/pluggableElementTypes/DisplayType.js +35 -82
  52. package/pluggableElementTypes/InternetAccountType.js +23 -64
  53. package/pluggableElementTypes/PluggableElementBase.js +8 -20
  54. package/pluggableElementTypes/RpcMethodType.js +85 -427
  55. package/pluggableElementTypes/TextSearchAdapterType.js +16 -55
  56. package/pluggableElementTypes/TrackType.js +26 -70
  57. package/pluggableElementTypes/ViewType.js +21 -63
  58. package/pluggableElementTypes/WidgetType.js +21 -64
  59. package/pluggableElementTypes/index.d.ts +4 -3
  60. package/pluggableElementTypes/index.js +42 -125
  61. package/pluggableElementTypes/models/BaseConnectionModelFactory.js +28 -43
  62. package/pluggableElementTypes/models/BaseDisplayModel.d.ts +10 -10
  63. package/pluggableElementTypes/models/BaseDisplayModel.js +58 -95
  64. package/pluggableElementTypes/models/BaseTrackModel.d.ts +1 -1
  65. package/pluggableElementTypes/models/BaseTrackModel.js +139 -200
  66. package/pluggableElementTypes/models/BaseViewModel.js +24 -40
  67. package/pluggableElementTypes/models/InternetAccountModel.js +116 -263
  68. package/pluggableElementTypes/models/baseConnectionConfig.js +14 -25
  69. package/pluggableElementTypes/models/baseInternetAccountConfig.js +29 -38
  70. package/pluggableElementTypes/models/baseTrackConfig.js +106 -133
  71. package/pluggableElementTypes/models/index.js +21 -70
  72. package/pluggableElementTypes/renderers/BoxRendererType.js +132 -291
  73. package/pluggableElementTypes/renderers/CircularChordRendererType.js +8 -38
  74. package/pluggableElementTypes/renderers/ComparativeServerSideRendererType.js +60 -192
  75. package/pluggableElementTypes/renderers/FeatureRendererType.d.ts +0 -2
  76. package/pluggableElementTypes/renderers/FeatureRendererType.js +89 -255
  77. package/pluggableElementTypes/renderers/RendererType.js +31 -105
  78. package/pluggableElementTypes/renderers/ServerSideRenderedContent.js +61 -72
  79. package/pluggableElementTypes/renderers/ServerSideRendererType.d.ts +2 -2
  80. package/pluggableElementTypes/renderers/ServerSideRendererType.js +112 -265
  81. package/pluggableElementTypes/renderers/index.js +19 -62
  82. package/pluggableElementTypes/renderers/util/serializableFilterChain.js +27 -65
  83. package/rpc/BaseRpcDriver.js +169 -405
  84. package/rpc/MainThreadRpcDriver.js +27 -150
  85. package/rpc/RpcManager.js +58 -159
  86. package/rpc/WebWorkerRpcDriver.js +54 -171
  87. package/rpc/configSchema.js +25 -49
  88. package/rpc/coreRpcMethods.d.ts +1 -3
  89. package/rpc/coreRpcMethods.js +221 -959
  90. package/rpc/remoteAbortSignals.js +46 -70
  91. package/tsconfig.build.tsbuildinfo +1 -1
  92. package/ui/AboutDialog.js +107 -158
  93. package/ui/App.js +157 -261
  94. package/ui/AssemblySelector.d.ts +1 -1
  95. package/ui/AssemblySelector.js +59 -115
  96. package/ui/CascadingMenu.js +100 -199
  97. package/ui/ColorPicker.d.ts +16 -0
  98. package/ui/ColorPicker.js +97 -0
  99. package/ui/Drawer.js +28 -58
  100. package/ui/DrawerWidget.js +109 -209
  101. package/ui/DropDownMenu.d.ts +0 -8
  102. package/ui/DropDownMenu.js +60 -97
  103. package/ui/EditableTypography.d.ts +1 -1
  104. package/ui/EditableTypography.js +87 -155
  105. package/ui/ErrorMessage.js +41 -66
  106. package/ui/FactoryResetDialog.js +24 -57
  107. package/ui/FatalErrorDialog.js +59 -91
  108. package/ui/FileSelector/FileSelector.js +123 -189
  109. package/ui/FileSelector/LocalFileChooser.js +44 -71
  110. package/ui/FileSelector/UrlChooser.js +17 -38
  111. package/ui/FileSelector/index.js +6 -12
  112. package/ui/Icons.d.ts +1 -1
  113. package/ui/Icons.js +45 -69
  114. package/ui/Logo.js +57 -110
  115. package/ui/Menu.d.ts +1 -1
  116. package/ui/Menu.js +232 -355
  117. package/ui/PrerenderedCanvas.js +63 -78
  118. package/ui/ResizeHandle.js +87 -114
  119. package/ui/ReturnToImportFormDialog.js +32 -59
  120. package/ui/SanitizedHTML.js +63 -52
  121. package/ui/Snackbar.js +74 -99
  122. package/ui/SnackbarModel.js +37 -51
  123. package/ui/Tooltip.d.ts +3 -1
  124. package/ui/Tooltip.js +49 -74
  125. package/ui/ViewContainer.js +113 -183
  126. package/ui/colors.d.ts +10 -0
  127. package/ui/colors.js +78 -0
  128. package/ui/index.js +51 -181
  129. package/ui/react-colorful.d.ts +17 -0
  130. package/ui/react-colorful.js +455 -0
  131. package/ui/theme.d.ts +279 -131
  132. package/ui/theme.js +197 -225
  133. package/util/Base1DUtils.d.ts +32 -0
  134. package/util/Base1DUtils.js +174 -0
  135. package/util/Base1DViewModel.d.ts +16 -37
  136. package/util/Base1DViewModel.js +116 -295
  137. package/util/QuickLRU.js +84 -332
  138. package/util/TimeTraveller.d.ts +19 -0
  139. package/util/TimeTraveller.js +86 -0
  140. package/util/aborting.js +49 -127
  141. package/util/analytics.js +91 -154
  142. package/util/blockTypes.js +106 -240
  143. package/util/calculateDynamicBlocks.js +98 -128
  144. package/util/calculateStaticBlocks.js +105 -125
  145. package/util/color/cssColorsLevel4.js +156 -160
  146. package/util/color/index.js +33 -55
  147. package/util/compositeMap.js +49 -333
  148. package/util/formatFastaStrings.js +9 -14
  149. package/util/idMaker.js +18 -31
  150. package/util/index.d.ts +18 -39
  151. package/util/index.js +743 -1236
  152. package/util/io/RemoteFileWithRangeCache.js +88 -257
  153. package/util/io/index.js +95 -169
  154. package/util/jexl.js +60 -115
  155. package/util/jexlStrings.js +24 -29
  156. package/util/layouts/BaseLayout.js +1 -4
  157. package/util/layouts/GranularRectLayout.js +388 -557
  158. package/util/layouts/MultiLayout.js +41 -109
  159. package/util/layouts/PrecomputedLayout.js +56 -114
  160. package/util/layouts/PrecomputedMultiLayout.js +22 -59
  161. package/util/layouts/SceneGraph.js +127 -197
  162. package/util/layouts/index.js +29 -66
  163. package/util/mst-reflection.js +55 -71
  164. package/util/offscreenCanvasPonyfill.js +66 -134
  165. package/util/offscreenCanvasUtils.d.ts +2 -7
  166. package/util/offscreenCanvasUtils.js +49 -146
  167. package/util/range.js +29 -40
  168. package/util/rxjs.js +20 -27
  169. package/util/simpleFeature.js +88 -152
  170. package/util/stats.js +91 -151
  171. package/util/tracks.js +130 -171
  172. package/util/types/index.d.ts +3 -3
  173. package/util/types/index.js +110 -179
  174. package/util/types/mst.d.ts +3 -3
  175. package/util/types/mst.js +91 -142
  176. package/util/types/util.js +1 -4
  177. package/util/when.js +54 -101
  178. package/BaseFeatureWidget/SequenceFeatureDetails.test.js +0 -122
  179. package/BaseFeatureWidget/index.test.js +0 -51
  180. package/TextSearch/BaseResults.test.js +0 -42
  181. package/configuration/configurationSchema.test.js +0 -266
  182. package/configuration/configurationSlot.test.js +0 -69
  183. package/configuration/util.test.js +0 -39
  184. package/data_adapters/BaseAdapter.test.js +0 -200
  185. package/declare.d.js +0 -1
  186. package/pluggableElementTypes/RpcMethodType.test.js +0 -118
  187. package/pluggableElementTypes/renderers/declare.d.js +0 -1
  188. package/pluggableElementTypes/renderers/util/serializableFilterChain.test.js +0 -20
  189. package/rpc/BaseRpcDriver.test.js +0 -540
  190. package/rpc/declaration.d.js +0 -1
  191. package/ui/FatalErrorDialog.test.js +0 -82
  192. package/ui/SanitizedHTML.test.js +0 -36
  193. package/ui/theme.test.js +0 -111
  194. package/util/Base1DViewModel.test.js +0 -130
  195. package/util/calculateDynamicBlocks.test.js +0 -74
  196. package/util/calculateStaticBlocks.test.js +0 -297
  197. package/util/declare.d.js +0 -1
  198. package/util/formatFastaStrings.test.js +0 -40
  199. package/util/index.test.js +0 -213
  200. package/util/jexlStrings.test.js +0 -48
  201. package/util/layouts/GranularRectLayout.test.js +0 -99
  202. package/util/range.test.js +0 -64
  203. package/util/simpleFeature.test.js +0 -34
  204. package/util/stats.test.js +0 -172
package/PluginLoader.js CHANGED
@@ -1,438 +1,169 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.isCJSPluginDefinition = exports.isESMPluginDefinition = exports.isUMDPluginDefinition = exports.PluginSourceConfigurationSchema = void 0;
7
+ const load_script2_1 = __importDefault(require("load-script2"));
8
+ const configuration_1 = require("./configuration");
9
+ const ReExports_1 = __importDefault(require("./ReExports"));
10
+ const util_1 = require("./util");
11
+ exports.PluginSourceConfigurationSchema = (0, configuration_1.ConfigurationSchema)('PluginSource', {
12
+ name: {
13
+ type: 'string',
14
+ defaultValue: '',
15
+ },
16
+ url: {
17
+ type: 'string',
18
+ defaultValue: '',
19
+ },
7
20
  });
8
- exports.default = exports.PluginSourceConfigurationSchema = void 0;
9
- exports.isCJSPluginDefinition = isCJSPluginDefinition;
10
- exports.isESMPluginDefinition = isESMPluginDefinition;
11
- exports.isUMDPluginDefinition = isUMDPluginDefinition;
12
-
13
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
14
-
15
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
16
-
17
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
18
-
19
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
20
-
21
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
22
-
23
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
24
-
25
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
26
-
27
- var _loadScript = _interopRequireDefault(require("load-script2"));
28
-
29
- var _configuration = require("./configuration");
30
-
31
- var _ReExports = _interopRequireDefault(require("./ReExports"));
32
-
33
- var _util = require("./util");
34
-
35
- var PluginSourceConfigurationSchema = (0, _configuration.ConfigurationSchema)('PluginSource', {
36
- name: {
37
- type: 'string',
38
- defaultValue: ''
39
- },
40
- url: {
41
- type: 'string',
42
- defaultValue: ''
43
- }
44
- });
45
- exports.PluginSourceConfigurationSchema = PluginSourceConfigurationSchema;
46
-
47
21
  function isUMDPluginDefinition(pluginDefinition) {
48
- return (pluginDefinition.umdUrl !== undefined || pluginDefinition.url !== undefined) && pluginDefinition.name !== undefined;
22
+ return ((pluginDefinition.umdUrl !== undefined ||
23
+ pluginDefinition.url !== undefined) &&
24
+ pluginDefinition
25
+ .name !== undefined);
49
26
  }
50
-
27
+ exports.isUMDPluginDefinition = isUMDPluginDefinition;
51
28
  function isESMPluginDefinition(pluginDefinition) {
52
- return pluginDefinition.esmUrl !== undefined;
29
+ return pluginDefinition.esmUrl !== undefined;
53
30
  }
54
-
31
+ exports.isESMPluginDefinition = isESMPluginDefinition;
55
32
  function isCJSPluginDefinition(pluginDefinition) {
56
- return pluginDefinition.cjsUrl !== undefined;
33
+ return pluginDefinition.cjsUrl !== undefined;
57
34
  }
58
-
35
+ exports.isCJSPluginDefinition = isCJSPluginDefinition;
59
36
  function getGlobalObject() {
60
- // Based on window-or-global
61
- // https://github.com/purposeindustries/window-or-global/blob/322abc71de0010c9e5d9d0729df40959e1ef8775/lib/index.js
62
- return (// eslint-disable-next-line no-restricted-globals
63
- (typeof self === "undefined" ? "undefined" : (0, _typeof2.default)(self)) === 'object' && self.self === self && self || (typeof global === "undefined" ? "undefined" : (0, _typeof2.default)(global)) === 'object' && global.global === global && global || // @ts-ignore
64
- this
65
- );
37
+ // Based on window-or-global
38
+ // https://github.com/purposeindustries/window-or-global/blob/322abc71de0010c9e5d9d0729df40959e1ef8775/lib/index.js
39
+ return (
40
+ // eslint-disable-next-line no-restricted-globals
41
+ (typeof self === 'object' && self.self === self && self) ||
42
+ (typeof global === 'object' && global.global === global && global) ||
43
+ // @ts-ignore
44
+ this);
66
45
  }
67
-
68
46
  function isInWebWorker(globalObject) {
69
- return Boolean('WorkerGlobalScope' in globalObject);
47
+ return Boolean('WorkerGlobalScope' in globalObject);
70
48
  }
71
-
72
- var PluginLoader = /*#__PURE__*/function () {
73
- function PluginLoader() {
74
- var pluginDefinitions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
75
- var args = arguments.length > 1 ? arguments[1] : undefined;
76
- (0, _classCallCheck2.default)(this, PluginLoader);
77
- (0, _defineProperty2.default)(this, "definitions", []);
78
- (0, _defineProperty2.default)(this, "fetchESM", void 0);
79
- (0, _defineProperty2.default)(this, "fetchCJS", void 0);
80
- this.fetchESM = args === null || args === void 0 ? void 0 : args.fetchESM;
81
- this.fetchCJS = args === null || args === void 0 ? void 0 : args.fetchCJS;
82
- this.definitions = JSON.parse(JSON.stringify(pluginDefinitions));
83
- }
84
-
85
- (0, _createClass2.default)(PluginLoader, [{
86
- key: "loadScript",
87
- value: function loadScript(scriptUrl) {
88
- var globalObject = getGlobalObject();
89
-
90
- if (!isInWebWorker(globalObject)) {
91
- return (0, _loadScript.default)(scriptUrl);
92
- } // @ts-ignore
93
-
94
-
95
- if (globalObject && globalObject.importScripts) {
96
- return new Promise(function (resolve, reject) {
97
- try {
98
- // @ts-ignore
99
- globalObject.importScripts(scriptUrl);
100
- } catch (error) {
101
- reject(error || new Error("failed to load ".concat(scriptUrl)));
102
- return;
103
- }
104
-
105
- resolve();
106
- });
107
- }
108
-
109
- throw new Error('cannot figure out how to load external JS scripts in this environment');
49
+ class PluginLoader {
50
+ constructor(pluginDefinitions = [], args) {
51
+ this.definitions = [];
52
+ this.fetchESM = args === null || args === void 0 ? void 0 : args.fetchESM;
53
+ this.fetchCJS = args === null || args === void 0 ? void 0 : args.fetchCJS;
54
+ this.definitions = JSON.parse(JSON.stringify(pluginDefinitions));
110
55
  }
111
- }, {
112
- key: "loadCJSPlugin",
113
- value: function () {
114
- var _loadCJSPlugin = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_ref) {
115
- var cjsUrl, parsedUrl;
116
- return _regenerator.default.wrap(function _callee$(_context) {
117
- while (1) {
118
- switch (_context.prev = _context.next) {
119
- case 0:
120
- cjsUrl = _ref.cjsUrl;
121
- _context.prev = 1;
122
- parsedUrl = new URL(cjsUrl, getGlobalObject().location.href);
123
- _context.next = 9;
124
- break;
125
-
126
- case 5:
127
- _context.prev = 5;
128
- _context.t0 = _context["catch"](1);
129
- console.error(_context.t0);
130
- throw new Error("Error parsing URL: ".concat(cjsUrl));
131
-
132
- case 9:
133
- if (!(parsedUrl.protocol !== 'http:' && parsedUrl.protocol !== 'https:')) {
134
- _context.next = 11;
135
- break;
136
- }
137
-
138
- throw new Error("Cannot load plugins using protocol \"".concat(parsedUrl.protocol, "\""));
139
-
140
- case 11:
141
- if (this.fetchCJS) {
142
- _context.next = 13;
143
- break;
144
- }
145
-
146
- throw new Error('No fetchCJS callback provided');
147
-
148
- case 13:
149
- return _context.abrupt("return", this.fetchCJS(parsedUrl.href));
150
-
151
- case 14:
152
- case "end":
153
- return _context.stop();
154
- }
155
- }
156
- }, _callee, this, [[1, 5]]);
157
- }));
158
-
159
- function loadCJSPlugin(_x) {
160
- return _loadCJSPlugin.apply(this, arguments);
161
- }
162
-
163
- return loadCJSPlugin;
164
- }()
165
- }, {
166
- key: "loadESMPlugin",
167
- value: function () {
168
- var _loadESMPlugin = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(pluginDefinition) {
169
- var _this$fetchESM;
170
-
171
- var parsedUrl, plugin;
172
- return _regenerator.default.wrap(function _callee2$(_context2) {
173
- while (1) {
174
- switch (_context2.prev = _context2.next) {
175
- case 0:
176
- _context2.prev = 0;
177
- parsedUrl = new URL(pluginDefinition.esmUrl, getGlobalObject().location.href);
178
- _context2.next = 8;
179
- break;
180
-
181
- case 4:
182
- _context2.prev = 4;
183
- _context2.t0 = _context2["catch"](0);
184
- console.error(_context2.t0);
185
- throw new Error("Error parsing URL: ".concat(pluginDefinition.esmUrl));
186
-
187
- case 8:
188
- if (!(parsedUrl.protocol !== 'http:' && parsedUrl.protocol !== 'https:')) {
189
- _context2.next = 10;
190
- break;
191
- }
192
-
193
- throw new Error("cannot load plugins using protocol \"".concat(parsedUrl.protocol, "\""));
194
-
195
- case 10:
196
- _context2.next = 12;
197
- return (_this$fetchESM = this.fetchESM) === null || _this$fetchESM === void 0 ? void 0 : _this$fetchESM.call(this, parsedUrl.href);
198
-
199
- case 12:
200
- plugin = _context2.sent;
201
-
202
- if (plugin) {
203
- _context2.next = 15;
204
- break;
205
- }
206
-
207
- throw new Error("Could not load ESM plugin: ".concat(parsedUrl));
208
-
209
- case 15:
210
- return _context2.abrupt("return", plugin);
211
-
212
- case 16:
213
- case "end":
214
- return _context2.stop();
215
- }
216
- }
217
- }, _callee2, this, [[0, 4]]);
218
- }));
219
-
220
- function loadESMPlugin(_x2) {
221
- return _loadESMPlugin.apply(this, arguments);
222
- }
223
-
224
- return loadESMPlugin;
225
- }()
226
- }, {
227
- key: "loadUMDPlugin",
228
- value: function () {
229
- var _loadUMDPlugin = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(pluginDefinition) {
230
- var umdUrl, parsedUrl, moduleName, umdName, globalObject, plugin;
231
- return _regenerator.default.wrap(function _callee3$(_context3) {
232
- while (1) {
233
- switch (_context3.prev = _context3.next) {
234
- case 0:
235
- umdUrl = 'url' in pluginDefinition ? pluginDefinition.url : pluginDefinition.umdUrl;
236
- _context3.prev = 1;
237
- parsedUrl = new URL(umdUrl, getGlobalObject().location.href);
238
- _context3.next = 9;
239
- break;
240
-
241
- case 5:
242
- _context3.prev = 5;
243
- _context3.t0 = _context3["catch"](1);
244
- console.error(_context3.t0);
245
- throw new Error("Error parsing URL: ".concat(umdUrl));
246
-
247
- case 9:
248
- if (!(parsedUrl.protocol !== 'http:' && parsedUrl.protocol !== 'https:')) {
249
- _context3.next = 11;
250
- break;
56
+ loadScript(scriptUrl) {
57
+ const globalObject = getGlobalObject();
58
+ if (!isInWebWorker(globalObject)) {
59
+ return (0, load_script2_1.default)(scriptUrl);
60
+ }
61
+ // @ts-ignore
62
+ if (globalObject && globalObject.importScripts) {
63
+ return new Promise((resolve, reject) => {
64
+ try {
65
+ // @ts-ignore
66
+ globalObject.importScripts(scriptUrl);
251
67
  }
252
-
253
- throw new Error("cannot load plugins using protocol \"".concat(parsedUrl.protocol, "\""));
254
-
255
- case 11:
256
- _context3.next = 13;
257
- return this.loadScript(parsedUrl.href);
258
-
259
- case 13:
260
- moduleName = pluginDefinition.name;
261
- umdName = "JBrowsePlugin".concat(moduleName);
262
- globalObject = getGlobalObject(); // eslint-disable-next-line @typescript-eslint/no-explicit-any
263
-
264
- plugin = globalObject[umdName];
265
-
266
- if (plugin) {
267
- _context3.next = 19;
268
- break;
68
+ catch (error) {
69
+ reject(error || new Error(`failed to load ${scriptUrl}`));
70
+ return;
269
71
  }
270
-
271
- throw new Error("Failed to load UMD bundle for ".concat(moduleName, ", ").concat(globalObject.constructor.name, ".").concat(umdName, " is undefined"));
272
-
273
- case 19:
274
- return _context3.abrupt("return", plugin);
275
-
276
- case 20:
277
- case "end":
278
- return _context3.stop();
279
- }
280
- }
281
- }, _callee3, this, [[1, 5]]);
282
- }));
283
-
284
- function loadUMDPlugin(_x3) {
285
- return _loadUMDPlugin.apply(this, arguments);
286
- }
287
-
288
- return loadUMDPlugin;
289
- }()
290
- }, {
291
- key: "loadPlugin",
292
- value: function () {
293
- var _loadPlugin = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(definition) {
294
- var plugin;
295
- return _regenerator.default.wrap(function _callee4$(_context4) {
296
- while (1) {
297
- switch (_context4.prev = _context4.next) {
298
- case 0:
299
- if (!(_util.isElectron && isCJSPluginDefinition(definition))) {
300
- _context4.next = 6;
301
- break;
302
- }
303
-
304
- _context4.next = 3;
305
- return this.loadCJSPlugin(definition);
306
-
307
- case 3:
308
- plugin = _context4.sent;
309
- _context4.next = 23;
310
- break;
311
-
312
- case 6:
313
- if (!isESMPluginDefinition(definition)) {
314
- _context4.next = 12;
315
- break;
316
- }
317
-
318
- _context4.next = 9;
319
- return this.loadESMPlugin(definition);
320
-
321
- case 9:
322
- plugin = _context4.sent;
323
- _context4.next = 23;
324
- break;
325
-
326
- case 12:
327
- if (!isUMDPluginDefinition(definition)) {
328
- _context4.next = 18;
329
- break;
330
- }
331
-
332
- _context4.next = 15;
333
- return this.loadUMDPlugin(definition);
334
-
335
- case 15:
336
- plugin = _context4.sent;
337
- _context4.next = 23;
338
- break;
339
-
340
- case 18:
341
- if (!(!_util.isElectron && isCJSPluginDefinition(definition))) {
342
- _context4.next = 22;
343
- break;
344
- }
345
-
346
- throw new Error("Only CommonJS plugin found, but not in a NodeJS environment: ".concat(JSON.stringify(definition)));
347
-
348
- case 22:
349
- throw new Error("Could not determine plugin type: ".concat(JSON.stringify(definition)));
350
-
351
- case 23:
352
- return _context4.abrupt("return", plugin.default);
353
-
354
- case 24:
355
- case "end":
356
- return _context4.stop();
357
- }
358
- }
359
- }, _callee4, this);
360
- }));
361
-
362
- function loadPlugin(_x4) {
363
- return _loadPlugin.apply(this, arguments);
364
- }
365
-
366
- return loadPlugin;
367
- }()
368
- }, {
369
- key: "installGlobalReExports",
370
- value: function installGlobalReExports(target) {
371
- // @ts-ignore
372
- target.JBrowseExports = Object.fromEntries(Object.entries(_ReExports.default).map(function (_ref2) {
373
- var _ref3 = (0, _slicedToArray2.default)(_ref2, 2),
374
- moduleName = _ref3[0],
375
- module = _ref3[1];
376
-
377
- return [moduleName, module];
378
- }));
72
+ resolve();
73
+ });
74
+ }
75
+ throw new Error('cannot figure out how to load external JS scripts in this environment');
76
+ }
77
+ async loadCJSPlugin({ cjsUrl }) {
78
+ let parsedUrl;
79
+ try {
80
+ parsedUrl = new URL(cjsUrl, getGlobalObject().location.href);
81
+ }
82
+ catch (error) {
83
+ console.error(error);
84
+ throw new Error(`Error parsing URL: ${cjsUrl}`);
85
+ }
86
+ if (parsedUrl.protocol !== 'http:' && parsedUrl.protocol !== 'https:') {
87
+ throw new Error(`Cannot load plugins using protocol "${parsedUrl.protocol}"`);
88
+ }
89
+ if (!this.fetchCJS) {
90
+ throw new Error('No fetchCJS callback provided');
91
+ }
92
+ return this.fetchCJS(parsedUrl.href);
93
+ }
94
+ async loadESMPlugin(pluginDefinition) {
95
+ var _a;
96
+ let parsedUrl;
97
+ try {
98
+ parsedUrl = new URL(pluginDefinition.esmUrl, getGlobalObject().location.href);
99
+ }
100
+ catch (error) {
101
+ console.error(error);
102
+ throw new Error(`Error parsing URL: ${pluginDefinition.esmUrl}`);
103
+ }
104
+ if (parsedUrl.protocol !== 'http:' && parsedUrl.protocol !== 'https:') {
105
+ throw new Error(`cannot load plugins using protocol "${parsedUrl.protocol}"`);
106
+ }
107
+ const plugin = (await ((_a = this.fetchESM) === null || _a === void 0 ? void 0 : _a.call(this, parsedUrl.href)));
108
+ if (!plugin) {
109
+ throw new Error(`Could not load ESM plugin: ${parsedUrl}`);
110
+ }
111
+ return plugin;
379
112
  }
380
- }, {
381
- key: "load",
382
- value: function () {
383
- var _load = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6() {
384
- var _this = this;
385
-
386
- return _regenerator.default.wrap(function _callee6$(_context6) {
387
- while (1) {
388
- switch (_context6.prev = _context6.next) {
389
- case 0:
390
- return _context6.abrupt("return", Promise.all(this.definitions.map( /*#__PURE__*/function () {
391
- var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(definition) {
392
- return _regenerator.default.wrap(function _callee5$(_context5) {
393
- while (1) {
394
- switch (_context5.prev = _context5.next) {
395
- case 0:
396
- _context5.next = 2;
397
- return _this.loadPlugin(definition);
398
-
399
- case 2:
400
- _context5.t0 = _context5.sent;
401
- _context5.t1 = definition;
402
- return _context5.abrupt("return", {
403
- plugin: _context5.t0,
404
- definition: _context5.t1
405
- });
406
-
407
- case 5:
408
- case "end":
409
- return _context5.stop();
410
- }
411
- }
412
- }, _callee5);
413
- }));
414
-
415
- return function (_x5) {
416
- return _ref4.apply(this, arguments);
417
- };
418
- }())));
419
-
420
- case 1:
421
- case "end":
422
- return _context6.stop();
423
- }
424
- }
425
- }, _callee6, this);
426
- }));
427
-
428
- function load() {
429
- return _load.apply(this, arguments);
430
- }
431
-
432
- return load;
433
- }()
434
- }]);
435
- return PluginLoader;
436
- }();
437
-
438
- exports.default = PluginLoader;
113
+ async loadUMDPlugin(pluginDefinition) {
114
+ const umdUrl = 'url' in pluginDefinition ? pluginDefinition.url : pluginDefinition.umdUrl;
115
+ let parsedUrl;
116
+ try {
117
+ parsedUrl = new URL(umdUrl, getGlobalObject().location.href);
118
+ }
119
+ catch (error) {
120
+ console.error(error);
121
+ throw new Error(`Error parsing URL: ${umdUrl}`);
122
+ }
123
+ if (parsedUrl.protocol !== 'http:' && parsedUrl.protocol !== 'https:') {
124
+ throw new Error(`cannot load plugins using protocol "${parsedUrl.protocol}"`);
125
+ }
126
+ await this.loadScript(parsedUrl.href);
127
+ const moduleName = pluginDefinition.name;
128
+ const umdName = `JBrowsePlugin${moduleName}`;
129
+ const globalObject = getGlobalObject();
130
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
131
+ const plugin = globalObject[umdName];
132
+ if (!plugin) {
133
+ throw new Error(`Failed to load UMD bundle for ${moduleName}, ${globalObject.constructor.name}.${umdName} is undefined`);
134
+ }
135
+ return plugin;
136
+ }
137
+ async loadPlugin(definition) {
138
+ let plugin;
139
+ if (util_1.isElectron && isCJSPluginDefinition(definition)) {
140
+ plugin = await this.loadCJSPlugin(definition);
141
+ }
142
+ else if (isESMPluginDefinition(definition)) {
143
+ plugin = await this.loadESMPlugin(definition);
144
+ }
145
+ else if (isUMDPluginDefinition(definition)) {
146
+ plugin = await this.loadUMDPlugin(definition);
147
+ }
148
+ else if (!util_1.isElectron && isCJSPluginDefinition(definition)) {
149
+ throw new Error(`Only CommonJS plugin found, but not in a NodeJS environment: ${JSON.stringify(definition)}`);
150
+ }
151
+ else {
152
+ throw new Error(`Could not determine plugin type: ${JSON.stringify(definition)}`);
153
+ }
154
+ return plugin.default;
155
+ }
156
+ installGlobalReExports(target) {
157
+ // @ts-ignore
158
+ target.JBrowseExports = Object.fromEntries(Object.entries(ReExports_1.default).map(([moduleName, module]) => {
159
+ return [moduleName, module];
160
+ }));
161
+ }
162
+ async load() {
163
+ return Promise.all(this.definitions.map(async (definition) => ({
164
+ plugin: await this.loadPlugin(definition),
165
+ definition,
166
+ })));
167
+ }
168
+ }
169
+ exports.default = PluginLoader;