ProjectMirador / mirador-annotations

a Mirador 3 plugin that adds annotation creation tools to the user interface
https://mirador-annotations.netlify.app/
39 stars 38 forks source link

Support alternative selectors #21

Closed robcast closed 4 years ago

robcast commented 4 years ago

Web Annotation supports multiple alternative selectors on a target, e.g. a SVG annotation and a #xywh fragment bounding box:

"Multiple Selectors SHOULD select the same content, however some Selectors will not have the same precision as others. Consuming user agents MUST pick one of the described segments, if they are different." (https://www.w3.org/TR/annotation-model/#selectors)

Mirador 2 annotations already support this using an oa:Choice selector:

  "selector": {
    "@type": "oa:Choice",
    "default": {
      "@type": "oa:FragmentSelector",
      "value": "xywh=585,1561,930,1131"
    },
    "item": {
      "@type": "oa:SvgSelector",
      "value": "<svg xmlns=http://www.w3.org/2000/svg><path xmlns=\"http://www.w3.org/2000/svg\" d=\"M585.10619,1560.88496h465.04425v0h465.04425v565.48673v565.48673h-465.04425h-465.04425v-565.48673z\" data-paper-data=\"{&quot;strokeWidth&quot;:1,&quot;rotation&quot;:0,&quot;deleteIcon&quot;:null,&quot;rotationIcon&quot;:null,&quot;group&quot;:null,&quot;editable&quot;:true,&quot;annotation&quot;:null}\" id=\"rectangle_0bd196c7-8796-4770-b793-58e2dfcf4d73\" fill-opacity=\"0\" fill=\"#00bfff\" fill-rule=\"nonzero\" stroke=\"#00bfff\" stroke-width=\"1\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-miterlimit=\"10\" stroke-dasharray=\"\" stroke-dashoffset=\"0\" font-family=\"none\" font-weight=\"none\" font-size=\"none\" text-anchor=\"none\" style=\"mix-blend-mode: normal\"/></svg>"
    }
  }

In WebAnno this could become:

  "selector": [
    {
      "@type": "FragmentSelector",
      "value": "xywh=585,1561,930,1131"
    },
    {
      "@type": "SvgSelector",
      "value": "<svg xmlns=http://www.w3.org/2000/svg><path xmlns=\"http://www.w3.org/2000/svg\" d=\"M585.10619,1560.88496h465.04425v0h465.04425v565.48673v565.48673h-465.04425h-465.04425v-565.48673z\" data-paper-data=\"{&quot;strokeWidth&quot;:1,&quot;rotation&quot;:0,&quot;deleteIcon&quot;:null,&quot;rotationIcon&quot;:null,&quot;group&quot;:null,&quot;editable&quot;:true,&quot;annotation&quot;:null}\" id=\"rectangle_0bd196c7-8796-4770-b793-58e2dfcf4d73\" fill-opacity=\"0\" fill=\"#00bfff\" fill-rule=\"nonzero\" stroke=\"#00bfff\" stroke-width=\"1\" stroke-linecap=\"butt\" stroke-linejoin=\"miter\" stroke-miterlimit=\"10\" stroke-dasharray=\"\" stroke-dashoffset=\"0\" font-family=\"none\" font-weight=\"none\" font-size=\"none\" text-anchor=\"none\" style=\"mix-blend-mode: normal\"/></svg>"
    }
  ]

The annotation plugin needs to

robcast commented 4 years ago

I have an implementation of WebAnnotation.js that creates JSON with an array of selectors:

https://github.com/robcast/mirador-annotations/blob/alternate-target-selector/src/WebAnnotation.js

In the last commit I decided that it is better to always create a selector, even when we only have a fragment. I can back that out if you think we should keep generating just a target with appended fragment.

robcast commented 4 years ago

I also have a SAS adapter version to match:

https://github.com/robcast/mirador-annotations/blob/simple-sas-adapter/src/SimpleAnnotationServerV2Adapter.js

robcast commented 4 years ago

I even have a test version that translates OpenAnnotations into WebAnnotations with multiple selectors:

https://github.com/robcast/mirador-annotations/blob/7218619b91d4bd1998808cd9bc9eae94af107407/src/SimpleAnnotationServerV2Adapter.js

but it crashes in Mirador's AnnotationItem.js:171 because that assumes selector can't be an array ;-(

mejackreed commented 4 years ago

@robcast yep working on an upstream fix right now

mejackreed commented 4 years ago

See https://github.com/ProjectMirador/mirador/pull/3232