x_ite 8.3.2 → 8.4.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 (117) hide show
  1. package/.github/workflows/pages-deploy.yml +1 -1
  2. package/.vscode/settings.json +2 -1
  3. package/dist/LICENSE.md +4 -4
  4. package/dist/assets/components/Annotation.js +13 -13
  5. package/dist/assets/components/Annotation.min.js +1 -1
  6. package/dist/assets/components/CADGeometry.js +13 -13
  7. package/dist/assets/components/CADGeometry.min.js +1 -1
  8. package/dist/assets/components/CubeMapTexturing.js +25 -25
  9. package/dist/assets/components/CubeMapTexturing.min.js +1 -1
  10. package/dist/assets/components/DIS.js +13 -13
  11. package/dist/assets/components/DIS.min.js +1 -1
  12. package/dist/assets/components/EventUtilities.js +9 -9
  13. package/dist/assets/components/EventUtilities.min.js +1 -1
  14. package/dist/assets/components/Geometry2D.js +19 -19
  15. package/dist/assets/components/Geometry2D.min.js +1 -1
  16. package/dist/assets/components/Geospatial.js +33 -33
  17. package/dist/assets/components/Geospatial.min.js +1 -1
  18. package/dist/assets/components/HAnim.js +64 -75
  19. package/dist/assets/components/HAnim.min.js +1 -1
  20. package/dist/assets/components/KeyDeviceSensor.js +8 -8
  21. package/dist/assets/components/KeyDeviceSensor.min.js +1 -1
  22. package/dist/assets/components/Layout.js +27 -27
  23. package/dist/assets/components/Layout.min.js +1 -1
  24. package/dist/assets/components/NURBS.js +24 -24
  25. package/dist/assets/components/NURBS.min.js +1 -1
  26. package/dist/assets/components/ParticleSystems.js +23 -23
  27. package/dist/assets/components/ParticleSystems.min.js +1 -1
  28. package/dist/assets/components/Picking.js +19 -19
  29. package/dist/assets/components/Picking.min.js +1 -1
  30. package/dist/assets/components/RigidBodyPhysics.js +17 -17
  31. package/dist/assets/components/RigidBodyPhysics.min.js +1 -1
  32. package/dist/assets/components/Scripting.js +28 -28
  33. package/dist/assets/components/Scripting.min.js +1 -1
  34. package/dist/assets/components/Text.js +24 -24
  35. package/dist/assets/components/Text.min.js +1 -1
  36. package/dist/assets/components/{ProjectiveTextureMapping.js → TextureProjector.js} +39 -39
  37. package/dist/assets/components/TextureProjector.min.js +1 -0
  38. package/dist/assets/components/Texturing3D.js +27 -27
  39. package/dist/assets/components/Texturing3D.min.js +1 -1
  40. package/dist/assets/components/VolumeRendering.js +19 -19
  41. package/dist/assets/components/VolumeRendering.min.js +1 -1
  42. package/dist/assets/components/X_ITE.js +9 -9
  43. package/dist/assets/components/X_ITE.min.js +1 -1
  44. package/dist/x_ite.css +1 -1
  45. package/dist/x_ite.js +3986 -1366
  46. package/dist/x_ite.min.js +1 -1
  47. package/dist/x_ite.zip +0 -0
  48. package/docs/Gemfile +1 -4
  49. package/docs/_config.yml +3 -3
  50. package/docs/_posts/getting-started.md +147 -441
  51. package/docs/_posts/reference/field-services-and-objects.md +24 -4
  52. package/docs/_posts/reference/prototype-services.md +24 -4
  53. package/docs/_posts/reference/scene-services.md +18 -2
  54. package/docs/_posts/what's-new.md +32 -4
  55. package/docs/_tabs/playground.html +36 -40
  56. package/docs/assets/css/style.scss +18 -0
  57. package/package.json +1 -1
  58. package/src/assets/components/{ProjectiveTextureMapping.js → TextureProjector.js} +5 -5
  59. package/src/examples.js +1 -1
  60. package/src/tests.js +5 -5
  61. package/src/x_ite/Base/X3DInfoArray.js +45 -19
  62. package/src/x_ite/Base/X3DObject.js +29 -20
  63. package/src/x_ite/Base/X3DObjectArrayField.js +71 -26
  64. package/src/x_ite/Base/X3DTypedArrayField.js +108 -32
  65. package/src/x_ite/Browser/DOMIntegration.js +4 -3
  66. package/src/x_ite/Browser/VERSION.js +1 -1
  67. package/src/x_ite/Browser/X3DBrowser.js +43 -28
  68. package/src/x_ite/Components/Core/X3DNode.js +682 -210
  69. package/src/x_ite/Components/Core/X3DPrototypeInstance.js +484 -100
  70. package/src/x_ite/Components/Grouping/X3DTransformMatrix3DNode.js +18 -43
  71. package/src/x_ite/Components/HAnim/HAnimHumanoid.js +27 -26
  72. package/src/x_ite/Components/HAnim/HAnimJoint.js +19 -31
  73. package/src/x_ite/Components/Rendering/X3DGeometryNode.js +6 -3
  74. package/src/x_ite/Components/Sound/X3DSoundProcessingNode.js +14 -1
  75. package/src/x_ite/Components/Sound/X3DSoundSourceNode.js +0 -1
  76. package/src/x_ite/Components/{ProjectiveTextureMapping → TextureProjector}/TextureProjector.js +1 -1
  77. package/src/x_ite/Components/{ProjectiveTextureMapping → TextureProjector}/TextureProjectorParallel.js +1 -1
  78. package/src/x_ite/Components/{ProjectiveTextureMapping → TextureProjector}/X3DTextureProjectorNode.js +0 -0
  79. package/src/x_ite/Components/Time/TimeSensor.js +5 -0
  80. package/src/x_ite/Components/Time/X3DTimeDependentNode.js +1 -0
  81. package/src/x_ite/Configuration/ComponentInfo.js +51 -22
  82. package/src/x_ite/Configuration/ProfileInfo.js +10 -6
  83. package/src/x_ite/Configuration/SupportedComponents.js +22 -20
  84. package/src/x_ite/Configuration/SupportedProfiles.js +1 -1
  85. package/src/x_ite/Configuration/UnitInfo.js +69 -26
  86. package/src/x_ite/Execution/X3DExecutionContext.js +78 -55
  87. package/src/x_ite/Execution/X3DExportedNode.js +75 -28
  88. package/src/x_ite/Execution/X3DImportedNode.js +227 -67
  89. package/src/x_ite/Execution/X3DScene.js +437 -117
  90. package/src/x_ite/Fields/ArrayFields.js +105 -55
  91. package/src/x_ite/Fields/SFBool.js +14 -6
  92. package/src/x_ite/Fields/SFColor.js +35 -12
  93. package/src/x_ite/Fields/SFColorRGBA.js +2 -0
  94. package/src/x_ite/Fields/SFDouble.js +17 -10
  95. package/src/x_ite/Fields/SFFloat.js +17 -10
  96. package/src/x_ite/Fields/SFImage.js +93 -8
  97. package/src/x_ite/Fields/SFInt32.js +14 -6
  98. package/src/x_ite/Fields/SFMatrixPrototypeTemplate.js +38 -13
  99. package/src/x_ite/Fields/SFNode.js +59 -21
  100. package/src/x_ite/Fields/SFRotation.js +38 -13
  101. package/src/x_ite/Fields/SFString.js +14 -7
  102. package/src/x_ite/Fields/SFTime.js +14 -6
  103. package/src/x_ite/Fields/SFVecPrototypeTemplate.js +39 -13
  104. package/src/x_ite/InputOutput/FileLoader.js +1 -1
  105. package/src/x_ite/InputOutput/Generator.js +178 -17
  106. package/src/x_ite/Parser/JSONParser.js +1 -1
  107. package/src/x_ite/Parser/VRMLParser.js +24 -27
  108. package/src/x_ite/Parser/X3DParser.js +0 -4
  109. package/src/x_ite/Parser/XMLParser.js +2 -2
  110. package/src/x_ite/Prototype/X3DExternProtoDeclaration.js +182 -64
  111. package/src/x_ite/Prototype/X3DProtoDeclaration.js +314 -93
  112. package/src/x_ite/Rendering/X3DRenderObject.js +6 -1
  113. package/src/x_ite/Routing/X3DRoute.js +104 -40
  114. package/src/x_ite.html +1 -1
  115. package/x_ite.min.html +1 -1
  116. package/dist/assets/components/ProjectiveTextureMapping.min.js +0 -1
  117. package/docs/Gemfile.lock +0 -116
