1 | 'use strict'
|
---|
2 |
|
---|
3 | let CssSyntaxError = require('./css-syntax-error')
|
---|
4 | let Declaration = require('./declaration')
|
---|
5 | let LazyResult = require('./lazy-result')
|
---|
6 | let Container = require('./container')
|
---|
7 | let Processor = require('./processor')
|
---|
8 | let stringify = require('./stringify')
|
---|
9 | let fromJSON = require('./fromJSON')
|
---|
10 | let Document = require('./document')
|
---|
11 | let Warning = require('./warning')
|
---|
12 | let Comment = require('./comment')
|
---|
13 | let AtRule = require('./at-rule')
|
---|
14 | let Result = require('./result.js')
|
---|
15 | let Input = require('./input')
|
---|
16 | let parse = require('./parse')
|
---|
17 | let list = require('./list')
|
---|
18 | let Rule = require('./rule')
|
---|
19 | let Root = require('./root')
|
---|
20 | let Node = require('./node')
|
---|
21 |
|
---|
22 | function postcss(...plugins) {
|
---|
23 | if (plugins.length === 1 && Array.isArray(plugins[0])) {
|
---|
24 | plugins = plugins[0]
|
---|
25 | }
|
---|
26 | return new Processor(plugins)
|
---|
27 | }
|
---|
28 |
|
---|
29 | postcss.plugin = function plugin(name, initializer) {
|
---|
30 | if (console && console.warn) {
|
---|
31 | console.warn(
|
---|
32 | name +
|
---|
33 | ': postcss.plugin was deprecated. Migration guide:\n' +
|
---|
34 | 'https://evilmartians.com/chronicles/postcss-8-plugin-migration'
|
---|
35 | )
|
---|
36 | if (process.env.LANG && process.env.LANG.startsWith('cn')) {
|
---|
37 | // istanbul ignore next
|
---|
38 | console.warn(
|
---|
39 | name +
|
---|
40 | ': 里面 postcss.plugin 被弃用. 迁移指南:\n' +
|
---|
41 | 'https://www.w3ctech.com/topic/2226'
|
---|
42 | )
|
---|
43 | }
|
---|
44 | }
|
---|
45 | function creator(...args) {
|
---|
46 | let transformer = initializer(...args)
|
---|
47 | transformer.postcssPlugin = name
|
---|
48 | transformer.postcssVersion = new Processor().version
|
---|
49 | return transformer
|
---|
50 | }
|
---|
51 |
|
---|
52 | let cache
|
---|
53 | Object.defineProperty(creator, 'postcss', {
|
---|
54 | get() {
|
---|
55 | if (!cache) cache = creator()
|
---|
56 | return cache
|
---|
57 | }
|
---|
58 | })
|
---|
59 |
|
---|
60 | creator.process = function (css, processOpts, pluginOpts) {
|
---|
61 | return postcss([creator(pluginOpts)]).process(css, processOpts)
|
---|
62 | }
|
---|
63 |
|
---|
64 | return creator
|
---|
65 | }
|
---|
66 |
|
---|
67 | postcss.stringify = stringify
|
---|
68 | postcss.parse = parse
|
---|
69 | postcss.fromJSON = fromJSON
|
---|
70 | postcss.list = list
|
---|
71 |
|
---|
72 | postcss.comment = defaults => new Comment(defaults)
|
---|
73 | postcss.atRule = defaults => new AtRule(defaults)
|
---|
74 | postcss.decl = defaults => new Declaration(defaults)
|
---|
75 | postcss.rule = defaults => new Rule(defaults)
|
---|
76 | postcss.root = defaults => new Root(defaults)
|
---|
77 | postcss.document = defaults => new Document(defaults)
|
---|
78 |
|
---|
79 | postcss.CssSyntaxError = CssSyntaxError
|
---|
80 | postcss.Declaration = Declaration
|
---|
81 | postcss.Container = Container
|
---|
82 | postcss.Document = Document
|
---|
83 | postcss.Comment = Comment
|
---|
84 | postcss.Warning = Warning
|
---|
85 | postcss.AtRule = AtRule
|
---|
86 | postcss.Result = Result
|
---|
87 | postcss.Input = Input
|
---|
88 | postcss.Rule = Rule
|
---|
89 | postcss.Root = Root
|
---|
90 | postcss.Node = Node
|
---|
91 |
|
---|
92 | LazyResult.registerPostcss(postcss)
|
---|
93 |
|
---|
94 | module.exports = postcss
|
---|
95 | postcss.default = postcss
|
---|