@cuemath/web-utils 1.0.19-beta.1 → 1.0.19-beta.3
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 @@
|
|
|
1
|
-
declare const loadScript: (url: string, id: string) =>
|
|
2
|
-
export { loadScript };
|
|
1
|
+
export declare const loadScript: (url: string, id: string, onLoad: (event: Event) => void) => void;
|
package/dist/cjs/script/index.js
CHANGED
|
@@ -1,41 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.loadScript = void 0;
|
|
4
|
-
const loadScript = (
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
})();
|
|
4
|
+
const loadScript = (url, id, onLoad) => {
|
|
5
|
+
const script = document.createElement('script');
|
|
6
|
+
script.id = id;
|
|
7
|
+
script.src = url;
|
|
8
|
+
script.onload = onLoad;
|
|
9
|
+
script.async = true;
|
|
10
|
+
document.body.appendChild(script);
|
|
11
|
+
};
|
|
40
12
|
exports.loadScript = loadScript;
|
|
41
13
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/script/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/script/index.ts"],"names":[],"mappings":";;;AAAO,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,EAAU,EAAE,MAA8B,EAAE,EAAE;IACpF,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;AATW,QAAA,UAAU,cASrB"}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
declare const loadScript: (url: string, id: string) =>
|
|
2
|
-
export { loadScript };
|
|
1
|
+
export declare const loadScript: (url: string, id: string, onLoad: (event: Event) => void) => void;
|
package/dist/esm/script/index.js
CHANGED
|
@@ -1,38 +1,9 @@
|
|
|
1
|
-
const loadScript = (
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
+
export 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
|
+
};
|
|
38
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/script/index.ts"],"names":[],"mappings":"AAAA,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/script/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,EAAU,EAAE,MAA8B,EAAE,EAAE;IACpF,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"}
|