@@ -45,11 +45,12 @@
45
45
  *
46
46
  ******************************************************************************/
47
47
 
48
- import X3DField from "../Base/X3DField.js";
49
- import Generator from "../InputOutput/Generator.js";
48
+ import X3DField from "../Base/X3DField.js";
50
49
 
51
50
  function SFMatrixPrototypeTemplate (TypeName, Type, Matrix, SFVec, double)
52
51
  {
52
+ const _formatter = double ? "DoublePrecision" : "Precision";
53
+
53
54
  return Object .assign (Object .create (X3DField .prototype),
54
55
  {
55
56
  [Symbol .iterator]: function* ()
@@ -136,28 +137,52 @@ function SFMatrixPrototypeTemplate (TypeName, Type, Matrix, SFVec, double)
136
137
  {
137
138
  return new SFVec (this .getValue () .multMatrixDir (vector .getValue () .copy ()));
138
139
  },
139
- toStream: function (stream)
140
+ toStream: function (generator)
140
141
  {
141
142
  const
142
- generator = Generator .Get (stream),
143
- value = this .getValue (),
144
- last = value .length - 1;
143
+ value = this .getValue (),
144
+ last = value .length - 1;
145
145
 
146
146
  for (let i = 0; i < last; ++ i)
147
147
  {
148
- stream .string += double ? generator .DoublePrecision (value [i]) : generator .Precision (value [i]);
149
- stream .string += " ";
148
+ generator .string += generator [_formatter] (value [i]);
149
+ generator .string += generator .TidySpace ();
150
150
  }
151
151
 
152
- stream .string += double ? generator .DoublePrecision (value [last]) : generator .Precision (value [last]);
152
+ generator .string += generator [_formatter] (value [last]);
153
+ },
154
+ toVRMLStream: function (generator)
155
+ {
156
+ this .toStream (generator);
153
157
  },
154
- toVRMLStream: function (stream)
158
+ toXMLStream: function (generator)
155
159
  {
156
- this .toStream (stream);
160
+ this .toStream (generator);
161
+ },
162
+ toJSONStream: function (generator)
163
+ {
164
+ generator .string += '[';
165
+ generator .string += generator .TidySpace ();
166
+
167
+ this .toJSONStreamValue (generator);
168
+
169
+ generator .string += generator .TidySpace ();
170
+ generator .string += ']';
157
171
  },
158
- toXMLStream: function (stream)
172
+ toJSONStreamValue: function (generator)
159
173
  {
160
- this .toStream (stream);
174
+ const
175
+ value = this .getValue (),
176
+ last = value .length - 1;
177
+
178
+ for (let i = 0; i < last; ++ i)
179
+ {
180
+ generator .string += generator .JSONNumber (generator [_formatter] (value [i]));
181
+ generator .string += ',';
182
+ generator .string += generator .TidySpace ();
183
+ }
184
+
185
+ generator .string += generator .JSONNumber (generator [_formatter] (value [last]));
161
186
  },
162
187
  });
163
188
  }
