@@ -38,13 +38,18 @@ const parseW3CTextTargets = (annotation: W3CTextAnnotation) => {
3838 } = annotation ;
3939
4040 const w3cTargets = Array . isArray ( target ) ? target : [ target ] ;
41+ if ( w3cTargets . length === 0 ) {
42+ return { error : Error ( `No targets found for annotation: ${ annotation . id } ` ) } ;
43+ }
4144
4245 const parsed : TextAnnotationTarget = {
4346 creator : parseW3CUser ( creator ) ,
4447 created : created ? new Date ( created ) : undefined ,
4548 updated : modified ? new Date ( modified ) : undefined ,
4649 annotation : annotationId ,
47- selector : [ ]
50+ selector : [ ] ,
51+ // @ts -expect-error: `styleClass` is not part of the core `TextAnnotationTarget` type
52+ styleClass : 'styleClass' in w3cTargets [ 0 ] ? w3cTargets [ 0 ] . styleClass : undefined
4853 } ;
4954
5055 for ( const w3cTarget of w3cTargets ) {
@@ -64,12 +69,14 @@ const parseW3CTextTargets = (annotation: W3CTextAnnotation) => {
6469 } , { } ) ;
6570
6671 if ( isTextSelector ( selector ) ) {
67- parsed . selector . push ( {
68- ...selector ,
69- id : w3cTarget . id ,
70- // @ts -ignore
71- scope : w3cTarget . scope
72- } ) ;
72+ parsed . selector . push (
73+ {
74+ ...selector ,
75+ id : w3cTarget . id ,
76+ // @ts -expect-error: `scope` is not part of the core `TextSelector` type
77+ scope : w3cTarget . scope
78+ }
79+ ) ;
7380 } else {
7481 const missingTypes = [
7582 ! selector . start ? 'TextPositionSelector' : undefined ,
@@ -127,7 +134,7 @@ export const serializeW3CTextAnnotation = (
127134 ...targetRest
128135 } = target ;
129136
130- const w3cTargets = selector . map ( ( s ) => {
137+ const w3cTargets = selector . map ( ( s ) : W3CTextAnnotationTarget => {
131138 const { id, quote, start, end, range } = s ;
132139
133140 const { prefix, suffix } = getQuoteContext ( range , container ) ;
@@ -146,10 +153,11 @@ export const serializeW3CTextAnnotation = (
146153 return {
147154 ...targetRest ,
148155 id,
156+ // @ts -expect-error: `scope` is not part of the core `TextAnnotationTarget` type
149157 scope : 'scope' in s ? s . scope : undefined ,
150158 source,
151159 selector : w3cSelectors
152- } as W3CTextAnnotationTarget ;
160+ } ;
153161 } ) ;
154162
155163
0 commit comments