-
-
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.
- Loading branch information
Showing
38 changed files
with
2,463 additions
and
3,428 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,89 +1,17 @@ | ||
// @flow | ||
// https://github.com/thysultan/stylis.js/tree/master/plugins/rule-sheet | ||
// inlined to avoid umd wrapper and peerDep warnings/installing stylis | ||
// since we use stylis after closure compiler | ||
import { DECLARATION, charat } from '@emotion/stylis' | ||
|
||
import type { StylisPlugin } from './types' | ||
|
||
const delimiter = '/*|*/' | ||
const needle = delimiter + '}' | ||
|
||
function toSheet(block) { | ||
if (block) { | ||
Sheet.current.insert(block + '}') | ||
} | ||
} | ||
|
||
export let Sheet: { current: { +insert: string => void } } = { | ||
current: (null: any) | ||
} | ||
|
||
export let ruleSheet: StylisPlugin = ( | ||
context, | ||
content, | ||
selectors, | ||
parents, | ||
line, | ||
column, | ||
length, | ||
ns, | ||
depth, | ||
at | ||
) => { | ||
switch (context) { | ||
// property | ||
case 1: { | ||
switch (content.charCodeAt(0)) { | ||
case 64: { | ||
// @import | ||
Sheet.current.insert(content + ';') | ||
return '' | ||
} | ||
// charcode for l | ||
case 108: { | ||
// charcode for b | ||
// this ignores label | ||
if (content.charCodeAt(2) === 98) { | ||
return '' | ||
} | ||
} | ||
} | ||
break | ||
export let removeLabel = element => { | ||
if (element.type === DECLARATION) { | ||
var value = element.value | ||
if ( | ||
// charcode for l | ||
charat(value, 0) === 108 && | ||
// charcode for b | ||
charat(value, 2) === 98 | ||
) { | ||
// this ignores label | ||
element.return = '' | ||
element.value = '' | ||
} | ||
// selector | ||
case 2: { | ||
if (ns === 0) return content + delimiter | ||
break | ||
} | ||
// at-rule | ||
case 3: { | ||
switch (ns) { | ||
// @font-face, @page | ||
case 102: | ||
case 112: { | ||
Sheet.current.insert(selectors[0] + content) | ||
return '' | ||
} | ||
default: { | ||
return content + (at === 0 ? delimiter : '') | ||
} | ||
} | ||
} | ||
case -2: { | ||
content.split(needle).forEach(toSheet) | ||
} | ||
} | ||
} | ||
|
||
export let removeLabel: StylisPlugin = (context, content) => { | ||
if ( | ||
context === 1 && | ||
// charcode for l | ||
content.charCodeAt(0) === 108 && | ||
// charcode for b | ||
content.charCodeAt(2) === 98 | ||
// this ignores label | ||
) { | ||
return '' | ||
} | ||
} |
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
Oops, something went wrong.