|
|
@ -142,23 +142,25 @@ class Editor extends React.Component {
|
|
|
|
|
|
|
|
|
|
|
|
const exportSize = (EXPORT_SIZES_HASH[this.state.exportSize] || DEFAULT_EXPORT_SIZE).value
|
|
|
|
const exportSize = (EXPORT_SIZES_HASH[this.state.exportSize] || DEFAULT_EXPORT_SIZE).value
|
|
|
|
|
|
|
|
|
|
|
|
let width = node.offsetWidth * exportSize
|
|
|
|
const map = new Map()
|
|
|
|
let height = this.state.squaredImage
|
|
|
|
const undoMap = value => {
|
|
|
|
? node.offsetWidth * exportSize
|
|
|
|
map.forEach((value, node) => (node.innerText = value))
|
|
|
|
: node.offsetHeight * exportSize
|
|
|
|
return value
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (isPNG) {
|
|
|
|
if (isPNG) {
|
|
|
|
const newNode = node.cloneNode(true)
|
|
|
|
node.querySelectorAll('span[role="presentation"]').forEach(node => {
|
|
|
|
newNode.querySelectorAll('.CodeMirror-line span[role="presentation"]').forEach(encodeTextNode)
|
|
|
|
if (node.innerText && node.innerText.match(/%\S\S/)) {
|
|
|
|
|
|
|
|
map.set(node, node.innerText)
|
|
|
|
newNode.style.visibility = 'hidden'
|
|
|
|
node.innerText = encodeURIComponent(node.innerText)
|
|
|
|
document.body.appendChild(newNode)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
width = newNode.offsetWidth * exportSize
|
|
|
|
|
|
|
|
height = this.state.squaredImage ? width : newNode.offsetHeight * exportSize
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
newNode.remove()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const width = node.offsetWidth * exportSize
|
|
|
|
|
|
|
|
const height = this.state.squaredImage
|
|
|
|
|
|
|
|
? node.offsetWidth * exportSize
|
|
|
|
|
|
|
|
: node.offsetHeight * exportSize
|
|
|
|
|
|
|
|
|
|
|
|
const config = {
|
|
|
|
const config = {
|
|
|
|
style: {
|
|
|
|
style: {
|
|
|
@ -170,13 +172,6 @@ class Editor extends React.Component {
|
|
|
|
if (n.className) {
|
|
|
|
if (n.className) {
|
|
|
|
return String(n.className).indexOf('eliminateOnRender') < 0
|
|
|
|
return String(n.className).indexOf('eliminateOnRender') < 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
|
|
|
|
isPNG && // only occurs when saving PNG
|
|
|
|
|
|
|
|
n.matches &&
|
|
|
|
|
|
|
|
n.matches('span[role="presentation"]')
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
encodeTextNode(n)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
},
|
|
|
|
},
|
|
|
|
width,
|
|
|
|
width,
|
|
|
@ -193,11 +188,14 @@ class Editor extends React.Component {
|
|
|
|
.then(data => window.URL.createObjectURL(data))
|
|
|
|
.then(data => window.URL.createObjectURL(data))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return domtoimage.toBlob(node, config).then(blob => window.URL.createObjectURL(blob))
|
|
|
|
return domtoimage
|
|
|
|
|
|
|
|
.toBlob(node, config)
|
|
|
|
|
|
|
|
.then(blob => window.URL.createObjectURL(blob))
|
|
|
|
|
|
|
|
.then(undoMap)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Twitter needs regular dataurls
|
|
|
|
// Twitter needs regular dataurls
|
|
|
|
return domtoimage.toPng(node, config)
|
|
|
|
return domtoimage.toPng(node, config).then(undoMap)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
updateSetting(key, value) {
|
|
|
|
updateSetting(key, value) {
|
|
|
@ -376,12 +374,6 @@ class Editor extends React.Component {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function encodeTextNode(node) {
|
|
|
|
|
|
|
|
if (node.innerText && node.innerText.match(/%\S\S/)) {
|
|
|
|
|
|
|
|
node.innerText = encodeURIComponent(node.innerText)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function formatTimestamp() {
|
|
|
|
function formatTimestamp() {
|
|
|
|
const timezoneOffset = new Date().getTimezoneOffset() * 60000
|
|
|
|
const timezoneOffset = new Date().getTimezoneOffset() * 60000
|
|
|
|
const timeString = new Date(Date.now() - timezoneOffset)
|
|
|
|
const timeString = new Date(Date.now() - timezoneOffset)
|
|
|
|