@jasonsbarr/htdp-image
Advanced tools
Comparing version 0.6.1 to 0.6.3
@@ -8,3 +8,3 @@ { | ||
}, | ||
"version": "0.6.1", | ||
"version": "0.6.3", | ||
"main": "./dist/index.cjs", | ||
@@ -11,0 +11,0 @@ "source": "./src/index.js", |
@@ -45,3 +45,3 @@ # HTDP/image.js | ||
```html | ||
<script src="https://www.unpkg.com/@jasonsbarr/htdp-image@0.6.1/dist/index.umd.js"></script> | ||
<script src="https://www.unpkg.com/@jasonsbarr/htdp-image@0.6.3/dist/index.umd.js"></script> | ||
@@ -48,0 +48,0 @@ <script> |
@@ -23,2 +23,3 @@ import { makeDocument } from "../../shared/document.js"; | ||
this.src = src; | ||
this._isLoaded = false; | ||
@@ -34,2 +35,3 @@ if (rawVideo) { | ||
this.video.loop = true; | ||
this._isLoaded = true; | ||
this.video.play(); | ||
@@ -47,2 +49,3 @@ } else { | ||
this.video.loop = true; | ||
this._isLoaded = true; | ||
this.video.play(); | ||
@@ -72,2 +75,6 @@ }); | ||
get isLoaded() { | ||
return this._isLoaded; | ||
} | ||
/** | ||
@@ -74,0 +81,0 @@ * Checks for equality |
@@ -125,2 +125,11 @@ import * as Lib from "./image-lib/index.js"; | ||
const imageIsLoaded = (img) => img.isLoaded; | ||
const renderImage = (image, element) => { | ||
const canvas = Lib.makeCanvas(image.width, image.height); | ||
const context = canvas.getContext("2d"); | ||
element.appendChild(canvas); | ||
image.render(context); | ||
}; | ||
/** | ||
@@ -132,7 +141,17 @@ * Renders an image to the DOM | ||
export const render = (image, element = document.body) => { | ||
const canvas = Lib.makeCanvas(image.width, image.height); | ||
const context = canvas.getContext("2d"); | ||
if (image instanceof FileImage || image instanceof FileVideo) { | ||
if (imageIsLoaded(image)) { | ||
renderImage(image, element); | ||
return; | ||
} | ||
element.appendChild(canvas); | ||
image.render(context); | ||
let interval = setInterval(() => { | ||
if (imageIsLoaded(image)) { | ||
renderImage(image, element); | ||
clearInterval(interval); | ||
} | ||
}, 100); | ||
} else { | ||
renderImage(image, element); | ||
} | ||
}; | ||
@@ -139,0 +158,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1765177
6763