MCPcopy Create free account
hub / github.com/simstudioai/sim / inferPathExtent

Function inferPathExtent

apps/sim/lib/pptx-renderer/shapes/custom-geometry.ts:7–35  ·  view source on GitHub ↗
(pathNode: SafeXmlNode)

Source from the content-addressed store, hash-verified

5import type { SafeXmlNode } from '../parser/xml-parser'
6
7function inferPathExtent(pathNode: SafeXmlNode): { w: number; h: number } {
8 let maxX = 0
9 let maxY = 0
10
11 for (const cmd of pathNode.allChildren()) {
12 if (cmd.localName === 'moveTo' || cmd.localName === 'lnTo') {
13 const pt = cmd.child('pt')
14 maxX = Math.max(maxX, pt.numAttr('x') ?? 0)
15 maxY = Math.max(maxY, pt.numAttr('y') ?? 0)
16 continue
17 }
18 if (cmd.localName === 'cubicBezTo' || cmd.localName === 'quadBezTo') {
19 for (const pt of cmd.children('pt')) {
20 maxX = Math.max(maxX, pt.numAttr('x') ?? 0)
21 maxY = Math.max(maxY, pt.numAttr('y') ?? 0)
22 }
23 continue
24 }
25 if (cmd.localName === 'arcTo') {
26 maxX = Math.max(maxX, cmd.numAttr('wR') ?? 0)
27 maxY = Math.max(maxY, cmd.numAttr('hR') ?? 0)
28 }
29 }
30
31 return {
32 w: Math.max(1, maxX),
33 h: Math.max(1, maxY),
34 }
35}
36
37/**
38 * Render a custom geometry element to an SVG path d-attribute string.

Callers 1

renderCustomGeometryFunction · 0.85

Calls 4

allChildrenMethod · 0.80
childMethod · 0.80
numAttrMethod · 0.80
childrenMethod · 0.80

Tested by

no test coverage detected