x3d-tidy 3.0.2 → 3.0.4

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 (2) hide show
  1. package/package.json +3 -3
  2. package/src/infer.js +30 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x3d-tidy",
3
- "version": "3.0.2",
3
+ "version": "3.0.4",
4
4
  "description": "X3D Converter, Beautifier and Minimizer",
5
5
  "main": "src/main.js",
6
6
  "bin": {
@@ -58,8 +58,8 @@
58
58
  },
59
59
  "dependencies": {
60
60
  "colors": "^1.4.0",
61
- "x_ite": "^14.0.2",
62
- "x_ite-node": "^2.0.2",
61
+ "x_ite": "^14.0.4",
62
+ "x_ite-node": "^2.0.4",
63
63
  "x3d-traverse": "^1.0.22",
64
64
  "yargs": "^18.0.0"
65
65
  },
package/src/infer.js CHANGED
@@ -17,16 +17,19 @@ module .exports = function inferProfileAndComponents (scene)
17
17
 
18
18
  function getUsedComponents (scene)
19
19
  {
20
- const components = new Set ();
20
+ const components = new Map ();
21
21
 
22
22
  for (const object of scene .traverse (Traverse .PROTO_DECLARATIONS | Traverse .PROTO_DECLARATION_BODY | Traverse .ROOT_NODES | Traverse .PROTOTYPE_INSTANCES))
23
23
  {
24
24
  if (!(object instanceof X3D .SFNode))
25
25
  continue;
26
26
 
27
- const node = object .getValue ();
27
+ const
28
+ node = object .getValue (),
29
+ componentInfo = node .getComponentInfo ();
28
30
 
29
- components .add (node .getComponentInfo () .name);
31
+ if (components .get (componentInfo .name) ?? 0 < componentInfo .level)
32
+ components .set (componentInfo .name, componentInfo .level);
30
33
  }
31
34
 
32
35
  return components;
@@ -34,31 +37,46 @@ function getUsedComponents (scene)
34
37
 
35
38
  function getProfileAndComponentsFromUsedComponents (browser, usedComponents)
36
39
  {
37
- const profiles = ["Interactive", "Interchange", "Immersive"] .map (name =>
40
+ const profiles = ["Interchange", "Interactive", "Immersive", "Full"] .map (name =>
38
41
  {
39
- return { profile: browser .getProfile (name), components: new Set (usedComponents) };
42
+ return { profile: browser .getProfile (name), components: new Map (usedComponents) };
40
43
  });
41
44
 
42
- profiles .forEach (object =>
45
+ profiles .forEach (({ profile, components }) =>
43
46
  {
44
- for (const component of object .profile .components)
45
- object .components .delete (component .name);
47
+ for (const component of profile .components)
48
+ {
49
+ const level = components .get (component .name);
50
+
51
+ if (level === undefined)
52
+ continue;
53
+
54
+ if (level > component .level)
55
+ continue;
56
+
57
+ components .delete (component .name);
58
+ }
46
59
  });
47
60
 
48
61
  const min = profiles .reduce ((min, object) =>
49
62
  {
50
- const count = object .profile .components .length + object .components .size;
63
+ const count = new Set ([
64
+ ... [... object .profile .components] .map (component => component .name),
65
+ ... object .components .keys ()
66
+ ]) .size;
51
67
 
52
68
  return min .count < count ? min : {
53
- count: count,
54
- object: object,
69
+ count,
70
+ object,
55
71
  };
56
72
  },
57
73
  { count: Number .POSITIVE_INFINITY });
58
74
 
59
75
  return {
60
76
  profile: min .object .profile,
61
- components: Array .from (min .object .components) .sort () .map (name => browser .getSupportedComponents () .get (name)),
77
+ components: Array .from (min .object .components .keys ())
78
+ .sort ()
79
+ .map (name => browser .getComponent (name)),
62
80
  };
63
81
  }
64
82