@@ -228,6 +228,13 @@ function shapeXml(element: ShapeElement, part: DrawingPart, opacity: number) {
228228const SVG_BLIP = ( relId : string ) =>
229229 `<a:extLst><a:ext uri="{96DAC541-7B7A-43D3-8B79-37D633B846F1}"><asvg:svgBlip xmlns:asvg="http://schemas.microsoft.com/office/drawing/2016/SVG/main" r:embed="${ relId } "/></a:ext></a:extLst>` ;
230230
231+ function sourceRectXml ( element : PictureElement , info : ImageInfo , area : Box ) {
232+ if ( element . fit === "cover" ) return coverCrop ( info , area ) ;
233+ const { crop } = element ;
234+ if ( ! crop ) return "" ;
235+ return `<a:srcRect l="${ percent ( crop . left ) } " t="${ percent ( crop . top ) } " r="${ percent ( crop . right ) } " b="${ percent ( crop . bottom ) } "/>` ;
236+ }
237+
231238function pictureXml (
232239 element : PictureElement ,
233240 part : DrawingPart ,
@@ -237,13 +244,6 @@ function pictureXml(
237244 const { info, relId } = part . image ( element . image ) ;
238245 const area = boxOf ( element ) ;
239246 const box = element . fit === "contain" ? contain ( info , area ) : area ;
240- const { crop } = element ;
241- const sourceRect =
242- element . fit === "cover"
243- ? coverCrop ( info , area )
244- : crop
245- ? `<a:srcRect l="${ percent ( crop . left ) } " t="${ percent ( crop . top ) } " r="${ percent ( crop . right ) } " b="${ percent ( crop . bottom ) } "/>`
246- : "" ;
247247 const blipChildren = `${ opacity < 1 ? `<a:alphaModFix amt="${ percent ( opacity ) } "/>` : "" } ${ element . svg ? SVG_BLIP ( part . svg ( element . svg ) ) : "" } ` ;
248248 const blip = blipChildren
249249 ? `<a:blip r:embed="${ relId } ">${ blipChildren } </a:blip>`
@@ -253,7 +253,7 @@ function pictureXml(
253253 return {
254254 spid,
255255 build : false ,
256- xml : `<p:pic><p:nvPicPr>${ cNvPr } <p:cNvPicPr><a:picLocks noChangeAspect="1"/></p:cNvPicPr><p:nvPr/></p:nvPicPr><p:blipFill>${ blip } ${ sourceRect } <a:stretch><a:fillRect/></a:stretch></p:blipFill><p:spPr>${ xfrm ( box , element . rotation ) } ${ geometry } ${ line } ${ shadowXml ( element . shadow , box , opacity ) } </p:spPr></p:pic>` ,
256+ xml : `<p:pic><p:nvPicPr>${ cNvPr } <p:cNvPicPr><a:picLocks noChangeAspect="1"/></p:cNvPicPr><p:nvPr/></p:nvPicPr><p:blipFill>${ blip } ${ sourceRectXml ( element , info , area ) } <a:stretch><a:fillRect/></a:stretch></p:blipFill><p:spPr>${ xfrm ( box , element . rotation ) } ${ geometry } ${ line } ${ shadowXml ( element . shadow , box , opacity ) } </p:spPr></p:pic>` ,
257257 } ;
258258}
259259
@@ -288,6 +288,24 @@ function groupXml(
288288 } ;
289289}
290290
291+ function drawnXml (
292+ element : FreeElement ,
293+ part : DrawingPart ,
294+ targets : Map < string , Target > ,
295+ opacity : number ,
296+ ) : Drawn {
297+ switch ( element . type ) {
298+ case "text" :
299+ return textXml ( element , part , opacity ) ;
300+ case "shape" :
301+ return shapeXml ( element , part , opacity ) ;
302+ case "image" :
303+ return pictureXml ( element , part , opacity ) ;
304+ case "group" :
305+ return groupXml ( element , part , targets , opacity ) ;
306+ }
307+ }
308+
291309/** Draws one element, recording the shape id of each element with an `id` for animations. */
292310export function elementXml (
293311 element : FreeElement ,
@@ -296,14 +314,7 @@ export function elementXml(
296314 inherited = 1 ,
297315) : string {
298316 const opacity = inherited * ( element . opacity ?? 1 ) ;
299- const drawn : Drawn =
300- element . type === "text"
301- ? textXml ( element , part , opacity )
302- : element . type === "shape"
303- ? shapeXml ( element , part , opacity )
304- : element . type === "image"
305- ? pictureXml ( element , part , opacity )
306- : groupXml ( element , part , targets , opacity ) ;
317+ const drawn = drawnXml ( element , part , targets , opacity ) ;
307318 if ( element . id !== undefined )
308319 targets . set ( element . id , { spid : drawn . spid , build : drawn . build } ) ;
309320 return drawn . xml ;
0 commit comments