Skip to content
Draft
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
7 changes: 0 additions & 7 deletions .codesandbox/ci.json

This file was deleted.

3 changes: 2 additions & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: ['18', '22']
node: ['22']

name: Node ${{ matrix.node }} build
steps:
Expand All @@ -31,3 +31,4 @@ jobs:
- run: node pkg-tests/node-load.cjs
- run: node pkg-tests/node-load.mjs
- run: node pkg-tests/node-umd.mjs
- run: pnpm dlx pkg-pr-new publish
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: '20.x'
node-version: '22.x'

- uses: pnpm/action-setup@v3
with:
Expand All @@ -36,7 +36,7 @@ jobs:
- name: Setup node
uses: actions/setup-node@v2
with:
node-version: '20.x'
node-version: '22.x'

- name: Set tag
id: tagName
Expand Down
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"singleQuote": true,
"singleQuote": false,
"printWidth": 120,
"trailingComma": "es5"
}
65 changes: 62 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ npm i @iiif/parser
This is a parser and set of low-level utilities for the following IIIF Specifications:

- [IIIF Presentation 3](https://iiif.io/api/presentation/3.0/) (current)
- [IIIF Presentation 4](https://preview.iiif.io/api/prezi-4/presentation/4.0/) (preview support via `/presentation-4`)
- [IIIF Image 3](https://iiif.io/api/image/3.0/) (current)
- [IIIF Presentation 2](https://iiif.io/api/presentation/2.1/)

Expand All @@ -16,12 +17,41 @@ These include:


> [!NOTE]
> A new version of the IIIF Presentation API is being developed (v4) which handles 3D content. This parser will
> support this version soon. You can read about the additions [here](https://github.com/IIIF/3d/blob/main/temp-draft-4.md)
> Presentation API v4 support is available from `@iiif/parser/presentation-4` and is designed for mixed v2.1/v3.0/v4.0 ingestion with a v4 normalization pipeline.

### Features
The features of this library are focussed on encoding the structure of all types of IIIF and providing utilities for extracting data from the IIIF or converting it into another format that is easier to develop with. The aim of the parser is to maximize the IIIF compatibility of other tools built on top of it.

#### Type Modules and DX Helpers

Type surfaces are available directly from parser subpaths:

- `@iiif/parser/presentation-2/types`
- `@iiif/parser/presentation-3/types`
- `@iiif/parser/presentation-3-normalized/types`
- `@iiif/parser/presentation-4/types`
- `@iiif/parser/presentation-4-normalized/types`

The versioned parser entrypoints also re-export `infer`, `cast` and `narrow` helpers:

```ts
import { infer, cast, narrow, type Manifest } from '@iiif/parser/presentation-3';

const manifest = {
id: 'https://example.org/manifest',
type: 'Manifest',
label: { en: ['Example'] },
items: [],
} satisfies Manifest;

const typed = infer.Manifest(manifest);
const checked = cast.Manifest(manifest);

if (narrow.isImage({ id: 'https://example.org/image.jpg', type: 'Image' })) {
// narrowed image resource
}
```

#### IIIF Presentation 3

- **Empty types** for each resource (e.g. Manifest, Canvas) which can be used as starting points for creating IIIF
Expand Down Expand Up @@ -104,6 +134,35 @@ export type TraversalMap = {
};
```

#### IIIF Presentation 4

- `upgradeToPresentation4()` to ingest v2.1, v3.0 or v4.0 into a v4-compatible shape
- `Traverse` with v4 container support (`Timeline`, `Canvas`, `Scene`)
- `normalize()` with deterministic ID minting for missing IDs
- `validatePresentation4()` with traversal-first diagnostics (`tolerant` or `strict`)
- `serializeConfigPresentation4` for native v4 output
- `serializeConfigPresentation3` for strict v4→v3 downgrade (fails on unsupported v4-only constructs)
- `pnpm run update-cookbook-v4` to refresh local `fixtures/cookbook-v4` from [preview cookbook v4](https://preview.iiif.io/cookbook/v4/)

```ts
import {
upgradeToPresentation4,
normalize,
validatePresentation4,
serialize,
serializeConfigPresentation4
} from '@iiif/parser/presentation-4';

const upgraded = upgradeToPresentation4(loadSomeManifest());
const report = validatePresentation4(upgraded);
const normalized = normalize(upgraded);
const serialized = serialize(
{ entities: normalized.entities, mapping: normalized.mapping, requests: {} },
normalized.resource,
serializeConfigPresentation4
);
```

#### Image 3

The Image 3 parser is adapted from an Image Server implementation, and supports:
Expand All @@ -128,7 +187,7 @@ The Image 3 parser is adapted from an Image Server implementation, and supports:

```ts
import { parseImageServiceRequest, imageServiceRequestInfo } from '@iiif/parser/image-3';
import { ImageService } from '@iiif/presentation-3';
import { ImageService } from '@iiif/parser/presentation-3/types';

const parsed = parseImageServiceRequest(
'https://munch.emuseum.com/apis/iiif/image/v2/17261/full/max/0/default.jpg',
Expand Down
2 changes: 1 addition & 1 deletion __tests__/image-3-parser/supports.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// noinspection DuplicatedCode

import { ImageService } from '@iiif/presentation-3';
import { ImageService } from '../../src/presentation-3/types';
import {
imageServiceRequestToString,
parseImageServiceRequest,
Expand Down
Loading
Loading