Security upgrades
This commit is contained in:
146
node_modules/jss-plugin-default-unit/src/defaultUnits.js
generated
vendored
Normal file
146
node_modules/jss-plugin-default-unit/src/defaultUnits.js
generated
vendored
Normal file
@@ -0,0 +1,146 @@
|
||||
// @flow
|
||||
|
||||
import {hasCSSTOMSupport} from 'jss'
|
||||
|
||||
const px = hasCSSTOMSupport && CSS ? CSS.px : 'px'
|
||||
const ms = hasCSSTOMSupport && CSS ? CSS.ms : 'ms'
|
||||
const percent = hasCSSTOMSupport && CSS ? CSS.percent : '%'
|
||||
|
||||
/**
|
||||
* Generated jss-plugin-default-unit CSS property units
|
||||
*
|
||||
* @type object
|
||||
*/
|
||||
export default {
|
||||
// Animation properties
|
||||
'animation-delay': ms,
|
||||
'animation-duration': ms,
|
||||
|
||||
// Background properties
|
||||
'background-position': px,
|
||||
'background-position-x': px,
|
||||
'background-position-y': px,
|
||||
'background-size': px,
|
||||
|
||||
// Border Properties
|
||||
border: px,
|
||||
'border-bottom': px,
|
||||
'border-bottom-left-radius': px,
|
||||
'border-bottom-right-radius': px,
|
||||
'border-bottom-width': px,
|
||||
'border-left': px,
|
||||
'border-left-width': px,
|
||||
'border-radius': px,
|
||||
'border-right': px,
|
||||
'border-right-width': px,
|
||||
'border-top': px,
|
||||
'border-top-left-radius': px,
|
||||
'border-top-right-radius': px,
|
||||
'border-top-width': px,
|
||||
'border-width': px,
|
||||
|
||||
// Margin properties
|
||||
margin: px,
|
||||
'margin-bottom': px,
|
||||
'margin-left': px,
|
||||
'margin-right': px,
|
||||
'margin-top': px,
|
||||
|
||||
// Padding properties
|
||||
padding: px,
|
||||
'padding-bottom': px,
|
||||
'padding-left': px,
|
||||
'padding-right': px,
|
||||
'padding-top': px,
|
||||
|
||||
// Mask properties
|
||||
'mask-position-x': px,
|
||||
'mask-position-y': px,
|
||||
'mask-size': px,
|
||||
|
||||
// Width and height properties
|
||||
height: px,
|
||||
width: px,
|
||||
'min-height': px,
|
||||
'max-height': px,
|
||||
'min-width': px,
|
||||
'max-width': px,
|
||||
|
||||
// Position properties
|
||||
bottom: px,
|
||||
left: px,
|
||||
top: px,
|
||||
right: px,
|
||||
|
||||
// Shadow properties
|
||||
'box-shadow': px,
|
||||
'text-shadow': px,
|
||||
|
||||
// Column properties
|
||||
'column-gap': px,
|
||||
'column-rule': px,
|
||||
'column-rule-width': px,
|
||||
'column-width': px,
|
||||
|
||||
// Font and text properties
|
||||
'font-size': px,
|
||||
'font-size-delta': px,
|
||||
'letter-spacing': px,
|
||||
'text-indent': px,
|
||||
'text-stroke': px,
|
||||
'text-stroke-width': px,
|
||||
'word-spacing': px,
|
||||
|
||||
// Motion properties
|
||||
motion: px,
|
||||
'motion-offset': px,
|
||||
|
||||
// Outline properties
|
||||
outline: px,
|
||||
'outline-offset': px,
|
||||
'outline-width': px,
|
||||
|
||||
// Perspective properties
|
||||
perspective: px,
|
||||
'perspective-origin-x': percent,
|
||||
'perspective-origin-y': percent,
|
||||
|
||||
// Transform properties
|
||||
'transform-origin': percent,
|
||||
'transform-origin-x': percent,
|
||||
'transform-origin-y': percent,
|
||||
'transform-origin-z': percent,
|
||||
|
||||
// Transition properties
|
||||
'transition-delay': ms,
|
||||
'transition-duration': ms,
|
||||
|
||||
// Alignment properties
|
||||
'vertical-align': px,
|
||||
'flex-basis': px,
|
||||
|
||||
// Some random properties
|
||||
'shape-margin': px,
|
||||
size: px,
|
||||
|
||||
// Grid properties
|
||||
grid: px,
|
||||
'grid-gap': px,
|
||||
'grid-row-gap': px,
|
||||
'grid-column-gap': px,
|
||||
'grid-template-rows': px,
|
||||
'grid-template-columns': px,
|
||||
'grid-auto-rows': px,
|
||||
'grid-auto-columns': px,
|
||||
|
||||
// Not existing properties.
|
||||
// Used to avoid issues with jss-plugin-expand integration.
|
||||
'box-shadow-x': px,
|
||||
'box-shadow-y': px,
|
||||
'box-shadow-blur': px,
|
||||
'box-shadow-spread': px,
|
||||
'font-line-height': px,
|
||||
'text-shadow-x': px,
|
||||
'text-shadow-y': px,
|
||||
'text-shadow-blur': px
|
||||
}
|
||||
5
node_modules/jss-plugin-default-unit/src/index.d.ts
generated
vendored
Normal file
5
node_modules/jss-plugin-default-unit/src/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import {Plugin} from 'jss'
|
||||
|
||||
export type Options = {[key: string]: string}
|
||||
|
||||
export default function jssPluginSyntaxDefaultUnit(options?: Options): Plugin
|
||||
77
node_modules/jss-plugin-default-unit/src/index.js
generated
vendored
Normal file
77
node_modules/jss-plugin-default-unit/src/index.js
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
// @flow
|
||||
import type {Plugin} from 'jss'
|
||||
import defaultUnits from './defaultUnits'
|
||||
|
||||
export type Options = {[key: string]: string | ((val: number) => string)}
|
||||
|
||||
/**
|
||||
* Clones the object and adds a camel cased property version.
|
||||
*/
|
||||
function addCamelCasedVersion(obj) {
|
||||
const regExp = /(-[a-z])/g
|
||||
const replace = str => str[1].toUpperCase()
|
||||
const newObj = {}
|
||||
for (const key in obj) {
|
||||
newObj[key] = obj[key]
|
||||
newObj[key.replace(regExp, replace)] = obj[key]
|
||||
}
|
||||
return newObj
|
||||
}
|
||||
|
||||
const units = addCamelCasedVersion(defaultUnits)
|
||||
|
||||
/**
|
||||
* Recursive deep style passing function
|
||||
*/
|
||||
function iterate(prop: string, value: any, options: Options) {
|
||||
if (!value) return value
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
value[i] = iterate(prop, value[i], options)
|
||||
}
|
||||
} else if (typeof value === 'object') {
|
||||
if (prop === 'fallbacks') {
|
||||
for (const innerProp in value) {
|
||||
value[innerProp] = iterate(innerProp, value[innerProp], options)
|
||||
}
|
||||
} else {
|
||||
for (const innerProp in value) {
|
||||
value[innerProp] = iterate(`${prop}-${innerProp}`, value[innerProp], options)
|
||||
}
|
||||
}
|
||||
} else if (typeof value === 'number') {
|
||||
const unit = options[prop] || units[prop]
|
||||
|
||||
if (unit) {
|
||||
return typeof unit === 'function' ? unit(value).toString() : `${value}${unit}`
|
||||
}
|
||||
|
||||
return value.toString()
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
/**
|
||||
* Add unit to numeric values.
|
||||
*/
|
||||
export default function defaultUnit(options: Options = {}): Plugin {
|
||||
const camelCasedOptions = addCamelCasedVersion(options)
|
||||
|
||||
function onProcessStyle(style, rule) {
|
||||
if (rule.type !== 'style') return style
|
||||
|
||||
for (const prop in style) {
|
||||
style[prop] = iterate(prop, style[prop], camelCasedOptions)
|
||||
}
|
||||
|
||||
return style
|
||||
}
|
||||
|
||||
function onChangeValue(value, prop) {
|
||||
return iterate(prop, value, camelCasedOptions)
|
||||
}
|
||||
|
||||
return {onProcessStyle, onChangeValue}
|
||||
}
|
||||
403
node_modules/jss-plugin-default-unit/src/index.test.js
generated
vendored
Normal file
403
node_modules/jss-plugin-default-unit/src/index.test.js
generated
vendored
Normal file
@@ -0,0 +1,403 @@
|
||||
import expect from 'expect.js'
|
||||
import expand from 'jss-plugin-expand'
|
||||
import {create} from 'jss'
|
||||
import {stripIndent} from 'common-tags'
|
||||
import Observable from 'zen-observable'
|
||||
import observablePlugin from 'jss-plugin-rule-value-observable'
|
||||
import functionPlugin from 'jss-plugin-rule-value-function'
|
||||
|
||||
import defaultUnit from './index'
|
||||
|
||||
const settings = {
|
||||
createGenerateId: () => rule => `${rule.key}-id`
|
||||
}
|
||||
|
||||
describe('jss-plugin-default-unit', () => {
|
||||
let jss
|
||||
|
||||
beforeEach(() => {
|
||||
jss = create(settings).use(defaultUnit({'min-width': 'pc', 'max-width': val => `${val / 2}px`}))
|
||||
})
|
||||
|
||||
describe('unitless values', () => {
|
||||
let sheet
|
||||
|
||||
beforeEach(() => {
|
||||
sheet = jss.createStyleSheet({
|
||||
a: {
|
||||
zoom: 1
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('should add rule', () => {
|
||||
expect(sheet.getRule('a')).to.not.be(undefined)
|
||||
})
|
||||
|
||||
it('should generate correct CSS', () => {
|
||||
expect(sheet.toString()).to.be('.a-id {\n zoom: 1;\n}')
|
||||
})
|
||||
})
|
||||
|
||||
describe('values with px units', () => {
|
||||
let sheet
|
||||
|
||||
beforeEach(() => {
|
||||
sheet = jss.createStyleSheet({
|
||||
a: {
|
||||
width: 10
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('should add rule', () => {
|
||||
expect(sheet.getRule('a')).to.not.be(undefined)
|
||||
})
|
||||
|
||||
it('should generate correct CSS', () => {
|
||||
expect(sheet.toString()).to.be('.a-id {\n width: 10px;\n}')
|
||||
})
|
||||
})
|
||||
|
||||
describe('values with ms units', () => {
|
||||
let sheet
|
||||
|
||||
beforeEach(() => {
|
||||
sheet = jss.createStyleSheet({
|
||||
a: {
|
||||
'animation-duration': 200
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('should add rule', () => {
|
||||
expect(sheet.getRule('a')).to.not.be(undefined)
|
||||
})
|
||||
|
||||
it('should generate correct CSS', () => {
|
||||
expect(sheet.toString()).to.be('.a-id {\n animation-duration: 200ms;\n}')
|
||||
})
|
||||
})
|
||||
|
||||
describe('values with % units', () => {
|
||||
let sheet
|
||||
|
||||
beforeEach(() => {
|
||||
sheet = jss.createStyleSheet({
|
||||
a: {
|
||||
'transform-origin-x': 50
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('should add rule', () => {
|
||||
expect(sheet.getRule('a')).to.not.be(undefined)
|
||||
})
|
||||
|
||||
it('should generate correct CSS', () => {
|
||||
expect(sheet.toString()).to.be('.a-id {\n transform-origin-x: 50%;\n}')
|
||||
})
|
||||
})
|
||||
|
||||
describe('leave non-regular rules unchanged', () => {
|
||||
let sheet
|
||||
|
||||
beforeEach(() => {
|
||||
sheet = jss.createStyleSheet({
|
||||
'@font-face': {
|
||||
'font-family': 'MyHelvetica',
|
||||
src: 'local("Helvetica")'
|
||||
},
|
||||
'@media print': {
|
||||
a: {
|
||||
'border-left': 1,
|
||||
border: 3
|
||||
}
|
||||
},
|
||||
'@keyframes a': {
|
||||
from: {top: 0},
|
||||
'30%': {top: 30},
|
||||
'60%, 70%': {top: 80}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('should generate correct CSS', () => {
|
||||
expect(sheet.toString()).to.be(
|
||||
'@font-face {\n' +
|
||||
' font-family: MyHelvetica;\n' +
|
||||
' src: local("Helvetica");\n' +
|
||||
'}\n' +
|
||||
'@media print {\n' +
|
||||
' .a-id {\n' +
|
||||
' border-left: 1px;\n' +
|
||||
' border: 3px;\n' +
|
||||
' }\n' +
|
||||
'}\n' +
|
||||
'@keyframes keyframes-a-id {\n' +
|
||||
' from {\n' +
|
||||
' top: 0;\n' +
|
||||
' }\n' +
|
||||
' 30% {\n' +
|
||||
' top: 30px;\n' +
|
||||
' }\n' +
|
||||
' 60%, 70% {\n' +
|
||||
' top: 80px;\n' +
|
||||
' }\n' +
|
||||
'}'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('comma-separated values', () => {
|
||||
let sheet
|
||||
|
||||
beforeEach(() => {
|
||||
sheet = jss.createStyleSheet({
|
||||
a: {
|
||||
'background-size': [10, 15]
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('should add rule', () => {
|
||||
expect(sheet.getRule('a')).to.not.be(undefined)
|
||||
})
|
||||
|
||||
it('should generate correct CSS', () => {
|
||||
expect(sheet.toString()).to.be('.a-id {\n background-size: 10px, 15px;\n}')
|
||||
})
|
||||
})
|
||||
|
||||
describe('comma-separated values', () => {
|
||||
let sheet
|
||||
|
||||
beforeEach(() => {
|
||||
sheet = jss.createStyleSheet({
|
||||
a: {
|
||||
'background-size': [[10, 5]]
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('should add rule', () => {
|
||||
expect(sheet.getRule('a')).to.not.be(undefined)
|
||||
})
|
||||
|
||||
it('should generate correct CSS', () => {
|
||||
expect(sheet.toString()).to.be('.a-id {\n background-size: 10px 5px;\n}')
|
||||
})
|
||||
})
|
||||
|
||||
describe('customized units via options object', () => {
|
||||
let sheet
|
||||
|
||||
beforeEach(() => {
|
||||
sheet = jss.createStyleSheet({
|
||||
a: {
|
||||
'min-width': 20,
|
||||
'max-width': 20
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('should add rule', () => {
|
||||
expect(sheet.getRule('a')).to.not.be(undefined)
|
||||
})
|
||||
|
||||
it('should generate correct CSS', () => {
|
||||
expect(sheet.toString()).to.be('.a-id {\n min-width: 20pc;\n max-width: 10px;\n}')
|
||||
})
|
||||
})
|
||||
|
||||
describe('ignore falsy values', () => {
|
||||
let sheet
|
||||
|
||||
beforeEach(() => {
|
||||
sheet = jss.createStyleSheet({
|
||||
a: {
|
||||
padding: 10,
|
||||
margin: null
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('should add rule', () => {
|
||||
expect(sheet.getRule('a')).to.not.be(undefined)
|
||||
})
|
||||
|
||||
it('should generate correct CSS', () => {
|
||||
expect(sheet.toString()).to.be('.a-id {\n padding: 10px;\n}')
|
||||
})
|
||||
})
|
||||
|
||||
describe('add default units to fallbacks', () => {
|
||||
let sheet
|
||||
|
||||
beforeEach(() => {
|
||||
const localJss = create(settings).use(defaultUnit())
|
||||
sheet = localJss.createStyleSheet({
|
||||
a: {
|
||||
padding: 1,
|
||||
fallbacks: {
|
||||
padding: 5
|
||||
}
|
||||
},
|
||||
b: {
|
||||
padding: 1,
|
||||
fallbacks: [{padding: 5}, {padding: 10}]
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('should add rule', () => {
|
||||
expect(sheet.getRule('a')).to.not.be(undefined)
|
||||
expect(sheet.getRule('b')).to.not.be(undefined)
|
||||
})
|
||||
|
||||
it('should generate correct CSS', () => {
|
||||
expect(sheet.toString()).to.be(
|
||||
'.a-id {\n' +
|
||||
' padding: 5px;\n' +
|
||||
' padding: 1px;\n' +
|
||||
'}\n' +
|
||||
'.b-id {\n' +
|
||||
' padding: 5px;\n' +
|
||||
' padding: 10px;\n' +
|
||||
' padding: 1px;\n' +
|
||||
'}'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('add default units in combination with expand plugin', () => {
|
||||
let sheet
|
||||
|
||||
beforeEach(() => {
|
||||
const localJss = create(settings).use(defaultUnit({'padding-top': 'rem'}), expand())
|
||||
sheet = localJss.createStyleSheet({
|
||||
a: {
|
||||
padding: {
|
||||
top: 5,
|
||||
left: 0,
|
||||
right: 10,
|
||||
bottom: 15
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('should add rule', () => {
|
||||
expect(sheet.getRule('a')).to.not.be(undefined)
|
||||
})
|
||||
|
||||
it('should generate correct CSS', () => {
|
||||
expect(sheet.toString()).to.be('.a-id {\n padding: 5rem 10px 15px 0;\n}')
|
||||
})
|
||||
})
|
||||
|
||||
describe('add default units in combination with expand plugin (objects inside arrays)', () => {
|
||||
let sheet
|
||||
|
||||
beforeEach(() => {
|
||||
const localJss = create(settings).use(defaultUnit(), expand())
|
||||
sheet = localJss.createStyleSheet({
|
||||
a: {
|
||||
transition: [
|
||||
{
|
||||
timingFunction: 'linear',
|
||||
delay: 100,
|
||||
property: 'opacity',
|
||||
duration: 200
|
||||
},
|
||||
{
|
||||
timingFunction: 'linear',
|
||||
property: 'transform',
|
||||
duration: 300
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('should add rule', () => {
|
||||
expect(sheet.getRule('a')).to.not.be(undefined)
|
||||
})
|
||||
|
||||
it('should generate correct CSS', () => {
|
||||
expect(sheet.toString()).to.be(
|
||||
'.a-id {\n transition: opacity 200ms linear 100ms, transform 300ms linear;\n}'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('support camel cased units', () => {
|
||||
it('should work with default units', () => {
|
||||
const sheet = jss.createStyleSheet({
|
||||
a: {
|
||||
borderBottom: 10
|
||||
}
|
||||
})
|
||||
expect(sheet.toString()).to.be('.a-id {\n borderBottom: 10px;\n}')
|
||||
})
|
||||
|
||||
it('should work with user units', () => {
|
||||
const localJss = create(settings).use(defaultUnit({borderBottom: 'pc'}))
|
||||
|
||||
const sheet = localJss.createStyleSheet({
|
||||
a: {
|
||||
borderBottom: 10
|
||||
}
|
||||
})
|
||||
|
||||
expect(sheet.toString()).to.be('.a-id {\n borderBottom: 10pc;\n}')
|
||||
})
|
||||
})
|
||||
|
||||
describe('support function values', () => {
|
||||
let sheet
|
||||
|
||||
beforeEach(() => {
|
||||
jss.use(functionPlugin())
|
||||
|
||||
sheet = jss.createStyleSheet({
|
||||
a: {
|
||||
width: () => 1
|
||||
}
|
||||
})
|
||||
sheet.update()
|
||||
})
|
||||
|
||||
it('should add default unit', () => {
|
||||
expect(sheet.toString()).to.be(stripIndent`
|
||||
.a-id {
|
||||
width: 1px;
|
||||
}
|
||||
`)
|
||||
})
|
||||
})
|
||||
|
||||
describe('support observable values', () => {
|
||||
let sheet
|
||||
|
||||
beforeEach(() => {
|
||||
jss.use(observablePlugin())
|
||||
|
||||
sheet = jss.createStyleSheet({
|
||||
a: {
|
||||
width: new Observable(observer => {
|
||||
observer.next(1)
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
it('should add default unit', () => {
|
||||
expect(sheet.toString()).to.be(stripIndent`
|
||||
.a-id {
|
||||
width: 1px;
|
||||
}
|
||||
`)
|
||||
})
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user