plugin-build-guide-block 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/dist/client/UserGuideBlock.d.ts +2 -0
  2. package/dist/client/UserGuideBlockInitializer.d.ts +2 -0
  3. package/dist/client/UserGuideBlockProvider.d.ts +2 -0
  4. package/dist/client/UserGuideManager.d.ts +2 -0
  5. package/dist/client/components/BuildButton.d.ts +2 -0
  6. package/dist/client/components/LLMServiceSelect.d.ts +2 -0
  7. package/dist/client/components/ModelSelect.d.ts +2 -0
  8. package/dist/client/components/StatusTag.d.ts +2 -0
  9. package/dist/client/index.d.ts +1 -0
  10. package/dist/client/index.js +1 -1
  11. package/dist/client/models/UserGuideBlockModel.d.ts +3 -0
  12. package/dist/client/models/index.d.ts +11 -0
  13. package/dist/client/plugin.d.ts +5 -0
  14. package/dist/client/schemas/spacesSchema.d.ts +305 -0
  15. package/dist/index.d.ts +2 -0
  16. package/dist/node_modules/sanitize-html/LICENSE +7 -0
  17. package/dist/node_modules/sanitize-html/index.js +7 -0
  18. package/dist/node_modules/sanitize-html/node_modules/nanoid/async/index.browser.cjs +34 -0
  19. package/dist/node_modules/sanitize-html/node_modules/nanoid/async/index.browser.js +34 -0
  20. package/dist/node_modules/sanitize-html/node_modules/nanoid/async/index.cjs +35 -0
  21. package/dist/node_modules/sanitize-html/node_modules/nanoid/async/index.d.ts +56 -0
  22. package/dist/node_modules/sanitize-html/node_modules/nanoid/async/index.js +35 -0
  23. package/dist/node_modules/sanitize-html/node_modules/nanoid/async/index.native.js +26 -0
  24. package/dist/node_modules/sanitize-html/node_modules/nanoid/async/package.json +12 -0
  25. package/dist/node_modules/sanitize-html/node_modules/nanoid/bin/nanoid.cjs +55 -0
  26. package/dist/node_modules/sanitize-html/node_modules/nanoid/index.browser.cjs +34 -0
  27. package/dist/node_modules/sanitize-html/node_modules/nanoid/index.browser.js +34 -0
  28. package/dist/node_modules/sanitize-html/node_modules/nanoid/index.cjs +45 -0
  29. package/dist/node_modules/sanitize-html/node_modules/nanoid/index.d.cts +91 -0
  30. package/dist/node_modules/sanitize-html/node_modules/nanoid/index.d.ts +91 -0
  31. package/dist/node_modules/sanitize-html/node_modules/nanoid/index.js +45 -0
  32. package/dist/node_modules/sanitize-html/node_modules/nanoid/nanoid.js +1 -0
  33. package/dist/node_modules/sanitize-html/node_modules/nanoid/non-secure/index.cjs +21 -0
  34. package/dist/node_modules/sanitize-html/node_modules/nanoid/non-secure/index.d.ts +33 -0
  35. package/dist/node_modules/sanitize-html/node_modules/nanoid/non-secure/index.js +21 -0
  36. package/dist/node_modules/sanitize-html/node_modules/nanoid/non-secure/package.json +6 -0
  37. package/dist/node_modules/sanitize-html/node_modules/nanoid/package.json +88 -0
  38. package/dist/node_modules/sanitize-html/node_modules/nanoid/url-alphabet/index.cjs +3 -0
  39. package/dist/node_modules/sanitize-html/node_modules/nanoid/url-alphabet/index.js +3 -0
  40. package/dist/node_modules/sanitize-html/node_modules/nanoid/url-alphabet/package.json +6 -0
  41. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/at-rule.d.ts +115 -0
  42. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/at-rule.js +25 -0
  43. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/comment.d.ts +67 -0
  44. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/comment.js +13 -0
  45. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/container.d.ts +452 -0
  46. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/container.js +439 -0
  47. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/css-syntax-error.d.ts +248 -0
  48. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/css-syntax-error.js +100 -0
  49. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/declaration.d.ts +148 -0
  50. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/declaration.js +24 -0
  51. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/document.d.ts +68 -0
  52. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/document.js +33 -0
  53. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/fromJSON.d.ts +9 -0
  54. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/fromJSON.js +54 -0
  55. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/input.d.ts +194 -0
  56. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/input.js +248 -0
  57. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/lazy-result.d.ts +190 -0
  58. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/lazy-result.js +550 -0
  59. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/list.d.ts +57 -0
  60. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/list.js +58 -0
  61. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/map-generator.js +359 -0
  62. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/no-work-result.d.ts +46 -0
  63. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/no-work-result.js +135 -0
  64. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/node.d.ts +536 -0
  65. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/node.js +381 -0
  66. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/parse.d.ts +9 -0
  67. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/parse.js +42 -0
  68. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/parser.js +610 -0
  69. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/postcss.d.mts +72 -0
  70. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/postcss.d.ts +441 -0
  71. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/postcss.js +101 -0
  72. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/previous-map.d.ts +81 -0
  73. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/previous-map.js +142 -0
  74. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/processor.d.ts +115 -0
  75. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/processor.js +67 -0
  76. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/result.d.ts +206 -0
  77. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/result.js +42 -0
  78. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/root.d.ts +86 -0
  79. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/root.js +61 -0
  80. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/rule.d.ts +113 -0
  81. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/rule.js +27 -0
  82. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/stringifier.d.ts +46 -0
  83. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/stringifier.js +353 -0
  84. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/stringify.d.ts +9 -0
  85. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/stringify.js +11 -0
  86. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/symbols.js +5 -0
  87. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/terminal-highlight.js +70 -0
  88. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/tokenize.js +266 -0
  89. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/warn-once.js +13 -0
  90. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/warning.d.ts +147 -0
  91. package/dist/node_modules/sanitize-html/node_modules/postcss/lib/warning.js +37 -0
  92. package/dist/node_modules/sanitize-html/node_modules/postcss/node_modules/.bin/nanoid +15 -0
  93. package/dist/node_modules/sanitize-html/node_modules/postcss/node_modules/.bin/nanoid.cmd +7 -0
  94. package/dist/node_modules/sanitize-html/node_modules/postcss/package.json +88 -0
  95. package/dist/node_modules/sanitize-html/package.json +1 -0
  96. package/dist/server/actions/build.d.ts +2 -0
  97. package/dist/server/actions/getHtml.d.ts +2 -0
  98. package/dist/server/collections/ai-build-guide-spaces.d.ts +2 -0
  99. package/dist/server/index.d.ts +1 -0
  100. package/dist/server/plugin.d.ts +11 -0
  101. package/package.json +9 -1
  102. package/src/client/UserGuideBlock.tsx +53 -0
  103. package/src/client/UserGuideBlockInitializer.tsx +26 -0
  104. package/src/client/UserGuideBlockProvider.tsx +12 -0
  105. package/src/client/UserGuideManager.tsx +133 -0
  106. package/src/client/client.d.ts +249 -0
  107. package/src/client/components/BuildButton.tsx +43 -0
  108. package/src/client/components/LLMServiceSelect.tsx +44 -0
  109. package/src/client/components/ModelSelect.tsx +41 -0
  110. package/src/client/components/StatusTag.tsx +17 -0
  111. package/src/client/index.tsx +1 -0
  112. package/src/client/models/UserGuideBlockModel.ts +47 -0
  113. package/src/client/models/index.ts +12 -0
  114. package/src/client/plugin.tsx +30 -0
  115. package/src/client/schemas/spacesSchema.ts +305 -0
  116. package/src/index.ts +2 -0
  117. package/src/locale/en-US.json +27 -0
  118. package/src/locale/vi-VN.json +27 -0
  119. package/src/locale/zh-CN.json +27 -0
  120. package/src/server/actions/build.ts +171 -0
  121. package/src/server/actions/getHtml.ts +26 -0
  122. package/src/server/collections/.gitkeep +0 -0
  123. package/src/server/collections/ai-build-guide-spaces.ts +49 -0
  124. package/src/server/index.ts +1 -0
  125. package/src/server/plugin.ts +42 -0
