Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix svg rendering #515

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ramp-storylines_demo-scenarios-pcar",
"description": "A user-configurable story product featuring interactive maps, charts and dynamic multimedia content alongside text.",
"version": "3.2.8",
"version": "3.2.9",
"private": false,
"license": "MIT",
"repository": "https://github.com/ramp4-pcar4/story-ramp",
Expand Down
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
26 changes: 18 additions & 8 deletions src/components/story/background-image.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,26 @@ const getImageSource = (src: string): Promise<string> => {
if (props.configFileStructure) {
const assetSrc = `${src.substring(src.indexOf('/') + 1)}`;
const imageFile = props.configFileStructure?.zip.file(assetSrc);
const imageType = assetSrc.split('.').at(-1);
const imageName = src.replace(/^.*[\\/]/, '');
if (imageFile) {
// Convert the image to a blob so it can be displayed locally.
imageFile.async('blob').then((res: Blob) => {
const blob = URL.createObjectURL(res);
if (imageType !== 'svg') {
// Convert the image to a blob so it can be displayed locally.
imageFile.async('blob').then((res: Blob) => {
const blob = URL.createObjectURL(res);

// Assign to blobStore and return the result.
blobStore[src] = blob;
resolve(blobStore[src]);
return;
});
// Assign to blobStore and return the result.
blobStore[src] = blob;
resolve(blobStore[src]);
return;
});
} else {
imageFile.async('text').then((res) => {
const image = new File([res], imageName, { type: 'image/svg+xml' });
resolve(URL.createObjectURL(image));
return;
});
}
} else {
resolve(src);
return;
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
Loading