Skip to content

Commit

Permalink
changes to support browser bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinita Yadav authored and vinita-mobstac committed Aug 28, 2024
1 parent 3ec9bca commit f5270d2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Svg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ export class SVGDrawing {


private async getImageBase64Data(imgSrc: string) {
const data = await loadImage(imgSrc ,this.config.imageServerURL , this.config.imageServerRequestHeaders )
const data = await loadImage(imgSrc)
const blob = await data.blob();
return new Promise<string | ArrayBuffer | null>((resolve, reject) => {
const reader = new FileReader();
Expand Down
20 changes: 12 additions & 8 deletions src/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@

export const isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null;

export const loadImage = (src: string, imageServerURL?: string | undefined | RequestInfo, imageServerRequestHeaders?: object | undefined) => {
export const loadImage = (src: string) => {
// @ts-ignore
imageServerRequestHeaders['Content-type'] = 'application/json'
// let imageServerRequestHeaders
// imageServerRequestHeaders['Content-type'] = 'image/svg+xml'
return new Promise<Response>((resolve , reject) =>{
fetch(<any>imageServerURL, {
method :'POST',
headers : <any>imageServerRequestHeaders,
body : JSON.stringify( {
url : src
})
fetch(<any>src, {
method :'GET',
headers : {
'Content-type' : 'image/svg+xml'
}
// body : JSON.stringify( {
// url : src
// })
}).then( (data : Response) => resolve(data))

.catch( (err : Error ) => reject(err))
})
};
Expand Down
4 changes: 2 additions & 2 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ module.exports = {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
},
target: 'node',
externals: [nodeExternals(), { fs: "commonjs fs" }],
target: 'web',
// externals: [nodeExternals(), { fs: "commonjs fs" }],
};

0 comments on commit f5270d2

Please sign in to comment.