@omnitron-dev/lumen 0.4.12 → 0.4.14

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 (188) hide show
  1. package/README.md +6 -0
  2. package/dist/config/define.d.ts.map +1 -1
  3. package/dist/config/define.js +1 -0
  4. package/dist/config/define.js.map +1 -1
  5. package/dist/config/schema.d.ts +2 -0
  6. package/dist/config/schema.d.ts.map +1 -1
  7. package/dist/config/schema.js +1 -0
  8. package/dist/config/schema.js.map +1 -1
  9. package/dist/corpus/routes.d.ts +1 -0
  10. package/dist/corpus/routes.d.ts.map +1 -1
  11. package/dist/corpus/routes.js +3 -0
  12. package/dist/corpus/routes.js.map +1 -1
  13. package/dist/search/index-builder.d.ts.map +1 -1
  14. package/dist/search/index-builder.js +8 -6
  15. package/dist/search/index-builder.js.map +1 -1
  16. package/dist/ssg/default-client.js +6 -2
  17. package/dist/ssg/default-client.js.map +1 -1
  18. package/dist/ssg/ssg-engine.d.ts.map +1 -1
  19. package/dist/ssg/ssg-engine.js +32 -16
  20. package/dist/ssg/ssg-engine.js.map +1 -1
  21. package/node_modules/fdir/LICENSE +7 -0
  22. package/node_modules/fdir/README.md +91 -0
  23. package/node_modules/fdir/dist/index.cjs +588 -0
  24. package/node_modules/fdir/dist/index.d.cts +155 -0
  25. package/node_modules/fdir/dist/index.d.mts +155 -0
  26. package/node_modules/fdir/dist/index.mjs +570 -0
  27. package/node_modules/fdir/package.json +103 -0
  28. package/node_modules/nanoid/LICENSE +20 -0
  29. package/node_modules/nanoid/README.md +39 -0
  30. package/node_modules/nanoid/async/index.browser.cjs +43 -0
  31. package/node_modules/nanoid/async/index.browser.js +43 -0
  32. package/node_modules/nanoid/async/index.cjs +47 -0
  33. package/node_modules/nanoid/async/index.d.cts +56 -0
  34. package/node_modules/nanoid/async/index.d.ts +56 -0
  35. package/node_modules/nanoid/async/index.js +47 -0
  36. package/node_modules/nanoid/async/index.native.js +38 -0
  37. package/node_modules/nanoid/async/package.json +12 -0
  38. package/node_modules/nanoid/bin/nanoid.cjs +55 -0
  39. package/node_modules/nanoid/index.browser.cjs +45 -0
  40. package/node_modules/nanoid/index.browser.js +45 -0
  41. package/node_modules/nanoid/index.cjs +63 -0
  42. package/node_modules/nanoid/index.d.cts +91 -0
  43. package/node_modules/nanoid/index.d.ts +91 -0
  44. package/node_modules/nanoid/index.js +63 -0
  45. package/node_modules/nanoid/nanoid.js +1 -0
  46. package/node_modules/nanoid/non-secure/index.cjs +24 -0
  47. package/node_modules/nanoid/non-secure/index.d.ts +33 -0
  48. package/node_modules/nanoid/non-secure/index.js +24 -0
  49. package/node_modules/nanoid/non-secure/package.json +6 -0
  50. package/node_modules/nanoid/package.json +89 -0
  51. package/node_modules/nanoid/url-alphabet/index.cjs +4 -0
  52. package/node_modules/nanoid/url-alphabet/index.js +4 -0
  53. package/node_modules/nanoid/url-alphabet/package.json +6 -0
  54. package/node_modules/picocolors/LICENSE +15 -0
  55. package/node_modules/picocolors/README.md +21 -0
  56. package/node_modules/picocolors/package.json +25 -0
  57. package/node_modules/picocolors/picocolors.browser.js +4 -0
  58. package/node_modules/picocolors/picocolors.d.ts +5 -0
  59. package/node_modules/picocolors/picocolors.js +75 -0
  60. package/node_modules/picocolors/types.d.ts +51 -0
  61. package/node_modules/picomatch/LICENSE +21 -0
  62. package/node_modules/picomatch/README.md +743 -0
  63. package/node_modules/picomatch/index.js +17 -0
  64. package/node_modules/picomatch/lib/constants.js +184 -0
  65. package/node_modules/picomatch/lib/parse.js +1439 -0
  66. package/node_modules/picomatch/lib/picomatch.js +361 -0
  67. package/node_modules/picomatch/lib/scan.js +403 -0
  68. package/node_modules/picomatch/lib/utils.js +72 -0
  69. package/node_modules/picomatch/package.json +83 -0
  70. package/node_modules/picomatch/posix.js +3 -0
  71. package/node_modules/postcss/LICENSE +20 -0
  72. package/node_modules/postcss/README.md +27 -0
  73. package/node_modules/postcss/lib/at-rule.d.ts +139 -0
  74. package/node_modules/postcss/lib/at-rule.js +25 -0
  75. package/node_modules/postcss/lib/comment.d.ts +67 -0
  76. package/node_modules/postcss/lib/comment.js +13 -0
  77. package/node_modules/postcss/lib/container.d.ts +474 -0
  78. package/node_modules/postcss/lib/container.js +494 -0
  79. package/node_modules/postcss/lib/css-syntax-error.d.ts +247 -0
  80. package/node_modules/postcss/lib/css-syntax-error.js +133 -0
  81. package/node_modules/postcss/lib/declaration.d.ts +150 -0
  82. package/node_modules/postcss/lib/declaration.js +24 -0
  83. package/node_modules/postcss/lib/document.d.ts +68 -0
  84. package/node_modules/postcss/lib/document.js +33 -0
  85. package/node_modules/postcss/lib/fromJSON.d.ts +9 -0
  86. package/node_modules/postcss/lib/fromJSON.js +107 -0
  87. package/node_modules/postcss/lib/input.d.ts +226 -0
  88. package/node_modules/postcss/lib/input.js +282 -0
  89. package/node_modules/postcss/lib/lazy-result.d.ts +189 -0
  90. package/node_modules/postcss/lib/lazy-result.js +626 -0
  91. package/node_modules/postcss/lib/list.d.ts +60 -0
  92. package/node_modules/postcss/lib/list.js +79 -0
  93. package/node_modules/postcss/lib/map-generator.js +383 -0
  94. package/node_modules/postcss/lib/no-work-result.d.ts +45 -0
  95. package/node_modules/postcss/lib/no-work-result.js +137 -0
  96. package/node_modules/postcss/lib/node.d.ts +555 -0
  97. package/node_modules/postcss/lib/node.js +494 -0
  98. package/node_modules/postcss/lib/parse.d.ts +9 -0
  99. package/node_modules/postcss/lib/parse.js +42 -0
  100. package/node_modules/postcss/lib/parser.js +626 -0
  101. package/node_modules/postcss/lib/postcss.d.mts +66 -0
  102. package/node_modules/postcss/lib/postcss.d.ts +464 -0
  103. package/node_modules/postcss/lib/postcss.js +101 -0
  104. package/node_modules/postcss/lib/postcss.mjs +30 -0
  105. package/node_modules/postcss/lib/previous-map.d.ts +80 -0
  106. package/node_modules/postcss/lib/previous-map.js +176 -0
  107. package/node_modules/postcss/lib/processor.d.ts +114 -0
  108. package/node_modules/postcss/lib/processor.js +67 -0
  109. package/node_modules/postcss/lib/result.d.ts +204 -0
  110. package/node_modules/postcss/lib/result.js +42 -0
  111. package/node_modules/postcss/lib/root.d.ts +86 -0
  112. package/node_modules/postcss/lib/root.js +76 -0
  113. package/node_modules/postcss/lib/rule.d.ts +126 -0
  114. package/node_modules/postcss/lib/rule.js +27 -0
  115. package/node_modules/postcss/lib/stringifier.d.ts +45 -0
  116. package/node_modules/postcss/lib/stringifier.js +457 -0
  117. package/node_modules/postcss/lib/stringify.d.ts +9 -0
  118. package/node_modules/postcss/lib/stringify.js +93 -0
  119. package/node_modules/postcss/lib/symbols.js +5 -0
  120. package/node_modules/postcss/lib/terminal-highlight.js +70 -0
  121. package/node_modules/postcss/lib/tokenize.js +270 -0
  122. package/node_modules/postcss/lib/warn-once.js +13 -0
  123. package/node_modules/postcss/lib/warning.d.ts +146 -0
  124. package/node_modules/postcss/lib/warning.js +48 -0
  125. package/node_modules/postcss/package.json +88 -0
  126. package/node_modules/source-map-js/LICENSE +28 -0
  127. package/node_modules/source-map-js/README.md +765 -0
  128. package/node_modules/source-map-js/lib/array-set.js +121 -0
  129. package/node_modules/source-map-js/lib/base64-vlq.js +140 -0
  130. package/node_modules/source-map-js/lib/base64.js +67 -0
  131. package/node_modules/source-map-js/lib/binary-search.js +111 -0
  132. package/node_modules/source-map-js/lib/mapping-list.js +79 -0
  133. package/node_modules/source-map-js/lib/quick-sort.js +141 -0
  134. package/node_modules/source-map-js/lib/source-map-consumer.d.ts +1 -0
  135. package/node_modules/source-map-js/lib/source-map-consumer.js +1236 -0
  136. package/node_modules/source-map-js/lib/source-map-generator.d.ts +1 -0
  137. package/node_modules/source-map-js/lib/source-map-generator.js +446 -0
  138. package/node_modules/source-map-js/lib/source-node.d.ts +1 -0
  139. package/node_modules/source-map-js/lib/source-node.js +420 -0
  140. package/node_modules/source-map-js/lib/util.js +594 -0
  141. package/node_modules/source-map-js/package.json +71 -0
  142. package/node_modules/source-map-js/source-map.d.ts +104 -0
  143. package/node_modules/source-map-js/source-map.js +8 -0
  144. package/{LICENSE → node_modules/tinyglobby/LICENSE} +1 -1
  145. package/node_modules/tinyglobby/README.md +25 -0
  146. package/node_modules/tinyglobby/dist/index.cjs +335 -0
  147. package/node_modules/tinyglobby/dist/index.d.cts +148 -0
  148. package/node_modules/tinyglobby/dist/index.d.mts +148 -0
  149. package/node_modules/tinyglobby/dist/index.mjs +307 -0
  150. package/node_modules/tinyglobby/package.json +70 -0
  151. package/node_modules/vite/LICENSE.md +2084 -0
  152. package/node_modules/vite/README.md +20 -0
  153. package/node_modules/vite/bin/openChrome.js +68 -0
  154. package/node_modules/vite/bin/vite.js +90 -0
  155. package/node_modules/vite/client.d.ts +285 -0
  156. package/node_modules/vite/dist/client/bundledDevClient.mjs +1642 -0
  157. package/node_modules/vite/dist/client/client.mjs +1331 -0
  158. package/node_modules/vite/dist/client/env.mjs +18 -0
  159. package/node_modules/vite/dist/node/chunks/build.js +5833 -0
  160. package/node_modules/vite/dist/node/chunks/dist.js +7029 -0
  161. package/node_modules/vite/dist/node/chunks/lib.js +371 -0
  162. package/node_modules/vite/dist/node/chunks/moduleRunnerTransport.d.ts +95 -0
  163. package/node_modules/vite/dist/node/chunks/node.js +38364 -0
  164. package/node_modules/vite/dist/node/chunks/postcss-import.js +465 -0
  165. package/node_modules/vite/dist/node/cli.js +849 -0
  166. package/node_modules/vite/dist/node/index.d.ts +4064 -0
  167. package/node_modules/vite/dist/node/index.js +1 -0
  168. package/node_modules/vite/dist/node/internal.d.ts +2 -0
  169. package/node_modules/vite/dist/node/internal.js +1 -0
  170. package/node_modules/vite/dist/node/module-runner.d.ts +314 -0
  171. package/node_modules/vite/dist/node/module-runner.js +1296 -0
  172. package/node_modules/vite/misc/false.js +1 -0
  173. package/node_modules/vite/misc/true.js +1 -0
  174. package/node_modules/vite/package.json +195 -0
  175. package/node_modules/vite/types/customEvent.d.ts +83 -0
  176. package/node_modules/vite/types/hmrPayload.d.ts +96 -0
  177. package/node_modules/vite/types/hot.d.ts +39 -0
  178. package/node_modules/vite/types/import-meta.d.ts +5 -0
  179. package/node_modules/vite/types/importGlob.d.ts +131 -0
  180. package/node_modules/vite/types/importMeta.d.ts +30 -0
  181. package/node_modules/vite/types/internal/cssPreprocessorOptions.d.ts +44 -0
  182. package/node_modules/vite/types/internal/devtoolsOptions.d.ts +9 -0
  183. package/node_modules/vite/types/internal/esbuildOptions.d.ts +28 -0
  184. package/node_modules/vite/types/internal/lightningcssOptions.d.ts +18 -0
  185. package/node_modules/vite/types/internal/rollupTypeCompat.d.ts +24 -0
  186. package/node_modules/vite/types/internal/terserOptions.d.ts +11 -0
  187. package/node_modules/vite/types/metadata.d.ts +47 -0
  188. package/package.json +15 -7
