code
stringlengths 28
313k
| docstring
stringlengths 25
85.3k
| func_name
stringlengths 1
74
| language
stringclasses 1
value | repo
stringlengths 5
60
| path
stringlengths 4
172
| url
stringlengths 44
218
| license
stringclasses 7
values |
|---|---|---|---|---|---|---|---|
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
|
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
|
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
|
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
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.