@@ -0,0 +1,142 @@
1
+ 'use strict'
2
+
3
+ let { SourceMapConsumer, SourceMapGenerator } = require('source-map-js')
4
+ let { existsSync, readFileSync } = require('fs')
5
+ let { dirname, join } = require('path')
6
+
7
+ function fromBase64(str) {
8
+ if (Buffer) {
9
+ return Buffer.from(str, 'base64').toString()
10
+ } else {
11
+ /* c8 ignore next 2 */
12
+ return window.atob(str)
13
+ }
14
+ }
15
+
16
+ class PreviousMap {
17
+ constructor(css, opts) {
18
+ if (opts.map === false) return
19
+ this.loadAnnotation(css)
20
+ this.inline = this.startWith(this.annotation, 'data:')
21
+
22
+ let prev = opts.map ? opts.map.prev : undefined
23
+ let text = this.loadMap(opts.from, prev)
24
+ if (!this.mapFile && opts.from) {
25
+ this.mapFile = opts.from
26
+ }
27
+ if (this.mapFile) this.root = dirname(this.mapFile)
28
+ if (text) this.text = text
29
+ }
30
+
31
+ consumer() {
32
+ if (!this.consumerCache) {
33
+ this.consumerCache = new SourceMapConsumer(this.text)
34
+ }
35
+ return this.consumerCache
36
+ }
37
+
38
+ decodeInline(text) {
39
+ let baseCharsetUri = /^data:application\/json;charset=utf-?8;base64,/
40
+ let baseUri = /^data:application\/json;base64,/
41
+ let charsetUri = /^data:application\/json;charset=utf-?8,/
42
+ let uri = /^data:application\/json,/
43
+
44
+ if (charsetUri.test(text) || uri.test(text)) {
45
+ return decodeURIComponent(text.substr(RegExp.lastMatch.length))
46
+ }
47
+
48
+ if (baseCharsetUri.test(text) || baseUri.test(text)) {
49
+ return fromBase64(text.substr(RegExp.lastMatch.length))
50
+ }
51
+
52
+ let encoding = text.match(/data:application\/json;([^,]+),/)[1]
53
+ throw new Error('Unsupported source map encoding ' + encoding)
54
+ }
55
+
56
+ getAnnotationURL(sourceMapString) {
57
+ return sourceMapString.replace(/^\/\*\s*# sourceMappingURL=/, '').trim()
58
+ }
59
+
60
+ isMap(map) {
61
+ if (typeof map !== 'object') return false
62
+ return (
63
+ typeof map.mappings === 'string' ||
64
+ typeof map._mappings === 'string' ||
65
+ Array.isArray(map.sections)
66
+ )
67
+ }
68
+
69
+ loadAnnotation(css) {
70
+ let comments = css.match(/\/\*\s*# sourceMappingURL=/gm)
71
+ if (!comments) return
72
+
73
+ // sourceMappingURLs from comments, strings, etc.
74
+ let start = css.lastIndexOf(comments.pop())
75
+ let end = css.indexOf('*/', start)
76
+
77
+ if (start > -1 && end > -1) {
78
+ // Locate the last sourceMappingURL to avoid pickin
79
+ this.annotation = this.getAnnotationURL(css.substring(start, end))
80
+ }
81
+ }
82
+
83
+ loadFile(path) {
84
+ this.root = dirname(path)
85
+ if (existsSync(path)) {
86
+ this.mapFile = path
87
+ return readFileSync(path, 'utf-8').toString().trim()
88
+ }
89
+ }
90
+
91
+ loadMap(file, prev) {
92
+ if (prev === false) return false
93
+
94
+ if (prev) {
95
+ if (typeof prev === 'string') {
96
+ return prev
97
+ } else if (typeof prev === 'function') {
98
+ let prevPath = prev(file)
99
+ if (prevPath) {
100
+ let map = this.loadFile(prevPath)
101
+ if (!map) {
102
+ throw new Error(
103
+ 'Unable to load previous source map: ' + prevPath.toString()
104
+ )
105
+ }
106
+ return map
107
+ }
108
+ } else if (prev instanceof SourceMapConsumer) {
109
+ return SourceMapGenerator.fromSourceMap(prev).toString()
110
+ } else if (prev instanceof SourceMapGenerator) {
111
+ return prev.toString()
112
+ } else if (this.isMap(prev)) {
113
+ return JSON.stringify(prev)
114
+ } else {
115
+ throw new Error(
116
+ 'Unsupported previous source map format: ' + prev.toString()
117
+ )
118
+ }
119
+ } else if (this.inline) {
120
+ return this.decodeInline(this.annotation)
121
+ } else if (this.annotation) {
122
+ let map = this.annotation
123
+ if (file) map = join(dirname(file), map)
124
+ return this.loadFile(map)
125
+ }
126
+ }
127
+
128
+ startWith(string, start) {
129
+ if (!string) return false
130
+ return string.substr(0, start.length) === start
131
+ }
132
+
133
+ withContent() {
134
+ return !!(
135
+ this.consumer().sourcesContent &&
136
+ this.consumer().sourcesContent.length > 0
137
+ )
138
+ }
139
+ }
140
+
141
+ module.exports = PreviousMap
142
+ PreviousMap.default = PreviousMap
@@ -0,0 +1,115 @@
1
+ import Document from './document.js'
2
+ import LazyResult from './lazy-result.js'
3
+ import NoWorkResult from './no-work-result.js'
4
+ import {
5
+ AcceptedPlugin,
6
+ Plugin,
7
+ ProcessOptions,
8
+ TransformCallback,
9
+ Transformer
10
+ } from './postcss.js'
11
+ import Result from './result.js'
12
+ import Root from './root.js'
13
+
14
+ declare namespace Processor {
15
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
16
+ export { Processor_ as default }
17
+ }
18
+
19
+ /**
20
+ * Contains plugins to process CSS. Create one `Processor` instance,
21
+ * initialize its plugins, and then use that instance on numerous CSS files.
22
+ *
23
+ * ```js
24
+ * const processor = postcss([autoprefixer, postcssNested])
25
+ * processor.process(css1).then(result => console.log(result.css))
26
+ * processor.process(css2).then(result => console.log(result.css))
27
+ * ```
28
+ */
29
+ declare class Processor_ {
30
+ /**
31
+ * Plugins added to this processor.
32
+ *
33
+ * ```js
34
+ * const processor = postcss([autoprefixer, postcssNested])
35
+ * processor.plugins.length //=> 2
36
+ * ```
37
+ */
38
+ plugins: (Plugin | TransformCallback | Transformer)[]
39
+
40
+ /**
41
+ * Current PostCSS version.
42
+ *
43
+ * ```js
44
+ * if (result.processor.version.split('.')[0] !== '6') {
45
+ * throw new Error('This plugin works only with PostCSS 6')
46
+ * }
47
+ * ```
48
+ */
49
+ version: string
50
+
51
+ /**
52
+ * @param plugins PostCSS plugins
53
+ */
54
+ constructor(plugins?: AcceptedPlugin[])
55
+
56
+ /**
57
+ * Parses source CSS and returns a `LazyResult` Promise proxy.
58
+ * Because some plugins can be asynchronous it doesn’t make
59
+ * any transformations. Transformations will be applied
60
+ * in the `LazyResult` methods.
61
+ *
62
+ * ```js
63
+ * processor.process(css, { from: 'a.css', to: 'a.out.css' })
64
+ * .then(result => {
65
+ * console.log(result.css)
66
+ * })
67
+ * ```
68
+ *
69
+ * @param css String with input CSS or any object with a `toString()` method,
70
+ * like a Buffer. Optionally, send a `Result` instance
71
+ * and the processor will take the `Root` from it.
72
+ * @param opts Options.
73
+ * @return Promise proxy.
74
+ */
75
+ process(
76
+ css: { toString(): string } | LazyResult | Result | Root | string
77
+ ): LazyResult | NoWorkResult
78
+ process<RootNode extends Document | Root = Root>(
79
+ css: { toString(): string } | LazyResult | Result | Root | string,
80
+ options: ProcessOptions<RootNode>
81
+ ): LazyResult<RootNode>
82
+
83
+ /**
84
+ * Adds a plugin to be used as a CSS processor.
85
+ *
86
+ * PostCSS plugin can be in 4 formats:
87
+ * * A plugin in `Plugin` format.
88
+ * * A plugin creator function with `pluginCreator.postcss = true`.
89
+ * PostCSS will call this function without argument to get plugin.
90
+ * * A function. PostCSS will pass the function a {@link Root}
91
+ * as the first argument and current `Result` instance
92
+ * as the second.
93
+ * * Another `Processor` instance. PostCSS will copy plugins
94
+ * from that instance into this one.
95
+ *
96
+ * Plugins can also be added by passing them as arguments when creating
97
+ * a `postcss` instance (see [`postcss(plugins)`]).
98
+ *
99
+ * Asynchronous plugins should return a `Promise` instance.
100
+ *
101
+ * ```js
102
+ * const processor = postcss()
103
+ * .use(autoprefixer)
104
+ * .use(postcssNested)
105
+ * ```
106
+ *
107
+ * @param plugin PostCSS plugin or `Processor` with plugins.
108
+ * @return Current processor to make methods chain.
109
+ */
110
+ use(plugin: AcceptedPlugin): this
111
+ }
112
+
113
+ declare class Processor extends Processor_ {}
114
+
115
+ export = Processor
@@ -0,0 +1,67 @@
1
+ 'use strict'
2
+
3
+ let NoWorkResult = require('./no-work-result')
4
+ let LazyResult = require('./lazy-result')
5
+ let Document = require('./document')
6
+ let Root = require('./root')
7
+
8
+ class Processor {
9
+ constructor(plugins = []) {
10
+ this.version = '8.4.32'
11
+ this.plugins = this.normalize(plugins)
12
+ }
13
+
14
+ normalize(plugins) {
15
+ let normalized = []
16
+ for (let i of plugins) {
17
+ if (i.postcss === true) {
18
+ i = i()
19
+ } else if (i.postcss) {
20
+ i = i.postcss
21
+ }
22
+
23
+ if (typeof i === 'object' && Array.isArray(i.plugins)) {
24
+ normalized = normalized.concat(i.plugins)
25
+ } else if (typeof i === 'object' && i.postcssPlugin) {
26
+ normalized.push(i)
27
+ } else if (typeof i === 'function') {
28
+ normalized.push(i)
29
+ } else if (typeof i === 'object' && (i.parse || i.stringify)) {
30
+ if (process.env.NODE_ENV !== 'production') {
31
+ throw new Error(
32
+ 'PostCSS syntaxes cannot be used as plugins. Instead, please use ' +
33
+ 'one of the syntax/parser/stringifier options as outlined ' +
34
+ 'in your PostCSS runner documentation.'
35
+ )
36
+ }
37
+ } else {
38
+ throw new Error(i + ' is not a PostCSS plugin')
39
+ }
40
+ }
41
+ return normalized
42
+ }
43
+
44
+ process(css, opts = {}) {
45
+ if (
46
+ this.plugins.length === 0 &&
47
+ typeof opts.parser === 'undefined' &&
48
+ typeof opts.stringifier === 'undefined' &&
49
+ typeof opts.syntax === 'undefined'
50
+ ) {
51
+ return new NoWorkResult(this, css, opts)
52
+ } else {
53
+ return new LazyResult(this, css, opts)
54
+ }
55
+ }
56
+
57
+ use(plugin) {
58
+ this.plugins = this.plugins.concat(this.normalize([plugin]))
59
+ return this
60
+ }
61
+ }
62
+
63
+ module.exports = Processor
64
+ Processor.default = Processor
65
+
66
+ Root.registerProcessor(Processor)
67
+ Document.registerProcessor(Processor)
@@ -0,0 +1,206 @@
1
+ import {
2
+ Document,
3
+ Node,
4
+ Plugin,
5
+ ProcessOptions,
6
+ Root,
7
+ SourceMap,
8
+ TransformCallback,
9
+ Warning,
10
+ WarningOptions
11
+ } from './postcss.js'
12
+ import Processor from './processor.js'
13
+
14
+ declare namespace Result {
15
+ export interface Message {
16
+ [others: string]: any
17
+
18
+ /**
19
+ * Source PostCSS plugin name.
20
+ */
21
+ plugin?: string
22
+
23
+ /**
24
+ * Message type.
25
+ */
26
+ type: string
27
+ }
28
+
29
+ export interface ResultOptions extends ProcessOptions {
30
+ /**
31
+ * The CSS node that was the source of the warning.
32
+ */
33
+ node?: Node
34
+
35
+ /**
36
+ * Name of plugin that created this warning. `Result#warn` will fill it
37
+ * automatically with `Plugin#postcssPlugin` value.
38
+ */
39
+ plugin?: string
40
+ }
41
+
42
+
43
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
44
+ export { Result_ as default }
45
+ }
46
+
47
+ /**
48
+ * Provides the result of the PostCSS transformations.
49
+ *
50
+ * A Result instance is returned by `LazyResult#then`
51
+ * or `Root#toResult` methods.
52
+ *
53
+ * ```js
54
+ * postcss([autoprefixer]).process(css).then(result => {
55
+ * console.log(result.css)
56
+ * })
57
+ * ```
58
+ *
59
+ * ```js
60
+ * const result2 = postcss.parse(css).toResult()
61
+ * ```
62
+ */
63
+ declare class Result_<RootNode = Document | Root> {
64
+ /**
65
+ * A CSS string representing of `Result#root`.
66
+ *
67
+ * ```js
68
+ * postcss.parse('a{}').toResult().css //=> "a{}"
69
+ * ```
70
+ */
71
+ css: string
72
+
73
+ /**
74
+ * Last runned PostCSS plugin.
75
+ */
76
+ lastPlugin: Plugin | TransformCallback
77
+
78
+ /**
79
+ * An instance of `SourceMapGenerator` class from the `source-map` library,
80
+ * representing changes to the `Result#root` instance.
81
+ *
82
+ * ```js
83
+ * result.map.toJSON() //=> { version: 3, file: 'a.css', … }
84
+ * ```
85
+ *
86
+ * ```js
87
+ * if (result.map) {
88
+ * fs.writeFileSync(result.opts.to + '.map', result.map.toString())
89
+ * }
90
+ * ```
91
+ */
92
+ map: SourceMap
93
+
94
+ /**
95
+ * Contains messages from plugins (e.g., warnings or custom messages).
96
+ * Each message should have type and plugin properties.
97
+ *
98
+ * ```js
99
+ * AtRule: {
100
+ * import: (atRule, { result }) {
101
+ * const importedFile = parseImport(atRule)
102
+ * result.messages.push({
103
+ * type: 'dependency',
104
+ * plugin: 'postcss-import',
105
+ * file: importedFile,
106
+ * parent: result.opts.from
107
+ * })
108
+ * }
109
+ * }
110
+ * ```
111
+ */
112
+ messages: Result.Message[]
113
+
114
+ /**
115
+ * Options from the `Processor#process` or `Root#toResult` call
116
+ * that produced this Result instance.]
117
+ *
118
+ * ```js
119
+ * root.toResult(opts).opts === opts
120
+ * ```
121
+ */
122
+ opts: Result.ResultOptions
123
+
124
+ /**
125
+ * The Processor instance used for this transformation.
126
+ *
127
+ * ```js
128
+ * for (const plugin of result.processor.plugins) {
129
+ * if (plugin.postcssPlugin === 'postcss-bad') {
130
+ * throw 'postcss-good is incompatible with postcss-bad'
131
+ * }
132
+ * })
133
+ * ```
134
+ */
135
+ processor: Processor
136
+
137
+ /**
138
+ * Root node after all transformations.
139
+ *
140
+ * ```js
141
+ * root.toResult().root === root
142
+ * ```
143
+ */
144
+ root: RootNode
145
+
146
+ /**
147
+ * @param processor Processor used for this transformation.
148
+ * @param root Root node after all transformations.
149
+ * @param opts Options from the `Processor#process` or `Root#toResult`.
150
+ */
151
+ constructor(processor: Processor, root: RootNode, opts: Result.ResultOptions)
152
+
153
+ /**
154
+ * Returns for `Result#css` content.
155
+ *
156
+ * ```js
157
+ * result + '' === result.css
158
+ * ```
159
+ *
160
+ * @return String representing of `Result#root`.
161
+ */
162
+ toString(): string
163
+
164
+ /**
165
+ * Creates an instance of `Warning` and adds it to `Result#messages`.
166
+ *
167
+ * ```js
168
+ * if (decl.important) {
169
+ * result.warn('Avoid !important', { node: decl, word: '!important' })
170
+ * }
171
+ * ```
172
+ *
173
+ * @param text Warning message.
174
+ * @param opts Warning options.
175
+ * @return Created warning.
176
+ */
177
+ warn(message: string, options?: WarningOptions): Warning
178
+
179
+ /**
180
+ * Returns warnings from plugins. Filters `Warning` instances
181
+ * from `Result#messages`.
182
+ *
183
+ * ```js
184
+ * result.warnings().forEach(warn => {
185
+ * console.warn(warn.toString())
186
+ * })
187
+ * ```
188
+ *
189
+ * @return Warnings from plugins.
190
+ */
191
+ warnings(): Warning[]
192
+
193
+ /**
194
+ * An alias for the `Result#css` property.
195
+ * Use it with syntaxes that generate non-CSS output.
196
+ *
197
+ * ```js
198
+ * result.css === result.content
199
+ * ```
200
+ */
201
+ get content(): string
202
+ }
203
+
204
+ declare class Result<RootNode = Document | Root> extends Result_<RootNode> {}
205
+
206
+ export = Result
@@ -0,0 +1,42 @@
1
+ 'use strict'
2
+
3
+ let Warning = require('./warning')
4
+
5
+ class Result {
6
+ constructor(processor, root, opts) {
7
+ this.processor = processor
8
+ this.messages = []
9
+ this.root = root
10
+ this.opts = opts
11
+ this.css = undefined
12
+ this.map = undefined
13
+ }
14
+
15
+ toString() {
16
+ return this.css
17
+ }
18
+
19
+ warn(text, opts = {}) {
20
+ if (!opts.plugin) {
21
+ if (this.lastPlugin && this.lastPlugin.postcssPlugin) {
22
+ opts.plugin = this.lastPlugin.postcssPlugin
23
+ }
24
+ }
25
+
26
+ let warning = new Warning(text, opts)
27
+ this.messages.push(warning)
28
+
29
+ return warning
30
+ }
31
+
32
+ warnings() {
33
+ return this.messages.filter(i => i.type === 'warning')
34
+ }
35
+
36
+ get content() {
37
+ return this.css
38
+ }
39
+ }
40
+
41
+ module.exports = Result
42
+ Result.default = Result
@@ -0,0 +1,86 @@
1
+ import Container, { ContainerProps } from './container.js'
2
+ import Document from './document.js'
3
+ import { ProcessOptions } from './postcss.js'
4
+ import Result from './result.js'
5
+
6
+ declare namespace Root {
7
+ export interface RootRaws extends Record<string, any> {
8
+ /**
9
+ * The space symbols after the last child to the end of file.
10
+ */
11
+ after?: string
12
+
13
+ /**
14
+ * Non-CSS code after `Root`, when `Root` is inside `Document`.
15
+ *
16
+ * **Experimental:** some aspects of this node could change within minor
17
+ * or patch version releases.
18
+ */
19
+ codeAfter?: string
20
+
21
+ /**
22
+ * Non-CSS code before `Root`, when `Root` is inside `Document`.
23
+ *
24
+ * **Experimental:** some aspects of this node could change within minor
25
+ * or patch version releases.
26
+ */
27
+ codeBefore?: string
28
+
29
+ /**
30
+ * Is the last child has an (optional) semicolon.
31
+ */
32
+ semicolon?: boolean
33
+ }
34
+
35
+ export interface RootProps extends ContainerProps {
36
+ /**
37
+ * Information used to generate byte-to-byte equal node string
38
+ * as it was in the origin input.
39
+ * */
40
+ raws?: RootRaws
41
+ }
42
+
43
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
44
+ export { Root_ as default }
45
+ }
46
+
47
+ /**
48
+ * Represents a CSS file and contains all its parsed nodes.
49
+ *
50
+ * ```js
51
+ * const root = postcss.parse('a{color:black} b{z-index:2}')
52
+ * root.type //=> 'root'
53
+ * root.nodes.length //=> 2
54
+ * ```
55
+ */
56
+ declare class Root_ extends Container {
57
+ parent: Document | undefined
58
+ raws: Root.RootRaws
59
+ type: 'root'
60
+
61
+ constructor(defaults?: Root.RootProps)
62
+
63
+ assign(overrides: object | Root.RootProps): this
64
+ clone(overrides?: Partial<Root.RootProps>): Root
65
+ cloneAfter(overrides?: Partial<Root.RootProps>): Root
66
+ cloneBefore(overrides?: Partial<Root.RootProps>): Root
67
+
68
+ /**
69
+ * Returns a `Result` instance representing the root’s CSS.
70
+ *
71
+ * ```js
72
+ * const root1 = postcss.parse(css1, { from: 'a.css' })
73
+ * const root2 = postcss.parse(css2, { from: 'b.css' })
74
+ * root1.append(root2)
75
+ * const result = root1.toResult({ to: 'all.css', map: true })
76
+ * ```
77
+ *
78
+ * @param opts Options.
79
+ * @return Result with current root’s CSS.
80
+ */
81
+ toResult(options?: ProcessOptions): Result
82
+ }
83
+
84
+ declare class Root extends Root_ {}
85
+
86
+ export = Root