|
@@ -1558,26 +1558,32 @@ export class TldrawApp extends StateManager<TDSnapshot> {
|
1558
|
1558
|
copySvg = (ids = this.selectedIds, pageId = this.currentPageId) => {
|
1559
|
1559
|
if (ids.length === 0) ids = Object.keys(this.page.shapes)
|
1560
|
1560
|
|
1561
|
|
- const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
|
1562
|
|
-
|
1563
|
1561
|
const shapes = ids.map((id) => this.getShape(id, pageId))
|
|
1562
|
+ const commonBounds = Utils.getCommonBounds(shapes.map(TLDR.getRotatedBounds))
|
|
1563
|
+ const padding = 16
|
1564
|
1564
|
|
1565
|
|
- function getSvgElementForShape(shape: TDShape) {
|
1566
|
|
- const elm = document.getElementById(shape.id + '_svg')
|
1567
|
|
-
|
1568
|
|
- if (!elm) return
|
|
1565
|
+ const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg')
|
|
1566
|
+ const defs = document.createElementNS('http://www.w3.org/2000/svg', 'defs')
|
|
1567
|
+ const style = document.createElementNS('http://www.w3.org/2000/svg', 'style')
|
1569
|
1568
|
|
1570
|
|
- // TODO: Create SVG elements for text
|
|
1569
|
+ style.textContent = `@import url('https://fonts.googleapis.com/css2?family=Caveat+Brush&family=Source+Code+Pro&family=Source+Sans+Pro&family=Source+Serif+Pro&display=swap');`
|
|
1570
|
+ defs.appendChild(style)
|
|
1571
|
+ svg.appendChild(defs)
|
1571
|
1572
|
|
1572
|
|
- const element = elm?.cloneNode(true) as SVGElement
|
|
1573
|
+ function getSvgElementForShape(shape: TDShape) {
|
|
1574
|
+ const util = TLDR.getShapeUtil(shape)
|
|
1575
|
+ const element = util.getSvgElement(shape)
|
|
1576
|
+ const bounds = util.getBounds(shape)
|
1573
|
1577
|
|
1574
|
|
- const bounds = TLDR.getShapeUtil(shape).getBounds(shape)
|
|
1578
|
+ if (!element) return
|
1575
|
1579
|
|
1576
|
1580
|
element.setAttribute(
|
1577
|
1581
|
'transform',
|
1578
|
|
- `translate(${shape.point[0]}, ${shape.point[1]}) rotate(${
|
1579
|
|
- ((shape.rotation || 0) * 180) / Math.PI
|
1580
|
|
- }, ${bounds.width / 2}, ${bounds.height / 2})`
|
|
1582
|
+ `translate(${padding + shape.point[0] - commonBounds.minX}, ${
|
|
1583
|
+ padding + shape.point[1] - commonBounds.minY
|
|
1584
|
+ }) rotate(${((shape.rotation || 0) * 180) / Math.PI}, ${bounds.width / 2}, ${
|
|
1585
|
+ bounds.height / 2
|
|
1586
|
+ })`
|
1581
|
1587
|
)
|
1582
|
1588
|
|
1583
|
1589
|
return element
|
|
@@ -1608,23 +1614,14 @@ export class TldrawApp extends StateManager<TDSnapshot> {
|
1608
|
1614
|
}
|
1609
|
1615
|
})
|
1610
|
1616
|
|
1611
|
|
- const bounds = Utils.getCommonBounds(shapes.map(TLDR.getRotatedBounds))
|
1612
|
|
- const padding = 16
|
1613
|
|
-
|
1614
|
1617
|
// Resize the element to the bounding box
|
1615
|
1618
|
svg.setAttribute(
|
1616
|
1619
|
'viewBox',
|
1617
|
|
- [
|
1618
|
|
- bounds.minX - padding,
|
1619
|
|
- bounds.minY - padding,
|
1620
|
|
- bounds.width + padding * 2,
|
1621
|
|
- bounds.height + padding * 2,
|
1622
|
|
- ].join(' ')
|
|
1620
|
+ [0, 0, commonBounds.width + padding * 2, commonBounds.height + padding * 2].join(' ')
|
1623
|
1621
|
)
|
1624
|
1622
|
|
1625
|
|
- svg.setAttribute('width', String(bounds.width))
|
1626
|
|
-
|
1627
|
|
- svg.setAttribute('height', String(bounds.height))
|
|
1623
|
+ svg.setAttribute('width', String(commonBounds.width))
|
|
1624
|
+ svg.setAttribute('height', String(commonBounds.height))
|
1628
|
1625
|
|
1629
|
1626
|
const s = new XMLSerializer()
|
1630
|
1627
|
|