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

Updated to @iiif/helpers and @iiif/parser v2 #20

Merged
merged 2 commits into from
Feb 12, 2024
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
6 changes: 3 additions & 3 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ name: Yarn build + test

on:
push:
branches: [ main ]
branches: [main]
pull_request:
branches: [ main ]
branches: [main]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node: [ '16', '14' ]
node: ['18', '20']

name: Node ${{ matrix.node }} build
steps:
Expand Down
65 changes: 65 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Release NPM package

on:
push:
tags: ['v*']

jobs:
build:
runs-on: ubuntu-latest
name: Node build
steps:
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: '18.x'

- name: Get yarn cache
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v1
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn

- run: yarn install --frozen-lockfile --non-interactive

- run: yarn run build

- run: yarn run test

release:
needs: [build]
runs-on: ubuntu-latest
name: Release
steps:
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: '18.x'

- name: Set tag
id: tagName
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}

- name: Get yarn cache
id: yarn-cache
run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/cache@v1
with:
path: ${{ steps.yarn-cache.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn

- run: yarn install --frozen-lockfile --non-interactive

- uses: JS-DevTools/npm-publish@v1
with:
token: ${{ secrets.NPM_TOKEN }}
115 changes: 115 additions & 0 deletions __tests__/canvas-builder.tests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IIIFBuilder } from '../src';
import { ContentResource } from '@iiif/presentation-3';
import { AnnotationNormalized } from '@iiif/presentation-3-normalized';

describe('Canvas builder', () => {
test('Ensure array works as expected', () => {
Expand Down Expand Up @@ -184,4 +185,118 @@ describe('Canvas builder', () => {
}
`);
});

test('Canvas with annotation page', () => {
const builder = new IIIFBuilder();
const manifest = builder.createManifest(
'https://preview.iiif.io/cookbook/3333-choice/recipe/0033-choice/manifest.json',
(manifest) => {
manifest.addLabel('John Dee performing an experiment before Queen Elizabeth I.', 'en');
manifest.createCanvas('https://preview.iiif.io/cookbook/3333-choice/recipe/0033-choice/canvas/p1', (canvas) => {
canvas.height = 1271;
canvas.width = 2000;

canvas.createAnnotation(
'https://preview.iiif.io/cookbook/3333-choice/recipe/0033-choice/annotation/p0001-image',
{
id: 'https://preview.iiif.io/cookbook/3333-choice/recipe/0033-choice/annotation/p0001-image',
type: 'Annotation',
motivation: 'painting',
body: {
id: 'https://iiif.io/api/image/3.0/example/reference/421e65be2ce95439b3ad6ef1f2ab87a9-dee-natural/full/max/0/default.jpg',
type: 'Image',
format: 'image/jpeg',
width: 2000,
height: 1271,
label: {
en: ['Natural Light'],
},
} as ContentResource,
}
);

canvas.createAnnotationPage(
'https://preview.iiif.io/cookbook/3333-choice/recipe/0033-choice/canvas/p1/annotations',
(annoPage) => {
annoPage.createAnnotation({
id: `${canvas.id}/annopage-2/anno-0`,
type: 'Annotation',
motivation: 'commenting',
body: {
type: 'TextualBody',
format: 'text/html',
value: '<p>Testing an annotation</p>',
},
target: canvas.id,
});
}
);
});
}
);

expect(builder.toPresentation3(manifest)).toMatchInlineSnapshot(`
{
"@context": "http://iiif.io/api/presentation/3/context.json",
"id": "https://preview.iiif.io/cookbook/3333-choice/recipe/0033-choice/manifest.json",
"items": [
{
"height": 1271,
"id": "https://preview.iiif.io/cookbook/3333-choice/recipe/0033-choice/canvas/p1",
"items": [
{
"id": "https://preview.iiif.io/cookbook/3333-choice/recipe/0033-choice/canvas/p1/annotation-page",
"items": [
{
"body": {
"format": "image/jpeg",
"height": 1271,
"id": "https://iiif.io/api/image/3.0/example/reference/421e65be2ce95439b3ad6ef1f2ab87a9-dee-natural/full/max/0/default.jpg",
"label": {
"en": [
"Natural Light",
],
},
"type": "Image",
"width": 2000,
},
"id": "https://preview.iiif.io/cookbook/3333-choice/recipe/0033-choice/annotation/p0001-image",
"motivation": "painting",
"target": "https://preview.iiif.io/cookbook/3333-choice/recipe/0033-choice/canvas/p1",
"type": "Annotation",
},
],
"type": "AnnotationPage",
},
{
"id": "https://preview.iiif.io/cookbook/3333-choice/recipe/0033-choice/canvas/p1/annotations",
"items": [
{
"body": {
"format": "text/html",
"type": "TextualBody",
"value": "<p>Testing an annotation</p>",
},
"id": "https://preview.iiif.io/cookbook/3333-choice/recipe/0033-choice/canvas/p1/annopage-2/anno-0",
"motivation": "commenting",
"target": "https://preview.iiif.io/cookbook/3333-choice/recipe/0033-choice/canvas/p1",
"type": "Annotation",
},
],
"type": "AnnotationPage",
},
],
"type": "Canvas",
"width": 2000,
},
],
"label": {
"en": [
"John Dee performing an experiment before Queen Elizabeth I.",
],
},
"type": "Manifest",
}
`);
});
});
6 changes: 6 additions & 0 deletions __tests__/collection-builder.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,19 @@ describe('Collection builder', () => {
collection.addSummary(summary, 'none');
collection.setHomepage({
id: homepage,
type: 'Text',
});
items.forEach((item) => {
collection.createCollection(item.id, (manifest) => {
manifest.addLabel(item.label, 'none');
manifest.addSummary(item.summary, 'none');
manifest.setHomepage({
id: homepage,
type: 'Text',
});
manifest.addThumbnail({
id: 'http://localhost:5001/...',
type: 'Image',
});
});
});
Expand All @@ -99,6 +102,7 @@ describe('Collection builder', () => {
"homepage": [
{
"id": "https://example.org/homepage",
"type": "Text",
},
],
"id": "https://example.org/collection-1",
Expand All @@ -118,6 +122,7 @@ describe('Collection builder', () => {
"thumbnail": [
{
"id": "http://localhost:5001/...",
"type": "Image",
},
],
"type": "Collection",
Expand All @@ -137,6 +142,7 @@ describe('Collection builder', () => {
"thumbnail": [
{
"id": "http://localhost:5001/...",
"type": "Image",
},
],
"type": "Collection",
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
"test": "jest"
},
"dependencies": {
"@iiif/parser": "1.x",
"@iiif/presentation-3": "1.x",
"@iiif/vault": "0.9.x || 1.x"
"@iiif/parser": "^2.0.2",
"@iiif/presentation-3": "^2.1.3",
"@iiif/presentation-3-normalized": "^0.9.7",
"@iiif/helpers": "^1.0.5"
},
"devDependencies": {
"@types/jest": "^27.4.0",
Expand Down
4 changes: 2 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const baseConfig = {
},
};

const external = ['@iiif/vault', '@iiif/vault/actions'];
const bundled = ['@iiif/parser'];
const external = ['@iiif/helpers/vault'];
const bundled = ['@iiif/parser', '@iiif/helpers/vault/actions'];
const nodeExternal = [];

// Roll up configs
Expand Down
3 changes: 2 additions & 1 deletion src/annotation-page-builder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Annotation, AnnotationPageNormalized, ChoiceBody } from '@iiif/presentation-3';
import { Annotation } from '@iiif/presentation-3';
import { AnnotationPageNormalized } from '@iiif/presentation-3-normalized';
import { IIIFBuilder } from './iiif-builder';
import { BaseEntityBuilder } from './base-entity-builder';

Expand Down
17 changes: 10 additions & 7 deletions src/base-entity-builder.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import {
CanvasNormalized,
CollectionNormalized,
MetadataItem,
ManifestNormalized,
InternationalString,
ContentResource,
Reference,
ViewingDirection,
CollectionItemSchemas,
AnnotationPageNormalized,
AnnotationPage,
Annotation,
SpecificResource,
} from '@iiif/presentation-3';
import { ServiceNormalized } from '@iiif/presentation-3/resources/service';
import {
CanvasNormalized,
CollectionNormalized,
ManifestNormalized,
AnnotationPageNormalized,
ServiceNormalized,
} from '@iiif/presentation-3-normalized';
import { IIIFBuilder } from './iiif-builder';
import { normalize } from '@iiif/parser';

Expand Down Expand Up @@ -396,11 +399,11 @@ export class BaseEntityBuilder<
}

// ✅ start
set start(start: Reference<'Canvas' | 'Selector'>) {
set start(start: SpecificResource<Reference<'Canvas'>> | null) {
this.setStart(start);
}

setStart(start: Reference<'Canvas' | 'Selector'>) {
setStart(start: SpecificResource<Reference<'Canvas'>> | null) {
if (this.isManifest(this.entity)) {
this.entity.start = start;
}
Expand Down
4 changes: 2 additions & 2 deletions src/canvas-builder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Annotation, CanvasNormalized } from '@iiif/presentation-3';

import { Annotation } from '@iiif/presentation-3';
import { CanvasNormalized } from '@iiif/presentation-3-normalized';
import { AnnotationPageInstanceBuilder } from './annotation-page-builder';
import { BaseEntityBuilder } from './base-entity-builder';
import { IIIFBuilder } from './iiif-builder';
Expand Down
2 changes: 1 addition & 1 deletion src/collection-builder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CollectionNormalized } from '@iiif/presentation-3';
import { CollectionNormalized } from '@iiif/presentation-3-normalized';
import { IIIFBuilder } from './iiif-builder';
import { BaseEntityBuilder } from './base-entity-builder';
import { emptyCollection, emptyManifest } from '@iiif/parser';
Expand Down
7 changes: 4 additions & 3 deletions src/iiif-builder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { emptyCollection, emptyManifest } from '@iiif/parser';
import { entityActions, mappingActions } from '@iiif/vault/actions';
import { Reference, ManifestNormalized, CollectionNormalized } from '@iiif/presentation-3';
import { Vault } from '@iiif/vault';
import { entityActions, mappingActions } from '@iiif/helpers/vault/actions';
import { Reference } from '@iiif/presentation-3';
import { ManifestNormalized, CollectionNormalized } from '@iiif/presentation-3-normalized';
import { Vault } from '@iiif/helpers/vault';
import { BaseEntityBuilder } from './base-entity-builder';
import { ManifestInstanceBuilder } from './manifest-builder';
import { CollectionInstanceBuilder } from './collection-builder';
Expand Down
2 changes: 1 addition & 1 deletion src/manifest-builder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { emptyCanvas } from '@iiif/parser';
import { CanvasNormalized, ManifestNormalized } from '@iiif/presentation-3';
import { CanvasNormalized, ManifestNormalized } from '@iiif/presentation-3-normalized';
import { IIIFBuilder } from './iiif-builder';
import { BaseEntityBuilder } from './base-entity-builder';
import { CanvasInstanceBuilder } from './canvas-builder';
Expand Down
Loading
Loading