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.
- package/package.json +3 -3
- 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.
|
|
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.
|
|
62
|
-
"x_ite-node": "^2.0.
|
|
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
|
|
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
|
|
27
|
+
const
|
|
28
|
+
node = object .getValue (),
|
|
29
|
+
componentInfo = node .getComponentInfo ();
|
|
28
30
|
|
|
29
|
-
components .
|
|
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 = ["
|
|
40
|
+
const profiles = ["Interchange", "Interactive", "Immersive", "Full"] .map (name =>
|
|
38
41
|
{
|
|
39
|
-
return { profile: browser .getProfile (name), components: new
|
|
42
|
+
return { profile: browser .getProfile (name), components: new Map (usedComponents) };
|
|
40
43
|
});
|
|
41
44
|
|
|
42
|
-
profiles .forEach (
|
|
45
|
+
profiles .forEach (({ profile, components }) =>
|
|
43
46
|
{
|
|
44
|
-
for (const component of
|
|
45
|
-
|
|
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 =
|
|
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
|
|
54
|
-
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
|
|
77
|
+
components: Array .from (min .object .components .keys ())
|
|
78
|
+
.sort ()
|
|
79
|
+
.map (name => browser .getComponent (name)),
|
|
62
80
|
};
|
|
63
81
|
}
|
|
64
82
|
|