Skip to content

Commit

Permalink
Merge pull request #26 from jamsinclair/png-polyfill-imagedata
Browse files Browse the repository at this point in the history
  • Loading branch information
jamsinclair authored Jul 8, 2023
2 parents 52ea8b8 + 6acacd1 commit 2399591
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 deletions.
7 changes: 7 additions & 0 deletions packages/png/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

## @jquash/png@2.1.0

### Added

- Include polyfills for Cloudflare Worker environment for easier compatibility
5 changes: 4 additions & 1 deletion packages/png/codec/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
"squoosh_png.js",
"squoosh_png.d.ts"
],
"scripts": {
"patch-pre-script": "cat pre.js >> squoosh_png.js"
},
"module": "squoosh_png.js",
"types": "squoosh_png.d.ts",
"sideEffects": false
}
}
15 changes: 15 additions & 0 deletions packages/png/codec/pre.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(function () {
const isRunningInCloudFlareWorkers = caches.default !== undefined;
if (isRunningInCloudFlareWorkers) {
if (!globalThis.ImageData) {
// Simple Polyfill for ImageData Object
globalThis.ImageData = class ImageData {
constructor(data, width, height) {
this.data = data;
this.width = width;
this.height = height;
}
};
}
}
})();
15 changes: 15 additions & 0 deletions packages/png/codec/squoosh_png.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,18 @@ async function init(input) {

export default init;

(function () {
const isRunningInCloudFlareWorkers = caches.default !== undefined;
if (isRunningInCloudFlareWorkers) {
if (!globalThis.ImageData) {
// Simple Polyfill for ImageData Object
globalThis.ImageData = class ImageData {
constructor(data, width, height) {
this.data = data;
this.width = width;
this.height = height;
}
};
}
}
})();
4 changes: 2 additions & 2 deletions packages/png/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jsquash/png",
"version": "2.0.0",
"version": "2.1.0",
"main": "index.js",
"description": "Wasm png encoder and decoder supporting the browser. Repackaged from Squoosh App.",
"repository": "jamsinclair/jSquash",
Expand All @@ -20,7 +20,7 @@
"license": "Apache-2.0",
"scripts": {
"clean": "rm -rf dist",
"build": "npm run clean && tsc && cp -r codec package.json README.md .npmignore dist"
"build": "npm run clean && tsc && cp -r codec package.json README.md CHANGELOG.md .npmignore dist"
},
"dependencies": {
"wasm-feature-detect": "^1.2.11"
Expand Down

0 comments on commit 2399591

Please sign in to comment.