-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
49 changed files
with
1,016 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
node_modules/ | ||
dist/ | ||
/coverage/ | ||
.cache/ | ||
public/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules/ | ||
dist/ | ||
/coverage/ | ||
/coverage/ | ||
.size-snapshot.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ node_modules/ | |
dist/ | ||
package.json | ||
CHANGELOG.md | ||
.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/* | ||
!/dist/**/*.js | ||
*.test.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright 2019 Smooth Code | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# @emotion/babel-preset-emotion-css-prop | ||
|
||
Same interface as [babel-preset-css-prop](https://github.com/emotion-js/emotion/tree/master/packages/babel-preset-css-prop). | ||
|
||
See [xstyled documentation](https://www.smooth-code.com/open-source/xstyled/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "@xstyled/babel-preset-emotion-css-prop", | ||
"description": "A babel preset to automatically enable emotion's css prop with xstyled", | ||
"version": "1.1.1", | ||
"sideEffects": false, | ||
"main": "dist/xstyled-babel-preset-emotion-css-prop.cjs.js", | ||
"module": "dist/xstyled-babel-preset-emotion-css-prop.es.js", | ||
"author": "Greg Bergé <berge.greg@gmail.com>", | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "rollup -c", | ||
"prebuild": "shx rm -rf dist", | ||
"prepublishOnly": "yarn build" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@babel/plugin-transform-react-jsx": "^7.3.0", | ||
"@babel/runtime": "^7.4.4", | ||
"@emotion/babel-plugin-jsx-pragmatic": "^0.1.2", | ||
"babel-plugin-emotion": "^10.0.9" | ||
}, | ||
"peerDependencies": { | ||
"@babel/core": "^7.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { getRollupConfig } from '../../config/rollup' | ||
import pkg from './package.json' | ||
|
||
export default getRollupConfig({ | ||
pwd: __dirname, | ||
buildName: 'xstyled-babel-preset-emotion-css-prop', | ||
pkg, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// see https://github.com/emotion-js/emotion/blob/master/packages/babel-preset-css-prop/src/index.js | ||
import jsx from '@babel/plugin-transform-react-jsx' | ||
import pragmatic from '@emotion/babel-plugin-jsx-pragmatic' | ||
import emotion from 'babel-plugin-emotion' | ||
|
||
const pragmaName = '___xstyledEmotionJSX' | ||
|
||
// pull out the emotion options and pass everything else to the jsx transformer | ||
// this means if @babel/plugin-transform-react-jsx adds more options, it'll just work | ||
// and if babel-plugin-emotion adds more options we can add them since this lives in | ||
// the same repo as babel-plugin-emotion | ||
|
||
export default ( | ||
api, | ||
{ | ||
pragma, | ||
sourceMap, | ||
autoLabel, | ||
labelFormat, | ||
instances = [], | ||
...options | ||
} = {}, | ||
) => { | ||
return { | ||
plugins: [ | ||
[ | ||
pragmatic, | ||
{ | ||
export: 'jsx', | ||
module: '@xstyled/emotion', | ||
import: pragmaName, | ||
}, | ||
], | ||
[jsx, { pragma: pragmaName, pragmaFrag: 'React.Fragment', ...options }], | ||
[ | ||
emotion, | ||
{ | ||
sourceMap, | ||
autoLabel, | ||
labelFormat, | ||
instances: ['@xstyled/emotion', ...instances], | ||
cssPropOptimization: true, | ||
}, | ||
], | ||
], | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { transform } from '@babel/core' | ||
import preset from './index' | ||
|
||
const testPreset = code => { | ||
const result = transform(code, { | ||
presets: [preset], | ||
configFile: false, | ||
}) | ||
|
||
return result.code | ||
} | ||
|
||
const code = ` | ||
import * as React from 'react' | ||
export let Button = props => { | ||
return ( | ||
<> | ||
<button | ||
css={{ | ||
color: 'hotpink', | ||
}} | ||
{...props} | ||
/> | ||
</> | ||
) | ||
} | ||
` | ||
|
||
describe('preset', () => { | ||
it('transforms code', () => { | ||
expect(testPreset(code)).toMatchInlineSnapshot(` | ||
"import { jsx as ___xstyledEmotionJSX } from \\"@xstyled/emotion\\"; | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
import * as React from 'react'; | ||
var _ref = process.env.NODE_ENV === \\"production\\" ? { | ||
name: \\"1v4u9bq-Button\\", | ||
styles: \\"color:hotpink;label:Button;\\" | ||
} : { | ||
name: \\"1v4u9bq-Button\\", | ||
styles: \\"color:hotpink;label:Button;\\", | ||
map: \\"/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInVua25vd24iXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBT1UiLCJmaWxlIjoidW5rbm93biIsInNvdXJjZXNDb250ZW50IjpbIlxuICBpbXBvcnQgKiBhcyBSZWFjdCBmcm9tICdyZWFjdCdcblxuICBleHBvcnQgbGV0IEJ1dHRvbiA9IHByb3BzID0+IHtcbiAgICByZXR1cm4gKFxuICAgICAgPD5cbiAgICAgICAgPGJ1dHRvblxuICAgICAgICAgIGNzcz17e1xuICAgICAgICAgICAgY29sb3I6ICdob3RwaW5rJyxcbiAgICAgICAgICB9fVxuICAgICAgICAgIHsuLi5wcm9wc31cbiAgICAgICAgLz5cbiAgICAgIDwvPlxuICAgIClcbiAgfVxuIl19 */\\" | ||
}; | ||
export let Button = props => { | ||
return ___xstyledEmotionJSX(React.Fragment, null, ___xstyledEmotionJSX(\\"button\\", _extends({ | ||
css: _ref | ||
}, props))); | ||
};" | ||
`) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/* | ||
!/dist/**/*.js | ||
*.test.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Copyright 2019 Smooth Code | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# @xstyled/core | ||
|
||
Core utilities of xstyled. This package must not be used directly. | ||
|
||
See [xstyled documentation](https://www.smooth-code.com/open-source/xstyled/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "@xstyled/core", | ||
"description": "xstyled core utilities", | ||
"version": "1.1.1", | ||
"sideEffects": false, | ||
"main": "dist/xstyled-core.cjs.js", | ||
"module": "dist/xstyled-core.es.js", | ||
"author": "Greg Bergé <berge.greg@gmail.com>", | ||
"license": "MIT", | ||
"scripts": { | ||
"build": "rollup -c", | ||
"prebuild": "shx rm -rf dist", | ||
"prepublishOnly": "yarn build" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@babel/runtime": "^7.4.4", | ||
"@xstyled/system": "^1.1.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { getRollupConfig } from '../../config/rollup' | ||
import pkg from './package.json' | ||
|
||
export default getRollupConfig({ | ||
pwd: __dirname, | ||
buildName: 'xstyled-core', | ||
pkg, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { system } from '@xstyled/system' | ||
|
||
export function createBox() { | ||
return [`&&{`, system, `}`] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from './createBox' | ||
export * from './propGetters' | ||
export * from './transform' | ||
export * from './util' |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* eslint-disable no-continue, no-loop-func, no-cond-assign */ | ||
import { propGetters } from './propGetters' | ||
|
||
const PROP_REGEXP = /(\s*)([^&{}:;\n]+):\s*([^&{}:;\n]+)(\s*);/g | ||
const IMPORTANT_REGEXP = /\s*!important\s*/ | ||
|
||
export function transform(rawValue) { | ||
if (typeof rawValue !== 'string') return rawValue | ||
let matches | ||
let lastIndex = 0 | ||
const values = [] | ||
while ((matches = PROP_REGEXP.exec(rawValue))) { | ||
const [, start, prop, propValue, end] = matches | ||
const getter = propGetters[prop] | ||
if (getter) { | ||
const hasImportant = IMPORTANT_REGEXP.test(propValue) | ||
const cleanValue = propValue.replace(IMPORTANT_REGEXP, '') | ||
values.push(rawValue.slice(lastIndex, matches.index)) | ||
values.push( | ||
p => | ||
`${start}${prop}: ${getter(cleanValue)(p)}${ | ||
hasImportant ? ' !important' : '' | ||
};${end}`, | ||
) | ||
lastIndex = matches.index + matches[0].length | ||
} | ||
} | ||
values.push(rawValue.slice(lastIndex, rawValue.length)) | ||
return values | ||
} |
Oops, something went wrong.