Security upgrades

This commit is contained in:
2020-07-15 19:54:48 +02:00
parent 59cc6c54cd
commit ad8ed283d2
3164 changed files with 408897 additions and 28 deletions

8
node_modules/jss/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,8 @@
The MIT License (MIT)
Copyright (c) 2014-present Oleg Isonen (Slobodskoi) & contributors
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.

2298
node_modules/jss/dist/jss.bundle.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

2236
node_modules/jss/dist/jss.cjs.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

3
node_modules/jss/dist/jss.cjs.js.flow generated vendored Normal file
View File

@@ -0,0 +1,3 @@
// @flow
export * from '../src';

2221
node_modules/jss/dist/jss.esm.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

2318
node_modules/jss/dist/jss.js generated vendored Normal file

File diff suppressed because it is too large Load Diff

1
node_modules/jss/dist/jss.js.map generated vendored Normal file

File diff suppressed because one or more lines are too long

1
node_modules/jss/dist/jss.min.js generated vendored Normal file

File diff suppressed because one or more lines are too long

84
node_modules/jss/package.json generated vendored Normal file
View File

@@ -0,0 +1,84 @@
{
"_from": "jss@^10.0.3",
"_id": "jss@10.3.0",
"_inBundle": false,
"_integrity": "sha512-B5sTRW9B6uHaUVzSo9YiMEOEp3UX8lWevU0Fsv+xtRnsShmgCfIYX44bTH8bPJe6LQKqEXku3ulKuHLbxBS97Q==",
"_location": "/jss",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "jss@^10.0.3",
"name": "jss",
"escapedName": "jss",
"rawSpec": "^10.0.3",
"saveSpec": null,
"fetchSpec": "^10.0.3"
},
"_requiredBy": [
"/@material-ui/styles",
"/jss-plugin-camel-case",
"/jss-plugin-default-unit",
"/jss-plugin-global",
"/jss-plugin-nested",
"/jss-plugin-props-sort",
"/jss-plugin-rule-value-function",
"/jss-plugin-vendor-prefixer"
],
"_resolved": "https://registry.npmjs.org/jss/-/jss-10.3.0.tgz",
"_shasum": "2cf7be265f72b59c1764d816fdabff1c5dd18326",
"_spec": "jss@^10.0.3",
"_where": "D:\\WORK\\Menui\\menui_backend\\node_modules\\@material-ui\\styles",
"author": {
"name": "JSS Team"
},
"bugs": {
"url": "https://github.com/cssinjs/jss/issues/new"
},
"bundleDependencies": false,
"dependencies": {
"@babel/runtime": "^7.3.1",
"csstype": "^2.6.5",
"is-in-browser": "^1.1.3",
"tiny-warning": "^1.0.2"
},
"deprecated": false,
"description": "A lib for generating Style Sheets with JavaScript.",
"files": [
"dist",
"src",
"LICENSE"
],
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/jss"
},
"gitHead": "4094410d82dfdae772e1c09f0cd187cb48fa1cdc",
"homepage": "https://cssinjs.org/",
"keywords": [
"jss",
"style",
"sheet",
"stylesheet",
"css",
"components",
"composable",
"css in js",
"css-in-js"
],
"license": "MIT",
"main": "dist/jss.cjs.js",
"module": "dist/jss.esm.js",
"name": "jss",
"repository": {
"type": "git",
"url": "git+https://github.com/cssinjs/jss.git"
},
"scripts": {
"build": "node ../../scripts/build.js",
"check-snapshot": "node ../../scripts/match-snapshot.js"
},
"typings": "./src/index.d.ts",
"unpkg": "dist/jss.bundle.js",
"version": "10.3.0"
}

26
node_modules/jss/readme.md generated vendored Normal file
View File

