code
stringlengths 24
2.07M
| docstring
stringlengths 25
85.3k
| func_name
stringlengths 1
92
| language
stringclasses 1
value | repo
stringlengths 5
64
| path
stringlengths 4
172
| url
stringlengths 44
218
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
createCSSMediaRule = (/** @type {string} */ sourceCssText, type) => {
return /** @type {CSSMediaRule} */ ({
type,
cssRules: [],
insertRule(cssText, index) {
this.cssRules.splice(index, 0, createCSSMediaRule(cssText, {
import: 3,
undefined: 1
}[(cssText.toLowerCase().match(/^@([a-z]+)/) || [])[1]] || 4))
},
get cssText() {
return sourceCssText === '@media{}' ? `@media{${[].map.call(this.cssRules, (cssRule) => cssRule.cssText).join('')}}` : sourceCssText
},
})
} | @type {GroupName} Name of the group. | createCSSMediaRule | javascript | stitchesjs/stitches | packages/core/src/sheet.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/sheet.js | MIT |
walk = (
/** @type {Style} Set of CSS styles */ style,
/** @type {string[]} Selectors that define the elements to which a set of CSS styles apply. */ selectors,
/** @type {string[]} Conditions that define the queries to which a set of CSS styles apply. */ conditions,
) => {
/** @type {keyof style} Represents the left-side "name" for the property (the at-rule prelude, style-rule selector, or declaration name). */
let name
/** @type {style[keyof style]} Represents the right-side "data" for the property (the rule block, or declaration value). */
let data
const each = (style) => {
for (name in style) {
/** Whether the current name represents an at-rule. */
const isAtRuleLike = name.charCodeAt(0) === 64
const datas = isAtRuleLike && Array.isArray(style[name]) ? style[name] : [style[name]]
for (data of datas) {
const camelName = toCamelCase(name)
/** Whether the current data represents a nesting rule, which is a plain object whose key is not already a util. */
const isRuleLike = typeof data === 'object' && data && data.toString === toStringOfObject && (!config.utils[camelName] || !selectors.length)
// if the left-hand "name" matches a configured utility
// conditionally transform the current data using the configured utility
if (camelName in config.utils && !isRuleLike) {
const util = config.utils[camelName]
if (util !== lastUtil) {
lastUtil = util
each(util(data))
lastUtil = null
continue
}
}
// otherwise, if the left-hand "name" matches a configured polyfill
// conditionally transform the current data using the polyfill
else if (camelName in toPolyfilledValue) {
const poly = toPolyfilledValue[camelName]
if (poly !== lastPoly) {
lastPoly = poly
each(poly(data))
lastPoly = null
continue
}
}
// if the left-hand "name" matches a configured at-rule
if (isAtRuleLike) {
// transform the current name with the configured media at-rule prelude
name = toResolvedMediaQueryRanges(name.slice(1) in config.media ? '@media ' + config.media[name.slice(1)] : name)
}
if (isRuleLike) {
/** Next conditions, which may include one new condition (if this is an at-rule). */
const nextConditions = isAtRuleLike ? conditions.concat(name) : [...conditions]
/** Next selectors, which may include one new selector (if this is not an at-rule). */
const nextSelections = isAtRuleLike ? [...selectors] : toResolvedSelectors(selectors, name.split(comma))
if (currentRule !== undefined) {
onCssText(toCssString(...currentRule))
}
currentRule = undefined
walk(data, nextSelections, nextConditions)
} else {
if (currentRule === undefined) currentRule = [[], selectors, conditions]
/** CSS left-hand side value, which may be a specially-formatted custom property. */
name = !isAtRuleLike && name.charCodeAt(0) === 36 ? `--${toTailDashed(config.prefix)}${name.slice(1).replace(/\$/g, '-')}` : name
/** CSS right-hand side value, which may be a specially-formatted custom property. */
data = (
// preserve object-like data
isRuleLike ? data
// replace all non-unitless props that are not custom properties with pixel versions
: typeof data === 'number'
? data && !(camelName in unitlessProps) && !(name.charCodeAt(0) === 45)
? String(data) + 'px'
: String(data)
// replace tokens with stringified primitive values
: toTokenizedValue(
toSizingValue(camelName, data == null ? '' : data),
config.prefix,
config.themeMap[camelName]
)
)
currentRule[0].push(`${isAtRuleLike ? `${name} ` : `${toHyphenCase(name)}:`}${data}`)
}
}
}
}
each(style)
if (currentRule !== undefined) {
onCssText(toCssString(...currentRule))
}
currentRule = undefined
} | Walks CSS styles and converts them into CSSOM-compatible rules. | walk | javascript | stitchesjs/stitches | packages/core/src/convert/toCssRules.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/convert/toCssRules.js | MIT |
walk = (
/** @type {Style} Set of CSS styles */ style,
/** @type {string[]} Selectors that define the elements to which a set of CSS styles apply. */ selectors,
/** @type {string[]} Conditions that define the queries to which a set of CSS styles apply. */ conditions,
) => {
/** @type {keyof style} Represents the left-side "name" for the property (the at-rule prelude, style-rule selector, or declaration name). */
let name
/** @type {style[keyof style]} Represents the right-side "data" for the property (the rule block, or declaration value). */
let data
const each = (style) => {
for (name in style) {
/** Whether the current name represents an at-rule. */
const isAtRuleLike = name.charCodeAt(0) === 64
const datas = isAtRuleLike && Array.isArray(style[name]) ? style[name] : [style[name]]
for (data of datas) {
const camelName = toCamelCase(name)
/** Whether the current data represents a nesting rule, which is a plain object whose key is not already a util. */
const isRuleLike = typeof data === 'object' && data && data.toString === toStringOfObject && (!config.utils[camelName] || !selectors.length)
// if the left-hand "name" matches a configured utility
// conditionally transform the current data using the configured utility
if (camelName in config.utils && !isRuleLike) {
const util = config.utils[camelName]
if (util !== lastUtil) {
lastUtil = util
each(util(data))
lastUtil = null
continue
}
}
// otherwise, if the left-hand "name" matches a configured polyfill
// conditionally transform the current data using the polyfill
else if (camelName in toPolyfilledValue) {
const poly = toPolyfilledValue[camelName]
if (poly !== lastPoly) {
lastPoly = poly
each(poly(data))
lastPoly = null
continue
}
}
// if the left-hand "name" matches a configured at-rule
if (isAtRuleLike) {
// transform the current name with the configured media at-rule prelude
name = toResolvedMediaQueryRanges(name.slice(1) in config.media ? '@media ' + config.media[name.slice(1)] : name)
}
if (isRuleLike) {
/** Next conditions, which may include one new condition (if this is an at-rule). */
const nextConditions = isAtRuleLike ? conditions.concat(name) : [...conditions]
/** Next selectors, which may include one new selector (if this is not an at-rule). */
const nextSelections = isAtRuleLike ? [...selectors] : toResolvedSelectors(selectors, name.split(comma))
if (currentRule !== undefined) {
onCssText(toCssString(...currentRule))
}
currentRule = undefined
walk(data, nextSelections, nextConditions)
} else {
if (currentRule === undefined) currentRule = [[], selectors, conditions]
/** CSS left-hand side value, which may be a specially-formatted custom property. */
name = !isAtRuleLike && name.charCodeAt(0) === 36 ? `--${toTailDashed(config.prefix)}${name.slice(1).replace(/\$/g, '-')}` : name
/** CSS right-hand side value, which may be a specially-formatted custom property. */
data = (
// preserve object-like data
isRuleLike ? data
// replace all non-unitless props that are not custom properties with pixel versions
: typeof data === 'number'
? data && !(camelName in unitlessProps) && !(name.charCodeAt(0) === 45)
? String(data) + 'px'
: String(data)
// replace tokens with stringified primitive values
: toTokenizedValue(
toSizingValue(camelName, data == null ? '' : data),
config.prefix,
config.themeMap[camelName]
)
)
currentRule[0].push(`${isAtRuleLike ? `${name} ` : `${toHyphenCase(name)}:`}${data}`)
}
}
}
}
each(style)
if (currentRule !== undefined) {
onCssText(toCssString(...currentRule))
}
currentRule = undefined
} | Walks CSS styles and converts them into CSSOM-compatible rules. | walk | javascript | stitchesjs/stitches | packages/core/src/convert/toCssRules.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/convert/toCssRules.js | MIT |
each = (style) => {
for (name in style) {
/** Whether the current name represents an at-rule. */
const isAtRuleLike = name.charCodeAt(0) === 64
const datas = isAtRuleLike && Array.isArray(style[name]) ? style[name] : [style[name]]
for (data of datas) {
const camelName = toCamelCase(name)
/** Whether the current data represents a nesting rule, which is a plain object whose key is not already a util. */
const isRuleLike = typeof data === 'object' && data && data.toString === toStringOfObject && (!config.utils[camelName] || !selectors.length)
// if the left-hand "name" matches a configured utility
// conditionally transform the current data using the configured utility
if (camelName in config.utils && !isRuleLike) {
const util = config.utils[camelName]
if (util !== lastUtil) {
lastUtil = util
each(util(data))
lastUtil = null
continue
}
}
// otherwise, if the left-hand "name" matches a configured polyfill
// conditionally transform the current data using the polyfill
else if (camelName in toPolyfilledValue) {
const poly = toPolyfilledValue[camelName]
if (poly !== lastPoly) {
lastPoly = poly
each(poly(data))
lastPoly = null
continue
}
}
// if the left-hand "name" matches a configured at-rule
if (isAtRuleLike) {
// transform the current name with the configured media at-rule prelude
name = toResolvedMediaQueryRanges(name.slice(1) in config.media ? '@media ' + config.media[name.slice(1)] : name)
}
if (isRuleLike) {
/** Next conditions, which may include one new condition (if this is an at-rule). */
const nextConditions = isAtRuleLike ? conditions.concat(name) : [...conditions]
/** Next selectors, which may include one new selector (if this is not an at-rule). */
const nextSelections = isAtRuleLike ? [...selectors] : toResolvedSelectors(selectors, name.split(comma))
if (currentRule !== undefined) {
onCssText(toCssString(...currentRule))
}
currentRule = undefined
walk(data, nextSelections, nextConditions)
} else {
if (currentRule === undefined) currentRule = [[], selectors, conditions]
/** CSS left-hand side value, which may be a specially-formatted custom property. */
name = !isAtRuleLike && name.charCodeAt(0) === 36 ? `--${toTailDashed(config.prefix)}${name.slice(1).replace(/\$/g, '-')}` : name
/** CSS right-hand side value, which may be a specially-formatted custom property. */
data = (
// preserve object-like data
isRuleLike ? data
// replace all non-unitless props that are not custom properties with pixel versions
: typeof data === 'number'
? data && !(camelName in unitlessProps) && !(name.charCodeAt(0) === 45)
? String(data) + 'px'
: String(data)
// replace tokens with stringified primitive values
: toTokenizedValue(
toSizingValue(camelName, data == null ? '' : data),
config.prefix,
config.themeMap[camelName]
)
)
currentRule[0].push(`${isAtRuleLike ? `${name} ` : `${toHyphenCase(name)}:`}${data}`)
}
}
}
} | @type {style[keyof style]} Represents the right-side "data" for the property (the rule block, or declaration value). | each | javascript | stitchesjs/stitches | packages/core/src/convert/toCssRules.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/convert/toCssRules.js | MIT |
each = (style) => {
for (name in style) {
/** Whether the current name represents an at-rule. */
const isAtRuleLike = name.charCodeAt(0) === 64
const datas = isAtRuleLike && Array.isArray(style[name]) ? style[name] : [style[name]]
for (data of datas) {
const camelName = toCamelCase(name)
/** Whether the current data represents a nesting rule, which is a plain object whose key is not already a util. */
const isRuleLike = typeof data === 'object' && data && data.toString === toStringOfObject && (!config.utils[camelName] || !selectors.length)
// if the left-hand "name" matches a configured utility
// conditionally transform the current data using the configured utility
if (camelName in config.utils && !isRuleLike) {
const util = config.utils[camelName]
if (util !== lastUtil) {
lastUtil = util
each(util(data))
lastUtil = null
continue
}
}
// otherwise, if the left-hand "name" matches a configured polyfill
// conditionally transform the current data using the polyfill
else if (camelName in toPolyfilledValue) {
const poly = toPolyfilledValue[camelName]
if (poly !== lastPoly) {
lastPoly = poly
each(poly(data))
lastPoly = null
continue
}
}
// if the left-hand "name" matches a configured at-rule
if (isAtRuleLike) {
// transform the current name with the configured media at-rule prelude
name = toResolvedMediaQueryRanges(name.slice(1) in config.media ? '@media ' + config.media[name.slice(1)] : name)
}
if (isRuleLike) {
/** Next conditions, which may include one new condition (if this is an at-rule). */
const nextConditions = isAtRuleLike ? conditions.concat(name) : [...conditions]
/** Next selectors, which may include one new selector (if this is not an at-rule). */
const nextSelections = isAtRuleLike ? [...selectors] : toResolvedSelectors(selectors, name.split(comma))
if (currentRule !== undefined) {
onCssText(toCssString(...currentRule))
}
currentRule = undefined
walk(data, nextSelections, nextConditions)
} else {
if (currentRule === undefined) currentRule = [[], selectors, conditions]
/** CSS left-hand side value, which may be a specially-formatted custom property. */
name = !isAtRuleLike && name.charCodeAt(0) === 36 ? `--${toTailDashed(config.prefix)}${name.slice(1).replace(/\$/g, '-')}` : name
/** CSS right-hand side value, which may be a specially-formatted custom property. */
data = (
// preserve object-like data
isRuleLike ? data
// replace all non-unitless props that are not custom properties with pixel versions
: typeof data === 'number'
? data && !(camelName in unitlessProps) && !(name.charCodeAt(0) === 45)
? String(data) + 'px'
: String(data)
// replace tokens with stringified primitive values
: toTokenizedValue(
toSizingValue(camelName, data == null ? '' : data),
config.prefix,
config.themeMap[camelName]
)
)
currentRule[0].push(`${isAtRuleLike ? `${name} ` : `${toHyphenCase(name)}:`}${data}`)
}
}
}
} | @type {style[keyof style]} Represents the right-side "data" for the property (the rule block, or declaration value). | each | javascript | stitchesjs/stitches | packages/core/src/convert/toCssRules.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/convert/toCssRules.js | MIT |
toCssString = (declarations, selectors, conditions) => (
`${conditions.map((condition) => `${condition}{`).join('')}${selectors.length ? `${selectors.join(',')}{` : ''}${declarations.join(';')}${selectors.length ? `}` : ''}${Array(conditions.length ? conditions.length + 1 : 0).join('}')}`
) | CSS right-hand side value, which may be a specially-formatted custom property. | toCssString | javascript | stitchesjs/stitches | packages/core/src/convert/toCssRules.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/convert/toCssRules.js | MIT |
toCssString = (declarations, selectors, conditions) => (
`${conditions.map((condition) => `${condition}{`).join('')}${selectors.length ? `${selectors.join(',')}{` : ''}${declarations.join(';')}${selectors.length ? `}` : ''}${Array(conditions.length ? conditions.length + 1 : 0).join('}')}`
) | CSS right-hand side value, which may be a specially-formatted custom property. | toCssString | javascript | stitchesjs/stitches | packages/core/src/convert/toCssRules.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/convert/toCssRules.js | MIT |
toHyphenCase = (/** @type {string} */ value) => (
// ignore kebab-like values
value.includes('-')
? value
// replace any upper-case letter with a dash and the lower-case variant
: value.replace(/[A-Z]/g, (capital) => '-' + capital.toLowerCase())
) | Returns the given value converted to kebab-case. | toHyphenCase | javascript | stitchesjs/stitches | packages/core/src/convert/toHyphenCase.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/convert/toHyphenCase.js | MIT |
toHyphenCase = (/** @type {string} */ value) => (
// ignore kebab-like values
value.includes('-')
? value
// replace any upper-case letter with a dash and the lower-case variant
: value.replace(/[A-Z]/g, (capital) => '-' + capital.toLowerCase())
) | Returns the given value converted to kebab-case. | toHyphenCase | javascript | stitchesjs/stitches | packages/core/src/convert/toHyphenCase.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/convert/toHyphenCase.js | MIT |
toResolvedMediaQueryRanges = (
/** @type {string} */
media
) => media.replace(
/\(\s*([\w-]+)\s*(=|<|<=|>|>=)\s*([\w-]+)\s*(?:(<|<=|>|>=)\s*([\w-]+)\s*)?\)/g,
(
__,
/** @type {string} 1st param, either the name or value in the query. */
p1,
/** @type {string} 1st operator. */
o1,
/** @type {string} 2nd param, either the name or value in the query. */
p2,
/** @type {string} Optional 2nd operator. */
o2,
/** @type {string} Optional 3rd param, always a value in the query.*/
p3
) => {
/** Whether the first param is a value. */
const isP1Value = mqunit.test(p1)
/** Numeric shift applied to a value when an operator is `<` or `>`. */
const shift = 0.0625 * (isP1Value ? -1 : 1)
const [name, value] = isP1Value ? [p2, p1] : [p1, p2]
return (
'(' +
(
o1[0] === '=' ? '' : (o1[0] === '>' === isP1Value ? 'max-' : 'min-')
) + name + ':' +
(o1[0] !== '=' && o1.length === 1 ? value.replace(mqunit, (_, v, u) => Number(v) + shift * (o1 === '>' ? 1 : -1) + u) : value) +
(
o2
? ') and (' + (
(o2[0] === '>' ? 'min-' : 'max-') + name + ':' +
(o2.length === 1 ? p3.replace(mqunit, (_, v, u) => Number(v) + shift * (o2 === '>' ? -1 : 1) + u) : p3)
)
: ''
) +
')'
)
}
) | Returns a media query with polyfilled ranges. | toResolvedMediaQueryRanges | javascript | stitchesjs/stitches | packages/core/src/convert/toResolvedMediaQueryRanges.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/convert/toResolvedMediaQueryRanges.js | MIT |
toResolvedMediaQueryRanges = (
/** @type {string} */
media
) => media.replace(
/\(\s*([\w-]+)\s*(=|<|<=|>|>=)\s*([\w-]+)\s*(?:(<|<=|>|>=)\s*([\w-]+)\s*)?\)/g,
(
__,
/** @type {string} 1st param, either the name or value in the query. */
p1,
/** @type {string} 1st operator. */
o1,
/** @type {string} 2nd param, either the name or value in the query. */
p2,
/** @type {string} Optional 2nd operator. */
o2,
/** @type {string} Optional 3rd param, always a value in the query.*/
p3
) => {
/** Whether the first param is a value. */
const isP1Value = mqunit.test(p1)
/** Numeric shift applied to a value when an operator is `<` or `>`. */
const shift = 0.0625 * (isP1Value ? -1 : 1)
const [name, value] = isP1Value ? [p2, p1] : [p1, p2]
return (
'(' +
(
o1[0] === '=' ? '' : (o1[0] === '>' === isP1Value ? 'max-' : 'min-')
) + name + ':' +
(o1[0] !== '=' && o1.length === 1 ? value.replace(mqunit, (_, v, u) => Number(v) + shift * (o1 === '>' ? 1 : -1) + u) : value) +
(
o2
? ') and (' + (
(o2[0] === '>' ? 'min-' : 'max-') + name + ':' +
(o2.length === 1 ? p3.replace(mqunit, (_, v, u) => Number(v) + shift * (o2 === '>' ? -1 : 1) + u) : p3)
)
: ''
) +
')'
)
}
) | Returns a media query with polyfilled ranges. | toResolvedMediaQueryRanges | javascript | stitchesjs/stitches | packages/core/src/convert/toResolvedMediaQueryRanges.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/convert/toResolvedMediaQueryRanges.js | MIT |
toResolvedSelectors = (
/** @type {string[]} Parent selectors (e.g. `["a", "button"]`). */
parentSelectors,
/** @type {string[]} Nested selectors (e.g. `["&:hover", "&:focus"]`). */
nestedSelectors,
) => (
parentSelectors.length
? parentSelectors.reduce(
(resolvedSelectors, parentSelector) => {
resolvedSelectors.push(
...nestedSelectors.map(
(selector) => (
selector.includes('&') ? selector.replace(
/&/g,
/[ +>|~]/.test(parentSelector) && /&.*&/.test(selector)
? `:is(${parentSelector})`
: parentSelector
) : parentSelector + ' ' + selector
)
)
)
return resolvedSelectors
},
[]
)
: nestedSelectors
) | Returns selectors resolved from parent selectors and nested selectors. | toResolvedSelectors | javascript | stitchesjs/stitches | packages/core/src/convert/toResolvedSelectors.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/convert/toResolvedSelectors.js | MIT |
toResolvedSelectors = (
/** @type {string[]} Parent selectors (e.g. `["a", "button"]`). */
parentSelectors,
/** @type {string[]} Nested selectors (e.g. `["&:hover", "&:focus"]`). */
nestedSelectors,
) => (
parentSelectors.length
? parentSelectors.reduce(
(resolvedSelectors, parentSelector) => {
resolvedSelectors.push(
...nestedSelectors.map(
(selector) => (
selector.includes('&') ? selector.replace(
/&/g,
/[ +>|~]/.test(parentSelector) && /&.*&/.test(selector)
? `:is(${parentSelector})`
: parentSelector
) : parentSelector + ' ' + selector
)
)
)
return resolvedSelectors
},
[]
)
: nestedSelectors
) | Returns selectors resolved from parent selectors and nested selectors. | toResolvedSelectors | javascript | stitchesjs/stitches | packages/core/src/convert/toResolvedSelectors.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/convert/toResolvedSelectors.js | MIT |
toSizingValue = (/** @type {string} */ declarationName, /** @type {string} */ declarationValue) => (
declarationName in sizeProps && typeof declarationValue === 'string'
? declarationValue.replace(
/^((?:[^]*[^\w-])?)(fit-content|stretch)((?:[^\w-][^]*)?)$/,
(data, lead, main, tail) => (
lead + (
main === 'stretch'
? `-moz-available${tail};${toHyphenCase(declarationName)}:${lead}-webkit-fill-available`
: `-moz-fit-content${tail};${toHyphenCase(declarationName)}:${lead}fit-content`
) + tail
),
)
: String(declarationValue)
) | Returns a declaration sizing value with polyfilled sizing keywords. | toSizingValue | javascript | stitchesjs/stitches | packages/core/src/convert/toSizingValue.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/convert/toSizingValue.js | MIT |
toSizingValue = (/** @type {string} */ declarationName, /** @type {string} */ declarationValue) => (
declarationName in sizeProps && typeof declarationValue === 'string'
? declarationValue.replace(
/^((?:[^]*[^\w-])?)(fit-content|stretch)((?:[^\w-][^]*)?)$/,
(data, lead, main, tail) => (
lead + (
main === 'stretch'
? `-moz-available${tail};${toHyphenCase(declarationName)}:${lead}-webkit-fill-available`
: `-moz-fit-content${tail};${toHyphenCase(declarationName)}:${lead}fit-content`
) + tail
),
)
: String(declarationValue)
) | Returns a declaration sizing value with polyfilled sizing keywords. | toSizingValue | javascript | stitchesjs/stitches | packages/core/src/convert/toSizingValue.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/convert/toSizingValue.js | MIT |
toTokenizedValue = (
/** @type {string} */
value,
/** @type {string} */
prefix,
/** @type {string} */
scale,
) => value.replace(
/([+-])?((?:\d+(?:\.\d*)?|\.\d+)(?:[Ee][+-]?\d+)?)?(\$|--)([$\w-]+)/g,
($0, direction, multiplier, separator, token) => (
separator == "$" == !!multiplier
? $0
: (
direction || separator == '--'
? 'calc('
: ''
) + (
'var(--' + (
separator === '$'
? toTailDashed(prefix) + (
!token.includes('$')
? toTailDashed(scale)
: ''
) + token.replace(/\$/g, '-')
: token
) + ')' + (
direction || separator == '--'
? '*' + (
direction || ''
) + (
multiplier || '1'
) + ')'
: ''
)
)
),
) | Returns a declaration value with transformed token values. | toTokenizedValue | javascript | stitchesjs/stitches | packages/core/src/convert/toTokenizedValue.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/convert/toTokenizedValue.js | MIT |
toTokenizedValue = (
/** @type {string} */
value,
/** @type {string} */
prefix,
/** @type {string} */
scale,
) => value.replace(
/([+-])?((?:\d+(?:\.\d*)?|\.\d+)(?:[Ee][+-]?\d+)?)?(\$|--)([$\w-]+)/g,
($0, direction, multiplier, separator, token) => (
separator == "$" == !!multiplier
? $0
: (
direction || separator == '--'
? 'calc('
: ''
) + (
'var(--' + (
separator === '$'
? toTailDashed(prefix) + (
!token.includes('$')
? toTailDashed(scale)
: ''
) + token.replace(/\$/g, '-')
: token
) + ')' + (
direction || separator == '--'
? '*' + (
direction || ''
) + (
multiplier || '1'
) + ')'
: ''
)
)
),
) | Returns a declaration value with transformed token values. | toTokenizedValue | javascript | stitchesjs/stitches | packages/core/src/convert/toTokenizedValue.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/convert/toTokenizedValue.js | MIT |
createCreateThemeFunction = (
config,
sheet
) => (
createCreateThemeFunctionMap(config, () => (className, style) => {
// theme is the first argument if it is an object, otherwise the second argument as an object
style = typeof className === 'object' && className || Object(style)
// class name is the first argument if it is a string, otherwise an empty string
className = typeof className === 'string' ? className : ''
/** @type {string} Theme name. @see `{CONFIG_PREFIX}t-{THEME_UUID}` */
className = className || `${toTailDashed(config.prefix)}t-${toHash(style)}`
const selector = `.${className}`
const themeObject = {}
const cssProps = []
for (const scale in style) {
themeObject[scale] = {}
for (const token in style[scale]) {
const propertyName = `--${toTailDashed(config.prefix)}${scale}-${token}`
const propertyValue = toTokenizedValue(String(style[scale][token]), config.prefix, scale)
themeObject[scale][token] = new ThemeToken(token, propertyValue, scale, config.prefix)
cssProps.push(`${propertyName}:${propertyValue}`)
}
}
const render = () => {
if (cssProps.length && !sheet.rules.themed.cache.has(className)) {
sheet.rules.themed.cache.add(className)
const rootPrelude = style === config.theme ? ':root,' : ''
const cssText = `${rootPrelude}.${className}{${cssProps.join(';')}}`
sheet.rules.themed.apply(cssText)
}
return className
}
return {
...themeObject,
get className() {
return render()
},
selector,
toString: render,
}
})
) | Returns a function that applies a theme and returns tokens of that theme. | createCreateThemeFunction | javascript | stitchesjs/stitches | packages/core/src/features/createTheme.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/features/createTheme.js | MIT |
createCreateThemeFunction = (
config,
sheet
) => (
createCreateThemeFunctionMap(config, () => (className, style) => {
// theme is the first argument if it is an object, otherwise the second argument as an object
style = typeof className === 'object' && className || Object(style)
// class name is the first argument if it is a string, otherwise an empty string
className = typeof className === 'string' ? className : ''
/** @type {string} Theme name. @see `{CONFIG_PREFIX}t-{THEME_UUID}` */
className = className || `${toTailDashed(config.prefix)}t-${toHash(style)}`
const selector = `.${className}`
const themeObject = {}
const cssProps = []
for (const scale in style) {
themeObject[scale] = {}
for (const token in style[scale]) {
const propertyName = `--${toTailDashed(config.prefix)}${scale}-${token}`
const propertyValue = toTokenizedValue(String(style[scale][token]), config.prefix, scale)
themeObject[scale][token] = new ThemeToken(token, propertyValue, scale, config.prefix)
cssProps.push(`${propertyName}:${propertyValue}`)
}
}
const render = () => {
if (cssProps.length && !sheet.rules.themed.cache.has(className)) {
sheet.rules.themed.cache.add(className)
const rootPrelude = style === config.theme ? ':root,' : ''
const cssText = `${rootPrelude}.${className}{${cssProps.join(';')}}`
sheet.rules.themed.apply(cssText)
}
return className
}
return {
...themeObject,
get className() {
return render()
},
selector,
toString: render,
}
})
) | Returns a function that applies a theme and returns tokens of that theme. | createCreateThemeFunction | javascript | stitchesjs/stitches | packages/core/src/features/createTheme.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/features/createTheme.js | MIT |
createCssFunction = (config, sheet) =>
createCssFunctionMap(config, () => {
const _css = (args, componentConfig = {}) => {
let internals = {
type: null,
composers: new Set(),
}
for (const arg of args) {
// skip any void argument
if (arg == null) continue
// conditionally extend the component
if (arg[internal]) {
if (internals.type == null) internals.type = arg[internal].type
for (const composer of arg[internal].composers) {
internals.composers.add(composer)
}
}
// otherwise, conditionally define the component type
else if (arg.constructor !== Object || arg.$$typeof) {
if (internals.type == null) internals.type = arg
}
// otherwise, add a new composer to this component
else {
internals.composers.add(createComposer(arg, config, componentConfig))
}
}
// set the component type if none was set
if (internals.type == null) internals.type = 'span'
if (!internals.composers.size) internals.composers.add(['PJLV', {}, [], [], {}, []])
return createRenderer(config, internals, sheet, componentConfig)
}
const css = (...args) => _css(args)
css.withConfig = (componentConfig) => (...args) => _css(args, componentConfig)
return css
}) | Returns a function that applies component styles. | createCssFunction | javascript | stitchesjs/stitches | packages/core/src/features/css.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/features/css.js | MIT |
createCssFunction = (config, sheet) =>
createCssFunctionMap(config, () => {
const _css = (args, componentConfig = {}) => {
let internals = {
type: null,
composers: new Set(),
}
for (const arg of args) {
// skip any void argument
if (arg == null) continue
// conditionally extend the component
if (arg[internal]) {
if (internals.type == null) internals.type = arg[internal].type
for (const composer of arg[internal].composers) {
internals.composers.add(composer)
}
}
// otherwise, conditionally define the component type
else if (arg.constructor !== Object || arg.$$typeof) {
if (internals.type == null) internals.type = arg
}
// otherwise, add a new composer to this component
else {
internals.composers.add(createComposer(arg, config, componentConfig))
}
}
// set the component type if none was set
if (internals.type == null) internals.type = 'span'
if (!internals.composers.size) internals.composers.add(['PJLV', {}, [], [], {}, []])
return createRenderer(config, internals, sheet, componentConfig)
}
const css = (...args) => _css(args)
css.withConfig = (componentConfig) => (...args) => _css(args, componentConfig)
return css
}) | Returns a function that applies component styles. | createCssFunction | javascript | stitchesjs/stitches | packages/core/src/features/css.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/features/css.js | MIT |
_css = (args, componentConfig = {}) => {
let internals = {
type: null,
composers: new Set(),
}
for (const arg of args) {
// skip any void argument
if (arg == null) continue
// conditionally extend the component
if (arg[internal]) {
if (internals.type == null) internals.type = arg[internal].type
for (const composer of arg[internal].composers) {
internals.composers.add(composer)
}
}
// otherwise, conditionally define the component type
else if (arg.constructor !== Object || arg.$$typeof) {
if (internals.type == null) internals.type = arg
}
// otherwise, add a new composer to this component
else {
internals.composers.add(createComposer(arg, config, componentConfig))
}
}
// set the component type if none was set
if (internals.type == null) internals.type = 'span'
if (!internals.composers.size) internals.composers.add(['PJLV', {}, [], [], {}, []])
return createRenderer(config, internals, sheet, componentConfig)
} | Returns a function that applies component styles. | _css | javascript | stitchesjs/stitches | packages/core/src/features/css.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/features/css.js | MIT |
_css = (args, componentConfig = {}) => {
let internals = {
type: null,
composers: new Set(),
}
for (const arg of args) {
// skip any void argument
if (arg == null) continue
// conditionally extend the component
if (arg[internal]) {
if (internals.type == null) internals.type = arg[internal].type
for (const composer of arg[internal].composers) {
internals.composers.add(composer)
}
}
// otherwise, conditionally define the component type
else if (arg.constructor !== Object || arg.$$typeof) {
if (internals.type == null) internals.type = arg
}
// otherwise, add a new composer to this component
else {
internals.composers.add(createComposer(arg, config, componentConfig))
}
}
// set the component type if none was set
if (internals.type == null) internals.type = 'span'
if (!internals.composers.size) internals.composers.add(['PJLV', {}, [], [], {}, []])
return createRenderer(config, internals, sheet, componentConfig)
} | Returns a function that applies component styles. | _css | javascript | stitchesjs/stitches | packages/core/src/features/css.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/features/css.js | MIT |
createRenderer = (config, internals, sheet, { shouldForwardStitchesProp }) => {
const [
baseClassName,
baseClassNames,
prefilledVariants,
undefinedVariants
] = getPreparedDataFromComposers(internals.composers)
const deferredInjector = typeof internals.type === 'function' || !!internals.type.$$typeof ? createRulesInjectionDeferrer(sheet) : null
const injectionTarget = (deferredInjector || sheet).rules
const selector = `.${baseClassName}${baseClassNames.length > 1 ? `:where(.${baseClassNames.slice(1).join('.')})` : ``}`
const render = (props) => {
props = typeof props === 'object' && props || empty
// 1. we cannot mutate `props`
// 2. we delete variant props
// 3. we delete `css` prop
// therefore: we must create a new props & css variables
const { ...forwardProps } = props
const variantProps = {}
for (const name in prefilledVariants) {
if (name in props) {
if (!shouldForwardStitchesProp?.(name)) delete forwardProps[name]
let data = props[name]
if (typeof data === 'object' && data) {
variantProps[name] = {
'@initial': prefilledVariants[name],
...data,
}
} else {
data = String(data)
variantProps[name] = (
data === 'undefined' && !undefinedVariants.has(name)
? prefilledVariants[name]
: data
)
}
} else {
variantProps[name] = prefilledVariants[name]
}
}
const classSet = new Set([ ...baseClassNames ])
// 1. builds up the variants (fills in defaults, calculates @initial on responsive, etc.)
// 2. iterates composers
// 2.1. add their base class
// 2.2. iterate their variants, add their variant classes
// 2.2.1. orders regular variants before responsive variants
// 2.3. iterate their compound variants, add their compound variant classes
for (const [composerBaseClass, composerBaseStyle, singularVariants, compoundVariants] of internals.composers) {
if (!sheet.rules.styled.cache.has(composerBaseClass)) {
sheet.rules.styled.cache.add(composerBaseClass)
toCssRules(composerBaseStyle, [`.${composerBaseClass}`], [], config, (cssText) => {
injectionTarget.styled.apply(cssText)
})
}
const singularVariantsToAdd = getTargetVariantsToAdd(singularVariants, variantProps, config.media)
const compoundVariantsToAdd = getTargetVariantsToAdd(compoundVariants, variantProps, config.media, true)
for (const variantToAdd of singularVariantsToAdd) {
if (variantToAdd === undefined) continue
for (const [vClass, vStyle, isResponsive] of variantToAdd) {
const variantClassName = `${composerBaseClass}-${toHash(vStyle)}-${vClass}`
classSet.add(variantClassName)
const groupCache = (isResponsive ? sheet.rules.resonevar : sheet.rules.onevar ).cache
/*
* make sure that normal variants are injected before responsive ones
* @see {@link https://github.com/stitchesjs/stitches/issues/737|github}
*/
const targetInjectionGroup = isResponsive ? injectionTarget.resonevar : injectionTarget.onevar
if (!groupCache.has(variantClassName)) {
groupCache.add(variantClassName)
toCssRules(vStyle, [`.${variantClassName}`], [], config, (cssText) => {
targetInjectionGroup.apply(cssText)
})
}
}
}
for (const variantToAdd of compoundVariantsToAdd) {
if (variantToAdd === undefined) continue
for (const [vClass, vStyle] of variantToAdd) {
const variantClassName = `${composerBaseClass}-${toHash(vStyle)}-${vClass}`
classSet.add(variantClassName)
if (!sheet.rules.allvar.cache.has(variantClassName)) {
sheet.rules.allvar.cache.add(variantClassName)
toCssRules(vStyle, [`.${variantClassName}`], [], config, (cssText) => {
injectionTarget.allvar.apply(cssText)
})
}
}
}
}
// apply css property styles
const css = forwardProps.css
if (typeof css === 'object' && css) {
if (!shouldForwardStitchesProp?.('css')) delete forwardProps.css
/** @type {string} Inline Class Unique Identifier. @see `{COMPOSER_UUID}-i{VARIANT_UUID}-css` */
const iClass = `${baseClassName}-i${toHash(css)}-css`
classSet.add(iClass)
if (!sheet.rules.inline.cache.has(iClass)) {
sheet.rules.inline.cache.add(iClass)
toCssRules(css, [`.${iClass}`], [], config, (cssText) => {
injectionTarget.inline.apply(cssText)
})
}
}
for (const propClassName of String(props.className || '').trim().split(/\s+/)) {
if (propClassName) classSet.add(propClassName)
}
const renderedClassName = forwardProps.className = [ ...classSet ].join(' ')
const renderedToString = () => renderedClassName
return {
type: internals.type,
className: renderedClassName,
selector,
props: forwardProps,
toString: renderedToString,
deferredInjector,
}
}
const toString = () => {
if (!sheet.rules.styled.cache.has(baseClassName)) render()
return baseClassName
}
return define(render, {
className: baseClassName,
selector,
[internal]: internals,
toString,
})
} | @type {string} Composer Unique Identifier. @see `{CONFIG_PREFIX}-?c-{STYLE_HASH}` | createRenderer | javascript | stitchesjs/stitches | packages/core/src/features/css.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/features/css.js | MIT |
createRenderer = (config, internals, sheet, { shouldForwardStitchesProp }) => {
const [
baseClassName,
baseClassNames,
prefilledVariants,
undefinedVariants
] = getPreparedDataFromComposers(internals.composers)
const deferredInjector = typeof internals.type === 'function' || !!internals.type.$$typeof ? createRulesInjectionDeferrer(sheet) : null
const injectionTarget = (deferredInjector || sheet).rules
const selector = `.${baseClassName}${baseClassNames.length > 1 ? `:where(.${baseClassNames.slice(1).join('.')})` : ``}`
const render = (props) => {
props = typeof props === 'object' && props || empty
// 1. we cannot mutate `props`
// 2. we delete variant props
// 3. we delete `css` prop
// therefore: we must create a new props & css variables
const { ...forwardProps } = props
const variantProps = {}
for (const name in prefilledVariants) {
if (name in props) {
if (!shouldForwardStitchesProp?.(name)) delete forwardProps[name]
let data = props[name]
if (typeof data === 'object' && data) {
variantProps[name] = {
'@initial': prefilledVariants[name],
...data,
}
} else {
data = String(data)
variantProps[name] = (
data === 'undefined' && !undefinedVariants.has(name)
? prefilledVariants[name]
: data
)
}
} else {
variantProps[name] = prefilledVariants[name]
}
}
const classSet = new Set([ ...baseClassNames ])
// 1. builds up the variants (fills in defaults, calculates @initial on responsive, etc.)
// 2. iterates composers
// 2.1. add their base class
// 2.2. iterate their variants, add their variant classes
// 2.2.1. orders regular variants before responsive variants
// 2.3. iterate their compound variants, add their compound variant classes
for (const [composerBaseClass, composerBaseStyle, singularVariants, compoundVariants] of internals.composers) {
if (!sheet.rules.styled.cache.has(composerBaseClass)) {
sheet.rules.styled.cache.add(composerBaseClass)
toCssRules(composerBaseStyle, [`.${composerBaseClass}`], [], config, (cssText) => {
injectionTarget.styled.apply(cssText)
})
}
const singularVariantsToAdd = getTargetVariantsToAdd(singularVariants, variantProps, config.media)
const compoundVariantsToAdd = getTargetVariantsToAdd(compoundVariants, variantProps, config.media, true)
for (const variantToAdd of singularVariantsToAdd) {
if (variantToAdd === undefined) continue
for (const [vClass, vStyle, isResponsive] of variantToAdd) {
const variantClassName = `${composerBaseClass}-${toHash(vStyle)}-${vClass}`
classSet.add(variantClassName)
const groupCache = (isResponsive ? sheet.rules.resonevar : sheet.rules.onevar ).cache
/*
* make sure that normal variants are injected before responsive ones
* @see {@link https://github.com/stitchesjs/stitches/issues/737|github}
*/
const targetInjectionGroup = isResponsive ? injectionTarget.resonevar : injectionTarget.onevar
if (!groupCache.has(variantClassName)) {
groupCache.add(variantClassName)
toCssRules(vStyle, [`.${variantClassName}`], [], config, (cssText) => {
targetInjectionGroup.apply(cssText)
})
}
}
}
for (const variantToAdd of compoundVariantsToAdd) {
if (variantToAdd === undefined) continue
for (const [vClass, vStyle] of variantToAdd) {
const variantClassName = `${composerBaseClass}-${toHash(vStyle)}-${vClass}`
classSet.add(variantClassName)
if (!sheet.rules.allvar.cache.has(variantClassName)) {
sheet.rules.allvar.cache.add(variantClassName)
toCssRules(vStyle, [`.${variantClassName}`], [], config, (cssText) => {
injectionTarget.allvar.apply(cssText)
})
}
}
}
}
// apply css property styles
const css = forwardProps.css
if (typeof css === 'object' && css) {
if (!shouldForwardStitchesProp?.('css')) delete forwardProps.css
/** @type {string} Inline Class Unique Identifier. @see `{COMPOSER_UUID}-i{VARIANT_UUID}-css` */
const iClass = `${baseClassName}-i${toHash(css)}-css`
classSet.add(iClass)
if (!sheet.rules.inline.cache.has(iClass)) {
sheet.rules.inline.cache.add(iClass)
toCssRules(css, [`.${iClass}`], [], config, (cssText) => {
injectionTarget.inline.apply(cssText)
})
}
}
for (const propClassName of String(props.className || '').trim().split(/\s+/)) {
if (propClassName) classSet.add(propClassName)
}
const renderedClassName = forwardProps.className = [ ...classSet ].join(' ')
const renderedToString = () => renderedClassName
return {
type: internals.type,
className: renderedClassName,
selector,
props: forwardProps,
toString: renderedToString,
deferredInjector,
}
}
const toString = () => {
if (!sheet.rules.styled.cache.has(baseClassName)) render()
return baseClassName
}
return define(render, {
className: baseClassName,
selector,
[internal]: internals,
toString,
})
} | @type {string} Composer Unique Identifier. @see `{CONFIG_PREFIX}-?c-{STYLE_HASH}` | createRenderer | javascript | stitchesjs/stitches | packages/core/src/features/css.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/features/css.js | MIT |
render = (props) => {
props = typeof props === 'object' && props || empty
// 1. we cannot mutate `props`
// 2. we delete variant props
// 3. we delete `css` prop
// therefore: we must create a new props & css variables
const { ...forwardProps } = props
const variantProps = {}
for (const name in prefilledVariants) {
if (name in props) {
if (!shouldForwardStitchesProp?.(name)) delete forwardProps[name]
let data = props[name]
if (typeof data === 'object' && data) {
variantProps[name] = {
'@initial': prefilledVariants[name],
...data,
}
} else {
data = String(data)
variantProps[name] = (
data === 'undefined' && !undefinedVariants.has(name)
? prefilledVariants[name]
: data
)
}
} else {
variantProps[name] = prefilledVariants[name]
}
}
const classSet = new Set([ ...baseClassNames ])
// 1. builds up the variants (fills in defaults, calculates @initial on responsive, etc.)
// 2. iterates composers
// 2.1. add their base class
// 2.2. iterate their variants, add their variant classes
// 2.2.1. orders regular variants before responsive variants
// 2.3. iterate their compound variants, add their compound variant classes
for (const [composerBaseClass, composerBaseStyle, singularVariants, compoundVariants] of internals.composers) {
if (!sheet.rules.styled.cache.has(composerBaseClass)) {
sheet.rules.styled.cache.add(composerBaseClass)
toCssRules(composerBaseStyle, [`.${composerBaseClass}`], [], config, (cssText) => {
injectionTarget.styled.apply(cssText)
})
}
const singularVariantsToAdd = getTargetVariantsToAdd(singularVariants, variantProps, config.media)
const compoundVariantsToAdd = getTargetVariantsToAdd(compoundVariants, variantProps, config.media, true)
for (const variantToAdd of singularVariantsToAdd) {
if (variantToAdd === undefined) continue
for (const [vClass, vStyle, isResponsive] of variantToAdd) {
const variantClassName = `${composerBaseClass}-${toHash(vStyle)}-${vClass}`
classSet.add(variantClassName)
const groupCache = (isResponsive ? sheet.rules.resonevar : sheet.rules.onevar ).cache
/*
* make sure that normal variants are injected before responsive ones
* @see {@link https://github.com/stitchesjs/stitches/issues/737|github}
*/
const targetInjectionGroup = isResponsive ? injectionTarget.resonevar : injectionTarget.onevar
if (!groupCache.has(variantClassName)) {
groupCache.add(variantClassName)
toCssRules(vStyle, [`.${variantClassName}`], [], config, (cssText) => {
targetInjectionGroup.apply(cssText)
})
}
}
}
for (const variantToAdd of compoundVariantsToAdd) {
if (variantToAdd === undefined) continue
for (const [vClass, vStyle] of variantToAdd) {
const variantClassName = `${composerBaseClass}-${toHash(vStyle)}-${vClass}`
classSet.add(variantClassName)
if (!sheet.rules.allvar.cache.has(variantClassName)) {
sheet.rules.allvar.cache.add(variantClassName)
toCssRules(vStyle, [`.${variantClassName}`], [], config, (cssText) => {
injectionTarget.allvar.apply(cssText)
})
}
}
}
}
// apply css property styles
const css = forwardProps.css
if (typeof css === 'object' && css) {
if (!shouldForwardStitchesProp?.('css')) delete forwardProps.css
/** @type {string} Inline Class Unique Identifier. @see `{COMPOSER_UUID}-i{VARIANT_UUID}-css` */
const iClass = `${baseClassName}-i${toHash(css)}-css`
classSet.add(iClass)
if (!sheet.rules.inline.cache.has(iClass)) {
sheet.rules.inline.cache.add(iClass)
toCssRules(css, [`.${iClass}`], [], config, (cssText) => {
injectionTarget.inline.apply(cssText)
})
}
}
for (const propClassName of String(props.className || '').trim().split(/\s+/)) {
if (propClassName) classSet.add(propClassName)
}
const renderedClassName = forwardProps.className = [ ...classSet ].join(' ')
const renderedToString = () => renderedClassName
return {
type: internals.type,
className: renderedClassName,
selector,
props: forwardProps,
toString: renderedToString,
deferredInjector,
}
} | @type {string} Composer Unique Identifier. @see `{CONFIG_PREFIX}-?c-{STYLE_HASH}` | render | javascript | stitchesjs/stitches | packages/core/src/features/css.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/features/css.js | MIT |
render = (props) => {
props = typeof props === 'object' && props || empty
// 1. we cannot mutate `props`
// 2. we delete variant props
// 3. we delete `css` prop
// therefore: we must create a new props & css variables
const { ...forwardProps } = props
const variantProps = {}
for (const name in prefilledVariants) {
if (name in props) {
if (!shouldForwardStitchesProp?.(name)) delete forwardProps[name]
let data = props[name]
if (typeof data === 'object' && data) {
variantProps[name] = {
'@initial': prefilledVariants[name],
...data,
}
} else {
data = String(data)
variantProps[name] = (
data === 'undefined' && !undefinedVariants.has(name)
? prefilledVariants[name]
: data
)
}
} else {
variantProps[name] = prefilledVariants[name]
}
}
const classSet = new Set([ ...baseClassNames ])
// 1. builds up the variants (fills in defaults, calculates @initial on responsive, etc.)
// 2. iterates composers
// 2.1. add their base class
// 2.2. iterate their variants, add their variant classes
// 2.2.1. orders regular variants before responsive variants
// 2.3. iterate their compound variants, add their compound variant classes
for (const [composerBaseClass, composerBaseStyle, singularVariants, compoundVariants] of internals.composers) {
if (!sheet.rules.styled.cache.has(composerBaseClass)) {
sheet.rules.styled.cache.add(composerBaseClass)
toCssRules(composerBaseStyle, [`.${composerBaseClass}`], [], config, (cssText) => {
injectionTarget.styled.apply(cssText)
})
}
const singularVariantsToAdd = getTargetVariantsToAdd(singularVariants, variantProps, config.media)
const compoundVariantsToAdd = getTargetVariantsToAdd(compoundVariants, variantProps, config.media, true)
for (const variantToAdd of singularVariantsToAdd) {
if (variantToAdd === undefined) continue
for (const [vClass, vStyle, isResponsive] of variantToAdd) {
const variantClassName = `${composerBaseClass}-${toHash(vStyle)}-${vClass}`
classSet.add(variantClassName)
const groupCache = (isResponsive ? sheet.rules.resonevar : sheet.rules.onevar ).cache
/*
* make sure that normal variants are injected before responsive ones
* @see {@link https://github.com/stitchesjs/stitches/issues/737|github}
*/
const targetInjectionGroup = isResponsive ? injectionTarget.resonevar : injectionTarget.onevar
if (!groupCache.has(variantClassName)) {
groupCache.add(variantClassName)
toCssRules(vStyle, [`.${variantClassName}`], [], config, (cssText) => {
targetInjectionGroup.apply(cssText)
})
}
}
}
for (const variantToAdd of compoundVariantsToAdd) {
if (variantToAdd === undefined) continue
for (const [vClass, vStyle] of variantToAdd) {
const variantClassName = `${composerBaseClass}-${toHash(vStyle)}-${vClass}`
classSet.add(variantClassName)
if (!sheet.rules.allvar.cache.has(variantClassName)) {
sheet.rules.allvar.cache.add(variantClassName)
toCssRules(vStyle, [`.${variantClassName}`], [], config, (cssText) => {
injectionTarget.allvar.apply(cssText)
})
}
}
}
}
// apply css property styles
const css = forwardProps.css
if (typeof css === 'object' && css) {
if (!shouldForwardStitchesProp?.('css')) delete forwardProps.css
/** @type {string} Inline Class Unique Identifier. @see `{COMPOSER_UUID}-i{VARIANT_UUID}-css` */
const iClass = `${baseClassName}-i${toHash(css)}-css`
classSet.add(iClass)
if (!sheet.rules.inline.cache.has(iClass)) {
sheet.rules.inline.cache.add(iClass)
toCssRules(css, [`.${iClass}`], [], config, (cssText) => {
injectionTarget.inline.apply(cssText)
})
}
}
for (const propClassName of String(props.className || '').trim().split(/\s+/)) {
if (propClassName) classSet.add(propClassName)
}
const renderedClassName = forwardProps.className = [ ...classSet ].join(' ')
const renderedToString = () => renderedClassName
return {
type: internals.type,
className: renderedClassName,
selector,
props: forwardProps,
toString: renderedToString,
deferredInjector,
}
} | @type {string} Composer Unique Identifier. @see `{CONFIG_PREFIX}-?c-{STYLE_HASH}` | render | javascript | stitchesjs/stitches | packages/core/src/features/css.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/features/css.js | MIT |
toString = () => {
if (!sheet.rules.styled.cache.has(baseClassName)) render()
return baseClassName
} | @type {string} Inline Class Unique Identifier. @see `{COMPOSER_UUID}-i{VARIANT_UUID}-css` | toString | javascript | stitchesjs/stitches | packages/core/src/features/css.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/features/css.js | MIT |
toString = () => {
if (!sheet.rules.styled.cache.has(baseClassName)) render()
return baseClassName
} | @type {string} Inline Class Unique Identifier. @see `{COMPOSER_UUID}-i{VARIANT_UUID}-css` | toString | javascript | stitchesjs/stitches | packages/core/src/features/css.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/features/css.js | MIT |
getPreparedDataFromComposers = (composers) => {
/** Class name of the first composer. */
let baseClassName = ''
/** @type {string[]} Combined class names for all composers. */
const baseClassNames = []
/** @type {PrefilledVariants} Combined variant pairings for all composers. */
const combinedPrefilledVariants = {}
/** @type {UndefinedVariants} List of variant names that can have an "undefined" pairing. */
const combinedUndefinedVariants = []
for (const [className, , , , prefilledVariants, undefinedVariants] of composers) {
if (baseClassName === '') baseClassName = className
baseClassNames.push(className)
combinedUndefinedVariants.push(...undefinedVariants)
for (const name in prefilledVariants) {
const data = prefilledVariants[name]
if (combinedPrefilledVariants[name] === undefined || data !== 'undefined' || undefinedVariants.includes(data)) combinedPrefilledVariants[name] = data
}
}
const preparedData = [
baseClassName,
baseClassNames,
combinedPrefilledVariants,
new Set(combinedUndefinedVariants)
]
return preparedData
} | Returns useful data that can be known before rendering. | getPreparedDataFromComposers | javascript | stitchesjs/stitches | packages/core/src/features/css.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/features/css.js | MIT |
getPreparedDataFromComposers = (composers) => {
/** Class name of the first composer. */
let baseClassName = ''
/** @type {string[]} Combined class names for all composers. */
const baseClassNames = []
/** @type {PrefilledVariants} Combined variant pairings for all composers. */
const combinedPrefilledVariants = {}
/** @type {UndefinedVariants} List of variant names that can have an "undefined" pairing. */
const combinedUndefinedVariants = []
for (const [className, , , , prefilledVariants, undefinedVariants] of composers) {
if (baseClassName === '') baseClassName = className
baseClassNames.push(className)
combinedUndefinedVariants.push(...undefinedVariants)
for (const name in prefilledVariants) {
const data = prefilledVariants[name]
if (combinedPrefilledVariants[name] === undefined || data !== 'undefined' || undefinedVariants.includes(data)) combinedPrefilledVariants[name] = data
}
}
const preparedData = [
baseClassName,
baseClassNames,
combinedPrefilledVariants,
new Set(combinedUndefinedVariants)
]
return preparedData
} | Returns useful data that can be known before rendering. | getPreparedDataFromComposers | javascript | stitchesjs/stitches | packages/core/src/features/css.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/features/css.js | MIT |
getTargetVariantsToAdd = (
targetVariants,
variantProps,
media,
isCompoundVariant,
) => {
const targetVariantsToAdd = []
targetVariants: for (let [vMatch, vStyle, vEmpty] of targetVariants) {
// skip empty variants
if (vEmpty) continue
/** Position the variant should be inserted into. */
let vOrder = 0
let vName
let isResponsive = false
for (vName in vMatch) {
const vPair = vMatch[vName]
let pPair = variantProps[vName]
// exact matches
if (pPair === vPair) continue
// responsive matches
else if (typeof pPair === 'object' && pPair) {
/** @type {boolean} Whether the responsive variant is matched. */
let didMatch
let qOrder = 0
// media queries matching the same variant
let matchedQueries
for (const query in pPair) {
if (vPair === String(pPair[query])) {
if (query !== '@initial') {
// check if the cleanQuery is in the media config and then we push the resulting media query to the matchedQueries array,
// if not, we remove the @media from the beginning and push it to the matched queries which then will be resolved a few lines down
// when we finish working on this variant and want wrap the vStyles with the matchedQueries
const cleanQuery = query.slice(1);
(matchedQueries = matchedQueries || []).push(cleanQuery in media ? media[cleanQuery] : query.replace(/^@media ?/, ''))
isResponsive = true
}
vOrder += qOrder
didMatch = true
}
++qOrder
}
if (matchedQueries && matchedQueries.length) {
vStyle = {
['@media ' + matchedQueries.join(', ')]: vStyle,
}
}
if (!didMatch) continue targetVariants
}
// non-matches
else continue targetVariants
}
(targetVariantsToAdd[vOrder] = targetVariantsToAdd[vOrder] || []).push([isCompoundVariant ? `cv` : `${vName}-${vMatch[vName]}`, vStyle, isResponsive])
}
return targetVariantsToAdd
} | @type {UndefinedVariants} List of variant names that can have an "undefined" pairing. | getTargetVariantsToAdd | javascript | stitchesjs/stitches | packages/core/src/features/css.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/features/css.js | MIT |
getTargetVariantsToAdd = (
targetVariants,
variantProps,
media,
isCompoundVariant,
) => {
const targetVariantsToAdd = []
targetVariants: for (let [vMatch, vStyle, vEmpty] of targetVariants) {
// skip empty variants
if (vEmpty) continue
/** Position the variant should be inserted into. */
let vOrder = 0
let vName
let isResponsive = false
for (vName in vMatch) {
const vPair = vMatch[vName]
let pPair = variantProps[vName]
// exact matches
if (pPair === vPair) continue
// responsive matches
else if (typeof pPair === 'object' && pPair) {
/** @type {boolean} Whether the responsive variant is matched. */
let didMatch
let qOrder = 0
// media queries matching the same variant
let matchedQueries
for (const query in pPair) {
if (vPair === String(pPair[query])) {
if (query !== '@initial') {
// check if the cleanQuery is in the media config and then we push the resulting media query to the matchedQueries array,
// if not, we remove the @media from the beginning and push it to the matched queries which then will be resolved a few lines down
// when we finish working on this variant and want wrap the vStyles with the matchedQueries
const cleanQuery = query.slice(1);
(matchedQueries = matchedQueries || []).push(cleanQuery in media ? media[cleanQuery] : query.replace(/^@media ?/, ''))
isResponsive = true
}
vOrder += qOrder
didMatch = true
}
++qOrder
}
if (matchedQueries && matchedQueries.length) {
vStyle = {
['@media ' + matchedQueries.join(', ')]: vStyle,
}
}
if (!didMatch) continue targetVariants
}
// non-matches
else continue targetVariants
}
(targetVariantsToAdd[vOrder] = targetVariantsToAdd[vOrder] || []).push([isCompoundVariant ? `cv` : `${vName}-${vMatch[vName]}`, vStyle, isResponsive])
}
return targetVariantsToAdd
} | @type {UndefinedVariants} List of variant names that can have an "undefined" pairing. | getTargetVariantsToAdd | javascript | stitchesjs/stitches | packages/core/src/features/css.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/features/css.js | MIT |
createGlobalCssFunction = (
config,
sheet
) => createGlobalCssFunctionMap(config, () => (
...styles
) => {
const render = () => {
for (let style of styles) {
style = typeof style === 'object' && style || {}
let uuid = toHash(style)
if (!sheet.rules.global.cache.has(uuid)) {
sheet.rules.global.cache.add(uuid)
// support @import rules
if ('@import' in style) {
let importIndex = [].indexOf.call(sheet.sheet.cssRules, sheet.rules.themed.group) - 1
// wrap import in quotes as a convenience
for (
let importValue of /** @type {string[]} */ ([].concat(style['@import']))
) {
importValue = importValue.includes('"') || importValue.includes("'") ? importValue : `"${importValue}"`
sheet.sheet.insertRule(`@import ${importValue};`, importIndex++)
}
delete style['@import']
}
toCssRules(style, [], [], config, (cssText) => {
sheet.rules.global.apply(cssText)
})
}
}
return ''
}
return define(render, {
toString: render,
})
}) | Returns a function that applies global styles. | createGlobalCssFunction | javascript | stitchesjs/stitches | packages/core/src/features/globalCss.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/features/globalCss.js | MIT |
createGlobalCssFunction = (
config,
sheet
) => createGlobalCssFunctionMap(config, () => (
...styles
) => {
const render = () => {
for (let style of styles) {
style = typeof style === 'object' && style || {}
let uuid = toHash(style)
if (!sheet.rules.global.cache.has(uuid)) {
sheet.rules.global.cache.add(uuid)
// support @import rules
if ('@import' in style) {
let importIndex = [].indexOf.call(sheet.sheet.cssRules, sheet.rules.themed.group) - 1
// wrap import in quotes as a convenience
for (
let importValue of /** @type {string[]} */ ([].concat(style['@import']))
) {
importValue = importValue.includes('"') || importValue.includes("'") ? importValue : `"${importValue}"`
sheet.sheet.insertRule(`@import ${importValue};`, importIndex++)
}
delete style['@import']
}
toCssRules(style, [], [], config, (cssText) => {
sheet.rules.global.apply(cssText)
})
}
}
return ''
}
return define(render, {
toString: render,
})
}) | Returns a function that applies global styles. | createGlobalCssFunction | javascript | stitchesjs/stitches | packages/core/src/features/globalCss.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/features/globalCss.js | MIT |
render = () => {
for (let style of styles) {
style = typeof style === 'object' && style || {}
let uuid = toHash(style)
if (!sheet.rules.global.cache.has(uuid)) {
sheet.rules.global.cache.add(uuid)
// support @import rules
if ('@import' in style) {
let importIndex = [].indexOf.call(sheet.sheet.cssRules, sheet.rules.themed.group) - 1
// wrap import in quotes as a convenience
for (
let importValue of /** @type {string[]} */ ([].concat(style['@import']))
) {
importValue = importValue.includes('"') || importValue.includes("'") ? importValue : `"${importValue}"`
sheet.sheet.insertRule(`@import ${importValue};`, importIndex++)
}
delete style['@import']
}
toCssRules(style, [], [], config, (cssText) => {
sheet.rules.global.apply(cssText)
})
}
}
return ''
} | Returns a function that applies global styles. | render | javascript | stitchesjs/stitches | packages/core/src/features/globalCss.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/features/globalCss.js | MIT |
render = () => {
for (let style of styles) {
style = typeof style === 'object' && style || {}
let uuid = toHash(style)
if (!sheet.rules.global.cache.has(uuid)) {
sheet.rules.global.cache.add(uuid)
// support @import rules
if ('@import' in style) {
let importIndex = [].indexOf.call(sheet.sheet.cssRules, sheet.rules.themed.group) - 1
// wrap import in quotes as a convenience
for (
let importValue of /** @type {string[]} */ ([].concat(style['@import']))
) {
importValue = importValue.includes('"') || importValue.includes("'") ? importValue : `"${importValue}"`
sheet.sheet.insertRule(`@import ${importValue};`, importIndex++)
}
delete style['@import']
}
toCssRules(style, [], [], config, (cssText) => {
sheet.rules.global.apply(cssText)
})
}
}
return ''
} | Returns a function that applies global styles. | render | javascript | stitchesjs/stitches | packages/core/src/features/globalCss.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/features/globalCss.js | MIT |
createKeyframesFunction = (/** @type {Config} */ config, /** @type {GroupSheet} */ sheet) => (
createKeyframesFunctionMap(config, () => (style) => {
/** @type {string} Keyframes Unique Identifier. @see `{CONFIG_PREFIX}-?k-{KEYFRAME_UUID}` */
const name = `${toTailDashed(config.prefix)}k-${toHash(style)}`
const render = () => {
if (!sheet.rules.global.cache.has(name)) {
sheet.rules.global.cache.add(name)
const cssRules = []
toCssRules(style, [], [], config, (cssText) => cssRules.push(cssText))
const cssText = `@keyframes ${name}{${cssRules.join('')}}`
sheet.rules.global.apply(cssText)
}
return name
}
return define(render, {
get name() {
return render()
},
toString: render,
})
})
) | Returns a function that applies a keyframes rule. | createKeyframesFunction | javascript | stitchesjs/stitches | packages/core/src/features/keyframes.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/features/keyframes.js | MIT |
createKeyframesFunction = (/** @type {Config} */ config, /** @type {GroupSheet} */ sheet) => (
createKeyframesFunctionMap(config, () => (style) => {
/** @type {string} Keyframes Unique Identifier. @see `{CONFIG_PREFIX}-?k-{KEYFRAME_UUID}` */
const name = `${toTailDashed(config.prefix)}k-${toHash(style)}`
const render = () => {
if (!sheet.rules.global.cache.has(name)) {
sheet.rules.global.cache.add(name)
const cssRules = []
toCssRules(style, [], [], config, (cssText) => cssRules.push(cssText))
const cssText = `@keyframes ${name}{${cssRules.join('')}}`
sheet.rules.global.apply(cssText)
}
return name
}
return define(render, {
get name() {
return render()
},
toString: render,
})
})
) | Returns a function that applies a keyframes rule. | createKeyframesFunction | javascript | stitchesjs/stitches | packages/core/src/features/keyframes.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/features/keyframes.js | MIT |
render = () => {
if (!sheet.rules.global.cache.has(name)) {
sheet.rules.global.cache.add(name)
const cssRules = []
toCssRules(style, [], [], config, (cssText) => cssRules.push(cssText))
const cssText = `@keyframes ${name}{${cssRules.join('')}}`
sheet.rules.global.apply(cssText)
}
return name
} | @type {string} Keyframes Unique Identifier. @see `{CONFIG_PREFIX}-?k-{KEYFRAME_UUID}` | render | javascript | stitchesjs/stitches | packages/core/src/features/keyframes.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/features/keyframes.js | MIT |
render = () => {
if (!sheet.rules.global.cache.has(name)) {
sheet.rules.global.cache.add(name)
const cssRules = []
toCssRules(style, [], [], config, (cssText) => cssRules.push(cssText))
const cssText = `@keyframes ${name}{${cssRules.join('')}}`
sheet.rules.global.apply(cssText)
}
return name
} | @type {string} Keyframes Unique Identifier. @see `{CONFIG_PREFIX}-?k-{KEYFRAME_UUID}` | render | javascript | stitchesjs/stitches | packages/core/src/features/keyframes.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/features/keyframes.js | MIT |
get name() {
return render()
} | @type {string} Keyframes Unique Identifier. @see `{CONFIG_PREFIX}-?k-{KEYFRAME_UUID}` | name | javascript | stitchesjs/stitches | packages/core/src/features/keyframes.js | https://github.com/stitchesjs/stitches/blob/master/packages/core/src/features/keyframes.js | MIT |
createStyledFunction = ({ config, sheet }) =>
createCssFunctionMap(config, () => {
const cssFunction = createCssFunction(config, sheet)
const _styled = (args, css = cssFunction, { displayName, shouldForwardStitchesProp } = {}) => {
const cssComponent = css(...args)
const DefaultType = cssComponent[internal].type
const shouldForwardAs = shouldForwardStitchesProp?.('as')
const styledComponent = React.forwardRef((props, ref) => {
const Type = props?.as && !shouldForwardAs ? props?.as : DefaultType
const { props: forwardProps, deferredInjector } = cssComponent(props)
if (!shouldForwardAs) {
delete forwardProps.as
}
forwardProps.ref = ref
if (deferredInjector) {
return React.createElement(React.Fragment, null, React.createElement(Type, forwardProps), React.createElement(deferredInjector, null))
}
return React.createElement(Type, forwardProps)
})
const toString = () => cssComponent.selector
styledComponent.className = cssComponent.className
styledComponent.displayName = displayName || `Styled.${DefaultType.displayName || DefaultType.name || DefaultType}`
styledComponent.selector = cssComponent.selector
styledComponent.toString = toString
styledComponent[internal] = cssComponent[internal]
return styledComponent
}
const styled = (...args) => _styled(args)
styled.withConfig = (componentConfig) => (...args) => {
const cssWithConfig = cssFunction.withConfig(componentConfig)
return _styled(args, cssWithConfig, componentConfig)
}
return styled
}) | Returns a function that applies component styles. | createStyledFunction | javascript | stitchesjs/stitches | packages/react/src/features/styled.js | https://github.com/stitchesjs/stitches/blob/master/packages/react/src/features/styled.js | MIT |
createStyledFunction = ({ config, sheet }) =>
createCssFunctionMap(config, () => {
const cssFunction = createCssFunction(config, sheet)
const _styled = (args, css = cssFunction, { displayName, shouldForwardStitchesProp } = {}) => {
const cssComponent = css(...args)
const DefaultType = cssComponent[internal].type
const shouldForwardAs = shouldForwardStitchesProp?.('as')
const styledComponent = React.forwardRef((props, ref) => {
const Type = props?.as && !shouldForwardAs ? props?.as : DefaultType
const { props: forwardProps, deferredInjector } = cssComponent(props)
if (!shouldForwardAs) {
delete forwardProps.as
}
forwardProps.ref = ref
if (deferredInjector) {
return React.createElement(React.Fragment, null, React.createElement(Type, forwardProps), React.createElement(deferredInjector, null))
}
return React.createElement(Type, forwardProps)
})
const toString = () => cssComponent.selector
styledComponent.className = cssComponent.className
styledComponent.displayName = displayName || `Styled.${DefaultType.displayName || DefaultType.name || DefaultType}`
styledComponent.selector = cssComponent.selector
styledComponent.toString = toString
styledComponent[internal] = cssComponent[internal]
return styledComponent
}
const styled = (...args) => _styled(args)
styled.withConfig = (componentConfig) => (...args) => {
const cssWithConfig = cssFunction.withConfig(componentConfig)
return _styled(args, cssWithConfig, componentConfig)
}
return styled
}) | Returns a function that applies component styles. | createStyledFunction | javascript | stitchesjs/stitches | packages/react/src/features/styled.js | https://github.com/stitchesjs/stitches/blob/master/packages/react/src/features/styled.js | MIT |
_styled = (args, css = cssFunction, { displayName, shouldForwardStitchesProp } = {}) => {
const cssComponent = css(...args)
const DefaultType = cssComponent[internal].type
const shouldForwardAs = shouldForwardStitchesProp?.('as')
const styledComponent = React.forwardRef((props, ref) => {
const Type = props?.as && !shouldForwardAs ? props?.as : DefaultType
const { props: forwardProps, deferredInjector } = cssComponent(props)
if (!shouldForwardAs) {
delete forwardProps.as
}
forwardProps.ref = ref
if (deferredInjector) {
return React.createElement(React.Fragment, null, React.createElement(Type, forwardProps), React.createElement(deferredInjector, null))
}
return React.createElement(Type, forwardProps)
})
const toString = () => cssComponent.selector
styledComponent.className = cssComponent.className
styledComponent.displayName = displayName || `Styled.${DefaultType.displayName || DefaultType.name || DefaultType}`
styledComponent.selector = cssComponent.selector
styledComponent.toString = toString
styledComponent[internal] = cssComponent[internal]
return styledComponent
} | Returns a function that applies component styles. | _styled | javascript | stitchesjs/stitches | packages/react/src/features/styled.js | https://github.com/stitchesjs/stitches/blob/master/packages/react/src/features/styled.js | MIT |
_styled = (args, css = cssFunction, { displayName, shouldForwardStitchesProp } = {}) => {
const cssComponent = css(...args)
const DefaultType = cssComponent[internal].type
const shouldForwardAs = shouldForwardStitchesProp?.('as')
const styledComponent = React.forwardRef((props, ref) => {
const Type = props?.as && !shouldForwardAs ? props?.as : DefaultType
const { props: forwardProps, deferredInjector } = cssComponent(props)
if (!shouldForwardAs) {
delete forwardProps.as
}
forwardProps.ref = ref
if (deferredInjector) {
return React.createElement(React.Fragment, null, React.createElement(Type, forwardProps), React.createElement(deferredInjector, null))
}
return React.createElement(Type, forwardProps)
})
const toString = () => cssComponent.selector
styledComponent.className = cssComponent.className
styledComponent.displayName = displayName || `Styled.${DefaultType.displayName || DefaultType.name || DefaultType}`
styledComponent.selector = cssComponent.selector
styledComponent.toString = toString
styledComponent[internal] = cssComponent[internal]
return styledComponent
} | Returns a function that applies component styles. | _styled | javascript | stitchesjs/stitches | packages/react/src/features/styled.js | https://github.com/stitchesjs/stitches/blob/master/packages/react/src/features/styled.js | MIT |
getResolvedSelectors = (
/** @type {string[]} Parent selectors (e.g. `["a", "button"]`). */
parentSelectors,
/** @type {string[]} Nested selectors (e.g. `["&:hover", "&:focus"]`). */
nestedSelectors,
) => (
parentSelectors.reduce(
(resolvedSelectors, parentSelector) => {
resolvedSelectors.push(
...nestedSelectors.map(
(selector) => (
selector.includes('&') ? selector.replace(
/&/g,
/[ +>|~]/.test(parentSelector) && /&.*&/.test(selector)
? `:is(${parentSelector})`
: parentSelector
) : parentSelector + ' ' + selector
)
)
)
return resolvedSelectors
},
[]
)
) | Returns selectors resolved from parent selectors and nested selectors. | getResolvedSelectors | javascript | stitchesjs/stitches | packages/stringify/src/getResolvedSelectors.js | https://github.com/stitchesjs/stitches/blob/master/packages/stringify/src/getResolvedSelectors.js | MIT |
getResolvedSelectors = (
/** @type {string[]} Parent selectors (e.g. `["a", "button"]`). */
parentSelectors,
/** @type {string[]} Nested selectors (e.g. `["&:hover", "&:focus"]`). */
nestedSelectors,
) => (
parentSelectors.reduce(
(resolvedSelectors, parentSelector) => {
resolvedSelectors.push(
...nestedSelectors.map(
(selector) => (
selector.includes('&') ? selector.replace(
/&/g,
/[ +>|~]/.test(parentSelector) && /&.*&/.test(selector)
? `:is(${parentSelector})`
: parentSelector
) : parentSelector + ' ' + selector
)
)
)
return resolvedSelectors
},
[]
)
) | Returns selectors resolved from parent selectors and nested selectors. | getResolvedSelectors | javascript | stitchesjs/stitches | packages/stringify/src/getResolvedSelectors.js | https://github.com/stitchesjs/stitches/blob/master/packages/stringify/src/getResolvedSelectors.js | MIT |
stringify = (
/** Object representing the current CSS. */
value,
/** Replacer function. */
replacer = undefined,
) => {
/** Set used to manage the opened and closed state of rules. */
const used = new WeakSet()
const parse = (style, selectors, conditions, prevName, prevData) => {
let cssText = ''
each: for (const name in style) {
const isAtRuleLike = name.charCodeAt(0) === 64
for (const data of isAtRuleLike && isArray(style[name]) ? style[name] : [style[name]]) {
if (replacer && (name !== prevName || data !== prevData)) {
const next = replacer(name, data, style)
if (next !== null) {
cssText += typeof next === 'object' && next ? parse(next, selectors, conditions, name, data) : next == null ? '' : next
continue each
}
}
const isObjectLike = typeof data === 'object' && data && data.toString === toString
if (isObjectLike) {
if (used.has(selectors)) {
used.delete(selectors)
cssText += '}'
}
const usedName = Object(name)
const nextSelectors = isAtRuleLike ? selectors : selectors.length ? getResolvedSelectors(selectors, name.split(comma)) : name.split(comma)
cssText += parse(data, nextSelectors, isAtRuleLike ? conditions.concat(usedName) : conditions)
if (used.has(usedName)) {
used.delete(usedName)
cssText += '}'
}
if (used.has(nextSelectors)) {
used.delete(nextSelectors)
cssText += '}'
}
} else {
for (let i = 0; i < conditions.length; ++i) {
if (!used.has(conditions[i])) {
used.add(conditions[i])
cssText += conditions[i] + '{'
}
}
if (selectors.length && !used.has(selectors)) {
used.add(selectors)
cssText += selectors + '{'
}
cssText += (isAtRuleLike ? name + ' ' : toKebabCase(name) + ':') + String(data) + ';'
}
}
}
return cssText
}
return parse(value, [], [])
} | Returns a string of CSS from an object of CSS. | stringify | javascript | stitchesjs/stitches | packages/stringify/src/index.js | https://github.com/stitchesjs/stitches/blob/master/packages/stringify/src/index.js | MIT |
stringify = (
/** Object representing the current CSS. */
value,
/** Replacer function. */
replacer = undefined,
) => {
/** Set used to manage the opened and closed state of rules. */
const used = new WeakSet()
const parse = (style, selectors, conditions, prevName, prevData) => {
let cssText = ''
each: for (const name in style) {
const isAtRuleLike = name.charCodeAt(0) === 64
for (const data of isAtRuleLike && isArray(style[name]) ? style[name] : [style[name]]) {
if (replacer && (name !== prevName || data !== prevData)) {
const next = replacer(name, data, style)
if (next !== null) {
cssText += typeof next === 'object' && next ? parse(next, selectors, conditions, name, data) : next == null ? '' : next
continue each
}
}
const isObjectLike = typeof data === 'object' && data && data.toString === toString
if (isObjectLike) {
if (used.has(selectors)) {
used.delete(selectors)
cssText += '}'
}
const usedName = Object(name)
const nextSelectors = isAtRuleLike ? selectors : selectors.length ? getResolvedSelectors(selectors, name.split(comma)) : name.split(comma)
cssText += parse(data, nextSelectors, isAtRuleLike ? conditions.concat(usedName) : conditions)
if (used.has(usedName)) {
used.delete(usedName)
cssText += '}'
}
if (used.has(nextSelectors)) {
used.delete(nextSelectors)
cssText += '}'
}
} else {
for (let i = 0; i < conditions.length; ++i) {
if (!used.has(conditions[i])) {
used.add(conditions[i])
cssText += conditions[i] + '{'
}
}
if (selectors.length && !used.has(selectors)) {
used.add(selectors)
cssText += selectors + '{'
}
cssText += (isAtRuleLike ? name + ' ' : toKebabCase(name) + ':') + String(data) + ';'
}
}
}
return cssText
}
return parse(value, [], [])
} | Returns a string of CSS from an object of CSS. | stringify | javascript | stitchesjs/stitches | packages/stringify/src/index.js | https://github.com/stitchesjs/stitches/blob/master/packages/stringify/src/index.js | MIT |
parse = (style, selectors, conditions, prevName, prevData) => {
let cssText = ''
each: for (const name in style) {
const isAtRuleLike = name.charCodeAt(0) === 64
for (const data of isAtRuleLike && isArray(style[name]) ? style[name] : [style[name]]) {
if (replacer && (name !== prevName || data !== prevData)) {
const next = replacer(name, data, style)
if (next !== null) {
cssText += typeof next === 'object' && next ? parse(next, selectors, conditions, name, data) : next == null ? '' : next
continue each
}
}
const isObjectLike = typeof data === 'object' && data && data.toString === toString
if (isObjectLike) {
if (used.has(selectors)) {
used.delete(selectors)
cssText += '}'
}
const usedName = Object(name)
const nextSelectors = isAtRuleLike ? selectors : selectors.length ? getResolvedSelectors(selectors, name.split(comma)) : name.split(comma)
cssText += parse(data, nextSelectors, isAtRuleLike ? conditions.concat(usedName) : conditions)
if (used.has(usedName)) {
used.delete(usedName)
cssText += '}'
}
if (used.has(nextSelectors)) {
used.delete(nextSelectors)
cssText += '}'
}
} else {
for (let i = 0; i < conditions.length; ++i) {
if (!used.has(conditions[i])) {
used.add(conditions[i])
cssText += conditions[i] + '{'
}
}
if (selectors.length && !used.has(selectors)) {
used.add(selectors)
cssText += selectors + '{'
}
cssText += (isAtRuleLike ? name + ' ' : toKebabCase(name) + ':') + String(data) + ';'
}
}
}
return cssText
} | Set used to manage the opened and closed state of rules. | parse | javascript | stitchesjs/stitches | packages/stringify/src/index.js | https://github.com/stitchesjs/stitches/blob/master/packages/stringify/src/index.js | MIT |
parse = (style, selectors, conditions, prevName, prevData) => {
let cssText = ''
each: for (const name in style) {
const isAtRuleLike = name.charCodeAt(0) === 64
for (const data of isAtRuleLike && isArray(style[name]) ? style[name] : [style[name]]) {
if (replacer && (name !== prevName || data !== prevData)) {
const next = replacer(name, data, style)
if (next !== null) {
cssText += typeof next === 'object' && next ? parse(next, selectors, conditions, name, data) : next == null ? '' : next
continue each
}
}
const isObjectLike = typeof data === 'object' && data && data.toString === toString
if (isObjectLike) {
if (used.has(selectors)) {
used.delete(selectors)
cssText += '}'
}
const usedName = Object(name)
const nextSelectors = isAtRuleLike ? selectors : selectors.length ? getResolvedSelectors(selectors, name.split(comma)) : name.split(comma)
cssText += parse(data, nextSelectors, isAtRuleLike ? conditions.concat(usedName) : conditions)
if (used.has(usedName)) {
used.delete(usedName)
cssText += '}'
}
if (used.has(nextSelectors)) {
used.delete(nextSelectors)
cssText += '}'
}
} else {
for (let i = 0; i < conditions.length; ++i) {
if (!used.has(conditions[i])) {
used.add(conditions[i])
cssText += conditions[i] + '{'
}
}
if (selectors.length && !used.has(selectors)) {
used.add(selectors)
cssText += selectors + '{'
}
cssText += (isAtRuleLike ? name + ' ' : toKebabCase(name) + ':') + String(data) + ';'
}
}
}
return cssText
} | Set used to manage the opened and closed state of rules. | parse | javascript | stitchesjs/stitches | packages/stringify/src/index.js | https://github.com/stitchesjs/stitches/blob/master/packages/stringify/src/index.js | MIT |
toKebabCase = (/** @type {string} */ value) => (
// ignore kebab-like values
value.includes('-')
? value
// replace any upper-case letter with a dash and the lower-case variant
: value.replace(/[A-Z]/g, (capital) => '-' + capital.toLowerCase())
) | Returns the given value converted to kebab-case. | toKebabCase | javascript | stitchesjs/stitches | packages/stringify/src/toCase.js | https://github.com/stitchesjs/stitches/blob/master/packages/stringify/src/toCase.js | MIT |
toKebabCase = (/** @type {string} */ value) => (
// ignore kebab-like values
value.includes('-')
? value
// replace any upper-case letter with a dash and the lower-case variant
: value.replace(/[A-Z]/g, (capital) => '-' + capital.toLowerCase())
) | Returns the given value converted to kebab-case. | toKebabCase | javascript | stitchesjs/stitches | packages/stringify/src/toCase.js | https://github.com/stitchesjs/stitches/blob/master/packages/stringify/src/toCase.js | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.