@@ -372,54 +372,92 @@ SFNode .prototype = Object .assign (Object .create (X3DField .prototype),
372
372
 
373
373
  return null;
374
374
  },
375
- toStream: function (stream)
375
+ toVRMLString: function (options = Object .prototype)
376
+ {
377
+ const
378
+ generator = new Generator (options),
379
+ value = this .getValue ();
380
+
381
+ if (value)
382
+ generator .PushExecutionContext (value .getExecutionContext ());
383
+
384
+ this .toVRMLStream (generator);
385
+
386
+ return generator .string;
387
+ },
388
+ toXMLString: function (options = Object .prototype)
389
+ {
390
+ const
391
+ generator = new Generator (options),
392
+ value = this .getValue ();
393
+
394
+ if (value)
395
+ generator .PushExecutionContext (value .getExecutionContext ());
396
+
397
+ this .toXMLStream (generator);
398
+
399
+ return generator .string;
400
+ },
401
+ toJSONString: function (options = Object .prototype)
402
+ {
403
+ const
404
+ generator = new Generator (options),
405
+ value = this .getValue ();
406
+
407
+ if (value)
408
+ generator .PushExecutionContext (value .getExecutionContext ());
409
+
410
+ this .toJSONStream (generator);
411
+
412
+ return generator .string;
413
+ },
414
+ toStream: function (generator)
376
415
  {
377
416
  const
378
417
  target = this [_target],
379
418
  value = target .getValue ();
380
419
 
381
420
  if (value)
382
- value .toStream (stream);
421
+ value .toStream (generator);
383
422
  else
384
- stream .string += "NULL";
423
+ generator .string += "NULL";
385
424
  },
