plugin-build-guide-block 1.0.2 → 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.
- package/dist/node_modules/sanitize-html/LICENSE +7 -0
- package/dist/node_modules/sanitize-html/index.js +7 -0
- package/dist/node_modules/sanitize-html/node_modules/nanoid/async/index.browser.cjs +34 -0
- package/dist/node_modules/sanitize-html/node_modules/nanoid/async/index.browser.js +34 -0
- package/dist/node_modules/sanitize-html/node_modules/nanoid/async/index.cjs +35 -0
- package/dist/node_modules/sanitize-html/node_modules/nanoid/async/index.d.ts +56 -0
- package/dist/node_modules/sanitize-html/node_modules/nanoid/async/index.js +35 -0
- package/dist/node_modules/sanitize-html/node_modules/nanoid/async/index.native.js +26 -0
- package/dist/node_modules/sanitize-html/node_modules/nanoid/async/package.json +12 -0
- package/dist/node_modules/sanitize-html/node_modules/nanoid/bin/nanoid.cjs +55 -0
- package/dist/node_modules/sanitize-html/node_modules/nanoid/index.browser.cjs +34 -0
- package/dist/node_modules/sanitize-html/node_modules/nanoid/index.browser.js +34 -0
- package/dist/node_modules/sanitize-html/node_modules/nanoid/index.cjs +45 -0
- package/dist/node_modules/sanitize-html/node_modules/nanoid/index.d.cts +91 -0
- package/dist/node_modules/sanitize-html/node_modules/nanoid/index.d.ts +91 -0
- package/dist/node_modules/sanitize-html/node_modules/nanoid/index.js +45 -0
- package/dist/node_modules/sanitize-html/node_modules/nanoid/nanoid.js +1 -0
- package/dist/node_modules/sanitize-html/node_modules/nanoid/non-secure/index.cjs +21 -0
- package/dist/node_modules/sanitize-html/node_modules/nanoid/non-secure/index.d.ts +33 -0
- package/dist/node_modules/sanitize-html/node_modules/nanoid/non-secure/index.js +21 -0
- package/dist/node_modules/sanitize-html/node_modules/nanoid/non-secure/package.json +6 -0
- package/dist/node_modules/sanitize-html/node_modules/nanoid/package.json +88 -0
- package/dist/node_modules/sanitize-html/node_modules/nanoid/url-alphabet/index.cjs +3 -0
- package/dist/node_modules/sanitize-html/node_modules/nanoid/url-alphabet/index.js +3 -0
- package/dist/node_modules/sanitize-html/node_modules/nanoid/url-alphabet/package.json +6 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/at-rule.d.ts +115 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/at-rule.js +25 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/comment.d.ts +67 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/comment.js +13 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/container.d.ts +452 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/container.js +439 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/css-syntax-error.d.ts +248 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/css-syntax-error.js +100 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/declaration.d.ts +148 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/declaration.js +24 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/document.d.ts +68 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/document.js +33 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/fromJSON.d.ts +9 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/fromJSON.js +54 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/input.d.ts +194 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/input.js +248 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/lazy-result.d.ts +190 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/lazy-result.js +550 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/list.d.ts +57 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/list.js +58 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/map-generator.js +359 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/no-work-result.d.ts +46 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/no-work-result.js +135 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/node.d.ts +536 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/node.js +381 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/parse.d.ts +9 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/parse.js +42 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/parser.js +610 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/postcss.d.mts +72 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/postcss.d.ts +441 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/postcss.js +101 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/previous-map.d.ts +81 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/previous-map.js +142 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/processor.d.ts +115 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/processor.js +67 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/result.d.ts +206 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/result.js +42 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/root.d.ts +86 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/root.js +61 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/rule.d.ts +113 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/rule.js +27 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/stringifier.d.ts +46 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/stringifier.js +353 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/stringify.d.ts +9 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/stringify.js +11 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/symbols.js +5 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/terminal-highlight.js +70 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/tokenize.js +266 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/warn-once.js +13 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/warning.d.ts +147 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/lib/warning.js +37 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/node_modules/.bin/nanoid +15 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/node_modules/.bin/nanoid.cmd +7 -0
- package/dist/node_modules/sanitize-html/node_modules/postcss/package.json +88 -0
- package/dist/node_modules/sanitize-html/package.json +1 -0
- package/package.json +9 -1
- package/src/client/UserGuideBlock.tsx +53 -0
- package/src/client/UserGuideBlockInitializer.tsx +26 -0
- package/src/client/UserGuideBlockProvider.tsx +12 -0
- package/src/client/UserGuideManager.tsx +133 -0
- package/src/client/client.d.ts +249 -0
- package/src/client/components/BuildButton.tsx +43 -0
- package/src/client/components/LLMServiceSelect.tsx +44 -0
- package/src/client/components/ModelSelect.tsx +41 -0
- package/src/client/components/StatusTag.tsx +17 -0
- package/src/client/index.tsx +1 -0
- package/src/client/models/UserGuideBlockModel.ts +47 -0
- package/src/client/models/index.ts +12 -0
- package/src/client/plugin.tsx +30 -0
- package/src/client/schemas/spacesSchema.ts +305 -0
- package/src/index.ts +2 -0
- package/src/locale/en-US.json +27 -0
- package/src/locale/vi-VN.json +27 -0
- package/src/locale/zh-CN.json +27 -0
- package/src/server/actions/build.ts +171 -0
- package/src/server/actions/getHtml.ts +26 -0
- package/src/server/collections/.gitkeep +0 -0
- package/src/server/collections/ai-build-guide-spaces.ts +49 -0
- package/src/server/index.ts +1 -0
- package/src/server/plugin.ts +42 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
let pico = require('picocolors')
|
|
4
|
+
|
|
5
|
+
let terminalHighlight = require('./terminal-highlight')
|
|
6
|
+
|
|
7
|
+
class CssSyntaxError extends Error {
|
|
8
|
+
constructor(message, line, column, source, file, plugin) {
|
|
9
|
+
super(message)
|
|
10
|
+
this.name = 'CssSyntaxError'
|
|
11
|
+
this.reason = message
|
|
12
|
+
|
|
13
|
+
if (file) {
|
|
14
|
+
this.file = file
|
|
15
|
+
}
|
|
16
|
+
if (source) {
|
|
17
|
+
this.source = source
|
|
18
|
+
}
|
|
19
|
+
if (plugin) {
|
|
20
|
+
this.plugin = plugin
|
|
21
|
+
}
|
|
22
|
+
if (typeof line !== 'undefined' && typeof column !== 'undefined') {
|
|
23
|
+
if (typeof line === 'number') {
|
|
24
|
+
this.line = line
|
|
25
|
+
this.column = column
|
|
26
|
+
} else {
|
|
27
|
+
this.line = line.line
|
|
28
|
+
this.column = line.column
|
|
29
|
+
this.endLine = column.line
|
|
30
|
+
this.endColumn = column.column
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
this.setMessage()
|
|
35
|
+
|
|
36
|
+
if (Error.captureStackTrace) {
|
|
37
|
+
Error.captureStackTrace(this, CssSyntaxError)
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
setMessage() {
|
|
42
|
+
this.message = this.plugin ? this.plugin + ': ' : ''
|
|
43
|
+
this.message += this.file ? this.file : '<css input>'
|
|
44
|
+
if (typeof this.line !== 'undefined') {
|
|
45
|
+
this.message += ':' + this.line + ':' + this.column
|
|
46
|
+
}
|
|
47
|
+
this.message += ': ' + this.reason
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
showSourceCode(color) {
|
|
51
|
+
if (!this.source) return ''
|
|
52
|
+
|
|
53
|
+
let css = this.source
|
|
54
|
+
if (color == null) color = pico.isColorSupported
|
|
55
|
+
if (terminalHighlight) {
|
|
56
|
+
if (color) css = terminalHighlight(css)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
let lines = css.split(/\r?\n/)
|
|
60
|
+
let start = Math.max(this.line - 3, 0)
|
|
61
|
+
let end = Math.min(this.line + 2, lines.length)
|
|
62
|
+
|
|
63
|
+
let maxWidth = String(end).length
|
|
64
|
+
|
|
65
|
+
let mark, aside
|
|
66
|
+
if (color) {
|
|
67
|
+
let { bold, gray, red } = pico.createColors(true)
|
|
68
|
+
mark = text => bold(red(text))
|
|
69
|
+
aside = text => gray(text)
|
|
70
|
+
} else {
|
|
71
|
+
mark = aside = str => str
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return lines
|
|
75
|
+
.slice(start, end)
|
|
76
|
+
.map((line, index) => {
|
|
77
|
+
let number = start + 1 + index
|
|
78
|
+
let gutter = ' ' + (' ' + number).slice(-maxWidth) + ' | '
|
|
79
|
+
if (number === this.line) {
|
|
80
|
+
let spacing =
|
|
81
|
+
aside(gutter.replace(/\d/g, ' ')) +
|
|
82
|
+
line.slice(0, this.column - 1).replace(/[^\t]/g, ' ')
|
|
83
|
+
return mark('>') + aside(gutter) + line + '\n ' + spacing + mark('^')
|
|
84
|
+
}
|
|
85
|
+
return ' ' + aside(gutter) + line
|
|
86
|
+
})
|
|
87
|
+
.join('\n')
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
toString() {
|
|
91
|
+
let code = this.showSourceCode()
|
|
92
|
+
if (code) {
|
|
93
|
+
code = '\n\n' + code + '\n'
|
|
94
|
+
}
|
|
95
|
+
return this.name + ': ' + this.message + code
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
module.exports = CssSyntaxError
|
|
100
|
+
CssSyntaxError.default = CssSyntaxError
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import Container from './container.js'
|
|
2
|
+
import Node from './node.js'
|
|
3
|
+
|
|
4
|
+
declare namespace Declaration {
|
|
5
|
+
export interface DeclarationRaws extends Record<string, unknown> {
|
|
6
|
+
/**
|
|
7
|
+
* The space symbols before the node. It also stores `*`
|
|
8
|
+
* and `_` symbols before the declaration (IE hack).
|
|
9
|
+
*/
|
|
10
|
+
before?: string
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The symbols between the property and value for declarations.
|
|
14
|
+
*/
|
|
15
|
+
between?: string
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The content of the important statement, if it is not just `!important`.
|
|
19
|
+
*/
|
|
20
|
+
important?: string
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Declaration value with comments.
|
|
24
|
+
*/
|
|
25
|
+
value?: {
|
|
26
|
+
raw: string
|
|
27
|
+
value: string
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface DeclarationProps {
|
|
32
|
+
/** Whether the declaration has an `!important` annotation. */
|
|
33
|
+
important?: boolean
|
|
34
|
+
/** Name of the declaration. */
|
|
35
|
+
prop: string
|
|
36
|
+
/** Information used to generate byte-to-byte equal node string as it was in the origin input. */
|
|
37
|
+
raws?: DeclarationRaws
|
|
38
|
+
/** Value of the declaration. */
|
|
39
|
+
value: string
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
43
|
+
export { Declaration_ as default }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* It represents a class that handles
|
|
48
|
+
* [CSS declarations](https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax#css_declarations)
|
|
49
|
+
*
|
|
50
|
+
* ```js
|
|
51
|
+
* Once (root, { Declaration }) {
|
|
52
|
+
* const color = new Declaration({ prop: 'color', value: 'black' })
|
|
53
|
+
* root.append(color)
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* ```js
|
|
58
|
+
* const root = postcss.parse('a { color: black }')
|
|
59
|
+
* const decl = root.first?.first
|
|
60
|
+
*
|
|
61
|
+
* decl.type //=> 'decl'
|
|
62
|
+
* decl.toString() //=> ' color: black'
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
declare class Declaration_ extends Node {
|
|
66
|
+
/**
|
|
67
|
+
* It represents a specificity of the declaration.
|
|
68
|
+
*
|
|
69
|
+
* If true, the CSS declaration will have an
|
|
70
|
+
* [important](https://developer.mozilla.org/en-US/docs/Web/CSS/important)
|
|
71
|
+
* specifier.
|
|
72
|
+
*
|
|
73
|
+
* ```js
|
|
74
|
+
* const root = postcss.parse('a { color: black !important; color: red }')
|
|
75
|
+
*
|
|
76
|
+
* root.first.first.important //=> true
|
|
77
|
+
* root.first.last.important //=> undefined
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
important: boolean
|
|
81
|
+
|
|
82
|
+
parent: Container | undefined
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The property name for a CSS declaration.
|
|
86
|
+
*
|
|
87
|
+
* ```js
|
|
88
|
+
* const root = postcss.parse('a { color: black }')
|
|
89
|
+
* const decl = root.first.first
|
|
90
|
+
*
|
|
91
|
+
* decl.prop //=> 'color'
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
prop: string
|
|
95
|
+
|
|
96
|
+
raws: Declaration.DeclarationRaws
|
|
97
|
+
|
|
98
|
+
type: 'decl'
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The property value for a CSS declaration.
|
|
102
|
+
*
|
|
103
|
+
* Any CSS comments inside the value string will be filtered out.
|
|
104
|
+
* CSS comments present in the source value will be available in
|
|
105
|
+
* the `raws` property.
|
|
106
|
+
*
|
|
107
|
+
* Assigning new `value` would ignore the comments in `raws`
|
|
108
|
+
* property while compiling node to string.
|
|
109
|
+
*
|
|
110
|
+
* ```js
|
|
111
|
+
* const root = postcss.parse('a { color: black }')
|
|
112
|
+
* const decl = root.first.first
|
|
113
|
+
*
|
|
114
|
+
* decl.value //=> 'black'
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
value: string
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* It represents a getter that returns `true` if a declaration starts with
|
|
121
|
+
* `--` or `$`, which are used to declare variables in CSS and SASS/SCSS.
|
|
122
|
+
*
|
|
123
|
+
* ```js
|
|
124
|
+
* const root = postcss.parse(':root { --one: 1 }')
|
|
125
|
+
* const one = root.first.first
|
|
126
|
+
*
|
|
127
|
+
* one.variable //=> true
|
|
128
|
+
* ```
|
|
129
|
+
*
|
|
130
|
+
* ```js
|
|
131
|
+
* const root = postcss.parse('$one: 1')
|
|
132
|
+
* const one = root.first
|
|
133
|
+
*
|
|
134
|
+
* one.variable //=> true
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
variable: boolean
|
|
138
|
+
|
|
139
|
+
constructor(defaults?: Declaration.DeclarationProps)
|
|
140
|
+
assign(overrides: Declaration.DeclarationProps | object): this
|
|
141
|
+
clone(overrides?: Partial<Declaration.DeclarationProps>): Declaration
|
|
142
|
+
cloneAfter(overrides?: Partial<Declaration.DeclarationProps>): Declaration
|
|
143
|
+
cloneBefore(overrides?: Partial<Declaration.DeclarationProps>): Declaration
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
declare class Declaration extends Declaration_ {}
|
|
147
|
+
|
|
148
|
+
export = Declaration
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
let Node = require('./node')
|
|
4
|
+
|
|
5
|
+
class Declaration extends Node {
|
|
6
|
+
constructor(defaults) {
|
|
7
|
+
if (
|
|
8
|
+
defaults &&
|
|
9
|
+
typeof defaults.value !== 'undefined' &&
|
|
10
|
+
typeof defaults.value !== 'string'
|
|
11
|
+
) {
|
|
12
|
+
defaults = { ...defaults, value: String(defaults.value) }
|
|
13
|
+
}
|
|
14
|
+
super(defaults)
|
|
15
|
+
this.type = 'decl'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
get variable() {
|
|
19
|
+
return this.prop.startsWith('--') || this.prop[0] === '$'
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = Declaration
|
|
24
|
+
Declaration.default = Declaration
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import Container, { ContainerProps } from './container.js'
|
|
2
|
+
import { ProcessOptions } from './postcss.js'
|
|
3
|
+
import Result from './result.js'
|
|
4
|
+
import Root from './root.js'
|
|
5
|
+
|
|
6
|
+
declare namespace Document {
|
|
7
|
+
export interface DocumentProps extends ContainerProps {
|
|
8
|
+
nodes?: Root[]
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Information to generate byte-to-byte equal node string as it was
|
|
12
|
+
* in the origin input.
|
|
13
|
+
*
|
|
14
|
+
* Every parser saves its own properties.
|
|
15
|
+
*/
|
|
16
|
+
raws?: Record<string, any>
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
20
|
+
export { Document_ as default }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Represents a file and contains all its parsed nodes.
|
|
25
|
+
*
|
|
26
|
+
* **Experimental:** some aspects of this node could change within minor
|
|
27
|
+
* or patch version releases.
|
|
28
|
+
*
|
|
29
|
+
* ```js
|
|
30
|
+
* const document = htmlParser(
|
|
31
|
+
* '<html><style>a{color:black}</style><style>b{z-index:2}</style>'
|
|
32
|
+
* )
|
|
33
|
+
* document.type //=> 'document'
|
|
34
|
+
* document.nodes.length //=> 2
|
|
35
|
+
* ```
|
|
36
|
+
*/
|
|
37
|
+
declare class Document_ extends Container<Root> {
|
|
38
|
+
parent: undefined
|
|
39
|
+
type: 'document'
|
|
40
|
+
|
|
41
|
+
constructor(defaults?: Document.DocumentProps)
|
|
42
|
+
|
|
43
|
+
assign(overrides: Document.DocumentProps | object): this
|
|
44
|
+
clone(overrides?: Partial<Document.DocumentProps>): Document
|
|
45
|
+
cloneAfter(overrides?: Partial<Document.DocumentProps>): Document
|
|
46
|
+
cloneBefore(overrides?: Partial<Document.DocumentProps>): Document
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Returns a `Result` instance representing the document’s CSS roots.
|
|
50
|
+
*
|
|
51
|
+
* ```js
|
|
52
|
+
* const root1 = postcss.parse(css1, { from: 'a.css' })
|
|
53
|
+
* const root2 = postcss.parse(css2, { from: 'b.css' })
|
|
54
|
+
* const document = postcss.document()
|
|
55
|
+
* document.append(root1)
|
|
56
|
+
* document.append(root2)
|
|
57
|
+
* const result = document.toResult({ to: 'all.css', map: true })
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @param opts Options.
|
|
61
|
+
* @return Result with current document’s CSS.
|
|
62
|
+
*/
|
|
63
|
+
toResult(options?: ProcessOptions): Result
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
declare class Document extends Document_ {}
|
|
67
|
+
|
|
68
|
+
export = Document
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
let Container = require('./container')
|
|
4
|
+
|
|
5
|
+
let LazyResult, Processor
|
|
6
|
+
|
|
7
|
+
class Document extends Container {
|
|
8
|
+
constructor(defaults) {
|
|
9
|
+
// type needs to be passed to super, otherwise child roots won't be normalized correctly
|
|
10
|
+
super({ type: 'document', ...defaults })
|
|
11
|
+
|
|
12
|
+
if (!this.nodes) {
|
|
13
|
+
this.nodes = []
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
toResult(opts = {}) {
|
|
18
|
+
let lazy = new LazyResult(new Processor(), this, opts)
|
|
19
|
+
|
|
20
|
+
return lazy.stringify()
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
Document.registerLazyResult = dependant => {
|
|
25
|
+
LazyResult = dependant
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
Document.registerProcessor = dependant => {
|
|
29
|
+
Processor = dependant
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = Document
|
|
33
|
+
Document.default = Document
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
let Declaration = require('./declaration')
|
|
4
|
+
let PreviousMap = require('./previous-map')
|
|
5
|
+
let Comment = require('./comment')
|
|
6
|
+
let AtRule = require('./at-rule')
|
|
7
|
+
let Input = require('./input')
|
|
8
|
+
let Root = require('./root')
|
|
9
|
+
let Rule = require('./rule')
|
|
10
|
+
|
|
11
|
+
function fromJSON(json, inputs) {
|
|
12
|
+
if (Array.isArray(json)) return json.map(n => fromJSON(n))
|
|
13
|
+
|
|
14
|
+
let { inputs: ownInputs, ...defaults } = json
|
|
15
|
+
if (ownInputs) {
|
|
16
|
+
inputs = []
|
|
17
|
+
for (let input of ownInputs) {
|
|
18
|
+
let inputHydrated = { ...input, __proto__: Input.prototype }
|
|
19
|
+
if (inputHydrated.map) {
|
|
20
|
+
inputHydrated.map = {
|
|
21
|
+
...inputHydrated.map,
|
|
22
|
+
__proto__: PreviousMap.prototype
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
inputs.push(inputHydrated)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (defaults.nodes) {
|
|
29
|
+
defaults.nodes = json.nodes.map(n => fromJSON(n, inputs))
|
|
30
|
+
}
|
|
31
|
+
if (defaults.source) {
|
|
32
|
+
let { inputId, ...source } = defaults.source
|
|
33
|
+
defaults.source = source
|
|
34
|
+
if (inputId != null) {
|
|
35
|
+
defaults.source.input = inputs[inputId]
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (defaults.type === 'root') {
|
|
39
|
+
return new Root(defaults)
|
|
40
|
+
} else if (defaults.type === 'decl') {
|
|
41
|
+
return new Declaration(defaults)
|
|
42
|
+
} else if (defaults.type === 'rule') {
|
|
43
|
+
return new Rule(defaults)
|
|
44
|
+
} else if (defaults.type === 'comment') {
|
|
45
|
+
return new Comment(defaults)
|
|
46
|
+
} else if (defaults.type === 'atrule') {
|
|
47
|
+
return new AtRule(defaults)
|
|
48
|
+
} else {
|
|
49
|
+
throw new Error('Unknown node type: ' + json.type)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = fromJSON
|
|
54
|
+
fromJSON.default = fromJSON
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { CssSyntaxError, ProcessOptions } from './postcss.js'
|
|
2
|
+
import PreviousMap from './previous-map.js'
|
|
3
|
+
|
|
4
|
+
declare namespace Input {
|
|
5
|
+
export interface FilePosition {
|
|
6
|
+
/**
|
|
7
|
+
* Column of inclusive start position in source file.
|
|
8
|
+
*/
|
|
9
|
+
column: number
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Column of exclusive end position in source file.
|
|
13
|
+
*/
|
|
14
|
+
endColumn?: number
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Line of exclusive end position in source file.
|
|
18
|
+
*/
|
|
19
|
+
endLine?: number
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Absolute path to the source file.
|
|
23
|
+
*/
|
|
24
|
+
file?: string
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Line of inclusive start position in source file.
|
|
28
|
+
*/
|
|
29
|
+
line: number
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Source code.
|
|
33
|
+
*/
|
|
34
|
+
source?: string
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* URL for the source file.
|
|
38
|
+
*/
|
|
39
|
+
url: string
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
43
|
+
export { Input_ as default }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Represents the source CSS.
|
|
48
|
+
*
|
|
49
|
+
* ```js
|
|
50
|
+
* const root = postcss.parse(css, { from: file })
|
|
51
|
+
* const input = root.source.input
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
declare class Input_ {
|
|
55
|
+
/**
|
|
56
|
+
* Input CSS source.
|
|
57
|
+
*
|
|
58
|
+
* ```js
|
|
59
|
+
* const input = postcss.parse('a{}', { from: file }).input
|
|
60
|
+
* input.css //=> "a{}"
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
css: string
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* The absolute path to the CSS source file defined
|
|
67
|
+
* with the `from` option.
|
|
68
|
+
*
|
|
69
|
+
* ```js
|
|
70
|
+
* const root = postcss.parse(css, { from: 'a.css' })
|
|
71
|
+
* root.source.input.file //=> '/home/ai/a.css'
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
file?: string
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The flag to indicate whether or not the source code has Unicode BOM.
|
|
78
|
+
*/
|
|
79
|
+
hasBOM: boolean
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* The unique ID of the CSS source. It will be created if `from` option
|
|
83
|
+
* is not provided (because PostCSS does not know the file path).
|
|
84
|
+
*
|
|
85
|
+
* ```js
|
|
86
|
+
* const root = postcss.parse(css)
|
|
87
|
+
* root.source.input.file //=> undefined
|
|
88
|
+
* root.source.input.id //=> "<input css 8LZeVF>"
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
id?: string
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The input source map passed from a compilation step before PostCSS
|
|
95
|
+
* (for example, from Sass compiler).
|
|
96
|
+
*
|
|
97
|
+
* ```js
|
|
98
|
+
* root.source.input.map.consumer().sources //=> ['a.sass']
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
map: PreviousMap
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @param css Input CSS source.
|
|
105
|
+
* @param opts Process options.
|
|
106
|
+
*/
|
|
107
|
+
constructor(css: string, opts?: ProcessOptions)
|
|
108
|
+
|
|
109
|
+
error(
|
|
110
|
+
message: string,
|
|
111
|
+
start:
|
|
112
|
+
| {
|
|
113
|
+
column: number
|
|
114
|
+
line: number
|
|
115
|
+
}
|
|
116
|
+
| {
|
|
117
|
+
offset: number
|
|
118
|
+
},
|
|
119
|
+
end:
|
|
120
|
+
| {
|
|
121
|
+
column: number
|
|
122
|
+
line: number
|
|
123
|
+
}
|
|
124
|
+
| {
|
|
125
|
+
offset: number
|
|
126
|
+
},
|
|
127
|
+
opts?: { plugin?: CssSyntaxError['plugin'] }
|
|
128
|
+
): CssSyntaxError
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Returns `CssSyntaxError` with information about the error and its position.
|
|
132
|
+
*/
|
|
133
|
+
error(
|
|
134
|
+
message: string,
|
|
135
|
+
line: number,
|
|
136
|
+
column: number,
|
|
137
|
+
opts?: { plugin?: CssSyntaxError['plugin'] }
|
|
138
|
+
): CssSyntaxError
|
|
139
|
+
|
|
140
|
+
error(
|
|
141
|
+
message: string,
|
|
142
|
+
offset: number,
|
|
143
|
+
opts?: { plugin?: CssSyntaxError['plugin'] }
|
|
144
|
+
): CssSyntaxError
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Converts source offset to line and column.
|
|
148
|
+
*
|
|
149
|
+
* @param offset Source offset.
|
|
150
|
+
*/
|
|
151
|
+
fromOffset(offset: number): { col: number; line: number } | null
|
|
152
|
+
/**
|
|
153
|
+
* Reads the input source map and returns a symbol position
|
|
154
|
+
* in the input source (e.g., in a Sass file that was compiled
|
|
155
|
+
* to CSS before being passed to PostCSS). Optionally takes an
|
|
156
|
+
* end position, exclusive.
|
|
157
|
+
*
|
|
158
|
+
* ```js
|
|
159
|
+
* root.source.input.origin(1, 1) //=> { file: 'a.css', line: 3, column: 1 }
|
|
160
|
+
* root.source.input.origin(1, 1, 1, 4)
|
|
161
|
+
* //=> { file: 'a.css', line: 3, column: 1, endLine: 3, endColumn: 4 }
|
|
162
|
+
* ```
|
|
163
|
+
*
|
|
164
|
+
* @param line Line for inclusive start position in input CSS.
|
|
165
|
+
* @param column Column for inclusive start position in input CSS.
|
|
166
|
+
* @param endLine Line for exclusive end position in input CSS.
|
|
167
|
+
* @param endColumn Column for exclusive end position in input CSS.
|
|
168
|
+
*
|
|
169
|
+
* @return Position in input source.
|
|
170
|
+
*/
|
|
171
|
+
origin(
|
|
172
|
+
line: number,
|
|
173
|
+
column: number,
|
|
174
|
+
endLine?: number,
|
|
175
|
+
endColumn?: number
|
|
176
|
+
): false | Input.FilePosition
|
|
177
|
+
/**
|
|
178
|
+
* The CSS source identifier. Contains `Input#file` if the user
|
|
179
|
+
* set the `from` option, or `Input#id` if they did not.
|
|
180
|
+
*
|
|
181
|
+
* ```js
|
|
182
|
+
* const root = postcss.parse(css, { from: 'a.css' })
|
|
183
|
+
* root.source.input.from //=> "/home/ai/a.css"
|
|
184
|
+
*
|
|
185
|
+
* const root = postcss.parse(css)
|
|
186
|
+
* root.source.input.from //=> "<input css 1>"
|
|
187
|
+
* ```
|
|
188
|
+
*/
|
|
189
|
+
get from(): string
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
declare class Input extends Input_ {}
|
|
193
|
+
|
|
194
|
+
export = Input
|