* Wrap a drawing in paper, padding and the mark. * * `body` is emitted inside a translate that moves the drawing's own origin to * the padded corner, so every caller can keep working in layout coordinates.
(frame: Frame, defs: string, body: string, options: ExportOptions)
| 267 | * the padded corner, so every caller can keep working in layout coordinates. |
| 268 | */ |
| 269 | function document_(frame: Frame, defs: string, body: string, options: ExportOptions): string { |
| 270 | const scale = options.scale ?? 1; |
| 271 | const markRow = MARK_GAP + MARK_SIZE; |
| 272 | const width = Math.max(1, Math.round(frame.width + EXPORT_PADDING * 2)); |
| 273 | const height = Math.max(1, Math.round(frame.height + EXPORT_PADDING * 2 + markRow)); |
| 274 | const markY = height - EXPORT_PADDING; |
| 275 | |
| 276 | const caption = |
| 277 | options.caption == null || options.caption === '' |
| 278 | ? '' |
| 279 | : textEl( |
| 280 | { |
| 281 | x: EXPORT_PADDING, |
| 282 | y: markY, |
| 283 | size: MARK_SIZE, |
| 284 | fill: EXPORT_COLORS.ink3, |
| 285 | family: MONO_STACK, |
| 286 | }, |
| 287 | esc( |
| 288 | truncate( |
| 289 | options.caption, |
| 290 | width - EXPORT_PADDING * 2 - monoWidth(MARK_TEXT.length + 3, MARK_SIZE), |
| 291 | MARK_SIZE |
| 292 | ) |
| 293 | ) |
| 294 | ); |
| 295 | |
| 296 | return [ |
| 297 | `<svg xmlns="http://www.w3.org/2000/svg" width="${Math.round(width * scale)}" height="${Math.round(height * scale)}" viewBox="0 0 ${width} ${height}" font-family="${SANS_STACK}">`, |
| 298 | defs === '' ? '' : `<defs>${defs}</defs>`, |
| 299 | rect(0, 0, width, height, { fill: EXPORT_COLORS.paper }), |
| 300 | `<g transform="translate(${round(EXPORT_PADDING - frame.minX)},${round(EXPORT_PADDING - frame.minY)})">`, |
| 301 | body, |
| 302 | '</g>', |
| 303 | caption, |
| 304 | textEl( |
| 305 | { |
| 306 | x: width - EXPORT_PADDING, |
| 307 | y: markY, |
| 308 | size: MARK_SIZE, |
| 309 | fill: EXPORT_COLORS.ink3, |
| 310 | family: MONO_STACK, |
| 311 | anchor: 'end', |
| 312 | }, |
| 313 | MARK_TEXT |
| 314 | ), |
| 315 | '</svg>', |
| 316 | ] |
| 317 | .filter(Boolean) |
| 318 | .join('\n'); |
| 319 | } |
| 320 | |
| 321 | /* ------------------------------------------------------------ flow strip -- */ |
| 322 |