386
- toVRMLStream: function (stream)
425
+ toVRMLStream: function (generator)
387
426
  {
388
427
  const
389
428
  target = this [_target],
390
429
  value = target .getValue ();
391
430
 
392
431
  if (value)
393
- value .toVRMLStream (stream);
432
+ value .toVRMLStream (generator);
394
433
  else
395
- stream .string += "NULL";
434
+ generator .string += "NULL";
396
435
  },
397
- toXMLString: function ()
436
+ toXMLStream: function (generator)
398
437
  {
399
438
  const
400
- target = this [_target],
401
- stream = { string: "" },
402
- generator = Generator .Get (stream),
403
- value = target .getValue ();
404
-
405
- generator .PushExecutionContext (value .getExecutionContext ());
406
-
407
- target .toXMLStream (stream);
408
-
409
- generator .PopExecutionContext ();
439
+ target = this [_target],
440
+ value = target .getValue ();
410
441
 
411
- return stream .string;
442
+ if (value)
443
+ value .toXMLStream (generator);
444
+ else
445
+ generator .string += "<!-- NULL -->";
446
+ },
447
+ toJSONStream: function (generator)
448
+ {
449
+ this .toJSONStreamValue (generator);
412
450
  },
413
- toXMLStream: function (stream)
451
+ toJSONStreamValue: function (generator)
414
452
  {
415
453
  const
416
454
  target = this [_target],
417
455
  value = target .getValue ();
418
456
 
419
457
  if (value)
420
- value .toXMLStream (stream);
458
+ value .toJSONStream (generator);
421
459
  else
422
- stream .string += "<!-- NULL -->";
460
+ generator .string += "null";
423
461
  },
424
462
  dispose: function ()