@@ -0,0 +1,494 @@
1
+ 'use strict'
2
+
3
+ let CssSyntaxError = require('./css-syntax-error')
4
+ let Stringifier = require('./stringifier')
5
+ let stringify = require('./stringify')
6
+ let { isClean, my } = require('./symbols')
7
+
8
+ function cloneNode(obj, parent) {
9
+ let cloned = new obj.constructor()
10
+ // An explicit stack instead of recursive calls to survive deeply
11
+ // nested trees. Each entry is [source, its clone, clone's parent].
12
+ let stack = [[obj, cloned, parent]]
13
+
14
+ while (stack.length > 0) {
15
+ let [source, target, targetParent] = stack.pop()
16
+ for (let i in source) {
17
+ if (!Object.prototype.hasOwnProperty.call(source, i)) {
18
+ /* c8 ignore next 2 */
19
+ continue
20
+ }
21
+ if (i === 'proxyCache') continue
22
+ let value = source[i]
23
+ let type = typeof value
24
+
25
+ if (i === 'parent' && type === 'object') {
26
+ if (targetParent) target[i] = targetParent
27
+ } else if (i === 'source') {
28
+ target[i] = value
29
+ } else if (Array.isArray(value)) {
30
+ let children = []
31
+ target[i] = children
32
+ for (let j of value) {
33
+ let childClone = new j.constructor()
34
+ children.push(childClone)
35
+ stack.push([j, childClone, target])
36
+ }
37
+ } else {
38
+ if (type === 'object' && value !== null) {
39
+ let valueClone = new value.constructor()
40
+ stack.push([value, valueClone, undefined])
41
+ value = valueClone
42
+ }
43
+ target[i] = value
44
+ }
45
+ }
46
+ }
47
+
48
+ return cloned
49
+ }
50
+
51
+ function sourceOffset(inputCSS, position) {
52
+ // Not all custom syntaxes support `offset` in `source.start` and `source.end`
53
+ if (position && typeof position.offset !== 'undefined') {
54
+ return position.offset
55
+ }
56
+
57
+ let column = 1
58
+ let line = 1
59
+ let offset = 0
60
+
61
+ for (let i = 0; i < inputCSS.length; i++) {
62
+ if (line === position.line && column === position.column) {
63
+ offset = i
64
+ break
65
+ }
66
+
67
+ if (inputCSS[i] === '\n') {
68
+ column = 1
69
+ line += 1
70
+ } else {
71
+ column += 1
72
+ }
73
+ }
74
+
75
+ return offset
76
+ }
77
+
78
+ class Node {
79
+ get proxyOf() {
80
+ return this
81
+ }
82
+
83
+ constructor(defaults = {}) {
84
+ this.raws = {}
85
+ this[isClean] = false
86
+ this[my] = true
87
+
88
+ for (let name of Object.keys(defaults)) {
89
+ if (name === '__proto__') continue
90
+ if (name === 'nodes') {
91
+ this.nodes = []
92
+ for (let node of defaults[name]) {
93
+ // Clone only nodes that already belong to another tree, so passing a
94
+ // freshly created (parent-less) node adopts that instance instead of
95
+ // a copy and keeps the caller's reference usable. See #1987.
96
+ if (typeof node.clone === 'function' && node.parent) {
97
+ this.append(node.clone())
98
+ } else {
99
+ this.append(node)
100
+ }
101
+ }
102
+ } else {
103
+ this[name] = defaults[name]
104
+ }
105
+ }
106
+ }
107
+
108
+ addToError(error) {
109
+ error.postcssNode = this
110
+ if (error.stack && this.source && /\n\s{4}at /.test(error.stack)) {
111
+ let s = this.source
112
+ error.stack = error.stack.replace(
113
+ /\n\s{4}at /,
114
+ `$&${s.input.from}:${s.start.line}:${s.start.column}$&`
115
+ )
116
+ }
117
+ return error
118
+ }
119
+
120
+ after(add) {
121
+ this.parent.insertAfter(this, add)
122
+ return this
123
+ }
124
+
125
+ assign(overrides = {}) {
126
+ for (let name in overrides) {
127
+ this[name] = overrides[name]
128
+ }
129
+ return this
130
+ }
131
+
132
+ before(add) {
133
+ this.parent.insertBefore(this, add)
134
+ return this
135
+ }
136
+
137
+ cleanRaws(keepBetween) {
138
+ delete this.raws.before
139
+ delete this.raws.after
140
+ if (!keepBetween) delete this.raws.between
141
+ }
142
+
143
+ clone(overrides = {}) {
144
+ let cloned = cloneNode(this)
145
+ for (let name in overrides) {
146
+ cloned[name] = overrides[name]
147
+ }
148
+ return cloned
149
+ }
150
+
151
+ cloneAfter(overrides = {}) {
152
+ let cloned = this.clone(overrides)
153
+ this.parent.insertAfter(this, cloned)
154
+ return cloned
155
+ }
156
+
157
+ cloneBefore(overrides = {}) {
158
+ let cloned = this.clone(overrides)
159
+ this.parent.insertBefore(this, cloned)
160
+ return cloned
161
+ }
162
+
163
+ error(message, opts = {}) {
164
+ if (this.source) {
165
+ let { end, start } = this.rangeBy(opts)
166
+ return this.source.input.error(
167
+ message,
168
+ { column: start.column, line: start.line },
169
+ { column: end.column, line: end.line },
170
+ opts
171
+ )
172
+ }
173
+ return new CssSyntaxError(message)
174
+ }
175
+
176
+ getProxyProcessor() {
177
+ return {
178
+ get(node, prop) {
179
+ if (prop === 'proxyOf') {
180
+ return node
181
+ } else if (prop === 'root') {
182
+ return () => node.root().toProxy()
183
+ } else {
184
+ return node[prop]
185
+ }
186
+ },
187
+
188
+ set(node, prop, value) {
189
+ if (node[prop] === value) return true
190
+ node[prop] = value
191
+ if (
192
+ prop === 'prop' ||
193
+ prop === 'value' ||
194
+ prop === 'name' ||
195
+ prop === 'params' ||
196
+ prop === 'important' ||
197
+ /* c8 ignore next */
198
+ prop === 'text'
199
+ ) {
200
+ node.markDirty()
201
+ }
202
+ return true
203
+ }
204
+ }
205
+ }
206
+
207
+ /* c8 ignore next 3 */
208
+ markClean() {
209
+ this[isClean] = true
210
+ }
211
+
212
+ markDirty() {
213
+ if (this[isClean]) {
214
+ this[isClean] = false
215
+ let next = this
216
+ while ((next = next.parent)) {
217
+ next[isClean] = false
218
+ }
219
+ }
220
+ }
221
+
222
+ next() {
223
+ if (!this.parent) return undefined
224
+ let index = this.parent.index(this)
225
+ return this.parent.nodes[index + 1]
226
+ }
227
+
228
+ positionBy(opts = {}) {
229
+ let inputString =
230
+ 'document' in this.source.input
231
+ ? this.source.input.document
232
+ : this.source.input.css
233
+ let pos = {
234
+ column: this.source.start.column,
235
+ line: this.source.start.line,
236
+ offset: sourceOffset(inputString, this.source.start)
237
+ }
238
+ if (opts.index) {
239
+ pos = this.positionInside(opts.index)
240
+ } else if (opts.word) {
241
+ let stringRepresentation = inputString.slice(
242
+ sourceOffset(inputString, this.source.start),
243
+ this.rangeBy().end.offset
244
+ )
245
+ let index = stringRepresentation.indexOf(opts.word)
246
+ if (index !== -1) pos = this.positionInside(index)
247
+ }
248
+ return pos
249
+ }
250
+
251
+ positionInside(index) {
252
+ let column = this.source.start.column
253
+ let line = this.source.start.line
254
+ let inputString =
255
+ 'document' in this.source.input
256
+ ? this.source.input.document
257
+ : this.source.input.css
258
+ let offset = sourceOffset(inputString, this.source.start)
259
+ let end = offset + index
260
+
261
+ for (let i = offset; i < end; i++) {
262
+ if (inputString[i] === '\n') {
263
+ column = 1
264
+ line += 1
265
+ } else {
266
+ column += 1
267
+ }
268
+ }
269
+
270
+ return { column, line, offset: end }
271
+ }
272
+
273
+ prev() {
274
+ if (!this.parent) return undefined
275
+ let index = this.parent.index(this)
276
+ return this.parent.nodes[index - 1]
277
+ }
278
+
279
+ rangeBy(opts = {}) {
280
+ let inputString =
281
+ 'document' in this.source.input
282
+ ? this.source.input.document
283
+ : this.source.input.css
284
+ let start = {
285
+ column: this.source.start.column,
286
+ line: this.source.start.line,
287
+ offset: sourceOffset(inputString, this.source.start)
288
+ }
289
+ let end = this.source.end
290
+ ? {
291
+ column: this.source.end.column + 1,
292
+ line: this.source.end.line,
293
+ offset:
294
+ typeof this.source.end.offset === 'number'
295
+ ? // `source.end.offset` is exclusive, so we don't need to add 1
296
+ this.source.end.offset
297
+ : // Since line/column in this.source.end is inclusive,
298
+ // the `sourceOffset(... , this.source.end)` returns an inclusive offset.
299
+ // So, we add 1 to convert it to exclusive.
300
+ sourceOffset(inputString, this.source.end) + 1
301
+ }
302
+ : {
303
+ column: start.column + 1,
304
+ line: start.line,
305
+ offset: start.offset + 1
306
+ }
307
+
308
+ if (opts.word) {
309
+ let stringRepresentation = inputString.slice(
310
+ sourceOffset(inputString, this.source.start),
311
+ end.offset
312
+ )
313
+ let index = stringRepresentation.indexOf(opts.word)
314
+ if (index !== -1) {
315
+ start = this.positionInside(index)
316
+ end = this.positionInside(index + opts.word.length)
317
+ }
318
+ } else {
319
+ if (opts.start) {
320
+ start = {
321
+ column: opts.start.column,
322
+ line: opts.start.line,
323
+ offset: sourceOffset(inputString, opts.start)
324
+ }
325
+ } else if (typeof opts.index === 'number') {
326
+ start = this.positionInside(opts.index)
327
+ }
328
+
329
+ if (opts.end) {
330
+ end = {
331
+ column: opts.end.column,
332
+ line: opts.end.line,
333
+ offset: sourceOffset(inputString, opts.end)
334
+ }
335
+ } else if (typeof opts.endIndex === 'number') {
336
+ end = this.positionInside(opts.endIndex)
337
+ } else if (typeof opts.index === 'number') {
338
+ end = this.positionInside(opts.index + 1)
339
+ }
340
+ }
341
+
342
+ if (
343
+ end.line < start.line ||
344
+ (end.line === start.line && end.column <= start.column)
345
+ ) {
346
+ end = {
347
+ column: start.column + 1,
348
+ line: start.line,
349
+ offset: start.offset + 1
350
+ }
351
+ }
352
+
353
+ return { end, start }
354
+ }
355
+
356
+ raw(prop, defaultType) {
357
+ let str = new Stringifier()
358
+ return str.raw(this, prop, defaultType)
359
+ }
360
+
361
+ remove() {
362
+ if (this.parent) {
363
+ this.parent.removeChild(this)
364
+ }
365
+ this.parent = undefined
366
+ return this
367
+ }
368
+
369
+ replaceWith(...nodes) {
370
+ if (this.parent) {
371
+ let bookmark = this
372
+ let foundSelf = false
373
+ for (let node of nodes) {
374
+ if (node === this) {
375
+ foundSelf = true
376
+ } else if (foundSelf) {
377
+ this.parent.insertAfter(bookmark, node)
378
+ bookmark = node
379
+ } else {
380
+ this.parent.insertBefore(bookmark, node)
381
+ }
382
+ }
383
+
384
+ if (!foundSelf) {
385
+ this.remove()
386
+ }
387
+ }
388
+
389
+ return this
390
+ }
391
+
392
+ root() {
393
+ let result = this
394
+ while (result.parent && result.parent.type !== 'document') {
395
+ result = result.parent
396
+ }
397
+ return result
398
+ }
399
+
400
+ toJSON(_, inputs) {
401
+ let emitInputs = inputs == null
402
+ inputs = inputs || new Map()
403
+
404
+ // A worklist instead of recursive `toJSON()` calls to survive deeply
405
+ // nested trees. Each entry converts one node and writes the result
406
+ // into the already converted parent by [holder, key].
407
+ let holderOfRoot = []
408
+ let queue = [[this, holderOfRoot, 0]]
409
+
410
+ for (let step = 0; step < queue.length; step++) {
411
+ let [node, holder, key] = queue[step]
412
+ let fixed = {}
413
+ holder[key] = fixed
414
+
415
+ for (let name in node) {
416
+ if (!Object.prototype.hasOwnProperty.call(node, name)) {
417
+ /* c8 ignore next 2 */
418
+ continue
419
+ }
420
+ if (name === 'parent' || name === 'proxyCache') continue
421
+ let value = node[name]
422
+
423
+ if (Array.isArray(value)) {
424
+ let fixedArray = []
425
+ fixed[name] = fixedArray
426
+ for (let i = 0; i < value.length; i++) {
427
+ let item = value[i]
428
+ if (typeof item === 'object' && item.toJSON) {
429
+ if (item.toJSON === Node.prototype.toJSON) {
430
+ queue.push([item, fixedArray, i])
431
+ } else {
432
+ fixedArray[i] = item.toJSON(null, inputs)
433
+ }
434
+ } else {
435
+ fixedArray[i] = item
436
+ }
437
+ }
438
+ } else if (typeof value === 'object' && value.toJSON) {
439
+ if (value.toJSON === Node.prototype.toJSON) {
440
+ queue.push([value, fixed, name])
441
+ } else {
442
+ fixed[name] = value.toJSON(null, inputs)
443
+ }
444
+ } else if (name === 'source') {
445
+ if (value == null) continue
446
+ let inputId = inputs.get(value.input)
447
+ if (inputId == null) {
448
+ inputId = inputs.size
449
+ inputs.set(value.input, inputId)
450
+ }
451
+ fixed[name] = {
452
+ end: value.end,
453
+ inputId,
454
+ start: value.start
455
+ }
456
+ } else {
457
+ fixed[name] = value
458
+ }
459
+ }
460
+ }
461
+
462
+ let fixed = holderOfRoot[0]
463
+ if (emitInputs) {
464
+ fixed.inputs = [...inputs.keys()].map(input => input.toJSON())
465
+ }
466
+
467
+ return fixed
468
+ }
469
+
470
+ toProxy() {
471
+ if (!this.proxyCache) {
472
+ this.proxyCache = new Proxy(this, this.getProxyProcessor())
473
+ }
474
+ return this.proxyCache
475
+ }
476
+
477
+ toString(stringifier = stringify) {
478
+ if (stringifier.stringify) stringifier = stringifier.stringify
479
+ let result = ''
480
+ stringifier(this, i => {
481
+ result += i
482
+ })
483
+ return result
484
+ }
485
+
486
+ warn(result, text, opts = {}) {
487
+ let data = { node: this }
488
+ for (let i in opts) data[i] = opts[i]
489
+ return result.warn(text, data)
490
+ }
491
+ }
492
+
493
+ module.exports = Node
494
+ Node.default = Node
@@ -0,0 +1,9 @@
1
+ import { Parser } from './postcss.js'
2
+
3
+ interface Parse extends Parser {
4
+ default: Parse
5
+ }
6
+
7
+ declare let parse: Parse
8
+
9
+ export = parse
@@ -0,0 +1,42 @@
1
+ 'use strict'
2
+
3
+ let Container = require('./container')
4
+ let Input = require('./input')
5
+ let Parser = require('./parser')
6
+
7
+ function parse(css, opts) {
8
+ let input = new Input(css, opts)
9
+ let parser = new Parser(input)
10
+ try {
11
+ parser.parse()
12
+ } catch (e) {
13
+ if (process.env.NODE_ENV !== 'production') {
14
+ if (e.name === 'CssSyntaxError' && opts && opts.from) {
15
+ if (/\.scss$/i.test(opts.from)) {
16
+ e.message +=
17
+ '\nYou tried to parse SCSS with ' +
18
+ 'the standard CSS parser; ' +
19
+ 'try again with the postcss-scss parser'
20
+ } else if (/\.sass/i.test(opts.from)) {
21
+ e.message +=
22
+ '\nYou tried to parse Sass with ' +
23
+ 'the standard CSS parser; ' +
24
+ 'try again with the postcss-sass parser'
25
+ } else if (/\.less$/i.test(opts.from)) {
26
+ e.message +=
27
+ '\nYou tried to parse Less with ' +
28
+ 'the standard CSS parser; ' +
29
+ 'try again with the postcss-less parser'
30
+ }
31
+ }
32
+ }
33
+ throw e
34
+ }
35
+
36
+ return parser.root
37
+ }
38
+
39
+ module.exports = parse
40
+ parse.default = parse
41
+
42
+ Container.registerParse(parse)