Skip to content
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 src/app/file/utils/filter-images.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export function filterImages(fileList: Array<string>) {
const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp'];
const imageExtensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp', '.webp', '.tiff', '.svg', '.svgz'];

return fileList.filter(file => {
const extension = file.substring(file.lastIndexOf('.')).toLowerCase();
Expand Down
15 changes: 14 additions & 1 deletion src/app/file/utils/process-images-in-batches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,21 @@ export async function processImagesInBatches(

await Promise.all(
batch.map(async (filename, index) => {
const blob = await zip.files[filename].async('blob');
const file = zip.files[filename];
if (!file) return;

const svgExtensions = ['.svg', '.svgz'];
let blob: Blob;

if (svgExtensions.some(ext => filename.toLowerCase().endsWith(ext))) {
const text = await file.async('string');
blob = new Blob([text], { type: 'image/svg+xml' });
} else {
blob = await file.async('blob');
}

const url = URL.createObjectURL(blob);

postMessage({
type: 'file',
url,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<manga-page [dir]="viewer.viewModeOption().dir" style="margin: auto;">
<manga-page [dir]="viewer.viewModeOption().dir" style="margin: auto 0;">
<svg dir="ltr" frame="3" viewBox="0 0 300 200">
<text x="50%" y="42%" font-size="28" style="font-family:'Troubleside'">
{{lang.ph().getByKey(viewer.viewModeOption().hintPhraceKey)}}
Expand Down
4 changes: 2 additions & 2 deletions src/app/viewer/viewer/components/page/page.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
}
<figure [class]="{nsfw:nsfw(), show: nsfw() && showNsfw()}">
@if(src()){
<img crossorigin="anonymous" [id]="'page_'+(index()+1)" [src]="src()" [alt]="alt()" [width]="width()"
[height]="height()" [loading]="(index()==0 || preload()) ? 'eager' : 'lazy'" (load)="imageLoad($event)">
<img crossorigin="anonymous" [id]="'page_'+(index()+1)" [src]="src()" [alt]="alt()" [attr.width]="widthPx()"
[attr.height]="heightPx()" [loading]="(index()==0 || preload()) ? 'eager' : 'lazy'" (load)="imageLoad($event)">
} @else {
<ng-content />
}
Expand Down
23 changes: 22 additions & 1 deletion src/app/viewer/viewer/components/page/page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export class PageComponent {
width = computed(() => this.naturalWidth() ?? this.inputWidth());
height = computed(() => this.naturalHeight() ?? this.inputHeight());

widthPx = computed(() => this.width().toString() + 'px');
heightPx = computed(() => this.height().toString() + 'px');

index: InputSignal<number> = input(0);

agree: OutputEmitterRef<void> = output();
Expand All @@ -42,12 +45,30 @@ export class PageComponent {
this.disagree.emit();
}

imageLoad(event: Event) {
async imageLoad(event: Event) {
const img = event.target as HTMLImageElement;
this.imageLoading.set(false)
this.naturalWidth.set(img.naturalWidth);
this.naturalHeight.set(img.naturalHeight);

try {
const response = await fetch(img.src);
const blob = await response.blob();

if (blob.type === 'image/svg+xml' || blob.type === 'image/svg+xml-compressed') {
const text = await blob.text();
const parser = new DOMParser();
const svgDoc = parser.parseFromString(text, 'image/svg+xml');
const svgElement: SVGSVGElement = svgDoc.documentElement as unknown as SVGSVGElement;
console.log(svgElement.viewBox.baseVal.width);

this.naturalWidth.set(svgElement.viewBox.baseVal.width);
this.naturalHeight.set(svgElement.viewBox.baseVal.height);
}
} catch (e) {
console.warn('Failed to get bitmap size, fallback to naturalWidth/naturalHeight', e);
}

this.detectLongPage(this.naturalWidth(), this.naturalHeight())
}

Expand Down
Loading