@@ -138,40 +138,10 @@ export class XmlHelper {
138138 return max ;
139139 }
140140
141- static pushRelTargets ( element : Element , prefix : string , targets : Target [ ] ) {
142- const type = element . getAttribute ( 'Type' ) ;
143- const target = element . getAttribute ( 'Target' ) ;
144- const rId = element . getAttribute ( 'Id' ) ;
145-
146- const subtype = _ . last ( prefix . split ( '/' ) ) ;
147- const relType = _ . last ( type . split ( '/' ) ) ;
148-
149- const matchNumber = target . match ( / ( \d + ) / ) ;
150- const stripNumber =
151- matchNumber && matchNumber [ 1 ] ? Number ( matchNumber [ 1 ] ) : 0 ;
152-
153- if ( XmlHelper . targetMatchesRelationship ( relType , subtype , target , prefix ) ) {
154- targets . push ( {
155- file : target ,
156- rId : rId ,
157- number : stripNumber ,
158- type : type ,
159- subtype : subtype ,
160- } as Target ) ;
161- }
162- }
163-
164- static targetMatchesRelationship ( relType , subtype , target , prefix ) {
165- if ( relType === 'package' ) return true ;
166-
167- return relType === subtype && target . indexOf ( prefix ) === 0 ;
168- }
169-
170141 static async getTargetsFromRelationships (
171142 archive : JSZip ,
172143 path : string ,
173144 prefix : string | string [ ] ,
174- suffix ?: string | RegExp ,
175145 ) : Promise < Target [ ] > {
176146 const prefixes = typeof prefix === 'string' ? [ prefix ] : prefix ;
177147
@@ -186,6 +156,45 @@ export class XmlHelper {
186156 ) ;
187157 }
188158
159+ static pushRelTargets ( element : Element , prefix : string , targets : Target [ ] ) {
160+ const type = element . getAttribute ( 'Type' ) ;
161+ const file = element . getAttribute ( 'Target' ) ;
162+ const rId = element . getAttribute ( 'Id' ) ;
163+
164+ const subtype = _ . last ( prefix . split ( '/' ) ) ;
165+ const relType = _ . last ( type . split ( '/' ) ) ;
166+ const filename = _ . last ( file . split ( '/' ) ) ;
167+ const filenameExt = _ . last ( filename . split ( '.' ) ) ;
168+ const filenameMatch = filename
169+ . replace ( '.' + filenameExt , '' )
170+ . match ( / ^ ( .+ ?) ( \d + ) * $ / ) ;
171+
172+ const number =
173+ filenameMatch && filenameMatch [ 2 ] ? Number ( filenameMatch [ 2 ] ) : 0 ;
174+ const filenameBase =
175+ filenameMatch && filenameMatch [ 1 ] ? filenameMatch [ 1 ] : filename ;
176+
177+ if ( XmlHelper . targetMatchesRelationship ( relType , subtype , file , prefix ) ) {
178+ targets . push ( {
179+ file,
180+ rId,
181+ number,
182+ type,
183+ subtype,
184+ prefix,
185+ filename,
186+ filenameExt,
187+ filenameBase,
188+ } as Target ) ;
189+ }
190+ }
191+
192+ static targetMatchesRelationship ( relType , subtype , target , prefix ) {
193+ if ( relType === 'package' ) return true ;
194+
195+ return relType === subtype && target . indexOf ( prefix ) === 0 ;
196+ }
197+
189198 static async getTargetsByRelationshipType (
190199 archive : JSZip ,
191200 path : string ,
@@ -278,7 +287,6 @@ export class XmlHelper {
278287 archive ,
279288 relsPath ,
280289 params . prefix ,
281- params . expression ,
282290 ) ;
283291 const target = imageRels . find ( ( rel ) => rel . rId === sourceRid ) ;
284292
0 commit comments