@xpert-ai/plugin-motion 0.2.0 → 0.3.0

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 (157) hide show
  1. package/.xpertai-plugin/plugin.json +16 -6
  2. package/README.md +19 -5
  3. package/assets/upstream/UPSTREAM-BASELINE.md +27 -0
  4. package/assets/upstream/app/data/reicon-LICENSE.txt +21 -0
  5. package/dist/assets/upstream/UPSTREAM-BASELINE.md +27 -0
  6. package/dist/assets/upstream/app/data/reicon-LICENSE.txt +21 -0
  7. package/dist/index.d.ts +2 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +18 -9
  10. package/dist/index.js.map +1 -1
  11. package/dist/lib/constants.d.ts +7 -1
  12. package/dist/lib/constants.d.ts.map +1 -1
  13. package/dist/lib/constants.js +7 -0
  14. package/dist/lib/constants.js.map +1 -1
  15. package/dist/lib/entities/motion-export.entity.d.ts +13 -1
  16. package/dist/lib/entities/motion-export.entity.d.ts.map +1 -1
  17. package/dist/lib/entities/motion-export.entity.js +49 -1
  18. package/dist/lib/entities/motion-export.entity.js.map +1 -1
  19. package/dist/lib/entities/motion-project-version.entity.d.ts +3 -1
  20. package/dist/lib/entities/motion-project-version.entity.d.ts.map +1 -1
  21. package/dist/lib/entities/motion-project-version.entity.js +8 -0
  22. package/dist/lib/entities/motion-project-version.entity.js.map +1 -1
  23. package/dist/lib/entities/motion-project.entity.d.ts +4 -1
  24. package/dist/lib/entities/motion-project.entity.d.ts.map +1 -1
  25. package/dist/lib/entities/motion-project.entity.js +8 -0
  26. package/dist/lib/entities/motion-project.entity.js.map +1 -1
  27. package/dist/lib/hyperframes-composition.d.ts +16 -0
  28. package/dist/lib/hyperframes-composition.d.ts.map +1 -0
  29. package/dist/lib/hyperframes-composition.js +106 -0
  30. package/dist/lib/hyperframes-composition.js.map +1 -0
  31. package/dist/lib/motion-agent-response.d.ts +8 -0
  32. package/dist/lib/motion-agent-response.d.ts.map +1 -1
  33. package/dist/lib/motion-agent-response.js +13 -0
  34. package/dist/lib/motion-agent-response.js.map +1 -1
  35. package/dist/lib/motion-render.processor.d.ts +9 -0
  36. package/dist/lib/motion-render.processor.d.ts.map +1 -0
  37. package/dist/lib/motion-render.processor.js +25 -0
  38. package/dist/lib/motion-render.processor.js.map +1 -0
  39. package/dist/lib/motion-view.provider.d.ts.map +1 -1
  40. package/dist/lib/motion-view.provider.js +31 -2
  41. package/dist/lib/motion-view.provider.js.map +1 -1
  42. package/dist/lib/motion.middleware.d.ts.map +1 -1
  43. package/dist/lib/motion.middleware.js +20 -6
  44. package/dist/lib/motion.middleware.js.map +1 -1
  45. package/dist/lib/motion.plugin.d.ts.map +1 -1
  46. package/dist/lib/motion.plugin.js +2 -1
  47. package/dist/lib/motion.plugin.js.map +1 -1
  48. package/dist/lib/motion.service.d.ts +174 -3
  49. package/dist/lib/motion.service.d.ts.map +1 -1
  50. package/dist/lib/motion.service.js +376 -19
  51. package/dist/lib/motion.service.js.map +1 -1
  52. package/dist/lib/remote-components/motion-workbench/app.css +1 -1
  53. package/dist/lib/remote-components/motion-workbench/app.js +553 -38
  54. package/dist/lib/types.d.ts +26 -1
  55. package/dist/lib/types.d.ts.map +1 -1
  56. package/dist/lib/types.js.map +1 -1
  57. package/dist/sandbox-actions/hyperframes-render/action.json +10 -0
  58. package/dist/sandbox-actions/hyperframes-render/bundle/runner.mjs +188 -0
  59. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/@esbuild/darwin-arm64/README.md +3 -0
  60. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/@esbuild/darwin-arm64/bin/esbuild +0 -0
  61. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/@esbuild/darwin-arm64/package.json +20 -0
  62. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/@esbuild/linux-x64/README.md +3 -0
  63. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/@esbuild/linux-x64/bin/esbuild +0 -0
  64. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/@esbuild/linux-x64/package.json +20 -0
  65. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/@hyperframes/producer/LICENSE +190 -0
  66. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/@hyperframes/producer/README.md +156 -0
  67. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/@hyperframes/producer/dist/distributed.js +156122 -0
  68. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/@hyperframes/producer/dist/hyperframe.manifest.json +22 -0
  69. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/@hyperframes/producer/dist/hyperframe.runtime.iife.js +356 -0
  70. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/@hyperframes/producer/dist/index.js +169375 -0
  71. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/@hyperframes/producer/dist/public-server.js +167618 -0
  72. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/@hyperframes/producer/dist/services/healthWorkerThread.js +53 -0
  73. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/@hyperframes/producer/dist/services/shaderTransitionWorker.js +606 -0
  74. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/@hyperframes/producer/package.json +109 -0
  75. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/esbuild/LICENSE.md +21 -0
  76. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/esbuild/README.md +3 -0
  77. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/esbuild/bin/esbuild +0 -0
  78. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/esbuild/install.js +289 -0
  79. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/esbuild/lib/main.js +2532 -0
  80. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/esbuild/package.json +49 -0
  81. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/nanoid/LICENSE +20 -0
  82. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/nanoid/README.md +36 -0
  83. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/nanoid/async/index.browser.cjs +42 -0
  84. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/nanoid/async/index.browser.js +42 -0
  85. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/nanoid/async/index.cjs +44 -0
  86. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/nanoid/async/index.js +44 -0
  87. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/nanoid/async/index.native.js +35 -0
  88. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/nanoid/async/package.json +12 -0
  89. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/nanoid/bin/nanoid.cjs +55 -0
  90. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/nanoid/index.browser.cjs +44 -0
  91. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/nanoid/index.browser.js +44 -0
  92. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/nanoid/index.cjs +57 -0
  93. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/nanoid/index.d.cts +91 -0
  94. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/nanoid/index.js +62 -0
  95. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/nanoid/nanoid.js +1 -0
  96. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/nanoid/non-secure/index.cjs +24 -0
  97. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/nanoid/non-secure/index.js +24 -0
  98. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/nanoid/non-secure/package.json +6 -0
  99. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/nanoid/package.json +89 -0
  100. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/nanoid/url-alphabet/index.cjs +4 -0
  101. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/nanoid/url-alphabet/index.js +4 -0
  102. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/nanoid/url-alphabet/package.json +6 -0
  103. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/picocolors/LICENSE +15 -0
  104. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/picocolors/README.md +21 -0
  105. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/picocolors/package.json +25 -0
  106. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/picocolors/picocolors.browser.js +4 -0
  107. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/picocolors/picocolors.js +75 -0
  108. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/LICENSE +20 -0
  109. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/README.md +25 -0
  110. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/lib/at-rule.js +25 -0
  111. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/lib/comment.js +13 -0
  112. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/lib/container.js +447 -0
  113. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/lib/css-syntax-error.js +133 -0
  114. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/lib/declaration.js +24 -0
  115. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/lib/document.js +33 -0
  116. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/lib/fromJSON.js +68 -0
  117. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/lib/input.js +276 -0
  118. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/lib/lazy-result.js +563 -0
  119. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/lib/list.js +58 -0
  120. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/lib/map-generator.js +376 -0
  121. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/lib/no-work-result.js +137 -0
  122. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/lib/node.js +456 -0
  123. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/lib/parse.js +42 -0
  124. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/lib/parser.js +618 -0
  125. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/lib/postcss.d.mts +66 -0
  126. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/lib/postcss.js +101 -0
  127. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/lib/postcss.mjs +30 -0
  128. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/lib/previous-map.js +161 -0
  129. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/lib/processor.js +67 -0
  130. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/lib/result.js +42 -0
  131. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/lib/root.js +61 -0
  132. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/lib/rule.js +27 -0
  133. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/lib/stringifier.js +374 -0
  134. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/lib/stringify.js +11 -0
  135. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/lib/symbols.js +5 -0
  136. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/lib/terminal-highlight.js +70 -0
  137. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/lib/tokenize.js +270 -0
  138. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/lib/warn-once.js +13 -0
  139. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/lib/warning.js +37 -0
  140. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/postcss/package.json +88 -0
  141. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/source-map-js/LICENSE +28 -0
  142. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/source-map-js/README.md +765 -0
  143. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/source-map-js/lib/array-set.js +121 -0
  144. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/source-map-js/lib/base64-vlq.js +140 -0
  145. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/source-map-js/lib/base64.js +67 -0
  146. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/source-map-js/lib/binary-search.js +111 -0
  147. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/source-map-js/lib/mapping-list.js +79 -0
  148. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/source-map-js/lib/quick-sort.js +132 -0
  149. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/source-map-js/lib/source-map-consumer.js +1188 -0
  150. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/source-map-js/lib/source-map-generator.js +444 -0
  151. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/source-map-js/lib/source-node.js +413 -0
  152. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/source-map-js/lib/util.js +594 -0
  153. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/source-map-js/package.json +71 -0
  154. package/dist/sandbox-actions/hyperframes-render/bundle/runtime-modules/source-map-js/source-map.js +8 -0
  155. package/dist/xpert-motion-assistant.yaml +240 -37
  156. package/package.json +17 -9
  157. package/skills/motion-agent-skill/SKILL.md +19 -7
