@prospective.co/procss 0.1.8 → 0.1.9
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/package.json +1 -1
- package/src/ast/selector/selector_term.rs +53 -6
- package/target/cjs/procss.js +32 -10
- package/target/cjs/procss_bg.wasm +0 -0
- package/target/esm/procss.js +28 -10
- package/target/esm/procss_bg.wasm +0 -0
package/package.json
CHANGED
|
@@ -22,25 +22,48 @@ use crate::ast::token::*;
|
|
|
22
22
|
use crate::parser::*;
|
|
23
23
|
use crate::render::*;
|
|
24
24
|
|
|
25
|
+
/// pseudo-selectors can be "pseudo-class" or "pseudo-element", and we are only
|
|
26
|
+
/// concerned about the distinction between them in regards to their syntax.
|
|
27
|
+
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
|
28
|
+
pub enum PseudoMode {
|
|
29
|
+
PseudoClass,
|
|
30
|
+
PseudoElement,
|
|
31
|
+
}
|
|
32
|
+
|
|
25
33
|
/// A pseudo-selector component of a `Selector`, including optional argument
|
|
26
34
|
/// selector (parenthesis delimited).
|
|
27
35
|
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
|
|
28
36
|
pub struct Pseudo<'a> {
|
|
29
37
|
property: &'a str,
|
|
30
38
|
value: Option<SelectorTerm<'a, Option<&'a str>>>,
|
|
39
|
+
mode: PseudoMode,
|
|
31
40
|
}
|
|
32
41
|
|
|
33
42
|
impl<'a> ParseCss<'a> for Pseudo<'a> {
|
|
34
43
|
fn parse<E: ParseError<&'a str>>(input: &'a str) -> IResult<&'a str, Self, E> {
|
|
35
|
-
let (input,
|
|
44
|
+
let (input, mode) = tuple((tag(":"), opt(tag(":"))))(input)?;
|
|
45
|
+
let (input, property) = parse_symbol(input)?;
|
|
36
46
|
let (input, value) = opt(delimited(tag("("), SelectorTerm::parse, tag(")")))(input)?;
|
|
37
|
-
|
|
47
|
+
let mode = mode
|
|
48
|
+
.1
|
|
49
|
+
.map(|_| PseudoMode::PseudoElement)
|
|
50
|
+
.unwrap_or(PseudoMode::PseudoClass);
|
|
51
|
+
|
|
52
|
+
Ok((input, Pseudo {
|
|
53
|
+
property,
|
|
54
|
+
value,
|
|
55
|
+
mode,
|
|
56
|
+
}))
|
|
38
57
|
}
|
|
39
58
|
}
|
|
40
59
|
|
|
41
60
|
impl<'a> RenderCss for Pseudo<'a> {
|
|
42
61
|
fn render(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
43
|
-
|
|
62
|
+
match self.mode {
|
|
63
|
+
PseudoMode::PseudoClass => write!(f, ":{}", self.property)?,
|
|
64
|
+
PseudoMode::PseudoElement => write!(f, "::{}", self.property)?,
|
|
65
|
+
};
|
|
66
|
+
|
|
44
67
|
if let Some(x) = self.value.as_ref() {
|
|
45
68
|
write!(f, "(")?;
|
|
46
69
|
x.render(f)?;
|
|
@@ -283,7 +306,7 @@ mod tests {
|
|
|
283
306
|
tag: Some("div"),
|
|
284
307
|
pseudo,
|
|
285
308
|
..
|
|
286
|
-
})) if pseudo.len() == 1 && matches!(pseudo[0], Pseudo{property: "hover", value: None })
|
|
309
|
+
})) if pseudo.len() == 1 && matches!(pseudo[0], Pseudo{property: "hover", value: None, mode: PseudoMode::PseudoClass })
|
|
287
310
|
)
|
|
288
311
|
}
|
|
289
312
|
|
|
@@ -295,7 +318,7 @@ mod tests {
|
|
|
295
318
|
tag: Some("div"),
|
|
296
319
|
pseudo,
|
|
297
320
|
..
|
|
298
|
-
})) if pseudo.len() == 1 && matches!(pseudo[0], Pseudo{ property: "not", value: Some(_) })
|
|
321
|
+
})) if pseudo.len() == 1 && matches!(pseudo[0], Pseudo{ property: "not", value: Some(_), mode: PseudoMode::PseudoClass })
|
|
299
322
|
)
|
|
300
323
|
}
|
|
301
324
|
|
|
@@ -307,7 +330,7 @@ mod tests {
|
|
|
307
330
|
tag: Some("div"),
|
|
308
331
|
pseudo,
|
|
309
332
|
..
|
|
310
|
-
})) if pseudo.len() == 1 && matches!(pseudo[0], Pseudo{ property: "nth-child", value: Some(_) })
|
|
333
|
+
})) if pseudo.len() == 1 && matches!(pseudo[0], Pseudo{ property: "nth-child", value: Some(_), mode: PseudoMode::PseudoClass })
|
|
311
334
|
)
|
|
312
335
|
}
|
|
313
336
|
|
|
@@ -322,4 +345,28 @@ mod tests {
|
|
|
322
345
|
Ok("div:nth-child(2)")
|
|
323
346
|
)
|
|
324
347
|
}
|
|
348
|
+
|
|
349
|
+
#[test]
|
|
350
|
+
fn test_pesudo_element() {
|
|
351
|
+
assert_matches!(
|
|
352
|
+
SelectorTerm::parse::<()>("div::-webkit-scroll-thumb"),
|
|
353
|
+
Ok(("", SelectorTerm {
|
|
354
|
+
tag: Some("div"),
|
|
355
|
+
pseudo,
|
|
356
|
+
..
|
|
357
|
+
})) if pseudo.len() == 1 && matches!(pseudo[0], Pseudo{property: "-webkit-scroll-thumb", value: None, mode: PseudoMode::PseudoElement })
|
|
358
|
+
)
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
#[test]
|
|
362
|
+
fn test_pesudo_element_renders_correctly() {
|
|
363
|
+
assert_matches!(
|
|
364
|
+
SelectorTerm::<Option<&str>>::parse::<nom::error::VerboseError<&str>>(
|
|
365
|
+
"div::-webkit-scroll-thumb"
|
|
366
|
+
)
|
|
367
|
+
.map(|x| x.as_css_string())
|
|
368
|
+
.as_deref(),
|
|
369
|
+
Ok("div::-webkit-scroll-thumb")
|
|
370
|
+
)
|
|
371
|
+
}
|
|
325
372
|
}
|
package/target/cjs/procss.js
CHANGED
|
@@ -177,32 +177,54 @@ class BuildCss {
|
|
|
177
177
|
}
|
|
178
178
|
module.exports.BuildCss = BuildCss;
|
|
179
179
|
|
|
180
|
-
module.exports.
|
|
181
|
-
|
|
180
|
+
module.exports.__wbindgen_throw = function(arg0, arg1) {
|
|
181
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
module.exports.__wbindgen_string_new = function(arg0, arg1) {
|
|
185
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
182
186
|
return addHeapObject(ret);
|
|
183
187
|
};
|
|
184
188
|
|
|
189
|
+
module.exports.__wbindgen_is_string = function(arg0) {
|
|
190
|
+
const ret = typeof(getObject(arg0)) === 'string';
|
|
191
|
+
return ret;
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
module.exports.__wbindgen_object_drop_ref = function(arg0) {
|
|
195
|
+
takeObject(arg0);
|
|
196
|
+
};
|
|
197
|
+
|
|
185
198
|
module.exports.__wbg_new_268f7b7dd3430798 = function() {
|
|
186
199
|
const ret = new Map();
|
|
187
200
|
return addHeapObject(ret);
|
|
188
201
|
};
|
|
189
202
|
|
|
190
|
-
module.exports.
|
|
191
|
-
const ret =
|
|
203
|
+
module.exports.__wbg_set_933729cf5b66ac11 = function(arg0, arg1, arg2) {
|
|
204
|
+
const ret = getObject(arg0).set(getObject(arg1), getObject(arg2));
|
|
192
205
|
return addHeapObject(ret);
|
|
193
206
|
};
|
|
194
207
|
|
|
195
|
-
module.exports.
|
|
196
|
-
const ret =
|
|
208
|
+
module.exports.__wbg_new_0b9bfdd97583284e = function() {
|
|
209
|
+
const ret = new Object();
|
|
197
210
|
return addHeapObject(ret);
|
|
198
211
|
};
|
|
199
212
|
|
|
200
|
-
module.exports.
|
|
201
|
-
|
|
213
|
+
module.exports.__wbindgen_error_new = function(arg0, arg1) {
|
|
214
|
+
const ret = new Error(getStringFromWasm0(arg0, arg1));
|
|
215
|
+
return addHeapObject(ret);
|
|
202
216
|
};
|
|
203
217
|
|
|
204
|
-
module.exports.
|
|
205
|
-
|
|
218
|
+
module.exports.__wbg_String_91fba7ded13ba54c = function(arg0, arg1) {
|
|
219
|
+
const ret = String(getObject(arg1));
|
|
220
|
+
const ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
221
|
+
const len0 = WASM_VECTOR_LEN;
|
|
222
|
+
getInt32Memory0()[arg0 / 4 + 1] = len0;
|
|
223
|
+
getInt32Memory0()[arg0 / 4 + 0] = ptr0;
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
module.exports.__wbg_set_20cbc34131e76824 = function(arg0, arg1, arg2) {
|
|
227
|
+
getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
|
|
206
228
|
};
|
|
207
229
|
|
|
208
230
|
const path = require('path').join(__dirname, 'procss_bg.wasm');
|
|
Binary file
|
package/target/esm/procss.js
CHANGED
|
@@ -208,27 +208,45 @@ async function load(module, imports) {
|
|
|
208
208
|
function getImports() {
|
|
209
209
|
const imports = {};
|
|
210
210
|
imports.wbg = {};
|
|
211
|
-
imports.wbg.
|
|
212
|
-
|
|
211
|
+
imports.wbg.__wbindgen_throw = function(arg0, arg1) {
|
|
212
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
213
|
+
};
|
|
214
|
+
imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
|
|
215
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
213
216
|
return addHeapObject(ret);
|
|
214
217
|
};
|
|
218
|
+
imports.wbg.__wbindgen_is_string = function(arg0) {
|
|
219
|
+
const ret = typeof(getObject(arg0)) === 'string';
|
|
220
|
+
return ret;
|
|
221
|
+
};
|
|
222
|
+
imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
|
|
223
|
+
takeObject(arg0);
|
|
224
|
+
};
|
|
215
225
|
imports.wbg.__wbg_new_268f7b7dd3430798 = function() {
|
|
216
226
|
const ret = new Map();
|
|
217
227
|
return addHeapObject(ret);
|
|
218
228
|
};
|
|
219
|
-
imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
|
|
220
|
-
const ret = getStringFromWasm0(arg0, arg1);
|
|
221
|
-
return addHeapObject(ret);
|
|
222
|
-
};
|
|
223
229
|
imports.wbg.__wbg_set_933729cf5b66ac11 = function(arg0, arg1, arg2) {
|
|
224
230
|
const ret = getObject(arg0).set(getObject(arg1), getObject(arg2));
|
|
225
231
|
return addHeapObject(ret);
|
|
226
232
|
};
|
|
227
|
-
imports.wbg.
|
|
228
|
-
|
|
233
|
+
imports.wbg.__wbg_new_0b9bfdd97583284e = function() {
|
|
234
|
+
const ret = new Object();
|
|
235
|
+
return addHeapObject(ret);
|
|
229
236
|
};
|
|
230
|
-
imports.wbg.
|
|
231
|
-
|
|
237
|
+
imports.wbg.__wbindgen_error_new = function(arg0, arg1) {
|
|
238
|
+
const ret = new Error(getStringFromWasm0(arg0, arg1));
|
|
239
|
+
return addHeapObject(ret);
|
|
240
|
+
};
|
|
241
|
+
imports.wbg.__wbg_String_91fba7ded13ba54c = function(arg0, arg1) {
|
|
242
|
+
const ret = String(getObject(arg1));
|
|
243
|
+
const ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
244
|
+
const len0 = WASM_VECTOR_LEN;
|
|
245
|
+
getInt32Memory0()[arg0 / 4 + 1] = len0;
|
|
246
|
+
getInt32Memory0()[arg0 / 4 + 0] = ptr0;
|
|
247
|
+
};
|
|
248
|
+
imports.wbg.__wbg_set_20cbc34131e76824 = function(arg0, arg1, arg2) {
|
|
249
|
+
getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
|
|
232
250
|
};
|
|
233
251
|
|
|
234
252
|
return imports;
|
|
Binary file
|