425
463
  {
@@ -49,7 +49,6 @@ import X3DField from "../Base/X3DField.js";
49
49
  import SFVec3 from "./SFVec3.js";
50
50
  import SFMatrix3 from "./SFMatrix3.js";
51
51
  import X3DConstants from "../Base/X3DConstants.js";
52
- import Generator from "../InputOutput/Generator.js";
53
52
  import Rotation4 from "../../standard/Math/Numbers/Rotation4.js";
54
53
  import Matrix3 from "../../standard/Math/Numbers/Matrix3.js";
55
54
 
@@ -153,24 +152,50 @@ SFRotation .prototype = Object .assign (Object .create (X3DField .prototype),
153
152
  {
154
153
  return new SFRotation (Rotation4 .slerp (this .getValue (), rotation .getValue (), t));
155
154
  },
156
- toStream: function (stream)
155
+ toStream: function (generator)
157
156
  {
158
- const
159
- generator = Generator .Get (stream),
160
- rotation = this .getValue ();
157
+ const rotation = this .getValue ();
161
158
 
162
- stream .string += generator .DoublePrecision (rotation .x) + " " +
163
- generator .DoublePrecision (rotation .y) + " " +
164
- generator .DoublePrecision (rotation .z) + " " +
165
- generator .DoublePrecision (generator .ToUnit ("angle", rotation .angle));
159
+ generator .string += generator .DoublePrecision (rotation .x);
160
+ generator .string += generator .TidySpace ();
161
+ generator .string += generator .DoublePrecision (rotation .y);
162
+ generator .string += generator .TidySpace ();
163
+ generator .string += generator .DoublePrecision (rotation .z);
164
+ generator .string += generator .TidySpace ();
165
+ generator .string += generator .DoublePrecision (generator .ToUnit ("angle", rotation .angle));
166
166
  },
167
- toVRMLStream: function (stream)
167
+ toVRMLStream: function (generator)
168
168
  {
169
- this .toStream (stream);
169
+ this .toStream (generator);
170
170
  },
171
- toXMLStream: function (stream)
171
+ toXMLStream: function (generator)
172
172
  {
173
- this .toStream (stream);
173
+ this .toStream (generator);
174
+ },
175
+ toJSONStream: function (generator)
176
+ {
177
+ generator .string += '[';
178
+ generator .string += generator .TidySpace ();
179
+
180
+ this .toJSONStreamValue (generator);
181
+
182
+ generator .string += generator .TidySpace ();
183
+ generator .string += ']';
184
+ },
185
+ toJSONStreamValue: function (generator)
186
+ {
187
+ const rotation = this .getValue ();
188
+
189
+ generator .string += generator .JSONNumber (generator .DoublePrecision (rotation .x));
190
+ generator .string += ',';
191
+ generator .string += generator .TidySpace ();
192
+ generator .string += generator .JSONNumber (generator .DoublePrecision (rotation .y));
193
+ generator .string += ',';
194
+ generator .string += generator .TidySpace ();
195
+ generator .string += generator .JSONNumber (generator .DoublePrecision (rotation .z));
196
+ generator .string += ',';
197
+ generator .string += generator .TidySpace ();
198
+ generator .string += generator .JSONNumber (generator .DoublePrecision (generator .ToUnit ("angle", rotation .angle)));
174
199
  },
175
200
  });
176
201
 
@@ -47,7 +47,6 @@
47
47
 
48
48
  import X3DField from "../Base/X3DField.js";
49
49
  import X3DConstants from "../Base/X3DConstants.js";
50
- import Generator from "../InputOutput/Generator.js";
51
50
 
52
51
  const
53
52
  unescape = /\\(.)/g,
@@ -98,17 +97,25 @@ SFString .prototype = Object .assign (Object .create (X3DField .prototype),
98
97
  X3DField .prototype .set .call (this, "" + value);
99
98
  },
100
99
  valueOf: X3DField .prototype .getValue,
101
- toStream: function (stream)
100
+ toStream: function (generator)
102
101
  {
103
- stream .string += '"' + SFString .escape (this .getValue ()) + '"';
102
+ generator .string += '"' + SFString .escape (this .getValue ()) + '"';
104
103
  },
105
- toVRMLStream: function (stream)
104
+ toVRMLStream: function (generator)
106
105
  {
107
- this .toStream (stream);
106
+ this .toStream (generator);
108
107
  },
109
- toXMLStream: function (stream)
108
+ toXMLStream: function (generator)
110
109
  {
111
- stream .string += Generator .Get (stream) .XMLEncode (this .getValue ());
110
+ generator .string += generator .XMLEncode (this .getValue ());
111
+ },
112
+ toJSONStream: function (generator)
113
+ {
114
+ this .toJSONStreamValue (generator)
115
+ },
116
+ toJSONStreamValue: function (generator)
117
+ {
118
+ generator .string += generator .JSONEncode (this .getValue ());
112
119
  },
113
120
  });
114
121
 
@@ -77,17 +77,25 @@ SFTime .prototype = Object .assign (Object .create (X3DField .prototype),
77
77
  X3DField .prototype .set .call (this, +value);
78
78
  },
79
79
  valueOf: X3DField .prototype .getValue,
