| 67 | } |
| 68 | |
| 69 | private base64ToArrayBuffer(base64: string, opts?: imageOptions) { |
| 70 | const base64Data = base64.replace(/^data:.+;base64,/, ""); |
| 71 | const paddedBase64Data = base64Data.padEnd( |
| 72 | base64Data.length + ((4 - (base64Data.length % 4)) % 4), |
| 73 | "=", |
| 74 | ); |
| 75 | |
| 76 | const binaryString = atob(paddedBase64Data); |
| 77 | const byteArray = new Uint8Array(binaryString.length); |
| 78 | for (let i = 0; i < binaryString.length; i++) { |
| 79 | byteArray[i] = binaryString.charCodeAt(i); |
| 80 | } |
| 81 | const blobProps = {}; |
| 82 | // @ts-ignore |
| 83 | if (opts?.contentType) blobProps["type"] = opts.contentType; |
| 84 | return new Blob([byteArray], blobProps); |
| 85 | } |
| 86 | |
| 87 | private isBase64(str: string): boolean { |
| 88 | const regex = /^data:([a-zA-Z0-9]+\/[a-zA-Z0-9-.+]+);base64,([^\s]*)$/; |