@prospective.co/procss 0.1.12 → 0.1.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prospective.co/procss",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "description": "A simple CSS parsing and transformation framework.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -32,7 +32,7 @@ use crate::transform::TransformCss;
32
32
  /// color: red;
33
33
  /// }
34
34
  /// ```
35
- #[derive(Debug, Clone)]
35
+ #[derive(Clone, Debug, Eq, PartialEq, Hash)]
36
36
  pub struct SelectorRuleset<'a, T>(pub Selector<'a>, pub Vec<T>);
37
37
 
38
38
  impl<'a, T: RenderCss> RenderCss for SelectorRuleset<'a, T> {
@@ -95,7 +95,7 @@ impl<'a> RenderCss for QualRule<'a> {
95
95
  /// font-family: "My Font";
96
96
  /// };
97
97
  /// ```
98
- #[derive(Debug, Clone)]
98
+ #[derive(Clone, Debug, Eq, PartialEq, Hash)]
99
99
  pub struct QualRuleset<'a, T>(pub QualRule<'a>, pub Vec<T>);
100
100
 
101
101
  impl<'a, T: RenderCss> RenderCss for QualRuleset<'a, T> {
@@ -139,7 +139,7 @@ impl<'a, T: TransformCss<U>, U> TransformCss<U> for QualRuleset<'a, T> {
139
139
  /// }
140
140
  /// }
141
141
  /// ```
142
- #[derive(Debug, Clone)]
142
+ #[derive(Clone, Debug, Eq, PartialEq, Hash)]
143
143
  pub struct QualNestedRuleset<'a, T>(pub QualRule<'a>, pub Vec<Ruleset<'a, T>>);
144
144
 
145
145
  impl<'a, T: RenderCss> RenderCss for QualNestedRuleset<'a, T> {
@@ -194,7 +194,7 @@ where
194
194
  /// }
195
195
  /// ```
196
196
  #[allow(clippy::enum_variant_names)]
197
- #[derive(Clone, Debug)]
197
+ #[derive(Clone, Debug, Eq, PartialEq, Hash)]
198
198
  pub enum Ruleset<'a, T> {
199
199
  SelectorRuleset(SelectorRuleset<'a, T>),
200
200
  QualRule(QualRule<'a>),
@@ -24,7 +24,7 @@ use crate::render::RenderCss;
24
24
  use crate::transform::TransformCss;
25
25
 
26
26
  /// A CSS rule, of the form `xxx: yyy` (delimited by `;` in a ruleset).
27
- #[derive(Clone, Debug)]
27
+ #[derive(Clone, Debug, Eq, PartialEq, Hash)]
28
28
  pub struct Rule<'a> {
29
29
  pub property: Cow<'a, str>,
30
30
  pub value: Cow<'a, str>,
@@ -28,7 +28,7 @@ use crate::transform::TransformCss;
28
28
  /// A tree node which expresses a recursive `T` over `Ruleset<T>`. Using this
29
29
  /// struct in place of `Rule` allows nested CSS selectors that can be later
30
30
  /// flattened.
31
- #[derive(Clone, Debug)]
31
+ #[derive(Clone, Debug, Eq, PartialEq, Hash)]
32
32
  pub enum TreeRule<'a> {
33
33
  Rule(Rule<'a>),
34
34
  Ruleset(TreeRuleset<'a>),
package/src/ast.rs CHANGED
@@ -41,7 +41,7 @@ use crate::transformers;
41
41
  /// A non-nested "flat" CSS representation, suitable for browser output. The
42
42
  /// [`Css`] AST is typically generated via the
43
43
  /// [`crate::ast::Tree::flatten_tree`] method.
44
- #[derive(Clone, Debug)]
44
+ #[derive(Clone, Debug, Eq, PartialEq, Hash)]
45
45
  pub struct Css<'a>(pub Vec<FlatRuleset<'a>>);
46
46
 
47
47
  impl<'a> Css<'a> {
@@ -67,7 +67,7 @@ impl<'a> Css<'a> {
67
67
  }
68
68
 
69
69
  /// Iterate over the immediate children of this Tree (non-recursive).
70
- pub fn iter(&self) -> impl Iterator<Item = &'_ FlatRuleset<'a>> {
70
+ pub fn iter(&self) -> impl DoubleEndedIterator<Item = &'_ FlatRuleset<'a>> {
71
71
  self.0.iter()
72
72
  }
73
73
  }
@@ -97,7 +97,7 @@ impl<'a> RenderCss for Css<'a> {
97
97
  /// [`RenderCss`] if this is needed, though this output can't be read by
98
98
  /// browsers and is not identical to the input since whitespace has been
99
99
  /// discarded.
100
- #[derive(Clone, Debug)]
100
+ #[derive(Clone, Debug, Eq, PartialEq, Hash)]
101
101
  pub struct Tree<'a>(pub Vec<TreeRuleset<'a>>);
102
102
 
103
103
  impl<'a> Tree<'a> {
package/src/builder.rs CHANGED
@@ -81,8 +81,9 @@ impl<'a> BuildCss<'a> {
81
81
  self.trees.insert(path, tree);
82
82
  }
83
83
 
84
- let dep_trees = self.trees.clone();
85
- for (path, tree) in self.trees.iter_mut() {
84
+ for path in self.paths.iter() {
85
+ let dep_trees = self.trees.clone();
86
+ let tree = self.trees.get_mut(path.as_path()).unwrap();
86
87
  transformers::apply_import(&dep_trees)(tree);
87
88
  transformers::apply_mixin(tree);
88
89
  transformers::apply_var(tree);
@@ -92,7 +93,10 @@ impl<'a> BuildCss<'a> {
92
93
  for (path, css) in self.css.iter_mut() {
93
94
  let srcdir = utils::join_paths(&self.rootdir, path);
94
95
  transformers::inline_url(&srcdir.to_string_lossy())(css);
95
- transformers::dedupe(css);
96
+ transformers::merge_siblings(css);
97
+ transformers::remove_mixin(css);
98
+ transformers::remove_var(css);
99
+ transformers::deduplicate(css);
96
100
  }
97
101
 
98
102
  Ok(CompiledCss(self))
package/src/lib.rs CHANGED
@@ -58,8 +58,10 @@
58
58
  //!
59
59
  //! let mut ast = procss::parse(test).unwrap();
60
60
  //! transformers::apply_mixin(&mut ast);
61
- //! let flat = ast.flatten_tree().as_css_string();
62
- //! assert_eq!(flat, "div{color:red;}");
61
+ //! let mut flat = ast.flatten_tree();
62
+ //! transformers::remove_mixin(&mut flat);
63
+ //! let css = flat.as_css_string();
64
+ //! assert_eq!(css, "div{color:red;}");
63
65
  //! ```
64
66
  //!
65
67
  //! For coordinating large builds on a tree of CSS files, the [`BuildCss`]
package/src/main.rs CHANGED
@@ -36,4 +36,6 @@ fn main() {
36
36
  }
37
37
 
38
38
  #[cfg(target_arch = "wasm32")]
39
- fn main() {}
39
+ fn main() {
40
+ std::panic::set_hook(Box::new(console_error_panic_hook::hook));
41
+ }
@@ -20,7 +20,7 @@ use crate::ast::*;
20
20
  /// # Example
21
21
  ///
22
22
  /// ```
23
- /// # use procss::{parse, transformers::apply_mixin, RenderCss};
23
+ /// # use procss::{parse, transformers::apply_mixin, transformers::remove_mixin, RenderCss};
24
24
  /// let css = "
25
25
  /// @mixin test {
26
26
  /// opacity: 0;
@@ -32,21 +32,21 @@ use crate::ast::*;
32
32
  /// ";
33
33
  /// let mut tree = parse(css).unwrap();
34
34
  /// apply_mixin(&mut tree);
35
- /// let css = tree.flatten_tree().as_css_string();
35
+ /// let mut flat = tree.flatten_tree();
36
+ /// remove_mixin(&mut flat);
37
+ /// let css = flat.as_css_string();
36
38
  /// assert_eq!(css, "div.open{color:red;}div.open{opacity:0;}");
37
39
  /// ```
38
40
  pub fn apply_mixin<'a>(tree: &mut Tree<'a>) {
39
41
  let mut mixins: HashMap<&'a str, Vec<TreeRule<'a>>> = HashMap::new();
40
42
  tree.transform(|ruleset| {
41
- if let Ruleset::QualRuleset(crate::ast::QualRuleset(QualRule(name, Some(val)), props)) = ruleset {
42
- if *name == "mixin" {
43
+ if let Ruleset::QualRuleset(crate::ast::QualRuleset(QualRule(name, Some(val)), props)) =
44
+ ruleset
45
+ {
46
+ if *name == "mixin" {
43
47
  mixins.insert(val.trim(), props.clone());
44
48
  }
45
49
  }
46
-
47
- if matches!(ruleset, Ruleset::QualRuleset(QualRuleset(QualRule(name, _), _)) if *name == "mixin") {
48
- *ruleset = Ruleset::SelectorRuleset(SelectorRuleset(Selector::default(), vec![]))
49
- }
50
50
  });
51
51
 
52
52
  let mut count = 5;
@@ -17,17 +17,11 @@ use crate::ast::*;
17
17
  pub fn apply_var<'a>(tree: &mut Tree<'a>) {
18
18
  let mut mixins: HashMap<&'a str, &'a str> = HashMap::new();
19
19
  tree.transform(|ruleset| {
20
- let mut is_mixin = false;
21
20
  if let Ruleset::QualRule(QualRule(name, Some(val))) = ruleset {
22
21
  if let Some(val) = val.strip_prefix(':') {
23
22
  mixins.insert(name, val);
24
- is_mixin = true;
25
23
  }
26
24
  }
27
-
28
- if is_mixin {
29
- *ruleset = Ruleset::QualRuleset(QualRuleset(QualRule("", None), vec![]))
30
- }
31
25
  });
32
26
 
33
27
  let mut mixins = mixins.iter().collect::<Vec<_>>();
@@ -0,0 +1,27 @@
1
+ // ┌───────────────────────────────────────────────────────────────────────────┐
2
+ // │ │
3
+ // │ ██████╗ ██████╗ ██████╗ Copyright (C) 2022, The Prospective Company │
4
+ // │ ██╔══██╗██╔══██╗██╔═══██╗ │
5
+ // │ ██████╔╝██████╔╝██║ ██║ This file is part of the Procss library, │
6
+ // │ ██╔═══╝ ██╔══██╗██║ ██║ distributed under the terms of the │
7
+ // │ ██║ ██║ ██║╚██████╔╝ Apache License 2.0. The full license can │
8
+ // │ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ be found in the LICENSE file. │
9
+ // │ │
10
+ // └───────────────────────────────────────────────────────────────────────────┘
11
+
12
+ use std::collections::HashSet;
13
+
14
+ use crate::ast::Ruleset::{self};
15
+ use crate::ast::*;
16
+
17
+ pub fn deduplicate(css: &mut Css) {
18
+ let mut seen: HashSet<&Ruleset<'_, Rule<'_>>> = HashSet::default();
19
+ let res = css
20
+ .iter()
21
+ .rev()
22
+ .filter(|x| seen.insert(*x))
23
+ .rev()
24
+ .cloned()
25
+ .collect();
26
+ *css = crate::ast::Css(res);
27
+ }
@@ -14,14 +14,12 @@ use crate::ast::*;
14
14
 
15
15
  pub fn filter_refs(tree: &mut Tree) {
16
16
  *tree = Tree(
17
- tree.iter()
18
- .cloned()
19
- .filter(|y| match y {
17
+ tree.iter().filter(|&y| match y {
20
18
  Ruleset::SelectorRuleset(_) => false,
21
19
  Ruleset::QualRule(_) => true,
22
20
  Ruleset::QualRuleset(_) => true,
23
21
  Ruleset::QualNestedRuleset(_) => true,
24
- })
22
+ }).cloned()
25
23
  .collect(),
26
24
  )
27
25
  }
@@ -21,6 +21,23 @@ use crate::utils::fs;
21
21
  #[cfg(feature = "iotest")]
22
22
  use crate::utils::IoTestFs;
23
23
 
24
+ #[cfg(not(target_arch = "wasm32"))]
25
+ fn read_file_sync(path: &Path) -> Option<Vec<u8>> {
26
+ fs::read(path).ok()
27
+ }
28
+
29
+ #[cfg(target_arch = "wasm32")]
30
+ fn read_file_sync(path: &Path) -> Option<Vec<u8>> {
31
+ use wasm_bindgen::prelude::*;
32
+ #[wasm_bindgen(module = "fs")]
33
+ extern "C" {
34
+ #[wasm_bindgen(catch)]
35
+ fn readFileSync(path: &str) -> Result<Vec<u8>, JsValue>;
36
+ }
37
+
38
+ readFileSync(&*path.to_string_lossy()).ok()
39
+ }
40
+
24
41
  fn parse_url(input: &str) -> nom::IResult<&str, &str> {
25
42
  let unquoted = delimited(tag("url("), is_not(")"), tag(")"));
26
43
  let quoted = delimited(tag("url(\""), is_not("\""), tag("\")"));
@@ -32,7 +49,7 @@ fn into_data_uri<'a>(path: &Path) -> Option<Cow<'a, str>> {
32
49
  return None;
33
50
  }
34
51
 
35
- let contents = fs::read(path).ok()?;
52
+ let contents = read_file_sync(path)?;
36
53
  let encoded = base64::encode(contents);
37
54
  let fff = path.extension().unwrap_or_default().to_string_lossy();
38
55
  let fmt = match fff.as_ref() {
@@ -9,10 +9,12 @@
9
9
  // │ │
10
10
  // └───────────────────────────────────────────────────────────────────────────┘
11
11
 
12
+ use std::collections::HashSet;
13
+
12
14
  use crate::ast::Ruleset::{self};
13
15
  use crate::ast::*;
14
16
 
15
- pub fn dedupe(css: &mut Css) {
17
+ pub fn merge_siblings(css: &mut Css) {
16
18
  let mut res = vec![];
17
19
  let reduced = css.iter().cloned().reduce(|x, y| match (x, y) {
18
20
  (Ruleset::QualRule(x), Ruleset::QualRule(y)) if x == y => Ruleset::QualRule(x),
@@ -31,5 +33,7 @@ pub fn dedupe(css: &mut Css) {
31
33
  res.push(reduced.clone());
32
34
  }
33
35
 
36
+ let mut seen: HashSet<&Ruleset<'_, Rule<'_>>> = HashSet::default();
37
+ let res = res.iter().filter(|x| seen.insert(*x)).cloned().collect();
34
38
  *css = crate::ast::Css(res)
35
39
  }
@@ -29,15 +29,21 @@
29
29
  mod apply_import;
30
30
  mod apply_mixin;
31
31
  mod apply_var;
32
- mod dedupe;
32
+ mod deduplicate;
33
33
  mod filter_refs;
34
34
  mod flat_self;
35
35
  mod inline_url;
36
+ mod merge_siblings;
37
+ mod remove_mixin;
38
+ mod remove_var;
36
39
 
37
40
  pub use self::apply_import::apply_import;
38
41
  pub use self::apply_mixin::apply_mixin;
39
42
  pub use self::apply_var::apply_var;
40
- pub use self::dedupe::dedupe;
43
+ pub use self::deduplicate::deduplicate;
41
44
  pub use self::filter_refs::filter_refs;
42
45
  pub(crate) use self::flat_self::flat_self;
43
46
  pub use self::inline_url::inline_url;
47
+ pub use self::merge_siblings::merge_siblings;
48
+ pub use self::remove_mixin::remove_mixin;
49
+ pub use self::remove_var::remove_var;
@@ -0,0 +1,29 @@
1
+ // ┌───────────────────────────────────────────────────────────────────────────┐
2
+ // │ │
3
+ // │ ██████╗ ██████╗ ██████╗ Copyright (C) 2022, The Prospective Company │
4
+ // │ ██╔══██╗██╔══██╗██╔═══██╗ │
5
+ // │ ██████╔╝██████╔╝██║ ██║ This file is part of the Procss library, │
6
+ // │ ██╔═══╝ ██╔══██╗██║ ██║ distributed under the terms of the │
7
+ // │ ██║ ██║ ██║╚██████╔╝ Apache License 2.0. The full license can │
8
+ // │ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ be found in the LICENSE file. │
9
+ // │ │
10
+ // └───────────────────────────────────────────────────────────────────────────┘
11
+
12
+ use crate::ast::Ruleset::{self};
13
+ use crate::ast::*;
14
+
15
+ pub fn remove_mixin(css: &mut Css) {
16
+ let reduced = css
17
+ .iter()
18
+ .filter(|&x| {
19
+ !matches!(
20
+ x,
21
+ Ruleset::QualRule(QualRule("mixin", _))
22
+ | Ruleset::QualNestedRuleset(QualNestedRuleset(QualRule("mixin", _), _))
23
+ | Ruleset::QualRuleset(QualRuleset(QualRule("mixin", _), _))
24
+ )
25
+ })
26
+ .cloned();
27
+
28
+ *css = crate::ast::Css(reduced.collect())
29
+ }
@@ -0,0 +1,27 @@
1
+ // ┌───────────────────────────────────────────────────────────────────────────┐
2
+ // │ │
3
+ // │ ██████╗ ██████╗ ██████╗ Copyright (C) 2022, The Prospective Company │
4
+ // │ ██╔══██╗██╔══██╗██╔═══██╗ │
5
+ // │ ██████╔╝██████╔╝██║ ██║ This file is part of the Procss library, │
6
+ // │ ██╔═══╝ ██╔══██╗██║ ██║ distributed under the terms of the │
7
+ // │ ██║ ██║ ██║╚██████╔╝ Apache License 2.0. The full license can │
8
+ // │ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ be found in the LICENSE file. │
9
+ // │ │
10
+ // └───────────────────────────────────────────────────────────────────────────┘
11
+
12
+ use crate::ast::Ruleset::{self};
13
+ use crate::ast::*;
14
+
15
+ pub fn remove_var(css: &mut Css) {
16
+ let reduced = css
17
+ .iter()
18
+ .filter(|&ruleset| match ruleset {
19
+ Ruleset::QualRule(QualRule(name, Some(val))) if val.strip_prefix(':').is_some() => {
20
+ false
21
+ }
22
+ _ => true,
23
+ })
24
+ .cloned();
25
+
26
+ *css = crate::ast::Css(reduced.collect())
27
+ }
@@ -1,26 +1,28 @@
1
1
  let imports = {};
2
2
  imports['__wbindgen_placeholder__'] = module.exports;
3
3
  let wasm;
4
+ const { readFileSync } = require(`fs`);
4
5
  const { TextDecoder, TextEncoder } = require(`util`);
5
6
 
6
7
  let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
7
8
 
8
9
  cachedTextDecoder.decode();
9
10
 
10
- let cachedUint8Memory0 = new Uint8Array();
11
+ let cachedUint8Memory0 = null;
11
12
 
12
13
  function getUint8Memory0() {
13
- if (cachedUint8Memory0.byteLength === 0) {
14
+ if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
14
15
  cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
15
16
  }
16
17
  return cachedUint8Memory0;
17
18
  }
18
19
 
19
20
  function getStringFromWasm0(ptr, len) {
21
+ ptr = ptr >>> 0;
20
22
  return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
21
23
  }
22
24
 
23
- const heap = new Array(32).fill(undefined);
25
+ const heap = new Array(128).fill(undefined);
24
26
 
25
27
  heap.push(undefined, null, true, false);
26
28
 
@@ -38,7 +40,7 @@ function addHeapObject(obj) {
38
40
  function getObject(idx) { return heap[idx]; }
39
41
 
40
42
  function dropObject(idx) {
41
- if (idx < 36) return;
43
+ if (idx < 132) return;
42
44
  heap[idx] = heap_next;
43
45
  heap_next = idx;
44
46
  }
@@ -70,14 +72,14 @@ function passStringToWasm0(arg, malloc, realloc) {
70
72
 
71
73
  if (realloc === undefined) {
72
74
  const buf = cachedTextEncoder.encode(arg);
73
- const ptr = malloc(buf.length);
75
+ const ptr = malloc(buf.length, 1) >>> 0;
74
76
  getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
75
77
  WASM_VECTOR_LEN = buf.length;
76
78
  return ptr;
77
79
  }
78
80
 
79
81
  let len = arg.length;
80
- let ptr = malloc(len);
82
+ let ptr = malloc(len, 1) >>> 0;
81
83
 
82
84
  const mem = getUint8Memory0();
83
85
 
@@ -93,7 +95,7 @@ function passStringToWasm0(arg, malloc, realloc) {
93
95
  if (offset !== 0) {
94
96
  arg = arg.slice(offset);
95
97
  }
96
- ptr = realloc(ptr, len, len = offset + arg.length * 3);
98
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
97
99
  const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
98
100
  const ret = encodeString(arg, view);
99
101
 
@@ -104,30 +106,38 @@ function passStringToWasm0(arg, malloc, realloc) {
104
106
  return ptr;
105
107
  }
106
108
 
107
- let cachedInt32Memory0 = new Int32Array();
109
+ let cachedInt32Memory0 = null;
108
110
 
109
111
  function getInt32Memory0() {
110
- if (cachedInt32Memory0.byteLength === 0) {
112
+ if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
111
113
  cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
112
114
  }
113
115
  return cachedInt32Memory0;
114
116
  }
117
+
118
+ function passArray8ToWasm0(arg, malloc) {
119
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
120
+ getUint8Memory0().set(arg, ptr / 1);
121
+ WASM_VECTOR_LEN = arg.length;
122
+ return ptr;
123
+ }
124
+
125
+ function handleError(f, args) {
126
+ try {
127
+ return f.apply(this, args);
128
+ } catch (e) {
129
+ wasm.__wbindgen_exn_store(addHeapObject(e));
130
+ }
131
+ }
115
132
  /**
116
133
  * An implementation of `BuildCss` which owns its data, suitable for use as an
117
134
  * exported type in JavaScript.
118
135
  */
119
136
  class BuildCss {
120
137
 
121
- static __wrap(ptr) {
122
- const obj = Object.create(BuildCss.prototype);
123
- obj.ptr = ptr;
124
-
125
- return obj;
126
- }
127
-
128
138
  __destroy_into_raw() {
129
- const ptr = this.ptr;
130
- this.ptr = 0;
139
+ const ptr = this.__wbg_ptr;
140
+ this.__wbg_ptr = 0;
131
141
 
132
142
  return ptr;
133
143
  }
@@ -143,7 +153,8 @@ class BuildCss {
143
153
  const ptr0 = passStringToWasm0(rootdir, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
144
154
  const len0 = WASM_VECTOR_LEN;
145
155
  const ret = wasm.buildcss_new(ptr0, len0);
146
- return BuildCss.__wrap(ret);
156
+ this.__wbg_ptr = ret >>> 0;
157
+ return this;
147
158
  }
148
159
  /**
149
160
  * @param {string} path
@@ -154,7 +165,7 @@ class BuildCss {
154
165
  const len0 = WASM_VECTOR_LEN;
155
166
  const ptr1 = passStringToWasm0(content, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
156
167
  const len1 = WASM_VECTOR_LEN;
157
- wasm.buildcss_add(this.ptr, ptr0, len0, ptr1, len1);
168
+ wasm.buildcss_add(this.__wbg_ptr, ptr0, len0, ptr1, len1);
158
169
  }
159
170
  /**
160
171
  * @returns {any}
@@ -162,7 +173,7 @@ class BuildCss {
162
173
  compile() {
163
174
  try {
164
175
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
165
- wasm.buildcss_compile(retptr, this.ptr);
176
+ wasm.buildcss_compile(retptr, this.__wbg_ptr);
166
177
  var r0 = getInt32Memory0()[retptr / 4 + 0];
167
178
  var r1 = getInt32Memory0()[retptr / 4 + 1];
168
179
  var r2 = getInt32Memory0()[retptr / 4 + 2];
@@ -177,8 +188,29 @@ class BuildCss {
177
188
  }
178
189
  module.exports.BuildCss = BuildCss;
179
190
 
180
- module.exports.__wbindgen_throw = function(arg0, arg1) {
181
- throw new Error(getStringFromWasm0(arg0, arg1));
191
+ module.exports.__wbg_error_f851667af71bcfc6 = function(arg0, arg1) {
192
+ let deferred0_0;
193
+ let deferred0_1;
194
+ try {
195
+ deferred0_0 = arg0;
196
+ deferred0_1 = arg1;
197
+ console.error(getStringFromWasm0(arg0, arg1));
198
+ } finally {
199
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
200
+ }
201
+ };
202
+
203
+ module.exports.__wbg_new_abda76e883ba8a5f = function() {
204
+ const ret = new Error();
205
+ return addHeapObject(ret);
206
+ };
207
+
208
+ module.exports.__wbg_stack_658279fe44541cf6 = function(arg0, arg1) {
209
+ const ret = getObject(arg1).stack;
210
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
211
+ const len1 = WASM_VECTOR_LEN;
212
+ getInt32Memory0()[arg0 / 4 + 1] = len1;
213
+ getInt32Memory0()[arg0 / 4 + 0] = ptr1;
182
214
  };
183
215
 
184
216
  module.exports.__wbindgen_string_new = function(arg0, arg1) {
@@ -186,47 +218,59 @@ module.exports.__wbindgen_string_new = function(arg0, arg1) {
186
218
  return addHeapObject(ret);
187
219
  };
188
220
 
221
+ module.exports.__wbindgen_object_drop_ref = function(arg0) {
222
+ takeObject(arg0);
223
+ };
224
+
225
+ module.exports.__wbindgen_throw = function(arg0, arg1) {
226
+ throw new Error(getStringFromWasm0(arg0, arg1));
227
+ };
228
+
189
229
  module.exports.__wbindgen_is_string = function(arg0) {
190
230
  const ret = typeof(getObject(arg0)) === 'string';
191
231
  return ret;
192
232
  };
193
233
 
194
- module.exports.__wbindgen_object_drop_ref = function(arg0) {
195
- takeObject(arg0);
196
- };
197
-
198
- module.exports.__wbg_new_268f7b7dd3430798 = function() {
234
+ module.exports.__wbg_new_1b94180eeb48f2a2 = function() {
199
235
  const ret = new Map();
200
236
  return addHeapObject(ret);
201
237
  };
202
238
 
203
- module.exports.__wbg_set_933729cf5b66ac11 = function(arg0, arg1, arg2) {
239
+ module.exports.__wbg_set_3355b9f2d3092e3b = function(arg0, arg1, arg2) {
204
240
  const ret = getObject(arg0).set(getObject(arg1), getObject(arg2));
205
241
  return addHeapObject(ret);
206
242
  };
207
243
 
208
- module.exports.__wbg_new_0b9bfdd97583284e = function() {
244
+ module.exports.__wbg_new_c728d68b8b34487e = function() {
209
245
  const ret = new Object();
210
246
  return addHeapObject(ret);
211
247
  };
212
248
 
213
- module.exports.__wbg_String_91fba7ded13ba54c = function(arg0, arg1) {
214
- const ret = String(getObject(arg1));
215
- const ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
216
- const len0 = WASM_VECTOR_LEN;
217
- getInt32Memory0()[arg0 / 4 + 1] = len0;
218
- getInt32Memory0()[arg0 / 4 + 0] = ptr0;
219
- };
220
-
221
249
  module.exports.__wbindgen_error_new = function(arg0, arg1) {
222
250
  const ret = new Error(getStringFromWasm0(arg0, arg1));
223
251
  return addHeapObject(ret);
224
252
  };
225
253
 
254
+ module.exports.__wbg_String_91fba7ded13ba54c = function(arg0, arg1) {
255
+ const ret = String(getObject(arg1));
256
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
257
+ const len1 = WASM_VECTOR_LEN;
258
+ getInt32Memory0()[arg0 / 4 + 1] = len1;
259
+ getInt32Memory0()[arg0 / 4 + 0] = ptr1;
260
+ };
261
+
226
262
  module.exports.__wbg_set_20cbc34131e76824 = function(arg0, arg1, arg2) {
227
263
  getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
228
264
  };
229
265
 
266
+ module.exports.__wbg_readFileSync_cf4388d92a927935 = function() { return handleError(function (arg0, arg1, arg2) {
267
+ const ret = readFileSync(getStringFromWasm0(arg1, arg2));
268
+ const ptr1 = passArray8ToWasm0(ret, wasm.__wbindgen_malloc);
269
+ const len1 = WASM_VECTOR_LEN;
270
+ getInt32Memory0()[arg0 / 4 + 1] = len1;
271
+ getInt32Memory0()[arg0 / 4 + 0] = ptr1;
272
+ }, arguments) };
273
+
230
274
  const path = require('path').join(__dirname, 'procss_bg.wasm');
231
275
  const bytes = require('fs').readFileSync(path);
232
276
 
Binary file
@@ -6,7 +6,9 @@ export function __wbg_buildcss_free(a: number): void;
6
6
  export function buildcss_new(a: number, b: number): number;
7
7
  export function buildcss_add(a: number, b: number, c: number, d: number, e: number): void;
8
8
  export function buildcss_compile(a: number, b: number): void;
9
- export function __wbindgen_malloc(a: number): number;
10
- export function __wbindgen_realloc(a: number, b: number, c: number): number;
9
+ export function __wbindgen_free(a: number, b: number, c: number): void;
10
+ export function __wbindgen_malloc(a: number, b: number): number;
11
+ export function __wbindgen_realloc(a: number, b: number, c: number, d: number): number;
11
12
  export function __wbindgen_add_to_stack_pointer(a: number): number;
13
+ export function __wbindgen_exn_store(a: number): void;
12
14
  export function __wbindgen_start(): void;
@@ -30,9 +30,11 @@ export interface InitOutput {
30
30
  readonly buildcss_new: (a: number, b: number) => number;
31
31
  readonly buildcss_add: (a: number, b: number, c: number, d: number, e: number) => void;
32
32
  readonly buildcss_compile: (a: number, b: number) => void;
33
- readonly __wbindgen_malloc: (a: number) => number;
34
- readonly __wbindgen_realloc: (a: number, b: number, c: number) => number;
33
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
34
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
35
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
35
36
  readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
37
+ readonly __wbindgen_exn_store: (a: number) => void;
36
38
  readonly __wbindgen_start: () => void;
37
39
  }
38
40
 
@@ -55,4 +57,4 @@ export function initSync(module: SyncInitInput): InitOutput;
55
57
  *
56
58
  * @returns {Promise<InitOutput>}
57
59
  */
58
- export default function init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
60
+ export default function __wbg_init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -1,24 +1,26 @@
1
+ import { readFileSync } from 'fs';
1
2
 
2
3
  let wasm;
3
4
 
4
- const cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
5
+ const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
5
6
 
6
- cachedTextDecoder.decode();
7
+ if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
7
8
 
8
- let cachedUint8Memory0 = new Uint8Array();
9
+ let cachedUint8Memory0 = null;
9
10
 
10
11
  function getUint8Memory0() {
11
- if (cachedUint8Memory0.byteLength === 0) {
12
+ if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
12
13
  cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
13
14
  }
14
15
  return cachedUint8Memory0;
15
16
  }
16
17
 
17
18
  function getStringFromWasm0(ptr, len) {
19
+ ptr = ptr >>> 0;
18
20
  return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
19
21
  }
20
22
 
21
- const heap = new Array(32).fill(undefined);
23
+ const heap = new Array(128).fill(undefined);
22
24
 
23
25
  heap.push(undefined, null, true, false);
24
26
 
@@ -36,7 +38,7 @@ function addHeapObject(obj) {
36
38
  function getObject(idx) { return heap[idx]; }
37
39
 
38
40
  function dropObject(idx) {
39
- if (idx < 36) return;
41
+ if (idx < 132) return;
40
42
  heap[idx] = heap_next;
41
43
  heap_next = idx;
42
44
  }
@@ -49,7 +51,7 @@ function takeObject(idx) {
49
51
 
50
52
  let WASM_VECTOR_LEN = 0;
51
53
 
52
- const cachedTextEncoder = new TextEncoder('utf-8');
54
+ const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
53
55
 
54
56
  const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
55
57
  ? function (arg, view) {
@@ -68,14 +70,14 @@ function passStringToWasm0(arg, malloc, realloc) {
68
70
 
69
71
  if (realloc === undefined) {
70
72
  const buf = cachedTextEncoder.encode(arg);
71
- const ptr = malloc(buf.length);
73
+ const ptr = malloc(buf.length, 1) >>> 0;
72
74
  getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
73
75
  WASM_VECTOR_LEN = buf.length;
74
76
  return ptr;
75
77
  }
76
78
 
77
79
  let len = arg.length;
78
- let ptr = malloc(len);
80
+ let ptr = malloc(len, 1) >>> 0;
79
81
 
80
82
  const mem = getUint8Memory0();
81
83
 
@@ -91,7 +93,7 @@ function passStringToWasm0(arg, malloc, realloc) {
91
93
  if (offset !== 0) {
92
94
  arg = arg.slice(offset);
93
95
  }
94
- ptr = realloc(ptr, len, len = offset + arg.length * 3);
96
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
95
97
  const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
96
98
  const ret = encodeString(arg, view);
97
99
 
@@ -102,30 +104,38 @@ function passStringToWasm0(arg, malloc, realloc) {
102
104
  return ptr;
103
105
  }
104
106
 
105
- let cachedInt32Memory0 = new Int32Array();
107
+ let cachedInt32Memory0 = null;
106
108
 
107
109
  function getInt32Memory0() {
108
- if (cachedInt32Memory0.byteLength === 0) {
110
+ if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) {
109
111
  cachedInt32Memory0 = new Int32Array(wasm.memory.buffer);
110
112
  }
111
113
  return cachedInt32Memory0;
112
114
  }
115
+
116
+ function passArray8ToWasm0(arg, malloc) {
117
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
118
+ getUint8Memory0().set(arg, ptr / 1);
119
+ WASM_VECTOR_LEN = arg.length;
120
+ return ptr;
121
+ }
122
+
123
+ function handleError(f, args) {
124
+ try {
125
+ return f.apply(this, args);
126
+ } catch (e) {
127
+ wasm.__wbindgen_exn_store(addHeapObject(e));
128
+ }
129
+ }
113
130
  /**
114
131
  * An implementation of `BuildCss` which owns its data, suitable for use as an
115
132
  * exported type in JavaScript.
116
133
  */
117
134
  export class BuildCss {
118
135
 
119
- static __wrap(ptr) {
120
- const obj = Object.create(BuildCss.prototype);
121
- obj.ptr = ptr;
122
-
123
- return obj;
124
- }
125
-
126
136
  __destroy_into_raw() {
127
- const ptr = this.ptr;
128
- this.ptr = 0;
137
+ const ptr = this.__wbg_ptr;
138
+ this.__wbg_ptr = 0;
129
139
 
130
140
  return ptr;
131
141
  }
@@ -141,7 +151,8 @@ export class BuildCss {
141
151
  const ptr0 = passStringToWasm0(rootdir, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
142
152
  const len0 = WASM_VECTOR_LEN;
143
153
  const ret = wasm.buildcss_new(ptr0, len0);
144
- return BuildCss.__wrap(ret);
154
+ this.__wbg_ptr = ret >>> 0;
155
+ return this;
145
156
  }
146
157
  /**
147
158
  * @param {string} path
@@ -152,7 +163,7 @@ export class BuildCss {
152
163
  const len0 = WASM_VECTOR_LEN;
153
164
  const ptr1 = passStringToWasm0(content, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
154
165
  const len1 = WASM_VECTOR_LEN;
155
- wasm.buildcss_add(this.ptr, ptr0, len0, ptr1, len1);
166
+ wasm.buildcss_add(this.__wbg_ptr, ptr0, len0, ptr1, len1);
156
167
  }
157
168
  /**
158
169
  * @returns {any}
@@ -160,7 +171,7 @@ export class BuildCss {
160
171
  compile() {
161
172
  try {
162
173
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
163
- wasm.buildcss_compile(retptr, this.ptr);
174
+ wasm.buildcss_compile(retptr, this.__wbg_ptr);
164
175
  var r0 = getInt32Memory0()[retptr / 4 + 0];
165
176
  var r1 = getInt32Memory0()[retptr / 4 + 1];
166
177
  var r2 = getInt32Memory0()[retptr / 4 + 2];
@@ -174,7 +185,7 @@ export class BuildCss {
174
185
  }
175
186
  }
176
187
 
177
- async function load(module, imports) {
188
+ async function __wbg_load(module, imports) {
178
189
  if (typeof Response === 'function' && module instanceof Response) {
179
190
  if (typeof WebAssembly.instantiateStreaming === 'function') {
180
191
  try {
@@ -205,71 +216,102 @@ async function load(module, imports) {
205
216
  }
206
217
  }
207
218
 
208
- function getImports() {
219
+ function __wbg_get_imports() {
209
220
  const imports = {};
210
221
  imports.wbg = {};
211
- imports.wbg.__wbindgen_throw = function(arg0, arg1) {
212
- throw new Error(getStringFromWasm0(arg0, arg1));
222
+ imports.wbg.__wbg_error_f851667af71bcfc6 = function(arg0, arg1) {
223
+ let deferred0_0;
224
+ let deferred0_1;
225
+ try {
226
+ deferred0_0 = arg0;
227
+ deferred0_1 = arg1;
228
+ console.error(getStringFromWasm0(arg0, arg1));
229
+ } finally {
230
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
231
+ }
232
+ };
233
+ imports.wbg.__wbg_new_abda76e883ba8a5f = function() {
234
+ const ret = new Error();
235
+ return addHeapObject(ret);
236
+ };
237
+ imports.wbg.__wbg_stack_658279fe44541cf6 = function(arg0, arg1) {
238
+ const ret = getObject(arg1).stack;
239
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
240
+ const len1 = WASM_VECTOR_LEN;
241
+ getInt32Memory0()[arg0 / 4 + 1] = len1;
242
+ getInt32Memory0()[arg0 / 4 + 0] = ptr1;
213
243
  };
214
244
  imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
215
245
  const ret = getStringFromWasm0(arg0, arg1);
216
246
  return addHeapObject(ret);
217
247
  };
248
+ imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
249
+ takeObject(arg0);
250
+ };
251
+ imports.wbg.__wbindgen_throw = function(arg0, arg1) {
252
+ throw new Error(getStringFromWasm0(arg0, arg1));
253
+ };
218
254
  imports.wbg.__wbindgen_is_string = function(arg0) {
219
255
  const ret = typeof(getObject(arg0)) === 'string';
220
256
  return ret;
221
257
  };
222
- imports.wbg.__wbindgen_object_drop_ref = function(arg0) {
223
- takeObject(arg0);
224
- };
225
- imports.wbg.__wbg_new_268f7b7dd3430798 = function() {
258
+ imports.wbg.__wbg_new_1b94180eeb48f2a2 = function() {
226
259
  const ret = new Map();
227
260
  return addHeapObject(ret);
228
261
  };
229
- imports.wbg.__wbg_set_933729cf5b66ac11 = function(arg0, arg1, arg2) {
262
+ imports.wbg.__wbg_set_3355b9f2d3092e3b = function(arg0, arg1, arg2) {
230
263
  const ret = getObject(arg0).set(getObject(arg1), getObject(arg2));
231
264
  return addHeapObject(ret);
232
265
  };
233
- imports.wbg.__wbg_new_0b9bfdd97583284e = function() {
266
+ imports.wbg.__wbg_new_c728d68b8b34487e = function() {
234
267
  const ret = new Object();
235
268
  return addHeapObject(ret);
236
269
  };
237
- imports.wbg.__wbg_String_91fba7ded13ba54c = function(arg0, arg1) {
238
- const ret = String(getObject(arg1));
239
- const ptr0 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
240
- const len0 = WASM_VECTOR_LEN;
241
- getInt32Memory0()[arg0 / 4 + 1] = len0;
242
- getInt32Memory0()[arg0 / 4 + 0] = ptr0;
243
- };
244
270
  imports.wbg.__wbindgen_error_new = function(arg0, arg1) {
245
271
  const ret = new Error(getStringFromWasm0(arg0, arg1));
246
272
  return addHeapObject(ret);
247
273
  };
274
+ imports.wbg.__wbg_String_91fba7ded13ba54c = function(arg0, arg1) {
275
+ const ret = String(getObject(arg1));
276
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
277
+ const len1 = WASM_VECTOR_LEN;
278
+ getInt32Memory0()[arg0 / 4 + 1] = len1;
279
+ getInt32Memory0()[arg0 / 4 + 0] = ptr1;
280
+ };
248
281
  imports.wbg.__wbg_set_20cbc34131e76824 = function(arg0, arg1, arg2) {
249
282
  getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
250
283
  };
284
+ imports.wbg.__wbg_readFileSync_cf4388d92a927935 = function() { return handleError(function (arg0, arg1, arg2) {
285
+ const ret = readFileSync(getStringFromWasm0(arg1, arg2));
286
+ const ptr1 = passArray8ToWasm0(ret, wasm.__wbindgen_malloc);
287
+ const len1 = WASM_VECTOR_LEN;
288
+ getInt32Memory0()[arg0 / 4 + 1] = len1;
289
+ getInt32Memory0()[arg0 / 4 + 0] = ptr1;
290
+ }, arguments) };
251
291
 
252
292
  return imports;
253
293
  }
254
294
 
255
- function initMemory(imports, maybe_memory) {
295
+ function __wbg_init_memory(imports, maybe_memory) {
256
296
 
257
297
  }
258
298
 
259
- function finalizeInit(instance, module) {
299
+ function __wbg_finalize_init(instance, module) {
260
300
  wasm = instance.exports;
261
- init.__wbindgen_wasm_module = module;
262
- cachedInt32Memory0 = new Int32Array();
263
- cachedUint8Memory0 = new Uint8Array();
301
+ __wbg_init.__wbindgen_wasm_module = module;
302
+ cachedInt32Memory0 = null;
303
+ cachedUint8Memory0 = null;
264
304
 
265
305
  wasm.__wbindgen_start();
266
306
  return wasm;
267
307
  }
268
308
 
269
309
  function initSync(module) {
270
- const imports = getImports();
310
+ if (wasm !== undefined) return wasm;
271
311
 
272
- initMemory(imports);
312
+ const imports = __wbg_get_imports();
313
+
314
+ __wbg_init_memory(imports);
273
315
 
274
316
  if (!(module instanceof WebAssembly.Module)) {
275
317
  module = new WebAssembly.Module(module);
@@ -277,25 +319,27 @@ function initSync(module) {
277
319
 
278
320
  const instance = new WebAssembly.Instance(module, imports);
279
321
 
280
- return finalizeInit(instance, module);
322
+ return __wbg_finalize_init(instance, module);
281
323
  }
282
324
 
283
- async function init(input) {
325
+ async function __wbg_init(input) {
326
+ if (wasm !== undefined) return wasm;
327
+
284
328
  if (typeof input === 'undefined') {
285
329
  input = new URL('procss_bg.wasm', import.meta.url);
286
330
  }
287
- const imports = getImports();
331
+ const imports = __wbg_get_imports();
288
332
 
289
333
  if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) {
290
334
  input = fetch(input);
291
335
  }
292
336
 
293
- initMemory(imports);
337
+ __wbg_init_memory(imports);
294
338
 
295
- const { instance, module } = await load(await input, imports);
339
+ const { instance, module } = await __wbg_load(await input, imports);
296
340
 
297
- return finalizeInit(instance, module);
341
+ return __wbg_finalize_init(instance, module);
298
342
  }
299
343
 
300
344
  export { initSync }
301
- export default init;
345
+ export default __wbg_init;
Binary file
@@ -6,7 +6,9 @@ export function __wbg_buildcss_free(a: number): void;
6
6
  export function buildcss_new(a: number, b: number): number;
7
7
  export function buildcss_add(a: number, b: number, c: number, d: number, e: number): void;
8
8
  export function buildcss_compile(a: number, b: number): void;
9
- export function __wbindgen_malloc(a: number): number;
10
- export function __wbindgen_realloc(a: number, b: number, c: number): number;
9
+ export function __wbindgen_free(a: number, b: number, c: number): void;
10
+ export function __wbindgen_malloc(a: number, b: number): number;
11
+ export function __wbindgen_realloc(a: number, b: number, c: number, d: number): number;
11
12
  export function __wbindgen_add_to_stack_pointer(a: number): number;
13
+ export function __wbindgen_exn_store(a: number): void;
12
14
  export function __wbindgen_start(): void;