{
7 | const img = new Image();
8 | const tempDom = temporaryDom.append(img);
9 |
10 | const loaded = new Promise((resolve, reject) => {
11 | img.onload = () => resolve();
12 | img.onerror = () => {
13 | const shortUrl = url.length <= 64 ? url : url.substr(0, 61) + '...';
14 | reject(new Error(`carbonite: failed to load image ${shortUrl}`));
15 | };
16 |
17 | img.src = url;
18 | });
19 |
20 | return loaded
21 | .then(() => callback(img))
22 | .then(
23 | (value) => {
24 | tempDom.dispose();
25 | return value;
26 | },
27 | (error) => {
28 | tempDom.dispose();
29 | return Promise.reject(error);
30 | });
31 | }
32 |
--------------------------------------------------------------------------------
/test/stand.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | Carbonite test stand
8 |
9 |
10 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
53 |
60 |
61 |
62 |
63 |
68 |
69 |
70 |
result
71 |
![]()
72 |
73 |
74 |
104 |
105 |
106 |
--------------------------------------------------------------------------------
/test/world.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/flapenguin/carbonite/b4d56b2de4f95965cf8168f9e4d4ee1e689411ac/test/world.png
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "es3",
4 | "module": "commonjs",
5 | "rootDir": "./src",
6 | "lib": [
7 | "es5",
8 | "dom",
9 | "es2015.promise"
10 | ],
11 | "strict": true
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "defaultSeverity": "error",
3 | "extends": [
4 | "tslint:recommended"
5 | ],
6 | "jsRules": {},
7 | "rules": {
8 | "quotemark": [true, "single", "avoid-escape"],
9 | "ordered-imports": false,
10 | "object-literal-sort-keys": false,
11 | "object-literal-shorthand": false,
12 | "trailing-comma": false,
13 | "no-angle-bracket-type-assertion": false,
14 | "variable-name": [true, "allow-leading-underscore"],
15 | "member-access": [true, "no-public"],
16 | "interface-name": false
17 | },
18 | "rulesDirectory": []
19 | }
20 |
--------------------------------------------------------------------------------
/webpack.config.js:
--------------------------------------------------------------------------------
1 | const path = require('path');
2 |
3 | module.exports = {
4 | entry: './src/index.ts',
5 | module: {
6 | rules: [
7 | {
8 | test: /\.ts$/,
9 | use: 'ts-loader',
10 | exclude: /node_modules/
11 | }
12 | ]
13 | },
14 | resolve: {
15 | extensions: [".ts"]
16 | },
17 | output: {
18 | filename: 'carbonite.js',
19 | path: path.resolve(__dirname, 'dist'),
20 | library: 'carbonite',
21 | libraryTarget: 'umd'
22 | }
23 | };
24 |
--------------------------------------------------------------------------------