react-iiif-vault 1.0.6 → 1.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle/cjs/index.js +1 -1
- package/dist/bundle/cjs/index.js.map +1 -1
- package/dist/bundle/esm/index.mjs +19 -18
- package/dist/bundle/esm/index.mjs.map +1 -1
- package/dist/canvas-panel/cjs/canvas-panel.js +2 -2
- package/dist/canvas-panel/cjs/canvas-panel.js.map +1 -1
- package/dist/canvas-panel/esm/canvas-panel.mjs +226 -225
- package/dist/canvas-panel/esm/canvas-panel.mjs.map +1 -1
- package/dist/index.umd.js +43 -43
- package/dist/index.umd.js.map +1 -1
- package/dist/react17/cjs/index.js +1 -1
- package/dist/react17/cjs/index.js.map +1 -1
- package/dist/react17/esm/index.mjs +19 -18
- package/dist/react17/esm/index.mjs.map +1 -1
- package/dist/utils/cjs/utils.js +1 -1
- package/dist/utils/cjs/utils.js.map +1 -1
- package/dist/utils/esm/utils.mjs +101 -100
- package/dist/utils/esm/utils.mjs.map +1 -1
- package/package.json +2 -2
package/dist/utils/cjs/utils.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("@iiif/helpers"),w=require("@atlas-viewer/iiif-image-api"),g=require("@iiif/helpers/annotation-targets");function I(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function m(e,
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("@iiif/helpers"),w=require("@atlas-viewer/iiif-image-api"),g=require("@iiif/helpers/annotation-targets");function I(e){return e.type==="SpecificResource"?[e.source,{selector:e.selector}]:[e,{selector:null}]}function m(e,o){const{selector:r,source:i}=T.expandTarget(o);if(i.id!==e.id)return[null,i];const t={type:"BoxSelector",spatial:{x:0,y:0,width:Number(e.width),height:Number(e.height)}};return[r?r.type==="TemporalSelector"?{type:"TemporalBoxSelector",temporal:r.temporal,spatial:t.spatial}:r:null,i]}const R={makeChoice:()=>{}},f={type:"unknown"},n=e=>({type:"unknown",reason:e,annotations:{pages:[]}}),y=(e,o)=>({type:"empty",width:e,height:o,annotations:{pages:[]},image:null,images:[]}),O=["model/gltf-binary"];function k(e,o){const i=o.items[0].resource;return i.format?O.indexOf(i.format)===-1?n(`3D format: ${i.format} is unsupported`):{type:"3d-model",model:i}:n("Unknown format")}function N(e,o){var i;if(!e.duration)return n("No duration on canvas");if(o.items.length>1)return n("Only one audio source supported");const r=(i=o.items[0])==null?void 0:i.resource;return r?r.format?{type:"media",media:{annotationId:o.items[0].annotationId,duration:e.duration,url:r.id,type:"Sound",target:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}},format:r.format,selector:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}}},annotations:{pages:[]}}:n("Audio does not have format"):n("Unknown audio")}function v(e,o,r){const i=[];for(const t of o.items){const u=t.resource&&t.resource.type==="SpecificResource"?t.resource.source:t.resource;if(!u.id)return n("No resource Identifier");let s;if(u.service){const a=w.getImageServices(u);a[0]&&(s=r(a[0],e))}const l={type:"BoxSelector",spatial:{x:0,y:0,width:Number(e.width),height:Number(e.height)}},[d,S]=m(e,t.target);if(S.id!==e.id)continue;t.resource.width&&t.resource.height&&(t.resource.width,t.resource.height);let c=t.resource.type==="SpecificResource"?g.expandTarget(t.resource):null;if(t.selector){const a=g.expandTarget({type:"SpecificResource",source:t.resource,selector:t.selector});a&&(c=a)}const p=c&&c.selector&&(c.selector.type==="BoxSelector"||c.selector.type==="TemporalBoxSelector")?{type:"BoxSelector",spatial:{x:c.selector.spatial.x,y:c.selector.spatial.y,width:c.selector.spatial.width,height:c.selector.spatial.height}}:void 0;s&&!s.id&&(s.id=s["@id"]);const x={id:u.id,type:"Image",annotationId:t.annotationId,width:Number(d||p?u.width:e.width),height:Number(d||p?u.height:e.height),service:s,sizes:s&&s.sizes?s.sizes:u.width&&u.height?[{width:u.width,height:u.height}]:[],target:d&&d.type!=="PointSelector"?d:l,selector:p};i.push(x)}return{type:"images",image:i[0],images:i,choice:o.choice}}function h(e,o={},r){const i=e.language||r||"none";switch(e.type){case"TextualBody":{typeof e.value<"u"&&(o[i]=e.value);break}case"List":case"Composite":case"Choice":e.items&&e.items.forEach(t=>h(t,o,i))}return o}function B(e,o){const r=[];return o.items.forEach(i=>{if(i.resource){const[t]=m(e,i.target);r.push({annotationId:i.annotationId,text:h(i.resource),target:t})}}),{type:"textual-content",items:r}}const C=/^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/|shorts\/)|(?:(?:watch)?\?vi?=|&vi?=))([^#&?]*).*/;function V(e,o){var l;const r=o.items.filter(d=>d.type==="video");let i=!1;if(e.duration||(i=!0),r.length>1)return n("Only one video source supported");const t=(l=r[0])==null?void 0:l.resource,u=!!(t.service||[]).find(d=>(d.profile||"").includes("youtube.com"));if(!u&&i)return n("Video does not have duration");if(!t)return n("Unknown video");if((!t.format||t.format==="text/html")&&!u)return n("Video does not have format");const s={annotationId:o.items[0].annotationId,duration:e.duration,url:t.id,type:"Video",items:[],target:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}},format:t.format,selector:{type:"TemporalSelector",temporal:{startTime:0,endTime:e.duration}}};if(u){s.type="VideoYouTube";const d=t.id.match(C);if(!d[1])return n("Video is not known youtube video");s.youTubeId=d[1]}return{type:"media",media:s,annotations:{pages:[]}}}function b({canvas:e,paintables:o,supports:r,loadImageService:i}){if(!e)return console.log("No canvas"),f;if(o.types.length===0)return r.indexOf("empty")!==-1?y(e.width,e.height):(console.log("No paintables"),f);if(o.types.length!==1)if(o.types.length===2&&o.types.indexOf("text")!==-1)o.types=o.types.filter(u=>u!=="text");else return r.indexOf("complex-timeline")===-1?n("Complex timeline not supported"):n("ComplexTimelineStrategy not yet supported");const t=o.types[0];return t==="image"?r.indexOf("images")===-1?n("Image not supported"):v(e,o,i):t==="Model"||t==="model"?r.indexOf("3d-model")===-1?n("3D not supported"):k(e,o):t==="textualbody"?r.indexOf("textual-content")===-1?n("Textual content not supported"):B(e,o):t==="sound"||t==="audio"?r.indexOf("media")===-1?n("Media not supported"):N(e,o):t==="video"?r.indexOf("media")===-1?n("Media not supported"):V(e,o):f}exports.emptyActions=R;exports.emptyStrategy=y;exports.getParsedTargetSelector=m;exports.getRenderingStrategy=b;exports.parseSpecificResource=I;exports.unknownResponse=f;exports.unsupportedStrategy=n;
|
|
2
2
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../../src/features/rendering-strategy/rendering-utils.ts","../../../src/features/rendering-strategy/3d-strategy.ts","../../../src/features/rendering-strategy/audio-strategy.ts","../../../src/features/rendering-strategy/image-strategy.ts","../../../src/features/rendering-strategy/textual-content-strategy.ts","../../../src/features/rendering-strategy/video-strategy.ts","../../../src/features/rendering-strategy/get-rendering-strategy.ts"],"sourcesContent":["import { ContentResource, PointSelector, W3CAnnotationTarget } from '@iiif/presentation-3';\nimport { CanvasNormalized } from '@iiif/presentation-3-normalized';\nimport { UseRenderingStrategy } from '../../hooks/useRenderingStrategy';\nimport { BoxSelector, expandTarget, SupportedTarget, TemporalBoxSelector } from '@iiif/helpers';\n\n/**\n * Parse specific resource.\n *\n * This could be expanded to support pulling out more from the specific resource.\n *\n * @param resource\n */\nexport function parseSpecificResource(resource: ContentResource) {\n if (resource.type === 'SpecificResource') {\n return [resource.source, { selector: resource.selector }];\n }\n\n return [resource, { selector: null }];\n}\n\nexport function getParsedTargetSelector(\n canvas: CanvasNormalized,\n target: W3CAnnotationTarget | W3CAnnotationTarget[]\n): [TemporalBoxSelector | BoxSelector | PointSelector | null, SupportedTarget['source']] {\n const { selector: imageTarget, source } = expandTarget(target);\n\n if (source.id !== canvas.id) {\n // Skip invalid targets.\n return [null, source];\n }\n\n // Target is where it should be painted.\n const defaultTarget: BoxSelector = {\n type: 'BoxSelector',\n spatial: {\n x: 0,\n y: 0,\n width: Number(canvas.width),\n height: Number(canvas.height),\n },\n };\n\n return [\n imageTarget\n ? imageTarget.type === 'TemporalSelector'\n ? ({\n type: 'TemporalBoxSelector',\n temporal: imageTarget.temporal,\n spatial: defaultTarget.spatial,\n } as any)\n : imageTarget\n : null,\n source,\n ];\n}\n\nexport const emptyActions = {\n makeChoice: () => {\n // no-op\n },\n};\n\nexport const unknownResponse: UseRenderingStrategy[0] = { type: 'unknown' };\n\nexport const unsupportedStrategy = (reason: string): UseRenderingStrategy[0] => {\n return { type: 'unknown', reason, annotations: { pages: [] } };\n};\n\nexport const emptyStrategy = (width: number, height: number): UseRenderingStrategy[0] => {\n return { type: 'empty', width, height, annotations: { pages: [] }, image: null, images: [] };\n};\n","import { CanvasNormalized } from '@iiif/presentation-3-normalized';\nimport { unsupportedStrategy } from './rendering-utils';\nimport { AnnotationPageDescription } from './resource-types';\nimport { ExternalWebResource } from '@iiif/presentation-3';\nimport { RenderingStrategy } from './strategies';\nimport { ChoiceDescription, Paintables } from '@iiif/helpers';\n\nexport type Single3DModelStrategy = {\n type: '3d-model';\n model: ExternalWebResource;\n choice?: ChoiceDescription; // future\n annotations?: AnnotationPageDescription; // future\n};\n\nconst supportedFormats = ['model/gltf-binary'];\n\nexport function get3dStrategy(canvas: CanvasNormalized, paintables: Paintables): RenderingStrategy {\n const first = paintables.items[0];\n const resource = first.resource as ExternalWebResource;\n\n if (!resource.format) {\n return unsupportedStrategy('Unknown format');\n }\n\n if (supportedFormats.indexOf(resource.format) === -1) {\n return unsupportedStrategy(`3D format: ${resource.format} is unsupported`);\n }\n\n return {\n type: '3d-model',\n model: resource as any,\n } as Single3DModelStrategy;\n}\n","import { CanvasNormalized } from '@iiif/presentation-3-normalized';\nimport { unsupportedStrategy } from './rendering-utils';\nimport { MediaStrategy } from './strategies';\nimport { Paintables } from '@iiif/helpers';\n\nexport function getAudioStrategy(canvas: CanvasNormalized, paintables: Paintables) {\n if (!canvas.duration) {\n return unsupportedStrategy('No duration on canvas');\n }\n\n if (paintables.items.length > 1) {\n return unsupportedStrategy('Only one audio source supported');\n }\n\n const audioResource = paintables.items[0]?.resource as any; // @todo stronger type for what this might be.\n\n if (!audioResource) {\n return unsupportedStrategy('Unknown audio');\n }\n\n if (!audioResource.format) {\n return unsupportedStrategy('Audio does not have format');\n }\n\n return {\n type: 'media',\n media: {\n annotationId: paintables.items[0].annotationId,\n duration: canvas.duration,\n url: audioResource.id,\n type: 'Sound',\n target: {\n type: 'TemporalSelector',\n temporal: {\n startTime: 0,\n endTime: canvas.duration,\n },\n },\n format: audioResource.format,\n selector: {\n type: 'TemporalSelector',\n temporal: {\n startTime: 0,\n endTime: canvas.duration,\n },\n },\n },\n annotations: {\n pages: [],\n },\n } as MediaStrategy;\n}\n","import { IIIFExternalWebResource } from '@iiif/presentation-3';\nimport { CanvasNormalized } from '@iiif/presentation-3-normalized';\nimport { ImageServiceLoaderType } from '../../hooks/useLoadImageService';\nimport { AnnotationPageDescription, ImageWithOptionalService } from './resource-types';\nimport { getImageServices } from '@atlas-viewer/iiif-image-api';\nimport { getParsedTargetSelector, unsupportedStrategy } from './rendering-utils';\nimport { expandTarget } from '@iiif/helpers/annotation-targets';\nimport { BoxSelector, ChoiceDescription, Paintables } from '@iiif/helpers';\n\nexport type SingleImageStrategy = {\n type: 'images';\n image: ImageWithOptionalService;\n images: Array<ImageWithOptionalService>;\n choice?: ChoiceDescription;\n annotations?: AnnotationPageDescription;\n};\n\nexport function getImageStrategy(\n canvas: CanvasNormalized,\n paintables: Paintables,\n loadImageService: ImageServiceLoaderType\n) {\n const imageTypes: ImageWithOptionalService[] = [];\n for (const singleImage of paintables.items) {\n // SingleImageStrategy\n const resource: IIIFExternalWebResource =\n singleImage.resource && singleImage.resource.type === 'SpecificResource'\n ? singleImage.resource.source\n : singleImage.resource;\n\n // Validation.\n if (!resource.id) {\n // @todo we could skip this?\n return unsupportedStrategy('No resource Identifier');\n }\n\n let imageService = undefined;\n if (resource.service) {\n const imageServices = getImageServices(resource as any) as any[];\n if (imageServices[0]) {\n imageService = loadImageService(imageServices[0], canvas);\n }\n }\n\n // Target is where it should be painted.\n const defaultTarget: BoxSelector = {\n type: 'BoxSelector',\n spatial: {\n x: 0,\n y: 0,\n width: Number(canvas.width),\n height: Number(canvas.height),\n },\n };\n\n const [target, source] = getParsedTargetSelector(canvas, singleImage.target);\n if (source.id !== canvas.id) {\n // Skip invalid targets.\n continue;\n }\n\n // Support for cropping before painting an annotation.\n // @todo this isn't working.\n const defaultImageSelector =\n (singleImage.resource as any).width && (singleImage.resource as any).height\n ? ({\n type: 'BoxSelector',\n spatial: {\n x: 0,\n y: 0,\n width: (singleImage.resource as any).width,\n height: (singleImage.resource as any).height,\n },\n } as BoxSelector)\n : undefined;\n\n let imageSelector = singleImage.resource.type === 'SpecificResource' ? expandTarget(singleImage.resource) : null;\n\n if (singleImage.selector) {\n const found = expandTarget({\n type: 'SpecificResource',\n source: singleImage.resource,\n selector: singleImage.selector,\n });\n\n if (found) {\n imageSelector = found;\n }\n }\n\n const selector: undefined | BoxSelector =\n imageSelector &&\n imageSelector.selector &&\n (imageSelector.selector.type === 'BoxSelector' || imageSelector.selector.type === 'TemporalBoxSelector')\n ? {\n type: 'BoxSelector',\n spatial: {\n x: imageSelector.selector.spatial.x,\n y: imageSelector.selector.spatial.y,\n width: imageSelector.selector.spatial.width,\n height: imageSelector.selector.spatial.height,\n },\n }\n : undefined;\n\n if (imageService && !imageService.id) {\n (imageService as any).id = imageService['@id'];\n }\n\n const imageType: ImageWithOptionalService = {\n id: resource.id,\n type: 'Image',\n annotationId: (singleImage as any).annotationId,\n width: Number(target || selector ? resource.width : canvas.width),\n height: Number(target || selector ? resource.height : canvas.height),\n service: imageService,\n sizes:\n imageService && imageService.sizes\n ? imageService.sizes\n : resource.width && resource.height\n ? [{ width: resource.width, height: resource.height }]\n : [],\n target: target && target.type !== 'PointSelector' ? target : defaultTarget,\n selector: selector,\n };\n\n imageTypes.push(imageType);\n }\n\n return {\n type: 'images',\n image: imageTypes[0],\n images: imageTypes,\n choice: paintables.choice,\n } as SingleImageStrategy;\n}\n","import { InternationalString } from '@iiif/presentation-3';\nimport { CanvasNormalized } from '@iiif/presentation-3-normalized';\nimport { AnnotationPageDescription } from './resource-types';\nimport { getParsedTargetSelector } from './rendering-utils';\nimport { RenderingStrategy } from './strategies';\nimport { ChoiceDescription, Paintables, SupportedTarget } from '@iiif/helpers';\n\nexport type TextualContentStrategy = {\n type: 'textual-content';\n items: { annotationId: string; text: InternationalString; target: SupportedTarget | null }[];\n choice?: ChoiceDescription; // future\n annotations?: AnnotationPageDescription; // future\n};\n\nfunction parseType(item: any, languageMap: InternationalString = {}, lang?: string) {\n const language = item.language || lang || 'none';\n switch (item.type) {\n case 'TextualBody': {\n if (typeof item.value !== 'undefined') {\n languageMap[language] = item.value;\n }\n break;\n }\n case 'List':\n case 'Composite':\n case 'Choice': {\n if (item.items) {\n item.items.forEach((inner: any) => parseType(inner, languageMap, language));\n }\n }\n }\n return languageMap;\n}\n\nexport function getTextualContentStrategy(canvas: CanvasNormalized, paintables: Paintables): RenderingStrategy {\n const items: TextualContentStrategy['items'] = [];\n\n paintables.items.forEach((item) => {\n if (item.resource) {\n const [target] = getParsedTargetSelector(canvas, item.target);\n items.push({ annotationId: item.annotationId, text: parseType(item.resource), target: target as any });\n }\n });\n\n return {\n type: 'textual-content',\n items,\n } as TextualContentStrategy;\n}\n","import { CanvasNormalized } from '@iiif/presentation-3-normalized';\nimport { unsupportedStrategy } from './rendering-utils';\nimport { MediaStrategy } from './strategies';\nimport { Paintables } from '@iiif/helpers';\n\n// https://stackoverflow.com/a/27728417\nconst ytRegex = /^.*(?:(?:youtu\\.be\\/|v\\/|vi\\/|u\\/\\w\\/|embed\\/|shorts\\/)|(?:(?:watch)?\\?vi?=|&vi?=))([^#&?]*).*/;\n\nexport function getVideoStrategy(canvas: CanvasNormalized, paintables: Paintables) {\n const videoPaintables = paintables.items.filter((t) => t.type === 'video');\n\n if (!canvas.duration) {\n return unsupportedStrategy('No duration on canvas');\n }\n\n if (videoPaintables.length > 1) {\n return unsupportedStrategy('Only one video source supported');\n }\n\n const audioResource = videoPaintables[0]?.resource as any; // @todo stronger type for what this might be.\n const isYouTube = !!(audioResource.service || []).find((service: any) =>\n (service.profile || '').includes('youtube.com')\n );\n\n if (!audioResource) {\n return unsupportedStrategy('Unknown video');\n }\n\n if (!audioResource.format || audioResource.format === 'text/html') {\n if (!isYouTube) {\n return unsupportedStrategy('Video does not have format');\n }\n }\n\n const media = {\n annotationId: (paintables.items[0] as any).annotationId,\n duration: canvas.duration,\n url: audioResource.id,\n type: 'Video',\n items: [],\n target: {\n type: 'TemporalSelector',\n temporal: {\n startTime: 0,\n endTime: canvas.duration,\n },\n },\n format: audioResource.format,\n selector: {\n type: 'TemporalSelector',\n temporal: {\n startTime: 0,\n endTime: canvas.duration,\n },\n },\n };\n\n if (isYouTube) {\n media.type = 'VideoYouTube';\n const id = audioResource.id.match(ytRegex);\n if (!id[1]) {\n return unsupportedStrategy('Video is not known youtube video');\n }\n (media as any).youTubeId = id[1];\n }\n\n // @todo support VTT\n\n return {\n type: 'media',\n media,\n annotations: {\n pages: [],\n },\n } as MediaStrategy;\n}\n","import { get3dStrategy } from './3d-strategy';\nimport { getAudioStrategy } from './audio-strategy';\nimport { getImageStrategy } from './image-strategy';\nimport { emptyStrategy, unknownResponse, unsupportedStrategy } from './rendering-utils';\nimport { getTextualContentStrategy } from './textual-content-strategy';\nimport { getVideoStrategy } from './video-strategy';\nimport type { CanvasNormalized } from '@iiif/presentation-3-normalized';\nimport type { Paintables } from '@iiif/helpers/painting-annotations';\nimport type { ImageServiceLoaderType } from '../../hooks/useLoadImageService';\n\ninterface GetRenderStrategyOptions {\n canvas: CanvasNormalized | null | undefined;\n paintables: Paintables;\n supports: string[];\n loadImageService: ImageServiceLoaderType;\n}\n\nexport function getRenderingStrategy({ canvas, paintables, supports, loadImageService }: GetRenderStrategyOptions) {\n if (!canvas) {\n console.log('No canvas');\n return unknownResponse;\n }\n\n if (paintables.types.length === 0) {\n if (supports.indexOf('empty') !== -1) {\n return emptyStrategy(canvas.width, canvas.height);\n }\n console.log('No paintables');\n return unknownResponse;\n }\n\n if (paintables.types.length !== 1) {\n if (paintables.types.length === 2 && paintables.types.indexOf('text') !== -1) {\n paintables.types = paintables.types.filter((t) => t !== 'text');\n } else {\n if (supports.indexOf('complex-timeline') === -1) {\n return unsupportedStrategy('Complex timeline not supported');\n }\n return unsupportedStrategy('ComplexTimelineStrategy not yet supported');\n }\n }\n\n const mainType = paintables.types[0];\n\n // Image\n if (mainType === 'image') {\n if (supports.indexOf('images') === -1) {\n return unsupportedStrategy('Image not supported');\n }\n\n return getImageStrategy(canvas, paintables, loadImageService);\n }\n\n // 3D\n if (mainType === 'Model' || mainType === 'model') {\n if (supports.indexOf('3d-model') === -1) {\n return unsupportedStrategy('3D not supported');\n }\n\n return get3dStrategy(canvas, paintables);\n }\n\n if (mainType === 'textualbody') {\n if (supports.indexOf('textual-content') === -1) {\n return unsupportedStrategy('Textual content not supported');\n }\n\n return getTextualContentStrategy(canvas, paintables);\n }\n\n if (mainType === 'sound' || mainType === 'audio') {\n if (supports.indexOf('media') === -1) {\n return unsupportedStrategy('Media not supported');\n }\n\n // Media Strategy with audio or audio sequence.\n return getAudioStrategy(canvas, paintables);\n }\n\n if (mainType === 'video') {\n if (supports.indexOf('media') === -1) {\n return unsupportedStrategy('Media not supported');\n }\n\n // Media Strategy with video or video sequence.\n return getVideoStrategy(canvas, paintables);\n }\n\n // Unknown fallback.\n return unknownResponse;\n}\n"],"names":["parseSpecificResource","resource","getParsedTargetSelector","canvas","target","imageTarget","source","expandTarget","defaultTarget","emptyActions","unknownResponse","unsupportedStrategy","reason","emptyStrategy","width","height","supportedFormats","get3dStrategy","paintables","getAudioStrategy","audioResource","_a","getImageStrategy","loadImageService","imageTypes","singleImage","imageService","imageServices","getImageServices","imageSelector","found","selector","imageType","parseType","item","languageMap","lang","language","inner","getTextualContentStrategy","items","ytRegex","getVideoStrategy","videoPaintables","t","isYouTube","service","media","id","getRenderingStrategy","supports","mainType"],"mappings":"yMAYO,SAASA,EAAsBC,EAA2B,CAC3D,OAAAA,EAAS,OAAS,mBACb,CAACA,EAAS,OAAQ,CAAE,SAAUA,EAAS,SAAU,EAGnD,CAACA,EAAU,CAAE,SAAU,IAAM,CAAA,CACtC,CAEgB,SAAAC,EACdC,EACAC,EACuF,CACvF,KAAM,CAAE,SAAUC,EAAa,OAAAC,CAAO,EAAIC,EAAAA,aAAaH,CAAM,EAEzD,GAAAE,EAAO,KAAOH,EAAO,GAEhB,MAAA,CAAC,KAAMG,CAAM,EAItB,MAAME,EAA6B,CACjC,KAAM,cACN,QAAS,CACP,EAAG,EACH,EAAG,EACH,MAAO,OAAOL,EAAO,KAAK,EAC1B,OAAQ,OAAOA,EAAO,MAAM,CAC9B,CAAA,EAGK,MAAA,CACLE,EACIA,EAAY,OAAS,mBAClB,CACC,KAAM,sBACN,SAAUA,EAAY,SACtB,QAASG,EAAc,SAEzBH,EACF,KACJC,CAAA,CAEJ,CAEO,MAAMG,EAAe,CAC1B,WAAY,IAAM,CAElB,CACF,EAEaC,EAA2C,CAAE,KAAM,SAAU,EAE7DC,EAAuBC,IAC3B,CAAE,KAAM,UAAW,OAAAA,EAAQ,YAAa,CAAE,MAAO,CAAC,CAAA,IAG9CC,EAAgB,CAACC,EAAeC,KACpC,CAAE,KAAM,QAAS,MAAAD,EAAO,OAAAC,EAAQ,YAAa,CAAE,MAAO,CAAA,CAAM,EAAA,MAAO,KAAM,OAAQ,CAAG,CAAA,GCvDvFC,EAAmB,CAAC,mBAAmB,EAE7B,SAAAC,EAAcd,EAA0Be,EAA2C,CAEjG,MAAMjB,EADQiB,EAAW,MAAM,CAAC,EACT,SAEnB,OAACjB,EAAS,OAIVe,EAAiB,QAAQf,EAAS,MAAM,IAAM,GACzCU,EAAoB,cAAcV,EAAS,MAAM,iBAAiB,EAGpE,CACL,KAAM,WACN,MAAO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OAAIiC,IAAa,QACXD,EAAS,QAAQ,QAAQ,IAAM,GAC1BvC,EAAoB,qBAAqB,EAG3CW,EAAiBnB,EAAQe,EAAYK,CAAgB,EAI1D4B,IAAa,SAAWA,IAAa,QACnCD,EAAS,QAAQ,UAAU,IAAM,GAC5BvC,EAAoB,kBAAkB,EAGxCM,EAAcd,EAAQe,CAAU,EAGrCiC,IAAa,cACXD,EAAS,QAAQ,iBAAiB,IAAM,GACnCvC,EAAoB,+BAA+B,EAGrD4B,EAA0BpC,EAAQe,CAAU,EAGjDiC,IAAa,SAAWA,IAAa,QACnCD,EAAS,QAAQ,OAAO,IAAM,GACzBvC,EAAoB,qBAAqB,EAI3CQ,EAAiBhB,EAAQe,CAAU,EAGxCiC,IAAa,QACXD,EAAS,QAAQ,OAAO,IAAM,GACzBvC,EAAoB,qBAAqB,EAI3C+B,EAAiBvC,EAAQe,CAAU,EAIrCR,CACT"}
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../../src/features/rendering-strategy/rendering-utils.ts","../../../src/features/rendering-strategy/3d-strategy.ts","../../../src/features/rendering-strategy/audio-strategy.ts","../../../src/features/rendering-strategy/image-strategy.ts","../../../src/features/rendering-strategy/textual-content-strategy.ts","../../../src/features/rendering-strategy/video-strategy.ts","../../../src/features/rendering-strategy/get-rendering-strategy.ts"],"sourcesContent":["import { ContentResource, PointSelector, W3CAnnotationTarget } from '@iiif/presentation-3';\nimport { CanvasNormalized } from '@iiif/presentation-3-normalized';\nimport { UseRenderingStrategy } from '../../hooks/useRenderingStrategy';\nimport { BoxSelector, expandTarget, SupportedTarget, TemporalBoxSelector } from '@iiif/helpers';\n\n/**\n * Parse specific resource.\n *\n * This could be expanded to support pulling out more from the specific resource.\n *\n * @param resource\n */\nexport function parseSpecificResource(resource: ContentResource) {\n if (resource.type === 'SpecificResource') {\n return [resource.source, { selector: resource.selector }];\n }\n\n return [resource, { selector: null }];\n}\n\nexport function getParsedTargetSelector(\n canvas: CanvasNormalized,\n target: W3CAnnotationTarget | W3CAnnotationTarget[]\n): [TemporalBoxSelector | BoxSelector | PointSelector | null, SupportedTarget['source']] {\n const { selector: imageTarget, source } = expandTarget(target);\n\n if (source.id !== canvas.id) {\n // Skip invalid targets.\n return [null, source];\n }\n\n // Target is where it should be painted.\n const defaultTarget: BoxSelector = {\n type: 'BoxSelector',\n spatial: {\n x: 0,\n y: 0,\n width: Number(canvas.width),\n height: Number(canvas.height),\n },\n };\n\n return [\n imageTarget\n ? imageTarget.type === 'TemporalSelector'\n ? ({\n type: 'TemporalBoxSelector',\n temporal: imageTarget.temporal,\n spatial: defaultTarget.spatial,\n } as any)\n : imageTarget\n : null,\n source,\n ];\n}\n\nexport const emptyActions = {\n makeChoice: () => {\n // no-op\n },\n};\n\nexport const unknownResponse: UseRenderingStrategy[0] = { type: 'unknown' };\n\nexport const unsupportedStrategy = (reason: string): UseRenderingStrategy[0] => {\n return { type: 'unknown', reason, annotations: { pages: [] } };\n};\n\nexport const emptyStrategy = (width: number, height: number): UseRenderingStrategy[0] => {\n return { type: 'empty', width, height, annotations: { pages: [] }, image: null, images: [] };\n};\n","import { CanvasNormalized } from '@iiif/presentation-3-normalized';\nimport { unsupportedStrategy } from './rendering-utils';\nimport { AnnotationPageDescription } from './resource-types';\nimport { ExternalWebResource } from '@iiif/presentation-3';\nimport { RenderingStrategy } from './strategies';\nimport { ChoiceDescription, Paintables } from '@iiif/helpers';\n\nexport type Single3DModelStrategy = {\n type: '3d-model';\n model: ExternalWebResource;\n choice?: ChoiceDescription; // future\n annotations?: AnnotationPageDescription; // future\n};\n\nconst supportedFormats = ['model/gltf-binary'];\n\nexport function get3dStrategy(canvas: CanvasNormalized, paintables: Paintables): RenderingStrategy {\n const first = paintables.items[0];\n const resource = first.resource as ExternalWebResource;\n\n if (!resource.format) {\n return unsupportedStrategy('Unknown format');\n }\n\n if (supportedFormats.indexOf(resource.format) === -1) {\n return unsupportedStrategy(`3D format: ${resource.format} is unsupported`);\n }\n\n return {\n type: '3d-model',\n model: resource as any,\n } as Single3DModelStrategy;\n}\n","import { CanvasNormalized } from '@iiif/presentation-3-normalized';\nimport { unsupportedStrategy } from './rendering-utils';\nimport { MediaStrategy } from './strategies';\nimport { Paintables } from '@iiif/helpers';\n\nexport function getAudioStrategy(canvas: CanvasNormalized, paintables: Paintables) {\n if (!canvas.duration) {\n return unsupportedStrategy('No duration on canvas');\n }\n\n if (paintables.items.length > 1) {\n return unsupportedStrategy('Only one audio source supported');\n }\n\n const audioResource = paintables.items[0]?.resource as any; // @todo stronger type for what this might be.\n\n if (!audioResource) {\n return unsupportedStrategy('Unknown audio');\n }\n\n if (!audioResource.format) {\n return unsupportedStrategy('Audio does not have format');\n }\n\n return {\n type: 'media',\n media: {\n annotationId: paintables.items[0].annotationId,\n duration: canvas.duration,\n url: audioResource.id,\n type: 'Sound',\n target: {\n type: 'TemporalSelector',\n temporal: {\n startTime: 0,\n endTime: canvas.duration,\n },\n },\n format: audioResource.format,\n selector: {\n type: 'TemporalSelector',\n temporal: {\n startTime: 0,\n endTime: canvas.duration,\n },\n },\n },\n annotations: {\n pages: [],\n },\n } as MediaStrategy;\n}\n","import { IIIFExternalWebResource } from '@iiif/presentation-3';\nimport { CanvasNormalized } from '@iiif/presentation-3-normalized';\nimport { ImageServiceLoaderType } from '../../hooks/useLoadImageService';\nimport { AnnotationPageDescription, ImageWithOptionalService } from './resource-types';\nimport { getImageServices } from '@atlas-viewer/iiif-image-api';\nimport { getParsedTargetSelector, unsupportedStrategy } from './rendering-utils';\nimport { expandTarget } from '@iiif/helpers/annotation-targets';\nimport { BoxSelector, ChoiceDescription, Paintables } from '@iiif/helpers';\n\nexport type SingleImageStrategy = {\n type: 'images';\n image: ImageWithOptionalService;\n images: Array<ImageWithOptionalService>;\n choice?: ChoiceDescription;\n annotations?: AnnotationPageDescription;\n};\n\nexport function getImageStrategy(\n canvas: CanvasNormalized,\n paintables: Paintables,\n loadImageService: ImageServiceLoaderType\n) {\n const imageTypes: ImageWithOptionalService[] = [];\n for (const singleImage of paintables.items) {\n // SingleImageStrategy\n const resource: IIIFExternalWebResource =\n singleImage.resource && singleImage.resource.type === 'SpecificResource'\n ? singleImage.resource.source\n : singleImage.resource;\n\n // Validation.\n if (!resource.id) {\n // @todo we could skip this?\n return unsupportedStrategy('No resource Identifier');\n }\n\n let imageService = undefined;\n if (resource.service) {\n const imageServices = getImageServices(resource as any) as any[];\n if (imageServices[0]) {\n imageService = loadImageService(imageServices[0], canvas);\n }\n }\n\n // Target is where it should be painted.\n const defaultTarget: BoxSelector = {\n type: 'BoxSelector',\n spatial: {\n x: 0,\n y: 0,\n width: Number(canvas.width),\n height: Number(canvas.height),\n },\n };\n\n const [target, source] = getParsedTargetSelector(canvas, singleImage.target);\n if (source.id !== canvas.id) {\n // Skip invalid targets.\n continue;\n }\n\n // Support for cropping before painting an annotation.\n // @todo this isn't working.\n const defaultImageSelector =\n (singleImage.resource as any).width && (singleImage.resource as any).height\n ? ({\n type: 'BoxSelector',\n spatial: {\n x: 0,\n y: 0,\n width: (singleImage.resource as any).width,\n height: (singleImage.resource as any).height,\n },\n } as BoxSelector)\n : undefined;\n\n let imageSelector = singleImage.resource.type === 'SpecificResource' ? expandTarget(singleImage.resource) : null;\n\n if (singleImage.selector) {\n const found = expandTarget({\n type: 'SpecificResource',\n source: singleImage.resource,\n selector: singleImage.selector,\n });\n\n if (found) {\n imageSelector = found;\n }\n }\n\n const selector: undefined | BoxSelector =\n imageSelector &&\n imageSelector.selector &&\n (imageSelector.selector.type === 'BoxSelector' || imageSelector.selector.type === 'TemporalBoxSelector')\n ? {\n type: 'BoxSelector',\n spatial: {\n x: imageSelector.selector.spatial.x,\n y: imageSelector.selector.spatial.y,\n width: imageSelector.selector.spatial.width,\n height: imageSelector.selector.spatial.height,\n },\n }\n : undefined;\n\n if (imageService && !imageService.id) {\n (imageService as any).id = imageService['@id'];\n }\n\n const imageType: ImageWithOptionalService = {\n id: resource.id,\n type: 'Image',\n annotationId: (singleImage as any).annotationId,\n width: Number(target || selector ? resource.width : canvas.width),\n height: Number(target || selector ? resource.height : canvas.height),\n service: imageService,\n sizes:\n imageService && imageService.sizes\n ? imageService.sizes\n : resource.width && resource.height\n ? [{ width: resource.width, height: resource.height }]\n : [],\n target: target && target.type !== 'PointSelector' ? target : defaultTarget,\n selector: selector,\n };\n\n imageTypes.push(imageType);\n }\n\n return {\n type: 'images',\n image: imageTypes[0],\n images: imageTypes,\n choice: paintables.choice,\n } as SingleImageStrategy;\n}\n","import { InternationalString } from '@iiif/presentation-3';\nimport { CanvasNormalized } from '@iiif/presentation-3-normalized';\nimport { AnnotationPageDescription } from './resource-types';\nimport { getParsedTargetSelector } from './rendering-utils';\nimport { RenderingStrategy } from './strategies';\nimport { ChoiceDescription, Paintables, SupportedTarget } from '@iiif/helpers';\n\nexport type TextualContentStrategy = {\n type: 'textual-content';\n items: { annotationId: string; text: InternationalString; target: SupportedTarget | null }[];\n choice?: ChoiceDescription; // future\n annotations?: AnnotationPageDescription; // future\n};\n\nfunction parseType(item: any, languageMap: InternationalString = {}, lang?: string) {\n const language = item.language || lang || 'none';\n switch (item.type) {\n case 'TextualBody': {\n if (typeof item.value !== 'undefined') {\n languageMap[language] = item.value;\n }\n break;\n }\n case 'List':\n case 'Composite':\n case 'Choice': {\n if (item.items) {\n item.items.forEach((inner: any) => parseType(inner, languageMap, language));\n }\n }\n }\n return languageMap;\n}\n\nexport function getTextualContentStrategy(canvas: CanvasNormalized, paintables: Paintables): RenderingStrategy {\n const items: TextualContentStrategy['items'] = [];\n\n paintables.items.forEach((item) => {\n if (item.resource) {\n const [target] = getParsedTargetSelector(canvas, item.target);\n items.push({ annotationId: item.annotationId, text: parseType(item.resource), target: target as any });\n }\n });\n\n return {\n type: 'textual-content',\n items,\n } as TextualContentStrategy;\n}\n","import { CanvasNormalized } from '@iiif/presentation-3-normalized';\nimport { unsupportedStrategy } from './rendering-utils';\nimport { MediaStrategy } from './strategies';\nimport { Paintables } from '@iiif/helpers';\n\n// https://stackoverflow.com/a/27728417\nconst ytRegex = /^.*(?:(?:youtu\\.be\\/|v\\/|vi\\/|u\\/\\w\\/|embed\\/|shorts\\/)|(?:(?:watch)?\\?vi?=|&vi?=))([^#&?]*).*/;\n\nexport function getVideoStrategy(canvas: CanvasNormalized, paintables: Paintables) {\n const videoPaintables = paintables.items.filter((t) => t.type === 'video');\n\n let noDuration = false;\n\n if (!canvas.duration) {\n noDuration = true;\n }\n\n if (videoPaintables.length > 1) {\n return unsupportedStrategy('Only one video source supported');\n }\n\n const videoResource = videoPaintables[0]?.resource as any; // @todo stronger type for what this might be.\n const isYouTube = !!(videoResource.service || []).find((service: any) =>\n (service.profile || '').includes('youtube.com')\n );\n\n if (!isYouTube && noDuration) {\n return unsupportedStrategy('Video does not have duration');\n }\n\n if (!videoResource) {\n return unsupportedStrategy('Unknown video');\n }\n\n if (!videoResource.format || videoResource.format === 'text/html') {\n if (!isYouTube) {\n return unsupportedStrategy('Video does not have format');\n }\n }\n\n const media = {\n annotationId: (paintables.items[0] as any).annotationId,\n duration: canvas.duration,\n url: videoResource.id,\n type: 'Video',\n items: [],\n target: {\n type: 'TemporalSelector',\n temporal: {\n startTime: 0,\n endTime: canvas.duration,\n },\n },\n format: videoResource.format,\n selector: {\n type: 'TemporalSelector',\n temporal: {\n startTime: 0,\n endTime: canvas.duration,\n },\n },\n };\n\n if (isYouTube) {\n media.type = 'VideoYouTube';\n const id = videoResource.id.match(ytRegex);\n if (!id[1]) {\n return unsupportedStrategy('Video is not known youtube video');\n }\n (media as any).youTubeId = id[1];\n }\n\n // @todo support VTT\n\n return {\n type: 'media',\n media,\n annotations: {\n pages: [],\n },\n } as MediaStrategy;\n}\n","import { get3dStrategy } from './3d-strategy';\nimport { getAudioStrategy } from './audio-strategy';\nimport { getImageStrategy } from './image-strategy';\nimport { emptyStrategy, unknownResponse, unsupportedStrategy } from './rendering-utils';\nimport { getTextualContentStrategy } from './textual-content-strategy';\nimport { getVideoStrategy } from './video-strategy';\nimport type { CanvasNormalized } from '@iiif/presentation-3-normalized';\nimport type { Paintables } from '@iiif/helpers/painting-annotations';\nimport type { ImageServiceLoaderType } from '../../hooks/useLoadImageService';\n\ninterface GetRenderStrategyOptions {\n canvas: CanvasNormalized | null | undefined;\n paintables: Paintables;\n supports: string[];\n loadImageService: ImageServiceLoaderType;\n}\n\nexport function getRenderingStrategy({ canvas, paintables, supports, loadImageService }: GetRenderStrategyOptions) {\n if (!canvas) {\n console.log('No canvas');\n return unknownResponse;\n }\n\n if (paintables.types.length === 0) {\n if (supports.indexOf('empty') !== -1) {\n return emptyStrategy(canvas.width, canvas.height);\n }\n console.log('No paintables');\n return unknownResponse;\n }\n\n if (paintables.types.length !== 1) {\n if (paintables.types.length === 2 && paintables.types.indexOf('text') !== -1) {\n paintables.types = paintables.types.filter((t) => t !== 'text');\n } else {\n if (supports.indexOf('complex-timeline') === -1) {\n return unsupportedStrategy('Complex timeline not supported');\n }\n return unsupportedStrategy('ComplexTimelineStrategy not yet supported');\n }\n }\n\n const mainType = paintables.types[0];\n\n // Image\n if (mainType === 'image') {\n if (supports.indexOf('images') === -1) {\n return unsupportedStrategy('Image not supported');\n }\n\n return getImageStrategy(canvas, paintables, loadImageService);\n }\n\n // 3D\n if (mainType === 'Model' || mainType === 'model') {\n if (supports.indexOf('3d-model') === -1) {\n return unsupportedStrategy('3D not supported');\n }\n\n return get3dStrategy(canvas, paintables);\n }\n\n if (mainType === 'textualbody') {\n if (supports.indexOf('textual-content') === -1) {\n return unsupportedStrategy('Textual content not supported');\n }\n\n return getTextualContentStrategy(canvas, paintables);\n }\n\n if (mainType === 'sound' || mainType === 'audio') {\n if (supports.indexOf('media') === -1) {\n return unsupportedStrategy('Media not supported');\n }\n\n // Media Strategy with audio or audio sequence.\n return getAudioStrategy(canvas, paintables);\n }\n\n if (mainType === 'video') {\n if (supports.indexOf('media') === -1) {\n return unsupportedStrategy('Media not supported');\n }\n\n // Media Strategy with video or video sequence.\n return getVideoStrategy(canvas, paintables);\n }\n\n // Unknown fallback.\n return unknownResponse;\n}\n"],"names":["parseSpecificResource","resource","getParsedTargetSelector","canvas","target","imageTarget","source","expandTarget","defaultTarget","emptyActions","unknownResponse","unsupportedStrategy","reason","emptyStrategy","width","height","supportedFormats","get3dStrategy","paintables","getAudioStrategy","audioResource","_a","getImageStrategy","loadImageService","imageTypes","singleImage","imageService","imageServices","getImageServices","imageSelector","found","selector","imageType","parseType","item","languageMap","lang","language","inner","getTextualContentStrategy","items","ytRegex","getVideoStrategy","videoPaintables","t","noDuration","videoResource","isYouTube","service","media","id","getRenderingStrategy","supports","mainType"],"mappings":"yMAYO,SAASA,EAAsBC,EAA2B,CAC3D,OAAAA,EAAS,OAAS,mBACb,CAACA,EAAS,OAAQ,CAAE,SAAUA,EAAS,SAAU,EAGnD,CAACA,EAAU,CAAE,SAAU,IAAM,CAAA,CACtC,CAEgB,SAAAC,EACdC,EACAC,EACuF,CACvF,KAAM,CAAE,SAAUC,EAAa,OAAAC,CAAO,EAAIC,EAAAA,aAAaH,CAAM,EAEzD,GAAAE,EAAO,KAAOH,EAAO,GAEhB,MAAA,CAAC,KAAMG,CAAM,EAItB,MAAME,EAA6B,CACjC,KAAM,cACN,QAAS,CACP,EAAG,EACH,EAAG,EACH,MAAO,OAAOL,EAAO,KAAK,EAC1B,OAAQ,OAAOA,EAAO,MAAM,CAC9B,CAAA,EAGK,MAAA,CACLE,EACIA,EAAY,OAAS,mBAClB,CACC,KAAM,sBACN,SAAUA,EAAY,SACtB,QAASG,EAAc,SAEzBH,EACF,KACJC,CAAA,CAEJ,CAEO,MAAMG,EAAe,CAC1B,WAAY,IAAM,CAElB,CACF,EAEaC,EAA2C,CAAE,KAAM,SAAU,EAE7DC,EAAuBC,IAC3B,CAAE,KAAM,UAAW,OAAAA,EAAQ,YAAa,CAAE,MAAO,CAAC,CAAA,IAG9CC,EAAgB,CAACC,EAAeC,KACpC,CAAE,KAAM,QAAS,MAAAD,EAAO,OAAAC,EAAQ,YAAa,CAAE,MAAO,C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,GAElD,QAAQ,IAAI,eAAe,EACpBO,GAGL,GAAAQ,EAAW,MAAM,SAAW,EAC1B,GAAAA,EAAW,MAAM,SAAW,GAAKA,EAAW,MAAM,QAAQ,MAAM,IAAM,GACxEA,EAAW,MAAQA,EAAW,MAAM,OAAQ0B,GAAMA,IAAM,MAAM,MAE9D,QAAIQ,EAAS,QAAQ,kBAAkB,IAAM,GACpCzC,EAAoB,gCAAgC,EAEtDA,EAAoB,2CAA2C,EAIpE,MAAA0C,EAAWnC,EAAW,MAAM,CAAC,EAGnC,OAAImC,IAAa,QACXD,EAAS,QAAQ,QAAQ,IAAM,GAC1BzC,EAAoB,qBAAqB,EAG3CW,EAAiBnB,EAAQe,EAAYK,CAAgB,EAI1D8B,IAAa,SAAWA,IAAa,QACnCD,EAAS,QAAQ,UAAU,IAAM,GAC5BzC,EAAoB,kBAAkB,EAGxCM,EAAcd,EAAQe,CAAU,EAGrCmC,IAAa,cACXD,EAAS,QAAQ,iBAAiB,IAAM,GACnCzC,EAAoB,+BAA+B,EAGrD4B,EAA0BpC,EAAQe,CAAU,EAGjDmC,IAAa,SAAWA,IAAa,QACnCD,EAAS,QAAQ,OAAO,IAAM,GACzBzC,EAAoB,qBAAqB,EAI3CQ,EAAiBhB,EAAQe,CAAU,EAGxCmC,IAAa,QACXD,EAAS,QAAQ,OAAO,IAAM,GACzBzC,EAAoB,qBAAqB,EAI3C+B,EAAiBvC,EAAQe,CAAU,EAIrCR,CACT"}
|
package/dist/utils/esm/utils.mjs
CHANGED
|
@@ -4,11 +4,11 @@ import { expandTarget as p } from "@iiif/helpers/annotation-targets";
|
|
|
4
4
|
function z(e) {
|
|
5
5
|
return e.type === "SpecificResource" ? [e.source, { selector: e.selector }] : [e, { selector: null }];
|
|
6
6
|
}
|
|
7
|
-
function g(e,
|
|
8
|
-
const { selector:
|
|
9
|
-
if (
|
|
10
|
-
return [null,
|
|
11
|
-
const
|
|
7
|
+
function g(e, o) {
|
|
8
|
+
const { selector: r, source: i } = S(o);
|
|
9
|
+
if (i.id !== e.id)
|
|
10
|
+
return [null, i];
|
|
11
|
+
const t = {
|
|
12
12
|
type: "BoxSelector",
|
|
13
13
|
spatial: {
|
|
14
14
|
x: 0,
|
|
@@ -18,38 +18,38 @@ function g(e, t) {
|
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
20
|
return [
|
|
21
|
-
|
|
21
|
+
r ? r.type === "TemporalSelector" ? {
|
|
22
22
|
type: "TemporalBoxSelector",
|
|
23
|
-
temporal:
|
|
24
|
-
spatial:
|
|
25
|
-
} :
|
|
26
|
-
|
|
23
|
+
temporal: r.temporal,
|
|
24
|
+
spatial: t.spatial
|
|
25
|
+
} : r : null,
|
|
26
|
+
i
|
|
27
27
|
];
|
|
28
28
|
}
|
|
29
29
|
const A = {
|
|
30
30
|
makeChoice: () => {
|
|
31
31
|
}
|
|
32
|
-
},
|
|
33
|
-
function
|
|
34
|
-
const
|
|
35
|
-
return
|
|
32
|
+
}, m = { type: "unknown" }, n = (e) => ({ type: "unknown", reason: e, annotations: { pages: [] } }), w = (e, o) => ({ type: "empty", width: e, height: o, annotations: { pages: [] }, image: null, images: [] }), I = ["model/gltf-binary"];
|
|
33
|
+
function O(e, o) {
|
|
34
|
+
const i = o.items[0].resource;
|
|
35
|
+
return i.format ? I.indexOf(i.format) === -1 ? n(`3D format: ${i.format} is unsupported`) : {
|
|
36
36
|
type: "3d-model",
|
|
37
|
-
model:
|
|
37
|
+
model: i
|
|
38
38
|
} : n("Unknown format");
|
|
39
39
|
}
|
|
40
|
-
function
|
|
41
|
-
var
|
|
40
|
+
function N(e, o) {
|
|
41
|
+
var i;
|
|
42
42
|
if (!e.duration)
|
|
43
43
|
return n("No duration on canvas");
|
|
44
|
-
if (
|
|
44
|
+
if (o.items.length > 1)
|
|
45
45
|
return n("Only one audio source supported");
|
|
46
|
-
const
|
|
47
|
-
return
|
|
46
|
+
const r = (i = o.items[0]) == null ? void 0 : i.resource;
|
|
47
|
+
return r ? r.format ? {
|
|
48
48
|
type: "media",
|
|
49
49
|
media: {
|
|
50
|
-
annotationId:
|
|
50
|
+
annotationId: o.items[0].annotationId,
|
|
51
51
|
duration: e.duration,
|
|
52
|
-
url:
|
|
52
|
+
url: r.id,
|
|
53
53
|
type: "Sound",
|
|
54
54
|
target: {
|
|
55
55
|
type: "TemporalSelector",
|
|
@@ -58,7 +58,7 @@ function O(e, t) {
|
|
|
58
58
|
endTime: e.duration
|
|
59
59
|
}
|
|
60
60
|
},
|
|
61
|
-
format:
|
|
61
|
+
format: r.format,
|
|
62
62
|
selector: {
|
|
63
63
|
type: "TemporalSelector",
|
|
64
64
|
temporal: {
|
|
@@ -72,18 +72,18 @@ function O(e, t) {
|
|
|
72
72
|
}
|
|
73
73
|
} : n("Audio does not have format") : n("Unknown audio");
|
|
74
74
|
}
|
|
75
|
-
function R(e,
|
|
76
|
-
const
|
|
77
|
-
for (const
|
|
78
|
-
const u =
|
|
75
|
+
function R(e, o, r) {
|
|
76
|
+
const i = [];
|
|
77
|
+
for (const t of o.items) {
|
|
78
|
+
const u = t.resource && t.resource.type === "SpecificResource" ? t.resource.source : t.resource;
|
|
79
79
|
if (!u.id)
|
|
80
80
|
return n("No resource Identifier");
|
|
81
|
-
let
|
|
81
|
+
let d;
|
|
82
82
|
if (u.service) {
|
|
83
|
-
const
|
|
84
|
-
|
|
83
|
+
const a = T(u);
|
|
84
|
+
a[0] && (d = r(a[0], e));
|
|
85
85
|
}
|
|
86
|
-
const
|
|
86
|
+
const f = {
|
|
87
87
|
type: "BoxSelector",
|
|
88
88
|
spatial: {
|
|
89
89
|
x: 0,
|
|
@@ -91,94 +91,95 @@ function R(e, t, i) {
|
|
|
91
91
|
width: Number(e.width),
|
|
92
92
|
height: Number(e.height)
|
|
93
93
|
}
|
|
94
|
-
}, [
|
|
94
|
+
}, [s, h] = g(e, t.target);
|
|
95
95
|
if (h.id !== e.id)
|
|
96
96
|
continue;
|
|
97
|
-
|
|
98
|
-
let
|
|
99
|
-
if (
|
|
100
|
-
const
|
|
97
|
+
t.resource.width && t.resource.height && (t.resource.width, t.resource.height);
|
|
98
|
+
let c = t.resource.type === "SpecificResource" ? p(t.resource) : null;
|
|
99
|
+
if (t.selector) {
|
|
100
|
+
const a = p({
|
|
101
101
|
type: "SpecificResource",
|
|
102
|
-
source:
|
|
103
|
-
selector:
|
|
102
|
+
source: t.resource,
|
|
103
|
+
selector: t.selector
|
|
104
104
|
});
|
|
105
|
-
|
|
105
|
+
a && (c = a);
|
|
106
106
|
}
|
|
107
|
-
const
|
|
107
|
+
const l = c && c.selector && (c.selector.type === "BoxSelector" || c.selector.type === "TemporalBoxSelector") ? {
|
|
108
108
|
type: "BoxSelector",
|
|
109
109
|
spatial: {
|
|
110
|
-
x:
|
|
111
|
-
y:
|
|
112
|
-
width:
|
|
113
|
-
height:
|
|
110
|
+
x: c.selector.spatial.x,
|
|
111
|
+
y: c.selector.spatial.y,
|
|
112
|
+
width: c.selector.spatial.width,
|
|
113
|
+
height: c.selector.spatial.height
|
|
114
114
|
}
|
|
115
115
|
} : void 0;
|
|
116
|
-
|
|
116
|
+
d && !d.id && (d.id = d["@id"]);
|
|
117
117
|
const x = {
|
|
118
118
|
id: u.id,
|
|
119
119
|
type: "Image",
|
|
120
|
-
annotationId:
|
|
121
|
-
width: Number(
|
|
122
|
-
height: Number(
|
|
123
|
-
service:
|
|
124
|
-
sizes:
|
|
125
|
-
target:
|
|
126
|
-
selector:
|
|
120
|
+
annotationId: t.annotationId,
|
|
121
|
+
width: Number(s || l ? u.width : e.width),
|
|
122
|
+
height: Number(s || l ? u.height : e.height),
|
|
123
|
+
service: d,
|
|
124
|
+
sizes: d && d.sizes ? d.sizes : u.width && u.height ? [{ width: u.width, height: u.height }] : [],
|
|
125
|
+
target: s && s.type !== "PointSelector" ? s : f,
|
|
126
|
+
selector: l
|
|
127
127
|
};
|
|
128
|
-
|
|
128
|
+
i.push(x);
|
|
129
129
|
}
|
|
130
130
|
return {
|
|
131
131
|
type: "images",
|
|
132
|
-
image:
|
|
133
|
-
images:
|
|
134
|
-
choice:
|
|
132
|
+
image: i[0],
|
|
133
|
+
images: i,
|
|
134
|
+
choice: o.choice
|
|
135
135
|
};
|
|
136
136
|
}
|
|
137
|
-
function y(e,
|
|
138
|
-
const
|
|
137
|
+
function y(e, o = {}, r) {
|
|
138
|
+
const i = e.language || r || "none";
|
|
139
139
|
switch (e.type) {
|
|
140
140
|
case "TextualBody": {
|
|
141
|
-
typeof e.value < "u" && (
|
|
141
|
+
typeof e.value < "u" && (o[i] = e.value);
|
|
142
142
|
break;
|
|
143
143
|
}
|
|
144
144
|
case "List":
|
|
145
145
|
case "Composite":
|
|
146
146
|
case "Choice":
|
|
147
|
-
e.items && e.items.forEach((
|
|
147
|
+
e.items && e.items.forEach((t) => y(t, o, i));
|
|
148
148
|
}
|
|
149
|
-
return
|
|
149
|
+
return o;
|
|
150
150
|
}
|
|
151
|
-
function k(e,
|
|
152
|
-
const
|
|
153
|
-
return
|
|
154
|
-
if (
|
|
155
|
-
const [
|
|
156
|
-
|
|
151
|
+
function k(e, o) {
|
|
152
|
+
const r = [];
|
|
153
|
+
return o.items.forEach((i) => {
|
|
154
|
+
if (i.resource) {
|
|
155
|
+
const [t] = g(e, i.target);
|
|
156
|
+
r.push({ annotationId: i.annotationId, text: y(i.resource), target: t });
|
|
157
157
|
}
|
|
158
158
|
}), {
|
|
159
159
|
type: "textual-content",
|
|
160
|
-
items:
|
|
160
|
+
items: r
|
|
161
161
|
};
|
|
162
162
|
}
|
|
163
163
|
const B = /^.*(?:(?:youtu\.be\/|v\/|vi\/|u\/\w\/|embed\/|shorts\/)|(?:(?:watch)?\?vi?=|&vi?=))([^#&?]*).*/;
|
|
164
|
-
function v(e,
|
|
165
|
-
var
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
if (i.length > 1)
|
|
164
|
+
function v(e, o) {
|
|
165
|
+
var f;
|
|
166
|
+
const r = o.items.filter((s) => s.type === "video");
|
|
167
|
+
let i = !1;
|
|
168
|
+
if (e.duration || (i = !0), r.length > 1)
|
|
170
169
|
return n("Only one video source supported");
|
|
171
|
-
const
|
|
172
|
-
(
|
|
170
|
+
const t = (f = r[0]) == null ? void 0 : f.resource, u = !!(t.service || []).find(
|
|
171
|
+
(s) => (s.profile || "").includes("youtube.com")
|
|
173
172
|
);
|
|
174
|
-
if (!
|
|
173
|
+
if (!u && i)
|
|
174
|
+
return n("Video does not have duration");
|
|
175
|
+
if (!t)
|
|
175
176
|
return n("Unknown video");
|
|
176
|
-
if ((!
|
|
177
|
+
if ((!t.format || t.format === "text/html") && !u)
|
|
177
178
|
return n("Video does not have format");
|
|
178
|
-
const
|
|
179
|
-
annotationId:
|
|
179
|
+
const d = {
|
|
180
|
+
annotationId: o.items[0].annotationId,
|
|
180
181
|
duration: e.duration,
|
|
181
|
-
url:
|
|
182
|
+
url: t.id,
|
|
182
183
|
type: "Video",
|
|
183
184
|
items: [],
|
|
184
185
|
target: {
|
|
@@ -188,7 +189,7 @@ function v(e, t) {
|
|
|
188
189
|
endTime: e.duration
|
|
189
190
|
}
|
|
190
191
|
},
|
|
191
|
-
format:
|
|
192
|
+
format: t.format,
|
|
192
193
|
selector: {
|
|
193
194
|
type: "TemporalSelector",
|
|
194
195
|
temporal: {
|
|
@@ -197,41 +198,41 @@ function v(e, t) {
|
|
|
197
198
|
}
|
|
198
199
|
}
|
|
199
200
|
};
|
|
200
|
-
if (
|
|
201
|
-
|
|
202
|
-
const
|
|
203
|
-
if (!
|
|
201
|
+
if (u) {
|
|
202
|
+
d.type = "VideoYouTube";
|
|
203
|
+
const s = t.id.match(B);
|
|
204
|
+
if (!s[1])
|
|
204
205
|
return n("Video is not known youtube video");
|
|
205
|
-
|
|
206
|
+
d.youTubeId = s[1];
|
|
206
207
|
}
|
|
207
208
|
return {
|
|
208
209
|
type: "media",
|
|
209
|
-
media:
|
|
210
|
+
media: d,
|
|
210
211
|
annotations: {
|
|
211
212
|
pages: []
|
|
212
213
|
}
|
|
213
214
|
};
|
|
214
215
|
}
|
|
215
|
-
function
|
|
216
|
+
function D({ canvas: e, paintables: o, supports: r, loadImageService: i }) {
|
|
216
217
|
if (!e)
|
|
217
|
-
return console.log("No canvas"),
|
|
218
|
-
if (
|
|
219
|
-
return
|
|
220
|
-
if (
|
|
221
|
-
if (
|
|
222
|
-
|
|
218
|
+
return console.log("No canvas"), m;
|
|
219
|
+
if (o.types.length === 0)
|
|
220
|
+
return r.indexOf("empty") !== -1 ? w(e.width, e.height) : (console.log("No paintables"), m);
|
|
221
|
+
if (o.types.length !== 1)
|
|
222
|
+
if (o.types.length === 2 && o.types.indexOf("text") !== -1)
|
|
223
|
+
o.types = o.types.filter((u) => u !== "text");
|
|
223
224
|
else
|
|
224
|
-
return
|
|
225
|
-
const
|
|
226
|
-
return
|
|
225
|
+
return r.indexOf("complex-timeline") === -1 ? n("Complex timeline not supported") : n("ComplexTimelineStrategy not yet supported");
|
|
226
|
+
const t = o.types[0];
|
|
227
|
+
return t === "image" ? r.indexOf("images") === -1 ? n("Image not supported") : R(e, o, i) : t === "Model" || t === "model" ? r.indexOf("3d-model") === -1 ? n("3D not supported") : O(e, o) : t === "textualbody" ? r.indexOf("textual-content") === -1 ? n("Textual content not supported") : k(e, o) : t === "sound" || t === "audio" ? r.indexOf("media") === -1 ? n("Media not supported") : N(e, o) : t === "video" ? r.indexOf("media") === -1 ? n("Media not supported") : v(e, o) : m;
|
|
227
228
|
}
|
|
228
229
|
export {
|
|
229
230
|
A as emptyActions,
|
|
230
231
|
w as emptyStrategy,
|
|
231
232
|
g as getParsedTargetSelector,
|
|
232
|
-
|
|
233
|
+
D as getRenderingStrategy,
|
|
233
234
|
z as parseSpecificResource,
|
|
234
|
-
|
|
235
|
+
m as unknownResponse,
|
|
235
236
|
n as unsupportedStrategy
|
|
236
237
|
};
|
|
237
238
|
//# sourceMappingURL=utils.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","sources":["../../../src/features/rendering-strategy/rendering-utils.ts","../../../src/features/rendering-strategy/3d-strategy.ts","../../../src/features/rendering-strategy/audio-strategy.ts","../../../src/features/rendering-strategy/image-strategy.ts","../../../src/features/rendering-strategy/textual-content-strategy.ts","../../../src/features/rendering-strategy/video-strategy.ts","../../../src/features/rendering-strategy/get-rendering-strategy.ts"],"sourcesContent":["import { ContentResource, PointSelector, W3CAnnotationTarget } from '@iiif/presentation-3';\nimport { CanvasNormalized } from '@iiif/presentation-3-normalized';\nimport { UseRenderingStrategy } from '../../hooks/useRenderingStrategy';\nimport { BoxSelector, expandTarget, SupportedTarget, TemporalBoxSelector } from '@iiif/helpers';\n\n/**\n * Parse specific resource.\n *\n * This could be expanded to support pulling out more from the specific resource.\n *\n * @param resource\n */\nexport function parseSpecificResource(resource: ContentResource) {\n if (resource.type === 'SpecificResource') {\n return [resource.source, { selector: resource.selector }];\n }\n\n return [resource, { selector: null }];\n}\n\nexport function getParsedTargetSelector(\n canvas: CanvasNormalized,\n target: W3CAnnotationTarget | W3CAnnotationTarget[]\n): [TemporalBoxSelector | BoxSelector | PointSelector | null, SupportedTarget['source']] {\n const { selector: imageTarget, source } = expandTarget(target);\n\n if (source.id !== canvas.id) {\n // Skip invalid targets.\n return [null, source];\n }\n\n // Target is where it should be painted.\n const defaultTarget: BoxSelector = {\n type: 'BoxSelector',\n spatial: {\n x: 0,\n y: 0,\n width: Number(canvas.width),\n height: Number(canvas.height),\n },\n };\n\n return [\n imageTarget\n ? imageTarget.type === 'TemporalSelector'\n ? ({\n type: 'TemporalBoxSelector',\n temporal: imageTarget.temporal,\n spatial: defaultTarget.spatial,\n } as any)\n : imageTarget\n : null,\n source,\n ];\n}\n\nexport const emptyActions = {\n makeChoice: () => {\n // no-op\n },\n};\n\nexport const unknownResponse: UseRenderingStrategy[0] = { type: 'unknown' };\n\nexport const unsupportedStrategy = (reason: string): UseRenderingStrategy[0] => {\n return { type: 'unknown', reason, annotations: { pages: [] } };\n};\n\nexport const emptyStrategy = (width: number, height: number): UseRenderingStrategy[0] => {\n return { type: 'empty', width, height, annotations: { pages: [] }, image: null, images: [] };\n};\n","import { CanvasNormalized } from '@iiif/presentation-3-normalized';\nimport { unsupportedStrategy } from './rendering-utils';\nimport { AnnotationPageDescription } from './resource-types';\nimport { ExternalWebResource } from '@iiif/presentation-3';\nimport { RenderingStrategy } from './strategies';\nimport { ChoiceDescription, Paintables } from '@iiif/helpers';\n\nexport type Single3DModelStrategy = {\n type: '3d-model';\n model: ExternalWebResource;\n choice?: ChoiceDescription; // future\n annotations?: AnnotationPageDescription; // future\n};\n\nconst supportedFormats = ['model/gltf-binary'];\n\nexport function get3dStrategy(canvas: CanvasNormalized, paintables: Paintables): RenderingStrategy {\n const first = paintables.items[0];\n const resource = first.resource as ExternalWebResource;\n\n if (!resource.format) {\n return unsupportedStrategy('Unknown format');\n }\n\n if (supportedFormats.indexOf(resource.format) === -1) {\n return unsupportedStrategy(`3D format: ${resource.format} is unsupported`);\n }\n\n return {\n type: '3d-model',\n model: resource as any,\n } as Single3DModelStrategy;\n}\n","import { CanvasNormalized } from '@iiif/presentation-3-normalized';\nimport { unsupportedStrategy } from './rendering-utils';\nimport { MediaStrategy } from './strategies';\nimport { Paintables } from '@iiif/helpers';\n\nexport function getAudioStrategy(canvas: CanvasNormalized, paintables: Paintables) {\n if (!canvas.duration) {\n return unsupportedStrategy('No duration on canvas');\n }\n\n if (paintables.items.length > 1) {\n return unsupportedStrategy('Only one audio source supported');\n }\n\n const audioResource = paintables.items[0]?.resource as any; // @todo stronger type for what this might be.\n\n if (!audioResource) {\n return unsupportedStrategy('Unknown audio');\n }\n\n if (!audioResource.format) {\n return unsupportedStrategy('Audio does not have format');\n }\n\n return {\n type: 'media',\n media: {\n annotationId: paintables.items[0].annotationId,\n duration: canvas.duration,\n url: audioResource.id,\n type: 'Sound',\n target: {\n type: 'TemporalSelector',\n temporal: {\n startTime: 0,\n endTime: canvas.duration,\n },\n },\n format: audioResource.format,\n selector: {\n type: 'TemporalSelector',\n temporal: {\n startTime: 0,\n endTime: canvas.duration,\n },\n },\n },\n annotations: {\n pages: [],\n },\n } as MediaStrategy;\n}\n","import { IIIFExternalWebResource } from '@iiif/presentation-3';\nimport { CanvasNormalized } from '@iiif/presentation-3-normalized';\nimport { ImageServiceLoaderType } from '../../hooks/useLoadImageService';\nimport { AnnotationPageDescription, ImageWithOptionalService } from './resource-types';\nimport { getImageServices } from '@atlas-viewer/iiif-image-api';\nimport { getParsedTargetSelector, unsupportedStrategy } from './rendering-utils';\nimport { expandTarget } from '@iiif/helpers/annotation-targets';\nimport { BoxSelector, ChoiceDescription, Paintables } from '@iiif/helpers';\n\nexport type SingleImageStrategy = {\n type: 'images';\n image: ImageWithOptionalService;\n images: Array<ImageWithOptionalService>;\n choice?: ChoiceDescription;\n annotations?: AnnotationPageDescription;\n};\n\nexport function getImageStrategy(\n canvas: CanvasNormalized,\n paintables: Paintables,\n loadImageService: ImageServiceLoaderType\n) {\n const imageTypes: ImageWithOptionalService[] = [];\n for (const singleImage of paintables.items) {\n // SingleImageStrategy\n const resource: IIIFExternalWebResource =\n singleImage.resource && singleImage.resource.type === 'SpecificResource'\n ? singleImage.resource.source\n : singleImage.resource;\n\n // Validation.\n if (!resource.id) {\n // @todo we could skip this?\n return unsupportedStrategy('No resource Identifier');\n }\n\n let imageService = undefined;\n if (resource.service) {\n const imageServices = getImageServices(resource as any) as any[];\n if (imageServices[0]) {\n imageService = loadImageService(imageServices[0], canvas);\n }\n }\n\n // Target is where it should be painted.\n const defaultTarget: BoxSelector = {\n type: 'BoxSelector',\n spatial: {\n x: 0,\n y: 0,\n width: Number(canvas.width),\n height: Number(canvas.height),\n },\n };\n\n const [target, source] = getParsedTargetSelector(canvas, singleImage.target);\n if (source.id !== canvas.id) {\n // Skip invalid targets.\n continue;\n }\n\n // Support for cropping before painting an annotation.\n // @todo this isn't working.\n const defaultImageSelector =\n (singleImage.resource as any).width && (singleImage.resource as any).height\n ? ({\n type: 'BoxSelector',\n spatial: {\n x: 0,\n y: 0,\n width: (singleImage.resource as any).width,\n height: (singleImage.resource as any).height,\n },\n } as BoxSelector)\n : undefined;\n\n let imageSelector = singleImage.resource.type === 'SpecificResource' ? expandTarget(singleImage.resource) : null;\n\n if (singleImage.selector) {\n const found = expandTarget({\n type: 'SpecificResource',\n source: singleImage.resource,\n selector: singleImage.selector,\n });\n\n if (found) {\n imageSelector = found;\n }\n }\n\n const selector: undefined | BoxSelector =\n imageSelector &&\n imageSelector.selector &&\n (imageSelector.selector.type === 'BoxSelector' || imageSelector.selector.type === 'TemporalBoxSelector')\n ? {\n type: 'BoxSelector',\n spatial: {\n x: imageSelector.selector.spatial.x,\n y: imageSelector.selector.spatial.y,\n width: imageSelector.selector.spatial.width,\n height: imageSelector.selector.spatial.height,\n },\n }\n : undefined;\n\n if (imageService && !imageService.id) {\n (imageService as any).id = imageService['@id'];\n }\n\n const imageType: ImageWithOptionalService = {\n id: resource.id,\n type: 'Image',\n annotationId: (singleImage as any).annotationId,\n width: Number(target || selector ? resource.width : canvas.width),\n height: Number(target || selector ? resource.height : canvas.height),\n service: imageService,\n sizes:\n imageService && imageService.sizes\n ? imageService.sizes\n : resource.width && resource.height\n ? [{ width: resource.width, height: resource.height }]\n : [],\n target: target && target.type !== 'PointSelector' ? target : defaultTarget,\n selector: selector,\n };\n\n imageTypes.push(imageType);\n }\n\n return {\n type: 'images',\n image: imageTypes[0],\n images: imageTypes,\n choice: paintables.choice,\n } as SingleImageStrategy;\n}\n","import { InternationalString } from '@iiif/presentation-3';\nimport { CanvasNormalized } from '@iiif/presentation-3-normalized';\nimport { AnnotationPageDescription } from './resource-types';\nimport { getParsedTargetSelector } from './rendering-utils';\nimport { RenderingStrategy } from './strategies';\nimport { ChoiceDescription, Paintables, SupportedTarget } from '@iiif/helpers';\n\nexport type TextualContentStrategy = {\n type: 'textual-content';\n items: { annotationId: string; text: InternationalString; target: SupportedTarget | null }[];\n choice?: ChoiceDescription; // future\n annotations?: AnnotationPageDescription; // future\n};\n\nfunction parseType(item: any, languageMap: InternationalString = {}, lang?: string) {\n const language = item.language || lang || 'none';\n switch (item.type) {\n case 'TextualBody': {\n if (typeof item.value !== 'undefined') {\n languageMap[language] = item.value;\n }\n break;\n }\n case 'List':\n case 'Composite':\n case 'Choice': {\n if (item.items) {\n item.items.forEach((inner: any) => parseType(inner, languageMap, language));\n }\n }\n }\n return languageMap;\n}\n\nexport function getTextualContentStrategy(canvas: CanvasNormalized, paintables: Paintables): RenderingStrategy {\n const items: TextualContentStrategy['items'] = [];\n\n paintables.items.forEach((item) => {\n if (item.resource) {\n const [target] = getParsedTargetSelector(canvas, item.target);\n items.push({ annotationId: item.annotationId, text: parseType(item.resource), target: target as any });\n }\n });\n\n return {\n type: 'textual-content',\n items,\n } as TextualContentStrategy;\n}\n","import { CanvasNormalized } from '@iiif/presentation-3-normalized';\nimport { unsupportedStrategy } from './rendering-utils';\nimport { MediaStrategy } from './strategies';\nimport { Paintables } from '@iiif/helpers';\n\n// https://stackoverflow.com/a/27728417\nconst ytRegex = /^.*(?:(?:youtu\\.be\\/|v\\/|vi\\/|u\\/\\w\\/|embed\\/|shorts\\/)|(?:(?:watch)?\\?vi?=|&vi?=))([^#&?]*).*/;\n\nexport function getVideoStrategy(canvas: CanvasNormalized, paintables: Paintables) {\n const videoPaintables = paintables.items.filter((t) => t.type === 'video');\n\n if (!canvas.duration) {\n return unsupportedStrategy('No duration on canvas');\n }\n\n if (videoPaintables.length > 1) {\n return unsupportedStrategy('Only one video source supported');\n }\n\n const audioResource = videoPaintables[0]?.resource as any; // @todo stronger type for what this might be.\n const isYouTube = !!(audioResource.service || []).find((service: any) =>\n (service.profile || '').includes('youtube.com')\n );\n\n if (!audioResource) {\n return unsupportedStrategy('Unknown video');\n }\n\n if (!audioResource.format || audioResource.format === 'text/html') {\n if (!isYouTube) {\n return unsupportedStrategy('Video does not have format');\n }\n }\n\n const media = {\n annotationId: (paintables.items[0] as any).annotationId,\n duration: canvas.duration,\n url: audioResource.id,\n type: 'Video',\n items: [],\n target: {\n type: 'TemporalSelector',\n temporal: {\n startTime: 0,\n endTime: canvas.duration,\n },\n },\n format: audioResource.format,\n selector: {\n type: 'TemporalSelector',\n temporal: {\n startTime: 0,\n endTime: canvas.duration,\n },\n },\n };\n\n if (isYouTube) {\n media.type = 'VideoYouTube';\n const id = audioResource.id.match(ytRegex);\n if (!id[1]) {\n return unsupportedStrategy('Video is not known youtube video');\n }\n (media as any).youTubeId = id[1];\n }\n\n // @todo support VTT\n\n return {\n type: 'media',\n media,\n annotations: {\n pages: [],\n },\n } as MediaStrategy;\n}\n","import { get3dStrategy } from './3d-strategy';\nimport { getAudioStrategy } from './audio-strategy';\nimport { getImageStrategy } from './image-strategy';\nimport { emptyStrategy, unknownResponse, unsupportedStrategy } from './rendering-utils';\nimport { getTextualContentStrategy } from './textual-content-strategy';\nimport { getVideoStrategy } from './video-strategy';\nimport type { CanvasNormalized } from '@iiif/presentation-3-normalized';\nimport type { Paintables } from '@iiif/helpers/painting-annotations';\nimport type { ImageServiceLoaderType } from '../../hooks/useLoadImageService';\n\ninterface GetRenderStrategyOptions {\n canvas: CanvasNormalized | null | undefined;\n paintables: Paintables;\n supports: string[];\n loadImageService: ImageServiceLoaderType;\n}\n\nexport function getRenderingStrategy({ canvas, paintables, supports, loadImageService }: GetRenderStrategyOptions) {\n if (!canvas) {\n console.log('No canvas');\n return unknownResponse;\n }\n\n if (paintables.types.length === 0) {\n if (supports.indexOf('empty') !== -1) {\n return emptyStrategy(canvas.width, canvas.height);\n }\n console.log('No paintables');\n return unknownResponse;\n }\n\n if (paintables.types.length !== 1) {\n if (paintables.types.length === 2 && paintables.types.indexOf('text') !== -1) {\n paintables.types = paintables.types.filter((t) => t !== 'text');\n } else {\n if (supports.indexOf('complex-timeline') === -1) {\n return unsupportedStrategy('Complex timeline not supported');\n }\n return unsupportedStrategy('ComplexTimelineStrategy not yet supported');\n }\n }\n\n const mainType = paintables.types[0];\n\n // Image\n if (mainType === 'image') {\n if (supports.indexOf('images') === -1) {\n return unsupportedStrategy('Image not supported');\n }\n\n return getImageStrategy(canvas, paintables, loadImageService);\n }\n\n // 3D\n if (mainType === 'Model' || mainType === 'model') {\n if (supports.indexOf('3d-model') === -1) {\n return unsupportedStrategy('3D not supported');\n }\n\n return get3dStrategy(canvas, paintables);\n }\n\n if (mainType === 'textualbody') {\n if (supports.indexOf('textual-content') === -1) {\n return unsupportedStrategy('Textual content not supported');\n }\n\n return getTextualContentStrategy(canvas, paintables);\n }\n\n if (mainType === 'sound' || mainType === 'audio') {\n if (supports.indexOf('media') === -1) {\n return unsupportedStrategy('Media not supported');\n }\n\n // Media Strategy with audio or audio sequence.\n return getAudioStrategy(canvas, paintables);\n }\n\n if (mainType === 'video') {\n if (supports.indexOf('media') === -1) {\n return unsupportedStrategy('Media not supported');\n }\n\n // Media Strategy with video or video sequence.\n return getVideoStrategy(canvas, paintables);\n }\n\n // Unknown fallback.\n return unknownResponse;\n}\n"],"names":["parseSpecificResource","resource","getParsedTargetSelector","canvas","target","imageTarget","source","expandTarget","defaultTarget","emptyActions","unknownResponse","unsupportedStrategy","reason","emptyStrategy","width","height","supportedFormats","get3dStrategy","paintables","getAudioStrategy","audioResource","_a","getImageStrategy","loadImageService","imageTypes","singleImage","imageService","imageServices","getImageServices","imageSelector","found","selector","imageType","parseType","item","languageMap","lang","language","inner","getTextualContentStrategy","items","ytRegex","getVideoStrategy","videoPaintables","t","isYouTube","service","media","id","getRenderingStrategy","supports","mainType"],"mappings":";;;AAYO,SAASA,EAAsBC,GAA2B;AAC3D,SAAAA,EAAS,SAAS,qBACb,CAACA,EAAS,QAAQ,EAAE,UAAUA,EAAS,UAAU,IAGnD,CAACA,GAAU,EAAE,UAAU,KAAM,CAAA;AACtC;AAEgB,SAAAC,EACdC,GACAC,GACuF;AACvF,QAAM,EAAE,UAAUC,GAAa,QAAAC,EAAO,IAAIC,EAAaH,CAAM;AAEzD,MAAAE,EAAO,OAAOH,EAAO;AAEhB,WAAA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,EAAW,MAAM,WAAW;AAC9B,WAAIgC,EAAS,QAAQ,OAAO,MAAM,KACzBrC,EAAcV,EAAO,OAAOA,EAAO,MAAM,KAElD,QAAQ,IAAI,eAAe,GACpBO;AAGL,MAAAQ,EAAW,MAAM,WAAW;AAC1B,QAAAA,EAAW,MAAM,WAAW,KAAKA,EAAW,MAAM,QAAQ,MAAM,MAAM;AACxE,MAAAA,EAAW,QAAQA,EAAW,MAAM,OAAO,CAAC0B,MAAMA,MAAM,MAAM;AAAA;AAE9D,aAAIM,EAAS,QAAQ,kBAAkB,MAAM,KACpCvC,EAAoB,gCAAgC,IAEtDA,EAAoB,2CAA2C;AAIpE,QAAAwC,IAAWjC,EAAW,MAAM,CAAC;AAGnC,SAAIiC,MAAa,UACXD,EAAS,QAAQ,QAAQ,MAAM,KAC1BvC,EAAoB,qBAAqB,IAG3CW,EAAiBnB,GAAQe,GAAYK,CAAgB,IAI1D4B,MAAa,WAAWA,MAAa,UACnCD,EAAS,QAAQ,UAAU,MAAM,KAC5BvC,EAAoB,kBAAkB,IAGxCM,EAAcd,GAAQe,CAAU,IAGrCiC,MAAa,gBACXD,EAAS,QAAQ,iBAAiB,MAAM,KACnCvC,EAAoB,+BAA+B,IAGrD4B,EAA0BpC,GAAQe,CAAU,IAGjDiC,MAAa,WAAWA,MAAa,UACnCD,EAAS,QAAQ,OAAO,MAAM,KACzBvC,EAAoB,qBAAqB,IAI3CQ,EAAiBhB,GAAQe,CAAU,IAGxCiC,MAAa,UACXD,EAAS,QAAQ,OAAO,MAAM,KACzBvC,EAAoB,qBAAqB,IAI3C+B,EAAiBvC,GAAQe,CAAU,IAIrCR;AACT;"}
|
|
1
|
+
{"version":3,"file":"utils.mjs","sources":["../../../src/features/rendering-strategy/rendering-utils.ts","../../../src/features/rendering-strategy/3d-strategy.ts","../../../src/features/rendering-strategy/audio-strategy.ts","../../../src/features/rendering-strategy/image-strategy.ts","../../../src/features/rendering-strategy/textual-content-strategy.ts","../../../src/features/rendering-strategy/video-strategy.ts","../../../src/features/rendering-strategy/get-rendering-strategy.ts"],"sourcesContent":["import { ContentResource, PointSelector, W3CAnnotationTarget } from '@iiif/presentation-3';\nimport { CanvasNormalized } from '@iiif/presentation-3-normalized';\nimport { UseRenderingStrategy } from '../../hooks/useRenderingStrategy';\nimport { BoxSelector, expandTarget, SupportedTarget, TemporalBoxSelector } from '@iiif/helpers';\n\n/**\n * Parse specific resource.\n *\n * This could be expanded to support pulling out more from the specific resource.\n *\n * @param resource\n */\nexport function parseSpecificResource(resource: ContentResource) {\n if (resource.type === 'SpecificResource') {\n return [resource.source, { selector: resource.selector }];\n }\n\n return [resource, { selector: null }];\n}\n\nexport function getParsedTargetSelector(\n canvas: CanvasNormalized,\n target: W3CAnnotationTarget | W3CAnnotationTarget[]\n): [TemporalBoxSelector | BoxSelector | PointSelector | null, SupportedTarget['source']] {\n const { selector: imageTarget, source } = expandTarget(target);\n\n if (source.id !== canvas.id) {\n // Skip invalid targets.\n return [null, source];\n }\n\n // Target is where it should be painted.\n const defaultTarget: BoxSelector = {\n type: 'BoxSelector',\n spatial: {\n x: 0,\n y: 0,\n width: Number(canvas.width),\n height: Number(canvas.height),\n },\n };\n\n return [\n imageTarget\n ? imageTarget.type === 'TemporalSelector'\n ? ({\n type: 'TemporalBoxSelector',\n temporal: imageTarget.temporal,\n spatial: defaultTarget.spatial,\n } as any)\n : imageTarget\n : null,\n source,\n ];\n}\n\nexport const emptyActions = {\n makeChoice: () => {\n // no-op\n },\n};\n\nexport const unknownResponse: UseRenderingStrategy[0] = { type: 'unknown' };\n\nexport const unsupportedStrategy = (reason: string): UseRenderingStrategy[0] => {\n return { type: 'unknown', reason, annotations: { pages: [] } };\n};\n\nexport const emptyStrategy = (width: number, height: number): UseRenderingStrategy[0] => {\n return { type: 'empty', width, height, annotations: { pages: [] }, image: null, images: [] };\n};\n","import { CanvasNormalized } from '@iiif/presentation-3-normalized';\nimport { unsupportedStrategy } from './rendering-utils';\nimport { AnnotationPageDescription } from './resource-types';\nimport { ExternalWebResource } from '@iiif/presentation-3';\nimport { RenderingStrategy } from './strategies';\nimport { ChoiceDescription, Paintables } from '@iiif/helpers';\n\nexport type Single3DModelStrategy = {\n type: '3d-model';\n model: ExternalWebResource;\n choice?: ChoiceDescription; // future\n annotations?: AnnotationPageDescription; // future\n};\n\nconst supportedFormats = ['model/gltf-binary'];\n\nexport function get3dStrategy(canvas: CanvasNormalized, paintables: Paintables): RenderingStrategy {\n const first = paintables.items[0];\n const resource = first.resource as ExternalWebResource;\n\n if (!resource.format) {\n return unsupportedStrategy('Unknown format');\n }\n\n if (supportedFormats.indexOf(resource.format) === -1) {\n return unsupportedStrategy(`3D format: ${resource.format} is unsupported`);\n }\n\n return {\n type: '3d-model',\n model: resource as any,\n } as Single3DModelStrategy;\n}\n","import { CanvasNormalized } from '@iiif/presentation-3-normalized';\nimport { unsupportedStrategy } from './rendering-utils';\nimport { MediaStrategy } from './strategies';\nimport { Paintables } from '@iiif/helpers';\n\nexport function getAudioStrategy(canvas: CanvasNormalized, paintables: Paintables) {\n if (!canvas.duration) {\n return unsupportedStrategy('No duration on canvas');\n }\n\n if (paintables.items.length > 1) {\n return unsupportedStrategy('Only one audio source supported');\n }\n\n const audioResource = paintables.items[0]?.resource as any; // @todo stronger type for what this might be.\n\n if (!audioResource) {\n return unsupportedStrategy('Unknown audio');\n }\n\n if (!audioResource.format) {\n return unsupportedStrategy('Audio does not have format');\n }\n\n return {\n type: 'media',\n media: {\n annotationId: paintables.items[0].annotationId,\n duration: canvas.duration,\n url: audioResource.id,\n type: 'Sound',\n target: {\n type: 'TemporalSelector',\n temporal: {\n startTime: 0,\n endTime: canvas.duration,\n },\n },\n format: audioResource.format,\n selector: {\n type: 'TemporalSelector',\n temporal: {\n startTime: 0,\n endTime: canvas.duration,\n },\n },\n },\n annotations: {\n pages: [],\n },\n } as MediaStrategy;\n}\n","import { IIIFExternalWebResource } from '@iiif/presentation-3';\nimport { CanvasNormalized } from '@iiif/presentation-3-normalized';\nimport { ImageServiceLoaderType } from '../../hooks/useLoadImageService';\nimport { AnnotationPageDescription, ImageWithOptionalService } from './resource-types';\nimport { getImageServices } from '@atlas-viewer/iiif-image-api';\nimport { getParsedTargetSelector, unsupportedStrategy } from './rendering-utils';\nimport { expandTarget } from '@iiif/helpers/annotation-targets';\nimport { BoxSelector, ChoiceDescription, Paintables } from '@iiif/helpers';\n\nexport type SingleImageStrategy = {\n type: 'images';\n image: ImageWithOptionalService;\n images: Array<ImageWithOptionalService>;\n choice?: ChoiceDescription;\n annotations?: AnnotationPageDescription;\n};\n\nexport function getImageStrategy(\n canvas: CanvasNormalized,\n paintables: Paintables,\n loadImageService: ImageServiceLoaderType\n) {\n const imageTypes: ImageWithOptionalService[] = [];\n for (const singleImage of paintables.items) {\n // SingleImageStrategy\n const resource: IIIFExternalWebResource =\n singleImage.resource && singleImage.resource.type === 'SpecificResource'\n ? singleImage.resource.source\n : singleImage.resource;\n\n // Validation.\n if (!resource.id) {\n // @todo we could skip this?\n return unsupportedStrategy('No resource Identifier');\n }\n\n let imageService = undefined;\n if (resource.service) {\n const imageServices = getImageServices(resource as any) as any[];\n if (imageServices[0]) {\n imageService = loadImageService(imageServices[0], canvas);\n }\n }\n\n // Target is where it should be painted.\n const defaultTarget: BoxSelector = {\n type: 'BoxSelector',\n spatial: {\n x: 0,\n y: 0,\n width: Number(canvas.width),\n height: Number(canvas.height),\n },\n };\n\n const [target, source] = getParsedTargetSelector(canvas, singleImage.target);\n if (source.id !== canvas.id) {\n // Skip invalid targets.\n continue;\n }\n\n // Support for cropping before painting an annotation.\n // @todo this isn't working.\n const defaultImageSelector =\n (singleImage.resource as any).width && (singleImage.resource as any).height\n ? ({\n type: 'BoxSelector',\n spatial: {\n x: 0,\n y: 0,\n width: (singleImage.resource as any).width,\n height: (singleImage.resource as any).height,\n },\n } as BoxSelector)\n : undefined;\n\n let imageSelector = singleImage.resource.type === 'SpecificResource' ? expandTarget(singleImage.resource) : null;\n\n if (singleImage.selector) {\n const found = expandTarget({\n type: 'SpecificResource',\n source: singleImage.resource,\n selector: singleImage.selector,\n });\n\n if (found) {\n imageSelector = found;\n }\n }\n\n const selector: undefined | BoxSelector =\n imageSelector &&\n imageSelector.selector &&\n (imageSelector.selector.type === 'BoxSelector' || imageSelector.selector.type === 'TemporalBoxSelector')\n ? {\n type: 'BoxSelector',\n spatial: {\n x: imageSelector.selector.spatial.x,\n y: imageSelector.selector.spatial.y,\n width: imageSelector.selector.spatial.width,\n height: imageSelector.selector.spatial.height,\n },\n }\n : undefined;\n\n if (imageService && !imageService.id) {\n (imageService as any).id = imageService['@id'];\n }\n\n const imageType: ImageWithOptionalService = {\n id: resource.id,\n type: 'Image',\n annotationId: (singleImage as any).annotationId,\n width: Number(target || selector ? resource.width : canvas.width),\n height: Number(target || selector ? resource.height : canvas.height),\n service: imageService,\n sizes:\n imageService && imageService.sizes\n ? imageService.sizes\n : resource.width && resource.height\n ? [{ width: resource.width, height: resource.height }]\n : [],\n target: target && target.type !== 'PointSelector' ? target : defaultTarget,\n selector: selector,\n };\n\n imageTypes.push(imageType);\n }\n\n return {\n type: 'images',\n image: imageTypes[0],\n images: imageTypes,\n choice: paintables.choice,\n } as SingleImageStrategy;\n}\n","import { InternationalString } from '@iiif/presentation-3';\nimport { CanvasNormalized } from '@iiif/presentation-3-normalized';\nimport { AnnotationPageDescription } from './resource-types';\nimport { getParsedTargetSelector } from './rendering-utils';\nimport { RenderingStrategy } from './strategies';\nimport { ChoiceDescription, Paintables, SupportedTarget } from '@iiif/helpers';\n\nexport type TextualContentStrategy = {\n type: 'textual-content';\n items: { annotationId: string; text: InternationalString; target: SupportedTarget | null }[];\n choice?: ChoiceDescription; // future\n annotations?: AnnotationPageDescription; // future\n};\n\nfunction parseType(item: any, languageMap: InternationalString = {}, lang?: string) {\n const language = item.language || lang || 'none';\n switch (item.type) {\n case 'TextualBody': {\n if (typeof item.value !== 'undefined') {\n languageMap[language] = item.value;\n }\n break;\n }\n case 'List':\n case 'Composite':\n case 'Choice': {\n if (item.items) {\n item.items.forEach((inner: any) => parseType(inner, languageMap, language));\n }\n }\n }\n return languageMap;\n}\n\nexport function getTextualContentStrategy(canvas: CanvasNormalized, paintables: Paintables): RenderingStrategy {\n const items: TextualContentStrategy['items'] = [];\n\n paintables.items.forEach((item) => {\n if (item.resource) {\n const [target] = getParsedTargetSelector(canvas, item.target);\n items.push({ annotationId: item.annotationId, text: parseType(item.resource), target: target as any });\n }\n });\n\n return {\n type: 'textual-content',\n items,\n } as TextualContentStrategy;\n}\n","import { CanvasNormalized } from '@iiif/presentation-3-normalized';\nimport { unsupportedStrategy } from './rendering-utils';\nimport { MediaStrategy } from './strategies';\nimport { Paintables } from '@iiif/helpers';\n\n// https://stackoverflow.com/a/27728417\nconst ytRegex = /^.*(?:(?:youtu\\.be\\/|v\\/|vi\\/|u\\/\\w\\/|embed\\/|shorts\\/)|(?:(?:watch)?\\?vi?=|&vi?=))([^#&?]*).*/;\n\nexport function getVideoStrategy(canvas: CanvasNormalized, paintables: Paintables) {\n const videoPaintables = paintables.items.filter((t) => t.type === 'video');\n\n let noDuration = false;\n\n if (!canvas.duration) {\n noDuration = true;\n }\n\n if (videoPaintables.length > 1) {\n return unsupportedStrategy('Only one video source supported');\n }\n\n const videoResource = videoPaintables[0]?.resource as any; // @todo stronger type for what this might be.\n const isYouTube = !!(videoResource.service || []).find((service: any) =>\n (service.profile || '').includes('youtube.com')\n );\n\n if (!isYouTube && noDuration) {\n return unsupportedStrategy('Video does not have duration');\n }\n\n if (!videoResource) {\n return unsupportedStrategy('Unknown video');\n }\n\n if (!videoResource.format || videoResource.format === 'text/html') {\n if (!isYouTube) {\n return unsupportedStrategy('Video does not have format');\n }\n }\n\n const media = {\n annotationId: (paintables.items[0] as any).annotationId,\n duration: canvas.duration,\n url: videoResource.id,\n type: 'Video',\n items: [],\n target: {\n type: 'TemporalSelector',\n temporal: {\n startTime: 0,\n endTime: canvas.duration,\n },\n },\n format: videoResource.format,\n selector: {\n type: 'TemporalSelector',\n temporal: {\n startTime: 0,\n endTime: canvas.duration,\n },\n },\n };\n\n if (isYouTube) {\n media.type = 'VideoYouTube';\n const id = videoResource.id.match(ytRegex);\n if (!id[1]) {\n return unsupportedStrategy('Video is not known youtube video');\n }\n (media as any).youTubeId = id[1];\n }\n\n // @todo support VTT\n\n return {\n type: 'media',\n media,\n annotations: {\n pages: [],\n },\n } as MediaStrategy;\n}\n","import { get3dStrategy } from './3d-strategy';\nimport { getAudioStrategy } from './audio-strategy';\nimport { getImageStrategy } from './image-strategy';\nimport { emptyStrategy, unknownResponse, unsupportedStrategy } from './rendering-utils';\nimport { getTextualContentStrategy } from './textual-content-strategy';\nimport { getVideoStrategy } from './video-strategy';\nimport type { CanvasNormalized } from '@iiif/presentation-3-normalized';\nimport type { Paintables } from '@iiif/helpers/painting-annotations';\nimport type { ImageServiceLoaderType } from '../../hooks/useLoadImageService';\n\ninterface GetRenderStrategyOptions {\n canvas: CanvasNormalized | null | undefined;\n paintables: Paintables;\n supports: string[];\n loadImageService: ImageServiceLoaderType;\n}\n\nexport function getRenderingStrategy({ canvas, paintables, supports, loadImageService }: GetRenderStrategyOptions) {\n if (!canvas) {\n console.log('No canvas');\n return unknownResponse;\n }\n\n if (paintables.types.length === 0) {\n if (supports.indexOf('empty') !== -1) {\n return emptyStrategy(canvas.width, canvas.height);\n }\n console.log('No paintables');\n return unknownResponse;\n }\n\n if (paintables.types.length !== 1) {\n if (paintables.types.length === 2 && paintables.types.indexOf('text') !== -1) {\n paintables.types = paintables.types.filter((t) => t !== 'text');\n } else {\n if (supports.indexOf('complex-timeline') === -1) {\n return unsupportedStrategy('Complex timeline not supported');\n }\n return unsupportedStrategy('ComplexTimelineStrategy not yet supported');\n }\n }\n\n const mainType = paintables.types[0];\n\n // Image\n if (mainType === 'image') {\n if (supports.indexOf('images') === -1) {\n return unsupportedStrategy('Image not supported');\n }\n\n return getImageStrategy(canvas, paintables, loadImageService);\n }\n\n // 3D\n if (mainType === 'Model' || mainType === 'model') {\n if (supports.indexOf('3d-model') === -1) {\n return unsupportedStrategy('3D not supported');\n }\n\n return get3dStrategy(canvas, paintables);\n }\n\n if (mainType === 'textualbody') {\n if (supports.indexOf('textual-content') === -1) {\n return unsupportedStrategy('Textual content not supported');\n }\n\n return getTextualContentStrategy(canvas, paintables);\n }\n\n if (mainType === 'sound' || mainType === 'audio') {\n if (supports.indexOf('media') === -1) {\n return unsupportedStrategy('Media not supported');\n }\n\n // Media Strategy with audio or audio sequence.\n return getAudioStrategy(canvas, paintables);\n }\n\n if (mainType === 'video') {\n if (supports.indexOf('media') === -1) {\n return unsupportedStrategy('Media not supported');\n }\n\n // Media Strategy with video or video sequence.\n return getVideoStrategy(canvas, paintables);\n }\n\n // Unknown fallback.\n return unknownResponse;\n}\n"],"names":["parseSpecificResource","resource","getParsedTargetSelector","canvas","target","imageTarget","source","expandTarget","defaultTarget","emptyActions","unknownResponse","unsupportedStrategy","reason","emptyStrategy","width","height","supportedFormats","get3dStrategy","paintables","getAudioStrategy","audioResource","_a","getImageStrategy","loadImageService","imageTypes","singleImage","imageService","imageServices","getImageServices","imageSelector","found","selector","imageType","parseType","item","languageMap","lang","language","inner","getTextualContentStrategy","items","ytRegex","getVideoStrategy","videoPaintables","t","noDuration","videoResource","isYouTube","service","media","id","getRenderingStrategy","supports","mainType"],"mappings":";;;AAYO,SAASA,EAAsBC,GAA2B;AAC3D,SAAAA,EAAS,SAAS,qBACb,CAACA,EAAS,QAAQ,EAAE,UAAUA,EAAS,UAAU,IAGnD,CAACA,GAAU,EAAE,UAAU,KAAM,CAAA;AACtC;AAEgB,SAAAC,EACdC,GACAC,GACuF;AACvF,QAAM,EAAE,UAAUC,GAAa,QAAAC,EAAO,IAAIC,EAAaH,CAAM;AAEzD,MAAAE,EAAO,OAAOH,EAAO;AAEhB,WAAA,CAAC,MAAMG,CAAM;AAItB,QAAME,IAA6B;AAAA,IACjC,MAAM;AAAA,IACN,SAAS;AAAA,MACP,GAAG;AAAA,MAC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