MCPcopy
hub / github.com/vercel/satori / parseInset

Function parseInset

src/parser/shape.ts:142–196  ·  view source on GitHub ↗
(str: string)

Source from the content-addressed store, hash-verified

140 }
141 }
142 function parseInset(str: string) {
143 const res = str.match(regexMap['inset'])
144
145 if (!res) return null
146
147 const [inset, radius] = (
148 res[1].includes('round') ? res[1] : `${res[1].trim()} round 0`
149 ).split('round')
150 const radiusMap = getStylesForProperty('borderRadius', radius, true)
151 const r = Object.values(radiusMap)
152 .map((s) => String(s))
153 .map(
154 (s, i) =>
155 lengthToNumber(
156 s,
157 inheritedStyle.fontSize as number,
158 i === 0 || i === 2 ? height : width,
159 inheritedStyle,
160 true
161 ) || 0
162 )
163 const offsets = Object.values(getStylesForProperty('margin', inset, true))
164 .map((s) => String(s))
165 .map(
166 (s, i) =>
167 lengthToNumber(
168 s,
169 inheritedStyle.fontSize as number,
170 i === 0 || i === 2 ? height : width,
171 inheritedStyle,
172 true
173 ) || 0
174 )
175 const x = offsets[3]
176 const y = offsets[0]
177 const w = width - (offsets[1] + offsets[3])
178 const h = height - (offsets[0] + offsets[2])
179
180 if (r.some((v) => v > 0)) {
181 const d = buildBorderRadius(
182 { left: x, top: y, width: w, height: h },
183 { ...style, ...radiusMap }
184 )
185
186 return { type: 'path', d }
187 }
188
189 return {
190 type: 'rect',
191 x,
192 y,
193 width: w,
194 height: h,
195 }
196 }
197
198 return {
199 parseCircle,

Callers

nothing calls this directly

Calls 1

lengthToNumberFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…