Deployed the page to Github Pages.
This commit is contained in:
parent
1d79754e93
commit
2c89899458
62797 changed files with 6551425 additions and 15279 deletions
25
node_modules/postcss/lib/at-rule.js
generated
vendored
Normal file
25
node_modules/postcss/lib/at-rule.js
generated
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
'use strict'
|
||||
|
||||
let Container = require('./container')
|
||||
|
||||
class AtRule extends Container {
|
||||
constructor(defaults) {
|
||||
super(defaults)
|
||||
this.type = 'atrule'
|
||||
}
|
||||
|
||||
append(...children) {
|
||||
if (!this.proxyOf.nodes) this.nodes = []
|
||||
return super.append(...children)
|
||||
}
|
||||
|
||||
prepend(...children) {
|
||||
if (!this.proxyOf.nodes) this.nodes = []
|
||||
return super.prepend(...children)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AtRule
|
||||
AtRule.default = AtRule
|
||||
|
||||
Container.registerAtRule(AtRule)
|
13
node_modules/postcss/lib/comment.js
generated
vendored
Normal file
13
node_modules/postcss/lib/comment.js
generated
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
'use strict'
|
||||
|
||||
let Node = require('./node')
|
||||
|
||||
class Comment extends Node {
|
||||
constructor(defaults) {
|
||||
super(defaults)
|
||||
this.type = 'comment'
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Comment
|
||||
Comment.default = Comment
|
445
node_modules/postcss/lib/container.js
generated
vendored
Normal file
445
node_modules/postcss/lib/container.js
generated
vendored
Normal file
|
@ -0,0 +1,445 @@
|
|||
'use strict'
|
||||
|
||||
let { isClean, my } = require('./symbols')
|
||||
let Declaration = require('./declaration')
|
||||
let Comment = require('./comment')
|
||||
let Node = require('./node')
|
||||
|
||||
let parse, Rule, AtRule, Root
|
||||
|
||||
function cleanSource(nodes) {
|
||||
return nodes.map(i => {
|
||||
if (i.nodes) i.nodes = cleanSource(i.nodes)
|
||||
delete i.source
|
||||
return i
|
||||
})
|
||||
}
|
||||
|
||||
function markTreeDirty(node) {
|
||||
node[isClean] = false
|
||||
if (node.proxyOf.nodes) {
|
||||
for (let i of node.proxyOf.nodes) {
|
||||
markTreeDirty(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Container extends Node {
|
||||
append(...children) {
|
||||
for (let child of children) {
|
||||
let nodes = this.normalize(child, this.last)
|
||||
for (let node of nodes) this.proxyOf.nodes.push(node)
|
||||
}
|
||||
|
||||
this.markDirty()
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
cleanRaws(keepBetween) {
|
||||
super.cleanRaws(keepBetween)
|
||||
if (this.nodes) {
|
||||
for (let node of this.nodes) node.cleanRaws(keepBetween)
|
||||
}
|
||||
}
|
||||
|
||||
each(callback) {
|
||||
if (!this.proxyOf.nodes) return undefined
|
||||
let iterator = this.getIterator()
|
||||
|
||||
let index, result
|
||||
while (this.indexes[iterator] < this.proxyOf.nodes.length) {
|
||||
index = this.indexes[iterator]
|
||||
result = callback(this.proxyOf.nodes[index], index)
|
||||
if (result === false) break
|
||||
|
||||
this.indexes[iterator] += 1
|
||||
}
|
||||
|
||||
delete this.indexes[iterator]
|
||||
return result
|
||||
}
|
||||
|
||||
every(condition) {
|
||||
return this.nodes.every(condition)
|
||||
}
|
||||
|
||||
getIterator() {
|
||||
if (!this.lastEach) this.lastEach = 0
|
||||
if (!this.indexes) this.indexes = {}
|
||||
|
||||
this.lastEach += 1
|
||||
let iterator = this.lastEach
|
||||
this.indexes[iterator] = 0
|
||||
|
||||
return iterator
|
||||
}
|
||||
|
||||
getProxyProcessor() {
|
||||
return {
|
||||
get(node, prop) {
|
||||
if (prop === 'proxyOf') {
|
||||
return node
|
||||
} else if (!node[prop]) {
|
||||
return node[prop]
|
||||
} else if (
|
||||
prop === 'each' ||
|
||||
(typeof prop === 'string' && prop.startsWith('walk'))
|
||||
) {
|
||||
return (...args) => {
|
||||
return node[prop](
|
||||
...args.map(i => {
|
||||
if (typeof i === 'function') {
|
||||
return (child, index) => i(child.toProxy(), index)
|
||||
} else {
|
||||
return i
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
} else if (prop === 'every' || prop === 'some') {
|
||||
return cb => {
|
||||
return node[prop]((child, ...other) =>
|
||||
cb(child.toProxy(), ...other)
|
||||
)
|
||||
}
|
||||
} else if (prop === 'root') {
|
||||
return () => node.root().toProxy()
|
||||
} else if (prop === 'nodes') {
|
||||
return node.nodes.map(i => i.toProxy())
|
||||
} else if (prop === 'first' || prop === 'last') {
|
||||
return node[prop].toProxy()
|
||||
} else {
|
||||
return node[prop]
|
||||
}
|
||||
},
|
||||
|
||||
set(node, prop, value) {
|
||||
if (node[prop] === value) return true
|
||||
node[prop] = value
|
||||
if (prop === 'name' || prop === 'params' || prop === 'selector') {
|
||||
node.markDirty()
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
index(child) {
|
||||
if (typeof child === 'number') return child
|
||||
if (child.proxyOf) child = child.proxyOf
|
||||
return this.proxyOf.nodes.indexOf(child)
|
||||
}
|
||||
|
||||
insertAfter(exist, add) {
|
||||
let existIndex = this.index(exist)
|
||||
let nodes = this.normalize(add, this.proxyOf.nodes[existIndex]).reverse()
|
||||
existIndex = this.index(exist)
|
||||
for (let node of nodes) this.proxyOf.nodes.splice(existIndex + 1, 0, node)
|
||||
|
||||
let index
|
||||
for (let id in this.indexes) {
|
||||
index = this.indexes[id]
|
||||
if (existIndex < index) {
|
||||
this.indexes[id] = index + nodes.length
|
||||
}
|
||||
}
|
||||
|
||||
this.markDirty()
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
insertBefore(exist, add) {
|
||||
let existIndex = this.index(exist)
|
||||
let type = existIndex === 0 ? 'prepend' : false
|
||||
let nodes = this.normalize(
|
||||
add,
|
||||
this.proxyOf.nodes[existIndex],
|
||||
type
|
||||
).reverse()
|
||||
existIndex = this.index(exist)
|
||||
for (let node of nodes) this.proxyOf.nodes.splice(existIndex, 0, node)
|
||||
|
||||
let index
|
||||
for (let id in this.indexes) {
|
||||
index = this.indexes[id]
|
||||
if (existIndex <= index) {
|
||||
this.indexes[id] = index + nodes.length
|
||||
}
|
||||
}
|
||||
|
||||
this.markDirty()
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
normalize(nodes, sample) {
|
||||
if (typeof nodes === 'string') {
|
||||
nodes = cleanSource(parse(nodes).nodes)
|
||||
} else if (typeof nodes === 'undefined') {
|
||||
nodes = []
|
||||
} else if (Array.isArray(nodes)) {
|
||||
nodes = nodes.slice(0)
|
||||
for (let i of nodes) {
|
||||
if (i.parent) i.parent.removeChild(i, 'ignore')
|
||||
}
|
||||
} else if (nodes.type === 'root' && this.type !== 'document') {
|
||||
nodes = nodes.nodes.slice(0)
|
||||
for (let i of nodes) {
|
||||
if (i.parent) i.parent.removeChild(i, 'ignore')
|
||||
}
|
||||
} else if (nodes.type) {
|
||||
nodes = [nodes]
|
||||
} else if (nodes.prop) {
|
||||
if (typeof nodes.value === 'undefined') {
|
||||
throw new Error('Value field is missed in node creation')
|
||||
} else if (typeof nodes.value !== 'string') {
|
||||
nodes.value = String(nodes.value)
|
||||
}
|
||||
nodes = [new Declaration(nodes)]
|
||||
} else if (nodes.selector || nodes.selectors) {
|
||||
nodes = [new Rule(nodes)]
|
||||
} else if (nodes.name) {
|
||||
nodes = [new AtRule(nodes)]
|
||||
} else if (nodes.text) {
|
||||
nodes = [new Comment(nodes)]
|
||||
} else {
|
||||
throw new Error('Unknown node type in node creation')
|
||||
}
|
||||
|
||||
let processed = nodes.map(i => {
|
||||
/* c8 ignore next */
|
||||
if (!i[my]) Container.rebuild(i)
|
||||
i = i.proxyOf
|
||||
if (i.parent) i.parent.removeChild(i)
|
||||
if (i[isClean]) markTreeDirty(i)
|
||||
if (typeof i.raws.before === 'undefined') {
|
||||
if (sample && typeof sample.raws.before !== 'undefined') {
|
||||
i.raws.before = sample.raws.before.replace(/\S/g, '')
|
||||
}
|
||||
}
|
||||
i.parent = this.proxyOf
|
||||
return i
|
||||
})
|
||||
|
||||
return processed
|
||||
}
|
||||
|
||||
prepend(...children) {
|
||||
children = children.reverse()
|
||||
for (let child of children) {
|
||||
let nodes = this.normalize(child, this.first, 'prepend').reverse()
|
||||
for (let node of nodes) this.proxyOf.nodes.unshift(node)
|
||||
for (let id in this.indexes) {
|
||||
this.indexes[id] = this.indexes[id] + nodes.length
|
||||
}
|
||||
}
|
||||
|
||||
this.markDirty()
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
push(child) {
|
||||
child.parent = this
|
||||
this.proxyOf.nodes.push(child)
|
||||
return this
|
||||
}
|
||||
|
||||
removeAll() {
|
||||
for (let node of this.proxyOf.nodes) node.parent = undefined
|
||||
this.proxyOf.nodes = []
|
||||
|
||||
this.markDirty()
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
removeChild(child) {
|
||||
child = this.index(child)
|
||||
this.proxyOf.nodes[child].parent = undefined
|
||||
this.proxyOf.nodes.splice(child, 1)
|
||||
|
||||
let index
|
||||
for (let id in this.indexes) {
|
||||
index = this.indexes[id]
|
||||
if (index >= child) {
|
||||
this.indexes[id] = index - 1
|
||||
}
|
||||
}
|
||||
|
||||
this.markDirty()
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
replaceValues(pattern, opts, callback) {
|
||||
if (!callback) {
|
||||
callback = opts
|
||||
opts = {}
|
||||
}
|
||||
|
||||
this.walkDecls(decl => {
|
||||
if (opts.props && !opts.props.includes(decl.prop)) return
|
||||
if (opts.fast && !decl.value.includes(opts.fast)) return
|
||||
|
||||
decl.value = decl.value.replace(pattern, callback)
|
||||
})
|
||||
|
||||
this.markDirty()
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
some(condition) {
|
||||
return this.nodes.some(condition)
|
||||
}
|
||||
|
||||
walk(callback) {
|
||||
return this.each((child, i) => {
|
||||
let result
|
||||
try {
|
||||
result = callback(child, i)
|
||||
} catch (e) {
|
||||
throw child.addToError(e)
|
||||
}
|
||||
if (result !== false && child.walk) {
|
||||
result = child.walk(callback)
|
||||
}
|
||||
|
||||
return result
|
||||
})
|
||||
}
|
||||
|
||||
walkAtRules(name, callback) {
|
||||
if (!callback) {
|
||||
callback = name
|
||||
return this.walk((child, i) => {
|
||||
if (child.type === 'atrule') {
|
||||
return callback(child, i)
|
||||
}
|
||||
})
|
||||
}
|
||||
if (name instanceof RegExp) {
|
||||
return this.walk((child, i) => {
|
||||
if (child.type === 'atrule' && name.test(child.name)) {
|
||||
return callback(child, i)
|
||||
}
|
||||
})
|
||||
}
|
||||
return this.walk((child, i) => {
|
||||
if (child.type === 'atrule' && child.name === name) {
|
||||
return callback(child, i)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
walkComments(callback) {
|
||||
return this.walk((child, i) => {
|
||||
if (child.type === 'comment') {
|
||||
return callback(child, i)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
walkDecls(prop, callback) {
|
||||
if (!callback) {
|
||||
callback = prop
|
||||
return this.walk((child, i) => {
|
||||
if (child.type === 'decl') {
|
||||
return callback(child, i)
|
||||
}
|
||||
})
|
||||
}
|
||||
if (prop instanceof RegExp) {
|
||||
return this.walk((child, i) => {
|
||||
if (child.type === 'decl' && prop.test(child.prop)) {
|
||||
return callback(child, i)
|
||||
}
|
||||
})
|
||||
}
|
||||
return this.walk((child, i) => {
|
||||
if (child.type === 'decl' && child.prop === prop) {
|
||||
return callback(child, i)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
walkRules(selector, callback) {
|
||||
if (!callback) {
|
||||
callback = selector
|
||||
|
||||
return this.walk((child, i) => {
|
||||
if (child.type === 'rule') {
|
||||
return callback(child, i)
|
||||
}
|
||||
})
|
||||
}
|
||||
if (selector instanceof RegExp) {
|
||||
return this.walk((child, i) => {
|
||||
if (child.type === 'rule' && selector.test(child.selector)) {
|
||||
return callback(child, i)
|
||||
}
|
||||
})
|
||||
}
|
||||
return this.walk((child, i) => {
|
||||
if (child.type === 'rule' && child.selector === selector) {
|
||||
return callback(child, i)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
get first() {
|
||||
if (!this.proxyOf.nodes) return undefined
|
||||
return this.proxyOf.nodes[0]
|
||||
}
|
||||
|
||||
get last() {
|
||||
if (!this.proxyOf.nodes) return undefined
|
||||
return this.proxyOf.nodes[this.proxyOf.nodes.length - 1]
|
||||
}
|
||||
}
|
||||
|
||||
Container.registerParse = dependant => {
|
||||
parse = dependant
|
||||
}
|
||||
|
||||
Container.registerRule = dependant => {
|
||||
Rule = dependant
|
||||
}
|
||||
|
||||
Container.registerAtRule = dependant => {
|
||||
AtRule = dependant
|
||||
}
|
||||
|
||||
Container.registerRoot = dependant => {
|
||||
Root = dependant
|
||||
}
|
||||
|
||||
module.exports = Container
|
||||
Container.default = Container
|
||||
|
||||
/* c8 ignore start */
|
||||
Container.rebuild = node => {
|
||||
if (node.type === 'atrule') {
|
||||
Object.setPrototypeOf(node, AtRule.prototype)
|
||||
} else if (node.type === 'rule') {
|
||||
Object.setPrototypeOf(node, Rule.prototype)
|
||||
} else if (node.type === 'decl') {
|
||||
Object.setPrototypeOf(node, Declaration.prototype)
|
||||
} else if (node.type === 'comment') {
|
||||
Object.setPrototypeOf(node, Comment.prototype)
|
||||
} else if (node.type === 'root') {
|
||||
Object.setPrototypeOf(node, Root.prototype)
|
||||
}
|
||||
|
||||
node[my] = true
|
||||
|
||||
if (node.nodes) {
|
||||
node.nodes.forEach(child => {
|
||||
Container.rebuild(child)
|
||||
})
|
||||
}
|
||||
}
|
||||
/* c8 ignore stop */
|
100
node_modules/postcss/lib/css-syntax-error.js
generated
vendored
Normal file
100
node_modules/postcss/lib/css-syntax-error.js
generated
vendored
Normal file
|
@ -0,0 +1,100 @@
|
|||
'use strict'
|
||||
|
||||
let pico = require('picocolors')
|
||||
|
||||
let terminalHighlight = require('./terminal-highlight')
|
||||
|
||||
class CssSyntaxError extends Error {
|
||||
constructor(message, line, column, source, file, plugin) {
|
||||
super(message)
|
||||
this.name = 'CssSyntaxError'
|
||||
this.reason = message
|
||||
|
||||
if (file) {
|
||||
this.file = file
|
||||
}
|
||||
if (source) {
|
||||
this.source = source
|
||||
}
|
||||
if (plugin) {
|
||||
this.plugin = plugin
|
||||
}
|
||||
if (typeof line !== 'undefined' && typeof column !== 'undefined') {
|
||||
if (typeof line === 'number') {
|
||||
this.line = line
|
||||
this.column = column
|
||||
} else {
|
||||
this.line = line.line
|
||||
this.column = line.column
|
||||
this.endLine = column.line
|
||||
this.endColumn = column.column
|
||||
}
|
||||
}
|
||||
|
||||
this.setMessage()
|
||||
|
||||
if (Error.captureStackTrace) {
|
||||
Error.captureStackTrace(this, CssSyntaxError)
|
||||
}
|
||||
}
|
||||
|
||||
setMessage() {
|
||||
this.message = this.plugin ? this.plugin + ': ' : ''
|
||||
this.message += this.file ? this.file : '<css input>'
|
||||
if (typeof this.line !== 'undefined') {
|
||||
this.message += ':' + this.line + ':' + this.column
|
||||
}
|
||||
this.message += ': ' + this.reason
|
||||
}
|
||||
|
||||
showSourceCode(color) {
|
||||
if (!this.source) return ''
|
||||
|
||||
let css = this.source
|
||||
if (color == null) color = pico.isColorSupported
|
||||
if (terminalHighlight) {
|
||||
if (color) css = terminalHighlight(css)
|
||||
}
|
||||
|
||||
let lines = css.split(/\r?\n/)
|
||||
let start = Math.max(this.line - 3, 0)
|
||||
let end = Math.min(this.line + 2, lines.length)
|
||||
|
||||
let maxWidth = String(end).length
|
||||
|
||||
let mark, aside
|
||||
if (color) {
|
||||
let { bold, gray, red } = pico.createColors(true)
|
||||
mark = text => bold(red(text))
|
||||
aside = text => gray(text)
|
||||
} else {
|
||||
mark = aside = str => str
|
||||
}
|
||||
|
||||
return lines
|
||||
.slice(start, end)
|
||||
.map((line, index) => {
|
||||
let number = start + 1 + index
|
||||
let gutter = ' ' + (' ' + number).slice(-maxWidth) + ' | '
|
||||
if (number === this.line) {
|
||||
let spacing =
|
||||
aside(gutter.replace(/\d/g, ' ')) +
|
||||
line.slice(0, this.column - 1).replace(/[^\t]/g, ' ')
|
||||
return mark('>') + aside(gutter) + line + '\n ' + spacing + mark('^')
|
||||
}
|
||||
return ' ' + aside(gutter) + line
|
||||
})
|
||||
.join('\n')
|
||||
}
|
||||
|
||||
toString() {
|
||||
let code = this.showSourceCode()
|
||||
if (code) {
|
||||
code = '\n\n' + code + '\n'
|
||||
}
|
||||
return this.name + ': ' + this.message + code
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CssSyntaxError
|
||||
CssSyntaxError.default = CssSyntaxError
|
24
node_modules/postcss/lib/declaration.js
generated
vendored
Normal file
24
node_modules/postcss/lib/declaration.js
generated
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
'use strict'
|
||||
|
||||
let Node = require('./node')
|
||||
|
||||
class Declaration extends Node {
|
||||
constructor(defaults) {
|
||||
if (
|
||||
defaults &&
|
||||
typeof defaults.value !== 'undefined' &&
|
||||
typeof defaults.value !== 'string'
|
||||
) {
|
||||
defaults = { ...defaults, value: String(defaults.value) }
|
||||
}
|
||||
super(defaults)
|
||||
this.type = 'decl'
|
||||
}
|
||||
|
||||
get variable() {
|
||||
return this.prop.startsWith('--') || this.prop[0] === '$'
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Declaration
|
||||
Declaration.default = Declaration
|
248
node_modules/postcss/lib/input.js
generated
vendored
Normal file
248
node_modules/postcss/lib/input.js
generated
vendored
Normal file
|
@ -0,0 +1,248 @@
|
|||
'use strict'
|
||||
|
||||
let { SourceMapConsumer, SourceMapGenerator } = require('source-map-js')
|
||||
let { fileURLToPath, pathToFileURL } = require('url')
|
||||
let { isAbsolute, resolve } = require('path')
|
||||
let { nanoid } = require('nanoid/non-secure')
|
||||
|
||||
let terminalHighlight = require('./terminal-highlight')
|
||||
let CssSyntaxError = require('./css-syntax-error')
|
||||
let PreviousMap = require('./previous-map')
|
||||
|
||||
let fromOffsetCache = Symbol('fromOffsetCache')
|
||||
|
||||
let sourceMapAvailable = Boolean(SourceMapConsumer && SourceMapGenerator)
|
||||
let pathAvailable = Boolean(resolve && isAbsolute)
|
||||
|
||||
class Input {
|
||||
constructor(css, opts = {}) {
|
||||
if (
|
||||
css === null ||
|
||||
typeof css === 'undefined' ||
|
||||
(typeof css === 'object' && !css.toString)
|
||||
) {
|
||||
throw new Error(`PostCSS received ${css} instead of CSS string`)
|
||||
}
|
||||
|
||||
this.css = css.toString()
|
||||
|
||||
if (this.css[0] === '\uFEFF' || this.css[0] === '\uFFFE') {
|
||||
this.hasBOM = true
|
||||
this.css = this.css.slice(1)
|
||||
} else {
|
||||
this.hasBOM = false
|
||||
}
|
||||
|
||||
if (opts.from) {
|
||||
if (
|
||||
!pathAvailable ||
|
||||
/^\w+:\/\//.test(opts.from) ||
|
||||
isAbsolute(opts.from)
|
||||
) {
|
||||
this.file = opts.from
|
||||
} else {
|
||||
this.file = resolve(opts.from)
|
||||
}
|
||||
}
|
||||
|
||||
if (pathAvailable && sourceMapAvailable) {
|
||||
let map = new PreviousMap(this.css, opts)
|
||||
if (map.text) {
|
||||
this.map = map
|
||||
let file = map.consumer().file
|
||||
if (!this.file && file) this.file = this.mapResolve(file)
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.file) {
|
||||
this.id = '<input css ' + nanoid(6) + '>'
|
||||
}
|
||||
if (this.map) this.map.file = this.from
|
||||
}
|
||||
|
||||
error(message, line, column, opts = {}) {
|
||||
let result, endLine, endColumn
|
||||
|
||||
if (line && typeof line === 'object') {
|
||||
let start = line
|
||||
let end = column
|
||||
if (typeof start.offset === 'number') {
|
||||
let pos = this.fromOffset(start.offset)
|
||||
line = pos.line
|
||||
column = pos.col
|
||||
} else {
|
||||
line = start.line
|
||||
column = start.column
|
||||
}
|
||||
if (typeof end.offset === 'number') {
|
||||
let pos = this.fromOffset(end.offset)
|
||||
endLine = pos.line
|
||||
endColumn = pos.col
|
||||
} else {
|
||||
endLine = end.line
|
||||
endColumn = end.column
|
||||
}
|
||||
} else if (!column) {
|
||||
let pos = this.fromOffset(line)
|
||||
line = pos.line
|
||||
column = pos.col
|
||||
}
|
||||
|
||||
let origin = this.origin(line, column, endLine, endColumn)
|
||||
if (origin) {
|
||||
result = new CssSyntaxError(
|
||||
message,
|
||||
origin.endLine === undefined
|
||||
? origin.line
|
||||
: { column: origin.column, line: origin.line },
|
||||
origin.endLine === undefined
|
||||
? origin.column
|
||||
: { column: origin.endColumn, line: origin.endLine },
|
||||
origin.source,
|
||||
origin.file,
|
||||
opts.plugin
|
||||
)
|
||||
} else {
|
||||
result = new CssSyntaxError(
|
||||
message,
|
||||
endLine === undefined ? line : { column, line },
|
||||
endLine === undefined ? column : { column: endColumn, line: endLine },
|
||||
this.css,
|
||||
this.file,
|
||||
opts.plugin
|
||||
)
|
||||
}
|
||||
|
||||
result.input = { column, endColumn, endLine, line, source: this.css }
|
||||
if (this.file) {
|
||||
if (pathToFileURL) {
|
||||
result.input.url = pathToFileURL(this.file).toString()
|
||||
}
|
||||
result.input.file = this.file
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
fromOffset(offset) {
|
||||
let lastLine, lineToIndex
|
||||
if (!this[fromOffsetCache]) {
|
||||
let lines = this.css.split('\n')
|
||||
lineToIndex = new Array(lines.length)
|
||||
let prevIndex = 0
|
||||
|
||||
for (let i = 0, l = lines.length; i < l; i++) {
|
||||
lineToIndex[i] = prevIndex
|
||||
prevIndex += lines[i].length + 1
|
||||
}
|
||||
|
||||
this[fromOffsetCache] = lineToIndex
|
||||
} else {
|
||||
lineToIndex = this[fromOffsetCache]
|
||||
}
|
||||
lastLine = lineToIndex[lineToIndex.length - 1]
|
||||
|
||||
let min = 0
|
||||
if (offset >= lastLine) {
|
||||
min = lineToIndex.length - 1
|
||||
} else {
|
||||
let max = lineToIndex.length - 2
|
||||
let mid
|
||||
while (min < max) {
|
||||
mid = min + ((max - min) >> 1)
|
||||
if (offset < lineToIndex[mid]) {
|
||||
max = mid - 1
|
||||
} else if (offset >= lineToIndex[mid + 1]) {
|
||||
min = mid + 1
|
||||
} else {
|
||||
min = mid
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
col: offset - lineToIndex[min] + 1,
|
||||
line: min + 1
|
||||
}
|
||||
}
|
||||
|
||||
mapResolve(file) {
|
||||
if (/^\w+:\/\//.test(file)) {
|
||||
return file
|
||||
}
|
||||
return resolve(this.map.consumer().sourceRoot || this.map.root || '.', file)
|
||||
}
|
||||
|
||||
origin(line, column, endLine, endColumn) {
|
||||
if (!this.map) return false
|
||||
let consumer = this.map.consumer()
|
||||
|
||||
let from = consumer.originalPositionFor({ column, line })
|
||||
if (!from.source) return false
|
||||
|
||||
let to
|
||||
if (typeof endLine === 'number') {
|
||||
to = consumer.originalPositionFor({ column: endColumn, line: endLine })
|
||||
}
|
||||
|
||||
let fromUrl
|
||||
|
||||
if (isAbsolute(from.source)) {
|
||||
fromUrl = pathToFileURL(from.source)
|
||||
} else {
|
||||
fromUrl = new URL(
|
||||
from.source,
|
||||
this.map.consumer().sourceRoot || pathToFileURL(this.map.mapFile)
|
||||
)
|
||||
}
|
||||
|
||||
let result = {
|
||||
column: from.column,
|
||||
endColumn: to && to.column,
|
||||
endLine: to && to.line,
|
||||
line: from.line,
|
||||
url: fromUrl.toString()
|
||||
}
|
||||
|
||||
if (fromUrl.protocol === 'file:') {
|
||||
if (fileURLToPath) {
|
||||
result.file = fileURLToPath(fromUrl)
|
||||
} else {
|
||||
/* c8 ignore next 2 */
|
||||
throw new Error(`file: protocol is not available in this PostCSS build`)
|
||||
}
|
||||
}
|
||||
|
||||
let source = consumer.sourceContentFor(from.source)
|
||||
if (source) result.source = source
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
let json = {}
|
||||
for (let name of ['hasBOM', 'css', 'file', 'id']) {
|
||||
if (this[name] != null) {
|
||||
json[name] = this[name]
|
||||
}
|
||||
}
|
||||
if (this.map) {
|
||||
json.map = { ...this.map }
|
||||
if (json.map.consumerCache) {
|
||||
json.map.consumerCache = undefined
|
||||
}
|
||||
}
|
||||
return json
|
||||
}
|
||||
|
||||
get from() {
|
||||
return this.file || this.id
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Input
|
||||
Input.default = Input
|
||||
|
||||
if (terminalHighlight && terminalHighlight.registerInput) {
|
||||
terminalHighlight.registerInput(Input)
|
||||
}
|
550
node_modules/postcss/lib/lazy-result.js
generated
vendored
Normal file
550
node_modules/postcss/lib/lazy-result.js
generated
vendored
Normal file
|
@ -0,0 +1,550 @@
|
|||
'use strict'
|
||||
|
||||
let { isClean, my } = require('./symbols')
|
||||
let MapGenerator = require('./map-generator')
|
||||
let stringify = require('./stringify')
|
||||
let Container = require('./container')
|
||||
let Document = require('./document')
|
||||
let warnOnce = require('./warn-once')
|
||||
let Result = require('./result')
|
||||
let parse = require('./parse')
|
||||
let Root = require('./root')
|
||||
|
||||
const TYPE_TO_CLASS_NAME = {
|
||||
atrule: 'AtRule',
|
||||
comment: 'Comment',
|
||||
decl: 'Declaration',
|
||||
document: 'Document',
|
||||
root: 'Root',
|
||||
rule: 'Rule'
|
||||
}
|
||||
|
||||
const PLUGIN_PROPS = {
|
||||
AtRule: true,
|
||||
AtRuleExit: true,
|
||||
Comment: true,
|
||||
CommentExit: true,
|
||||
Declaration: true,
|
||||
DeclarationExit: true,
|
||||
Document: true,
|
||||
DocumentExit: true,
|
||||
Once: true,
|
||||
OnceExit: true,
|
||||
postcssPlugin: true,
|
||||
prepare: true,
|
||||
Root: true,
|
||||
RootExit: true,
|
||||
Rule: true,
|
||||
RuleExit: true
|
||||
}
|
||||
|
||||
const NOT_VISITORS = {
|
||||
Once: true,
|
||||
postcssPlugin: true,
|
||||
prepare: true
|
||||
}
|
||||
|
||||
const CHILDREN = 0
|
||||
|
||||
function isPromise(obj) {
|
||||
return typeof obj === 'object' && typeof obj.then === 'function'
|
||||
}
|
||||
|
||||
function getEvents(node) {
|
||||
let key = false
|
||||
let type = TYPE_TO_CLASS_NAME[node.type]
|
||||
if (node.type === 'decl') {
|
||||
key = node.prop.toLowerCase()
|
||||
} else if (node.type === 'atrule') {
|
||||
key = node.name.toLowerCase()
|
||||
}
|
||||
|
||||
if (key && node.append) {
|
||||
return [
|
||||
type,
|
||||
type + '-' + key,
|
||||
CHILDREN,
|
||||
type + 'Exit',
|
||||
type + 'Exit-' + key
|
||||
]
|
||||
} else if (key) {
|
||||
return [type, type + '-' + key, type + 'Exit', type + 'Exit-' + key]
|
||||
} else if (node.append) {
|
||||
return [type, CHILDREN, type + 'Exit']
|
||||
} else {
|
||||
return [type, type + 'Exit']
|
||||
}
|
||||
}
|
||||
|
||||
function toStack(node) {
|
||||
let events
|
||||
if (node.type === 'document') {
|
||||
events = ['Document', CHILDREN, 'DocumentExit']
|
||||
} else if (node.type === 'root') {
|
||||
events = ['Root', CHILDREN, 'RootExit']
|
||||
} else {
|
||||
events = getEvents(node)
|
||||
}
|
||||
|
||||
return {
|
||||
eventIndex: 0,
|
||||
events,
|
||||
iterator: 0,
|
||||
node,
|
||||
visitorIndex: 0,
|
||||
visitors: []
|
||||
}
|
||||
}
|
||||
|
||||
function cleanMarks(node) {
|
||||
node[isClean] = false
|
||||
if (node.nodes) node.nodes.forEach(i => cleanMarks(i))
|
||||
return node
|
||||
}
|
||||
|
||||
let postcss = {}
|
||||
|
||||
class LazyResult {
|
||||
constructor(processor, css, opts) {
|
||||
this.stringified = false
|
||||
this.processed = false
|
||||
|
||||
let root
|
||||
if (
|
||||
typeof css === 'object' &&
|
||||
css !== null &&
|
||||
(css.type === 'root' || css.type === 'document')
|
||||
) {
|
||||
root = cleanMarks(css)
|
||||
} else if (css instanceof LazyResult || css instanceof Result) {
|
||||
root = cleanMarks(css.root)
|
||||
if (css.map) {
|
||||
if (typeof opts.map === 'undefined') opts.map = {}
|
||||
if (!opts.map.inline) opts.map.inline = false
|
||||
opts.map.prev = css.map
|
||||
}
|
||||
} else {
|
||||
let parser = parse
|
||||
if (opts.syntax) parser = opts.syntax.parse
|
||||
if (opts.parser) parser = opts.parser
|
||||
if (parser.parse) parser = parser.parse
|
||||
|
||||
try {
|
||||
root = parser(css, opts)
|
||||
} catch (error) {
|
||||
this.processed = true
|
||||
this.error = error
|
||||
}
|
||||
|
||||
if (root && !root[my]) {
|
||||
/* c8 ignore next 2 */
|
||||
Container.rebuild(root)
|
||||
}
|
||||
}
|
||||
|
||||
this.result = new Result(processor, root, opts)
|
||||
this.helpers = { ...postcss, postcss, result: this.result }
|
||||
this.plugins = this.processor.plugins.map(plugin => {
|
||||
if (typeof plugin === 'object' && plugin.prepare) {
|
||||
return { ...plugin, ...plugin.prepare(this.result) }
|
||||
} else {
|
||||
return plugin
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async() {
|
||||
if (this.error) return Promise.reject(this.error)
|
||||
if (this.processed) return Promise.resolve(this.result)
|
||||
if (!this.processing) {
|
||||
this.processing = this.runAsync()
|
||||
}
|
||||
return this.processing
|
||||
}
|
||||
|
||||
catch(onRejected) {
|
||||
return this.async().catch(onRejected)
|
||||
}
|
||||
|
||||
finally(onFinally) {
|
||||
return this.async().then(onFinally, onFinally)
|
||||
}
|
||||
|
||||
getAsyncError() {
|
||||
throw new Error('Use process(css).then(cb) to work with async plugins')
|
||||
}
|
||||
|
||||
handleError(error, node) {
|
||||
let plugin = this.result.lastPlugin
|
||||
try {
|
||||
if (node) node.addToError(error)
|
||||
this.error = error
|
||||
if (error.name === 'CssSyntaxError' && !error.plugin) {
|
||||
error.plugin = plugin.postcssPlugin
|
||||
error.setMessage()
|
||||
} else if (plugin.postcssVersion) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
let pluginName = plugin.postcssPlugin
|
||||
let pluginVer = plugin.postcssVersion
|
||||
let runtimeVer = this.result.processor.version
|
||||
let a = pluginVer.split('.')
|
||||
let b = runtimeVer.split('.')
|
||||
|
||||
if (a[0] !== b[0] || parseInt(a[1]) > parseInt(b[1])) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(
|
||||
'Unknown error from PostCSS plugin. Your current PostCSS ' +
|
||||
'version is ' +
|
||||
runtimeVer +
|
||||
', but ' +
|
||||
pluginName +
|
||||
' uses ' +
|
||||
pluginVer +
|
||||
'. Perhaps this is the source of the error below.'
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
/* c8 ignore next 3 */
|
||||
// eslint-disable-next-line no-console
|
||||
if (console && console.error) console.error(err)
|
||||
}
|
||||
return error
|
||||
}
|
||||
|
||||
prepareVisitors() {
|
||||
this.listeners = {}
|
||||
let add = (plugin, type, cb) => {
|
||||
if (!this.listeners[type]) this.listeners[type] = []
|
||||
this.listeners[type].push([plugin, cb])
|
||||
}
|
||||
for (let plugin of this.plugins) {
|
||||
if (typeof plugin === 'object') {
|
||||
for (let event in plugin) {
|
||||
if (!PLUGIN_PROPS[event] && /^[A-Z]/.test(event)) {
|
||||
throw new Error(
|
||||
`Unknown event ${event} in ${plugin.postcssPlugin}. ` +
|
||||
`Try to update PostCSS (${this.processor.version} now).`
|
||||
)
|
||||
}
|
||||
if (!NOT_VISITORS[event]) {
|
||||
if (typeof plugin[event] === 'object') {
|
||||
for (let filter in plugin[event]) {
|
||||
if (filter === '*') {
|
||||
add(plugin, event, plugin[event][filter])
|
||||
} else {
|
||||
add(
|
||||
plugin,
|
||||
event + '-' + filter.toLowerCase(),
|
||||
plugin[event][filter]
|
||||
)
|
||||
}
|
||||
}
|
||||
} else if (typeof plugin[event] === 'function') {
|
||||
add(plugin, event, plugin[event])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
this.hasListener = Object.keys(this.listeners).length > 0
|
||||
}
|
||||
|
||||
async runAsync() {
|
||||
this.plugin = 0
|
||||
for (let i = 0; i < this.plugins.length; i++) {
|
||||
let plugin = this.plugins[i]
|
||||
let promise = this.runOnRoot(plugin)
|
||||
if (isPromise(promise)) {
|
||||
try {
|
||||
await promise
|
||||
} catch (error) {
|
||||
throw this.handleError(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.prepareVisitors()
|
||||
if (this.hasListener) {
|
||||
let root = this.result.root
|
||||
while (!root[isClean]) {
|
||||
root[isClean] = true
|
||||
let stack = [toStack(root)]
|
||||
while (stack.length > 0) {
|
||||
let promise = this.visitTick(stack)
|
||||
if (isPromise(promise)) {
|
||||
try {
|
||||
await promise
|
||||
} catch (e) {
|
||||
let node = stack[stack.length - 1].node
|
||||
throw this.handleError(e, node)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.listeners.OnceExit) {
|
||||
for (let [plugin, visitor] of this.listeners.OnceExit) {
|
||||
this.result.lastPlugin = plugin
|
||||
try {
|
||||
if (root.type === 'document') {
|
||||
let roots = root.nodes.map(subRoot =>
|
||||
visitor(subRoot, this.helpers)
|
||||
)
|
||||
|
||||
await Promise.all(roots)
|
||||
} else {
|
||||
await visitor(root, this.helpers)
|
||||
}
|
||||
} catch (e) {
|
||||
throw this.handleError(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.processed = true
|
||||
return this.stringify()
|
||||
}
|
||||
|
||||
runOnRoot(plugin) {
|
||||
this.result.lastPlugin = plugin
|
||||
try {
|
||||
if (typeof plugin === 'object' && plugin.Once) {
|
||||
if (this.result.root.type === 'document') {
|
||||
let roots = this.result.root.nodes.map(root =>
|
||||
plugin.Once(root, this.helpers)
|
||||
)
|
||||
|
||||
if (isPromise(roots[0])) {
|
||||
return Promise.all(roots)
|
||||
}
|
||||
|
||||
return roots
|
||||
}
|
||||
|
||||
return plugin.Once(this.result.root, this.helpers)
|
||||
} else if (typeof plugin === 'function') {
|
||||
return plugin(this.result.root, this.result)
|
||||
}
|
||||
} catch (error) {
|
||||
throw this.handleError(error)
|
||||
}
|
||||
}
|
||||
|
||||
stringify() {
|
||||
if (this.error) throw this.error
|
||||
if (this.stringified) return this.result
|
||||
this.stringified = true
|
||||
|
||||
this.sync()
|
||||
|
||||
let opts = this.result.opts
|
||||
let str = stringify
|
||||
if (opts.syntax) str = opts.syntax.stringify
|
||||
if (opts.stringifier) str = opts.stringifier
|
||||
if (str.stringify) str = str.stringify
|
||||
|
||||
let map = new MapGenerator(str, this.result.root, this.result.opts)
|
||||
let data = map.generate()
|
||||
this.result.css = data[0]
|
||||
this.result.map = data[1]
|
||||
|
||||
return this.result
|
||||
}
|
||||
|
||||
sync() {
|
||||
if (this.error) throw this.error
|
||||
if (this.processed) return this.result
|
||||
this.processed = true
|
||||
|
||||
if (this.processing) {
|
||||
throw this.getAsyncError()
|
||||
}
|
||||
|
||||
for (let plugin of this.plugins) {
|
||||
let promise = this.runOnRoot(plugin)
|
||||
if (isPromise(promise)) {
|
||||
throw this.getAsyncError()
|
||||
}
|
||||
}
|
||||
|
||||
this.prepareVisitors()
|
||||
if (this.hasListener) {
|
||||
let root = this.result.root
|
||||
while (!root[isClean]) {
|
||||
root[isClean] = true
|
||||
this.walkSync(root)
|
||||
}
|
||||
if (this.listeners.OnceExit) {
|
||||
if (root.type === 'document') {
|
||||
for (let subRoot of root.nodes) {
|
||||
this.visitSync(this.listeners.OnceExit, subRoot)
|
||||
}
|
||||
} else {
|
||||
this.visitSync(this.listeners.OnceExit, root)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.result
|
||||
}
|
||||
|
||||
then(onFulfilled, onRejected) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (!('from' in this.opts)) {
|
||||
warnOnce(
|
||||
'Without `from` option PostCSS could generate wrong source map ' +
|
||||
'and will not find Browserslist config. Set it to CSS file path ' +
|
||||
'or to `undefined` to prevent this warning.'
|
||||
)
|
||||
}
|
||||
}
|
||||
return this.async().then(onFulfilled, onRejected)
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.css
|
||||
}
|
||||
|
||||
visitSync(visitors, node) {
|
||||
for (let [plugin, visitor] of visitors) {
|
||||
this.result.lastPlugin = plugin
|
||||
let promise
|
||||
try {
|
||||
promise = visitor(node, this.helpers)
|
||||
} catch (e) {
|
||||
throw this.handleError(e, node.proxyOf)
|
||||
}
|
||||
if (node.type !== 'root' && node.type !== 'document' && !node.parent) {
|
||||
return true
|
||||
}
|
||||
if (isPromise(promise)) {
|
||||
throw this.getAsyncError()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
visitTick(stack) {
|
||||
let visit = stack[stack.length - 1]
|
||||
let { node, visitors } = visit
|
||||
|
||||
if (node.type !== 'root' && node.type !== 'document' && !node.parent) {
|
||||
stack.pop()
|
||||
return
|
||||
}
|
||||
|
||||
if (visitors.length > 0 && visit.visitorIndex < visitors.length) {
|
||||
let [plugin, visitor] = visitors[visit.visitorIndex]
|
||||
visit.visitorIndex += 1
|
||||
if (visit.visitorIndex === visitors.length) {
|
||||
visit.visitors = []
|
||||
visit.visitorIndex = 0
|
||||
}
|
||||
this.result.lastPlugin = plugin
|
||||
try {
|
||||
return visitor(node.toProxy(), this.helpers)
|
||||
} catch (e) {
|
||||
throw this.handleError(e, node)
|
||||
}
|
||||
}
|
||||
|
||||
if (visit.iterator !== 0) {
|
||||
let iterator = visit.iterator
|
||||
let child
|
||||
while ((child = node.nodes[node.indexes[iterator]])) {
|
||||
node.indexes[iterator] += 1
|
||||
if (!child[isClean]) {
|
||||
child[isClean] = true
|
||||
stack.push(toStack(child))
|
||||
return
|
||||
}
|
||||
}
|
||||
visit.iterator = 0
|
||||
delete node.indexes[iterator]
|
||||
}
|
||||
|
||||
let events = visit.events
|
||||
while (visit.eventIndex < events.length) {
|
||||
let event = events[visit.eventIndex]
|
||||
visit.eventIndex += 1
|
||||
if (event === CHILDREN) {
|
||||
if (node.nodes && node.nodes.length) {
|
||||
node[isClean] = true
|
||||
visit.iterator = node.getIterator()
|
||||
}
|
||||
return
|
||||
} else if (this.listeners[event]) {
|
||||
visit.visitors = this.listeners[event]
|
||||
return
|
||||
}
|
||||
}
|
||||
stack.pop()
|
||||
}
|
||||
|
||||
walkSync(node) {
|
||||
node[isClean] = true
|
||||
let events = getEvents(node)
|
||||
for (let event of events) {
|
||||
if (event === CHILDREN) {
|
||||
if (node.nodes) {
|
||||
node.each(child => {
|
||||
if (!child[isClean]) this.walkSync(child)
|
||||
})
|
||||
}
|
||||
} else {
|
||||
let visitors = this.listeners[event]
|
||||
if (visitors) {
|
||||
if (this.visitSync(visitors, node.toProxy())) return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
warnings() {
|
||||
return this.sync().warnings()
|
||||
}
|
||||
|
||||
get content() {
|
||||
return this.stringify().content
|
||||
}
|
||||
|
||||
get css() {
|
||||
return this.stringify().css
|
||||
}
|
||||
|
||||
get map() {
|
||||
return this.stringify().map
|
||||
}
|
||||
|
||||
get messages() {
|
||||
return this.sync().messages
|
||||
}
|
||||
|
||||
get opts() {
|
||||
return this.result.opts
|
||||
}
|
||||
|
||||
get processor() {
|
||||
return this.result.processor
|
||||
}
|
||||
|
||||
get root() {
|
||||
return this.sync().root
|
||||
}
|
||||
|
||||
get [Symbol.toStringTag]() {
|
||||
return 'LazyResult'
|
||||
}
|
||||
}
|
||||
|
||||
LazyResult.registerPostcss = dependant => {
|
||||
postcss = dependant
|
||||
}
|
||||
|
||||
module.exports = LazyResult
|
||||
LazyResult.default = LazyResult
|
||||
|
||||
Root.registerLazyResult(LazyResult)
|
||||
Document.registerLazyResult(LazyResult)
|
58
node_modules/postcss/lib/list.js
generated
vendored
Normal file
58
node_modules/postcss/lib/list.js
generated
vendored
Normal file
|
@ -0,0 +1,58 @@
|
|||
'use strict'
|
||||
|
||||
let list = {
|
||||
comma(string) {
|
||||
return list.split(string, [','], true)
|
||||
},
|
||||
|
||||
space(string) {
|
||||
let spaces = [' ', '\n', '\t']
|
||||
return list.split(string, spaces)
|
||||
},
|
||||
|
||||
split(string, separators, last) {
|
||||
let array = []
|
||||
let current = ''
|
||||
let split = false
|
||||
|
||||
let func = 0
|
||||
let inQuote = false
|
||||
let prevQuote = ''
|
||||
let escape = false
|
||||
|
||||
for (let letter of string) {
|
||||
if (escape) {
|
||||
escape = false
|
||||
} else if (letter === '\\') {
|
||||
escape = true
|
||||
} else if (inQuote) {
|
||||
if (letter === prevQuote) {
|
||||
inQuote = false
|
||||
}
|
||||
} else if (letter === '"' || letter === "'") {
|
||||
inQuote = true
|
||||
prevQuote = letter
|
||||
} else if (letter === '(') {
|
||||
func += 1
|
||||
} else if (letter === ')') {
|
||||
if (func > 0) func -= 1
|
||||
} else if (func === 0) {
|
||||
if (separators.includes(letter)) split = true
|
||||
}
|
||||
|
||||
if (split) {
|
||||
if (current !== '') array.push(current.trim())
|
||||
current = ''
|
||||
split = false
|
||||
} else {
|
||||
current += letter
|
||||
}
|
||||
}
|
||||
|
||||
if (last || current !== '') array.push(current.trim())
|
||||
return array
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = list
|
||||
list.default = list
|
368
node_modules/postcss/lib/map-generator.js
generated
vendored
Normal file
368
node_modules/postcss/lib/map-generator.js
generated
vendored
Normal file
|
@ -0,0 +1,368 @@
|
|||
'use strict'
|
||||
|
||||
let { SourceMapConsumer, SourceMapGenerator } = require('source-map-js')
|
||||
let { dirname, relative, resolve, sep } = require('path')
|
||||
let { pathToFileURL } = require('url')
|
||||
|
||||
let Input = require('./input')
|
||||
|
||||
let sourceMapAvailable = Boolean(SourceMapConsumer && SourceMapGenerator)
|
||||
let pathAvailable = Boolean(dirname && resolve && relative && sep)
|
||||
|
||||
class MapGenerator {
|
||||
constructor(stringify, root, opts, cssString) {
|
||||
this.stringify = stringify
|
||||
this.mapOpts = opts.map || {}
|
||||
this.root = root
|
||||
this.opts = opts
|
||||
this.css = cssString
|
||||
this.originalCSS = cssString
|
||||
this.usesFileUrls = !this.mapOpts.from && this.mapOpts.absolute
|
||||
|
||||
this.memoizedFileURLs = new Map()
|
||||
this.memoizedPaths = new Map()
|
||||
this.memoizedURLs = new Map()
|
||||
}
|
||||
|
||||
addAnnotation() {
|
||||
let content
|
||||
|
||||
if (this.isInline()) {
|
||||
content =
|
||||
'data:application/json;base64,' + this.toBase64(this.map.toString())
|
||||
} else if (typeof this.mapOpts.annotation === 'string') {
|
||||
content = this.mapOpts.annotation
|
||||
} else if (typeof this.mapOpts.annotation === 'function') {
|
||||
content = this.mapOpts.annotation(this.opts.to, this.root)
|
||||
} else {
|
||||
content = this.outputFile() + '.map'
|
||||
}
|
||||
let eol = '\n'
|
||||
if (this.css.includes('\r\n')) eol = '\r\n'
|
||||
|
||||
this.css += eol + '/*# sourceMappingURL=' + content + ' */'
|
||||
}
|
||||
|
||||
applyPrevMaps() {
|
||||
for (let prev of this.previous()) {
|
||||
let from = this.toUrl(this.path(prev.file))
|
||||
let root = prev.root || dirname(prev.file)
|
||||
let map
|
||||
|
||||
if (this.mapOpts.sourcesContent === false) {
|
||||
map = new SourceMapConsumer(prev.text)
|
||||
if (map.sourcesContent) {
|
||||
map.sourcesContent = null
|
||||
}
|
||||
} else {
|
||||
map = prev.consumer()
|
||||
}
|
||||
|
||||
this.map.applySourceMap(map, from, this.toUrl(this.path(root)))
|
||||
}
|
||||
}
|
||||
|
||||
clearAnnotation() {
|
||||
if (this.mapOpts.annotation === false) return
|
||||
|
||||
if (this.root) {
|
||||
let node
|
||||
for (let i = this.root.nodes.length - 1; i >= 0; i--) {
|
||||
node = this.root.nodes[i]
|
||||
if (node.type !== 'comment') continue
|
||||
if (node.text.indexOf('# sourceMappingURL=') === 0) {
|
||||
this.root.removeChild(i)
|
||||
}
|
||||
}
|
||||
} else if (this.css) {
|
||||
this.css = this.css.replace(/\n*\/\*#[\S\s]*?\*\/$/gm, '')
|
||||
}
|
||||
}
|
||||
|
||||
generate() {
|
||||
this.clearAnnotation()
|
||||
if (pathAvailable && sourceMapAvailable && this.isMap()) {
|
||||
return this.generateMap()
|
||||
} else {
|
||||
let result = ''
|
||||
this.stringify(this.root, i => {
|
||||
result += i
|
||||
})
|
||||
return [result]
|
||||
}
|
||||
}
|
||||
|
||||
generateMap() {
|
||||
if (this.root) {
|
||||
this.generateString()
|
||||
} else if (this.previous().length === 1) {
|
||||
let prev = this.previous()[0].consumer()
|
||||
prev.file = this.outputFile()
|
||||
this.map = SourceMapGenerator.fromSourceMap(prev, {
|
||||
ignoreInvalidMapping: true
|
||||
})
|
||||
} else {
|
||||
this.map = new SourceMapGenerator({
|
||||
file: this.outputFile(),
|
||||
ignoreInvalidMapping: true
|
||||
})
|
||||
this.map.addMapping({
|
||||
generated: { column: 0, line: 1 },
|
||||
original: { column: 0, line: 1 },
|
||||
source: this.opts.from
|
||||
? this.toUrl(this.path(this.opts.from))
|
||||
: '<no source>'
|
||||
})
|
||||
}
|
||||
|
||||
if (this.isSourcesContent()) this.setSourcesContent()
|
||||
if (this.root && this.previous().length > 0) this.applyPrevMaps()
|
||||
if (this.isAnnotation()) this.addAnnotation()
|
||||
|
||||
if (this.isInline()) {
|
||||
return [this.css]
|
||||
} else {
|
||||
return [this.css, this.map]
|
||||
}
|
||||
}
|
||||
|
||||
generateString() {
|
||||
this.css = ''
|
||||
this.map = new SourceMapGenerator({
|
||||
file: this.outputFile(),
|
||||
ignoreInvalidMapping: true
|
||||
})
|
||||
|
||||
let line = 1
|
||||
let column = 1
|
||||
|
||||
let noSource = '<no source>'
|
||||
let mapping = {
|
||||
generated: { column: 0, line: 0 },
|
||||
original: { column: 0, line: 0 },
|
||||
source: ''
|
||||
}
|
||||
|
||||
let lines, last
|
||||
this.stringify(this.root, (str, node, type) => {
|
||||
this.css += str
|
||||
|
||||
if (node && type !== 'end') {
|
||||
mapping.generated.line = line
|
||||
mapping.generated.column = column - 1
|
||||
if (node.source && node.source.start) {
|
||||
mapping.source = this.sourcePath(node)
|
||||
mapping.original.line = node.source.start.line
|
||||
mapping.original.column = node.source.start.column - 1
|
||||
this.map.addMapping(mapping)
|
||||
} else {
|
||||
mapping.source = noSource
|
||||
mapping.original.line = 1
|
||||
mapping.original.column = 0
|
||||
this.map.addMapping(mapping)
|
||||
}
|
||||
}
|
||||
|
||||
lines = str.match(/\n/g)
|
||||
if (lines) {
|
||||
line += lines.length
|
||||
last = str.lastIndexOf('\n')
|
||||
column = str.length - last
|
||||
} else {
|
||||
column += str.length
|
||||
}
|
||||
|
||||
if (node && type !== 'start') {
|
||||
let p = node.parent || { raws: {} }
|
||||
let childless =
|
||||
node.type === 'decl' || (node.type === 'atrule' && !node.nodes)
|
||||
if (!childless || node !== p.last || p.raws.semicolon) {
|
||||
if (node.source && node.source.end) {
|
||||
mapping.source = this.sourcePath(node)
|
||||
mapping.original.line = node.source.end.line
|
||||
mapping.original.column = node.source.end.column - 1
|
||||
mapping.generated.line = line
|
||||
mapping.generated.column = column - 2
|
||||
this.map.addMapping(mapping)
|
||||
} else {
|
||||
mapping.source = noSource
|
||||
mapping.original.line = 1
|
||||
mapping.original.column = 0
|
||||
mapping.generated.line = line
|
||||
mapping.generated.column = column - 1
|
||||
this.map.addMapping(mapping)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
isAnnotation() {
|
||||
if (this.isInline()) {
|
||||
return true
|
||||
}
|
||||
if (typeof this.mapOpts.annotation !== 'undefined') {
|
||||
return this.mapOpts.annotation
|
||||
}
|
||||
if (this.previous().length) {
|
||||
return this.previous().some(i => i.annotation)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
isInline() {
|
||||
if (typeof this.mapOpts.inline !== 'undefined') {
|
||||
return this.mapOpts.inline
|
||||
}
|
||||
|
||||
let annotation = this.mapOpts.annotation
|
||||
if (typeof annotation !== 'undefined' && annotation !== true) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (this.previous().length) {
|
||||
return this.previous().some(i => i.inline)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
isMap() {
|
||||
if (typeof this.opts.map !== 'undefined') {
|
||||
return !!this.opts.map
|
||||
}
|
||||
return this.previous().length > 0
|
||||
}
|
||||
|
||||
isSourcesContent() {
|
||||
if (typeof this.mapOpts.sourcesContent !== 'undefined') {
|
||||
return this.mapOpts.sourcesContent
|
||||
}
|
||||
if (this.previous().length) {
|
||||
return this.previous().some(i => i.withContent())
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
outputFile() {
|
||||
if (this.opts.to) {
|
||||
return this.path(this.opts.to)
|
||||
} else if (this.opts.from) {
|
||||
return this.path(this.opts.from)
|
||||
} else {
|
||||
return 'to.css'
|
||||
}
|
||||
}
|
||||
|
||||
path(file) {
|
||||
if (this.mapOpts.absolute) return file
|
||||
if (file.charCodeAt(0) === 60 /* `<` */) return file
|
||||
if (/^\w+:\/\//.test(file)) return file
|
||||
let cached = this.memoizedPaths.get(file)
|
||||
if (cached) return cached
|
||||
|
||||
let from = this.opts.to ? dirname(this.opts.to) : '.'
|
||||
|
||||
if (typeof this.mapOpts.annotation === 'string') {
|
||||
from = dirname(resolve(from, this.mapOpts.annotation))
|
||||
}
|
||||
|
||||
let path = relative(from, file)
|
||||
this.memoizedPaths.set(file, path)
|
||||
|
||||
return path
|
||||
}
|
||||
|
||||
previous() {
|
||||
if (!this.previousMaps) {
|
||||
this.previousMaps = []
|
||||
if (this.root) {
|
||||
this.root.walk(node => {
|
||||
if (node.source && node.source.input.map) {
|
||||
let map = node.source.input.map
|
||||
if (!this.previousMaps.includes(map)) {
|
||||
this.previousMaps.push(map)
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
let input = new Input(this.originalCSS, this.opts)
|
||||
if (input.map) this.previousMaps.push(input.map)
|
||||
}
|
||||
}
|
||||
|
||||
return this.previousMaps
|
||||
}
|
||||
|
||||
setSourcesContent() {
|
||||
let already = {}
|
||||
if (this.root) {
|
||||
this.root.walk(node => {
|
||||
if (node.source) {
|
||||
let from = node.source.input.from
|
||||
if (from && !already[from]) {
|
||||
already[from] = true
|
||||
let fromUrl = this.usesFileUrls
|
||||
? this.toFileUrl(from)
|
||||
: this.toUrl(this.path(from))
|
||||
this.map.setSourceContent(fromUrl, node.source.input.css)
|
||||
}
|
||||
}
|
||||
})
|
||||
} else if (this.css) {
|
||||
let from = this.opts.from
|
||||
? this.toUrl(this.path(this.opts.from))
|
||||
: '<no source>'
|
||||
this.map.setSourceContent(from, this.css)
|
||||
}
|
||||
}
|
||||
|
||||
sourcePath(node) {
|
||||
if (this.mapOpts.from) {
|
||||
return this.toUrl(this.mapOpts.from)
|
||||
} else if (this.usesFileUrls) {
|
||||
return this.toFileUrl(node.source.input.from)
|
||||
} else {
|
||||
return this.toUrl(this.path(node.source.input.from))
|
||||
}
|
||||
}
|
||||
|
||||
toBase64(str) {
|
||||
if (Buffer) {
|
||||
return Buffer.from(str).toString('base64')
|
||||
} else {
|
||||
return window.btoa(unescape(encodeURIComponent(str)))
|
||||
}
|
||||
}
|
||||
|
||||
toFileUrl(path) {
|
||||
let cached = this.memoizedFileURLs.get(path)
|
||||
if (cached) return cached
|
||||
|
||||
if (pathToFileURL) {
|
||||
let fileURL = pathToFileURL(path).toString()
|
||||
this.memoizedFileURLs.set(path, fileURL)
|
||||
|
||||
return fileURL
|
||||
} else {
|
||||
throw new Error(
|
||||
'`map.absolute` option is not available in this PostCSS build'
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
toUrl(path) {
|
||||
let cached = this.memoizedURLs.get(path)
|
||||
if (cached) return cached
|
||||
|
||||
if (sep === '\\') {
|
||||
path = path.replace(/\\/g, '/')
|
||||
}
|
||||
|
||||
let url = encodeURI(path).replace(/[#?]/g, encodeURIComponent)
|
||||
this.memoizedURLs.set(path, url)
|
||||
|
||||
return url
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = MapGenerator
|
381
node_modules/postcss/lib/node.js
generated
vendored
Normal file
381
node_modules/postcss/lib/node.js
generated
vendored
Normal file
|
@ -0,0 +1,381 @@
|
|||
'use strict'
|
||||
|
||||
let { isClean, my } = require('./symbols')
|
||||
let CssSyntaxError = require('./css-syntax-error')
|
||||
let Stringifier = require('./stringifier')
|
||||
let stringify = require('./stringify')
|
||||
|
||||
function cloneNode(obj, parent) {
|
||||
let cloned = new obj.constructor()
|
||||
|
||||
for (let i in obj) {
|
||||
if (!Object.prototype.hasOwnProperty.call(obj, i)) {
|
||||
/* c8 ignore next 2 */
|
||||
continue
|
||||
}
|
||||
if (i === 'proxyCache') continue
|
||||
let value = obj[i]
|
||||
let type = typeof value
|
||||
|
||||
if (i === 'parent' && type === 'object') {
|
||||
if (parent) cloned[i] = parent
|
||||
} else if (i === 'source') {
|
||||
cloned[i] = value
|
||||
} else if (Array.isArray(value)) {
|
||||
cloned[i] = value.map(j => cloneNode(j, cloned))
|
||||
} else {
|
||||
if (type === 'object' && value !== null) value = cloneNode(value)
|
||||
cloned[i] = value
|
||||
}
|
||||
}
|
||||
|
||||
return cloned
|
||||
}
|
||||
|
||||
class Node {
|
||||
constructor(defaults = {}) {
|
||||
this.raws = {}
|
||||
this[isClean] = false
|
||||
this[my] = true
|
||||
|
||||
for (let name in defaults) {
|
||||
if (name === 'nodes') {
|
||||
this.nodes = []
|
||||
for (let node of defaults[name]) {
|
||||
if (typeof node.clone === 'function') {
|
||||
this.append(node.clone())
|
||||
} else {
|
||||
this.append(node)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this[name] = defaults[name]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addToError(error) {
|
||||
error.postcssNode = this
|
||||
if (error.stack && this.source && /\n\s{4}at /.test(error.stack)) {
|
||||
let s = this.source
|
||||
error.stack = error.stack.replace(
|
||||
/\n\s{4}at /,
|
||||
`$&${s.input.from}:${s.start.line}:${s.start.column}$&`
|
||||
)
|
||||
}
|
||||
return error
|
||||
}
|
||||
|
||||
after(add) {
|
||||
this.parent.insertAfter(this, add)
|
||||
return this
|
||||
}
|
||||
|
||||
assign(overrides = {}) {
|
||||
for (let name in overrides) {
|
||||
this[name] = overrides[name]
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
||||
before(add) {
|
||||
this.parent.insertBefore(this, add)
|
||||
return this
|
||||
}
|
||||
|
||||
cleanRaws(keepBetween) {
|
||||
delete this.raws.before
|
||||
delete this.raws.after
|
||||
if (!keepBetween) delete this.raws.between
|
||||
}
|
||||
|
||||
clone(overrides = {}) {
|
||||
let cloned = cloneNode(this)
|
||||
for (let name in overrides) {
|
||||
cloned[name] = overrides[name]
|
||||
}
|
||||
return cloned
|
||||
}
|
||||
|
||||
cloneAfter(overrides = {}) {
|
||||
let cloned = this.clone(overrides)
|
||||
this.parent.insertAfter(this, cloned)
|
||||
return cloned
|
||||
}
|
||||
|
||||
cloneBefore(overrides = {}) {
|
||||
let cloned = this.clone(overrides)
|
||||
this.parent.insertBefore(this, cloned)
|
||||
return cloned
|
||||
}
|
||||
|
||||
error(message, opts = {}) {
|
||||
if (this.source) {
|
||||
let { end, start } = this.rangeBy(opts)
|
||||
return this.source.input.error(
|
||||
message,
|
||||
{ column: start.column, line: start.line },
|
||||
{ column: end.column, line: end.line },
|
||||
opts
|
||||
)
|
||||
}
|
||||
return new CssSyntaxError(message)
|
||||
}
|
||||
|
||||
getProxyProcessor() {
|
||||
return {
|
||||
get(node, prop) {
|
||||
if (prop === 'proxyOf') {
|
||||
return node
|
||||
} else if (prop === 'root') {
|
||||
return () => node.root().toProxy()
|
||||
} else {
|
||||
return node[prop]
|
||||
}
|
||||
},
|
||||
|
||||
set(node, prop, value) {
|
||||
if (node[prop] === value) return true
|
||||
node[prop] = value
|
||||
if (
|
||||
prop === 'prop' ||
|
||||
prop === 'value' ||
|
||||
prop === 'name' ||
|
||||
prop === 'params' ||
|
||||
prop === 'important' ||
|
||||
/* c8 ignore next */
|
||||
prop === 'text'
|
||||
) {
|
||||
node.markDirty()
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
markDirty() {
|
||||
if (this[isClean]) {
|
||||
this[isClean] = false
|
||||
let next = this
|
||||
while ((next = next.parent)) {
|
||||
next[isClean] = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
next() {
|
||||
if (!this.parent) return undefined
|
||||
let index = this.parent.index(this)
|
||||
return this.parent.nodes[index + 1]
|
||||
}
|
||||
|
||||
positionBy(opts, stringRepresentation) {
|
||||
let pos = this.source.start
|
||||
if (opts.index) {
|
||||
pos = this.positionInside(opts.index, stringRepresentation)
|
||||
} else if (opts.word) {
|
||||
stringRepresentation = this.toString()
|
||||
let index = stringRepresentation.indexOf(opts.word)
|
||||
if (index !== -1) pos = this.positionInside(index, stringRepresentation)
|
||||
}
|
||||
return pos
|
||||
}
|
||||
|
||||
positionInside(index, stringRepresentation) {
|
||||
let string = stringRepresentation || this.toString()
|
||||
let column = this.source.start.column
|
||||
let line = this.source.start.line
|
||||
|
||||
for (let i = 0; i < index; i++) {
|
||||
if (string[i] === '\n') {
|
||||
column = 1
|
||||
line += 1
|
||||
} else {
|
||||
column += 1
|
||||
}
|
||||
}
|
||||
|
||||
return { column, line }
|
||||
}
|
||||
|
||||
prev() {
|
||||
if (!this.parent) return undefined
|
||||
let index = this.parent.index(this)
|
||||
return this.parent.nodes[index - 1]
|
||||
}
|
||||
|
||||
rangeBy(opts) {
|
||||
let start = {
|
||||
column: this.source.start.column,
|
||||
line: this.source.start.line
|
||||
}
|
||||
let end = this.source.end
|
||||
? {
|
||||
column: this.source.end.column + 1,
|
||||
line: this.source.end.line
|
||||
}
|
||||
: {
|
||||
column: start.column + 1,
|
||||
line: start.line
|
||||
}
|
||||
|
||||
if (opts.word) {
|
||||
let stringRepresentation = this.toString()
|
||||
let index = stringRepresentation.indexOf(opts.word)
|
||||
if (index !== -1) {
|
||||
start = this.positionInside(index, stringRepresentation)
|
||||
end = this.positionInside(index + opts.word.length, stringRepresentation)
|
||||
}
|
||||
} else {
|
||||
if (opts.start) {
|
||||
start = {
|
||||
column: opts.start.column,
|
||||
line: opts.start.line
|
||||
}
|
||||
} else if (opts.index) {
|
||||
start = this.positionInside(opts.index)
|
||||
}
|
||||
|
||||
if (opts.end) {
|
||||
end = {
|
||||
column: opts.end.column,
|
||||
line: opts.end.line
|
||||
}
|
||||
} else if (typeof opts.endIndex === 'number') {
|
||||
end = this.positionInside(opts.endIndex)
|
||||
} else if (opts.index) {
|
||||
end = this.positionInside(opts.index + 1)
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
end.line < start.line ||
|
||||
(end.line === start.line && end.column <= start.column)
|
||||
) {
|
||||
end = { column: start.column + 1, line: start.line }
|
||||
}
|
||||
|
||||
return { end, start }
|
||||
}
|
||||
|
||||
raw(prop, defaultType) {
|
||||
let str = new Stringifier()
|
||||
return str.raw(this, prop, defaultType)
|
||||
}
|
||||
|
||||
remove() {
|
||||
if (this.parent) {
|
||||
this.parent.removeChild(this)
|
||||
}
|
||||
this.parent = undefined
|
||||
return this
|
||||
}
|
||||
|
||||
replaceWith(...nodes) {
|
||||
if (this.parent) {
|
||||
let bookmark = this
|
||||
let foundSelf = false
|
||||
for (let node of nodes) {
|
||||
if (node === this) {
|
||||
foundSelf = true
|
||||
} else if (foundSelf) {
|
||||
this.parent.insertAfter(bookmark, node)
|
||||
bookmark = node
|
||||
} else {
|
||||
this.parent.insertBefore(bookmark, node)
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundSelf) {
|
||||
this.remove()
|
||||
}
|
||||
}
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
root() {
|
||||
let result = this
|
||||
while (result.parent && result.parent.type !== 'document') {
|
||||
result = result.parent
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
toJSON(_, inputs) {
|
||||
let fixed = {}
|
||||
let emitInputs = inputs == null
|
||||
inputs = inputs || new Map()
|
||||
let inputsNextIndex = 0
|
||||
|
||||
for (let name in this) {
|
||||
if (!Object.prototype.hasOwnProperty.call(this, name)) {
|
||||
/* c8 ignore next 2 */
|
||||
continue
|
||||
}
|
||||
if (name === 'parent' || name === 'proxyCache') continue
|
||||
let value = this[name]
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
fixed[name] = value.map(i => {
|
||||
if (typeof i === 'object' && i.toJSON) {
|
||||
return i.toJSON(null, inputs)
|
||||
} else {
|
||||
return i
|
||||
}
|
||||
})
|
||||
} else if (typeof value === 'object' && value.toJSON) {
|
||||
fixed[name] = value.toJSON(null, inputs)
|
||||
} else if (name === 'source') {
|
||||
let inputId = inputs.get(value.input)
|
||||
if (inputId == null) {
|
||||
inputId = inputsNextIndex
|
||||
inputs.set(value.input, inputsNextIndex)
|
||||
inputsNextIndex++
|
||||
}
|
||||
fixed[name] = {
|
||||
end: value.end,
|
||||
inputId,
|
||||
start: value.start
|
||||
}
|
||||
} else {
|
||||
fixed[name] = value
|
||||
}
|
||||
}
|
||||
|
||||
if (emitInputs) {
|
||||
fixed.inputs = [...inputs.keys()].map(input => input.toJSON())
|
||||
}
|
||||
|
||||
return fixed
|
||||
}
|
||||
|
||||
toProxy() {
|
||||
if (!this.proxyCache) {
|
||||
this.proxyCache = new Proxy(this, this.getProxyProcessor())
|
||||
}
|
||||
return this.proxyCache
|
||||
}
|
||||
|
||||
toString(stringifier = stringify) {
|
||||
if (stringifier.stringify) stringifier = stringifier.stringify
|
||||
let result = ''
|
||||
stringifier(this, i => {
|
||||
result += i
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
warn(result, text, opts) {
|
||||
let data = { node: this }
|
||||
for (let i in opts) data[i] = opts[i]
|
||||
return result.warn(text, data)
|
||||
}
|
||||
|
||||
get proxyOf() {
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Node
|
||||
Node.default = Node
|
42
node_modules/postcss/lib/parse.js
generated
vendored
Normal file
42
node_modules/postcss/lib/parse.js
generated
vendored
Normal file
|
@ -0,0 +1,42 @@
|
|||
'use strict'
|
||||
|
||||
let Container = require('./container')
|
||||
let Parser = require('./parser')
|
||||
let Input = require('./input')
|
||||
|
||||
function parse(css, opts) {
|
||||
let input = new Input(css, opts)
|
||||
let parser = new Parser(input)
|
||||
try {
|
||||
parser.parse()
|
||||
} catch (e) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
if (e.name === 'CssSyntaxError' && opts && opts.from) {
|
||||
if (/\.scss$/i.test(opts.from)) {
|
||||
e.message +=
|
||||
'\nYou tried to parse SCSS with ' +
|
||||
'the standard CSS parser; ' +
|
||||
'try again with the postcss-scss parser'
|
||||
} else if (/\.sass/i.test(opts.from)) {
|
||||
e.message +=
|
||||
'\nYou tried to parse Sass with ' +
|
||||
'the standard CSS parser; ' +
|
||||
'try again with the postcss-sass parser'
|
||||
} else if (/\.less$/i.test(opts.from)) {
|
||||
e.message +=
|
||||
'\nYou tried to parse Less with ' +
|
||||
'the standard CSS parser; ' +
|
||||
'try again with the postcss-less parser'
|
||||
}
|
||||
}
|
||||
}
|
||||
throw e
|
||||
}
|
||||
|
||||
return parser.root
|
||||
}
|
||||
|
||||
module.exports = parse
|
||||
parse.default = parse
|
||||
|
||||
Container.registerParse(parse)
|
609
node_modules/postcss/lib/parser.js
generated
vendored
Normal file
609
node_modules/postcss/lib/parser.js
generated
vendored
Normal file
|
@ -0,0 +1,609 @@
|
|||
'use strict'
|
||||
|
||||
let Declaration = require('./declaration')
|
||||
let tokenizer = require('./tokenize')
|
||||
let Comment = require('./comment')
|
||||
let AtRule = require('./at-rule')
|
||||
let Root = require('./root')
|
||||
let Rule = require('./rule')
|
||||
|
||||
const SAFE_COMMENT_NEIGHBOR = {
|
||||
empty: true,
|
||||
space: true
|
||||
}
|
||||
|
||||
function findLastWithPosition(tokens) {
|
||||
for (let i = tokens.length - 1; i >= 0; i--) {
|
||||
let token = tokens[i]
|
||||
let pos = token[3] || token[2]
|
||||
if (pos) return pos
|
||||
}
|
||||
}
|
||||
|
||||
class Parser {
|
||||
constructor(input) {
|
||||
this.input = input
|
||||
|
||||
this.root = new Root()
|
||||
this.current = this.root
|
||||
this.spaces = ''
|
||||
this.semicolon = false
|
||||
|
||||
this.createTokenizer()
|
||||
this.root.source = { input, start: { column: 1, line: 1, offset: 0 } }
|
||||
}
|
||||
|
||||
atrule(token) {
|
||||
let node = new AtRule()
|
||||
node.name = token[1].slice(1)
|
||||
if (node.name === '') {
|
||||
this.unnamedAtrule(node, token)
|
||||
}
|
||||
this.init(node, token[2])
|
||||
|
||||
let type
|
||||
let prev
|
||||
let shift
|
||||
let last = false
|
||||
let open = false
|
||||
let params = []
|
||||
let brackets = []
|
||||
|
||||
while (!this.tokenizer.endOfFile()) {
|
||||
token = this.tokenizer.nextToken()
|
||||
type = token[0]
|
||||
|
||||
if (type === '(' || type === '[') {
|
||||
brackets.push(type === '(' ? ')' : ']')
|
||||
} else if (type === '{' && brackets.length > 0) {
|
||||
brackets.push('}')
|
||||
} else if (type === brackets[brackets.length - 1]) {
|
||||
brackets.pop()
|
||||
}
|
||||
|
||||
if (brackets.length === 0) {
|
||||
if (type === ';') {
|
||||
node.source.end = this.getPosition(token[2])
|
||||
node.source.end.offset++
|
||||
this.semicolon = true
|
||||
break
|
||||
} else if (type === '{') {
|
||||
open = true
|
||||
break
|
||||
} else if (type === '}') {
|
||||
if (params.length > 0) {
|
||||
shift = params.length - 1
|
||||
prev = params[shift]
|
||||
while (prev && prev[0] === 'space') {
|
||||
prev = params[--shift]
|
||||
}
|
||||
if (prev) {
|
||||
node.source.end = this.getPosition(prev[3] || prev[2])
|
||||
node.source.end.offset++
|
||||
}
|
||||
}
|
||||
this.end(token)
|
||||
break
|
||||
} else {
|
||||
params.push(token)
|
||||
}
|
||||
} else {
|
||||
params.push(token)
|
||||
}
|
||||
|
||||
if (this.tokenizer.endOfFile()) {
|
||||
last = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
node.raws.between = this.spacesAndCommentsFromEnd(params)
|
||||
if (params.length) {
|
||||
node.raws.afterName = this.spacesAndCommentsFromStart(params)
|
||||
this.raw(node, 'params', params)
|
||||
if (last) {
|
||||
token = params[params.length - 1]
|
||||
node.source.end = this.getPosition(token[3] || token[2])
|
||||
node.source.end.offset++
|
||||
this.spaces = node.raws.between
|
||||
node.raws.between = ''
|
||||
}
|
||||
} else {
|
||||
node.raws.afterName = ''
|
||||
node.params = ''
|
||||
}
|
||||
|
||||
if (open) {
|
||||
node.nodes = []
|
||||
this.current = node
|
||||
}
|
||||
}
|
||||
|
||||
checkMissedSemicolon(tokens) {
|
||||
let colon = this.colon(tokens)
|
||||
if (colon === false) return
|
||||
|
||||
let founded = 0
|
||||
let token
|
||||
for (let j = colon - 1; j >= 0; j--) {
|
||||
token = tokens[j]
|
||||
if (token[0] !== 'space') {
|
||||
founded += 1
|
||||
if (founded === 2) break
|
||||
}
|
||||
}
|
||||
// If the token is a word, e.g. `!important`, `red` or any other valid property's value.
|
||||
// Then we need to return the colon after that word token. [3] is the "end" colon of that word.
|
||||
// And because we need it after that one we do +1 to get the next one.
|
||||
throw this.input.error(
|
||||
'Missed semicolon',
|
||||
token[0] === 'word' ? token[3] + 1 : token[2]
|
||||
)
|
||||
}
|
||||
|
||||
colon(tokens) {
|
||||
let brackets = 0
|
||||
let token, type, prev
|
||||
for (let [i, element] of tokens.entries()) {
|
||||
token = element
|
||||
type = token[0]
|
||||
|
||||
if (type === '(') {
|
||||
brackets += 1
|
||||
}
|
||||
if (type === ')') {
|
||||
brackets -= 1
|
||||
}
|
||||
if (brackets === 0 && type === ':') {
|
||||
if (!prev) {
|
||||
this.doubleColon(token)
|
||||
} else if (prev[0] === 'word' && prev[1] === 'progid') {
|
||||
continue
|
||||
} else {
|
||||
return i
|
||||
}
|
||||
}
|
||||
|
||||
prev = token
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
comment(token) {
|
||||
let node = new Comment()
|
||||
this.init(node, token[2])
|
||||
node.source.end = this.getPosition(token[3] || token[2])
|
||||
node.source.end.offset++
|
||||
|
||||
let text = token[1].slice(2, -2)
|
||||
if (/^\s*$/.test(text)) {
|
||||
node.text = ''
|
||||
node.raws.left = text
|
||||
node.raws.right = ''
|
||||
} else {
|
||||
let match = text.match(/^(\s*)([^]*\S)(\s*)$/)
|
||||
node.text = match[2]
|
||||
node.raws.left = match[1]
|
||||
node.raws.right = match[3]
|
||||
}
|
||||
}
|
||||
|
||||
createTokenizer() {
|
||||
this.tokenizer = tokenizer(this.input)
|
||||
}
|
||||
|
||||
decl(tokens, customProperty) {
|
||||
let node = new Declaration()
|
||||
this.init(node, tokens[0][2])
|
||||
|
||||
let last = tokens[tokens.length - 1]
|
||||
if (last[0] === ';') {
|
||||
this.semicolon = true
|
||||
tokens.pop()
|
||||
}
|
||||
|
||||
node.source.end = this.getPosition(
|
||||
last[3] || last[2] || findLastWithPosition(tokens)
|
||||
)
|
||||
node.source.end.offset++
|
||||
|
||||
while (tokens[0][0] !== 'word') {
|
||||
if (tokens.length === 1) this.unknownWord(tokens)
|
||||
node.raws.before += tokens.shift()[1]
|
||||
}
|
||||
node.source.start = this.getPosition(tokens[0][2])
|
||||
|
||||
node.prop = ''
|
||||
while (tokens.length) {
|
||||
let type = tokens[0][0]
|
||||
if (type === ':' || type === 'space' || type === 'comment') {
|
||||
break
|
||||
}
|
||||
node.prop += tokens.shift()[1]
|
||||
}
|
||||
|
||||
node.raws.between = ''
|
||||
|
||||
let token
|
||||
while (tokens.length) {
|
||||
token = tokens.shift()
|
||||
|
||||
if (token[0] === ':') {
|
||||
node.raws.between += token[1]
|
||||
break
|
||||
} else {
|
||||
if (token[0] === 'word' && /\w/.test(token[1])) {
|
||||
this.unknownWord([token])
|
||||
}
|
||||
node.raws.between += token[1]
|
||||
}
|
||||
}
|
||||
|
||||
if (node.prop[0] === '_' || node.prop[0] === '*') {
|
||||
node.raws.before += node.prop[0]
|
||||
node.prop = node.prop.slice(1)
|
||||
}
|
||||
|
||||
let firstSpaces = []
|
||||
let next
|
||||
while (tokens.length) {
|
||||
next = tokens[0][0]
|
||||
if (next !== 'space' && next !== 'comment') break
|
||||
firstSpaces.push(tokens.shift())
|
||||
}
|
||||
|
||||
this.precheckMissedSemicolon(tokens)
|
||||
|
||||
for (let i = tokens.length - 1; i >= 0; i--) {
|
||||
token = tokens[i]
|
||||
if (token[1].toLowerCase() === '!important') {
|
||||
node.important = true
|
||||
let string = this.stringFrom(tokens, i)
|
||||
string = this.spacesFromEnd(tokens) + string
|
||||
if (string !== ' !important') node.raws.important = string
|
||||
break
|
||||
} else if (token[1].toLowerCase() === 'important') {
|
||||
let cache = tokens.slice(0)
|
||||
let str = ''
|
||||
for (let j = i; j > 0; j--) {
|
||||
let type = cache[j][0]
|
||||
if (str.trim().indexOf('!') === 0 && type !== 'space') {
|
||||
break
|
||||
}
|
||||
str = cache.pop()[1] + str
|
||||
}
|
||||
if (str.trim().indexOf('!') === 0) {
|
||||
node.important = true
|
||||
node.raws.important = str
|
||||
tokens = cache
|
||||
}
|
||||
}
|
||||
|
||||
if (token[0] !== 'space' && token[0] !== 'comment') {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
let hasWord = tokens.some(i => i[0] !== 'space' && i[0] !== 'comment')
|
||||
|
||||
if (hasWord) {
|
||||
node.raws.between += firstSpaces.map(i => i[1]).join('')
|
||||
firstSpaces = []
|
||||
}
|
||||
this.raw(node, 'value', firstSpaces.concat(tokens), customProperty)
|
||||
|
||||
if (node.value.includes(':') && !customProperty) {
|
||||
this.checkMissedSemicolon(tokens)
|
||||
}
|
||||
}
|
||||
|
||||
doubleColon(token) {
|
||||
throw this.input.error(
|
||||
'Double colon',
|
||||
{ offset: token[2] },
|
||||
{ offset: token[2] + token[1].length }
|
||||
)
|
||||
}
|
||||
|
||||
emptyRule(token) {
|
||||
let node = new Rule()
|
||||
this.init(node, token[2])
|
||||
node.selector = ''
|
||||
node.raws.between = ''
|
||||
this.current = node
|
||||
}
|
||||
|
||||
end(token) {
|
||||
if (this.current.nodes && this.current.nodes.length) {
|
||||
this.current.raws.semicolon = this.semicolon
|
||||
}
|
||||
this.semicolon = false
|
||||
|
||||
this.current.raws.after = (this.current.raws.after || '') + this.spaces
|
||||
this.spaces = ''
|
||||
|
||||
if (this.current.parent) {
|
||||
this.current.source.end = this.getPosition(token[2])
|
||||
this.current.source.end.offset++
|
||||
this.current = this.current.parent
|
||||
} else {
|
||||
this.unexpectedClose(token)
|
||||
}
|
||||
}
|
||||
|
||||
endFile() {
|
||||
if (this.current.parent) this.unclosedBlock()
|
||||
if (this.current.nodes && this.current.nodes.length) {
|
||||
this.current.raws.semicolon = this.semicolon
|
||||
}
|
||||
this.current.raws.after = (this.current.raws.after || '') + this.spaces
|
||||
this.root.source.end = this.getPosition(this.tokenizer.position())
|
||||
}
|
||||
|
||||
freeSemicolon(token) {
|
||||
this.spaces += token[1]
|
||||
if (this.current.nodes) {
|
||||
let prev = this.current.nodes[this.current.nodes.length - 1]
|
||||
if (prev && prev.type === 'rule' && !prev.raws.ownSemicolon) {
|
||||
prev.raws.ownSemicolon = this.spaces
|
||||
this.spaces = ''
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Helpers
|
||||
|
||||
getPosition(offset) {
|
||||
let pos = this.input.fromOffset(offset)
|
||||
return {
|
||||
column: pos.col,
|
||||
line: pos.line,
|
||||
offset
|
||||
}
|
||||
}
|
||||
|
||||
init(node, offset) {
|
||||
this.current.push(node)
|
||||
node.source = {
|
||||
input: this.input,
|
||||
start: this.getPosition(offset)
|
||||
}
|
||||
node.raws.before = this.spaces
|
||||
this.spaces = ''
|
||||
if (node.type !== 'comment') this.semicolon = false
|
||||
}
|
||||
|
||||
other(start) {
|
||||
let end = false
|
||||
let type = null
|
||||
let colon = false
|
||||
let bracket = null
|
||||
let brackets = []
|
||||
let customProperty = start[1].startsWith('--')
|
||||
|
||||
let tokens = []
|
||||
let token = start
|
||||
while (token) {
|
||||
type = token[0]
|
||||
tokens.push(token)
|
||||
|
||||
if (type === '(' || type === '[') {
|
||||
if (!bracket) bracket = token
|
||||
brackets.push(type === '(' ? ')' : ']')
|
||||
} else if (customProperty && colon && type === '{') {
|
||||
if (!bracket) bracket = token
|
||||
brackets.push('}')
|
||||
} else if (brackets.length === 0) {
|
||||
if (type === ';') {
|
||||
if (colon) {
|
||||
this.decl(tokens, customProperty)
|
||||
return
|
||||
} else {
|
||||
break
|
||||
}
|
||||
} else if (type === '{') {
|
||||
this.rule(tokens)
|
||||
return
|
||||
} else if (type === '}') {
|
||||
this.tokenizer.back(tokens.pop())
|
||||
end = true
|
||||
break
|
||||
} else if (type === ':') {
|
||||
colon = true
|
||||
}
|
||||
} else if (type === brackets[brackets.length - 1]) {
|
||||
brackets.pop()
|
||||
if (brackets.length === 0) bracket = null
|
||||
}
|
||||
|
||||
token = this.tokenizer.nextToken()
|
||||
}
|
||||
|
||||
if (this.tokenizer.endOfFile()) end = true
|
||||
if (brackets.length > 0) this.unclosedBracket(bracket)
|
||||
|
||||
if (end && colon) {
|
||||
if (!customProperty) {
|
||||
while (tokens.length) {
|
||||
token = tokens[tokens.length - 1][0]
|
||||
if (token !== 'space' && token !== 'comment') break
|
||||
this.tokenizer.back(tokens.pop())
|
||||
}
|
||||
}
|
||||
this.decl(tokens, customProperty)
|
||||
} else {
|
||||
this.unknownWord(tokens)
|
||||
}
|
||||
}
|
||||
|
||||
parse() {
|
||||
let token
|
||||
while (!this.tokenizer.endOfFile()) {
|
||||
token = this.tokenizer.nextToken()
|
||||
|
||||
switch (token[0]) {
|
||||
case 'space':
|
||||
this.spaces += token[1]
|
||||
break
|
||||
|
||||
case ';':
|
||||
this.freeSemicolon(token)
|
||||
break
|
||||
|
||||
case '}':
|
||||
this.end(token)
|
||||
break
|
||||
|
||||
case 'comment':
|
||||
this.comment(token)
|
||||
break
|
||||
|
||||
case 'at-word':
|
||||
this.atrule(token)
|
||||
break
|
||||
|
||||
case '{':
|
||||
this.emptyRule(token)
|
||||
break
|
||||
|
||||
default:
|
||||
this.other(token)
|
||||
break
|
||||
}
|
||||
}
|
||||
this.endFile()
|
||||
}
|
||||
|
||||
precheckMissedSemicolon(/* tokens */) {
|
||||
// Hook for Safe Parser
|
||||
}
|
||||
|
||||
raw(node, prop, tokens, customProperty) {
|
||||
let token, type
|
||||
let length = tokens.length
|
||||
let value = ''
|
||||
let clean = true
|
||||
let next, prev
|
||||
|
||||
for (let i = 0; i < length; i += 1) {
|
||||
token = tokens[i]
|
||||
type = token[0]
|
||||
if (type === 'space' && i === length - 1 && !customProperty) {
|
||||
clean = false
|
||||
} else if (type === 'comment') {
|
||||
prev = tokens[i - 1] ? tokens[i - 1][0] : 'empty'
|
||||
next = tokens[i + 1] ? tokens[i + 1][0] : 'empty'
|
||||
if (!SAFE_COMMENT_NEIGHBOR[prev] && !SAFE_COMMENT_NEIGHBOR[next]) {
|
||||
if (value.slice(-1) === ',') {
|
||||
clean = false
|
||||
} else {
|
||||
value += token[1]
|
||||
}
|
||||
} else {
|
||||
clean = false
|
||||
}
|
||||
} else {
|
||||
value += token[1]
|
||||
}
|
||||
}
|
||||
if (!clean) {
|
||||
let raw = tokens.reduce((all, i) => all + i[1], '')
|
||||
node.raws[prop] = { raw, value }
|
||||
}
|
||||
node[prop] = value
|
||||
}
|
||||
|
||||
rule(tokens) {
|
||||
tokens.pop()
|
||||
|
||||
let node = new Rule()
|
||||
this.init(node, tokens[0][2])
|
||||
|
||||
node.raws.between = this.spacesAndCommentsFromEnd(tokens)
|
||||
this.raw(node, 'selector', tokens)
|
||||
this.current = node
|
||||
}
|
||||
|
||||
spacesAndCommentsFromEnd(tokens) {
|
||||
let lastTokenType
|
||||
let spaces = ''
|
||||
while (tokens.length) {
|
||||
lastTokenType = tokens[tokens.length - 1][0]
|
||||
if (lastTokenType !== 'space' && lastTokenType !== 'comment') break
|
||||
spaces = tokens.pop()[1] + spaces
|
||||
}
|
||||
return spaces
|
||||
}
|
||||
|
||||
// Errors
|
||||
|
||||
spacesAndCommentsFromStart(tokens) {
|
||||
let next
|
||||
let spaces = ''
|
||||
while (tokens.length) {
|
||||
next = tokens[0][0]
|
||||
if (next !== 'space' && next !== 'comment') break
|
||||
spaces += tokens.shift()[1]
|
||||
}
|
||||
return spaces
|
||||
}
|
||||
|
||||
spacesFromEnd(tokens) {
|
||||
let lastTokenType
|
||||
let spaces = ''
|
||||
while (tokens.length) {
|
||||
lastTokenType = tokens[tokens.length - 1][0]
|
||||
if (lastTokenType !== 'space') break
|
||||
spaces = tokens.pop()[1] + spaces
|
||||
}
|
||||
return spaces
|
||||
}
|
||||
|
||||
stringFrom(tokens, from) {
|
||||
let result = ''
|
||||
for (let i = from; i < tokens.length; i++) {
|
||||
result += tokens[i][1]
|
||||
}
|
||||
tokens.splice(from, tokens.length - from)
|
||||
return result
|
||||
}
|
||||
|
||||
unclosedBlock() {
|
||||
let pos = this.current.source.start
|
||||
throw this.input.error('Unclosed block', pos.line, pos.column)
|
||||
}
|
||||
|
||||
unclosedBracket(bracket) {
|
||||
throw this.input.error(
|
||||
'Unclosed bracket',
|
||||
{ offset: bracket[2] },
|
||||
{ offset: bracket[2] + 1 }
|
||||
)
|
||||
}
|
||||
|
||||
unexpectedClose(token) {
|
||||
throw this.input.error(
|
||||
'Unexpected }',
|
||||
{ offset: token[2] },
|
||||
{ offset: token[2] + 1 }
|
||||
)
|
||||
}
|
||||
|
||||
unknownWord(tokens) {
|
||||
throw this.input.error(
|
||||
'Unknown word',
|
||||
{ offset: tokens[0][2] },
|
||||
{ offset: tokens[0][2] + tokens[0][1].length }
|
||||
)
|
||||
}
|
||||
|
||||
unnamedAtrule(node, token) {
|
||||
throw this.input.error(
|
||||
'At-rule without name',
|
||||
{ offset: token[2] },
|
||||
{ offset: token[2] + token[1].length }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Parser
|
450
node_modules/postcss/lib/postcss.d.ts
generated
vendored
Normal file
450
node_modules/postcss/lib/postcss.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,450 @@
|
|||
import { RawSourceMap, SourceMapGenerator } from 'source-map-js'
|
||||
|
||||
import AtRule, { AtRuleProps } from './at-rule.js'
|
||||
import Comment, { CommentProps } from './comment.js'
|
||||
import Container, { ContainerProps } from './container.js'
|
||||
import CssSyntaxError from './css-syntax-error.js'
|
||||
import Declaration, { DeclarationProps } from './declaration.js'
|
||||
import Document, { DocumentProps } from './document.js'
|
||||
import Input, { FilePosition } from './input.js'
|
||||
import LazyResult from './lazy-result.js'
|
||||
import list from './list.js'
|
||||
import Node, {
|
||||
AnyNode,
|
||||
ChildNode,
|
||||
ChildProps,
|
||||
NodeErrorOptions,
|
||||
NodeProps,
|
||||
Position,
|
||||
Source
|
||||
} from './node.js'
|
||||
import Processor from './processor.js'
|
||||
import Result, { Message } from './result.js'
|
||||
import Root, { RootProps } from './root.js'
|
||||
import Rule, { RuleProps } from './rule.js'
|
||||
import Warning, { WarningOptions } from './warning.js'
|
||||
|
||||
type DocumentProcessor = (
|
||||
document: Document,
|
||||
helper: postcss.Helpers
|
||||
) => Promise<void> | void
|
||||
type RootProcessor = (
|
||||
root: Root,
|
||||
helper: postcss.Helpers
|
||||
) => Promise<void> | void
|
||||
type DeclarationProcessor = (
|
||||
decl: Declaration,
|
||||
helper: postcss.Helpers
|
||||
) => Promise<void> | void
|
||||
type RuleProcessor = (
|
||||
rule: Rule,
|
||||
helper: postcss.Helpers
|
||||
) => Promise<void> | void
|
||||
type AtRuleProcessor = (
|
||||
atRule: AtRule,
|
||||
helper: postcss.Helpers
|
||||
) => Promise<void> | void
|
||||
type CommentProcessor = (
|
||||
comment: Comment,
|
||||
helper: postcss.Helpers
|
||||
) => Promise<void> | void
|
||||
|
||||
interface Processors {
|
||||
/**
|
||||
* Will be called on all`AtRule` nodes.
|
||||
*
|
||||
* Will be called again on node or children changes.
|
||||
*/
|
||||
AtRule?: { [name: string]: AtRuleProcessor } | AtRuleProcessor
|
||||
|
||||
/**
|
||||
* Will be called on all `AtRule` nodes, when all children will be processed.
|
||||
*
|
||||
* Will be called again on node or children changes.
|
||||
*/
|
||||
AtRuleExit?: { [name: string]: AtRuleProcessor } | AtRuleProcessor
|
||||
|
||||
/**
|
||||
* Will be called on all `Comment` nodes.
|
||||
*
|
||||
* Will be called again on node or children changes.
|
||||
*/
|
||||
Comment?: CommentProcessor
|
||||
|
||||
/**
|
||||
* Will be called on all `Comment` nodes after listeners
|
||||
* for `Comment` event.
|
||||
*
|
||||
* Will be called again on node or children changes.
|
||||
*/
|
||||
CommentExit?: CommentProcessor
|
||||
|
||||
/**
|
||||
* Will be called on all `Declaration` nodes after listeners
|
||||
* for `Declaration` event.
|
||||
*
|
||||
* Will be called again on node or children changes.
|
||||
*/
|
||||
Declaration?: { [prop: string]: DeclarationProcessor } | DeclarationProcessor
|
||||
|
||||
/**
|
||||
* Will be called on all `Declaration` nodes.
|
||||
*
|
||||
* Will be called again on node or children changes.
|
||||
*/
|
||||
DeclarationExit?:
|
||||
| { [prop: string]: DeclarationProcessor }
|
||||
| DeclarationProcessor
|
||||
|
||||
/**
|
||||
* Will be called on `Document` node.
|
||||
*
|
||||
* Will be called again on children changes.
|
||||
*/
|
||||
Document?: DocumentProcessor
|
||||
|
||||
/**
|
||||
* Will be called on `Document` node, when all children will be processed.
|
||||
*
|
||||
* Will be called again on children changes.
|
||||
*/
|
||||
DocumentExit?: DocumentProcessor
|
||||
|
||||
/**
|
||||
* Will be called on `Root` node once.
|
||||
*/
|
||||
Once?: RootProcessor
|
||||
|
||||
/**
|
||||
* Will be called on `Root` node once, when all children will be processed.
|
||||
*/
|
||||
OnceExit?: RootProcessor
|
||||
|
||||
/**
|
||||
* Will be called on `Root` node.
|
||||
*
|
||||
* Will be called again on children changes.
|
||||
*/
|
||||
Root?: RootProcessor
|
||||
|
||||
/**
|
||||
* Will be called on `Root` node, when all children will be processed.
|
||||
*
|
||||
* Will be called again on children changes.
|
||||
*/
|
||||
RootExit?: RootProcessor
|
||||
|
||||
/**
|
||||
* Will be called on all `Rule` nodes.
|
||||
*
|
||||
* Will be called again on node or children changes.
|
||||
*/
|
||||
Rule?: RuleProcessor
|
||||
|
||||
/**
|
||||
* Will be called on all `Rule` nodes, when all children will be processed.
|
||||
*
|
||||
* Will be called again on node or children changes.
|
||||
*/
|
||||
RuleExit?: RuleProcessor
|
||||
}
|
||||
|
||||
declare namespace postcss {
|
||||
export {
|
||||
AnyNode,
|
||||
AtRule,
|
||||
AtRuleProps,
|
||||
ChildNode,
|
||||
ChildProps,
|
||||
Comment,
|
||||
CommentProps,
|
||||
Container,
|
||||
ContainerProps,
|
||||
CssSyntaxError,
|
||||
Declaration,
|
||||
DeclarationProps,
|
||||
Document,
|
||||
DocumentProps,
|
||||
FilePosition,
|
||||
Input,
|
||||
LazyResult,
|
||||
list,
|
||||
Message,
|
||||
Node,
|
||||
NodeErrorOptions,
|
||||
NodeProps,
|
||||
Position,
|
||||
Processor,
|
||||
Result,
|
||||
Root,
|
||||
RootProps,
|
||||
Rule,
|
||||
RuleProps,
|
||||
Source,
|
||||
Warning,
|
||||
WarningOptions
|
||||
}
|
||||
|
||||
export type SourceMap = {
|
||||
toJSON(): RawSourceMap
|
||||
} & SourceMapGenerator
|
||||
|
||||
export type Helpers = { postcss: Postcss; result: Result } & Postcss
|
||||
|
||||
export interface Plugin extends Processors {
|
||||
postcssPlugin: string
|
||||
prepare?: (result: Result) => Processors
|
||||
}
|
||||
|
||||
export interface PluginCreator<PluginOptions> {
|
||||
(opts?: PluginOptions): Plugin | Processor
|
||||
postcss: true
|
||||
}
|
||||
|
||||
export interface Transformer extends TransformCallback {
|
||||
postcssPlugin: string
|
||||
postcssVersion: string
|
||||
}
|
||||
|
||||
export interface TransformCallback {
|
||||
(root: Root, result: Result): Promise<void> | void
|
||||
}
|
||||
|
||||
export interface OldPlugin<T> extends Transformer {
|
||||
(opts?: T): Transformer
|
||||
postcss: Transformer
|
||||
}
|
||||
|
||||
export type AcceptedPlugin =
|
||||
| {
|
||||
postcss: Processor | TransformCallback
|
||||
}
|
||||
| OldPlugin<any>
|
||||
| Plugin
|
||||
| PluginCreator<any>
|
||||
| Processor
|
||||
| TransformCallback
|
||||
|
||||
export interface Parser<RootNode = Document | Root> {
|
||||
(
|
||||
css: { toString(): string } | string,
|
||||
opts?: Pick<ProcessOptions, 'from' | 'map'>
|
||||
): RootNode
|
||||
}
|
||||
|
||||
export interface Builder {
|
||||
(part: string, node?: AnyNode, type?: 'end' | 'start'): void
|
||||
}
|
||||
|
||||
export interface Stringifier {
|
||||
(node: AnyNode, builder: Builder): void
|
||||
}
|
||||
|
||||
export interface JSONHydrator {
|
||||
(data: object): Node
|
||||
(data: object[]): Node[]
|
||||
}
|
||||
|
||||
export interface Syntax<RootNode = Document | Root> {
|
||||
/**
|
||||
* Function to generate AST by string.
|
||||
*/
|
||||
parse?: Parser<RootNode>
|
||||
|
||||
/**
|
||||
* Class to generate string by AST.
|
||||
*/
|
||||
stringify?: Stringifier
|
||||
}
|
||||
|
||||
export interface SourceMapOptions {
|
||||
/**
|
||||
* Use absolute path in generated source map.
|
||||
*/
|
||||
absolute?: boolean
|
||||
|
||||
/**
|
||||
* Indicates that PostCSS should add annotation comments to the CSS.
|
||||
* By default, PostCSS will always add a comment with a path
|
||||
* to the source map. PostCSS will not add annotations to CSS files
|
||||
* that do not contain any comments.
|
||||
*
|
||||
* By default, PostCSS presumes that you want to save the source map as
|
||||
* `opts.to + '.map'` and will use this path in the annotation comment.
|
||||
* A different path can be set by providing a string value for annotation.
|
||||
*
|
||||
* If you have set `inline: true`, annotation cannot be disabled.
|
||||
*/
|
||||
annotation?: ((file: string, root: Root) => string) | boolean | string
|
||||
|
||||
/**
|
||||
* Override `from` in map’s sources.
|
||||
*/
|
||||
from?: string
|
||||
|
||||
/**
|
||||
* Indicates that the source map should be embedded in the output CSS
|
||||
* as a Base64-encoded comment. By default, it is `true`.
|
||||
* But if all previous maps are external, not inline, PostCSS will not embed
|
||||
* the map even if you do not set this option.
|
||||
*
|
||||
* If you have an inline source map, the result.map property will be empty,
|
||||
* as the source map will be contained within the text of `result.css`.
|
||||
*/
|
||||
inline?: boolean
|
||||
|
||||
/**
|
||||
* Source map content from a previous processing step (e.g., Sass).
|
||||
*
|
||||
* PostCSS will try to read the previous source map
|
||||
* automatically (based on comments within the source CSS), but you can use
|
||||
* this option to identify it manually.
|
||||
*
|
||||
* If desired, you can omit the previous map with prev: `false`.
|
||||
*/
|
||||
prev?: ((file: string) => string) | boolean | object | string
|
||||
|
||||
/**
|
||||
* Indicates that PostCSS should set the origin content (e.g., Sass source)
|
||||
* of the source map. By default, it is true. But if all previous maps do not
|
||||
* contain sources content, PostCSS will also leave it out even if you
|
||||
* do not set this option.
|
||||
*/
|
||||
sourcesContent?: boolean
|
||||
}
|
||||
|
||||
export interface ProcessOptions<RootNode = Document | Root> {
|
||||
/**
|
||||
* The path of the CSS source file. You should always set `from`,
|
||||
* because it is used in source map generation and syntax error messages.
|
||||
*/
|
||||
from?: string | undefined
|
||||
|
||||
/**
|
||||
* Source map options
|
||||
*/
|
||||
map?: boolean | SourceMapOptions
|
||||
|
||||
/**
|
||||
* Function to generate AST by string.
|
||||
*/
|
||||
parser?: Parser<RootNode> | Syntax<RootNode>
|
||||
|
||||
/**
|
||||
* Class to generate string by AST.
|
||||
*/
|
||||
stringifier?: Stringifier | Syntax<RootNode>
|
||||
|
||||
/**
|
||||
* Object with parse and stringify.
|
||||
*/
|
||||
syntax?: Syntax<RootNode>
|
||||
|
||||
/**
|
||||
* The path where you'll put the output CSS file. You should always set `to`
|
||||
* to generate correct source maps.
|
||||
*/
|
||||
to?: string
|
||||
}
|
||||
|
||||
export type Postcss = typeof postcss
|
||||
|
||||
/**
|
||||
* Default function to convert a node tree into a CSS string.
|
||||
*/
|
||||
export let stringify: Stringifier
|
||||
|
||||
/**
|
||||
* Parses source css and returns a new `Root` or `Document` node,
|
||||
* which contains the source CSS nodes.
|
||||
*
|
||||
* ```js
|
||||
* // Simple CSS concatenation with source map support
|
||||
* const root1 = postcss.parse(css1, { from: file1 })
|
||||
* const root2 = postcss.parse(css2, { from: file2 })
|
||||
* root1.append(root2).toResult().css
|
||||
* ```
|
||||
*/
|
||||
export let parse: Parser<Root>
|
||||
|
||||
/**
|
||||
* Rehydrate a JSON AST (from `Node#toJSON`) back into the AST classes.
|
||||
*
|
||||
* ```js
|
||||
* const json = root.toJSON()
|
||||
* // save to file, send by network, etc
|
||||
* const root2 = postcss.fromJSON(json)
|
||||
* ```
|
||||
*/
|
||||
export let fromJSON: JSONHydrator
|
||||
|
||||
/**
|
||||
* Creates a new `Comment` node.
|
||||
*
|
||||
* @param defaults Properties for the new node.
|
||||
* @return New comment node
|
||||
*/
|
||||
export function comment(defaults?: CommentProps): Comment
|
||||
|
||||
/**
|
||||
* Creates a new `AtRule` node.
|
||||
*
|
||||
* @param defaults Properties for the new node.
|
||||
* @return New at-rule node.
|
||||
*/
|
||||
export function atRule(defaults?: AtRuleProps): AtRule
|
||||
|
||||
/**
|
||||
* Creates a new `Declaration` node.
|
||||
*
|
||||
* @param defaults Properties for the new node.
|
||||
* @return New declaration node.
|
||||
*/
|
||||
export function decl(defaults?: DeclarationProps): Declaration
|
||||
|
||||
/**
|
||||
* Creates a new `Rule` node.
|
||||
*
|
||||
* @param default Properties for the new node.
|
||||
* @return New rule node.
|
||||
*/
|
||||
export function rule(defaults?: RuleProps): Rule
|
||||
|
||||
/**
|
||||
* Creates a new `Root` node.
|
||||
*
|
||||
* @param defaults Properties for the new node.
|
||||
* @return New root node.
|
||||
*/
|
||||
export function root(defaults?: RootProps): Root
|
||||
|
||||
/**
|
||||
* Creates a new `Document` node.
|
||||
*
|
||||
* @param defaults Properties for the new node.
|
||||
* @return New document node.
|
||||
*/
|
||||
export function document(defaults?: DocumentProps): Document
|
||||
|
||||
export { postcss as default }
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new `Processor` instance that will apply `plugins`
|
||||
* as CSS processors.
|
||||
*
|
||||
* ```js
|
||||
* let postcss = require('postcss')
|
||||
*
|
||||
* postcss(plugins).process(css, { from, to }).then(result => {
|
||||
* console.log(result.css)
|
||||
* })
|
||||
* ```
|
||||
*
|
||||
* @param plugins PostCSS plugins.
|
||||
* @return Processor to process multiple CSS.
|
||||
*/
|
||||
declare function postcss(plugins?: postcss.AcceptedPlugin[]): Processor
|
||||
declare function postcss(...plugins: postcss.AcceptedPlugin[]): Processor
|
||||
|
||||
export = postcss
|
101
node_modules/postcss/lib/postcss.js
generated
vendored
Normal file
101
node_modules/postcss/lib/postcss.js
generated
vendored
Normal file
|
@ -0,0 +1,101 @@
|
|||
'use strict'
|
||||
|
||||
let CssSyntaxError = require('./css-syntax-error')
|
||||
let Declaration = require('./declaration')
|
||||
let LazyResult = require('./lazy-result')
|
||||
let Container = require('./container')
|
||||
let Processor = require('./processor')
|
||||
let stringify = require('./stringify')
|
||||
let fromJSON = require('./fromJSON')
|
||||
let Document = require('./document')
|
||||
let Warning = require('./warning')
|
||||
let Comment = require('./comment')
|
||||
let AtRule = require('./at-rule')
|
||||
let Result = require('./result.js')
|
||||
let Input = require('./input')
|
||||
let parse = require('./parse')
|
||||
let list = require('./list')
|
||||
let Rule = require('./rule')
|
||||
let Root = require('./root')
|
||||
let Node = require('./node')
|
||||
|
||||
function postcss(...plugins) {
|
||||
if (plugins.length === 1 && Array.isArray(plugins[0])) {
|
||||
plugins = plugins[0]
|
||||
}
|
||||
return new Processor(plugins)
|
||||
}
|
||||
|
||||
postcss.plugin = function plugin(name, initializer) {
|
||||
let warningPrinted = false
|
||||
function creator(...args) {
|
||||
// eslint-disable-next-line no-console
|
||||
if (console && console.warn && !warningPrinted) {
|
||||
warningPrinted = true
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(
|
||||
name +
|
||||
': postcss.plugin was deprecated. Migration guide:\n' +
|
||||
'https://evilmartians.com/chronicles/postcss-8-plugin-migration'
|
||||
)
|
||||
if (process.env.LANG && process.env.LANG.startsWith('cn')) {
|
||||
/* c8 ignore next 7 */
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(
|
||||
name +
|
||||
': 里面 postcss.plugin 被弃用. 迁移指南:\n' +
|
||||
'https://www.w3ctech.com/topic/2226'
|
||||
)
|
||||
}
|
||||
}
|
||||
let transformer = initializer(...args)
|
||||
transformer.postcssPlugin = name
|
||||
transformer.postcssVersion = new Processor().version
|
||||
return transformer
|
||||
}
|
||||
|
||||
let cache
|
||||
Object.defineProperty(creator, 'postcss', {
|
||||
get() {
|
||||
if (!cache) cache = creator()
|
||||
return cache
|
||||
}
|
||||
})
|
||||
|
||||
creator.process = function (css, processOpts, pluginOpts) {
|
||||
return postcss([creator(pluginOpts)]).process(css, processOpts)
|
||||
}
|
||||
|
||||
return creator
|
||||
}
|
||||
|
||||
postcss.stringify = stringify
|
||||
postcss.parse = parse
|
||||
postcss.fromJSON = fromJSON
|
||||
postcss.list = list
|
||||
|
||||
postcss.comment = defaults => new Comment(defaults)
|
||||
postcss.atRule = defaults => new AtRule(defaults)
|
||||
postcss.decl = defaults => new Declaration(defaults)
|
||||
postcss.rule = defaults => new Rule(defaults)
|
||||
postcss.root = defaults => new Root(defaults)
|
||||
postcss.document = defaults => new Document(defaults)
|
||||
|
||||
postcss.CssSyntaxError = CssSyntaxError
|
||||
postcss.Declaration = Declaration
|
||||
postcss.Container = Container
|
||||
postcss.Processor = Processor
|
||||
postcss.Document = Document
|
||||
postcss.Comment = Comment
|
||||
postcss.Warning = Warning
|
||||
postcss.AtRule = AtRule
|
||||
postcss.Result = Result
|
||||
postcss.Input = Input
|
||||
postcss.Rule = Rule
|
||||
postcss.Root = Root
|
||||
postcss.Node = Node
|
||||
|
||||
LazyResult.registerPostcss(postcss)
|
||||
|
||||
module.exports = postcss
|
||||
postcss.default = postcss
|
144
node_modules/postcss/lib/previous-map.js
generated
vendored
Normal file
144
node_modules/postcss/lib/previous-map.js
generated
vendored
Normal file
|
@ -0,0 +1,144 @@
|
|||
'use strict'
|
||||
|
||||
let { SourceMapConsumer, SourceMapGenerator } = require('source-map-js')
|
||||
let { existsSync, readFileSync } = require('fs')
|
||||
let { dirname, join } = require('path')
|
||||
|
||||
function fromBase64(str) {
|
||||
if (Buffer) {
|
||||
return Buffer.from(str, 'base64').toString()
|
||||
} else {
|
||||
/* c8 ignore next 2 */
|
||||
return window.atob(str)
|
||||
}
|
||||
}
|
||||
|
||||
class PreviousMap {
|
||||
constructor(css, opts) {
|
||||
if (opts.map === false) return
|
||||
this.loadAnnotation(css)
|
||||
this.inline = this.startWith(this.annotation, 'data:')
|
||||
|
||||
let prev = opts.map ? opts.map.prev : undefined
|
||||
let text = this.loadMap(opts.from, prev)
|
||||
if (!this.mapFile && opts.from) {
|
||||
this.mapFile = opts.from
|
||||
}
|
||||
if (this.mapFile) this.root = dirname(this.mapFile)
|
||||
if (text) this.text = text
|
||||
}
|
||||
|
||||
consumer() {
|
||||
if (!this.consumerCache) {
|
||||
this.consumerCache = new SourceMapConsumer(this.text)
|
||||
}
|
||||
return this.consumerCache
|
||||
}
|
||||
|
||||
decodeInline(text) {
|
||||
let baseCharsetUri = /^data:application\/json;charset=utf-?8;base64,/
|
||||
let baseUri = /^data:application\/json;base64,/
|
||||
let charsetUri = /^data:application\/json;charset=utf-?8,/
|
||||
let uri = /^data:application\/json,/
|
||||
|
||||
let uriMatch = text.match(charsetUri) || text.match(uri)
|
||||
if (uriMatch) {
|
||||
return decodeURIComponent(text.substr(uriMatch[0].length))
|
||||
}
|
||||
|
||||
let baseUriMatch = text.match(baseCharsetUri) || text.match(baseUri)
|
||||
if (baseUriMatch) {
|
||||
return fromBase64(text.substr(baseUriMatch[0].length))
|
||||
}
|
||||
|
||||
let encoding = text.match(/data:application\/json;([^,]+),/)[1]
|
||||
throw new Error('Unsupported source map encoding ' + encoding)
|
||||
}
|
||||
|
||||
getAnnotationURL(sourceMapString) {
|
||||
return sourceMapString.replace(/^\/\*\s*# sourceMappingURL=/, '').trim()
|
||||
}
|
||||
|
||||
isMap(map) {
|
||||
if (typeof map !== 'object') return false
|
||||
return (
|
||||
typeof map.mappings === 'string' ||
|
||||
typeof map._mappings === 'string' ||
|
||||
Array.isArray(map.sections)
|
||||
)
|
||||
}
|
||||
|
||||
loadAnnotation(css) {
|
||||
let comments = css.match(/\/\*\s*# sourceMappingURL=/g)
|
||||
if (!comments) return
|
||||
|
||||
// sourceMappingURLs from comments, strings, etc.
|
||||
let start = css.lastIndexOf(comments.pop())
|
||||
let end = css.indexOf('*/', start)
|
||||
|
||||
if (start > -1 && end > -1) {
|
||||
// Locate the last sourceMappingURL to avoid pickin
|
||||
this.annotation = this.getAnnotationURL(css.substring(start, end))
|
||||
}
|
||||
}
|
||||
|
||||
loadFile(path) {
|
||||
this.root = dirname(path)
|
||||
if (existsSync(path)) {
|
||||
this.mapFile = path
|
||||
return readFileSync(path, 'utf-8').toString().trim()
|
||||
}
|
||||
}
|
||||
|
||||
loadMap(file, prev) {
|
||||
if (prev === false) return false
|
||||
|
||||
if (prev) {
|
||||
if (typeof prev === 'string') {
|
||||
return prev
|
||||
} else if (typeof prev === 'function') {
|
||||
let prevPath = prev(file)
|
||||
if (prevPath) {
|
||||
let map = this.loadFile(prevPath)
|
||||
if (!map) {
|
||||
throw new Error(
|
||||
'Unable to load previous source map: ' + prevPath.toString()
|
||||
)
|
||||
}
|
||||
return map
|
||||
}
|
||||
} else if (prev instanceof SourceMapConsumer) {
|
||||
return SourceMapGenerator.fromSourceMap(prev).toString()
|
||||
} else if (prev instanceof SourceMapGenerator) {
|
||||
return prev.toString()
|
||||
} else if (this.isMap(prev)) {
|
||||
return JSON.stringify(prev)
|
||||
} else {
|
||||
throw new Error(
|
||||
'Unsupported previous source map format: ' + prev.toString()
|
||||
)
|
||||
}
|
||||
} else if (this.inline) {
|
||||
return this.decodeInline(this.annotation)
|
||||
} else if (this.annotation) {
|
||||
let map = this.annotation
|
||||
if (file) map = join(dirname(file), map)
|
||||
return this.loadFile(map)
|
||||
}
|
||||
}
|
||||
|
||||
startWith(string, start) {
|
||||
if (!string) return false
|
||||
return string.substr(0, start.length) === start
|
||||
}
|
||||
|
||||
withContent() {
|
||||
return !!(
|
||||
this.consumer().sourcesContent &&
|
||||
this.consumer().sourcesContent.length > 0
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = PreviousMap
|
||||
PreviousMap.default = PreviousMap
|
67
node_modules/postcss/lib/processor.js
generated
vendored
Normal file
67
node_modules/postcss/lib/processor.js
generated
vendored
Normal file
|
@ -0,0 +1,67 @@
|
|||
'use strict'
|
||||
|
||||
let NoWorkResult = require('./no-work-result')
|
||||
let LazyResult = require('./lazy-result')
|
||||
let Document = require('./document')
|
||||
let Root = require('./root')
|
||||
|
||||
class Processor {
|
||||
constructor(plugins = []) {
|
||||
this.version = '8.4.41'
|
||||
this.plugins = this.normalize(plugins)
|
||||
}
|
||||
|
||||
normalize(plugins) {
|
||||
let normalized = []
|
||||
for (let i of plugins) {
|
||||
if (i.postcss === true) {
|
||||
i = i()
|
||||
} else if (i.postcss) {
|
||||
i = i.postcss
|
||||
}
|
||||
|
||||
if (typeof i === 'object' && Array.isArray(i.plugins)) {
|
||||
normalized = normalized.concat(i.plugins)
|
||||
} else if (typeof i === 'object' && i.postcssPlugin) {
|
||||
normalized.push(i)
|
||||
} else if (typeof i === 'function') {
|
||||
normalized.push(i)
|
||||
} else if (typeof i === 'object' && (i.parse || i.stringify)) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
throw new Error(
|
||||
'PostCSS syntaxes cannot be used as plugins. Instead, please use ' +
|
||||
'one of the syntax/parser/stringifier options as outlined ' +
|
||||
'in your PostCSS runner documentation.'
|
||||
)
|
||||
}
|
||||
} else {
|
||||
throw new Error(i + ' is not a PostCSS plugin')
|
||||
}
|
||||
}
|
||||
return normalized
|
||||
}
|
||||
|
||||
process(css, opts = {}) {
|
||||
if (
|
||||
!this.plugins.length &&
|
||||
!opts.parser &&
|
||||
!opts.stringifier &&
|
||||
!opts.syntax
|
||||
) {
|
||||
return new NoWorkResult(this, css, opts)
|
||||
} else {
|
||||
return new LazyResult(this, css, opts)
|
||||
}
|
||||
}
|
||||
|
||||
use(plugin) {
|
||||
this.plugins = this.plugins.concat(this.normalize([plugin]))
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Processor
|
||||
Processor.default = Processor
|
||||
|
||||
Root.registerProcessor(Processor)
|
||||
Document.registerProcessor(Processor)
|
42
node_modules/postcss/lib/result.js
generated
vendored
Normal file
42
node_modules/postcss/lib/result.js
generated
vendored
Normal file
|
@ -0,0 +1,42 @@
|
|||
'use strict'
|
||||
|
||||
let Warning = require('./warning')
|
||||
|
||||
class Result {
|
||||
constructor(processor, root, opts) {
|
||||
this.processor = processor
|
||||
this.messages = []
|
||||
this.root = root
|
||||
this.opts = opts
|
||||
this.css = undefined
|
||||
this.map = undefined
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.css
|
||||
}
|
||||
|
||||
warn(text, opts = {}) {
|
||||
if (!opts.plugin) {
|
||||
if (this.lastPlugin && this.lastPlugin.postcssPlugin) {
|
||||
opts.plugin = this.lastPlugin.postcssPlugin
|
||||
}
|
||||
}
|
||||
|
||||
let warning = new Warning(text, opts)
|
||||
this.messages.push(warning)
|
||||
|
||||
return warning
|
||||
}
|
||||
|
||||
warnings() {
|
||||
return this.messages.filter(i => i.type === 'warning')
|
||||
}
|
||||
|
||||
get content() {
|
||||
return this.css
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Result
|
||||
Result.default = Result
|
61
node_modules/postcss/lib/root.js
generated
vendored
Normal file
61
node_modules/postcss/lib/root.js
generated
vendored
Normal file
|
@ -0,0 +1,61 @@
|
|||
'use strict'
|
||||
|
||||
let Container = require('./container')
|
||||
|
||||
let LazyResult, Processor
|
||||
|
||||
class Root extends Container {
|
||||
constructor(defaults) {
|
||||
super(defaults)
|
||||
this.type = 'root'
|
||||
if (!this.nodes) this.nodes = []
|
||||
}
|
||||
|
||||
normalize(child, sample, type) {
|
||||
let nodes = super.normalize(child)
|
||||
|
||||
if (sample) {
|
||||
if (type === 'prepend') {
|
||||
if (this.nodes.length > 1) {
|
||||
sample.raws.before = this.nodes[1].raws.before
|
||||
} else {
|
||||
delete sample.raws.before
|
||||
}
|
||||
} else if (this.first !== sample) {
|
||||
for (let node of nodes) {
|
||||
node.raws.before = sample.raws.before
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nodes
|
||||
}
|
||||
|
||||
removeChild(child, ignore) {
|
||||
let index = this.index(child)
|
||||
|
||||
if (!ignore && index === 0 && this.nodes.length > 1) {
|
||||
this.nodes[1].raws.before = this.nodes[index].raws.before
|
||||
}
|
||||
|
||||
return super.removeChild(child)
|
||||
}
|
||||
|
||||
toResult(opts = {}) {
|
||||
let lazy = new LazyResult(new Processor(), this, opts)
|
||||
return lazy.stringify()
|
||||
}
|
||||
}
|
||||
|
||||
Root.registerLazyResult = dependant => {
|
||||
LazyResult = dependant
|
||||
}
|
||||
|
||||
Root.registerProcessor = dependant => {
|
||||
Processor = dependant
|
||||
}
|
||||
|
||||
module.exports = Root
|
||||
Root.default = Root
|
||||
|
||||
Container.registerRoot(Root)
|
27
node_modules/postcss/lib/rule.js
generated
vendored
Normal file
27
node_modules/postcss/lib/rule.js
generated
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
'use strict'
|
||||
|
||||
let Container = require('./container')
|
||||
let list = require('./list')
|
||||
|
||||
class Rule extends Container {
|
||||
constructor(defaults) {
|
||||
super(defaults)
|
||||
this.type = 'rule'
|
||||
if (!this.nodes) this.nodes = []
|
||||
}
|
||||
|
||||
get selectors() {
|
||||
return list.comma(this.selector)
|
||||
}
|
||||
|
||||
set selectors(values) {
|
||||
let match = this.selector ? this.selector.match(/,\s*/) : null
|
||||
let sep = match ? match[0] : ',' + this.raw('between', 'beforeOpen')
|
||||
this.selector = values.join(sep)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Rule
|
||||
Rule.default = Rule
|
||||
|
||||
Container.registerRule(Rule)
|
353
node_modules/postcss/lib/stringifier.js
generated
vendored
Normal file
353
node_modules/postcss/lib/stringifier.js
generated
vendored
Normal file
|
@ -0,0 +1,353 @@
|
|||
'use strict'
|
||||
|
||||
const DEFAULT_RAW = {
|
||||
after: '\n',
|
||||
beforeClose: '\n',
|
||||
beforeComment: '\n',
|
||||
beforeDecl: '\n',
|
||||
beforeOpen: ' ',
|
||||
beforeRule: '\n',
|
||||
colon: ': ',
|
||||
commentLeft: ' ',
|
||||
commentRight: ' ',
|
||||
emptyBody: '',
|
||||
indent: ' ',
|
||||
semicolon: false
|
||||
}
|
||||
|
||||
function capitalize(str) {
|
||||
return str[0].toUpperCase() + str.slice(1)
|
||||
}
|
||||
|
||||
class Stringifier {
|
||||
constructor(builder) {
|
||||
this.builder = builder
|
||||
}
|
||||
|
||||
atrule(node, semicolon) {
|
||||
let name = '@' + node.name
|
||||
let params = node.params ? this.rawValue(node, 'params') : ''
|
||||
|
||||
if (typeof node.raws.afterName !== 'undefined') {
|
||||
name += node.raws.afterName
|
||||
} else if (params) {
|
||||
name += ' '
|
||||
}
|
||||
|
||||
if (node.nodes) {
|
||||
this.block(node, name + params)
|
||||
} else {
|
||||
let end = (node.raws.between || '') + (semicolon ? ';' : '')
|
||||
this.builder(name + params + end, node)
|
||||
}
|
||||
}
|
||||
|
||||
beforeAfter(node, detect) {
|
||||
let value
|
||||
if (node.type === 'decl') {
|
||||
value = this.raw(node, null, 'beforeDecl')
|
||||
} else if (node.type === 'comment') {
|
||||
value = this.raw(node, null, 'beforeComment')
|
||||
} else if (detect === 'before') {
|
||||
value = this.raw(node, null, 'beforeRule')
|
||||
} else {
|
||||
value = this.raw(node, null, 'beforeClose')
|
||||
}
|
||||
|
||||
let buf = node.parent
|
||||
let depth = 0
|
||||
while (buf && buf.type !== 'root') {
|
||||
depth += 1
|
||||
buf = buf.parent
|
||||
}
|
||||
|
||||
if (value.includes('\n')) {
|
||||
let indent = this.raw(node, null, 'indent')
|
||||
if (indent.length) {
|
||||
for (let step = 0; step < depth; step++) value += indent
|
||||
}
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
block(node, start) {
|
||||
let between = this.raw(node, 'between', 'beforeOpen')
|
||||
this.builder(start + between + '{', node, 'start')
|
||||
|
||||
let after
|
||||
if (node.nodes && node.nodes.length) {
|
||||
this.body(node)
|
||||
after = this.raw(node, 'after')
|
||||
} else {
|
||||
after = this.raw(node, 'after', 'emptyBody')
|
||||
}
|
||||
|
||||
if (after) this.builder(after)
|
||||
this.builder('}', node, 'end')
|
||||
}
|
||||
|
||||
body(node) {
|
||||
let last = node.nodes.length - 1
|
||||
while (last > 0) {
|
||||
if (node.nodes[last].type !== 'comment') break
|
||||
last -= 1
|
||||
}
|
||||
|
||||
let semicolon = this.raw(node, 'semicolon')
|
||||
for (let i = 0; i < node.nodes.length; i++) {
|
||||
let child = node.nodes[i]
|
||||
let before = this.raw(child, 'before')
|
||||
if (before) this.builder(before)
|
||||
this.stringify(child, last !== i || semicolon)
|
||||
}
|
||||
}
|
||||
|
||||
comment(node) {
|
||||
let left = this.raw(node, 'left', 'commentLeft')
|
||||
let right = this.raw(node, 'right', 'commentRight')
|
||||
this.builder('/*' + left + node.text + right + '*/', node)
|
||||
}
|
||||
|
||||
decl(node, semicolon) {
|
||||
let between = this.raw(node, 'between', 'colon')
|
||||
let string = node.prop + between + this.rawValue(node, 'value')
|
||||
|
||||
if (node.important) {
|
||||
string += node.raws.important || ' !important'
|
||||
}
|
||||
|
||||
if (semicolon) string += ';'
|
||||
this.builder(string, node)
|
||||
}
|
||||
|
||||
document(node) {
|
||||
this.body(node)
|
||||
}
|
||||
|
||||
raw(node, own, detect) {
|
||||
let value
|
||||
if (!detect) detect = own
|
||||
|
||||
// Already had
|
||||
if (own) {
|
||||
value = node.raws[own]
|
||||
if (typeof value !== 'undefined') return value
|
||||
}
|
||||
|
||||
let parent = node.parent
|
||||
|
||||
if (detect === 'before') {
|
||||
// Hack for first rule in CSS
|
||||
if (!parent || (parent.type === 'root' && parent.first === node)) {
|
||||
return ''
|
||||
}
|
||||
|
||||
// `root` nodes in `document` should use only their own raws
|
||||
if (parent && parent.type === 'document') {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
// Floating child without parent
|
||||
if (!parent) return DEFAULT_RAW[detect]
|
||||
|
||||
// Detect style by other nodes
|
||||
let root = node.root()
|
||||
if (!root.rawCache) root.rawCache = {}
|
||||
if (typeof root.rawCache[detect] !== 'undefined') {
|
||||
return root.rawCache[detect]
|
||||
}
|
||||
|
||||
if (detect === 'before' || detect === 'after') {
|
||||
return this.beforeAfter(node, detect)
|
||||
} else {
|
||||
let method = 'raw' + capitalize(detect)
|
||||
if (this[method]) {
|
||||
value = this[method](root, node)
|
||||
} else {
|
||||
root.walk(i => {
|
||||
value = i.raws[own]
|
||||
if (typeof value !== 'undefined') return false
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof value === 'undefined') value = DEFAULT_RAW[detect]
|
||||
|
||||
root.rawCache[detect] = value
|
||||
return value
|
||||
}
|
||||
|
||||
rawBeforeClose(root) {
|
||||
let value
|
||||
root.walk(i => {
|
||||
if (i.nodes && i.nodes.length > 0) {
|
||||
if (typeof i.raws.after !== 'undefined') {
|
||||
value = i.raws.after
|
||||
if (value.includes('\n')) {
|
||||
value = value.replace(/[^\n]+$/, '')
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
})
|
||||
if (value) value = value.replace(/\S/g, '')
|
||||
return value
|
||||
}
|
||||
|
||||
rawBeforeComment(root, node) {
|
||||
let value
|
||||
root.walkComments(i => {
|
||||
if (typeof i.raws.before !== 'undefined') {
|
||||
value = i.raws.before
|
||||
if (value.includes('\n')) {
|
||||
value = value.replace(/[^\n]+$/, '')
|
||||
}
|
||||
return false
|
||||
}
|
||||
})
|
||||
if (typeof value === 'undefined') {
|
||||
value = this.raw(node, null, 'beforeDecl')
|
||||
} else if (value) {
|
||||
value = value.replace(/\S/g, '')
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
rawBeforeDecl(root, node) {
|
||||
let value
|
||||
root.walkDecls(i => {
|
||||
if (typeof i.raws.before !== 'undefined') {
|
||||
value = i.raws.before
|
||||
if (value.includes('\n')) {
|
||||
value = value.replace(/[^\n]+$/, '')
|
||||
}
|
||||
return false
|
||||
}
|
||||
})
|
||||
if (typeof value === 'undefined') {
|
||||
value = this.raw(node, null, 'beforeRule')
|
||||
} else if (value) {
|
||||
value = value.replace(/\S/g, '')
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
rawBeforeOpen(root) {
|
||||
let value
|
||||
root.walk(i => {
|
||||
if (i.type !== 'decl') {
|
||||
value = i.raws.between
|
||||
if (typeof value !== 'undefined') return false
|
||||
}
|
||||
})
|
||||
return value
|
||||
}
|
||||
|
||||
rawBeforeRule(root) {
|
||||
let value
|
||||
root.walk(i => {
|
||||
if (i.nodes && (i.parent !== root || root.first !== i)) {
|
||||
if (typeof i.raws.before !== 'undefined') {
|
||||
value = i.raws.before
|
||||
if (value.includes('\n')) {
|
||||
value = value.replace(/[^\n]+$/, '')
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
})
|
||||
if (value) value = value.replace(/\S/g, '')
|
||||
return value
|
||||
}
|
||||
|
||||
rawColon(root) {
|
||||
let value
|
||||
root.walkDecls(i => {
|
||||
if (typeof i.raws.between !== 'undefined') {
|
||||
value = i.raws.between.replace(/[^\s:]/g, '')
|
||||
return false
|
||||
}
|
||||
})
|
||||
return value
|
||||
}
|
||||
|
||||
rawEmptyBody(root) {
|
||||
let value
|
||||
root.walk(i => {
|
||||
if (i.nodes && i.nodes.length === 0) {
|
||||
value = i.raws.after
|
||||
if (typeof value !== 'undefined') return false
|
||||
}
|
||||
})
|
||||
return value
|
||||
}
|
||||
|
||||
rawIndent(root) {
|
||||
if (root.raws.indent) return root.raws.indent
|
||||
let value
|
||||
root.walk(i => {
|
||||
let p = i.parent
|
||||
if (p && p !== root && p.parent && p.parent === root) {
|
||||
if (typeof i.raws.before !== 'undefined') {
|
||||
let parts = i.raws.before.split('\n')
|
||||
value = parts[parts.length - 1]
|
||||
value = value.replace(/\S/g, '')
|
||||
return false
|
||||
}
|
||||
}
|
||||
})
|
||||
return value
|
||||
}
|
||||
|
||||
rawSemicolon(root) {
|
||||
let value
|
||||
root.walk(i => {
|
||||
if (i.nodes && i.nodes.length && i.last.type === 'decl') {
|
||||
value = i.raws.semicolon
|
||||
if (typeof value !== 'undefined') return false
|
||||
}
|
||||
})
|
||||
return value
|
||||
}
|
||||
|
||||
rawValue(node, prop) {
|
||||
let value = node[prop]
|
||||
let raw = node.raws[prop]
|
||||
if (raw && raw.value === value) {
|
||||
return raw.raw
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
root(node) {
|
||||
this.body(node)
|
||||
if (node.raws.after) this.builder(node.raws.after)
|
||||
}
|
||||
|
||||
rule(node) {
|
||||
this.block(node, this.rawValue(node, 'selector'))
|
||||
if (node.raws.ownSemicolon) {
|
||||
this.builder(node.raws.ownSemicolon, node, 'end')
|
||||
}
|
||||
}
|
||||
|
||||
stringify(node, semicolon) {
|
||||
/* c8 ignore start */
|
||||
if (!this[node.type]) {
|
||||
throw new Error(
|
||||
'Unknown AST node type ' +
|
||||
node.type +
|
||||
'. ' +
|
||||
'Maybe you need to change PostCSS stringifier.'
|
||||
)
|
||||
}
|
||||
/* c8 ignore stop */
|
||||
this[node.type](node, semicolon)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Stringifier
|
||||
Stringifier.default = Stringifier
|
11
node_modules/postcss/lib/stringify.js
generated
vendored
Normal file
11
node_modules/postcss/lib/stringify.js
generated
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
'use strict'
|
||||
|
||||
let Stringifier = require('./stringifier')
|
||||
|
||||
function stringify(node, builder) {
|
||||
let str = new Stringifier(builder)
|
||||
str.stringify(node)
|
||||
}
|
||||
|
||||
module.exports = stringify
|
||||
stringify.default = stringify
|
70
node_modules/postcss/lib/terminal-highlight.js
generated
vendored
Normal file
70
node_modules/postcss/lib/terminal-highlight.js
generated
vendored
Normal file
|
@ -0,0 +1,70 @@
|
|||
'use strict'
|
||||
|
||||
let pico = require('picocolors')
|
||||
|
||||
let tokenizer = require('./tokenize')
|
||||
|
||||
let Input
|
||||
|
||||
function registerInput(dependant) {
|
||||
Input = dependant
|
||||
}
|
||||
|
||||
const HIGHLIGHT_THEME = {
|
||||
';': pico.yellow,
|
||||
':': pico.yellow,
|
||||
'(': pico.cyan,
|
||||
')': pico.cyan,
|
||||
'[': pico.yellow,
|
||||
']': pico.yellow,
|
||||
'{': pico.yellow,
|
||||
'}': pico.yellow,
|
||||
'at-word': pico.cyan,
|
||||
'brackets': pico.cyan,
|
||||
'call': pico.cyan,
|
||||
'class': pico.yellow,
|
||||
'comment': pico.gray,
|
||||
'hash': pico.magenta,
|
||||
'string': pico.green
|
||||
}
|
||||
|
||||
function getTokenType([type, value], processor) {
|
||||
if (type === 'word') {
|
||||
if (value[0] === '.') {
|
||||
return 'class'
|
||||
}
|
||||
if (value[0] === '#') {
|
||||
return 'hash'
|
||||
}
|
||||
}
|
||||
|
||||
if (!processor.endOfFile()) {
|
||||
let next = processor.nextToken()
|
||||
processor.back(next)
|
||||
if (next[0] === 'brackets' || next[0] === '(') return 'call'
|
||||
}
|
||||
|
||||
return type
|
||||
}
|
||||
|
||||
function terminalHighlight(css) {
|
||||
let processor = tokenizer(new Input(css), { ignoreErrors: true })
|
||||
let result = ''
|
||||
while (!processor.endOfFile()) {
|
||||
let token = processor.nextToken()
|
||||
let color = HIGHLIGHT_THEME[getTokenType(token, processor)]
|
||||
if (color) {
|
||||
result += token[1]
|
||||
.split(/\r?\n/)
|
||||
.map(i => color(i))
|
||||
.join('\n')
|
||||
} else {
|
||||
result += token[1]
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
terminalHighlight.registerInput = registerInput
|
||||
|
||||
module.exports = terminalHighlight
|
266
node_modules/postcss/lib/tokenize.js
generated
vendored
Normal file
266
node_modules/postcss/lib/tokenize.js
generated
vendored
Normal file
|
@ -0,0 +1,266 @@
|
|||
'use strict'
|
||||
|
||||
const SINGLE_QUOTE = "'".charCodeAt(0)
|
||||
const DOUBLE_QUOTE = '"'.charCodeAt(0)
|
||||
const BACKSLASH = '\\'.charCodeAt(0)
|
||||
const SLASH = '/'.charCodeAt(0)
|
||||
const NEWLINE = '\n'.charCodeAt(0)
|
||||
const SPACE = ' '.charCodeAt(0)
|
||||
const FEED = '\f'.charCodeAt(0)
|
||||
const TAB = '\t'.charCodeAt(0)
|
||||
const CR = '\r'.charCodeAt(0)
|
||||
const OPEN_SQUARE = '['.charCodeAt(0)
|
||||
const CLOSE_SQUARE = ']'.charCodeAt(0)
|
||||
const OPEN_PARENTHESES = '('.charCodeAt(0)
|
||||
const CLOSE_PARENTHESES = ')'.charCodeAt(0)
|
||||
const OPEN_CURLY = '{'.charCodeAt(0)
|
||||
const CLOSE_CURLY = '}'.charCodeAt(0)
|
||||
const SEMICOLON = ';'.charCodeAt(0)
|
||||
const ASTERISK = '*'.charCodeAt(0)
|
||||
const COLON = ':'.charCodeAt(0)
|
||||
const AT = '@'.charCodeAt(0)
|
||||
|
||||
const RE_AT_END = /[\t\n\f\r "#'()/;[\\\]{}]/g
|
||||
const RE_WORD_END = /[\t\n\f\r !"#'():;@[\\\]{}]|\/(?=\*)/g
|
||||
const RE_BAD_BRACKET = /.[\r\n"'(/\\]/
|
||||
const RE_HEX_ESCAPE = /[\da-f]/i
|
||||
|
||||
module.exports = function tokenizer(input, options = {}) {
|
||||
let css = input.css.valueOf()
|
||||
let ignore = options.ignoreErrors
|
||||
|
||||
let code, next, quote, content, escape
|
||||
let escaped, escapePos, prev, n, currentToken
|
||||
|
||||
let length = css.length
|
||||
let pos = 0
|
||||
let buffer = []
|
||||
let returned = []
|
||||
|
||||
function position() {
|
||||
return pos
|
||||
}
|
||||
|
||||
function unclosed(what) {
|
||||
throw input.error('Unclosed ' + what, pos)
|
||||
}
|
||||
|
||||
function endOfFile() {
|
||||
return returned.length === 0 && pos >= length
|
||||
}
|
||||
|
||||
function nextToken(opts) {
|
||||
if (returned.length) return returned.pop()
|
||||
if (pos >= length) return
|
||||
|
||||
let ignoreUnclosed = opts ? opts.ignoreUnclosed : false
|
||||
|
||||
code = css.charCodeAt(pos)
|
||||
|
||||
switch (code) {
|
||||
case NEWLINE:
|
||||
case SPACE:
|
||||
case TAB:
|
||||
case CR:
|
||||
case FEED: {
|
||||
next = pos
|
||||
do {
|
||||
next += 1
|
||||
code = css.charCodeAt(next)
|
||||
} while (
|
||||
code === SPACE ||
|
||||
code === NEWLINE ||
|
||||
code === TAB ||
|
||||
code === CR ||
|
||||
code === FEED
|
||||
)
|
||||
|
||||
currentToken = ['space', css.slice(pos, next)]
|
||||
pos = next - 1
|
||||
break
|
||||
}
|
||||
|
||||
case OPEN_SQUARE:
|
||||
case CLOSE_SQUARE:
|
||||
case OPEN_CURLY:
|
||||
case CLOSE_CURLY:
|
||||
case COLON:
|
||||
case SEMICOLON:
|
||||
case CLOSE_PARENTHESES: {
|
||||
let controlChar = String.fromCharCode(code)
|
||||
currentToken = [controlChar, controlChar, pos]
|
||||
break
|
||||
}
|
||||
|
||||
case OPEN_PARENTHESES: {
|
||||
prev = buffer.length ? buffer.pop()[1] : ''
|
||||
n = css.charCodeAt(pos + 1)
|
||||
if (
|
||||
prev === 'url' &&
|
||||
n !== SINGLE_QUOTE &&
|
||||
n !== DOUBLE_QUOTE &&
|
||||
n !== SPACE &&
|
||||
n !== NEWLINE &&
|
||||
n !== TAB &&
|
||||
n !== FEED &&
|
||||
n !== CR
|
||||
) {
|
||||
next = pos
|
||||
do {
|
||||
escaped = false
|
||||
next = css.indexOf(')', next + 1)
|
||||
if (next === -1) {
|
||||
if (ignore || ignoreUnclosed) {
|
||||
next = pos
|
||||
break
|
||||
} else {
|
||||
unclosed('bracket')
|
||||
}
|
||||
}
|
||||
escapePos = next
|
||||
while (css.charCodeAt(escapePos - 1) === BACKSLASH) {
|
||||
escapePos -= 1
|
||||
escaped = !escaped
|
||||
}
|
||||
} while (escaped)
|
||||
|
||||
currentToken = ['brackets', css.slice(pos, next + 1), pos, next]
|
||||
|
||||
pos = next
|
||||
} else {
|
||||
next = css.indexOf(')', pos + 1)
|
||||
content = css.slice(pos, next + 1)
|
||||
|
||||
if (next === -1 || RE_BAD_BRACKET.test(content)) {
|
||||
currentToken = ['(', '(', pos]
|
||||
} else {
|
||||
currentToken = ['brackets', content, pos, next]
|
||||
pos = next
|
||||
}
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
|
||||
case SINGLE_QUOTE:
|
||||
case DOUBLE_QUOTE: {
|
||||
quote = code === SINGLE_QUOTE ? "'" : '"'
|
||||
next = pos
|
||||
do {
|
||||
escaped = false
|
||||
next = css.indexOf(quote, next + 1)
|
||||
if (next === -1) {
|
||||
if (ignore || ignoreUnclosed) {
|
||||
next = pos + 1
|
||||
break
|
||||
} else {
|
||||
unclosed('string')
|
||||
}
|
||||
}
|
||||
escapePos = next
|
||||
while (css.charCodeAt(escapePos - 1) === BACKSLASH) {
|
||||
escapePos -= 1
|
||||
escaped = !escaped
|
||||
}
|
||||
} while (escaped)
|
||||
|
||||
currentToken = ['string', css.slice(pos, next + 1), pos, next]
|
||||
pos = next
|
||||
break
|
||||
}
|
||||
|
||||
case AT: {
|
||||
RE_AT_END.lastIndex = pos + 1
|
||||
RE_AT_END.test(css)
|
||||
if (RE_AT_END.lastIndex === 0) {
|
||||
next = css.length - 1
|
||||
} else {
|
||||
next = RE_AT_END.lastIndex - 2
|
||||
}
|
||||
|
||||
currentToken = ['at-word', css.slice(pos, next + 1), pos, next]
|
||||
|
||||
pos = next
|
||||
break
|
||||
}
|
||||
|
||||
case BACKSLASH: {
|
||||
next = pos
|
||||
escape = true
|
||||
while (css.charCodeAt(next + 1) === BACKSLASH) {
|
||||
next += 1
|
||||
escape = !escape
|
||||
}
|
||||
code = css.charCodeAt(next + 1)
|
||||
if (
|
||||
escape &&
|
||||
code !== SLASH &&
|
||||
code !== SPACE &&
|
||||
code !== NEWLINE &&
|
||||
code !== TAB &&
|
||||
code !== CR &&
|
||||
code !== FEED
|
||||
) {
|
||||
next += 1
|
||||
if (RE_HEX_ESCAPE.test(css.charAt(next))) {
|
||||
while (RE_HEX_ESCAPE.test(css.charAt(next + 1))) {
|
||||
next += 1
|
||||
}
|
||||
if (css.charCodeAt(next + 1) === SPACE) {
|
||||
next += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
currentToken = ['word', css.slice(pos, next + 1), pos, next]
|
||||
|
||||
pos = next
|
||||
break
|
||||
}
|
||||
|
||||
default: {
|
||||
if (code === SLASH && css.charCodeAt(pos + 1) === ASTERISK) {
|
||||
next = css.indexOf('*/', pos + 2) + 1
|
||||
if (next === 0) {
|
||||
if (ignore || ignoreUnclosed) {
|
||||
next = css.length
|
||||
} else {
|
||||
unclosed('comment')
|
||||
}
|
||||
}
|
||||
|
||||
currentToken = ['comment', css.slice(pos, next + 1), pos, next]
|
||||
pos = next
|
||||
} else {
|
||||
RE_WORD_END.lastIndex = pos + 1
|
||||
RE_WORD_END.test(css)
|
||||
if (RE_WORD_END.lastIndex === 0) {
|
||||
next = css.length - 1
|
||||
} else {
|
||||
next = RE_WORD_END.lastIndex - 2
|
||||
}
|
||||
|
||||
currentToken = ['word', css.slice(pos, next + 1), pos, next]
|
||||
buffer.push(currentToken)
|
||||
pos = next
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
pos++
|
||||
return currentToken
|
||||
}
|
||||
|
||||
function back(token) {
|
||||
returned.push(token)
|
||||
}
|
||||
|
||||
return {
|
||||
back,
|
||||
endOfFile,
|
||||
nextToken,
|
||||
position
|
||||
}
|
||||
}
|
13
node_modules/postcss/lib/warn-once.js
generated
vendored
Normal file
13
node_modules/postcss/lib/warn-once.js
generated
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
/* eslint-disable no-console */
|
||||
'use strict'
|
||||
|
||||
let printed = {}
|
||||
|
||||
module.exports = function warnOnce(message) {
|
||||
if (printed[message]) return
|
||||
printed[message] = true
|
||||
|
||||
if (typeof console !== 'undefined' && console.warn) {
|
||||
console.warn(message)
|
||||
}
|
||||
}
|
37
node_modules/postcss/lib/warning.js
generated
vendored
Normal file
37
node_modules/postcss/lib/warning.js
generated
vendored
Normal file
|
@ -0,0 +1,37 @@
|
|||
'use strict'
|
||||
|
||||
class Warning {
|
||||
constructor(text, opts = {}) {
|
||||
this.type = 'warning'
|
||||
this.text = text
|
||||
|
||||
if (opts.node && opts.node.source) {
|
||||
let range = opts.node.rangeBy(opts)
|
||||
this.line = range.start.line
|
||||
this.column = range.start.column
|
||||
this.endLine = range.end.line
|
||||
this.endColumn = range.end.column
|
||||
}
|
||||
|
||||
for (let opt in opts) this[opt] = opts[opt]
|
||||
}
|
||||
|
||||
toString() {
|
||||
if (this.node) {
|
||||
return this.node.error(this.text, {
|
||||
index: this.index,
|
||||
plugin: this.plugin,
|
||||
word: this.word
|
||||
}).message
|
||||
}
|
||||
|
||||
if (this.plugin) {
|
||||
return this.plugin + ': ' + this.text
|
||||
}
|
||||
|
||||
return this.text
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Warning
|
||||
Warning.default = Warning
|
Loading…
Add table
Add a link
Reference in a new issue