2020-01-27 17:28:07 +01:00
|
|
|
import React, { useState } from 'react'
|
|
|
|
import Draft from '../../Draft'
|
2020-04-25 13:29:02 +02:00
|
|
|
import Zoombox from '../Zoombox'
|
2020-01-27 17:28:07 +01:00
|
|
|
import Design from '../Design'
|
|
|
|
import fileSaver from 'file-saver'
|
|
|
|
import theme from '@freesewing/plugin-theme'
|
2020-07-18 16:48:29 +02:00
|
|
|
import Events from './Events'
|
2019-05-03 19:54:46 +02:00
|
|
|
|
2020-04-25 13:29:02 +02:00
|
|
|
const DraftPattern = (props) => {
|
|
|
|
const svgToFile = (svg) => {
|
2019-07-19 12:48:57 +02:00
|
|
|
const blob = new Blob([svg], {
|
2020-01-27 17:28:07 +01:00
|
|
|
type: 'image/svg+xml;charset=utf-8'
|
|
|
|
})
|
|
|
|
fileSaver.saveAs(blob, 'freesewing-' + props.config.name + '.svg')
|
|
|
|
}
|
2019-07-19 12:48:57 +02:00
|
|
|
|
|
|
|
if (props.svgExport) {
|
|
|
|
svgToFile(
|
2019-09-17 10:41:57 +02:00
|
|
|
new props.Pattern({
|
|
|
|
...props.gist.settings,
|
|
|
|
embed: false
|
|
|
|
})
|
2019-07-19 12:48:57 +02:00
|
|
|
.use(theme)
|
|
|
|
.draft()
|
|
|
|
.render()
|
2020-01-27 17:28:07 +01:00
|
|
|
)
|
|
|
|
props.setSvgExport(false)
|
2019-07-19 12:48:57 +02:00
|
|
|
}
|
|
|
|
|
2020-01-27 17:28:07 +01:00
|
|
|
let focusCount = 0
|
2019-05-09 15:24:26 +02:00
|
|
|
if (focus !== null) {
|
|
|
|
for (let p of Object.keys(focus)) {
|
2020-01-27 17:28:07 +01:00
|
|
|
for (let i in focus[p].points) focusCount++
|
|
|
|
for (let i in focus[p].paths) focusCount++
|
|
|
|
for (let i in focus[p].coords) focusCount++
|
2019-05-09 15:24:26 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-03 19:54:46 +02:00
|
|
|
return (
|
2021-01-10 15:06:38 +01:00
|
|
|
<>
|
2020-10-25 18:35:28 +01:00
|
|
|
<Draft
|
|
|
|
{...props.patternProps}
|
|
|
|
design={props.design}
|
|
|
|
focus={props.focus}
|
|
|
|
raiseEvent={props.raiseEvent}
|
|
|
|
viewBox={props.viewBox}
|
|
|
|
className="freesewing draft shadow"
|
|
|
|
/>
|
|
|
|
<Events events={props.patternProps.events} />
|
2021-01-10 15:06:38 +01:00
|
|
|
</>
|
2020-01-27 17:28:07 +01:00
|
|
|
)
|
|
|
|
}
|
2019-05-03 19:54:46 +02:00
|
|
|
|
2020-01-27 17:28:07 +01:00
|
|
|
export default DraftPattern
|