Support variable export sizes (#264)

main
Takahiko Inayama 7 years ago committed by Jake Dexheimer
parent b1ef2d1263
commit b7adab9bea

@ -248,6 +248,15 @@
"contributions": [ "contributions": [
"code" "code"
] ]
},
{
"login": "TETRA2000",
"name": "Takahiko Inayama",
"avatar_url": "https://avatars1.githubusercontent.com/u/1459450?v=4",
"profile": "https://www.behance.net/tetra2000",
"contributions": [
"code"
]
} }
] ]
} }

@ -78,5 +78,5 @@ Thanks goes out to all these wonderful people ([emoji key](https://github.com/ke
| :---: | :---: | :---: | :---: | :---: | :---: | :---: | | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| [<img src="https://avatars1.githubusercontent.com/u/225946?v=4" width="100px;"/><br /><sub><b>otobrglez</b></sub>](https://github.com/otobrglez)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=otobrglez "Code") | [<img src="https://avatars3.githubusercontent.com/u/11488612?v=4" width="100px;"/><br /><sub><b>darahak</b></sub>](https://github.com/darahak)<br />[πŸ“–](https://github.com/dawnlabs/carbon/commits?author=darahak "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/246651?v=4" width="100px;"/><br /><sub><b>dom96</b></sub>](https://github.com/dom96)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=dom96 "Code") | [<img src="https://avatars3.githubusercontent.com/u/784056?v=4" width="100px;"/><br /><sub><b>elrumordelaluz</b></sub>](https://github.com/elrumordelaluz)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=elrumordelaluz "Code") | [<img src="https://avatars2.githubusercontent.com/u/21217?v=4" width="100px;"/><br /><sub><b>cjb</b></sub>](https://github.com/cjb)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=cjb "Code") | [<img src="https://avatars1.githubusercontent.com/u/5427083?v=4" width="100px;"/><br /><sub><b>Krzysztof-Cieslak</b></sub>](https://github.com/Krzysztof-Cieslak)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=Krzysztof-Cieslak "Code") | [<img src="https://avatars0.githubusercontent.com/u/2369851?v=4" width="100px;"/><br /><sub><b>fernahh</b></sub>](https://github.com/fernahh)<br />[πŸ“–](https://github.com/dawnlabs/carbon/commits?author=fernahh "Documentation") | | [<img src="https://avatars1.githubusercontent.com/u/225946?v=4" width="100px;"/><br /><sub><b>otobrglez</b></sub>](https://github.com/otobrglez)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=otobrglez "Code") | [<img src="https://avatars3.githubusercontent.com/u/11488612?v=4" width="100px;"/><br /><sub><b>darahak</b></sub>](https://github.com/darahak)<br />[πŸ“–](https://github.com/dawnlabs/carbon/commits?author=darahak "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/246651?v=4" width="100px;"/><br /><sub><b>dom96</b></sub>](https://github.com/dom96)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=dom96 "Code") | [<img src="https://avatars3.githubusercontent.com/u/784056?v=4" width="100px;"/><br /><sub><b>elrumordelaluz</b></sub>](https://github.com/elrumordelaluz)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=elrumordelaluz "Code") | [<img src="https://avatars2.githubusercontent.com/u/21217?v=4" width="100px;"/><br /><sub><b>cjb</b></sub>](https://github.com/cjb)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=cjb "Code") | [<img src="https://avatars1.githubusercontent.com/u/5427083?v=4" width="100px;"/><br /><sub><b>Krzysztof-Cieslak</b></sub>](https://github.com/Krzysztof-Cieslak)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=Krzysztof-Cieslak "Code") | [<img src="https://avatars0.githubusercontent.com/u/2369851?v=4" width="100px;"/><br /><sub><b>fernahh</b></sub>](https://github.com/fernahh)<br />[πŸ“–](https://github.com/dawnlabs/carbon/commits?author=fernahh "Documentation") |
| [<img src="https://avatars1.githubusercontent.com/u/10941033?v=4" width="100px;"/><br /><sub><b>g3r4n</b></sub>](https://github.com/g3r4n)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=g3r4n "Code") | [<img src="https://avatars0.githubusercontent.com/u/55830?v=4" width="100px;"/><br /><sub><b>Mat Gadd</b></sub>](http://drarok.com/)<br />[πŸ›](https://github.com/dawnlabs/carbon/issues?q=author%3ADrarok "Bug reports") [πŸ’»](https://github.com/dawnlabs/carbon/commits?author=Drarok "Code") | [<img src="https://avatars1.githubusercontent.com/u/11805775?v=4" width="100px;"/><br /><sub><b>Brad Davies</b></sub>](https://bradlab.co.uk)<br />[πŸ›](https://github.com/dawnlabs/carbon/issues?q=author%3Avarbrad "Bug reports") [πŸ’»](https://github.com/dawnlabs/carbon/commits?author=varbrad "Code") | [<img src="https://avatars1.githubusercontent.com/u/9087886?v=4" width="100px;"/><br /><sub><b>Rafael CΓ’mara</b></sub>](http://www.rafaelcamaram.com/)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=rafaelcamaram "Code") | [<img src="https://avatars1.githubusercontent.com/u/2212006?v=4" width="100px;"/><br /><sub><b>Gleb Bahmutov</b></sub>](https://glebbahmutov.com/)<br />[⚠️](https://github.com/dawnlabs/carbon/commits?author=bahmutov "Tests") [πŸ”§](#tool-bahmutov "Tools") | [<img src="https://avatars2.githubusercontent.com/u/10677789?v=4" width="100px;"/><br /><sub><b>IvΓ‘n MunguΓ­a</b></sub>](https://ivan-munguia.netlify.com)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=warborn "Code") | [<img src="https://avatars1.githubusercontent.com/u/2755722?v=4" width="100px;"/><br /><sub><b>Dillon Mulroy</b></sub>](https://dillonmulroy.com)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=dmmulroy "Code") | | [<img src="https://avatars1.githubusercontent.com/u/10941033?v=4" width="100px;"/><br /><sub><b>g3r4n</b></sub>](https://github.com/g3r4n)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=g3r4n "Code") | [<img src="https://avatars0.githubusercontent.com/u/55830?v=4" width="100px;"/><br /><sub><b>Mat Gadd</b></sub>](http://drarok.com/)<br />[πŸ›](https://github.com/dawnlabs/carbon/issues?q=author%3ADrarok "Bug reports") [πŸ’»](https://github.com/dawnlabs/carbon/commits?author=Drarok "Code") | [<img src="https://avatars1.githubusercontent.com/u/11805775?v=4" width="100px;"/><br /><sub><b>Brad Davies</b></sub>](https://bradlab.co.uk)<br />[πŸ›](https://github.com/dawnlabs/carbon/issues?q=author%3Avarbrad "Bug reports") [πŸ’»](https://github.com/dawnlabs/carbon/commits?author=varbrad "Code") | [<img src="https://avatars1.githubusercontent.com/u/9087886?v=4" width="100px;"/><br /><sub><b>Rafael CΓ’mara</b></sub>](http://www.rafaelcamaram.com/)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=rafaelcamaram "Code") | [<img src="https://avatars1.githubusercontent.com/u/2212006?v=4" width="100px;"/><br /><sub><b>Gleb Bahmutov</b></sub>](https://glebbahmutov.com/)<br />[⚠️](https://github.com/dawnlabs/carbon/commits?author=bahmutov "Tests") [πŸ”§](#tool-bahmutov "Tools") | [<img src="https://avatars2.githubusercontent.com/u/10677789?v=4" width="100px;"/><br /><sub><b>IvΓ‘n MunguΓ­a</b></sub>](https://ivan-munguia.netlify.com)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=warborn "Code") | [<img src="https://avatars1.githubusercontent.com/u/2755722?v=4" width="100px;"/><br /><sub><b>Dillon Mulroy</b></sub>](https://dillonmulroy.com)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=dmmulroy "Code") |
| [<img src="https://avatars2.githubusercontent.com/u/253398?v=4" width="100px;"/><br /><sub><b>Nihad Abbasov</b></sub>](https://github.com/NARKOZ)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=NARKOZ "Code") | [<img src="https://avatars1.githubusercontent.com/u/7328625?v=4" width="100px;"/><br /><sub><b>Hugo Torzuoli</b></sub>](https://torzuolih.github.io)<br />[πŸ“–](https://github.com/dawnlabs/carbon/commits?author=TorzuoliH "Documentation") | [<img src="https://avatars1.githubusercontent.com/u/1906977?v=4" width="100px;"/><br /><sub><b>Bruno C. Couto</b></sub>](https://github.com/bruno02221)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=bruno02221 "Code") | [<img src="https://avatars2.githubusercontent.com/u/13263073?v=4" width="100px;"/><br /><sub><b>Mark Molnar</b></sub>](https://github.com/molnarmark)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=molnarmark "Code") | | [<img src="https://avatars2.githubusercontent.com/u/253398?v=4" width="100px;"/><br /><sub><b>Nihad Abbasov</b></sub>](https://github.com/NARKOZ)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=NARKOZ "Code") | [<img src="https://avatars1.githubusercontent.com/u/7328625?v=4" width="100px;"/><br /><sub><b>Hugo Torzuoli</b></sub>](https://torzuolih.github.io)<br />[πŸ“–](https://github.com/dawnlabs/carbon/commits?author=TorzuoliH "Documentation") | [<img src="https://avatars1.githubusercontent.com/u/1906977?v=4" width="100px;"/><br /><sub><b>Bruno C. Couto</b></sub>](https://github.com/bruno02221)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=bruno02221 "Code") | [<img src="https://avatars2.githubusercontent.com/u/13263073?v=4" width="100px;"/><br /><sub><b>Mark Molnar</b></sub>](https://github.com/molnarmark)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=molnarmark "Code") | [<img src="https://avatars1.githubusercontent.com/u/1459450?v=4" width="100px;"/><br /><sub><b>Takahiko Inayama</b></sub>](https://www.behance.net/tetra2000)<br />[πŸ’»](https://github.com/dawnlabs/carbon/commits?author=TETRA2000 "Code") |
<!-- ALL-CONTRIBUTORS-LIST:END --> <!-- ALL-CONTRIBUTORS-LIST:END -->

@ -0,0 +1,88 @@
import React from 'react'
import { COLORS } from '../lib/constants'
import Checkmark from './svg/Checkmark'
import { RESOLUTIONS } from '../lib/constants'
export default class extends React.Component {
constructor(props) {
super()
this.state = { isVisible: false }
this.select = this.select.bind(this)
this.toggle = this.toggle.bind(this)
}
select(resolution) {
if (this.props.selected !== resolution) {
this.props.onChange(resolution)
}
}
toggle() {
this.setState({ isVisible: !this.state.isVisible })
}
renderResolutions() {
return RESOLUTIONS.map((resolution, i) => {
return (
<div className="list-item" key={i} onClick={this.select.bind(null, resolution.id)}>
<span style={{ Resolution: resolution.id }}>{resolution.name}</span>
{this.props.selected === resolution.id ? <Checkmark /> : null}
<style jsx>{`
.list-item {
display: flex;
align-items: center;
justify-content: space-between;
cursor: pointer;
user-select: none;
padding: 8px 16px;
border-bottom: 1px solid ${COLORS.SECONDARY};
background: rgba(255, 255, 255, 0.165);
}
.list-item:first-of-type {
border-top: 1px solid ${COLORS.SECONDARY};
}
.list-item:last-of-type {
border-bottom: none;
}
`}</style>
</div>
)
})
}
render() {
const selectedResolution =
RESOLUTIONS.filter(resolution => resolution.id === this.props.selected)[0] || {}
return (
<div className="resolution-select-container">
<div
onClick={this.toggle}
className={`display ${this.state.isVisible ? 'is-visible' : ''}`}
>
<span className="label">Resolution</span>
<span style={{ resolution: selectedResolution.id }}>{selectedResolution.name}</span>
</div>
<div className="list">{this.renderResolutions()}</div>
<style jsx>{`
.display {
display: flex;
align-items: center;
justify-content: space-between;
cursor: pointer;
user-select: none;
padding: 8px;
}
.list {
display: none;
margin-top: -1px;
max-height: 80px;
overflow-y: scroll;
}
.is-visible + .list {
display: block;
}
`}</style>
</div>
)
}
}

@ -3,6 +3,7 @@ import enhanceWithClickOutside from 'react-click-outside'
import SettingsIcon from './svg/Settings' import SettingsIcon from './svg/Settings'
import ThemeSelect from './ThemeSelect' import ThemeSelect from './ThemeSelect'
import FontSelect from './FontSelect' import FontSelect from './FontSelect'
import ResolutionSelect from './ResolutionSelect'
import Slider from './Slider' import Slider from './Slider'
import Toggle from './Toggle' import Toggle from './Toggle'
import WindowPointer from './WindowPointer' import WindowPointer from './WindowPointer'
@ -99,6 +100,10 @@ class Settings extends React.Component {
enabled={this.props.enabled.squaredImage} enabled={this.props.enabled.squaredImage}
onChange={this.props.onChange.bind(null, 'squaredImage')} onChange={this.props.onChange.bind(null, 'squaredImage')}
/> />
<ResolutionSelect
selected={this.props.enabled.resolution || '2x'}
onChange={this.props.onChange.bind(null, 'resolution')}
/>
<Toggle <Toggle
label="Reset settings" label="Reset settings"
enabled={false} enabled={false}

@ -386,6 +386,14 @@ export const LANGUAGES = [
} }
] ]
export const RESOLUTIONS = [
{ id: '4x', name: '4x', value: '4' },
{ id: '2x', name: '2x', value: '2' },
{ id: '1x', name: '1x', value: '1' }
]
export const RESOLUTIONS_HASH = toHash(RESOLUTIONS)
export const LANGUAGE_MIME_HASH = toHash(LANGUAGES, 'mime') export const LANGUAGE_MIME_HASH = toHash(LANGUAGES, 'mime')
export const LANGUAGE_MODE_HASH = toHash(LANGUAGES, 'mode') export const LANGUAGE_MODE_HASH = toHash(LANGUAGES, 'mode')
export const LANGUAGE_NAME_HASH = toHash(LANGUAGES, 'short') export const LANGUAGE_NAME_HASH = toHash(LANGUAGES, 'short')
@ -393,6 +401,7 @@ export const LANGUAGE_NAME_HASH = toHash(LANGUAGES, 'short')
export const DEFAULT_LANGUAGE = 'auto' export const DEFAULT_LANGUAGE = 'auto'
export const DEFAULT_THEME = THEMES_HASH.seti export const DEFAULT_THEME = THEMES_HASH.seti
export const DEFAULT_BG_COLOR = 'rgba(171, 184, 195, 1)' export const DEFAULT_BG_COLOR = 'rgba(171, 184, 195, 1)'
export const DEFAULT_RESOLUTION = RESOLUTIONS_HASH['2x']
export const COLORS = { export const COLORS = {
BLACK: '#121212', BLACK: '#121212',
@ -448,5 +457,6 @@ export const DEFAULT_SETTINGS = {
fontSize: '14px', fontSize: '14px',
windowControls: true, windowControls: true,
widthAdjustment: true, widthAdjustment: true,
lineNumbers: false lineNumbers: false,
resolution: '2x'
} }

@ -33,7 +33,8 @@ const mappings = [
{ field: 'fm:fontFamily' }, { field: 'fm:fontFamily' },
{ field: 'fs:fontSize' }, { field: 'fs:fontSize' },
{ field: 'si:squaredImage', type: 'bool' }, { field: 'si:squaredImage', type: 'bool' },
{ field: 'code:code' } { field: 'code:code' },
{ field: 'rs:resolution' }
] ]
const reverseMappings = mappings.map(mapping => const reverseMappings = mappings.map(mapping =>

@ -24,7 +24,10 @@ import {
LANGUAGE_NAME_HASH, LANGUAGE_NAME_HASH,
DEFAULT_LANGUAGE, DEFAULT_LANGUAGE,
DEFAULT_THEME, DEFAULT_THEME,
DEFAULT_RESOLUTION,
COLORS, COLORS,
RESOLUTIONS,
RESOLUTIONS_HASH,
DEFAULT_CODE, DEFAULT_CODE,
DEFAULT_BG_COLOR, DEFAULT_BG_COLOR,
DEFAULT_SETTINGS DEFAULT_SETTINGS
@ -99,15 +102,18 @@ class Editor extends React.Component {
getCarbonImage() { getCarbonImage() {
const node = document.getElementById('export-container') const node = document.getElementById('export-container')
const resolutionRatio = (RESOLUTIONS_HASH[this.state.resolution] || DEFAULT_RESOLUTION).value
const config = { const config = {
style: { style: {
transform: 'scale(2)', transform: `scale(${resolutionRatio})`,
'transform-origin': 'center', 'transform-origin': 'center',
'background': (this.state.squaredImage) ? this.state.backgroundColor : 'none' background: this.state.squaredImage ? this.state.backgroundColor : 'none'
}, },
filter: n => (n.className ? String(n.className).indexOf('eliminateOnRender') < 0 : true), filter: n => (n.className ? String(n.className).indexOf('eliminateOnRender') < 0 : true),
width: node.offsetWidth * 2, width: node.offsetWidth * resolutionRatio,
height: (this.state.squaredImage) ? node.offsetWidth * 2 : node.offsetHeight * 2 height: this.state.squaredImage
? node.offsetWidth * resolutionRatio
: node.offsetHeight * resolutionRatio
} }
return domtoimage.toPng(node, config) return domtoimage.toPng(node, config)

Loading…
Cancel
Save