Security upgrades
This commit is contained in:
3
node_modules/jss-plugin-vendor-prefixer/src/index.d.ts
generated
vendored
Normal file
3
node_modules/jss-plugin-vendor-prefixer/src/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import {Plugin} from 'jss'
|
||||
|
||||
export default function jssPluginVendorPrefixer(): Plugin
|
||||
53
node_modules/jss-plugin-vendor-prefixer/src/index.js
generated
vendored
Normal file
53
node_modules/jss-plugin-vendor-prefixer/src/index.js
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
// @flow
|
||||
import * as vendor from 'css-vendor'
|
||||
import {toCssValue, type Plugin, type KeyframesRule} from 'jss'
|
||||
|
||||
/**
|
||||
* Add vendor prefix to a property name when needed.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
export default function jssVendorPrefixer(): Plugin {
|
||||
function onProcessRule(rule) {
|
||||
if (rule.type === 'keyframes') {
|
||||
const atRule: KeyframesRule = (rule: any)
|
||||
atRule.at = vendor.supportedKeyframes(atRule.at)
|
||||
}
|
||||
}
|
||||
|
||||
function prefixStyle(style) {
|
||||
for (const prop in style) {
|
||||
const value = style[prop]
|
||||
if (prop === 'fallbacks' && Array.isArray(value)) {
|
||||
style[prop] = value.map(prefixStyle)
|
||||
continue
|
||||
}
|
||||
let changeProp = false
|
||||
const supportedProp = vendor.supportedProperty(prop)
|
||||
if (supportedProp && supportedProp !== prop) changeProp = true
|
||||
|
||||
let changeValue = false
|
||||
const supportedValue = vendor.supportedValue(supportedProp, toCssValue(value))
|
||||
if (supportedValue && supportedValue !== value) changeValue = true
|
||||
|
||||
if (changeProp || changeValue) {
|
||||
if (changeProp) delete style[prop]
|
||||
style[supportedProp || prop] = supportedValue || value
|
||||
}
|
||||
}
|
||||
|
||||
return style
|
||||
}
|
||||
|
||||
function onProcessStyle(style, rule) {
|
||||
if (rule.type !== 'style') return style
|
||||
|
||||
return prefixStyle(style)
|
||||
}
|
||||
|
||||
function onChangeValue(value, prop) {
|
||||
return vendor.supportedValue(prop, toCssValue(value)) || value
|
||||
}
|
||||
|
||||
return {onProcessRule, onProcessStyle, onChangeValue}
|
||||
}
|
||||
198
node_modules/jss-plugin-vendor-prefixer/src/index.test.js
generated
vendored
Normal file
198
node_modules/jss-plugin-vendor-prefixer/src/index.test.js
generated
vendored
Normal file
@@ -0,0 +1,198 @@
|
||||
import expect from 'expect.js'
|
||||
import {create} from 'jss'
|
||||
import * as cssVendor from 'css-vendor'
|
||||
import browser from 'detect-browser'
|
||||
import {stripIndent} from 'common-tags'
|
||||
import functionPlugin from 'jss-plugin-rule-value-function'
|
||||
|
||||
import vendorPrefixer from './index'
|
||||
|
||||
const settings = {
|
||||
createGenerateId: () => rule => `${rule.key}-id`
|
||||
}
|
||||
|
||||
const isIE9 = browser.name === 'ie' && browser.version === '9.0.0'
|
||||
const isIEorEdge = browser.name === 'edge' || browser.name === 'ie'
|
||||
|
||||
describe('jss-plugin-vendor-prefixer', () => {
|
||||
let jss
|
||||
|
||||
beforeEach(() => {
|
||||
jss = create(settings).use(vendorPrefixer())
|
||||
})
|
||||
|
||||
describe('prefixed property', () => {
|
||||
if (isIE9) {
|
||||
return
|
||||
}
|
||||
|
||||
let sheet
|
||||
|
||||
beforeEach(() => {
|
||||
sheet = jss.createStyleSheet({
|
||||
a: {animation: 'yyy'}
|
||||
})
|
||||
})
|
||||
|
||||
it('should generate correct CSS', () => {
|
||||
const prefixedProp = cssVendor.supportedProperty('animation')
|
||||
expect(sheet.toString()).to.be(`.a-id {\n ${prefixedProp}: yyy;\n}`)
|
||||
})
|
||||
})
|
||||
|
||||
describe('@keyframes', () => {
|
||||
let sheet
|
||||
|
||||
beforeEach(() => {
|
||||
sheet = jss.createStyleSheet({
|
||||
'@keyframes a': {}
|
||||
})
|
||||
})
|
||||
|
||||
it('should generate correct CSS', () => {
|
||||
if (isIEorEdge) {
|
||||
expect(sheet.toString()).to.be('@keyframes keyframes-a-id {}')
|
||||
return
|
||||
}
|
||||
const prefixedKeyframes = `@${cssVendor.prefix.css}keyframes`
|
||||
expect(sheet.toString()).to.be(`${prefixedKeyframes} keyframes-a-id {}`)
|
||||
})
|
||||
})
|
||||
|
||||
describe('unknown property', () => {
|
||||
let sheet
|
||||
|
||||
beforeEach(() => {
|
||||
sheet = jss.createStyleSheet({
|
||||
a: {xxx: 'block'}
|
||||
})
|
||||
})
|
||||
|
||||
it('should generate correct CSS', () => {
|
||||
expect(sheet.toString()).to.be('.a-id {\n xxx: block;\n}')
|
||||
})
|
||||
})
|
||||
|
||||
describe('unknown value', () => {
|
||||
let sheet
|
||||
|
||||
beforeEach(() => {
|
||||
sheet = jss.createStyleSheet({
|
||||
a: {display: 'yyy'}
|
||||
})
|
||||
})
|
||||
|
||||
it('should generate correct CSS', () => {
|
||||
expect(sheet.toString()).to.be('.a-id {\n display: yyy;\n}')
|
||||
})
|
||||
})
|
||||
|
||||
describe('unknown property and value', () => {
|
||||
let sheet
|
||||
|
||||
beforeEach(() => {
|
||||
sheet = jss.createStyleSheet({
|
||||
a: {xxx: 'yyy'}
|
||||
})
|
||||
})
|
||||
|
||||
it('should generate correct CSS', () => {
|
||||
expect(sheet.toString()).to.be('.a-id {\n xxx: yyy;\n}')
|
||||
})
|
||||
})
|
||||
|
||||
describe('array value', () => {
|
||||
it('should generate correct border', () => {
|
||||
const sheet = jss.createStyleSheet({
|
||||
a: {border: ['red', 'green']}
|
||||
})
|
||||
expect(sheet.toString()).to.be('.a-id {\n border: red, green;\n}')
|
||||
})
|
||||
|
||||
it('should generate correct margin', () => {
|
||||
const sheet = jss.createStyleSheet({
|
||||
a: {margin: [['10px', '20px']]}
|
||||
})
|
||||
expect(sheet.toString()).to.be('.a-id {\n margin: 10px 20px;\n}')
|
||||
})
|
||||
|
||||
it('should generate correct important', () => {
|
||||
const sheet = jss.createStyleSheet({
|
||||
a: {margin: [['10px', '20px'], '!important']}
|
||||
})
|
||||
expect(sheet.toString()).to.be('.a-id {\n margin: 10px 20px !important;\n}')
|
||||
})
|
||||
})
|
||||
|
||||
describe('prefixed value', () => {
|
||||
if (isIE9) {
|
||||
return
|
||||
}
|
||||
|
||||
let sheet
|
||||
|
||||
beforeEach(() => {
|
||||
sheet = jss.createStyleSheet({
|
||||
a: {display: 'flex'}
|
||||
})
|
||||
})
|
||||
|
||||
it('should generate correct CSS', () => {
|
||||
const supportedValue = cssVendor.supportedValue('display', 'flex')
|
||||
expect(sheet.toString()).to.be(`.a-id {\n display: ${supportedValue};\n}`)
|
||||
})
|
||||
})
|
||||
|
||||
describe('prefix function values', () => {
|
||||
if (isIE9) {
|
||||
return
|
||||
}
|
||||
|
||||
let sheet
|
||||
|
||||
beforeEach(() => {
|
||||
const localJss = create(settings).use(functionPlugin(), vendorPrefixer())
|
||||
sheet = localJss.createStyleSheet({
|
||||
a: {display: () => 'flex'}
|
||||
})
|
||||
sheet.update()
|
||||
})
|
||||
|
||||
it('should generate correct CSS', () => {
|
||||
const supportedValue = cssVendor.supportedValue('display', 'flex')
|
||||
expect(sheet.toString()).to.be(`.a-id {\n display: ${supportedValue};\n}`)
|
||||
})
|
||||
})
|
||||
|
||||
describe('prefix fallbacks', () => {
|
||||
it('should prefix array of objects', () => {
|
||||
const sheet = jss.createStyleSheet({
|
||||
a: {
|
||||
display: 'run-in',
|
||||
fallbacks: [{display: 'inline'}]
|
||||
}
|
||||
})
|
||||
expect(sheet.toString()).to.be(stripIndent`
|
||||
.a-id {
|
||||
display: inline;
|
||||
display: run-in;
|
||||
}
|
||||
`)
|
||||
})
|
||||
|
||||
it('should prefix an object', () => {
|
||||
const sheet = jss.createStyleSheet({
|
||||
a: {
|
||||
display: 'run-in',
|
||||
fallbacks: {display: 'inline'}
|
||||
}
|
||||
})
|
||||
expect(sheet.toString()).to.be(stripIndent`
|
||||
.a-id {
|
||||
display: inline;
|
||||
display: run-in;
|
||||
}
|
||||
`)
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user