80
- toStream: function (stream)
80
+ toStream: function (generator)
81
81
  {
82
- stream .string += this .getValue ();
82
+ generator .string += this .getValue ();
83
83
  },
84
- toVRMLStream: function (stream)
84
+ toVRMLStream: function (generator)
85
85
  {
86
- this .toStream (stream);
86
+ this .toStream (generator);
87
87
  },
88
- toXMLStream: function (stream)
88
+ toXMLStream: function (generator)
89
89
  {
90
- this .toStream (stream);
90
+ this .toStream (generator);
91
+ },
92
+ toJSONStream: function (generator)
93
+ {
94
+ this .toJSONStreamValue (generator);
95
+ },
96
+ toJSONStreamValue: function (generator)
97
+ {
98
+ generator .string += generator .JSONNumber (generator .DoublePrecision (this .getValue ()));
91
99
  },
92
100
  });
93
101
 
@@ -46,10 +46,11 @@
46
46
  ******************************************************************************/
47
47
 
48
48
  import X3DField from "../Base/X3DField.js";
49
- import Generator from "../InputOutput/Generator.js";
50
49
 
51
50
  function SFVecPrototypeTemplate (TypeName, Type, ValueType, double)
52
51
  {
52
+ const _formatter = double ? "DoublePrecision" : "Precision";
53
+
53
54
  return Object .assign (Object .create (X3DField .prototype),
54
55
  {
55
56
  [Symbol .iterator]: function* ()
@@ -144,29 +145,54 @@ function SFVecPrototypeTemplate (TypeName, Type, ValueType, double)
144
145
  {
145
146
  return new (this .constructor) (ValueType .subtract (this .getValue (), vector .getValue ()));
146
147
  },
147
- toStream: function (stream)
148
+ toStream: function (generator)
148
149
  {
149
150
  const
150
- generator = Generator .Get (stream),
151
- value = this .getValue (),
152
- category = generator .Unit (this .getUnit ()),
153
- last = value .length - 1;
151
+ value = this .getValue (),
152
+ last = value .length - 1,
153
+ category = generator .Unit (this .getUnit ());
154
154
 
155
155
  for (let i = 0; i < last; ++ i)
156
156
  {
157
- stream .string += double ? generator .DoublePrecision (generator .ToUnit (category, value [i])) : generator .Precision (generator .ToUnit (category, value [i]));
158
- stream .string += " ";
157
+ generator .string += generator [_formatter] (generator .ToUnit (category, value [i]));
158
+ generator .string += generator .TidySpace ();
159
159
  }
160
160
 
161
- stream .string += double ? generator .DoublePrecision (generator .ToUnit (category, value [last])) : generator .Precision (generator .ToUnit (category, value [last]));
161
+ generator .string += generator [_formatter] (generator .ToUnit (category, value [last]));
162
+ },
163
+ toVRMLStream: function (generator)
164
+ {
165
+ this .toStream (generator);
162
166
  },
163
- toVRMLStream: function (stream)
167
+ toXMLStream: function (generator)
164
168
  {
165
- this .toStream (stream);
169
+ this .toStream (generator);
170
+ },
171
+ toJSONStream: function (generator)
172
+ {
173
+ generator .string += '[';
174
+ generator .string += generator .TidySpace ();
175
+
176
+ this .toJSONStreamValue (generator);
177
+
178
+ generator .string += generator .TidySpace ();
179
+ generator .string += ']';
166
180
  },
167
- toXMLStream: function (stream)
181
+ toJSONStreamValue: function (generator)
168
182
  {
169
- this .toStream (stream);
183
+ const
184
+ value = this .getValue (),
185
+ last = value .length - 1,
186
+ category = generator .Unit (this .getUnit ());
187
+
188
+ for (let i = 0; i < last; ++ i)
189
+ {
190
+ generator .string += generator .JSONNumber (generator [_formatter] (generator .ToUnit (category, value [i])));
191
+ generator .string += ',';
192
+ generator .string += generator .TidySpace ();
193
+ }
194
+
195
+ generator .string += generator .JSONNumber (generator [_formatter] (generator .ToUnit (category, value [last])));
170
196
  },
171
197
  });
172
198
  }
