Initial commit
This commit is contained in:
9
node_modules/@tailwindcss/typography/src/index.d.ts
generated
vendored
Normal file
9
node_modules/@tailwindcss/typography/src/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
declare function plugin(options?: Partial<{ className: string; target: 'modern' | 'legacy' }>): {
|
||||
handler: () => void
|
||||
}
|
||||
|
||||
declare namespace plugin {
|
||||
const __isOptionsFunction: true
|
||||
}
|
||||
|
||||
export = plugin
|
140
node_modules/@tailwindcss/typography/src/index.js
generated
vendored
Normal file
140
node_modules/@tailwindcss/typography/src/index.js
generated
vendored
Normal file
@@ -0,0 +1,140 @@
|
||||
const plugin = require('tailwindcss/plugin')
|
||||
const merge = require('lodash.merge')
|
||||
const castArray = require('lodash.castarray')
|
||||
const styles = require('./styles')
|
||||
const { commonTrailingPseudos } = require('./utils')
|
||||
|
||||
const computed = {
|
||||
// Reserved for future "magic properties", for example:
|
||||
// bulletColor: (color) => ({ 'ul > li::before': { backgroundColor: color } }),
|
||||
}
|
||||
|
||||
function inWhere(selector, { className, modifier, prefix }) {
|
||||
let prefixedNot = prefix(`.not-${className}`).slice(1)
|
||||
let selectorPrefix = selector.startsWith('>')
|
||||
? `${modifier === 'DEFAULT' ? `.${className}` : `.${className}-${modifier}`} `
|
||||
: ''
|
||||
|
||||
// Parse the selector, if every component ends in the same pseudo element(s) then move it to the end
|
||||
let [trailingPseudo, rebuiltSelector] = commonTrailingPseudos(selector)
|
||||
|
||||
if (trailingPseudo) {
|
||||
return `:where(${selectorPrefix}${rebuiltSelector}):not(:where([class~="${prefixedNot}"],[class~="${prefixedNot}"] *))${trailingPseudo}`
|
||||
}
|
||||
|
||||
return `:where(${selectorPrefix}${selector}):not(:where([class~="${prefixedNot}"],[class~="${prefixedNot}"] *))`
|
||||
}
|
||||
|
||||
function isObject(value) {
|
||||
return typeof value === 'object' && value !== null
|
||||
}
|
||||
|
||||
function configToCss(config = {}, { target, className, modifier, prefix }) {
|
||||
function updateSelector(k, v) {
|
||||
if (target === 'legacy') {
|
||||
return [k, v]
|
||||
}
|
||||
|
||||
if (Array.isArray(v)) {
|
||||
return [k, v]
|
||||
}
|
||||
|
||||
if (isObject(v)) {
|
||||
let nested = Object.values(v).some(isObject)
|
||||
if (nested) {
|
||||
return [
|
||||
inWhere(k, { className, modifier, prefix }),
|
||||
v,
|
||||
Object.fromEntries(Object.entries(v).map(([k, v]) => updateSelector(k, v))),
|
||||
]
|
||||
}
|
||||
|
||||
return [inWhere(k, { className, modifier, prefix }), v]
|
||||
}
|
||||
|
||||
return [k, v]
|
||||
}
|
||||
|
||||
return Object.fromEntries(
|
||||
Object.entries(
|
||||
merge(
|
||||
{},
|
||||
...Object.keys(config)
|
||||
.filter((key) => computed[key])
|
||||
.map((key) => computed[key](config[key])),
|
||||
...castArray(config.css || {})
|
||||
)
|
||||
).map(([k, v]) => updateSelector(k, v))
|
||||
)
|
||||
}
|
||||
|
||||
module.exports = plugin.withOptions(
|
||||
({ className = 'prose', target = 'modern' } = {}) => {
|
||||
return function ({ addVariant, addComponents, theme, prefix }) {
|
||||
let modifiers = theme('typography')
|
||||
|
||||
let options = { className, prefix }
|
||||
|
||||
for (let [name, ...selectors] of [
|
||||
['headings', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'th'],
|
||||
['h1'],
|
||||
['h2'],
|
||||
['h3'],
|
||||
['h4'],
|
||||
['h5'],
|
||||
['h6'],
|
||||
['p'],
|
||||
['a'],
|
||||
['blockquote'],
|
||||
['figure'],
|
||||
['figcaption'],
|
||||
['strong'],
|
||||
['em'],
|
||||
['kbd'],
|
||||
['code'],
|
||||
['pre'],
|
||||
['ol'],
|
||||
['ul'],
|
||||
['li'],
|
||||
['table'],
|
||||
['thead'],
|
||||
['tr'],
|
||||
['th'],
|
||||
['td'],
|
||||
['img'],
|
||||
['video'],
|
||||
['hr'],
|
||||
['lead', '[class~="lead"]'],
|
||||
]) {
|
||||
selectors = selectors.length === 0 ? [name] : selectors
|
||||
|
||||
let selector =
|
||||
target === 'legacy' ? selectors.map((selector) => `& ${selector}`) : selectors.join(', ')
|
||||
|
||||
addVariant(
|
||||
`${className}-${name}`,
|
||||
target === 'legacy' ? selector : `& :is(${inWhere(selector, options)})`
|
||||
)
|
||||
}
|
||||
|
||||
addComponents(
|
||||
Object.keys(modifiers).map((modifier) => ({
|
||||
[modifier === 'DEFAULT' ? `.${className}` : `.${className}-${modifier}`]: configToCss(
|
||||
modifiers[modifier],
|
||||
{
|
||||
target,
|
||||
className,
|
||||
modifier,
|
||||
prefix,
|
||||
}
|
||||
),
|
||||
}))
|
||||
)
|
||||
}
|
||||
},
|
||||
() => {
|
||||
return {
|
||||
theme: { typography: styles },
|
||||
}
|
||||
}
|
||||
)
|
1423
node_modules/@tailwindcss/typography/src/index.test.js
generated
vendored
Normal file
1423
node_modules/@tailwindcss/typography/src/index.test.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1632
node_modules/@tailwindcss/typography/src/styles.js
generated
vendored
Normal file
1632
node_modules/@tailwindcss/typography/src/styles.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
62
node_modules/@tailwindcss/typography/src/utils.js
generated
vendored
Normal file
62
node_modules/@tailwindcss/typography/src/utils.js
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
const isPlainObject = require('lodash.isplainobject')
|
||||
|
||||
const parser = require('postcss-selector-parser')
|
||||
const parseSelector = parser()
|
||||
|
||||
module.exports = {
|
||||
isUsableColor(color, values) {
|
||||
return isPlainObject(values) && color !== 'gray' && values[600]
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {string} selector
|
||||
*/
|
||||
commonTrailingPseudos(selector) {
|
||||
let ast = parseSelector.astSync(selector)
|
||||
|
||||
/** @type {import('postcss-selector-parser').Pseudo[][]} */
|
||||
let matrix = []
|
||||
|
||||
// Put the pseudo elements in reverse order in a sparse, column-major 2D array
|
||||
for (let [i, sel] of ast.nodes.entries()) {
|
||||
for (const [j, child] of [...sel.nodes].reverse().entries()) {
|
||||
// We only care about pseudo elements
|
||||
if (child.type !== 'pseudo' || !child.value.startsWith('::')) {
|
||||
break
|
||||
}
|
||||
|
||||
matrix[j] = matrix[j] || []
|
||||
matrix[j][i] = child
|
||||
}
|
||||
}
|
||||
|
||||
let trailingPseudos = parser.selector()
|
||||
|
||||
// At this point the pseudo elements are in a column-major 2D array
|
||||
// This means each row contains one "column" of pseudo elements from each selector
|
||||
// We can compare all the pseudo elements in a row to see if they are the same
|
||||
for (const pseudos of matrix) {
|
||||
// It's a sparse 2D array so there are going to be holes in the rows
|
||||
// We skip those
|
||||
if (!pseudos) {
|
||||
continue
|
||||
}
|
||||
|
||||
let values = new Set([...pseudos.map((p) => p.value)])
|
||||
|
||||
// The pseudo elements are not the same
|
||||
if (values.size > 1) {
|
||||
break
|
||||
}
|
||||
|
||||
pseudos.forEach((pseudo) => pseudo.remove())
|
||||
trailingPseudos.prepend(pseudos[0])
|
||||
}
|
||||
|
||||
if (trailingPseudos.nodes.length) {
|
||||
return [trailingPseudos.toString(), ast.toString()]
|
||||
}
|
||||
|
||||
return [null, selector]
|
||||
},
|
||||
}
|
Reference in New Issue
Block a user