@@ -0,0 +1,26 @@
# jss
[![Version](https://img.shields.io/npm/v/jss.svg?style=flat)](https://npmjs.org/package/jss)
[![License](https://img.shields.io/npm/l/jss.svg?style=flat)](https://github.com/cssinjs/jss/blob/master/LICENSE)
[![Downlodas](https://img.shields.io/npm/dm/jss.svg?style=flat)](https://npmjs.org/package/jss)
[![Size](https://img.shields.io/bundlephobia/minzip/jss.svg?style=flat)](https://npmjs.org/package/jss)
[![Dependencies](https://img.shields.io/david/cssinjs/jss.svg?path=packages%2Fjss&style=flat)](https://npmjs.org/package/jss)
[![Gitter](https://badges.gitter.im/JoinChat.svg)](https://gitter.im/cssinjs/lobby)
> A lib for generating Style Sheets with JavaScript.
See our website [jss](https://cssinjs.org/setup?v=v10.3.0) for more information.
## Install
Using npm:
```sh
npm install jss
```
or using yarn:
```sh
yarn add jss
```

460
node_modules/jss/src/DomRenderer.js generated vendored Normal file
View File

@@ -0,0 +1,460 @@
/* @flow */
import warning from 'tiny-warning'
import sheets from './sheets'
import toCssValue from './utils/toCssValue'
import type {
CSSStyleRule,
CSSMediaRule,
CSSKeyframesRule,
CSSKeyframeRule,
HTMLElementWithStyleMap,
AnyCSSRule,
Rule,
RuleList,
ContainerRule,
JssValue,
InsertionPoint,
StyleSheet
} from './types'
type PriorityOptions = {
index: number,
insertionPoint?: InsertionPoint
}
/**
* Cache the value from the first time a function is called.
*/
const memoize = <Value>(fn: () => Value): (() => Value) => {
let value
return () => {
if (!value) value = fn()
return value
}
}
/**
* Get a style property value.
*/
function getPropertyValue(
cssRule: HTMLElementWithStyleMap | CSSStyleRule | CSSKeyframeRule,
prop: string
): string {
try {
// Support CSSTOM.
if (cssRule.attributeStyleMap) {
return cssRule.attributeStyleMap.get(prop)
}
return cssRule.style.getPropertyValue(prop)
} catch (err) {
// IE may throw if property is unknown.
return ''
}
}
/**
* Set a style property.
*/
function setProperty(
cssRule: HTMLElementWithStyleMap | CSSStyleRule | CSSKeyframeRule,
prop: string,
value: JssValue
): boolean {
try {
let cssValue = ((value: any): string)
if (Array.isArray(value)) {
cssValue = toCssValue(value, true)
if (value[value.length - 1] === '!important') {
cssRule.style.setProperty(prop, cssValue, 'important')
return true
}
}
// Support CSSTOM.
if (cssRule.attributeStyleMap) {
cssRule.attributeStyleMap.set(prop, cssValue)
} else {
cssRule.style.setProperty(prop, cssValue)
}
} catch (err) {
// IE may throw if property is unknown.
return false
}
return true
}
/**
* Remove a style property.
*/
function removeProperty(
cssRule: HTMLElementWithStyleMap | CSSStyleRule | CSSKeyframeRule,
prop: string
) {
try {
// Support CSSTOM.
if (cssRule.attributeStyleMap) {
cssRule.attributeStyleMap.delete(prop)
} else {
cssRule.style.removeProperty(prop)
}
} catch (err) {
warning(
false,
`[JSS] DOMException "${err.message}" was thrown. Tried to remove property "${prop}".`
)
}
}
/**
* Set the selector.
*/
function setSelector(cssRule: CSSStyleRule, selectorText: string): boolean {
cssRule.selectorText = selectorText
// Return false if setter was not successful.
// Currently works in chrome only.
return cssRule.selectorText === selectorText
}
/**
* Gets the `head` element upon the first call and caches it.
* We assume it can't be null.
*/
const getHead = memoize((): HTMLElement => (document.querySelector('head'): any))
/**
* Find attached sheet with an index higher than the passed one.
*/
function findHigherSheet(registry: Array<StyleSheet>, options: PriorityOptions): StyleSheet | null {
for (let i = 0; i < registry.length; i++) {
const sheet = registry[i]
if (
sheet.attached &&
sheet.options.index > options.index &&
sheet.options.insertionPoint === options.insertionPoint
) {
return sheet
}
}
return null
}
/**
* Find attached sheet with the highest index.
*/
function findHighestSheet(
registry: Array<StyleSheet>,
options: PriorityOptions
): StyleSheet | null {
for (let i = registry.length - 1; i >= 0; i--) {
const sheet = registry[i]
if (sheet.attached && sheet.options.insertionPoint === options.insertionPoint) {
return sheet
}
}
return null
}
/**
* Find a comment with "jss" inside.
*/
function findCommentNode(text: string): Node | null {
const head = getHead()
for (let i = 0; i < head.childNodes.length; i++) {
const node = head.childNodes[i]
if (node.nodeType === 8 && node.nodeValue.trim() === text) {
return node
}
}
return null
}
type PrevNode = {
parent: ?Node,
node: ?Node
}
/**
* Find a node before which we can insert the sheet.
*/
function findPrevNode(options: PriorityOptions): PrevNode | false {
const {registry} = sheets
if (registry.length > 0) {
// Try to insert before the next higher sheet.
let sheet = findHigherSheet(registry, options)
if (sheet && sheet.renderer) {
return {
parent: sheet.renderer.element.parentNode,
node: sheet.renderer.element
}
}
// Otherwise insert after the last attached.
sheet = findHighestSheet(registry, options)
if (sheet && sheet.renderer) {
return {
parent: sheet.renderer.element.parentNode,
node: sheet.renderer.element.nextSibling
}
}
}
// Try to find a comment placeholder if registry is empty.
const {insertionPoint} = options
if (insertionPoint && typeof insertionPoint === 'string') {
const comment = findCommentNode(insertionPoint)
if (comment) {
return {
parent: comment.parentNode,
node: comment.nextSibling
}
}
// If user specifies an insertion point and it can't be found in the document -
// bad specificity issues may appear.
warning(false, `[JSS] Insertion point "${insertionPoint}" not found.`)
}
return false
}
/**
* Insert style element into the DOM.
*/
function insertStyle(style: HTMLElement, options: PriorityOptions) {
const {insertionPoint} = options
const nextNode = findPrevNode(options)
if (nextNode !== false && nextNode.parent) {
nextNode.parent.insertBefore(style, nextNode.node)
return
}
// Works with iframes and any node types.
if (insertionPoint && typeof insertionPoint.nodeType === 'number') {
// https://stackoverflow.com/questions/41328728/force-casting-in-flow
const insertionPointElement: HTMLElement = (insertionPoint: any)
const {parentNode} = insertionPointElement
if (parentNode) parentNode.insertBefore(style, insertionPointElement.nextSibling)
else warning(false, '[JSS] Insertion point is not in the DOM.')
return
}
getHead().appendChild(style)
}
/**
* Read jss nonce setting from the page if the user has set it.
*/
const getNonce = memoize(
(): ?string => {
const node = document.querySelector('meta[property="csp-nonce"]')
return node ? node.getAttribute('content') : null
}
)
const insertRule = (
container: CSSStyleSheet | CSSMediaRule | CSSKeyframesRule,
rule: string,
index?: number
): false | any => {
const maxIndex = container.cssRules.length
// In case previous insertion fails, passed index might be wrong
if (index === undefined || index > maxIndex) {
// eslint-disable-next-line no-param-reassign
index = maxIndex
}
try {
if ('insertRule' in container) {
const c = ((container: any): CSSStyleSheet)
c.insertRule(rule, index)
}
// Keyframes rule.
else if ('appendRule' in container) {
const c = ((container: any): CSSKeyframesRule)
c.appendRule(rule)
}
} catch (err) {
warning(false, `[JSS] ${err.message}`)
return false
}
return container.cssRules[index]
}
const createStyle = (): HTMLElement => {
const el = document.createElement('style')
// Without it, IE will have a broken source order specificity if we
// insert rules after we insert the style tag.
// It seems to kick-off the source order specificity algorithm.
el.textContent = '\n'
return el
}
export default class DomRenderer {
getPropertyValue = getPropertyValue
setProperty = setProperty
removeProperty = removeProperty
setSelector = setSelector
// HTMLStyleElement needs fixing https://github.com/facebook/flow/issues/2696
element: any
sheet: StyleSheet | void
hasInsertedRules: boolean = false
constructor(sheet?: StyleSheet) {
// There is no sheet when the renderer is used from a standalone StyleRule.
if (sheet) sheets.add(sheet)
this.sheet = sheet
const {media, meta, element} = this.sheet ? this.sheet.options : {}
this.element = element || createStyle()
this.element.setAttribute('data-jss', '')
if (media) this.element.setAttribute('media', media)
if (meta) this.element.setAttribute('data-meta', meta)
const nonce = getNonce()
if (nonce) this.element.setAttribute('nonce', nonce)
}
/**
* Insert style element into render tree.
*/
attach(): void {
// In the case the element node is external and it is already in the DOM.
if (this.element.parentNode || !this.sheet) return
insertStyle(this.element, this.sheet.options)
// When rules are inserted using `insertRule` API, after `sheet.detach().attach()`
// most browsers create a new CSSStyleSheet, except of all IEs.
const deployed = Boolean(this.sheet && this.sheet.deployed)
if (this.hasInsertedRules && deployed) {
this.hasInsertedRules = false
this.deploy()
}
}
/**
* Remove style element from render tree.
*/
detach(): void {
const {parentNode} = this.element
if (parentNode) parentNode.removeChild(this.element)
}
/**
* Inject CSS string into element.
*/
deploy(): void {
const {sheet} = this
if (!sheet) return
if (sheet.options.link) {
this.insertRules(sheet.rules)
return
}
this.element.textContent = `\n${sheet.toString()}\n`
}
/**
* Insert RuleList into an element.
*/
insertRules(rules: RuleList, nativeParent?: CSSStyleSheet | CSSMediaRule | CSSKeyframesRule) {
for (let i = 0; i < rules.index.length; i++) {
this.insertRule(rules.index[i], i, nativeParent)
}
}
/**
* Insert a rule into element.
*/
insertRule(
rule: Rule,
index?: number,
nativeParent?: CSSStyleSheet | CSSMediaRule | CSSKeyframesRule = this.element.sheet
): false | CSSStyleSheet | AnyCSSRule {
if (rule.rules) {
const parent: ContainerRule = (rule: any)
let latestNativeParent = nativeParent
if (rule.type === 'conditional' || rule.type === 'keyframes') {
// We need to render the container without children first.
latestNativeParent = insertRule(nativeParent, parent.toString({children: false}), index)
if (latestNativeParent === false) {
return false
}
}
this.insertRules(parent.rules, latestNativeParent)
return latestNativeParent
}
// IE keeps the CSSStyleSheet after style node has been reattached,
// so we need to check if the `renderable` reference the right style sheet and not
// rerender those rules.
if (rule.renderable && rule.renderable.parentStyleSheet === this.element.sheet) {
return rule.renderable
}
const ruleStr = rule.toString()
if (!ruleStr) return false
const nativeRule = insertRule(nativeParent, ruleStr, index)
if (nativeRule === false) {
return false
}
this.hasInsertedRules = true
rule.renderable = nativeRule
return nativeRule
}
/**
* Delete a rule.
*/
deleteRule(cssRule: AnyCSSRule): boolean {
const {sheet} = this.element
const index = this.indexOf(cssRule)
if (index === -1) return false
sheet.deleteRule(index)
return true
}
/**
* Get index of a CSS Rule.
*/
indexOf(cssRule: AnyCSSRule): number {
const {cssRules} = this.element.sheet
for (let index = 0; index < cssRules.length; index++) {
if (cssRule === cssRules[index]) return index
}
return -1
}
/**
* Generate a new CSS rule and replace the existing one.
*
* Only used for some old browsers because they can't set a selector.
*/
replaceRule(cssRule: AnyCSSRule, rule: Rule): false | CSSStyleSheet | AnyCSSRule {
const index = this.indexOf(cssRule)
if (index === -1) return false
this.element.sheet.deleteRule(index)
return this.insertRule(rule, index)
}
/**
* Get all rules elements.
*/
getRules(): CSSRuleList {
return this.element.sheet.cssRules
}
}

142
node_modules/jss/src/Jss.js generated vendored Normal file
View File

@@ -0,0 +1,142 @@
/* @flow */
import isInBrowser from 'is-in-browser'
import StyleSheet from './StyleSheet'
import PluginsRegistry from './PluginsRegistry'
import sheets from './sheets'
import {plugins as internalPlugins} from './plugins/index'
import createGenerateIdDefault from './utils/createGenerateId'
import createRule from './utils/createRule'
import DomRenderer from './DomRenderer'
import type {
Rule,
RuleFactoryOptions,
RuleOptions,
StyleSheetFactoryOptions,
Plugin,
JssOptions,
InternalJssOptions,
JssStyle
} from './types'
import type {GenerateId} from './utils/createGenerateId'
let instanceCounter = 0
export default class Jss {
id = instanceCounter++
version = process.env.VERSION
plugins = new PluginsRegistry()
options: InternalJssOptions = {
id: {minify: false},
createGenerateId: createGenerateIdDefault,
Renderer: isInBrowser ? DomRenderer : null,
plugins: []
}
generateId: GenerateId = createGenerateIdDefault({minify: false})
constructor(options?: JssOptions) {
for (let i = 0; i < internalPlugins.length; i++) {
this.plugins.use(internalPlugins[i], {queue: 'internal'})
}
this.setup(options)
}
/**
* Prepares various options, applies plugins.
* Should not be used twice on the same instance, because there is no plugins
* deduplication logic.
*/
setup(options?: JssOptions = {}): this {
if (options.createGenerateId) {
this.options.createGenerateId = options.createGenerateId
}
if (options.id) {
this.options.id = {
...this.options.id,
...options.id
}
}
if (options.createGenerateId || options.id) {
this.generateId = this.options.createGenerateId(this.options.id)
}
if (options.insertionPoint != null) this.options.insertionPoint = options.insertionPoint
if ('Renderer' in options) {
this.options.Renderer = options.Renderer
}
// eslint-disable-next-line prefer-spread
if (options.plugins) this.use.apply(this, options.plugins)
return this
}
/**
* Create a Style Sheet.
*/
createStyleSheet(styles: Object, options: StyleSheetFactoryOptions = {}): StyleSheet {
let {index} = options
if (typeof index !== 'number') {
index = sheets.index === 0 ? 0 : sheets.index + 1
}
const sheet = new StyleSheet(styles, {
...options,
jss: this,
generateId: options.generateId || this.generateId,
insertionPoint: this.options.insertionPoint,
Renderer: this.options.Renderer,
index
})
this.plugins.onProcessSheet(sheet)
return sheet
}
/**
* Detach the Style Sheet and remove it from the registry.
*/
removeStyleSheet(sheet: StyleSheet): this {
sheet.detach()
sheets.remove(sheet)
return this
}
/**
* Create a rule without a Style Sheet.
* [Deprecated] will be removed in the next major version.
*/
createRule(name?: string, style?: JssStyle = {}, options?: RuleFactoryOptions = {}): Rule | null {
// Enable rule without name for inline styles.
if (typeof name === 'object') {
return this.createRule(undefined, name, style)
}
const ruleOptions: RuleOptions = {...options, name, jss: this, Renderer: this.options.Renderer}
if (!ruleOptions.generateId) ruleOptions.generateId = this.generateId
if (!ruleOptions.classes) ruleOptions.classes = {}
if (!ruleOptions.keyframes) ruleOptions.keyframes = {}
const rule = createRule(name, style, ruleOptions)
if (rule) this.plugins.onProcessRule(rule)
return rule
}
/**
* Register plugin. Passed function will be invoked with a rule instance.
*/
use(...plugins: Array<Plugin>): this {
plugins.forEach(plugin => {
this.plugins.use(plugin)
})
return this
}
}

140
node_modules/jss/src/PluginsRegistry.js generated vendored Normal file
View File

@@ -0,0 +1,140 @@
/* @flow */
import warning from 'tiny-warning'
import type StyleSheet from './StyleSheet'
import type {
Plugin,
Rule,
RuleOptions,
UpdateOptions,
JssStyle,
JssValue,
OnCreateRule,
OnProcessRule,
OnProcessStyle,
OnProcessSheet,
OnChangeValue,
OnUpdate
} from './types'
import type {StyleRule} from './plugins/styleRule'
type Registry = {
onCreateRule: Array<OnCreateRule>,
onProcessRule: Array<OnProcessRule>,
onProcessStyle: Array<OnProcessStyle>,
onProcessSheet: Array<OnProcessSheet>,
onChangeValue: Array<OnChangeValue>,
onUpdate: Array<OnUpdate>
}
export default class PluginsRegistry {
plugins: {
internal: Array<Plugin>,
external: Array<Plugin>
} = {
internal: [],
external: []
}
registry: Registry
/**
* Call `onCreateRule` hooks and return an object if returned by a hook.
*/
onCreateRule(name?: string, decl: JssStyle, options: RuleOptions): Rule | null {
for (let i = 0; i < this.registry.onCreateRule.length; i++) {
const rule = this.registry.onCreateRule[i](name, decl, options)
if (rule) return rule
}
return null
}
/**
* Call `onProcessRule` hooks.
*/
onProcessRule(rule: Rule): void {
if (rule.isProcessed) return
const {sheet} = rule.options
for (let i = 0; i < this.registry.onProcessRule.length; i++) {
this.registry.onProcessRule[i](rule, sheet)
}
if (rule.style) this.onProcessStyle(rule.style, rule, sheet)
rule.isProcessed = true
}
/**
* Call `onProcessStyle` hooks.
*/
onProcessStyle(style: JssStyle, rule: Rule, sheet?: StyleSheet): void {
for (let i = 0; i < this.registry.onProcessStyle.length; i++) {
// $FlowFixMe
rule.style = this.registry.onProcessStyle[i](rule.style, rule, sheet)
}
}
/**
* Call `onProcessSheet` hooks.
*/
onProcessSheet(sheet: StyleSheet): void {
for (let i = 0; i < this.registry.onProcessSheet.length; i++) {
this.registry.onProcessSheet[i](sheet)
}
}
/**
* Call `onUpdate` hooks.
*/
onUpdate(data: Object, rule: Rule, sheet: StyleSheet, options: UpdateOptions): void {
for (let i = 0; i < this.registry.onUpdate.length; i++) {
this.registry.onUpdate[i](data, rule, sheet, options)
}
}
/**
* Call `onChangeValue` hooks.
*/
onChangeValue(value: JssValue, prop: string, rule: StyleRule): JssValue {
let processedValue = value
for (let i = 0; i < this.registry.onChangeValue.length; i++) {
processedValue = this.registry.onChangeValue[i](processedValue, prop, rule)
}
return processedValue
}
/**
* Register a plugin.
*/
use(newPlugin: Plugin, options: {queue: 'internal' | 'external'} = {queue: 'external'}): void {
const plugins = this.plugins[options.queue]
// Avoids applying same plugin twice, at least based on ref.
if (plugins.indexOf(newPlugin) !== -1) {
return
}
plugins.push(newPlugin)
this.registry = [...this.plugins.external, ...this.plugins.internal].reduce(
(registry: Registry, plugin: Plugin) => {
for (const name in plugin) {
if (name in registry) {
registry[name].push(plugin[name])
} else {
warning(false, `[JSS] Unknown hook "${name}".`)
}
}
return registry
},
{
onCreateRule: [],
onProcessRule: [],
onProcessStyle: [],
onProcessSheet: [],
onChangeValue: [],
onUpdate: []
}
)
}
}

262
node_modules/jss/src/RuleList.js generated vendored Normal file
View File

@@ -0,0 +1,262 @@
/* @flow */
import createRule from './utils/createRule'
import {StyleRule, KeyframesRule} from './plugins/index'
import type {
RuleListOptions,
ToCssOptions,
Rule,
RuleOptions,
JssStyle,
Classes,
KeyframesMap,
UpdateArguments,
UpdateOptions
} from './types'
import escape from './utils/escape'
const defaultUpdateOptions = {
process: true
}
const forceUpdateOptions = {
force: true,
process: true
}
/**
* Contains rules objects and allows adding/removing etc.
* Is used for e.g. by `StyleSheet` or `ConditionalRule`.
*/
export default class RuleList {
// Rules registry for access by .get() method.
// It contains the same rule registered by name and by selector.
map: {[key: string]: Rule} = {}
// Original styles object.
raw: {[key: string]: JssStyle} = {}
// Used to ensure correct rules order.
index: Array<Rule> = []
counter: number = 0
options: RuleListOptions
classes: Classes
keyframes: KeyframesMap
constructor(options: RuleListOptions) {
this.options = options
this.classes = options.classes
this.keyframes = options.keyframes
}
/**
* Create and register rule.
*
* Will not render after Style Sheet was rendered the first time.
*/
add(name: string, decl: JssStyle, ruleOptions?: RuleOptions): Rule | null {
const {parent, sheet, jss, Renderer, generateId, scoped} = this.options
const options = {
classes: this.classes,
parent,
sheet,
jss,
Renderer,
generateId,
scoped,
name,
...ruleOptions
}
// When user uses .createStyleSheet(), duplicate names are not possible, but
// `sheet.addRule()` opens the door for any duplicate rule name. When this happens
// we need to make the key unique within this RuleList instance scope.
let key = name
if (name in this.raw) {
key = `${name}-d${this.counter++}`
}
// We need to save the original decl before creating the rule
// because cache plugin needs to use it as a key to return a cached rule.
this.raw[key] = decl
if (key in this.classes) {
// E.g. rules inside of @media container
options.selector = `.${escape(this.classes[key])}`
}
const rule = createRule(key, decl, options)
if (!rule) return null
this.register(rule)
const index = options.index === undefined ? this.index.length : options.index
this.index.splice(index, 0, rule)
return rule
}
/**
* Get a rule.
*/
get(name: string): Rule {
return this.map[name]
}
/**
* Delete a rule.
*/
remove(rule: Rule): void {
this.unregister(rule)
delete this.raw[rule.key]
this.index.splice(this.index.indexOf(rule), 1)
}
/**
* Get index of a rule.
*/
indexOf(rule: Rule): number {
return this.index.indexOf(rule)
}
/**
* Run `onProcessRule()` plugins on every rule.
*/
process(): void {
const {plugins} = this.options.jss
// We need to clone array because if we modify the index somewhere else during a loop
// we end up with very hard-to-track-down side effects.
this.index.slice(0).forEach(plugins.onProcessRule, plugins)
}
/**
* Register a rule in `.map`, `.classes` and `.keyframes` maps.
*/
register(rule: Rule): void {
this.map[rule.key] = rule
if (rule instanceof StyleRule) {
this.map[rule.selector] = rule
if (rule.id) this.classes[rule.key] = rule.id
} else if (rule instanceof KeyframesRule && this.keyframes) {
this.keyframes[rule.name] = rule.id
}
}
/**
* Unregister a rule.
*/
unregister(rule: Rule): void {
delete this.map[rule.key]
if (rule instanceof StyleRule) {
delete this.map[rule.selector]
delete this.classes[rule.key]
} else if (rule instanceof KeyframesRule) {
delete this.keyframes[rule.name]
}
}
/**
* Update the function values with a new data.
*/
update(...args: UpdateArguments): void {
let name
let data
let options
if (typeof args[0] === 'string') {
name = args[0]
// $FlowFixMe
data = args[1]
// $FlowFixMe
options = args[2]
} else {
data = args[0]
// $FlowFixMe
options = args[1]
name = null
}
if (name) {
this.updateOne(this.map[name], data, options)
} else {
for (let index = 0; index < this.index.length; index++) {
this.updateOne(this.index[index], data, options)
}
}
}
/**
* Execute plugins, update rule props.
*/
updateOne(rule: Rule, data: Object, options?: UpdateOptions = defaultUpdateOptions) {
const {
jss: {plugins},
sheet
} = this.options
// It is a rules container like for e.g. ConditionalRule.
if (rule.rules instanceof RuleList) {
rule.rules.update(data, options)
return
}
const styleRule: StyleRule = (rule: any)
const {style} = styleRule
plugins.onUpdate(data, rule, sheet, options)
// We rely on a new `style` ref in case it was mutated during onUpdate hook.
if (options.process && style && style !== styleRule.style) {
// We need to run the plugins in case new `style` relies on syntax plugins.
plugins.onProcessStyle(styleRule.style, styleRule, sheet)
// Update and add props.
for (const prop in styleRule.style) {
const nextValue = styleRule.style[prop]
const prevValue = style[prop]
// We need to use `force: true` because `rule.style` has been updated during onUpdate hook, so `rule.prop()` will not update the CSSOM rule.
// We do this comparison to avoid unneeded `rule.prop()` calls, since we have the old `style` object here.
if (nextValue !== prevValue) {
styleRule.prop(prop, nextValue, forceUpdateOptions)
}
}
// Remove props.
for (const prop in style) {
const nextValue = styleRule.style[prop]
const prevValue = style[prop]
// We need to use `force: true` because `rule.style` has been updated during onUpdate hook, so `rule.prop()` will not update the CSSOM rule.
// We do this comparison to avoid unneeded `rule.prop()` calls, since we have the old `style` object here.
if (nextValue == null && nextValue !== prevValue) {
styleRule.prop(prop, null, forceUpdateOptions)
}
}
}
}
/**
* Convert rules to a CSS string.
*/
toString(options?: ToCssOptions): string {
let str = ''
const {sheet} = this.options
const link = sheet ? sheet.options.link : false
for (let index = 0; index < this.index.length; index++) {
const rule = this.index[index]
const css = rule.toString(options)
// No need to render an empty rule.
if (!css && !link) continue
if (str) str += '\n'
str += css
}
return str
}
}

71
node_modules/jss/src/SheetsManager.js generated vendored Normal file
View File

@@ -0,0 +1,71 @@
/* @flow */
import warn from 'tiny-warning'
import type StyleSheet from './StyleSheet'
/**
* SheetsManager is like a WeakMap which is designed to count StyleSheet
* instances and attach/detach automatically.
*/
export default class SheetsManager {
length = 0
sheets = new WeakMap<
Object,
{
refs: number,
sheet: StyleSheet
}
>()
get size(): number {
return this.length
}
get(key: Object): ?StyleSheet {
const entry = this.sheets.get(key)
return entry && entry.sheet
}
add(key: Object, sheet: StyleSheet) {
if (this.sheets.has(key)) return
this.length++
this.sheets.set(key, {
sheet,
refs: 0
})
}
manage(key: Object): ?StyleSheet {
const entry = this.sheets.get(key)
if (entry) {
if (entry.refs === 0) {
entry.sheet.attach()
}
entry.refs++
return entry.sheet
}
warn(false, "[JSS] SheetsManager: can't find sheet to manage")
return undefined
}
unmanage(key: Object) {
const entry = this.sheets.get(key)
if (entry) {
if (entry.refs > 0) {
entry.refs--
if (entry.refs === 0) entry.sheet.detach()
}
} else {
warn(false, "SheetsManager: can't find sheet to unmanage")
}
}
}

71
node_modules/jss/src/SheetsRegistry.js generated vendored Normal file
View File

@@ -0,0 +1,71 @@
/* @flow */
import type {ToCssOptions} from './types'
import type StyleSheet from './StyleSheet'
/**
* Sheets registry to access them all at one place.
*/
export default class SheetsRegistry {
registry: Array<StyleSheet> = []
/**
* Current highest index number.
*/
get index(): number {
return this.registry.length === 0 ? 0 : this.registry[this.registry.length - 1].options.index
}
/**
* Register a Style Sheet.
*/
add(sheet: StyleSheet): void {
const {registry} = this
const {index} = sheet.options
if (registry.indexOf(sheet) !== -1) return
if (registry.length === 0 || index >= this.index) {
registry.push(sheet)
return
}
// Find a position.
for (let i = 0; i < registry.length; i++) {
if (registry[i].options.index > index) {
registry.splice(i, 0, sheet)
return
}
}
}
/**
* Reset the registry.
*/
reset(): void {
this.registry = []
}
/**
* Remove a Style Sheet.
*/
remove(sheet: StyleSheet): void {
const index = this.registry.indexOf(sheet)
this.registry.splice(index, 1)
}
/**
* Convert all attached sheets to a CSS string.
*/
toString({attached, ...options}: {attached?: boolean, ...ToCssOptions} = {}): string {
let css = ''
for (let i = 0; i < this.registry.length; i++) {
const sheet = this.registry[i]
if (attached != null && sheet.attached !== attached) {
continue
}
if (css) css += '\n'
css += sheet.toString(options)
}
return css
}
}

206
node_modules/jss/src/StyleSheet.js generated vendored Normal file
View File

@@ -0,0 +1,206 @@
/* @flow */
import RuleList from './RuleList'
import type {
InternalStyleSheetOptions,
Rule,
ToCssOptions,
RuleOptions,
StyleSheetOptions,
JssStyle,
Classes,
KeyframesMap,
JssStyles,
Renderer,
UpdateArguments,
UpdateOptions
} from './types'
export default class StyleSheet {
options: InternalStyleSheetOptions
deployed: boolean
attached: boolean
rules: RuleList
renderer: Renderer | null
classes: Classes
keyframes: KeyframesMap
queue: ?Array<Rule>
constructor(styles: JssStyles, options: StyleSheetOptions) {
this.attached = false
this.deployed = false
this.classes = {}
this.keyframes = {}
this.options = {
...options,
sheet: this,
parent: this,
classes: this.classes,
keyframes: this.keyframes
}
if (options.Renderer) {
this.renderer = new options.Renderer(this)
}
this.rules = new RuleList(this.options)
for (const name in styles) {
this.rules.add(name, styles[name])
}
this.rules.process()
}
/**
* Attach renderable to the render tree.
*/
attach(): this {
if (this.attached) return this
if (this.renderer) this.renderer.attach()
this.attached = true
// Order is important, because we can't use insertRule API if style element is not attached.
if (!this.deployed) this.deploy()
return this
}
/**
* Remove renderable from render tree.
*/
detach(): this {
if (!this.attached) return this
if (this.renderer) this.renderer.detach()
this.attached = false
return this
}
/**
* Add a rule to the current stylesheet.
* Will insert a rule also after the stylesheet has been rendered first time.
*/
addRule(name: string, decl: JssStyle, options?: RuleOptions): Rule | null {
const {queue} = this
// Plugins can create rules.
// In order to preserve the right order, we need to queue all `.addRule` calls,
// which happen after the first `rules.add()` call.
if (this.attached && !queue) this.queue = []
const rule = this.rules.add(name, decl, options)
if (!rule) return null
this.options.jss.plugins.onProcessRule(rule)
if (this.attached) {
if (!this.deployed) return rule
// Don't insert rule directly if there is no stringified version yet.
// It will be inserted all together when .attach is called.
if (queue) queue.push(rule)
else {
this.insertRule(rule)
if (this.queue) {
this.queue.forEach(this.insertRule, this)
this.queue = undefined
}
}
return rule
}
// We can't add rules to a detached style node.
// We will redeploy the sheet once user will attach it.
this.deployed = false
return rule
}
/**
* Insert rule into the StyleSheet
*/
insertRule(rule: Rule) {
if (this.renderer) {
this.renderer.insertRule(rule)
}
}
/**
* Create and add rules.
* Will render also after Style Sheet was rendered the first time.
*/
addRules(styles: JssStyles, options?: RuleOptions): Array<Rule> {
const added = []
for (const name in styles) {
const rule = this.addRule(name, styles[name], options)
if (rule) added.push(rule)
}
return added
}
/**
* Get a rule by name.
*/
getRule(name: string): Rule {
return this.rules.get(name)
}
/**
* Delete a rule by name.
* Returns `true`: if rule has been deleted from the DOM.
*/
deleteRule(name: string | Rule): boolean {
const rule = typeof name === 'object' ? name : this.rules.get(name)
if (!rule) return false
this.rules.remove(rule)
if (this.attached && rule.renderable && this.renderer) {
return this.renderer.deleteRule(rule.renderable)
}
return true
}
/**
* Get index of a rule.
*/
indexOf(rule: Rule): number {
return this.rules.indexOf(rule)
}
/**
* Deploy pure CSS string to a renderable.
*/
deploy(): this {
if (this.renderer) this.renderer.deploy()
this.deployed = true
return this
}
/**
* Update the function values with a new data.
*/
update(...args: UpdateArguments): this {
this.rules.update(...args)
return this
}
/**
* Updates a single rule.
*/
updateOne(rule: Rule, data: Object, options?: UpdateOptions): this {
this.rules.updateOne(rule, data, options)
return this
}
/**
* Convert rules to a CSS string.
*/
toString(options?: ToCssOptions): string {
return this.rules.toString(options)
}
}

258
node_modules/jss/src/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,258 @@
import * as css from 'csstype'
// TODO: Type data better, currently typed as any for allowing to override it
type Func<R> = ((data: any) => R)
type NormalCssProperties = css.Properties<string | number>
type NormalCssValues<K> = K extends keyof NormalCssProperties
? NormalCssProperties[K] | JssValue
: JssValue
export type JssStyle = {
[K in keyof NormalCssProperties | string]:
| NormalCssValues<K>
| JssStyle
| Func<NormalCssValues<K> | JssStyle | undefined>
}
export type Styles<Name extends string | number | symbol = string> = Record<
Name,
JssStyle | string | Func<JssStyle | string | null | undefined>
>
export type Classes<Name extends string | number | symbol = string> = Record<Name, string>
export type Keyframes<Name extends string = string> = Record<Name, string>
export interface CreateGenerateIdOptions {
minify?: boolean
}
export type CreateGenerateId = (options?: CreateGenerateIdOptions) => GenerateId
export type GenerateId = (rule: Rule, sheet?: StyleSheet<string>) => string
export type JssValue =
| string
| number
| Array<string | number | Array<string | number> | '!important'>
| null
| false
export type InsertionPoint = string | HTMLElement | Comment
export interface UpdateOptions {
process?: boolean
force?: boolean
}
export interface ToCssOptions {
indent?: number
allowEmpty?: boolean
}
interface RuleListOptions {
classes: Classes
generateClassName: GenerateId
Renderer: Renderer
jss: Jss
sheet: StyleSheet
parent: ContainerRule | StyleSheet
}
declare class RuleList {
constructor(options: RuleListOptions)
add(name: string, decl: JssStyle, options?: RuleOptions): Rule
get(name: string): Rule
remove(rule: Rule): void
indexOf(rule: Rule): number
process(): void
register(rule: Rule, className?: string): void
unregister(rule: Rule): void
update(name: string, data: {}): void
update(data: {}): void
toString(options?: ToCssOptions): string
}
interface RuleOptions {
selector?: string
sheet?: StyleSheet
index?: number
parent?: ContainerRule | StyleSheet
classes: Classes
jss: Jss
generateId: GenerateId
Renderer: Renderer
}
interface BaseRule {
type: string
key: string
isProcessed: boolean
// eslint-disable-next-line no-use-before-define
options: RuleOptions
toString(options?: ToCssOptions): string
}
interface ContainerRule extends BaseRule {
rules: RuleList
}
export interface Plugin {
onCreateRule?(name: string, decl: JssStyle, options: RuleOptions): Rule
onProcessRule?(rule: Rule, sheet?: StyleSheet): void
onProcessStyle?(style: JssStyle, rule: Rule, sheet?: StyleSheet): JssStyle
onProcessSheet?(sheet?: StyleSheet): void
onChangeValue?(value: string, prop: string, rule: Rule): string | null | false
onUpdate?(data: object, rule: Rule, sheet?: StyleSheet): void
}
export type Rule = BaseRule | ContainerRule
export interface Renderer {
setProperty(cssRule: HTMLElement | CSSStyleRule, prop: string, value: JssValue): boolean
getPropertyValue(cssRule: HTMLElement | CSSStyleRule, prop: string): string
removeProperty(cssRule: HTMLElement | CSSStyleRule, prop: string): void
setSelector(cssRule: CSSStyleRule, selectorText: string): boolean
attach(): void
detach(): void
deploy(sheet: StyleSheet): void
insertRule(rule: Rule): false | CSSRule
deleteRule(cssRule: CSSRule): boolean
replaceRule(cssRule: CSSRule, rule: Rule): false | CSSRule
indexOf(cssRule: CSSRule): number
getRules(): CSSRuleList | void
}
interface RuleFactoryOptions {
selector?: string
classes?: object
sheet?: StyleSheet
index?: number
jss?: Jss
generateId?: GenerateId
Renderer?: Renderer
}
export interface StyleSheetFactoryOptions {
media?: string
meta?: string
index?: number
link?: boolean
element?: HTMLStyleElement
generateId?: GenerateId
classNamePrefix?: string
}
interface StyleSheetOptions extends StyleSheetFactoryOptions {
index: number
generateId: GenerateId
Renderer: Renderer
insertionPoint?: InsertionPoint
jss: Jss
}
declare class SheetsRegistry {
readonly index: number
add<RuleName extends string | number | symbol>(sheet: StyleSheet<RuleName>): void
reset(): void
remove<RuleName extends string | number | symbol>(sheet: StyleSheet<RuleName>): void
toString(options?: ToCssOptions): string
}
declare class SheetsManager {
readonly size: number
get(key: object): StyleSheet | null
add(key: object, sheet: StyleSheet): void
manage(key: object): StyleSheet | null
unmanage(key: object): void
}
export interface StyleSheet<RuleName extends string | number | symbol = string | number | symbol> {
// Gives auto-completion on the rules declared in `createStyleSheet` without
// causing errors for rules added dynamically after creation.
classes: Classes<RuleName>
keyframes: Keyframes<string>
options: StyleSheetOptions
linked: boolean
attached: boolean
/**
* Attach renderable to the render tree.
*/
attach(): this
/**
* Remove renderable from render tree.
*/
detach(): this
deploy(): this
/**
* Add a rule to the current stylesheet.
* Will insert a rule also after the stylesheet has been rendered first time.
*/
addRule(style: JssStyle, options?: Partial<RuleOptions>): Rule
addRule(name: RuleName, style: JssStyle, options?: Partial<RuleOptions>): Rule
insertRule(rule: Rule): void
/**
* Create and add rules.
* Will render also after Style Sheet was rendered the first time.
*/
addRules(styles: Partial<Styles<RuleName>>, options?: Partial<RuleOptions>): Rule[]
/**
* Get a rule by name.
*/
getRule(name: RuleName): Rule
/**
* Delete a rule by name.
* Returns `true`: if rule has been deleted from the DOM.
*/
deleteRule(name: RuleName): boolean
/**
* Get index of a rule.
*/
indexOf(rule: Rule): number
/**
* Update the function values with a new data.
*/
update(name: string, data: object, options?: UpdateOptions): this
update(data: object, options?: UpdateOptions): this
/**
* Convert rules to a CSS string.
*/
toString(options?: ToCssOptions): string
}
export interface JssOptions {
createGenerateId: CreateGenerateId
plugins: ReadonlyArray<Plugin>
Renderer?: {new (): Renderer} | null
insertionPoint: InsertionPoint
id: CreateGenerateIdOptions
}
export interface Jss {
createStyleSheet<Name extends string | number | symbol>(
styles: Partial<Styles<Name>>,
options?: StyleSheetFactoryOptions
): StyleSheet<Name>
removeStyleSheet(sheet: StyleSheet): this
setup(options?: Partial<JssOptions>): this
use(...plugins: Plugin[]): this
createRule(style: JssStyle, options?: RuleFactoryOptions): Rule
createRule<Name extends string>(name: Name, style: JssStyle, options?: RuleFactoryOptions): Rule
}
/**
* Creates a new instance of JSS.
*/
declare const sheets: SheetsRegistry
export {sheets, SheetsManager, SheetsRegistry, RuleList}
export function create(options?: Partial<JssOptions>): Jss
export const createGenerateId: CreateGenerateId
export function createRule<D>(name: string, decl: JssStyle, options: RuleOptions): Rule
export function toCssValue(value: JssValue, ignoreImportant: boolean): string
export function getDynamicStyles(styles: Styles): Styles | null
declare const jss: Jss
/**
* A global JSS instance.
*/
export default jss

106
node_modules/jss/src/index.js generated vendored Normal file
View File

@@ -0,0 +1,106 @@
/* @flow */
/**
* A better abstraction over CSS.
*
* @copyright Oleg Isonen (Slobodskoi) / Isonen 2014-present
* @website https://github.com/cssinjs/jss
* @license MIT
*/
import Jss from './Jss'
import type StyleSheet from './StyleSheet'
import type {
ConditionalRule,
KeyframesRule,
StyleRule,
ViewportRule,
SimpleRule,
FontFaceRule
} from './plugins'
import type {JssOptions} from './types'
/**
* Export types for better typing inside plugins and integrations.
*/
export type {
StyleSheetFactoryOptions,
JssValue,
JssOptions,
JssStyle,
Plugin,
RuleListOptions,
Rule,
Renderer,
RuleOptions,
UpdateOptions,
Classes,
BaseRule,
ContainerRule
} from './types'
export type {GenerateId, CreateGenerateId, CreateGenerateIdOptions} from './utils/createGenerateId'
export type {
Jss,
StyleSheet,
ConditionalRule,
KeyframesRule,
StyleRule,
ViewportRule,
SimpleRule,
FontFaceRule
}
/**
* Export a constant indicating if this browser has CSSTOM support.
* https://developers.google.com/web/updates/2018/03/cssom
*/
export const hasCSSTOMSupport = typeof CSS !== 'undefined' && CSS && 'number' in CSS
/**
* Extracts a styles object with only rules that contain function values.
*/
export {default as getDynamicStyles} from './utils/getDynamicStyles'
/**
* Converts JSS array value to a CSS string.
*/
export {default as toCssValue} from './utils/toCssValue'
/**
* Create a rule instance.
*/
export {default as createRule} from './utils/createRule'
/**
* SheetsRegistry for SSR.
*/
export {default as SheetsRegistry} from './SheetsRegistry'
/**
* SheetsManager for react-jss and co.
*/
export {default as SheetsManager} from './SheetsManager'
/**
* RuleList for plugins.
*/
export {default as RuleList} from './RuleList'
/**
* Default global SheetsRegistry instance.
*/
export {default as sheets} from './sheets'
/**
* Class name generator creator.
*/
export {default as createGenerateId} from './utils/createGenerateId'
/**
* Creates a new instance of Jss.
*/
export const create = (options?: JssOptions): Jss => new Jss(options)
/**
* A global Jss instance.
*/
export default create()

92
node_modules/jss/src/plugins/conditionalRule.js generated vendored Normal file
View File

@@ -0,0 +1,92 @@
/* @flow */
import RuleList from '../RuleList'
import type {CSSMediaRule, Rule, RuleOptions, ToCssOptions, JssStyle, ContainerRule} from '../types'
const defaultToStringOptions = {
indent: 1,
children: true
}
const atRegExp = /@([\w-]+)/
/**
* Conditional rule for @media, @supports
*/
export class ConditionalRule implements ContainerRule {
type = 'conditional'
at: string
key: string
query: string
rules: RuleList
options: RuleOptions
isProcessed: boolean = false
renderable: ?CSSMediaRule
constructor(key: string, styles: Object, options: RuleOptions) {
this.key = key
// Key might contain a unique suffix in case the `name` passed by user was duplicate.
this.query = options.name
const atMatch = key.match(atRegExp)
this.at = atMatch ? atMatch[1] : 'unknown'
this.options = options
this.rules = new RuleList({...options, parent: this})
for (const name in styles) {
this.rules.add(name, styles[name])
}
this.rules.process()
}
/**
* Get a rule.
*/
getRule(name: string): Rule {
return this.rules.get(name)
}
/**
* Get index of a rule.
*/
indexOf(rule: Rule): number {
return this.rules.indexOf(rule)
}
/**
* Create and register rule, run plugins.
*/
addRule(name: string, style: JssStyle, options?: RuleOptions): Rule | null {
const rule = this.rules.add(name, style, options)
if (!rule) return null
this.options.jss.plugins.onProcessRule(rule)
return rule
}
/**
* Generates a CSS string.
*/
toString(options?: ToCssOptions = defaultToStringOptions): string {
if (options.indent == null) options.indent = defaultToStringOptions.indent
if (options.children == null) options.children = defaultToStringOptions.children
if (options.children === false) {
return `${this.query} {}`
}
const children = this.rules.toString(options)
return children ? `${this.query} {\n${children}\n}` : ''
}
}
const keyRegExp = /@media|@supports\s+/
export default {
onCreateRule(key: string, styles: JssStyle, options: RuleOptions): ConditionalRule | null {
return keyRegExp.test(key) ? new ConditionalRule(key, styles, options) : null
}
}

49
node_modules/jss/src/plugins/fontFaceRule.js generated vendored Normal file
View File

@@ -0,0 +1,49 @@
/* @flow */
import toCss from '../utils/toCss'
import type {CSSFontFaceRule, RuleOptions, JssStyle, ToCssOptions, BaseRule} from '../types'
export class FontFaceRule implements BaseRule {
type = 'font-face'
at: string = '@font-face'
key: string
style: JssStyle
options: RuleOptions
isProcessed: boolean = false
renderable: ?CSSFontFaceRule
constructor(key: string, style: JssStyle, options: RuleOptions) {
this.key = key
this.style = style
this.options = options
}
/**
* Generates a CSS string.
*/
toString(options?: ToCssOptions): string {
if (Array.isArray(this.style)) {
let str = ''
for (let index = 0; index < this.style.length; index++) {
str += toCss(this.at, this.style[index])
if (this.style[index + 1]) str += '\n'
}
return str
}
return toCss(this.at, this.style, options)
}
}
const keyRegExp = /@font-face/
export default {
onCreateRule(key: string, style: JssStyle, options: RuleOptions): FontFaceRule | null {
return keyRegExp.test(key) ? new FontFaceRule(key, style, options) : null
}
}

27
node_modules/jss/src/plugins/index.js generated vendored Normal file
View File

@@ -0,0 +1,27 @@
import pluginStyleRule, {StyleRule} from './styleRule'
import pluginConditionalRule, {ConditionalRule} from './conditionalRule'
import pluginKeyframesRule, {KeyframesRule} from './keyframesRule'
import pluginKeyframeRule, {KeyframeRule} from './keyframeRule'
import pluginFontFaceRule, {FontFaceRule} from './fontFaceRule'
import pluginViewportRule, {ViewportRule} from './viewportRule'
import pluginSimpleRule, {SimpleRule} from './simpleRule'
export const plugins = [
pluginStyleRule,
pluginConditionalRule,
pluginKeyframesRule,
pluginKeyframeRule,
pluginFontFaceRule,
pluginViewportRule,
pluginSimpleRule
]
export {
StyleRule,
ConditionalRule,
KeyframesRule,
KeyframeRule,
FontFaceRule,
ViewportRule,
SimpleRule
}

27
node_modules/jss/src/plugins/keyframeRule.js generated vendored Normal file
View File

@@ -0,0 +1,27 @@
/* @flow */
import toCss from '../utils/toCss'
import type {JssStyle, RuleOptions, ToCssOptions, CSSKeyframeRule} from '../types'
import {BaseStyleRule} from './styleRule'
export class KeyframeRule extends BaseStyleRule {
renderable: ?CSSKeyframeRule
/**
* Generates a CSS string.
*/
toString(options?: ToCssOptions): string {
const {sheet} = this.options
const link = sheet ? sheet.options.link : false
const opts = link ? {...options, allowEmpty: true} : options
return toCss(this.key, this.style, opts)
}
}
export default {
onCreateRule(key: string, style: JssStyle, options: RuleOptions): KeyframeRule | null {
if (options.parent && options.parent.type === 'keyframes') {
return new KeyframeRule(key, style, options)
}
return null
}
}

149
node_modules/jss/src/plugins/keyframesRule.js generated vendored Normal file
View File

@@ -0,0 +1,149 @@
/* @flow */
import warning from 'tiny-warning'
import RuleList from '../RuleList'
import type {
CSSKeyframesRule,
JssStyle,
RuleOptions,
ToCssOptions,
ContainerRule,
KeyframesMap,
Plugin
} from '../types'
import escape from '../utils/escape'
const defaultToStringOptions = {
indent: 1,
children: true
}
const nameRegExp = /@keyframes\s+([\w-]+)/
/**
* Rule for @keyframes
*/
export class KeyframesRule implements ContainerRule {
type = 'keyframes'
at: string = '@keyframes'
key: string
name: string
id: string
rules: RuleList
options: RuleOptions
isProcessed: boolean = false
renderable: ?CSSKeyframesRule
constructor(key: string, frames: Object, options: RuleOptions) {
const nameMatch = key.match(nameRegExp)
if (nameMatch && nameMatch[1]) {
this.name = nameMatch[1]
} else {
this.name = 'noname'
warning(false, `[JSS] Bad keyframes name ${key}`)
}
this.key = `${this.type}-${this.name}`
this.options = options
const {scoped, sheet, generateId} = options
this.id = scoped === false ? this.name : escape(generateId(this, sheet))
this.rules = new RuleList({...options, parent: this})
for (const name in frames) {
this.rules.add(name, frames[name], {
...options,
parent: this
})
}
this.rules.process()
}
/**
* Generates a CSS string.
*/
toString(options?: ToCssOptions = defaultToStringOptions): string {
if (options.indent == null) options.indent = defaultToStringOptions.indent
if (options.children == null) options.children = defaultToStringOptions.children
if (options.children === false) {
return `${this.at} ${this.id} {}`
}
let children = this.rules.toString(options)
if (children) children = `\n${children}\n`
return `${this.at} ${this.id} {${children}}`
}
}
const keyRegExp = /@keyframes\s+/
const refRegExp = /\$([\w-]+)/g
const findReferencedKeyframe = (val, keyframes) => {
if (typeof val === 'string') {
return val.replace(refRegExp, (match, name) => {
if (name in keyframes) {
return keyframes[name]
}
warning(false, `[JSS] Referenced keyframes rule "${name}" is not defined.`)
return match
})
}
return val
}
/**
* Replace the reference for a animation name.
*/
const replaceRef = (style: JssStyle, prop: string, keyframes: KeyframesMap) => {
const value = style[prop]
const refKeyframe = findReferencedKeyframe(value, keyframes)
if (refKeyframe !== value) {
style[prop] = refKeyframe
}
}
const plugin: Plugin = {
onCreateRule(key, frames, options) {
return typeof key === 'string' && keyRegExp.test(key)
? new KeyframesRule(key, frames, options)
: null
},
// Animation name ref replacer.
onProcessStyle: (style, rule, sheet) => {
if (rule.type !== 'style' || !sheet) return style
if ('animation-name' in style) replaceRef(style, 'animation-name', sheet.keyframes)
if ('animation' in style) replaceRef(style, 'animation', sheet.keyframes)
return style
},
onChangeValue(val, prop, rule) {
const {sheet} = rule.options
if (!sheet) {
return val
}
switch (prop) {
case 'animation':
return findReferencedKeyframe(val, sheet.keyframes)
case 'animation-name':
return findReferencedKeyframe(val, sheet.keyframes)
default:
return val
}
}
}
export default plugin

59
node_modules/jss/src/plugins/simpleRule.js generated vendored Normal file
View File

@@ -0,0 +1,59 @@
/* @flow */
import type {
CSSCharsetRule,
CSSImportRule,
CSSNamespaceRule,
RuleOptions,
JssStyle,
ToCssOptions,
BaseRule
} from '../types'
export class SimpleRule implements BaseRule {
type = 'simple'
key: string
value: string
options: RuleOptions
isProcessed: boolean = false
renderable: ?CSSCharsetRule | CSSImportRule | CSSNamespaceRule
constructor(key: string, value: string, options: RuleOptions) {
this.key = key
this.value = value
this.options = options
}
/**
* Generates a CSS string.
*/
// eslint-disable-next-line no-unused-vars
toString(options?: ToCssOptions): string {
if (Array.isArray(this.value)) {
let str = ''
for (let index = 0; index < this.value.length; index++) {
str += `${this.key} ${this.value[index]};`
if (this.value[index + 1]) str += '\n'
}
return str
}
return `${this.key} ${this.value};`
}
}
const keysMap = {
'@charset': true,
'@import': true,
'@namespace': true
}
export default {
onCreateRule(key: string, value: JssStyle, options: RuleOptions): SimpleRule | null {
return key in keysMap ? new SimpleRule(key, ((value: any): string), options) : null
}
}

179
node_modules/jss/src/plugins/styleRule.js generated vendored Normal file
View File

@@ -0,0 +1,179 @@
/* @flow */
import warning from 'tiny-warning'
import toCss from '../utils/toCss'
import toCssValue from '../utils/toCssValue'
import escape from '../utils/escape'
import type {
CSSStyleRule,
HTMLElementWithStyleMap,
ToCssOptions,
RuleOptions,
UpdateOptions,
Renderer as RendererInterface,
JssStyle,
JssValue,
BaseRule
} from '../types'
export class BaseStyleRule implements BaseRule {
type = 'style'
key: string
isProcessed: boolean = false
style: JssStyle
renderer: RendererInterface | null
renderable: ?Object
options: RuleOptions
constructor(key: string, style: JssStyle, options: RuleOptions) {
const {sheet, Renderer} = options
this.key = key
this.options = options
this.style = style
if (sheet) this.renderer = sheet.renderer
else if (Renderer) this.renderer = new Renderer()
}
/**
* Get or set a style property.
*/
prop(name: string, value?: JssValue, options?: UpdateOptions): this | string {
// It's a getter.
if (value === undefined) return this.style[name]
// Don't do anything if the value has not changed.
const force = options ? options.force : false
if (!force && this.style[name] === value) return this
let newValue = value
if (!options || options.process !== false) {
newValue = this.options.jss.plugins.onChangeValue(value, name, this)
}
const isEmpty = newValue == null || newValue === false
const isDefined = name in this.style
// Value is empty and wasn't defined before.
if (isEmpty && !isDefined && !force) return this
// We are going to remove this value.
const remove = isEmpty && isDefined
if (remove) delete this.style[name]
else this.style[name] = newValue
// Renderable is defined if StyleSheet option `link` is true.
if (this.renderable && this.renderer) {
if (remove) this.renderer.removeProperty(this.renderable, name)
else this.renderer.setProperty(this.renderable, name, newValue)
return this
}
const {sheet} = this.options
if (sheet && sheet.attached) {
warning(false, '[JSS] Rule is not linked. Missing sheet option "link: true".')
}
return this
}
}
export class StyleRule extends BaseStyleRule {
selectorText: string
id: ?string
renderable: ?CSSStyleRule
constructor(key: string, style: JssStyle, options: RuleOptions) {
super(key, style, options)
const {selector, scoped, sheet, generateId} = options
if (selector) {
this.selectorText = selector
} else if (scoped !== false) {
this.id = generateId(this, sheet)
this.selectorText = `.${escape(this.id)}`
}
}
/**
* Set selector string.
* Attention: use this with caution. Most browsers didn't implement
* selectorText setter, so this may result in rerendering of entire Style Sheet.
*/
set selector(selector: string): void {
if (selector === this.selectorText) return
this.selectorText = selector
const {renderer, renderable} = this
if (!renderable || !renderer) return
const hasChanged = renderer.setSelector(renderable, selector)
// If selector setter is not implemented, rerender the rule.
if (!hasChanged) {
renderer.replaceRule(renderable, this)
}
}
/**
* Get selector string.
*/
get selector(): string {
return this.selectorText
}
/**
* Apply rule to an element inline.
*/
applyTo(renderable: HTMLElementWithStyleMap): this {
const {renderer} = this
if (renderer) {
const json = this.toJSON()
for (const prop in json) {
renderer.setProperty(renderable, prop, json[prop])
}
}
return this
}
/**
* Returns JSON representation of the rule.
* Fallbacks are not supported.
* Useful for inline styles.
*/
toJSON(): Object {
const json = {}
for (const prop in this.style) {
const value = this.style[prop]
if (typeof value !== 'object') json[prop] = value
else if (Array.isArray(value)) json[prop] = toCssValue(value)
}
return json
}
/**
* Generates a CSS string.
*/
toString(options?: ToCssOptions): string {
const {sheet} = this.options
const link = sheet ? sheet.options.link : false
const opts = link ? {...options, allowEmpty: true} : options
return toCss(this.selectorText, this.style, opts)
}
}
export default {
onCreateRule(name: string, style: JssStyle, options: RuleOptions): StyleRule | null {
if (name[0] === '@' || (options.parent && options.parent.type === 'keyframes')) {
return null
}
return new StyleRule(name, style, options)
}
}

40
node_modules/jss/src/plugins/viewportRule.js generated vendored Normal file
View File

@@ -0,0 +1,40 @@
/* @flow */
import toCss from '../utils/toCss'
import type {CSSViewportRule, RuleOptions, JssStyle, ToCssOptions, BaseRule} from '../types'
export class ViewportRule implements BaseRule {
type = 'viewport'
at: string = '@viewport'
key: string
style: JssStyle
options: RuleOptions
isProcessed: boolean = false
renderable: ?CSSViewportRule
constructor(key: string, style: JssStyle, options: RuleOptions) {
this.key = key
this.style = style
this.options = options
}
/**
* Generates a CSS string.
*/
toString(options?: ToCssOptions): string {
return toCss(this.key, this.style, options)
}
}
export default {
onCreateRule(key: string, style: JssStyle, options: RuleOptions): ViewportRule | null {
return key === '@viewport' || key === '@-ms-viewport'
? new ViewportRule(key, style, options)
: null
}
}

10
node_modules/jss/src/sheets.js generated vendored Normal file
View File

@@ -0,0 +1,10 @@
/* @flow */
import SheetsRegistry from './SheetsRegistry'
/**
* This is a global sheets registry. Only DomRenderer will add sheets to it.
* On the server one should use an own SheetsRegistry instance and add the
* sheets to it, because you need to make sure to create a new registry for
* each request in order to not leak sheets across requests.
*/
export default new SheetsRegistry()

98
node_modules/jss/src/types/cssom.js generated vendored Normal file
View File

@@ -0,0 +1,98 @@
// @flow
import type {DOMString} from './dom'
export interface StylePropertyMap {
get(property: DOMString): DOMString;
set(property: DOMString, value: DOMString): DOMString;
delete(property: DOMString): void;
}
export interface CSSRuleBase<T> {
+type: $PropertyType<T, 'type'>;
+CSSRule: ?CSSRule;
+CSSStyleSheet: ?CSSStyleSheet;
cssText: DOMString;
attributeStyleMap: StylePropertyMap;
}
export interface CSSGroupingRule<T> extends CSSRuleBase<T> {
// eslint-disable-next-line no-use-before-define
+cssRules: CSSRuleList;
insertRule(rule: DOMString, index: number): number;
deleteRule(index: number): void;
}
export interface CSSStyleRule extends CSSRuleBase<{type: 1 | 1}> {
+type: 1;
+style: CSSStyleDeclaration;
selectorText: DOMString;
}
export interface CSSCharsetRule extends CSSRuleBase<{type: 2 | 2}> {
+type: 2;
charset: DOMString;
}
export interface CSSImportRule extends CSSRuleBase<{type: 3 | 3}> {
+type: 3;
+mediaList: {
+mediaText: DOMString,
length: number,
item?: DOMString,
appendMedium(medium: DOMString): void,
deleteMedium(medium: DOMString): void
};
}
export interface CSSMediaRule extends CSSGroupingRule<{type: 4 | 4}> {
+type: 4;
+mediaList: {
+mediaText: DOMString,
length: number,
item?: DOMString,
appendMedium(medium: DOMString): void,
deleteMedium(medium: DOMString): void
};
}
export interface CSSFontFaceRule extends CSSRuleBase<{type: 5 | 5}> {
+type: 5;
+style: CSSStyleDeclaration;
}
export interface CSSKeyframeRule extends CSSRuleBase<{type: 8 | 8}> {
+type: 8;
+style: CSSStyleDeclaration;
keyText: DOMString;
}
export interface CSSKeyframesRule extends CSSRuleBase<{type: 7 | 7}> {
+type: 7;
+cssRules: CSSRuleList;
name: DOMString;
appendRule(rule: DOMString): void;
deleteRule(key: DOMString): void;
findRule(key: DOMString): CSSKeyframeRule;
}
export interface CSSNamespaceRule extends CSSRuleBase<{type: 10 | 10}> {
+type: 10;
namespaceURI: DOMString;
prefix: DOMString;
}
export interface CSSViewportRule extends CSSRuleBase<{type: 15 | 15}> {
+type: 15;
+style: CSSStyleDeclaration;
}
export type AnyCSSRule =
| CSSMediaRule
| CSSFontFaceRule
| CSSKeyframesRule
| CSSCharsetRule
| CSSImportRule
| CSSNamespaceRule
| CSSStyleRule
| CSSViewportRule

9
node_modules/jss/src/types/dom.js generated vendored Normal file
View File

@@ -0,0 +1,9 @@
// @flow
import {StylePropertyMap} from './cssom'
export type DOMString = string
export interface HTMLElementWithStyleMap extends HTMLElement {
+attributeStyleMap?: StylePropertyMap;
}

5
node_modules/jss/src/types/index.js generated vendored Normal file
View File

@@ -0,0 +1,5 @@
// @flow
export * from './cssom'
export * from './dom'
export * from './jss'

208
node_modules/jss/src/types/jss.js generated vendored Normal file
View File

@@ -0,0 +1,208 @@
/* @flow */
import type Jss from '../Jss'
import type StyleSheet from '../StyleSheet'
import type {ConditionalRule} from '../plugins/conditionalRule'
import type {KeyframesRule} from '../plugins/keyframesRule'
import type {StyleRule} from '../plugins/styleRule'
import type {ViewportRule} from '../plugins/viewportRule'
import type {SimpleRule} from '../plugins/simpleRule'
import type {FontFaceRule} from '../plugins/fontFaceRule'
import type {CSSStyleRule, AnyCSSRule} from './cssom'
import type {HTMLElementWithStyleMap} from './dom'
import type RuleList from '../RuleList'
import type {CreateGenerateId, CreateGenerateIdOptions, GenerateId} from '../utils/createGenerateId'
export type {RuleList, StyleSheet}
export type Classes = {[string]: string}
export type KeyframesMap = {[string]: string}
export type ToCssOptions = {
indent?: number,
allowEmpty?: boolean,
children?: boolean
}
export type UpdateOptions = {
process?: boolean,
force?: boolean
}
export type UpdateArguments =
| [Object]
| [Object, UpdateOptions]
| [string, Object]
| [string, Object, UpdateOptions]
export interface BaseRule {
type: string;
// Key is used as part of a class name and keyframes-name. It has to be
// a valid CSS identifier https://www.w3.org/TR/CSS21/syndata.html#value-def-identifier
key: string;
isProcessed: boolean;
// eslint-disable-next-line no-use-before-define
options: RuleOptions;
renderable?: Object | null | void;
toString(options?: ToCssOptions): string;
}
export type Rule =
| StyleRule
| ConditionalRule
| FontFaceRule
| KeyframesRule
| SimpleRule
| ViewportRule
| BaseRule
// TODO
// Find a way to declare all types: Object|string|Array<Object>
export type JssStyle = Object
export type JssStyles = {[string]: JssStyle}
export type JssValue =
| string
| number
| Array<string | number | Array<string | number> | '!important'>
| Object
| null
| false
export interface Renderer {
constructor(sheet?: StyleSheet): void;
// HTMLStyleElement needs fixing https://github.com/facebook/flow/issues/2696
element: any;
setProperty(
cssRule: HTMLElementWithStyleMap | CSSStyleRule,
prop: string,
value: JssValue
): boolean;
getPropertyValue(cssRule: HTMLElementWithStyleMap | CSSStyleRule, prop: string): string;
removeProperty(cssRule: HTMLElementWithStyleMap | CSSStyleRule, prop: string): void;
setSelector(cssRule: CSSStyleRule, selectorText: string): boolean;
attach(): void;
detach(): void;
deploy(): void;
insertRule(rule: Rule): false | CSSStyleSheet | AnyCSSRule;
deleteRule(cssRule: AnyCSSRule): boolean;
replaceRule(cssRule: AnyCSSRule, rule: Rule): false | CSSStyleSheet | AnyCSSRule;
indexOf(cssRule: AnyCSSRule): number;
getRules(): CSSRuleList | void;
}
export type RuleFactoryOptions = {
selector?: string,
classes?: Classes,
keyframes?: KeyframesMap,
sheet?: StyleSheet,
index?: number,
jss?: Jss,
generateId?: GenerateId,
Renderer?: Class<Renderer> | null
}
export interface ContainerRule extends BaseRule {
at: string;
rules: RuleList;
}
export type RuleOptions = {
selector?: string,
scoped?: boolean,
sheet?: StyleSheet,
index?: number,
parent?: ContainerRule | StyleSheet,
classes: Classes,
keyframes: KeyframesMap,
jss: Jss,
generateId: GenerateId,
Renderer?: Class<Renderer> | null,
name: string
}
export type RuleListOptions = {
classes: Classes,
scoped?: boolean,
keyframes: KeyframesMap,
generateId: GenerateId,
Renderer?: Class<Renderer> | null,
jss: Jss,
sheet: StyleSheet,
parent: ContainerRule | StyleSheet
}
export type OnCreateRule = (name?: string, decl: JssStyle, options: RuleOptions) => BaseRule | null
export type OnProcessRule = (rule: Rule, sheet?: StyleSheet) => void
export type OnProcessStyle = (style: JssStyle, rule: Rule, sheet?: StyleSheet) => JssStyle
export type OnProcessSheet = (sheet?: StyleSheet) => void
export type OnChangeValue = (value: JssValue, prop: string, rule: StyleRule) => JssValue
export type OnUpdate = (data: Object, rule: Rule, sheet: StyleSheet, options: UpdateOptions) => void
export type Plugin = {|
onCreateRule?: OnCreateRule,
onProcessRule?: OnProcessRule,
onProcessStyle?: OnProcessStyle,
onProcessSheet?: OnProcessSheet,
onChangeValue?: OnChangeValue,
onUpdate?: OnUpdate
|}
export type InsertionPoint = string | HTMLElementWithStyleMap
export type JssOptions = {
createGenerateId?: CreateGenerateId,
id?: CreateGenerateIdOptions,
plugins?: Array<Plugin>,
insertionPoint?: InsertionPoint,
Renderer?: Class<Renderer> | null
}
export type InternalJssOptions = {|
createGenerateId: CreateGenerateId,
plugins: Array<Plugin>,
id: CreateGenerateIdOptions,
insertionPoint?: InsertionPoint,
Renderer?: Class<Renderer> | null
|}
export type StyleSheetFactoryOptions = {
media?: string,
meta?: string,
index?: number,
link?: boolean,
element?: HTMLStyleElement,
generateId?: GenerateId,
classNamePrefix?: string
}
export type StyleSheetOptions = {|
media?: string,
meta?: string,
link?: boolean,
element?: HTMLStyleElement,
index: number,
generateId: GenerateId,
classNamePrefix?: string,
Renderer?: Class<Renderer> | null,
insertionPoint?: InsertionPoint,
jss: Jss
|}
export type InternalStyleSheetOptions = {|
media?: string,
meta?: string,
link?: boolean,
element?: HTMLStyleElement,
index: number,
insertionPoint?: InsertionPoint,
Renderer?: Class<Renderer> | null,
generateId: GenerateId,
classNamePrefix?: string,
jss: Jss,
sheet: StyleSheet,
parent: ConditionalRule | KeyframesRule | StyleSheet,
classes: Classes,
keyframes: KeyframesMap
|}

15
node_modules/jss/src/utils/cloneStyle.js generated vendored Normal file
View File

@@ -0,0 +1,15 @@
import type {JssStyle} from '../types'
const plainObjectConstrurctor = {}.constructor
export default function cloneStyle(style: JssStyle): JssStyle {
if (style == null || typeof style !== 'object') return style
if (Array.isArray(style)) return style.map(cloneStyle)
if (style.constructor !== plainObjectConstrurctor) return style
const newStyle = {}
for (const name in style) {
newStyle[name] = cloneStyle(style[name])
}
return newStyle
}

52
node_modules/jss/src/utils/createGenerateId.js generated vendored Normal file
View File

@@ -0,0 +1,52 @@
/* @flow */
import warning from 'tiny-warning'
import type {Rule} from '../types'
import StyleSheet from '../StyleSheet'
import moduleId from './moduleId'
const maxRules = 1e10
export type CreateGenerateIdOptions = {|
minify: boolean
|}
export type GenerateId = (rule: Rule, sheet?: StyleSheet) => string
export type CreateGenerateId = (options: CreateGenerateIdOptions) => GenerateId
/**
* Returns a function which generates unique class names based on counters.
* When new generator function is created, rule counter is reseted.
* We need to reset the rule counter for SSR for each request.
*/
const createGenerateId: CreateGenerateId = (options = {}) => {
let ruleCounter = 0
return (rule: Rule, sheet?: StyleSheet): string => {
ruleCounter += 1
if (ruleCounter > maxRules) {
warning(false, `[JSS] You might have a memory leak. Rule counter is at ${ruleCounter}.`)
}
let jssId = ''
let prefix = ''
if (sheet) {
if (sheet.options.classNamePrefix) {
prefix = sheet.options.classNamePrefix
}
if (sheet.options.jss.id != null) {
jssId = String(sheet.options.jss.id)
}
}
if (options.minify) {
// Using "c" because a number can't be the first char in a class name.
return `${prefix || 'c'}${moduleId}${jssId}${ruleCounter}`
}
return `${prefix + rule.key}-${moduleId}${jssId ? `-${jssId}` : ''}-${ruleCounter}`
}
}
export default createGenerateId

26
node_modules/jss/src/utils/createRule.js generated vendored Normal file
View File

@@ -0,0 +1,26 @@
/* @flow */
import warning from 'tiny-warning'
import type {Rule, RuleOptions, JssStyle} from '../types'
import cloneStyle from './cloneStyle'
/**
* Create a rule instance.
*/
export default function createRule(
name: string = 'unnamed',
decl: JssStyle,
options: RuleOptions
): Rule | null {
const {jss} = options
const declCopy = cloneStyle(decl)
const rule = jss.plugins.onCreateRule(name, declCopy, options)
if (rule) return rule
// It is an at-rule and it has no instance.
if (name[0] === '@') {
warning(false, `[JSS] Unknown rule ${name}`)
}
return null
}

4
node_modules/jss/src/utils/escape.js generated vendored Normal file
View File

@@ -0,0 +1,4 @@
const escapeRegex = /([[\].#*$><+~=|^:(),"'`\s])/g
const nativeEscape = typeof CSS !== 'undefined' && CSS.escape
export default str => (nativeEscape ? nativeEscape(str) : str.replace(escapeRegex, '\\$1'))

24
node_modules/jss/src/utils/getDynamicStyles.js generated vendored Normal file
View File

@@ -0,0 +1,24 @@
/**
* Extracts a styles object with only props that contain function values.
*/
export default function getDynamicStyles(styles: Object): Object | null {
let to = null
for (const key in styles) {
const value = styles[key]
const type = typeof value
if (type === 'function') {
if (!to) to = {}
to[key] = value
} else if (type === 'object' && value !== null && !Array.isArray(value)) {
const extracted = getDynamicStyles(value)
if (extracted) {
if (!to) to = {}
to[key] = extracted
}
}
}
return to
}

7
node_modules/jss/src/utils/globalThis.js generated vendored Normal file
View File

@@ -0,0 +1,7 @@
/* eslint-disable */
// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
export default (typeof window != 'undefined' && window.Math == Math
? window
: typeof self != 'undefined' && self.Math == Math
? self
: Function('return this')())

10
node_modules/jss/src/utils/moduleId.js generated vendored Normal file
View File

@@ -0,0 +1,10 @@
import globalThis from './globalThis'
const ns = '2f1acc6c3a606b082e5eef5e54414ffb'
if (globalThis[ns] == null) globalThis[ns] = 0
// Bundle may contain multiple JSS versions at the same time. In order to identify
// the current version with just one short number and use it for classes generation
// we use a counter. Also it is more accurate, because user can manually reevaluate
// the module.
export default globalThis[ns]++

77
node_modules/jss/src/utils/toCss.js generated vendored Normal file
View File

@@ -0,0 +1,77 @@
/* @flow */
import toCssValue from './toCssValue'
import type {ToCssOptions, JssStyle} from '../types'
/**
* Indent a string.
* http://jsperf.com/array-join-vs-for
*/
function indentStr(str: string, indent: number): string {
let result = ''
for (let index = 0; index < indent; index++) result += ' '
return result + str
}
/**
* Converts a Rule to CSS string.
*/
export default function toCss(
selector?: string,
style: JssStyle,
options: ToCssOptions = {}
): string {
let result = ''
if (!style) return result
let {indent = 0} = options
const {fallbacks} = style
if (selector) indent++
// Apply fallbacks first.
if (fallbacks) {
// Array syntax {fallbacks: [{prop: value}]}
if (Array.isArray(fallbacks)) {
for (let index = 0; index < fallbacks.length; index++) {
const fallback = fallbacks[index]
for (const prop in fallback) {
const value = fallback[prop]
if (value != null) {
if (result) result += '\n'
result += `${indentStr(`${prop}: ${toCssValue(value)};`, indent)}`
}
}
}
} else {
// Object syntax {fallbacks: {prop: value}}
for (const prop in fallbacks) {
const value = fallbacks[prop]
if (value != null) {
if (result) result += '\n'
result += `${indentStr(`${prop}: ${toCssValue(value)};`, indent)}`
}
}
}
}
for (const prop in style) {
const value = style[prop]
if (value != null && prop !== 'fallbacks') {
if (result) result += '\n'
result += `${indentStr(`${prop}: ${toCssValue(value)};`, indent)}`
}
}
// Allow empty style in this case, because properties will be added dynamically.
if (!result && !options.allowEmpty) return result
// When rule is being stringified before selector was defined.
if (!selector) return result
indent--
if (result) result = `\n${result}\n`
return indentStr(`${selector} {${result}`, indent) + indentStr('}', indent)
}

42
node_modules/jss/src/utils/toCssValue.js generated vendored Normal file
View File

@@ -0,0 +1,42 @@
/* @flow */
const join = (value, by) => {
let result = ''
for (let i = 0; i < value.length; i++) {
// Remove !important from the value, it will be readded later.
if (value[i] === '!important') break
if (result) result += by
result += value[i]
}
return result
}
/**
* Converts array values to string.
*
* `margin: [['5px', '10px']]` > `margin: 5px 10px;`
* `border: ['1px', '2px']` > `border: 1px, 2px;`
* `margin: [['5px', '10px'], '!important']` > `margin: 5px 10px !important;`
* `color: ['red', !important]` > `color: red !important;`
*/
export default function toCssValue(value: any, ignoreImportant: boolean = false) {
if (!Array.isArray(value)) return value
let cssValue = ''
// Support space separated values via `[['5px', '10px']]`.
if (Array.isArray(value[0])) {
for (let i = 0; i < value.length; i++) {
if (value[i] === '!important') break
if (cssValue) cssValue += ', '
cssValue += join(value[i], ' ')
}
} else cssValue = join(value, ', ')
// Add !important, because it was ignored.
if (!ignoreImportant && value[value.length - 1] === '!important') {
cssValue += ' !important'
}
return cssValue
}