@@ -101,7 +101,7 @@ FileLoader .prototype = Object .assign (Object .create (X3DObject .prototype),
101
101
  {
102
102
  return this .URL;
103
103
  },
104
- createX3DFromString: function (worldURL, string, success, error)
104
+ createX3DFromString: function (worldURL, string = "", success, error)
105
105
  {
106
106
  try
107
107
  {
@@ -47,13 +47,16 @@
47
47
 
48
48
  import X3DConstants from "../Base/X3DConstants.js";
49
49
 
50
- function Generator ()
50
+ function Generator ({ style = "TIDY", precision = 6, doublePrecision = 14 })
51
51
  {
52
+ this .Style (style);
53
+
54
+ this .string = "";
52
55
  this .indent = "";
53
- this .indentChar = " ";
54
- this .precision = 6;
55
- this .doublePrecision = 14;
56
- this .removeTrailingZeros = /\.?0*(?=$|[eE])/;
56
+ this .listIndent = "";
57
+ this .precision = precision;
58
+ this .doublePrecision = doublePrecision;
59
+ this .removeTrailingZeros = /(?:\.|(\.[0-9]*?))0*(?=[eE]|$)/;
57
60
 
58
61
  this .executionContextStack = [ null ];
59
62
  this .importedNodesIndex = new Map ();
@@ -75,17 +78,126 @@ function Generator ()
75
78
  Generator .prototype =
76
79
  {
77
80
  constructor: Generator,
81
+ Style: function (style)
82
+ {
83
+ switch (style)
84
+ {
85
+ case "CLEAN":
86
+ {
87
+ this .comma = " ";
88
+ this .break = " ";
89
+ this .tidyBreak = "";
90
+ this .tidySpace = "";
91
+ this .indentChar = "";
92
+ this .listEnclosure = "";
93
+ this .listBreak = "";
94
+ this .listIndentChar = "";
95
+ this .attribBreak = " ";
96
+ break;
97
+ }
98
+ case "SMALL":
99
+ {
100
+ this .comma = ",";
101
+ this .break = "\n";
102
+ this .tidyBreak = "\n";
103
+ this .tidySpace = "";
104
+ this .indentChar = "";
105
+ this .listEnclosure = "";
106
+ this .listBreak = "";
107
+ this .listIndentChar = "";
108
+ this .attribBreak = " ";
109
+ break;
110
+ }
111
+ case "COMPACT":
112
+ {
113
+ this .comma = ",";
114
+ this .break = "\n";
115
+ this .tidyBreak = "\n";
116
+ this .tidySpace = " ";
117
+ this .indentChar = " ";
118
+ this .listEnclosure = " ";
119
+ this .listBreak = " ";
120
+ this .listIndentChar = "";
121
+ this .attribBreak = " ";
122
+ break;
123
+ }
124
+ case "TIDY":
125
+ default:
126
+ {
127
+ this .comma = ",";
128
+ this .break = "\n";
129
+ this .tidyBreak = "\n";
130
+ this .tidySpace = " ";
131
+ this .indentChar = " ";
132
+ this .listEnclosure = "\n";
133
+ this .listBreak = "\n";
134
+ this .listIndentChar = " ";
135
+ this .attribBreak = "\n";
136
+ break;
137
+ }
138
+ }
139
+ },
140
+ Comma: function ()
141
+ {
142
+ return this .comma;
143
+ },
144
+ Break: function ()
145
+ {
146
+ return this .break;
147
+ },
148
+ TidyBreak: function ()
149
+ {
150
+ return this .tidyBreak;
151
+ },
152
+ ForceBreak: function ()
153
+ {
154
+ return "\n";
155
+ },
156
+ Space: function ()
157
+ {
158
+ return " ";
159
+ },
160
+ TidySpace: function ()
161
+ {
162
+ return this .tidySpace;
163
+ },
164
+ ListStart: function ()
165
+ {
166
+ return this .listEnclosure;
167
+ },
168
+ ListEnd: function ()
169
+ {
170
+ return this .listEnclosure;
171
+ },
172
+ ListBreak: function ()
173
+ {
174
+ return this .listBreak;
175
+ },
176
+ AttribBreak: function ()
177
+ {
178
+ return this .attribBreak;
179
+ },
78
180
  Indent: function ()
79
181
  {
80
182
  return this .indent;
81
183
  },
184
+ ListIndent: function ()
185
+ {
186
+ return this .listIndent;
187
+ },
82
188
  IncIndent: function ()
83
189
  {
84
- this .indent += this .indentChar;
190
+ this .indent += this .indentChar;
191
+ this .listIndent += this .listIndentChar;
192
+
193
+ return "";
85
194
  },
86
195
  DecIndent: function ()
87
196
  {
88
- this .indent = this .indent .substr (0, this .indent .length - this .indentChar .length);
197
+ this .indent = this .indent .slice (0, this .indent .length - this .indentChar .length);
198
+ this .listIndent = this .listIndent .slice (0, this .listIndent .length - this .listIndentChar .length);
199
+
200
+ return "";
89
201
  },
90
202
  PadRight: function (string, pad)
91
203
  {
@@ -96,11 +208,11 @@ Generator .prototype =
96
208
  },
97
209
  Precision: function (value)
98
210
  {
99
- return Math .fround (value) .toPrecision (this .precision) .replace (this .removeTrailingZeros, "");
211
+ return Math .fround (value) .toPrecision (this .precision) .replace (this .removeTrailingZeros, "$1");
100
212
  },
101
213
  DoublePrecision: function (value)
102
214
  {
103
- return value .toPrecision (this .doublePrecision) .replace (this .removeTrailingZeros, "");
215
+ return value .toPrecision (this .doublePrecision) .replace (this .removeTrailingZeros, "$1");
104
216
  },
105
217
  PushExecutionContext: function (executionContext)
106
218
  {
@@ -411,17 +523,66 @@ Generator .prototype =
411
523
  {
412
524
  return string .replace (/\]\]\>/g, "\\]\\]\\>");
413
525
  },
414
- };
526
+ JSONEncode: function (string)
527
+ {
528
+ let result = '"';
415
529
 
416
- for (const key of Reflect .ownKeys (Generator .prototype))
417
- Object .defineProperty (Generator .prototype, key, { enumerable: false });
530
+ for (const character of string)
531
+ {
532
+ switch (character)
533
+ {
534
+ case '\r':
535
+ {
536
+ result += "\\r";
537
+ break;
538
+ }
539
+ case '\n':
540
+ {
541
+ result += "\\n";
542
+ break;
543
+ }
544
+ case '\t':
545
+ {
546
+ result += "\\t";
547
+ break;
548
+ }
549
+ case '"':
550
+ {
551
+ result += "\\\"";
552
+ break;
553
+ }
554
+ case '\\':
555
+ {
556
+ result += "\\\\";
557
+ break;
558
+ }
559
+ default:
560
+ {
561
+ result += character;
562
+ break;
563
+ }
564
+ }
565
+ }
418
566
 
419
- Generator .Get = function (stream)
420
- {
421
- if (! stream .generator)
422
- stream .generator = new Generator ();
567
+ result += '"';
423
568
 
424
- return stream .generator;
569
+ return result;
570
+ },
571
+ JSONNumber: function (value)
572
+ {
573
+ switch (value)
574
+ {
575
+ case "NaN":
576
+ case "Infinity":
577
+ case "-Infinity":
578
+ return '"' + value + '"';
579
+ default:
580
+ return value;
581
+ }
582
+ },
425
583
  };
426
584
 
585
+ for (const key of Reflect .ownKeys (Generator .prototype))
586
+ Object .defineProperty (Generator .prototype, key, { enumerable: false });
587
+
427
588
  export default Generator;
@@ -73,7 +73,7 @@ JSONParser .prototype = Object .assign (Object .create (X3DParser .prototype),
73
73
  try
74
74
  {
75
75
  if (typeof json === "string")
76
- json = JSON .parse (json)
76
+ json = JSON .parse (json);
77
77
 
78
78
  this .input = json;
79
79
  }