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,359 @@
1
+ 'use strict'
2
+
3
+ let { SourceMapConsumer, SourceMapGenerator } = require('source-map-js')
4
+ let { dirname, relative, resolve, sep } = require('path')
5
+ let { pathToFileURL } = require('url')
6
+
7
+ let Input = require('./input')
8
+
9
+ let sourceMapAvailable = Boolean(SourceMapConsumer && SourceMapGenerator)
10
+ let pathAvailable = Boolean(dirname && resolve && relative && sep)
11
+
12
+ class MapGenerator {
13
+ constructor(stringify, root, opts, cssString) {
14
+ this.stringify = stringify
15
+ this.mapOpts = opts.map || {}
16
+ this.root = root
17
+ this.opts = opts
18
+ this.css = cssString
19
+ this.usesFileUrls = !this.mapOpts.from && this.mapOpts.absolute
20
+
21
+ this.memoizedFileURLs = new Map()
22
+ this.memoizedPaths = new Map()
23
+ this.memoizedURLs = new Map()
24
+ }
25
+
26
+ addAnnotation() {
27
+ let content
28
+
29
+ if (this.isInline()) {
30
+ content =
31
+ 'data:application/json;base64,' + this.toBase64(this.map.toString())
32
+ } else if (typeof this.mapOpts.annotation === 'string') {
33
+ content = this.mapOpts.annotation
34
+ } else if (typeof this.mapOpts.annotation === 'function') {
35
+ content = this.mapOpts.annotation(this.opts.to, this.root)
36
+ } else {
37
+ content = this.outputFile() + '.map'
38
+ }
39
+ let eol = '\n'
40
+ if (this.css.includes('\r\n')) eol = '\r\n'
41
+
42
+ this.css += eol + '/*# sourceMappingURL=' + content + ' */'
43
+ }
44
+
45
+ applyPrevMaps() {
46
+ for (let prev of this.previous()) {
47
+ let from = this.toUrl(this.path(prev.file))
48
+ let root = prev.root || dirname(prev.file)
49
+ let map
50
+
51
+ if (this.mapOpts.sourcesContent === false) {
52
+ map = new SourceMapConsumer(prev.text)
53
+ if (map.sourcesContent) {
54
+ map.sourcesContent = map.sourcesContent.map(() => null)
55
+ }
56
+ } else {
57
+ map = prev.consumer()
58
+ }
59
+
60
+ this.map.applySourceMap(map, from, this.toUrl(this.path(root)))
61
+ }
62
+ }
63
+
64
+ clearAnnotation() {
65
+ if (this.mapOpts.annotation === false) return
66
+
67
+ if (this.root) {
68
+ let node
69
+ for (let i = this.root.nodes.length - 1; i >= 0; i--) {
70
+ node = this.root.nodes[i]
71
+ if (node.type !== 'comment') continue
72
+ if (node.text.indexOf('# sourceMappingURL=') === 0) {
73
+ this.root.removeChild(i)
74
+ }
75
+ }
76
+ } else if (this.css) {
77
+ this.css = this.css.replace(/(\n)?\/\*#[\S\s]*?\*\/$/gm, '')
78
+ }
79
+ }
80
+
81
+ generate() {
82
+ this.clearAnnotation()
83
+ if (pathAvailable && sourceMapAvailable && this.isMap()) {
84
+ return this.generateMap()
85
+ } else {
86
+ let result = ''
87
+ this.stringify(this.root, i => {
88
+ result += i
89
+ })
90
+ return [result]
91
+ }
92
+ }
93
+
94
+ generateMap() {
95
+ if (this.root) {
96
+ this.generateString()
97
+ } else if (this.previous().length === 1) {
98
+ let prev = this.previous()[0].consumer()
99
+ prev.file = this.outputFile()
100
+ this.map = SourceMapGenerator.fromSourceMap(prev)
101
+ } else {
102
+ this.map = new SourceMapGenerator({ file: this.outputFile() })
103
+ this.map.addMapping({
104
+ generated: { column: 0, line: 1 },
105
+ original: { column: 0, line: 1 },
106
+ source: this.opts.from
107
+ ? this.toUrl(this.path(this.opts.from))
108
+ : '<no source>'
109
+ })
110
+ }
111
+
112
+ if (this.isSourcesContent()) this.setSourcesContent()
113
+ if (this.root && this.previous().length > 0) this.applyPrevMaps()
114
+ if (this.isAnnotation()) this.addAnnotation()
115
+
116
+ if (this.isInline()) {
117
+ return [this.css]
118
+ } else {
119
+ return [this.css, this.map]
120
+ }
121
+ }
122
+
123
+ generateString() {
124
+ this.css = ''
125
+ this.map = new SourceMapGenerator({ file: this.outputFile() })
126
+
127
+ let line = 1
128
+ let column = 1
129
+
130
+ let noSource = '<no source>'
131
+ let mapping = {
132
+ generated: { column: 0, line: 0 },
133
+ original: { column: 0, line: 0 },
134
+ source: ''
135
+ }
136
+
137
+ let lines, last
138
+ this.stringify(this.root, (str, node, type) => {
139
+ this.css += str
140
+
141
+ if (node && type !== 'end') {
142
+ mapping.generated.line = line
143
+ mapping.generated.column = column - 1
144
+ if (node.source && node.source.start) {
145
+ mapping.source = this.sourcePath(node)
146
+ mapping.original.line = node.source.start.line
147
+ mapping.original.column = node.source.start.column - 1
148
+ this.map.addMapping(mapping)
149
+ } else {
150
+ mapping.source = noSource
151
+ mapping.original.line = 1
152
+ mapping.original.column = 0
153
+ this.map.addMapping(mapping)
154
+ }
155
+ }
156
+
157
+ lines = str.match(/\n/g)
158
+ if (lines) {
159
+ line += lines.length
160
+ last = str.lastIndexOf('\n')
161
+ column = str.length - last
162
+ } else {
163
+ column += str.length
164
+ }
165
+
166
+ if (node && type !== 'start') {
167
+ let p = node.parent || { raws: {} }
168
+ let childless =
169
+ node.type === 'decl' || (node.type === 'atrule' && !node.nodes)
170
+ if (!childless || node !== p.last || p.raws.semicolon) {
171
+ if (node.source && node.source.end) {
172
+ mapping.source = this.sourcePath(node)
173
+ mapping.original.line = node.source.end.line
174
+ mapping.original.column = node.source.end.column - 1
175
+ mapping.generated.line = line
176
+ mapping.generated.column = column - 2
177
+ this.map.addMapping(mapping)
178
+ } else {
179
+ mapping.source = noSource
180
+ mapping.original.line = 1
181
+ mapping.original.column = 0
182
+ mapping.generated.line = line
183
+ mapping.generated.column = column - 1
184
+ this.map.addMapping(mapping)
185
+ }
186
+ }
187
+ }
188
+ })
189
+ }
190
+
191
+ isAnnotation() {
192
+ if (this.isInline()) {
193
+ return true
194
+ }
195
+ if (typeof this.mapOpts.annotation !== 'undefined') {
196
+ return this.mapOpts.annotation
197
+ }
198
+ if (this.previous().length) {
199
+ return this.previous().some(i => i.annotation)
200
+ }
201
+ return true
202
+ }
203
+
204
+ isInline() {
205
+ if (typeof this.mapOpts.inline !== 'undefined') {
206
+ return this.mapOpts.inline
207
+ }
208
+
209
+ let annotation = this.mapOpts.annotation
210
+ if (typeof annotation !== 'undefined' && annotation !== true) {
211
+ return false
212
+ }
213
+
214
+ if (this.previous().length) {
215
+ return this.previous().some(i => i.inline)
216
+ }
217
+ return true
218
+ }
219
+
220
+ isMap() {
221
+ if (typeof this.opts.map !== 'undefined') {
222
+ return !!this.opts.map
223
+ }
224
+ return this.previous().length > 0
225
+ }
226
+
227
+ isSourcesContent() {
228
+ if (typeof this.mapOpts.sourcesContent !== 'undefined') {
229
+ return this.mapOpts.sourcesContent
230
+ }
231
+ if (this.previous().length) {
232
+ return this.previous().some(i => i.withContent())
233
+ }
234
+ return true
235
+ }
236
+
237
+ outputFile() {
238
+ if (this.opts.to) {
239
+ return this.path(this.opts.to)
240
+ } else if (this.opts.from) {
241
+ return this.path(this.opts.from)
242
+ } else {
243
+ return 'to.css'
244
+ }
245
+ }
246
+
247
+ path(file) {
248
+ if (this.mapOpts.absolute) return file
249
+ if (file.charCodeAt(0) === 60 /* `<` */) return file
250
+ if (/^\w+:\/\//.test(file)) return file
251
+ let cached = this.memoizedPaths.get(file)
252
+ if (cached) return cached
253
+
254
+ let from = this.opts.to ? dirname(this.opts.to) : '.'
255
+
256
+ if (typeof this.mapOpts.annotation === 'string') {
257
+ from = dirname(resolve(from, this.mapOpts.annotation))
258
+ }
259
+
260
+ let path = relative(from, file)
261
+ this.memoizedPaths.set(file, path)
262
+
263
+ return path
264
+ }
265
+
266
+ previous() {
267
+ if (!this.previousMaps) {
268
+ this.previousMaps = []
269
+ if (this.root) {
270
+ this.root.walk(node => {
271
+ if (node.source && node.source.input.map) {
272
+ let map = node.source.input.map
273
+ if (!this.previousMaps.includes(map)) {
274
+ this.previousMaps.push(map)
275
+ }
276
+ }
277
+ })
278
+ } else {
279
+ let input = new Input(this.css, this.opts)
280
+ if (input.map) this.previousMaps.push(input.map)
281
+ }
282
+ }
283
+
284
+ return this.previousMaps
285
+ }
286
+
287
+ setSourcesContent() {
288
+ let already = {}
289
+ if (this.root) {
290
+ this.root.walk(node => {
291
+ if (node.source) {
292
+ let from = node.source.input.from
293
+ if (from && !already[from]) {
294
+ already[from] = true
295
+ let fromUrl = this.usesFileUrls
296
+ ? this.toFileUrl(from)
297
+ : this.toUrl(this.path(from))
298
+ this.map.setSourceContent(fromUrl, node.source.input.css)
299
+ }
300
+ }
301
+ })
302
+ } else if (this.css) {
303
+ let from = this.opts.from
304
+ ? this.toUrl(this.path(this.opts.from))
305
+ : '<no source>'
306
+ this.map.setSourceContent(from, this.css)
307
+ }
308
+ }
309
+
310
+ sourcePath(node) {
311
+ if (this.mapOpts.from) {
312
+ return this.toUrl(this.mapOpts.from)
313
+ } else if (this.usesFileUrls) {
314
+ return this.toFileUrl(node.source.input.from)
315
+ } else {
316
+ return this.toUrl(this.path(node.source.input.from))
317
+ }
318
+ }
319
+
320
+ toBase64(str) {
321
+ if (Buffer) {
322
+ return Buffer.from(str).toString('base64')
323
+ } else {
324
+ return window.btoa(unescape(encodeURIComponent(str)))
325
+ }
326
+ }
327
+
328
+ toFileUrl(path) {
329
+ let cached = this.memoizedFileURLs.get(path)
330
+ if (cached) return cached
331
+
332
+ if (pathToFileURL) {
333
+ let fileURL = pathToFileURL(path).toString()
334
+ this.memoizedFileURLs.set(path, fileURL)
335
+
336
+ return fileURL
337
+ } else {
338
+ throw new Error(
339
+ '`map.absolute` option is not available in this PostCSS build'
340
+ )
341
+ }
342
+ }
343
+
344
+ toUrl(path) {
345
+ let cached = this.memoizedURLs.get(path)
346
+ if (cached) return cached
347
+
348
+ if (sep === '\\') {
349
+ path = path.replace(/\\/g, '/')
350
+ }
351
+
352
+ let url = encodeURI(path).replace(/[#?]/g, encodeURIComponent)
353
+ this.memoizedURLs.set(path, url)
354
+
355
+ return url
356
+ }
357
+ }
358
+
359
+ module.exports = MapGenerator
@@ -0,0 +1,46 @@
1
+ import LazyResult from './lazy-result.js'
2
+ import { SourceMap } from './postcss.js'
3
+ import Processor from './processor.js'
4
+ import Result, { Message, ResultOptions } from './result.js'
5
+ import Root from './root.js'
6
+ import Warning from './warning.js'
7
+
8
+ declare namespace NoWorkResult {
9
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
10
+ export { NoWorkResult_ as default }
11
+ }
12
+
13
+ /**
14
+ * A Promise proxy for the result of PostCSS transformations.
15
+ * This lazy result instance doesn't parse css unless `NoWorkResult#root` or `Result#root`
16
+ * are accessed. See the example below for details.
17
+ * A `NoWork` instance is returned by `Processor#process` ONLY when no plugins defined.
18
+ *
19
+ * ```js
20
+ * const noWorkResult = postcss().process(css) // No plugins are defined.
21
+ * // CSS is not parsed
22
+ * let root = noWorkResult.root // now css is parsed because we accessed the root
23
+ * ```
24
+ */
25
+ declare class NoWorkResult_ implements LazyResult<Root> {
26
+ catch: Promise<Result<Root>>['catch']
27
+ finally: Promise<Result<Root>>['finally']
28
+ then: Promise<Result<Root>>['then']
29
+ constructor(processor: Processor, css: string, opts: ResultOptions)
30
+ async(): Promise<Result<Root>>
31
+ sync(): Result<Root>
32
+ toString(): string
33
+ warnings(): Warning[]
34
+ get content(): string
35
+ get css(): string
36
+ get map(): SourceMap
37
+ get messages(): Message[]
38
+ get opts(): ResultOptions
39
+ get processor(): Processor
40
+ get root(): Root
41
+ get [Symbol.toStringTag](): string
42
+ }
43
+
44
+ declare class NoWorkResult extends NoWorkResult_ {}
45
+
46
+ export = NoWorkResult
@@ -0,0 +1,135 @@
1
+ 'use strict'
2
+
3
+ let MapGenerator = require('./map-generator')
4
+ let stringify = require('./stringify')
5
+ let warnOnce = require('./warn-once')
6
+ let parse = require('./parse')
7
+ const Result = require('./result')
8
+
9
+ class NoWorkResult {
10
+ constructor(processor, css, opts) {
11
+ css = css.toString()
12
+ this.stringified = false
13
+
14
+ this._processor = processor
15
+ this._css = css
16
+ this._opts = opts
17
+ this._map = undefined
18
+ let root
19
+
20
+ let str = stringify
21
+ this.result = new Result(this._processor, root, this._opts)
22
+ this.result.css = css
23
+
24
+ let self = this
25
+ Object.defineProperty(this.result, 'root', {
26
+ get() {
27
+ return self.root
28
+ }
29
+ })
30
+
31
+ let map = new MapGenerator(str, root, this._opts, css)
32
+ if (map.isMap()) {
33
+ let [generatedCSS, generatedMap] = map.generate()
34
+ if (generatedCSS) {
35
+ this.result.css = generatedCSS
36
+ }
37
+ if (generatedMap) {
38
+ this.result.map = generatedMap
39
+ }
40
+ }
41
+ }
42
+
43
+ async() {
44
+ if (this.error) return Promise.reject(this.error)
45
+ return Promise.resolve(this.result)
46
+ }
47
+
48
+ catch(onRejected) {
49
+ return this.async().catch(onRejected)
50
+ }
51
+
52
+ finally(onFinally) {
53
+ return this.async().then(onFinally, onFinally)
54
+ }
55
+
56
+ sync() {
57
+ if (this.error) throw this.error
58
+ return this.result
59
+ }
60
+
61
+ then(onFulfilled, onRejected) {
62
+ if (process.env.NODE_ENV !== 'production') {
63
+ if (!('from' in this._opts)) {
64
+ warnOnce(
65
+ 'Without `from` option PostCSS could generate wrong source map ' +
66
+ 'and will not find Browserslist config. Set it to CSS file path ' +
67
+ 'or to `undefined` to prevent this warning.'
68
+ )
69
+ }
70
+ }
71
+
72
+ return this.async().then(onFulfilled, onRejected)
73
+ }
74
+
75
+ toString() {
76
+ return this._css
77
+ }
78
+
79
+ warnings() {
80
+ return []
81
+ }
82
+
83
+ get content() {
84
+ return this.result.css
85
+ }
86
+
87
+ get css() {
88
+ return this.result.css
89
+ }
90
+
91
+ get map() {
92
+ return this.result.map
93
+ }
94
+
95
+ get messages() {
96
+ return []
97
+ }
98
+
99
+ get opts() {
100
+ return this.result.opts
101
+ }
102
+
103
+ get processor() {
104
+ return this.result.processor
105
+ }
106
+
107
+ get root() {
108
+ if (this._root) {
109
+ return this._root
110
+ }
111
+
112
+ let root
113
+ let parser = parse
114
+
115
+ try {
116
+ root = parser(this._css, this._opts)
117
+ } catch (error) {
118
+ this.error = error
119
+ }
120
+
121
+ if (this.error) {
122
+ throw this.error
123
+ } else {
124
+ this._root = root
125
+ return root
126
+ }
127
+ }
128
+
129
+ get [Symbol.toStringTag]() {
130
+ return 'NoWorkResult'
131
+ }
132
+ }
133
+
134
+ module.exports = NoWorkResult
135
+ NoWorkResult.default = NoWorkResult