Skip to content

Commit

Permalink
fix svg rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
IshavSohal committed Dec 6, 2024
1 parent 20a17a9 commit 823c49c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
15 changes: 12 additions & 3 deletions src/components/panels/image-panel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,20 @@ onMounted((): void => {
const image = props.config;
const assetSrc = `${image.src.substring(image.src.indexOf('/') + 1)}`;
const imageFile = props.configFileStructure?.zip.file(assetSrc);
const imageType = assetSrc.split('.').at(-1);
const imageName = image.src.replace(/^.*[\\/]/, '');
if (imageFile) {
// Convert the image to a blob so it can be displayed locally.
imageFile.async('blob').then((res: Blob) => {
state.src = props.config.src = URL.createObjectURL(res);
});
if (imageType !== 'svg') {
imageFile.async('blob').then((res: Blob) => {
state.src = props.config.src = URL.createObjectURL(res);
});
} else {
imageFile.async('text').then((res) => {
const image = new File([res], imageName, { type: 'image/svg+xml' });
state.src = props.config.src = URL.createObjectURL(image);
});
}
}
}
Expand Down
31 changes: 24 additions & 7 deletions src/components/story/introduction.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ const state = reactive({
onMounted(() => {
state.logo = props.config.logo ? props.config.logo.src : '';
state.backgroundImage = props.config.backgroundImage ?? '';
// obtain logo and background image from ZIP file if it exists
if (props.configFileStructure) {
const logo = props.config.logo?.src;
Expand All @@ -112,20 +111,38 @@ onMounted(() => {
if (logo) {
const logoSrc = `${logo.substring(logo.indexOf('/') + 1)}`;
const logoFile = props.configFileStructure.zip.file(logoSrc);
const logoType = logoSrc.split('.').at(-1);
const logoName = logo.replace(/^.*[\\/]/, '');
if (logoFile) {
logoFile.async('blob').then((res: Blob) => {
state.logo = props.config.logo.src = URL.createObjectURL(res);
});
if (logoType !== 'svg') {
logoFile.async('blob').then((res: Blob) => {
state.logo = props.config.logo.src = URL.createObjectURL(res);
});
} else {
logoFile.async('text').then((res) => {
const image = new File([res], logoName, { type: 'image/svg+xml' });
state.logo = props.config.logo.src = URL.createObjectURL(image);
});
}
}
}
if (background) {
const bgSrc = `${background.substring(background.indexOf('/') + 1)}`;
const bgFile = props.configFileStructure.zip.file(bgSrc);
const bgType = bgSrc.split('.').at(-1);
const bgName = logo.replace(/^.*[\\/]/, '');
if (bgFile) {
bgFile.async('blob').then((res: Blob) => {
state.backgroundImage = props.config.backgroundImage = URL.createObjectURL(res);
});
if (bgType !== 'svg') {
bgFile.async('blob').then((res: Blob) => {
state.backgroundImage = props.config.backgroundImage = URL.createObjectURL(res);
});
} else {
bgFile.async('blob').then((res: Blob) => {
const image = new File([res], bgName, { type: 'image/svg+xml' });
state.backgroundImage = props.config.backgroundImage = URL.createObjectURL(image);
});
}
}
}
}
Expand Down

0 comments on commit 823c49c

Please sign in to comment.