Socket
Socket
Sign inDemoInstall

@shapediver/viewer.shared.services

Package Overview
Dependencies
Maintainers
0
Versions
203
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@shapediver/viewer.shared.services - npm Package Compare versions

Comparing version 3.2.8 to 3.3.0

32

dist/converter/Converter.d.ts

@@ -7,2 +7,34 @@ import { HttpResponse } from '../http-client/HttpResponse';

static get instance(): Converter;
/**
* Converts a data URL to a Blob object.
*
* @param dataURL
* @returns
*/
dataURLtoBlob(dataURL: string): {
blob: Blob;
arrayBuffer: ArrayBufferLike;
};
/**
* Convert the given image to an ArrayBuffer and return the image data.
*
* @param image The image to convert.
* @param arrayBuffer Optional: The ArrayBuffer of the image, if it was already converted.
* @returns
*/
constructImageData(image: Blob | File, arrayBuffer?: ArrayBuffer): Promise<{
imageData: {
filename?: string;
format: string;
size: number;
};
arrayBuffer: ArrayBuffer;
}>;
/**
* Convert the given input to an ArrayBuffer.
*
* @param input
* @returns
*/
convertToArrayBuffer(input: (() => Promise<ArrayBuffer>) | ArrayBuffer | (() => Promise<Blob>) | Blob | File): Promise<ArrayBuffer>;
processSVG(blob: Blob): Promise<HTMLImageElement>;

@@ -9,0 +41,0 @@ responseToImage(response: HttpResponse<{

@@ -28,2 +28,82 @@ "use strict";

}
/**
* Converts a data URL to a Blob object.
*
* @param dataURL
* @returns
*/
dataURLtoBlob(dataURL) {
// Split the data URL to get the base64 data
const arr = dataURL.split(",");
const mime = arr[0].match(/:(.*?);/)[1];
const bstr = window.atob(arr[1]);
let n = bstr.length;
const u8arr = new Uint8Array(n);
// Convert the binary string to a Uint8Array
while (n--)
u8arr[n] = bstr.charCodeAt(n);
// Create a Blob object from the Uint8Array
return {
blob: new Blob([u8arr], { type: mime }),
arrayBuffer: u8arr.buffer
};
}
/**
* Convert the given image to an ArrayBuffer and return the image data.
*
* @param image The image to convert.
* @param arrayBuffer Optional: The ArrayBuffer of the image, if it was already converted.
* @returns
*/
constructImageData(image, arrayBuffer) {
return __awaiter(this, void 0, void 0, function* () {
if (image instanceof File) {
return {
imageData: {
filename: image.name,
format: image.type,
size: image.size
},
arrayBuffer: arrayBuffer || (yield image.arrayBuffer())
};
}
else {
return {
imageData: {
format: image.type,
size: image.size
},
arrayBuffer: arrayBuffer || (yield image.arrayBuffer())
};
}
});
}
/**
* Convert the given input to an ArrayBuffer.
*
* @param input
* @returns
*/
convertToArrayBuffer(input) {
return __awaiter(this, void 0, void 0, function* () {
if (input instanceof File) {
return yield input.arrayBuffer();
}
else if (input instanceof Blob) {
return yield input.arrayBuffer();
}
else if (input instanceof ArrayBuffer) {
return input;
}
else {
const result = yield input();
if (result instanceof Blob) {
return yield result.arrayBuffer();
}
else {
return result;
}
}
});
}
// #endregion Public Static Getters And Setters (1)

@@ -30,0 +110,0 @@ // #region Public Methods (8)

8

package.json
{
"name": "@shapediver/viewer.shared.services",
"version": "3.2.8",
"version": "3.3.0",
"description": "",

@@ -43,5 +43,5 @@ "keywords": [],

"@ctrl/tinycolor": "^3.4.0",
"@shapediver/sdk.geometry-api-sdk-v2": "1.10.0",
"@shapediver/sdk.geometry-api-sdk-v2": "1.11.0",
"@shapediver/viewer.settings": "1.0.2",
"@shapediver/viewer.shared.build-data": "3.2.8",
"@shapediver/viewer.shared.build-data": "3.3.0",
"@types/dompurify": "^2.3.1",

@@ -56,3 +56,3 @@ "@types/ua-parser-js": "^0.7.36",

},
"gitHead": "a8c27c745498812d103635aeec6d5311d6e8c8e3"
"gitHead": "61b4be88aa0005d398662a34a186ef142ea51763"
}

@@ -22,2 +22,85 @@ import { ColorInput, TinyColor } from '@ctrl/tinycolor';

/**
* Converts a data URL to a Blob object.
*
* @param dataURL
* @returns
*/
public dataURLtoBlob(dataURL: string) {
// Split the data URL to get the base64 data
const arr = dataURL.split(",");
const mime = arr[0].match(/:(.*?);/)![1];
const bstr = window.atob(arr[1]);
let n = bstr.length;
const u8arr = new Uint8Array(n);
// Convert the binary string to a Uint8Array
while (n--) u8arr[n] = bstr.charCodeAt(n);
// Create a Blob object from the Uint8Array
return {
blob: new Blob([u8arr], { type: mime }),
arrayBuffer: u8arr.buffer
};
}
/**
* Convert the given image to an ArrayBuffer and return the image data.
*
* @param image The image to convert.
* @param arrayBuffer Optional: The ArrayBuffer of the image, if it was already converted.
* @returns
*/
public async constructImageData(image: Blob | File, arrayBuffer?: ArrayBuffer): Promise<{
imageData: {
filename?: string,
format: string,
size: number
},
arrayBuffer: ArrayBuffer
}> {
if(image instanceof File) {
return {
imageData: {
filename: image.name,
format: image.type,
size: image.size
},
arrayBuffer: arrayBuffer || await image.arrayBuffer()
};
} else {
return {
imageData: {
format: image.type,
size: image.size
},
arrayBuffer: arrayBuffer || await image.arrayBuffer()
};
}
}
/**
* Convert the given input to an ArrayBuffer.
*
* @param input
* @returns
*/
public async convertToArrayBuffer(input: (() => Promise<ArrayBuffer>) | ArrayBuffer | (() => Promise<Blob>) | Blob | File): Promise<ArrayBuffer> {
if (input instanceof File) {
return await input.arrayBuffer();
} else if (input instanceof Blob) {
return await input.arrayBuffer();
} else if (input instanceof ArrayBuffer) {
return input;
} else {
const result = await input();
if (result instanceof Blob) {
return await result.arrayBuffer();
} else {
return result;
}
}
}
// #endregion Public Static Getters And Setters (1)

@@ -24,0 +107,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc