@cuemath/web-utils 1.0.19-beta.1 → 1.0.19-beta.2

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.
@@ -1,2 +1,2 @@
1
- declare const loadScript: (url: string, id: string) => Promise<void>;
2
- export { loadScript };
1
+ declare const loadScript: (url: string, id: string, onLoad: (event: Event) => void) => void;
2
+ export default loadScript;
@@ -1,41 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadScript = void 0;
4
- const loadScript = (() => {
5
- const promises = {};
6
- return (url, id) => {
7
- if (promises[id] !== null && promises[id] !== undefined) {
8
- return promises[id];
9
- }
10
- promises[id] = new Promise((resolve, reject) => {
11
- const existingElement = document.querySelector(`#${id}`);
12
- const head = document.getElementsByTagName('head')[0];
13
- const script = document.createElement('script');
14
- script.type = 'text/javascript';
15
- script.id = id;
16
- script.src = url;
17
- script.onload = () => {
18
- resolve();
19
- };
20
- script.onerror = (event) => {
21
- reject(new Error(`Failed to load ${typeof event === 'string'
22
- ? event
23
- : event?.target?.src}`));
24
- };
25
- if (existingElement !== null) {
26
- existingElement.remove();
27
- }
28
- head.appendChild(script);
29
- });
30
- promises[id]
31
- ?.then(() => {
32
- promises[id] = null;
33
- })
34
- .catch(() => {
35
- promises[id] = null;
36
- });
37
- return promises[id];
38
- };
39
- })();
40
- exports.loadScript = loadScript;
3
+ const loadScript = (url, id, onLoad) => {
4
+ const script = document.createElement('script');
5
+ script.id = id;
6
+ script.src = url;
7
+ script.onload = onLoad;
8
+ script.async = true;
9
+ document.body.appendChild(script);
10
+ };
11
+ exports.default = loadScript;
41
12
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/script/index.ts"],"names":[],"mappings":";;;AAAA,MAAM,UAAU,GAAG,CAAC,GAAG,EAAE;IACvB,MAAM,QAAQ,GAA2C,EAAE,CAAC;IAE5D,OAAO,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;QACtB,CAAC,CAAC;aACD,KAAK,CAAC,GAAG,EAAE;YACV,QAAQ,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;QACtB,CAAC,CAAC,CAAC;QAEL,OAAO,QAAQ,CAAC,EAAE,CAAkB,CAAC;IACvC,CAAC,CAAC;AACJ,CAAC,CAAC,EAAE,CAAC;AAEI,gCAAU"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/script/index.ts"],"names":[],"mappings":";;AAAA,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,EAAU,EAAE,MAA8B,EAAE,EAAE;IAC7E,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAEhD,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC;IACf,MAAM,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC;IAEpB,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;AACpC,CAAC,CAAC;AAEF,kBAAe,UAAU,CAAC"}
@@ -1,2 +1,2 @@
1
- declare const loadScript: (url: string, id: string) => Promise<void>;
2
- export { loadScript };
1
+ declare const loadScript: (url: string, id: string, onLoad: (event: Event) => void) => void;
2
+ export default loadScript;
@@ -1,38 +1,10 @@
1
- const loadScript = (() => {
2
- const promises = {};
3
- return (url, id) => {
4
- var _a;
5
- if (promises[id] !== null && promises[id] !== undefined) {
6
- return promises[id];
7
- }
8
- promises[id] = new Promise((resolve, reject) => {
9
- const existingElement = document.querySelector(`#${id}`);
10
- const head = document.getElementsByTagName('head')[0];
11
- const script = document.createElement('script');
12
- script.type = 'text/javascript';
13
- script.id = id;
14
- script.src = url;
15
- script.onload = () => {
16
- resolve();
17
- };
18
- script.onerror = (event) => {
19
- var _a;
20
- reject(new Error(`Failed to load ${typeof event === 'string'
21
- ? event
22
- : (_a = event === null || event === void 0 ? void 0 : event.target) === null || _a === void 0 ? void 0 : _a.src}`));
23
- };
24
- if (existingElement !== null) {
25
- existingElement.remove();
26
- }
27
- head.appendChild(script);
28
- });
29
- (_a = promises[id]) === null || _a === void 0 ? void 0 : _a.then(() => {
30
- promises[id] = null;
31
- }).catch(() => {
32
- promises[id] = null;
33
- });
34
- return promises[id];
35
- };
36
- })();
37
- export { loadScript };
1
+ const loadScript = (url, id, onLoad) => {
2
+ const script = document.createElement('script');
3
+ script.id = id;
4
+ script.src = url;
5
+ script.onload = onLoad;
6
+ script.async = true;
7
+ document.body.appendChild(script);
8
+ };
9
+ export default loadScript;
38
10
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/script/index.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,GAAG,CAAC,GAAG,EAAE;IACvB,MAAM,QAAQ,GAA2C,EAAE,CAAC;IAE5D,OAAO,CAAC,GAAW,EAAE,EAAU,EAAiB,EAAE;;QAChD,IAAI,QAAQ,CAAC,EAAE,CAAC,KAAK,IAAI,IAAI,QAAQ,CAAC,EAAE,CAAC,KAAK,SAAS,EAAE;YACvD,OAAO,QAAQ,CAAC,EAAE,CAAkB,CAAC;SACtC;QAED,QAAQ,CAAC,EAAE,CAAC,GAAG,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC7C,MAAM,eAAe,GAAG,QAAQ,CAAC,aAAa,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;YACzD,MAAM,IAAI,GAAG,QAAQ,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;YACtD,MAAM,MAAM,GAAsB,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;YAEnE,MAAM,CAAC,IAAI,GAAG,iBAAiB,CAAC;YAChC,MAAM,CAAC,EAAE,GAAG,EAAE,CAAC;YACf,MAAM,CAAC,GAAG,GAAG,GAAG,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K,GAAG,IAAI,CAAC;IAEpB,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;AACpC,CAAC,CAAC;AAEF,eAAe,UAAU,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cuemath/web-utils",
3
- "version": "1.0.19-beta.1",
3
+ "version": "1.0.19-beta.2",
4
4
  "description": "Shared web utils package",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",