mirror of
https://gitee.com/onvia/ccc-tnt-psd2ui
synced 2025-12-08 13:58:58 +00:00
mac npm-packages
This commit is contained in:
@@ -11,37 +11,37 @@ let parse = require('./parse')
|
||||
let Root = require('./root')
|
||||
|
||||
const TYPE_TO_CLASS_NAME = {
|
||||
atrule: 'AtRule',
|
||||
comment: 'Comment',
|
||||
decl: 'Declaration',
|
||||
document: 'Document',
|
||||
root: 'Root',
|
||||
atrule: 'AtRule',
|
||||
rule: 'Rule',
|
||||
decl: 'Declaration',
|
||||
comment: 'Comment'
|
||||
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,
|
||||
Once: true,
|
||||
Document: true,
|
||||
Root: true,
|
||||
Declaration: true,
|
||||
Rule: true,
|
||||
AtRule: true,
|
||||
Comment: true,
|
||||
DeclarationExit: true,
|
||||
RuleExit: true,
|
||||
AtRuleExit: true,
|
||||
CommentExit: true,
|
||||
RootExit: true,
|
||||
DocumentExit: true,
|
||||
OnceExit: true
|
||||
Rule: true,
|
||||
RuleExit: true
|
||||
}
|
||||
|
||||
const NOT_VISITORS = {
|
||||
Once: true,
|
||||
postcssPlugin: true,
|
||||
prepare: true,
|
||||
Once: true
|
||||
prepare: true
|
||||
}
|
||||
|
||||
const CHILDREN = 0
|
||||
@@ -87,12 +87,12 @@ function toStack(node) {
|
||||
}
|
||||
|
||||
return {
|
||||
node,
|
||||
events,
|
||||
eventIndex: 0,
|
||||
visitors: [],
|
||||
events,
|
||||
iterator: 0,
|
||||
node,
|
||||
visitorIndex: 0,
|
||||
iterator: 0
|
||||
visitors: []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ class LazyResult {
|
||||
}
|
||||
|
||||
this.result = new Result(processor, root, opts)
|
||||
this.helpers = { ...postcss, result: this.result, postcss }
|
||||
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) }
|
||||
@@ -153,67 +153,6 @@ class LazyResult {
|
||||
})
|
||||
}
|
||||
|
||||
get [Symbol.toStringTag]() {
|
||||
return 'LazyResult'
|
||||
}
|
||||
|
||||
get processor() {
|
||||
return this.result.processor
|
||||
}
|
||||
|
||||
get opts() {
|
||||
return this.result.opts
|
||||
}
|
||||
|
||||
get css() {
|
||||
return this.stringify().css
|
||||
}
|
||||
|
||||
get content() {
|
||||
return this.stringify().content
|
||||
}
|
||||
|
||||
get map() {
|
||||
return this.stringify().map
|
||||
}
|
||||
|
||||
get root() {
|
||||
return this.sync().root
|
||||
}
|
||||
|
||||
get messages() {
|
||||
return this.sync().messages
|
||||
}
|
||||
|
||||
warnings() {
|
||||
return this.sync().warnings()
|
||||
}
|
||||
|
||||
toString() {
|
||||
return this.css
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
|
||||
catch(onRejected) {
|
||||
return this.async().catch(onRejected)
|
||||
}
|
||||
|
||||
finally(onFinally) {
|
||||
return this.async().then(onFinally, onFinally)
|
||||
}
|
||||
|
||||
async() {
|
||||
if (this.error) return Promise.reject(this.error)
|
||||
if (this.processed) return Promise.resolve(this.result)
|
||||
@@ -223,124 +162,20 @@ class LazyResult {
|
||||
return this.processing
|
||||
}
|
||||
|
||||
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
|
||||
catch(onRejected) {
|
||||
return this.async().catch(onRejected)
|
||||
}
|
||||
|
||||
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
|
||||
get content() {
|
||||
return this.stringify().content
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
get css() {
|
||||
return this.stringify().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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
finally(onFinally) {
|
||||
return this.async().then(onFinally, onFinally)
|
||||
}
|
||||
|
||||
getAsyncError() {
|
||||
@@ -386,6 +221,64 @@ class LazyResult {
|
||||
return error
|
||||
}
|
||||
|
||||
get map() {
|
||||
return this.stringify().map
|
||||
}
|
||||
|
||||
get messages() {
|
||||
return this.sync().messages
|
||||
}
|
||||
|
||||
get opts() {
|
||||
return this.result.opts
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
get processor() {
|
||||
return this.result.processor
|
||||
}
|
||||
|
||||
get root() {
|
||||
return this.sync().root
|
||||
}
|
||||
|
||||
async runAsync() {
|
||||
this.plugin = 0
|
||||
for (let i = 0; i < this.plugins.length; i++) {
|
||||
@@ -443,42 +336,126 @@ class LazyResult {
|
||||
return this.stringify()
|
||||
}
|
||||
|
||||
prepareVisitors() {
|
||||
this.listeners = {}
|
||||
let add = (plugin, type, cb) => {
|
||||
if (!this.listeners[type]) this.listeners[type] = []
|
||||
this.listeners[type].push([plugin, cb])
|
||||
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
|
||||
}
|
||||
|
||||
get [Symbol.toStringTag]() {
|
||||
return 'LazyResult'
|
||||
}
|
||||
|
||||
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) {
|
||||
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])
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
this.hasListener = Object.keys(this.listeners).length > 0
|
||||
|
||||
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) {
|
||||
@@ -537,6 +514,29 @@ class LazyResult {
|
||||
}
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
||||
LazyResult.registerPostcss = dependant => {
|
||||
|
||||
Reference in New Issue
Block a user