@cloudparker/moldex.js 0.0.83 → 0.0.84

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.
@@ -264,9 +264,25 @@ export async function openFilePickerDialog(accepts = '*/*', options = { multiple
264
264
  * @param options - Additional options for capturing images (e.g., required resolution, file size, output format).
265
265
  * @returns A promise that resolves to a processed File object or an array of File objects, or null if no file was selected.
266
266
  */
267
- export async function openImagePickerDialog(accepts = 'image/*', options) {
267
+ export async function openImagePickerDialog(accepts = 'image/*', options = {}) {
268
268
  return new Promise((resolve, reject) => {
269
269
  try {
270
+ options = options || {};
271
+ if (!options.maxWidth) {
272
+ options.maxWidth = 1280;
273
+ }
274
+ if (!options.maxHeight) {
275
+ options.maxHeight = options.maxWidth;
276
+ }
277
+ if (!options.quality || options.quality < 0) {
278
+ options.quality = 0.8;
279
+ }
280
+ if (options.quality > 1) {
281
+ options.quality = options.quality / 100;
282
+ }
283
+ if (options.outputFormat) {
284
+ options.outputFormat = 'image/webp';
285
+ }
270
286
  // Create an input element of type 'file'
271
287
  const inputElement = document.createElement('input');
272
288
  inputElement.type = 'file';
@@ -6,10 +6,26 @@ export const ACCEPT_IMAGE_FILES = ".png,.PNG,.jpg,.jpg,.jepg,.JPEG,.webp,.WEBP";
6
6
  * @param options - Options for resizing, compressing, and converting the image.
7
7
  * @returns A promise that resolves to a processed File object with the correct filename and extension.
8
8
  */
9
- export async function processImageFile(file, options) {
10
- // Return the original file if no processing is needed
11
- if (!options?.maxWidth && !options?.maxHeight && !options?.maxSizeInBytes && !options?.outputFormat) {
12
- return file;
9
+ export async function processImageFile(file, options = {}) {
10
+ // // Return the original file if no processing is needed
11
+ // if (!options?.maxWidth && !options?.maxHeight && !options?.maxSizeInBytes && !options?.outputFormat) {
12
+ // return file;
13
+ // }
14
+ options = options || {};
15
+ if (!options.maxWidth) {
16
+ options.maxWidth = 1280;
17
+ }
18
+ if (!options.maxHeight) {
19
+ options.maxHeight = options.maxWidth;
20
+ }
21
+ if (!options.quality || options.quality < 0) {
22
+ options.quality = 0.8;
23
+ }
24
+ if (options.quality > 1) {
25
+ options.quality = options.quality / 100;
26
+ }
27
+ if (options.outputFormat) {
28
+ options.outputFormat = 'image/webp';
13
29
  }
14
30
  // Read the image as a data URL
15
31
  const imageDataUrl = await readFileAsDataURL(file);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudparker/moldex.js",
3
- "version": "0.0.83",
3
+ "version": "0.0.84",
4
4
  "author": "cloudparker.com",
5
5
  "license": "MIT",
6
6
  "keywords": [