@@ -0,0 +1,447 @@
1
+ 'use strict'
2
+
3
+ let Comment = require('./comment')
4
+ let Declaration = require('./declaration')
5
+ let Node = require('./node')
6
+ let { isClean, my } = require('./symbols')
7
+
8
+ let AtRule, parse, Root, Rule
9
+
10
+ function cleanSource(nodes) {
11
+ return nodes.map(i => {
12
+ if (i.nodes) i.nodes = cleanSource(i.nodes)
13
+ delete i.source
14
+ return i
15
+ })
16
+ }
17
+
18
+ function markTreeDirty(node) {
19
+ node[isClean] = false
20
+ if (node.proxyOf.nodes) {
21
+ for (let i of node.proxyOf.nodes) {
22
+ markTreeDirty(i)
23
+ }
24
+ }
25
+ }
26
+
27
+ class Container extends Node {
28
+ get first() {
29
+ if (!this.proxyOf.nodes) return undefined
30
+ return this.proxyOf.nodes[0]
31
+ }
32
+
33
+ get last() {
34
+ if (!this.proxyOf.nodes) return undefined
35
+ return this.proxyOf.nodes[this.proxyOf.nodes.length - 1]
36
+ }
37
+
38
+ append(...children) {
39
+ for (let child of children) {
40
+ let nodes = this.normalize(child, this.last)
41
+ for (let node of nodes) this.proxyOf.nodes.push(node)
42
+ }
43
+
44
+ this.markDirty()
45
+
46
+ return this
47
+ }
48
+
49
+ cleanRaws(keepBetween) {
50
+ super.cleanRaws(keepBetween)
51
+ if (this.nodes) {
52
+ for (let node of this.nodes) node.cleanRaws(keepBetween)
53
+ }
54
+ }
55
+
56
+ each(callback) {
57
+ if (!this.proxyOf.nodes) return undefined
58
+ let iterator = this.getIterator()
59
+
60
+ let index, result
61
+ while (this.indexes[iterator] < this.proxyOf.nodes.length) {
62
+ index = this.indexes[iterator]
63
+ result = callback(this.proxyOf.nodes[index], index)
64
+ if (result === false) break
65
+
66
+ this.indexes[iterator] += 1
67
+ }
68
+
69
+ delete this.indexes[iterator]
70
+ return result
71
+ }
72
+
73
+ every(condition) {
74
+ return this.nodes.every(condition)
75
+ }
76
+
77
+ getIterator() {
78
+ if (!this.lastEach) this.lastEach = 0
79
+ if (!this.indexes) this.indexes = {}
80
+
81
+ this.lastEach += 1
82
+ let iterator = this.lastEach
83
+ this.indexes[iterator] = 0
84
+
85
+ return iterator
86
+ }
87
+
88
+ getProxyProcessor() {
89
+ return {
90
+ get(node, prop) {
91
+ if (prop === 'proxyOf') {
92
+ return node
93
+ } else if (!node[prop]) {
94
+ return node[prop]
95
+ } else if (
96
+ prop === 'each' ||
97
+ (typeof prop === 'string' && prop.startsWith('walk'))
98
+ ) {
99
+ return (...args) => {
100
+ return node[prop](
101
+ ...args.map(i => {
102
+ if (typeof i === 'function') {
103
+ return (child, index) => i(child.toProxy(), index)
104
+ } else {
105
+ return i
106
+ }
107
+ })
108
+ )
109
+ }
110
+ } else if (prop === 'every' || prop === 'some') {
111
+ return cb => {
112
+ return node[prop]((child, ...other) =>
113
+ cb(child.toProxy(), ...other)
114
+ )
115
+ }
116
+ } else if (prop === 'root') {
117
+ return () => node.root().toProxy()
118
+ } else if (prop === 'nodes') {
119
+ return node.nodes.map(i => i.toProxy())
120
+ } else if (prop === 'first' || prop === 'last') {
121
+ return node[prop].toProxy()
122
+ } else {
123
+ return node[prop]
124
+ }
125
+ },
126
+
127
+ set(node, prop, value) {
128
+ if (node[prop] === value) return true
129
+ node[prop] = value
130
+ if (prop === 'name' || prop === 'params' || prop === 'selector') {
131
+ node.markDirty()
132
+ }
133
+ return true
134
+ }
135
+ }
136
+ }
137
+
138
+ index(child) {
139
+ if (typeof child === 'number') return child
140
+ if (child.proxyOf) child = child.proxyOf
141
+ return this.proxyOf.nodes.indexOf(child)
142
+ }
143
+
144
+ insertAfter(exist, add) {
145
+ let existIndex = this.index(exist)
146
+ let nodes = this.normalize(add, this.proxyOf.nodes[existIndex]).reverse()
147
+ existIndex = this.index(exist)
148
+ for (let node of nodes) this.proxyOf.nodes.splice(existIndex + 1, 0, node)
149
+
150
+ let index
151
+ for (let id in this.indexes) {
152
+ index = this.indexes[id]
153
+ if (existIndex < index) {
154
+ this.indexes[id] = index + nodes.length
155
+ }
156
+ }
157
+
158
+ this.markDirty()
159
+
160
+ return this
161
+ }
162
+
163
+ insertBefore(exist, add) {
164
+ let existIndex = this.index(exist)
165
+ let type = existIndex === 0 ? 'prepend' : false
166
+ let nodes = this.normalize(
167
+ add,
168
+ this.proxyOf.nodes[existIndex],
169
+ type
170
+ ).reverse()
171
+ existIndex = this.index(exist)
172
+ for (let node of nodes) this.proxyOf.nodes.splice(existIndex, 0, node)
173
+
174
+ let index
175
+ for (let id in this.indexes) {
176
+ index = this.indexes[id]
177
+ if (existIndex <= index) {
178
+ this.indexes[id] = index + nodes.length
179
+ }
180
+ }
181
+
182
+ this.markDirty()
183
+
184
+ return this
185
+ }
186
+
187
+ normalize(nodes, sample) {
188
+ if (typeof nodes === 'string') {
189
+ nodes = cleanSource(parse(nodes).nodes)
190
+ } else if (typeof nodes === 'undefined') {
191
+ nodes = []
192
+ } else if (Array.isArray(nodes)) {
193
+ nodes = nodes.slice(0)
194
+ for (let i of nodes) {
195
+ if (i.parent) i.parent.removeChild(i, 'ignore')
196
+ }
197
+ } else if (nodes.type === 'root' && this.type !== 'document') {
198
+ nodes = nodes.nodes.slice(0)
199
+ for (let i of nodes) {
200
+ if (i.parent) i.parent.removeChild(i, 'ignore')
201
+ }
202
+ } else if (nodes.type) {
203
+ nodes = [nodes]
204
+ } else if (nodes.prop) {
205
+ if (typeof nodes.value === 'undefined') {
206
+ throw new Error('Value field is missed in node creation')
207
+ } else if (typeof nodes.value !== 'string') {
208
+ nodes.value = String(nodes.value)
209
+ }
210
+ nodes = [new Declaration(nodes)]
211
+ } else if (nodes.selector || nodes.selectors) {
212
+ nodes = [new Rule(nodes)]
213
+ } else if (nodes.name) {
214
+ nodes = [new AtRule(nodes)]
215
+ } else if (nodes.text) {
216
+ nodes = [new Comment(nodes)]
217
+ } else {
218
+ throw new Error('Unknown node type in node creation')
219
+ }
220
+
221
+ let processed = nodes.map(i => {
222
+ /* c8 ignore next */
223
+ if (!i[my]) Container.rebuild(i)
224
+ i = i.proxyOf
225
+ if (i.parent) i.parent.removeChild(i)
226
+ if (i[isClean]) markTreeDirty(i)
227
+
228
+ if (!i.raws) i.raws = {}
229
+ if (typeof i.raws.before === 'undefined') {
230
+ if (sample && typeof sample.raws.before !== 'undefined') {
231
+ i.raws.before = sample.raws.before.replace(/\S/g, '')
232
+ }
233
+ }
234
+ i.parent = this.proxyOf
235
+ return i
236
+ })
237
+
238
+ return processed
239
+ }
240
+
241
+ prepend(...children) {
242
+ children = children.reverse()
243
+ for (let child of children) {
244
+ let nodes = this.normalize(child, this.first, 'prepend').reverse()
245
+ for (let node of nodes) this.proxyOf.nodes.unshift(node)
246
+ for (let id in this.indexes) {
247
+ this.indexes[id] = this.indexes[id] + nodes.length
248
+ }
249
+ }
250
+
251
+ this.markDirty()
252
+
253
+ return this
254
+ }
255
+
256
+ push(child) {
257
+ child.parent = this
258
+ this.proxyOf.nodes.push(child)
259
+ return this
260
+ }
261
+
262
+ removeAll() {
263
+ for (let node of this.proxyOf.nodes) node.parent = undefined
264
+ this.proxyOf.nodes = []
265
+
266
+ this.markDirty()
267
+
268
+ return this
269
+ }
270
+
271
+ removeChild(child) {
272
+ child = this.index(child)
273
+ this.proxyOf.nodes[child].parent = undefined
274
+ this.proxyOf.nodes.splice(child, 1)
275
+
276
+ let index
277
+ for (let id in this.indexes) {
278
+ index = this.indexes[id]
279
+ if (index >= child) {
280
+ this.indexes[id] = index - 1
281
+ }
282
+ }
283
+
284
+ this.markDirty()
285
+
286
+ return this
287
+ }
288
+
289
+ replaceValues(pattern, opts, callback) {
290
+ if (!callback) {
291
+ callback = opts
292
+ opts = {}
293
+ }
294
+
295
+ this.walkDecls(decl => {
296
+ if (opts.props && !opts.props.includes(decl.prop)) return
297
+ if (opts.fast && !decl.value.includes(opts.fast)) return
298
+
299
+ decl.value = decl.value.replace(pattern, callback)
300
+ })
301
+
302
+ this.markDirty()
303
+
304
+ return this
305
+ }
306
+
307
+ some(condition) {
308
+ return this.nodes.some(condition)
309
+ }
310
+
311
+ walk(callback) {
312
+ return this.each((child, i) => {
313
+ let result
314
+ try {
315
+ result = callback(child, i)
316
+ } catch (e) {
317
+ throw child.addToError(e)
318
+ }
319
+ if (result !== false && child.walk) {
320
+ result = child.walk(callback)
321
+ }
322
+
323
+ return result
324
+ })
325
+ }
326
+
327
+ walkAtRules(name, callback) {
328
+ if (!callback) {
329
+ callback = name
330
+ return this.walk((child, i) => {
331
+ if (child.type === 'atrule') {
332
+ return callback(child, i)
333
+ }
334
+ })
335
+ }
336
+ if (name instanceof RegExp) {
337
+ return this.walk((child, i) => {
338
+ if (child.type === 'atrule' && name.test(child.name)) {
339
+ return callback(child, i)
340
+ }
341
+ })
342
+ }
343
+ return this.walk((child, i) => {
344
+ if (child.type === 'atrule' && child.name === name) {
345
+ return callback(child, i)
346
+ }
347
+ })
348
+ }
349
+
350
+ walkComments(callback) {
351
+ return this.walk((child, i) => {
352
+ if (child.type === 'comment') {
353
+ return callback(child, i)
354
+ }
355
+ })
356
+ }
357
+
358
+ walkDecls(prop, callback) {
359
+ if (!callback) {
360
+ callback = prop
361
+ return this.walk((child, i) => {
362
+ if (child.type === 'decl') {
363
+ return callback(child, i)
364
+ }
365
+ })
366
+ }
367
+ if (prop instanceof RegExp) {
368
+ return this.walk((child, i) => {
369
+ if (child.type === 'decl' && prop.test(child.prop)) {
370
+ return callback(child, i)
371
+ }
372
+ })
373
+ }
374
+ return this.walk((child, i) => {
375
+ if (child.type === 'decl' && child.prop === prop) {
376
+ return callback(child, i)
377
+ }
378
+ })
379
+ }
380
+
381
+ walkRules(selector, callback) {
382
+ if (!callback) {
383
+ callback = selector
384
+
385
+ return this.walk((child, i) => {
386
+ if (child.type === 'rule') {
387
+ return callback(child, i)
388
+ }
389
+ })
390
+ }
391
+ if (selector instanceof RegExp) {
392
+ return this.walk((child, i) => {
393
+ if (child.type === 'rule' && selector.test(child.selector)) {
394
+ return callback(child, i)
395
+ }
396
+ })
397
+ }
398
+ return this.walk((child, i) => {
399
+ if (child.type === 'rule' && child.selector === selector) {
400
+ return callback(child, i)
401
+ }
402
+ })
403
+ }
404
+ }
405
+
406
+ Container.registerParse = dependant => {
407
+ parse = dependant
408
+ }
409
+
410
+ Container.registerRule = dependant => {
411
+ Rule = dependant
412
+ }
413
+
414
+ Container.registerAtRule = dependant => {
415
+ AtRule = dependant
416
+ }
417
+
418
+ Container.registerRoot = dependant => {
419
+ Root = dependant
420
+ }
421
+
422
+ module.exports = Container
423
+ Container.default = Container
424
+
425
+ /* c8 ignore start */
426
+ Container.rebuild = node => {
427
+ if (node.type === 'atrule') {
428
+ Object.setPrototypeOf(node, AtRule.prototype)
429
+ } else if (node.type === 'rule') {
430
+ Object.setPrototypeOf(node, Rule.prototype)
431
+ } else if (node.type === 'decl') {
432
+ Object.setPrototypeOf(node, Declaration.prototype)
433
+ } else if (node.type === 'comment') {
434
+ Object.setPrototypeOf(node, Comment.prototype)
435
+ } else if (node.type === 'root') {
436
+ Object.setPrototypeOf(node, Root.prototype)
437
+ }
438
+
439
+ node[my] = true
440
+
441
+ if (node.nodes) {
442
+ node.nodes.forEach(child => {
443
+ Container.rebuild(child)
444
+ })
445
+ }
446
+ }
447
+ /* c8 ignore stop */
@@ -0,0 +1,133 @@
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
+
56
+ let aside = text => text
57
+ let mark = text => text
58
+ let highlight = text => text
59
+ if (color) {
60
+ let { bold, gray, red } = pico.createColors(true)
61
+ mark = text => bold(red(text))
62
+ aside = text => gray(text)
63
+ if (terminalHighlight) {
64
+ highlight = text => terminalHighlight(text)
65
+ }
66
+ }
67
+
68
+ let lines = css.split(/\r?\n/)
69
+ let start = Math.max(this.line - 3, 0)
70
+ let end = Math.min(this.line + 2, lines.length)
71
+ let maxWidth = String(end).length
72
+
73
+ return lines
74
+ .slice(start, end)
75
+ .map((line, index) => {
76
+ let number = start + 1 + index
77
+ let gutter = ' ' + (' ' + number).slice(-maxWidth) + ' | '
78
+ if (number === this.line) {
79
+ if (line.length > 160) {
80
+ let padding = 20
81
+ let subLineStart = Math.max(0, this.column - padding)
82
+ let subLineEnd = Math.max(
83
+ this.column + padding,
84
+ this.endColumn + padding
85
+ )
86
+ let subLine = line.slice(subLineStart, subLineEnd)
87
+
88
+ let spacing =
89
+ aside(gutter.replace(/\d/g, ' ')) +
90
+ line
91
+ .slice(0, Math.min(this.column - 1, padding - 1))
92
+ .replace(/[^\t]/g, ' ')
93
+
94
+ return (
95
+ mark('>') +
96
+ aside(gutter) +
97
+ highlight(subLine) +
98
+ '\n ' +
99
+ spacing +
100
+ mark('^')
101
+ )
102
+ }
103
+
104
+ let spacing =
105
+ aside(gutter.replace(/\d/g, ' ')) +
106
+ line.slice(0, this.column - 1).replace(/[^\t]/g, ' ')
107
+
108
+ return (
109
+ mark('>') +
110
+ aside(gutter) +
111
+ highlight(line) +
112
+ '\n ' +
113
+ spacing +
114
+ mark('^')
115
+ )
116
+ }
117
+
118
+ return ' ' + aside(gutter) + highlight(line)
119
+ })
120
+ .join('\n')
121
+ }
122
+
123
+ toString() {
124
+ let code = this.showSourceCode()
125
+ if (code) {
126
+ code = '\n\n' + code + '\n'
127
+ }
128
+ return this.name + ': ' + this.message + code
129
+ }
130
+ }
131
+
132
+ module.exports = CssSyntaxError
133
+ CssSyntaxError.default = CssSyntaxError
@@ -0,0 +1,24 @@
1
+ 'use strict'
2
+
3
+ let Node = require('./node')
4
+
5
+ class Declaration extends Node {
6
+ get variable() {
7
+ return this.prop.startsWith('--') || this.prop[0] === '$'
8
+ }
9
+
10
+ constructor(defaults) {
11
+ if (
12
+ defaults &&
13
+ typeof defaults.value !== 'undefined' &&
14
+ typeof defaults.value !== 'string'
15
+ ) {
16
+ defaults = { ...defaults, value: String(defaults.value) }
17
+ }
18
+ super(defaults)
19
+ this.type = 'decl'
20
+ }
21
+ }
22
+
23
+ module.exports = Declaration
24
+ Declaration.default = Declaration
@@ -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,68 @@
1
+ 'use strict'
2
+
3
+ let AtRule = require('./at-rule')
4
+ let Comment = require('./comment')
5
+ let Declaration = require('./declaration')
6
+ let Input = require('./input')
7
+ let PreviousMap = require('./previous-map')
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
+ // Rehydrate children separately and attach them after construction.
29
+ // Passing them through the container constructor would re-run insertion
30
+ // spacing normalization and overwrite each child's own `raws.before`.
31
+ let nodes
32
+ if (defaults.nodes) {
33
+ nodes = json.nodes.map(n => fromJSON(n, inputs))
34
+ delete defaults.nodes
35
+ }
36
+ if (defaults.source) {
37
+ let { inputId, ...source } = defaults.source
38
+ defaults.source = source
39
+ if (inputId != null) {
40
+ defaults.source.input = inputs[inputId]
41
+ }
42
+ }
43
+
44
+ let node
45
+ if (defaults.type === 'root') {
46
+ node = new Root(defaults)
47
+ } else if (defaults.type === 'decl') {
48
+ node = new Declaration(defaults)
49
+ } else if (defaults.type === 'rule') {
50
+ node = new Rule(defaults)
51
+ } else if (defaults.type === 'comment') {
52
+ node = new Comment(defaults)
53
+ } else if (defaults.type === 'atrule') {
54
+ node = new AtRule(defaults)
55
+ } else {
56
+ throw new Error('Unknown node type: ' + json.type)
57
+ }
58
+
59
+ if (nodes) {
60
+ node.nodes = nodes
61
+ for (let child of nodes) child.parent = node
62
+ }
63
+
64
+ return node
65
+ }
66
+
67
+ module.exports = fromJSON
68
+ fromJSON.default = fromJSON