-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract insertion plugin into stylis-plugin-emotion (#391)
* Extract stylis-plugin-emotion from emotion so that other libraries can use it. * Update rollup and jest configs * Fix linting * Lint fix * Add tests from stylis to test the plugin. * Code cleanup * Add stylis-plugin-emotion snapshots * Update travis cache. * Update snapshots after prettier update * Add another test case
- Loading branch information
Kye Hohenberger
authored
Oct 8, 2017
1 parent
d2ae53a
commit dafab02
Showing
9 changed files
with
852 additions
and
92 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
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
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,43 @@ | ||
{ | ||
"name": "stylis-plugin-emotion", | ||
"version": "8.0.4", | ||
"description": "stylis plugin to insert parsed rules via insertRule", | ||
"main": "dist/index.cjs.js", | ||
"module": "dist/index.es.js", | ||
"files": [ | ||
"src", | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "npm-run-all clean rollup", | ||
"clean": "rimraf dist", | ||
"watch": "rollup -c ../../rollup.config.js --watch", | ||
"rollup": "rollup -c ../../rollup.config.js" | ||
}, | ||
"author": "Mitchell Hamilton", | ||
"homepage": "https://github.com/emotion-js/emotion#readme", | ||
"license": "MIT", | ||
"repository": "https://github.com/emotion-js/emotion/tree/master/packages/stylis-plugin-emotion", | ||
"keywords": [ | ||
"styles", | ||
"emotion", | ||
"react", | ||
"css", | ||
"css-in-js", | ||
"insertRule", | ||
"stylis", | ||
"plugin", | ||
"insert rule", | ||
"stylesheet" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/tkh44/emotion/issues" | ||
}, | ||
"devDependencies": { | ||
"emotion": "^8.0.4", | ||
"emotion-utils": "^8.0.2-7", | ||
"npm-run-all": "^4.0.2", | ||
"rimraf": "^2.6.1", | ||
"rollup": "^0.47.2" | ||
} | ||
} |
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,79 @@ | ||
let queue = [] | ||
let parentQueue = [] | ||
|
||
export default insertRule => | ||
function insertionPlugin( | ||
context, | ||
content, | ||
selectors, | ||
parents, | ||
line, | ||
column, | ||
length, | ||
id | ||
) { | ||
switch (context) { | ||
case -2: { | ||
queue.forEach(insertRule) | ||
queue = [] | ||
parentQueue = [] | ||
break | ||
} | ||
|
||
case 2: { | ||
if (id === 0) { | ||
const selector = selectors.join(',') | ||
let parent = parents.join(',') | ||
const rule = `${selector}{${content}}` | ||
let index = parentQueue.indexOf(selector) | ||
if (index === -1) { | ||
index = parentQueue.length | ||
} else { | ||
let length = queue.length | ||
while (length--) { | ||
if (parentQueue[length] === selector) { | ||
parentQueue[length] = undefined | ||
} | ||
} | ||
} | ||
queue.splice(index, 0, rule) | ||
parentQueue.splice(index, 0, parent) | ||
} | ||
break | ||
} | ||
// after an at rule block | ||
case 3: { | ||
let parent = parents.join(',') | ||
parentQueue.push(parent) | ||
let chars = selectors.join('') | ||
const second = chars.charCodeAt(1) | ||
let child = content | ||
switch (second) { | ||
// s upports | ||
case 115: | ||
// d ocument | ||
// eslint-disable-next-line no-fallthrough | ||
case 100: | ||
// m edia | ||
// eslint-disable-next-line no-fallthrough | ||
case 109: { | ||
queue.push(chars + '{' + child + '}') | ||
break | ||
} | ||
// k eyframes | ||
case 107: { | ||
chars = chars.substring(1) | ||
child = chars + '{' + child + '}' | ||
queue.push('@-webkit-' + child) | ||
queue.push('@' + child) | ||
parentQueue.push(parent) | ||
break | ||
} | ||
default: { | ||
queue.push(chars + child) | ||
break | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.