Skip to content

Commit

Permalink
Added annotation to rendering strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenwf committed Jan 13, 2025
1 parent 4a08663 commit 5ae43a1
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
},
"dependencies": {
"@atlas-viewer/atlas": "^2.2.9",
"@iiif/helpers": "^1.3.0",
"@iiif/helpers": "^1.3.1",
"@iiif/parser": "^2.1.7",
"@iiif/presentation-2": "^1.0.4",
"@iiif/presentation-3": "^2.2.3",
Expand Down
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/features/rendering-strategy/3d-strategy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CanvasNormalized } from '@iiif/presentation-3-normalized';
import { AnnotationNormalized, CanvasNormalized } from '@iiif/presentation-3-normalized';
import { unsupportedStrategy } from './rendering-utils';
import { AnnotationPageDescription } from './resource-types';
import { ExternalWebResource } from '@iiif/presentation-3';
Expand All @@ -10,6 +10,8 @@ export type Single3DModelStrategy = {
model: ExternalWebResource;
choice?: ChoiceDescription; // future
annotations?: AnnotationPageDescription; // future
annotation: AnnotationNormalized;
annotationId: string;
};

const supportedFormats = ['model/gltf-binary'];
Expand All @@ -29,5 +31,7 @@ export function get3dStrategy(canvas: CanvasNormalized, paintables: Paintables):
return {
type: '3d-model',
model: resource as any,
annotationId: first.annotationId,
annotation: first.annotation,
} as Single3DModelStrategy;
}
16 changes: 12 additions & 4 deletions src/features/rendering-strategy/audio-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,36 @@ import { MediaStrategy } from './strategies';
import { Paintables } from '@iiif/helpers';

export function getAudioStrategy(canvas: CanvasNormalized, paintables: Paintables) {
const items = paintables.items;
const audio = items[0];

if (items.length === 0 || !audio) {
return unsupportedStrategy('No audio');
}

if (!canvas.duration) {
return unsupportedStrategy('No duration on canvas');
}

if (paintables.items.length > 1) {
if (items.length > 1) {
return unsupportedStrategy('Only one audio source supported');
}

const audioResource = paintables.items[0]?.resource as any; // @todo stronger type for what this might be.
const audioResource = audio.resource; // @todo stronger type for what this might be.

if (!audioResource) {
return unsupportedStrategy('Unknown audio');
}

if (!audioResource.format) {
if (!('format' in audioResource)) {
return unsupportedStrategy('Audio does not have format');
}

return {
type: 'media',
media: {
annotationId: paintables.items[0].annotationId,
annotationId: audio.annotationId,
annotation: audio.annotation,
duration: canvas.duration,
url: audioResource.id,
type: 'Sound',
Expand Down
2 changes: 1 addition & 1 deletion src/features/rendering-strategy/complex-timeline.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CanvasNormalized } from '@iiif/presentation-3-normalized';
import { ChoiceDescription, ComplexChoice, Paintables, Vault } from '@iiif/helpers';
import { ChoiceDescription, ComplexChoice, Paintables } from '@iiif/helpers';
import { ComplexTimelineStrategy } from './strategies';
import { getImageStrategy } from './image-strategy';
import { ImageServiceLoaderType } from '../../hooks/useLoadImageService';
Expand Down
1 change: 0 additions & 1 deletion src/features/rendering-strategy/get-rendering-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type { CanvasNormalized } from '@iiif/presentation-3-normalized';
import type { Paintables } from '@iiif/helpers/painting-annotations';
import type { ImageServiceLoaderType } from '../../hooks/useLoadImageService';
import { getComplexTimelineStrategy } from './complex-timeline';
import { Vault } from '@iiif/helpers';
import { CompatVault, compatVault } from '../../utility/compat-vault';

interface GetRenderStrategyOptions {
Expand Down
3 changes: 2 additions & 1 deletion src/features/rendering-strategy/image-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ export function getImageStrategy(
const imageType: ImageWithOptionalService = {
id: resource.id,
type: 'Image',
annotationId: (singleImage as any).annotationId,
annotationId: singleImage.annotationId,
annotation: singleImage.annotation,
width: Number(target || selector ? resource.width : canvas.width),
height: Number(target || selector ? resource.height : canvas.height),
service: imageService,
Expand Down
6 changes: 5 additions & 1 deletion src/features/rendering-strategy/resource-types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { ImageService } from '@iiif/presentation-3';
import { AnnotationPageNormalized } from '@iiif/presentation-3-normalized';
import { AnnotationNormalized, AnnotationPageNormalized } from '@iiif/presentation-3-normalized';
import { BoxSelector, TemporalBoxSelector, TemporalSelector } from '@iiif/helpers/annotation-targets';

export type ImageWithOptionalService = {
id: string;
annotationId: string;
annotation: AnnotationNormalized;
type: 'Image';
service?: ImageService;
width?: number;
Expand All @@ -20,6 +21,7 @@ export type ImageWithOptionalService = {
export type SingleAudio = {
type: 'Sound';
annotationId: string;
annotation: AnnotationNormalized;
url: string;
format: string;
duration: number;
Expand All @@ -33,6 +35,7 @@ export type SingleAudio = {
export type SingleYouTubeVideo = {
type: 'VideoYouTube';
annotationId: string;
annotation: AnnotationNormalized;
url: string;
youTubeId: string;
duration: number;
Expand All @@ -43,6 +46,7 @@ export type SingleYouTubeVideo = {
export type SingleVideo = {
type: 'Video';
annotationId: string;
annotation: AnnotationNormalized;
url: string;
format: string;
duration: number;
Expand Down
6 changes: 4 additions & 2 deletions src/features/rendering-strategy/textual-content-strategy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { InternationalString } from '@iiif/presentation-3';
import { CanvasNormalized } from '@iiif/presentation-3-normalized';
import { AnnotationNormalized, CanvasNormalized } from '@iiif/presentation-3-normalized';
import { AnnotationPageDescription } from './resource-types';
import { getParsedTargetSelector } from './rendering-utils';
import { RenderingStrategy } from './strategies';
Expand All @@ -14,9 +14,10 @@ export type TextualContentStrategy = {

export type TextContent = {
type: 'Text';
annotationId: string;
text: InternationalString;
target: SupportedTarget | null;
annotationId: string;
annotation: AnnotationNormalized;
};

function parseType(item: any, languageMap: InternationalString = {}, lang?: string) {
Expand Down Expand Up @@ -48,6 +49,7 @@ export function getTextualContentStrategy(canvas: CanvasNormalized, paintables:
items.push({
type: 'Text',
annotationId: item.annotationId,
annotation: item.annotation,
text: parseType(item.resource),
target: target as any,
});
Expand Down
8 changes: 4 additions & 4 deletions src/features/rendering-strategy/video-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ export function getVideoStrategy(
vault: CompatVault
): UnknownStrategy | MediaStrategy {
const videoPaintables = paintables.items.filter((t) => t.type === 'video');
const video = videoPaintables[0];

let noDuration = false;

if (!canvas.duration) {
noDuration = true;
}

if (videoPaintables.length > 1) {
if (videoPaintables.length > 1 || !video) {
return unsupportedStrategy('Only one video source supported');
}

Expand Down Expand Up @@ -87,10 +88,9 @@ export function getVideoStrategy(
}
}

const video = paintables.items[0];

const media: SingleVideo | SingleYouTubeVideo = {
annotationId: (paintables.items[0] as any).annotationId,
annotationId: video.annotationId,
annotation: video.annotation,
duration: canvas.duration,
url: videoResource.id,
type: 'Video',
Expand Down

0 comments on commit 5ae43a1

Please sign in to comment.