@inweb/viewer-three 27.1.0 → 27.1.2

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 (85) hide show
  1. package/dist/extensions/components/AxesHelperComponent.js +12 -11
  2. package/dist/extensions/components/AxesHelperComponent.js.map +1 -1
  3. package/dist/extensions/components/AxesHelperComponent.min.js +1 -1
  4. package/dist/extensions/components/AxesHelperComponent.module.js +12 -11
  5. package/dist/extensions/components/AxesHelperComponent.module.js.map +1 -1
  6. package/dist/extensions/components/GridHelperComponent.js +4 -6
  7. package/dist/extensions/components/GridHelperComponent.js.map +1 -1
  8. package/dist/extensions/components/GridHelperComponent.min.js +1 -1
  9. package/dist/extensions/components/GridHelperComponent.module.js +4 -6
  10. package/dist/extensions/components/GridHelperComponent.module.js.map +1 -1
  11. package/dist/extensions/components/InfoPanelComponent.js +7 -9
  12. package/dist/extensions/components/InfoPanelComponent.js.map +1 -1
  13. package/dist/extensions/components/InfoPanelComponent.min.js +1 -1
  14. package/dist/extensions/components/InfoPanelComponent.module.js +7 -9
  15. package/dist/extensions/components/InfoPanelComponent.module.js.map +1 -1
  16. package/dist/extensions/components/LightHelperComponent.js +5 -5
  17. package/dist/extensions/components/LightHelperComponent.js.map +1 -1
  18. package/dist/extensions/components/LightHelperComponent.min.js +1 -1
  19. package/dist/extensions/components/LightHelperComponent.module.js +6 -6
  20. package/dist/extensions/components/LightHelperComponent.module.js.map +1 -1
  21. package/dist/extensions/loaders/GLTFCloudLoader.js +1 -1
  22. package/dist/extensions/loaders/GLTFCloudLoader.js.map +1 -1
  23. package/dist/extensions/loaders/GLTFCloudLoader.min.js +1 -1
  24. package/dist/extensions/loaders/GLTFCloudLoader.module.js +1 -1
  25. package/dist/extensions/loaders/GLTFCloudLoader.module.js.map +1 -1
  26. package/dist/extensions/loaders/GLTFFileLoader.js +1 -1
  27. package/dist/extensions/loaders/GLTFFileLoader.js.map +1 -1
  28. package/dist/extensions/loaders/GLTFFileLoader.min.js +1 -1
  29. package/dist/extensions/loaders/GLTFFileLoader.module.js +1 -1
  30. package/dist/extensions/loaders/GLTFFileLoader.module.js.map +1 -1
  31. package/dist/extensions/loaders/IFCXLoader.js +2 -2
  32. package/dist/extensions/loaders/IFCXLoader.js.map +1 -1
  33. package/dist/extensions/loaders/IFCXLoader.min.js +1 -1
  34. package/dist/extensions/loaders/IFCXLoader.module.js +2 -2
  35. package/dist/extensions/loaders/IFCXLoader.module.js.map +1 -1
  36. package/dist/extensions/loaders/PotreeLoader.js +1 -1
  37. package/dist/extensions/loaders/PotreeLoader.js.map +1 -1
  38. package/dist/extensions/loaders/PotreeLoader.min.js +1 -1
  39. package/dist/extensions/loaders/PotreeLoader.module.js +1 -1
  40. package/dist/extensions/loaders/PotreeLoader.module.js.map +1 -1
  41. package/dist/viewer-three.js +1379 -104
  42. package/dist/viewer-three.js.map +1 -1
  43. package/dist/viewer-three.min.js +4 -4
  44. package/dist/viewer-three.module.js +133 -105
  45. package/dist/viewer-three.module.js.map +1 -1
  46. package/extensions/components/AxesHelperComponent.ts +13 -12
  47. package/extensions/components/GridHelperComponent.ts +4 -6
  48. package/extensions/components/InfoPanelComponent.ts +8 -11
  49. package/extensions/components/LightHelperComponent.ts +6 -6
  50. package/extensions/loaders/GLTFCloudLoader.ts +1 -1
  51. package/extensions/loaders/GLTFFileLoader.ts +1 -1
  52. package/extensions/loaders/IFCX/IFCXCloudLoader.ts +1 -1
  53. package/extensions/loaders/IFCX/IFCXFileLoader.ts +1 -1
  54. package/extensions/loaders/Potree/PotreeFileLoader.ts +1 -1
  55. package/lib/Viewer/Viewer.d.ts +1 -1
  56. package/lib/Viewer/commands/CreatePreview.d.ts +1 -1
  57. package/lib/Viewer/commands/SetDefaultViewPosition.d.ts +1 -1
  58. package/lib/Viewer/components/RenderLoopComponent.d.ts +1 -1
  59. package/lib/Viewer/draggers/FlyDragger.d.ts +1 -0
  60. package/lib/Viewer/draggers/WalkDragger.d.ts +1 -0
  61. package/lib/Viewer/loaders/GLTFBinaryParser.d.ts +11 -0
  62. package/lib/Viewer/loaders/GLTFFileDynamicLoader.d.ts +0 -1
  63. package/lib/Viewer/loaders/JSONStreamParser.d.ts +5 -0
  64. package/lib/Viewer/loaders/index.d.ts +2 -1
  65. package/package.json +7 -5
  66. package/src/Viewer/Viewer.ts +32 -32
  67. package/src/Viewer/commands/CreatePreview.ts +2 -2
  68. package/src/Viewer/commands/SetDefaultViewPosition.ts +3 -3
  69. package/src/Viewer/commands/ZoomTo.ts +6 -6
  70. package/src/Viewer/components/CameraComponent.ts +3 -3
  71. package/src/Viewer/components/InfoComponent.ts +4 -4
  72. package/src/Viewer/components/LightComponent.ts +5 -8
  73. package/src/Viewer/components/RenderLoopComponent.ts +2 -2
  74. package/src/Viewer/components/SelectionComponent.ts +3 -1
  75. package/src/Viewer/draggers/CuttingPlaneDragger.ts +6 -6
  76. package/src/Viewer/draggers/FlyDragger.ts +9 -2
  77. package/src/Viewer/draggers/MeasureLineDragger.ts +10 -7
  78. package/src/Viewer/draggers/WalkDragger.ts +9 -2
  79. package/src/Viewer/loaders/DynamicGltfLoader/GltfStructure.js +7 -1
  80. package/src/Viewer/loaders/{GLTFBinaryExtension.ts → GLTFBinaryParser.ts} +34 -29
  81. package/src/Viewer/loaders/GLTFCloudDynamicLoader.ts +12 -11
  82. package/src/Viewer/loaders/GLTFFileDynamicLoader.ts +11 -10
  83. package/src/Viewer/loaders/JSONStreamParser.ts +38 -0
  84. package/src/Viewer/loaders/index.ts +2 -1
  85. package/lib/Viewer/loaders/GLTFBinaryExtension.d.ts +0 -5
@@ -171,6 +171,11 @@
171
171
  cancel() {
172
172
  this.abortController.abort();
173
173
  }
174
+ yield() {
175
+ return new Promise((resolve) => {
176
+ setTimeout(resolve, 0);
177
+ });
178
+ }
174
179
  extractFileName(file) {
175
180
  const regex = /[^/\\?#:]+(?=\?|#|$)/;
176
181
  if (typeof file === "string")
@@ -33865,7 +33870,7 @@ void main() {
33865
33870
  this.orbit.enabled = !event.value;
33866
33871
  };
33867
33872
  this.updatePlaneSize = () => {
33868
- this.planeHelper.size = this.viewer.extents.getSize(new Vector3()).length();
33873
+ this.planeHelper.size = this.viewer.extents.getSize(new Vector3()).length() || 1;
33869
33874
  this.viewer.update();
33870
33875
  };
33871
33876
  this.updateTransformCamera = () => {
@@ -33876,17 +33881,17 @@ void main() {
33876
33881
  this.plane.negate();
33877
33882
  this.viewer.update();
33878
33883
  };
33879
- const size = viewer.extents.getSize(new Vector3()).length();
33880
- const center = viewer.extents.getCenter(new Vector3());
33881
- const constant = -center.dot(normal);
33884
+ const extentsSize = viewer.extents.getSize(new Vector3()).length() || 1;
33885
+ const extentsCenter = viewer.extents.getCenter(new Vector3());
33886
+ const constant = -extentsCenter.dot(normal);
33882
33887
  this.plane = new Plane(normal, constant);
33883
33888
  if (!viewer.renderer.clippingPlanes)
33884
33889
  viewer.renderer.clippingPlanes = [];
33885
33890
  viewer.renderer.clippingPlanes.push(this.plane);
33886
- this.planeHelper = new PlaneHelper(this.plane, size, color, center);
33891
+ this.planeHelper = new PlaneHelper(this.plane, extentsSize, color, extentsCenter);
33887
33892
  this.viewer.helpers.add(this.planeHelper);
33888
33893
  this.planeCenter = new Object3D();
33889
- this.planeCenter.position.copy(viewer.extents.getCenter(new Vector3()));
33894
+ this.planeCenter.position.copy(extentsCenter);
33890
33895
  this.viewer.helpers.add(this.planeCenter);
33891
33896
  this.transform = new TransformControls(viewer.camera, viewer.canvas);
33892
33897
  this.transform.showX = !!normal.x;
@@ -34197,7 +34202,11 @@ void main() {
34197
34202
  const model = this.viewer.models[0];
34198
34203
  const units = (_a = this.viewer.options.rulerUnit) !== null && _a !== void 0 ? _a : "Default";
34199
34204
  const precision = (_b = this.viewer.options.rulerPrecision) !== null && _b !== void 0 ? _b : "Default";
34200
- if (units === "Default") {
34205
+ if (!model) {
34206
+ this.scale = 1;
34207
+ this.units = "";
34208
+ }
34209
+ else if (units === "Default") {
34201
34210
  this.scale = model.getUnitScale();
34202
34211
  this.units = model.getUnitString();
34203
34212
  }
@@ -34205,20 +34214,21 @@ void main() {
34205
34214
  this.scale = convertUnits(model.getUnits(), units, 1);
34206
34215
  this.units = units;
34207
34216
  }
34208
- if (precision === "Default") {
34217
+ if (!model)
34218
+ this.precision = 2;
34219
+ else if (precision === "Default")
34209
34220
  this.precision = model.getPrecision();
34210
- }
34211
- else {
34221
+ else
34212
34222
  this.precision = precision;
34213
- }
34214
34223
  this.overlay.updateLineUnits(this.scale, this.units, this.precision);
34215
34224
  };
34216
34225
  this.overlay = new MeasureOverlay(viewer.camera, viewer.canvas);
34217
34226
  this.overlay.attach();
34218
34227
  this.line = new MeasureLine(this.overlay, this.scale, this.units, this.precision);
34219
34228
  this.overlay.addLine(this.line);
34229
+ const extentsSize = this.viewer.extents.getSize(new Vector3()).length() || 1;
34220
34230
  this.snapper = new Snapper(viewer.camera, viewer.renderer, viewer.canvas);
34221
- this.snapper.threshold = viewer.extents.getSize(new Vector3()).length() / 10000;
34231
+ this.snapper.threshold = extentsSize / 10000;
34222
34232
  this.objects = [];
34223
34233
  this.updateObjects();
34224
34234
  this.updateUnits();
@@ -34917,7 +34927,7 @@ void main() {
34917
34927
  constructor(viewer) {
34918
34928
  this.updateControls = () => {
34919
34929
  const size = this.viewer.extents.getSize(new Vector3());
34920
- this.controls.movementSpeed = Math.min(size.x, size.y, size.z) / 2;
34930
+ this.controls.movementSpeed = Math.min(size.x, size.y, size.z) / 2 || 1;
34921
34931
  this.joyStickControls.movementSpeed = this.controls.movementSpeed;
34922
34932
  this.joyStickControls.multiplier = this.controls.multiplier;
34923
34933
  };
@@ -34934,11 +34944,13 @@ void main() {
34934
34944
  };
34935
34945
  this.viewerRender = () => {
34936
34946
  this.joyStickControls.update();
34937
- this.controls.update();
34938
34947
  };
34939
34948
  this.viewerZoom = () => {
34940
34949
  this.controls.rotateDelta.set(0, 0);
34941
34950
  };
34951
+ this.animate = () => {
34952
+ this.controls.update();
34953
+ };
34942
34954
  const meshOnlyGround = [];
34943
34955
  viewer.models.forEach((model) => model.getVisibleObjects().forEach((obj) => {
34944
34956
  if (obj instanceof Mesh) {
@@ -34951,12 +34963,14 @@ void main() {
34951
34963
  this.joyStickControls = new JoyStickControls(viewer.camera, viewer.canvas, viewer.canvas, meshOnlyGround);
34952
34964
  this.joyStickControls.addEventListener("change", this.controlsChange);
34953
34965
  this.viewer = viewer;
34966
+ this.viewer.addEventListener("animate", this.animate);
34954
34967
  this.viewer.addEventListener("render", this.viewerRender);
34955
34968
  this.viewer.addEventListener("zoom", this.viewerZoom);
34956
34969
  this.viewer.addEventListener("changecameramode", this.updateControlsCamera);
34957
34970
  this.updateControls();
34958
34971
  }
34959
34972
  dispose() {
34973
+ this.viewer.removeEventListener("animate", this.animate);
34960
34974
  this.viewer.removeEventListener("render", this.viewerRender);
34961
34975
  this.viewer.removeEventListener("zoom", this.viewerZoom);
34962
34976
  this.viewer.removeEventListener("changecameramode", this.updateControlsCamera);
@@ -35119,7 +35133,7 @@ void main() {
35119
35133
  constructor(viewer) {
35120
35134
  this.updateControls = () => {
35121
35135
  const size = this.viewer.extents.getSize(new Vector3());
35122
- this.controls.movementSpeed = Math.min(size.x, size.y, size.z) / 2;
35136
+ this.controls.movementSpeed = Math.min(size.x, size.y, size.z) / 2 || 1;
35123
35137
  this.joyStickControls.movementSpeed = this.controls.movementSpeed;
35124
35138
  this.joyStickControls.multiplier = this.controls.multiplier;
35125
35139
  };
@@ -35136,23 +35150,27 @@ void main() {
35136
35150
  };
35137
35151
  this.viewerRender = () => {
35138
35152
  this.joyStickControls.update();
35139
- this.controls.update();
35140
35153
  };
35141
35154
  this.viewerZoom = () => {
35142
35155
  this.controls.rotateDelta.set(0, 0);
35143
35156
  };
35157
+ this.animate = () => {
35158
+ this.controls.update();
35159
+ };
35144
35160
  this.controls = new FlyControls(viewer.camera, viewer.canvas);
35145
35161
  this.controls.addEventListener("change", this.controlsChange);
35146
35162
  this.controls.addEventListener("flyspeedchange", this.flyspeedChange);
35147
35163
  this.joyStickControls = new JoyStickControls(viewer.camera, viewer.canvas, viewer.canvas, []);
35148
35164
  this.joyStickControls.addEventListener("change", this.controlsChange);
35149
35165
  this.viewer = viewer;
35166
+ this.viewer.addEventListener("animate", this.animate);
35150
35167
  this.viewer.addEventListener("render", this.viewerRender);
35151
35168
  this.viewer.addEventListener("zoom", this.viewerZoom);
35152
35169
  this.viewer.addEventListener("changecameramode", this.updateControlsCamera);
35153
35170
  this.updateControls();
35154
35171
  }
35155
35172
  dispose() {
35173
+ this.viewer.removeEventListener("animate", this.animate);
35156
35174
  this.viewer.removeEventListener("render", this.viewerRender);
35157
35175
  this.viewer.removeEventListener("zoom", this.viewerZoom);
35158
35176
  this.viewer.removeEventListener("changecameramode", this.updateControlsCamera);
@@ -35202,9 +35220,9 @@ void main() {
35202
35220
  viewer.clearSlices();
35203
35221
  }
35204
35222
 
35205
- function createPreview(viewer, type = "image/jpeg", encoderOptions = 0.25) {
35223
+ function createPreview(viewer, type = "image/jpeg", quality = 0.25) {
35206
35224
  viewer.update(true);
35207
- return viewer.canvas.toDataURL(type, encoderOptions);
35225
+ return viewer.canvas.toDataURL(type, quality);
35208
35226
  }
35209
35227
 
35210
35228
  function explode(viewer, index = 0) {
@@ -35220,27 +35238,27 @@ void main() {
35220
35238
  if (box.isEmpty())
35221
35239
  return;
35222
35240
  const boxCenter = box.getCenter(new Vector3());
35223
- const boxSize = box.getBoundingSphere(new Sphere()).radius;
35241
+ const boxSize = box.getSize(new Vector3()).length() || 1;
35224
35242
  const rendererSize = viewer.renderer.getSize(new Vector2());
35225
35243
  const aspectRatio = rendererSize.x / rendererSize.y;
35226
35244
  const camera = viewer.camera;
35227
35245
  if (camera.isPerspectiveCamera) {
35228
35246
  const offset = new Vector3(0, 0, 1)
35229
35247
  .applyQuaternion(camera.quaternion)
35230
- .multiplyScalar(boxSize / Math.tan(MathUtils.degToRad(camera.fov * 0.5)));
35248
+ .multiplyScalar(boxSize / (2 * Math.tan(MathUtils.degToRad(camera.fov * 0.5))));
35231
35249
  camera.position.copy(offset).add(boxCenter);
35232
35250
  camera.updateMatrixWorld();
35233
35251
  }
35234
35252
  if (camera.isOrthographicCamera) {
35235
- camera.top = boxSize;
35236
- camera.bottom = -boxSize;
35253
+ camera.top = boxSize / 2;
35254
+ camera.bottom = -boxSize / 2;
35237
35255
  camera.left = camera.bottom * aspectRatio;
35238
35256
  camera.right = camera.top * aspectRatio;
35239
35257
  camera.zoom = 1;
35240
35258
  camera.updateProjectionMatrix();
35241
35259
  const offset = new Vector3(0, 0, 1)
35242
35260
  .applyQuaternion(camera.quaternion)
35243
- .multiplyScalar(viewer.extents.getBoundingSphere(new Sphere()).radius * 3);
35261
+ .multiplyScalar(viewer.extents.getSize(new Vector3()).length() || 1);
35244
35262
  camera.position.copy(offset).add(boxCenter);
35245
35263
  camera.updateMatrixWorld();
35246
35264
  }
@@ -35261,9 +35279,9 @@ void main() {
35261
35279
  ne: new Vector3(-1, 1, 1).normalize(),
35262
35280
  nw: new Vector3(1, 1, 1).normalize(),
35263
35281
  };
35264
- function setDefaultViewPosition(viewer, position) {
35282
+ function setDefaultViewPosition(viewer, position = "sw") {
35265
35283
  const extentsCenter = viewer.extents.getCenter(new Vector3());
35266
- const extentsSize = viewer.extents.getBoundingSphere(new Sphere()).radius * 2;
35284
+ const extentsSize = viewer.extents.getSize(new Vector3()).length() || 1;
35267
35285
  const upY = new Vector3(0, 1, 0);
35268
35286
  const offsetY = defaultViewPositions[position] || defaultViewPositions["sw"];
35269
35287
  const up = new Vector3().copy(viewer.camera.up);
@@ -35520,7 +35538,7 @@ void main() {
35520
35538
  return camera.isOrthographicCamera ? "orthographic" : "perspective";
35521
35539
  }
35522
35540
  switchCamera(camera) {
35523
- const extentsSize = this.viewer.extents.getBoundingSphere(new Sphere()).radius * 2 || 1;
35541
+ const extentsSize = this.viewer.extents.getSize(new Vector3()).length() || 1;
35524
35542
  const rendererSize = this.viewer.renderer.getSize(new Vector2());
35525
35543
  const aspectRatio = rendererSize.x / rendererSize.y;
35526
35544
  if (camera.isPerspectiveCamera) {
@@ -35560,7 +35578,7 @@ void main() {
35560
35578
  if (currentCamera.isPerspectiveCamera) {
35561
35579
  const fov = currentCamera.fov;
35562
35580
  const distance = currentCamera.position.distanceTo(target);
35563
- const fieldHeight = 2 * Math.tan(MathUtils.degToRad(fov) / 2) * distance;
35581
+ const fieldHeight = 2 * Math.tan(MathUtils.degToRad(fov * 0.5)) * distance;
35564
35582
  camera = new OrthographicCamera();
35565
35583
  camera.top = fieldHeight / 2;
35566
35584
  camera.bottom = -fieldHeight / 2;
@@ -35618,7 +35636,7 @@ void main() {
35618
35636
  if (this.viewer.extents.isEmpty())
35619
35637
  return;
35620
35638
  const extentsCenter = this.viewer.extents.getCenter(new Vector3());
35621
- const extentsSize = this.viewer.extents.getBoundingSphere(new Sphere()).radius;
35639
+ const extentsSize = this.viewer.extents.getSize(new Vector3()).length() || 1;
35622
35640
  const upY = new Vector3(0, 1, 0);
35623
35641
  const frontY = new Vector3(0, 0, -1);
35624
35642
  const up = new Vector3().copy(this.viewer.camera.up);
@@ -35627,17 +35645,14 @@ void main() {
35627
35645
  this.directionalLight.position
35628
35646
  .copy(up)
35629
35647
  .applyAxisAngle(front, (-Math.PI * 30) / 180)
35630
- .multiplyScalar(extentsSize * 2)
35648
+ .multiplyScalar(extentsSize)
35631
35649
  .add(extentsCenter);
35632
35650
  this.directionalLight.target.position.copy(extentsCenter);
35633
- this.frontLight.position
35634
- .copy(front)
35635
- .multiplyScalar(extentsSize * 2)
35636
- .add(extentsCenter);
35651
+ this.frontLight.position.copy(front).multiplyScalar(extentsSize).add(extentsCenter);
35637
35652
  this.frontLight.target.position.copy(extentsCenter);
35638
35653
  this.hemisphereLight.position
35639
35654
  .copy(front)
35640
- .multiplyScalar(extentsSize * 3)
35655
+ .multiplyScalar(extentsSize * 1.5)
35641
35656
  .add(extentsCenter);
35642
35657
  this.viewer.scene.add(this.ambientLight);
35643
35658
  this.viewer.scene.add(this.directionalLight);
@@ -35751,9 +35766,9 @@ void main() {
35751
35766
  console.log("File load time:", this.viewer.info.performance.loadTime, "ms");
35752
35767
  };
35753
35768
  this.resize = () => {
35754
- const rendererSize = this.viewer.renderer.getSize(new Vector2());
35755
- this.viewer.info.render.viewport.width = rendererSize.x;
35756
- this.viewer.info.render.viewport.height = rendererSize.y;
35769
+ const { width, height } = this.viewer.canvas;
35770
+ this.viewer.info.render.viewport.width = width;
35771
+ this.viewer.info.render.viewport.height = height;
35757
35772
  };
35758
35773
  this.render = () => {
35759
35774
  this.viewer.info.render.drawCalls = this.viewer.renderer.info.render.calls;
@@ -35802,13 +35817,13 @@ void main() {
35802
35817
 
35803
35818
  class RenderLoopComponent {
35804
35819
  constructor(viewer) {
35805
- this.animate = (time = 0) => {
35820
+ this.animate = (time) => {
35806
35821
  this.requestId = requestAnimationFrame(this.animate);
35807
35822
  this.viewer.render(time);
35808
35823
  this.viewer.emitEvent({ type: "animate", time });
35809
35824
  };
35810
35825
  this.viewer = viewer;
35811
- this.animate();
35826
+ this.requestId = requestAnimationFrame(this.animate);
35812
35827
  }
35813
35828
  dispose() {
35814
35829
  cancelAnimationFrame(this.requestId);
@@ -36682,8 +36697,9 @@ void main() {
36682
36697
  const upPosition = this.getMousePosition(event, new Vector2());
36683
36698
  if (upPosition.distanceTo(this.downPosition) !== 0)
36684
36699
  return;
36700
+ const extentsSize = this.viewer.extents.getSize(new Vector3()).length() || 1;
36685
36701
  const snapper = new Snapper(this.viewer.camera, this.viewer.renderer, this.viewer.canvas);
36686
- snapper.threshold = this.viewer.extents.getSize(new Vector3()).length() / 10000;
36702
+ snapper.threshold = extentsSize / 10000;
36687
36703
  let intersections = [];
36688
36704
  this.viewer.models.forEach((model) => {
36689
36705
  const objects = model.getVisibleObjects();
@@ -37452,7 +37468,11 @@ void main() {
37452
37468
  this.criticalError = null;
37453
37469
  }
37454
37470
  async initialize(loader) {
37455
- this.json = await this.loadController.loadJson();
37471
+ const json = await this.loadController.loadJson();
37472
+ if (json.asset === undefined || json.asset.version[0] < 2) {
37473
+ throw new Error("GltfStructure: Unsupported asset. glTF versions >=2.0 are supported.");
37474
+ }
37475
+ this.json = json;
37456
37476
  this.loader = loader;
37457
37477
  this.uri = this.json.buffers[0].uri || "";
37458
37478
  }
@@ -40097,48 +40117,1302 @@ void main() {
40097
40117
 
40098
40118
  const BINARY_EXTENSION_HEADER_MAGIC = "glTF";
40099
40119
  const BINARY_EXTENSION_HEADER_LENGTH = 12;
40100
- const BINARY_EXTENSION_CHUNK_TYPES = { JSON: 0x4e4f534a, BIN: 0x004e4042 };
40101
- class GLTFBinaryExtension {
40120
+ const BINARY_EXTENSION_CHUNK_TYPES = { JSON: 0x4e4f534a, BIN: 0x004e4942 };
40121
+ class GLTFBinaryParser {
40102
40122
  constructor(data) {
40103
- const headerView = new DataView(data, 0, BINARY_EXTENSION_HEADER_LENGTH);
40123
+ const dataView = new DataView(data, 0);
40104
40124
  const textDecoder = new TextDecoder();
40105
- const magic = textDecoder.decode(new Uint8Array(data.slice(0, 4)));
40125
+ const magic = textDecoder.decode(new Uint8Array(data, 0, Math.min(4, data.byteLength)));
40106
40126
  if (magic !== BINARY_EXTENSION_HEADER_MAGIC) {
40107
- this.content = textDecoder.decode(data);
40127
+ this.content = new Uint8Array(data);
40108
40128
  return;
40109
40129
  }
40110
- const header = {
40130
+ this.header = {
40111
40131
  magic,
40112
- version: headerView.getUint32(4, true),
40113
- length: headerView.getUint32(8, true),
40132
+ version: dataView.getUint32(4, true),
40133
+ length: dataView.getUint32(8, true),
40114
40134
  };
40115
- if (header.magic !== BINARY_EXTENSION_HEADER_MAGIC) {
40116
- throw new Error("Unsupported glTF-Binary header.");
40117
- }
40118
- if (header.version < 2.0) {
40119
- throw new Error("Legacy binary file detected.");
40120
- }
40121
- const chunkContentsLength = header.length - BINARY_EXTENSION_HEADER_LENGTH;
40122
- const chunkView = new DataView(data, BINARY_EXTENSION_HEADER_LENGTH);
40123
- let chunkIndex = 0;
40124
- while (chunkIndex < chunkContentsLength) {
40125
- const chunkLength = chunkView.getUint32(chunkIndex, true);
40126
- chunkIndex += 4;
40127
- const chunkType = chunkView.getUint32(chunkIndex, true);
40128
- chunkIndex += 4;
40135
+ if (this.header.length !== data.byteLength) {
40136
+ throw new Error("GLTFBinaryParser: Invalid binary file header.");
40137
+ }
40138
+ if (this.header.version < 2.0) {
40139
+ throw new Error("GLTFBinaryParser: Legacy binary file detected.");
40140
+ }
40141
+ let offset = BINARY_EXTENSION_HEADER_LENGTH;
40142
+ while (offset < this.header.length) {
40143
+ const chunkLength = dataView.getUint32(offset, true);
40144
+ offset += 4;
40145
+ const chunkType = dataView.getUint32(offset, true);
40146
+ offset += 4;
40129
40147
  if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.JSON) {
40130
- const contentArray = new Uint8Array(data, BINARY_EXTENSION_HEADER_LENGTH + chunkIndex, chunkLength);
40131
- this.content = textDecoder.decode(contentArray);
40148
+ this.content = new Uint8Array(data, offset, chunkLength);
40132
40149
  }
40133
40150
  else if (chunkType === BINARY_EXTENSION_CHUNK_TYPES.BIN) {
40134
- const byteOffset = BINARY_EXTENSION_HEADER_LENGTH + chunkIndex;
40135
- this.body = data.slice(byteOffset, byteOffset + chunkLength);
40151
+ this.body = data.slice(offset, offset + chunkLength);
40136
40152
  }
40137
- chunkIndex += chunkLength;
40153
+ offset += chunkLength;
40138
40154
  }
40139
40155
  if (typeof this.content === "undefined") {
40140
- throw new Error("JSON content not found.");
40156
+ throw new Error("GLTFBinaryParser: JSON content not found.");
40157
+ }
40158
+ if (typeof this.body === "undefined") {
40159
+ throw new Error("GLTFBinaryParser: Binary buffer chunk not found or type not supported.");
40160
+ }
40161
+ }
40162
+ }
40163
+
40164
+ var charset;
40165
+ (function (charset) {
40166
+ charset[charset["BACKSPACE"] = 8] = "BACKSPACE";
40167
+ charset[charset["FORM_FEED"] = 12] = "FORM_FEED";
40168
+ charset[charset["NEWLINE"] = 10] = "NEWLINE";
40169
+ charset[charset["CARRIAGE_RETURN"] = 13] = "CARRIAGE_RETURN";
40170
+ charset[charset["TAB"] = 9] = "TAB";
40171
+ charset[charset["SPACE"] = 32] = "SPACE";
40172
+ charset[charset["EXCLAMATION_MARK"] = 33] = "EXCLAMATION_MARK";
40173
+ charset[charset["QUOTATION_MARK"] = 34] = "QUOTATION_MARK";
40174
+ charset[charset["NUMBER_SIGN"] = 35] = "NUMBER_SIGN";
40175
+ charset[charset["DOLLAR_SIGN"] = 36] = "DOLLAR_SIGN";
40176
+ charset[charset["PERCENT_SIGN"] = 37] = "PERCENT_SIGN";
40177
+ charset[charset["AMPERSAND"] = 38] = "AMPERSAND";
40178
+ charset[charset["APOSTROPHE"] = 39] = "APOSTROPHE";
40179
+ charset[charset["LEFT_PARENTHESIS"] = 40] = "LEFT_PARENTHESIS";
40180
+ charset[charset["RIGHT_PARENTHESIS"] = 41] = "RIGHT_PARENTHESIS";
40181
+ charset[charset["ASTERISK"] = 42] = "ASTERISK";
40182
+ charset[charset["PLUS_SIGN"] = 43] = "PLUS_SIGN";
40183
+ charset[charset["COMMA"] = 44] = "COMMA";
40184
+ charset[charset["HYPHEN_MINUS"] = 45] = "HYPHEN_MINUS";
40185
+ charset[charset["FULL_STOP"] = 46] = "FULL_STOP";
40186
+ charset[charset["SOLIDUS"] = 47] = "SOLIDUS";
40187
+ charset[charset["DIGIT_ZERO"] = 48] = "DIGIT_ZERO";
40188
+ charset[charset["DIGIT_ONE"] = 49] = "DIGIT_ONE";
40189
+ charset[charset["DIGIT_TWO"] = 50] = "DIGIT_TWO";
40190
+ charset[charset["DIGIT_THREE"] = 51] = "DIGIT_THREE";
40191
+ charset[charset["DIGIT_FOUR"] = 52] = "DIGIT_FOUR";
40192
+ charset[charset["DIGIT_FIVE"] = 53] = "DIGIT_FIVE";
40193
+ charset[charset["DIGIT_SIX"] = 54] = "DIGIT_SIX";
40194
+ charset[charset["DIGIT_SEVEN"] = 55] = "DIGIT_SEVEN";
40195
+ charset[charset["DIGIT_EIGHT"] = 56] = "DIGIT_EIGHT";
40196
+ charset[charset["DIGIT_NINE"] = 57] = "DIGIT_NINE";
40197
+ charset[charset["COLON"] = 58] = "COLON";
40198
+ charset[charset["SEMICOLON"] = 59] = "SEMICOLON";
40199
+ charset[charset["LESS_THAN_SIGN"] = 60] = "LESS_THAN_SIGN";
40200
+ charset[charset["EQUALS_SIGN"] = 61] = "EQUALS_SIGN";
40201
+ charset[charset["GREATER_THAN_SIGN"] = 62] = "GREATER_THAN_SIGN";
40202
+ charset[charset["QUESTION_MARK"] = 63] = "QUESTION_MARK";
40203
+ charset[charset["COMMERCIAL_AT"] = 64] = "COMMERCIAL_AT";
40204
+ charset[charset["LATIN_CAPITAL_LETTER_A"] = 65] = "LATIN_CAPITAL_LETTER_A";
40205
+ charset[charset["LATIN_CAPITAL_LETTER_B"] = 66] = "LATIN_CAPITAL_LETTER_B";
40206
+ charset[charset["LATIN_CAPITAL_LETTER_C"] = 67] = "LATIN_CAPITAL_LETTER_C";
40207
+ charset[charset["LATIN_CAPITAL_LETTER_D"] = 68] = "LATIN_CAPITAL_LETTER_D";
40208
+ charset[charset["LATIN_CAPITAL_LETTER_E"] = 69] = "LATIN_CAPITAL_LETTER_E";
40209
+ charset[charset["LATIN_CAPITAL_LETTER_F"] = 70] = "LATIN_CAPITAL_LETTER_F";
40210
+ charset[charset["LATIN_CAPITAL_LETTER_G"] = 71] = "LATIN_CAPITAL_LETTER_G";
40211
+ charset[charset["LATIN_CAPITAL_LETTER_H"] = 72] = "LATIN_CAPITAL_LETTER_H";
40212
+ charset[charset["LATIN_CAPITAL_LETTER_I"] = 73] = "LATIN_CAPITAL_LETTER_I";
40213
+ charset[charset["LATIN_CAPITAL_LETTER_J"] = 74] = "LATIN_CAPITAL_LETTER_J";
40214
+ charset[charset["LATIN_CAPITAL_LETTER_K"] = 75] = "LATIN_CAPITAL_LETTER_K";
40215
+ charset[charset["LATIN_CAPITAL_LETTER_L"] = 76] = "LATIN_CAPITAL_LETTER_L";
40216
+ charset[charset["LATIN_CAPITAL_LETTER_M"] = 77] = "LATIN_CAPITAL_LETTER_M";
40217
+ charset[charset["LATIN_CAPITAL_LETTER_N"] = 78] = "LATIN_CAPITAL_LETTER_N";
40218
+ charset[charset["LATIN_CAPITAL_LETTER_O"] = 79] = "LATIN_CAPITAL_LETTER_O";
40219
+ charset[charset["LATIN_CAPITAL_LETTER_P"] = 80] = "LATIN_CAPITAL_LETTER_P";
40220
+ charset[charset["LATIN_CAPITAL_LETTER_Q"] = 81] = "LATIN_CAPITAL_LETTER_Q";
40221
+ charset[charset["LATIN_CAPITAL_LETTER_R"] = 82] = "LATIN_CAPITAL_LETTER_R";
40222
+ charset[charset["LATIN_CAPITAL_LETTER_S"] = 83] = "LATIN_CAPITAL_LETTER_S";
40223
+ charset[charset["LATIN_CAPITAL_LETTER_T"] = 84] = "LATIN_CAPITAL_LETTER_T";
40224
+ charset[charset["LATIN_CAPITAL_LETTER_U"] = 85] = "LATIN_CAPITAL_LETTER_U";
40225
+ charset[charset["LATIN_CAPITAL_LETTER_V"] = 86] = "LATIN_CAPITAL_LETTER_V";
40226
+ charset[charset["LATIN_CAPITAL_LETTER_W"] = 87] = "LATIN_CAPITAL_LETTER_W";
40227
+ charset[charset["LATIN_CAPITAL_LETTER_X"] = 88] = "LATIN_CAPITAL_LETTER_X";
40228
+ charset[charset["LATIN_CAPITAL_LETTER_Y"] = 89] = "LATIN_CAPITAL_LETTER_Y";
40229
+ charset[charset["LATIN_CAPITAL_LETTER_Z"] = 90] = "LATIN_CAPITAL_LETTER_Z";
40230
+ charset[charset["LEFT_SQUARE_BRACKET"] = 91] = "LEFT_SQUARE_BRACKET";
40231
+ charset[charset["REVERSE_SOLIDUS"] = 92] = "REVERSE_SOLIDUS";
40232
+ charset[charset["RIGHT_SQUARE_BRACKET"] = 93] = "RIGHT_SQUARE_BRACKET";
40233
+ charset[charset["CIRCUMFLEX_ACCENT"] = 94] = "CIRCUMFLEX_ACCENT";
40234
+ charset[charset["LOW_LINE"] = 95] = "LOW_LINE";
40235
+ charset[charset["GRAVE_ACCENT"] = 96] = "GRAVE_ACCENT";
40236
+ charset[charset["LATIN_SMALL_LETTER_A"] = 97] = "LATIN_SMALL_LETTER_A";
40237
+ charset[charset["LATIN_SMALL_LETTER_B"] = 98] = "LATIN_SMALL_LETTER_B";
40238
+ charset[charset["LATIN_SMALL_LETTER_C"] = 99] = "LATIN_SMALL_LETTER_C";
40239
+ charset[charset["LATIN_SMALL_LETTER_D"] = 100] = "LATIN_SMALL_LETTER_D";
40240
+ charset[charset["LATIN_SMALL_LETTER_E"] = 101] = "LATIN_SMALL_LETTER_E";
40241
+ charset[charset["LATIN_SMALL_LETTER_F"] = 102] = "LATIN_SMALL_LETTER_F";
40242
+ charset[charset["LATIN_SMALL_LETTER_G"] = 103] = "LATIN_SMALL_LETTER_G";
40243
+ charset[charset["LATIN_SMALL_LETTER_H"] = 104] = "LATIN_SMALL_LETTER_H";
40244
+ charset[charset["LATIN_SMALL_LETTER_I"] = 105] = "LATIN_SMALL_LETTER_I";
40245
+ charset[charset["LATIN_SMALL_LETTER_J"] = 106] = "LATIN_SMALL_LETTER_J";
40246
+ charset[charset["LATIN_SMALL_LETTER_K"] = 107] = "LATIN_SMALL_LETTER_K";
40247
+ charset[charset["LATIN_SMALL_LETTER_L"] = 108] = "LATIN_SMALL_LETTER_L";
40248
+ charset[charset["LATIN_SMALL_LETTER_M"] = 109] = "LATIN_SMALL_LETTER_M";
40249
+ charset[charset["LATIN_SMALL_LETTER_N"] = 110] = "LATIN_SMALL_LETTER_N";
40250
+ charset[charset["LATIN_SMALL_LETTER_O"] = 111] = "LATIN_SMALL_LETTER_O";
40251
+ charset[charset["LATIN_SMALL_LETTER_P"] = 112] = "LATIN_SMALL_LETTER_P";
40252
+ charset[charset["LATIN_SMALL_LETTER_Q"] = 113] = "LATIN_SMALL_LETTER_Q";
40253
+ charset[charset["LATIN_SMALL_LETTER_R"] = 114] = "LATIN_SMALL_LETTER_R";
40254
+ charset[charset["LATIN_SMALL_LETTER_S"] = 115] = "LATIN_SMALL_LETTER_S";
40255
+ charset[charset["LATIN_SMALL_LETTER_T"] = 116] = "LATIN_SMALL_LETTER_T";
40256
+ charset[charset["LATIN_SMALL_LETTER_U"] = 117] = "LATIN_SMALL_LETTER_U";
40257
+ charset[charset["LATIN_SMALL_LETTER_V"] = 118] = "LATIN_SMALL_LETTER_V";
40258
+ charset[charset["LATIN_SMALL_LETTER_W"] = 119] = "LATIN_SMALL_LETTER_W";
40259
+ charset[charset["LATIN_SMALL_LETTER_X"] = 120] = "LATIN_SMALL_LETTER_X";
40260
+ charset[charset["LATIN_SMALL_LETTER_Y"] = 121] = "LATIN_SMALL_LETTER_Y";
40261
+ charset[charset["LATIN_SMALL_LETTER_Z"] = 122] = "LATIN_SMALL_LETTER_Z";
40262
+ charset[charset["LEFT_CURLY_BRACKET"] = 123] = "LEFT_CURLY_BRACKET";
40263
+ charset[charset["VERTICAL_LINE"] = 124] = "VERTICAL_LINE";
40264
+ charset[charset["RIGHT_CURLY_BRACKET"] = 125] = "RIGHT_CURLY_BRACKET";
40265
+ charset[charset["TILDE"] = 126] = "TILDE";
40266
+ })(charset || (charset = {}));
40267
+ const escapedSequences = {
40268
+ [charset.QUOTATION_MARK]: charset.QUOTATION_MARK,
40269
+ [charset.REVERSE_SOLIDUS]: charset.REVERSE_SOLIDUS,
40270
+ [charset.SOLIDUS]: charset.SOLIDUS,
40271
+ [charset.LATIN_SMALL_LETTER_B]: charset.BACKSPACE,
40272
+ [charset.LATIN_SMALL_LETTER_F]: charset.FORM_FEED,
40273
+ [charset.LATIN_SMALL_LETTER_N]: charset.NEWLINE,
40274
+ [charset.LATIN_SMALL_LETTER_R]: charset.CARRIAGE_RETURN,
40275
+ [charset.LATIN_SMALL_LETTER_T]: charset.TAB,
40276
+ };
40277
+
40278
+ class NonBufferedString {
40279
+ constructor() {
40280
+ this.decoder = new TextDecoder("utf-8");
40281
+ this.strings = [];
40282
+ this.byteLength = 0;
40283
+ }
40284
+ appendChar(char) {
40285
+ this.strings.push(String.fromCharCode(char));
40286
+ this.byteLength += 1;
40287
+ }
40288
+ appendBuf(buf, start = 0, end = buf.length) {
40289
+ this.strings.push(this.decoder.decode(buf.subarray(start, end)));
40290
+ this.byteLength += end - start;
40291
+ }
40292
+ reset() {
40293
+ this.strings = [];
40294
+ this.byteLength = 0;
40295
+ }
40296
+ toString() {
40297
+ return this.strings.join("");
40298
+ }
40299
+ }
40300
+ class BufferedString {
40301
+ constructor(bufferSize) {
40302
+ this.decoder = new TextDecoder("utf-8");
40303
+ this.bufferOffset = 0;
40304
+ this.string = "";
40305
+ this.byteLength = 0;
40306
+ this.buffer = new Uint8Array(bufferSize);
40307
+ }
40308
+ appendChar(char) {
40309
+ if (this.bufferOffset >= this.buffer.length)
40310
+ this.flushStringBuffer();
40311
+ this.buffer[this.bufferOffset++] = char;
40312
+ this.byteLength += 1;
40313
+ }
40314
+ appendBuf(buf, start = 0, end = buf.length) {
40315
+ const size = end - start;
40316
+ if (this.bufferOffset + size > this.buffer.length)
40317
+ this.flushStringBuffer();
40318
+ this.buffer.set(buf.subarray(start, end), this.bufferOffset);
40319
+ this.bufferOffset += size;
40320
+ this.byteLength += size;
40321
+ }
40322
+ flushStringBuffer() {
40323
+ this.string += this.decoder.decode(this.buffer.subarray(0, this.bufferOffset));
40324
+ this.bufferOffset = 0;
40325
+ }
40326
+ reset() {
40327
+ this.string = "";
40328
+ this.bufferOffset = 0;
40329
+ this.byteLength = 0;
40330
+ }
40331
+ toString() {
40332
+ this.flushStringBuffer();
40333
+ return this.string;
40334
+ }
40335
+ }
40336
+
40337
+ var TokenType$1;
40338
+ (function (TokenType) {
40339
+ TokenType[TokenType["LEFT_BRACE"] = 0] = "LEFT_BRACE";
40340
+ TokenType[TokenType["RIGHT_BRACE"] = 1] = "RIGHT_BRACE";
40341
+ TokenType[TokenType["LEFT_BRACKET"] = 2] = "LEFT_BRACKET";
40342
+ TokenType[TokenType["RIGHT_BRACKET"] = 3] = "RIGHT_BRACKET";
40343
+ TokenType[TokenType["COLON"] = 4] = "COLON";
40344
+ TokenType[TokenType["COMMA"] = 5] = "COMMA";
40345
+ TokenType[TokenType["TRUE"] = 6] = "TRUE";
40346
+ TokenType[TokenType["FALSE"] = 7] = "FALSE";
40347
+ TokenType[TokenType["NULL"] = 8] = "NULL";
40348
+ TokenType[TokenType["STRING"] = 9] = "STRING";
40349
+ TokenType[TokenType["NUMBER"] = 10] = "NUMBER";
40350
+ TokenType[TokenType["SEPARATOR"] = 11] = "SEPARATOR";
40351
+ })(TokenType$1 || (TokenType$1 = {}));
40352
+ var TokenType = TokenType$1;
40353
+
40354
+ var TokenizerStates;
40355
+ (function (TokenizerStates) {
40356
+ TokenizerStates[TokenizerStates["START"] = 0] = "START";
40357
+ TokenizerStates[TokenizerStates["ENDED"] = 1] = "ENDED";
40358
+ TokenizerStates[TokenizerStates["ERROR"] = 2] = "ERROR";
40359
+ TokenizerStates[TokenizerStates["TRUE1"] = 3] = "TRUE1";
40360
+ TokenizerStates[TokenizerStates["TRUE2"] = 4] = "TRUE2";
40361
+ TokenizerStates[TokenizerStates["TRUE3"] = 5] = "TRUE3";
40362
+ TokenizerStates[TokenizerStates["FALSE1"] = 6] = "FALSE1";
40363
+ TokenizerStates[TokenizerStates["FALSE2"] = 7] = "FALSE2";
40364
+ TokenizerStates[TokenizerStates["FALSE3"] = 8] = "FALSE3";
40365
+ TokenizerStates[TokenizerStates["FALSE4"] = 9] = "FALSE4";
40366
+ TokenizerStates[TokenizerStates["NULL1"] = 10] = "NULL1";
40367
+ TokenizerStates[TokenizerStates["NULL2"] = 11] = "NULL2";
40368
+ TokenizerStates[TokenizerStates["NULL3"] = 12] = "NULL3";
40369
+ TokenizerStates[TokenizerStates["STRING_DEFAULT"] = 13] = "STRING_DEFAULT";
40370
+ TokenizerStates[TokenizerStates["STRING_AFTER_BACKSLASH"] = 14] = "STRING_AFTER_BACKSLASH";
40371
+ TokenizerStates[TokenizerStates["STRING_UNICODE_DIGIT_1"] = 15] = "STRING_UNICODE_DIGIT_1";
40372
+ TokenizerStates[TokenizerStates["STRING_UNICODE_DIGIT_2"] = 16] = "STRING_UNICODE_DIGIT_2";
40373
+ TokenizerStates[TokenizerStates["STRING_UNICODE_DIGIT_3"] = 17] = "STRING_UNICODE_DIGIT_3";
40374
+ TokenizerStates[TokenizerStates["STRING_UNICODE_DIGIT_4"] = 18] = "STRING_UNICODE_DIGIT_4";
40375
+ TokenizerStates[TokenizerStates["STRING_INCOMPLETE_CHAR"] = 19] = "STRING_INCOMPLETE_CHAR";
40376
+ TokenizerStates[TokenizerStates["NUMBER_AFTER_INITIAL_MINUS"] = 20] = "NUMBER_AFTER_INITIAL_MINUS";
40377
+ TokenizerStates[TokenizerStates["NUMBER_AFTER_INITIAL_ZERO"] = 21] = "NUMBER_AFTER_INITIAL_ZERO";
40378
+ TokenizerStates[TokenizerStates["NUMBER_AFTER_INITIAL_NON_ZERO"] = 22] = "NUMBER_AFTER_INITIAL_NON_ZERO";
40379
+ TokenizerStates[TokenizerStates["NUMBER_AFTER_FULL_STOP"] = 23] = "NUMBER_AFTER_FULL_STOP";
40380
+ TokenizerStates[TokenizerStates["NUMBER_AFTER_DECIMAL"] = 24] = "NUMBER_AFTER_DECIMAL";
40381
+ TokenizerStates[TokenizerStates["NUMBER_AFTER_E"] = 25] = "NUMBER_AFTER_E";
40382
+ TokenizerStates[TokenizerStates["NUMBER_AFTER_E_AND_SIGN"] = 26] = "NUMBER_AFTER_E_AND_SIGN";
40383
+ TokenizerStates[TokenizerStates["NUMBER_AFTER_E_AND_DIGIT"] = 27] = "NUMBER_AFTER_E_AND_DIGIT";
40384
+ TokenizerStates[TokenizerStates["SEPARATOR"] = 28] = "SEPARATOR";
40385
+ TokenizerStates[TokenizerStates["BOM_OR_START"] = 29] = "BOM_OR_START";
40386
+ TokenizerStates[TokenizerStates["BOM"] = 30] = "BOM";
40387
+ })(TokenizerStates || (TokenizerStates = {}));
40388
+ function TokenizerStateToString(tokenizerState) {
40389
+ return [
40390
+ "START",
40391
+ "ENDED",
40392
+ "ERROR",
40393
+ "TRUE1",
40394
+ "TRUE2",
40395
+ "TRUE3",
40396
+ "FALSE1",
40397
+ "FALSE2",
40398
+ "FALSE3",
40399
+ "FALSE4",
40400
+ "NULL1",
40401
+ "NULL2",
40402
+ "NULL3",
40403
+ "STRING_DEFAULT",
40404
+ "STRING_AFTER_BACKSLASH",
40405
+ "STRING_UNICODE_DIGIT_1",
40406
+ "STRING_UNICODE_DIGIT_2",
40407
+ "STRING_UNICODE_DIGIT_3",
40408
+ "STRING_UNICODE_DIGIT_4",
40409
+ "STRING_INCOMPLETE_CHAR",
40410
+ "NUMBER_AFTER_INITIAL_MINUS",
40411
+ "NUMBER_AFTER_INITIAL_ZERO",
40412
+ "NUMBER_AFTER_INITIAL_NON_ZERO",
40413
+ "NUMBER_AFTER_FULL_STOP",
40414
+ "NUMBER_AFTER_DECIMAL",
40415
+ "NUMBER_AFTER_E",
40416
+ "NUMBER_AFTER_E_AND_SIGN",
40417
+ "NUMBER_AFTER_E_AND_DIGIT",
40418
+ "SEPARATOR",
40419
+ "BOM_OR_START",
40420
+ "BOM",
40421
+ ][tokenizerState];
40422
+ }
40423
+ const defaultOpts$1 = {
40424
+ stringBufferSize: 0,
40425
+ numberBufferSize: 0,
40426
+ separator: undefined,
40427
+ emitPartialTokens: false,
40428
+ };
40429
+ class TokenizerError extends Error {
40430
+ constructor(message) {
40431
+ super(message);
40432
+ Object.setPrototypeOf(this, TokenizerError.prototype);
40433
+ }
40434
+ }
40435
+ class Tokenizer {
40436
+ constructor(opts) {
40437
+ this.state = TokenizerStates.BOM_OR_START;
40438
+ this.bomIndex = 0;
40439
+ this.separatorIndex = 0;
40440
+ this.escapedCharsByteLength = 0;
40441
+ this.bytes_remaining = 0;
40442
+ this.bytes_in_sequence = 0;
40443
+ this.char_split_buffer = new Uint8Array(4);
40444
+ this.encoder = new TextEncoder();
40445
+ this.offset = -1;
40446
+ opts = Object.assign(Object.assign({}, defaultOpts$1), opts);
40447
+ this.emitPartialTokens = opts.emitPartialTokens === true;
40448
+ this.bufferedString =
40449
+ opts.stringBufferSize && opts.stringBufferSize > 4
40450
+ ? new BufferedString(opts.stringBufferSize)
40451
+ : new NonBufferedString();
40452
+ this.bufferedNumber =
40453
+ opts.numberBufferSize && opts.numberBufferSize > 0
40454
+ ? new BufferedString(opts.numberBufferSize)
40455
+ : new NonBufferedString();
40456
+ this.separator = opts.separator;
40457
+ this.separatorBytes = opts.separator
40458
+ ? this.encoder.encode(opts.separator)
40459
+ : undefined;
40460
+ }
40461
+ get isEnded() {
40462
+ return this.state === TokenizerStates.ENDED;
40463
+ }
40464
+ write(input) {
40465
+ try {
40466
+ let buffer;
40467
+ if (input instanceof Uint8Array) {
40468
+ buffer = input;
40469
+ }
40470
+ else if (typeof input === "string") {
40471
+ buffer = this.encoder.encode(input);
40472
+ }
40473
+ else if (Array.isArray(input)) {
40474
+ buffer = Uint8Array.from(input);
40475
+ }
40476
+ else if (ArrayBuffer.isView(input)) {
40477
+ buffer = new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
40478
+ }
40479
+ else {
40480
+ throw new TypeError("Unexpected type. The `write` function only accepts Arrays, TypedArrays and Strings.");
40481
+ }
40482
+ for (let i = 0; i < buffer.length; i += 1) {
40483
+ const n = buffer[i];
40484
+ switch (this.state) {
40485
+ case TokenizerStates.BOM_OR_START:
40486
+ if (input instanceof Uint8Array && n === 0xef) {
40487
+ this.bom = [0xef, 0xbb, 0xbf];
40488
+ this.bomIndex += 1;
40489
+ this.state = TokenizerStates.BOM;
40490
+ continue;
40491
+ }
40492
+ if (input instanceof Uint16Array) {
40493
+ if (n === 0xfe) {
40494
+ this.bom = [0xfe, 0xff];
40495
+ this.bomIndex += 1;
40496
+ this.state = TokenizerStates.BOM;
40497
+ continue;
40498
+ }
40499
+ if (n === 0xff) {
40500
+ this.bom = [0xff, 0xfe];
40501
+ this.bomIndex += 1;
40502
+ this.state = TokenizerStates.BOM;
40503
+ continue;
40504
+ }
40505
+ }
40506
+ if (input instanceof Uint32Array) {
40507
+ if (n === 0x00) {
40508
+ this.bom = [0x00, 0x00, 0xfe, 0xff];
40509
+ this.bomIndex += 1;
40510
+ this.state = TokenizerStates.BOM;
40511
+ continue;
40512
+ }
40513
+ if (n === 0xff) {
40514
+ this.bom = [0xff, 0xfe, 0x00, 0x00];
40515
+ this.bomIndex += 1;
40516
+ this.state = TokenizerStates.BOM;
40517
+ continue;
40518
+ }
40519
+ }
40520
+ case TokenizerStates.START:
40521
+ this.offset += 1;
40522
+ if (this.separatorBytes && n === this.separatorBytes[0]) {
40523
+ if (this.separatorBytes.length === 1) {
40524
+ this.state = TokenizerStates.START;
40525
+ this.onToken({
40526
+ token: TokenType.SEPARATOR,
40527
+ value: this.separator,
40528
+ offset: this.offset + this.separatorBytes.length - 1,
40529
+ });
40530
+ continue;
40531
+ }
40532
+ this.state = TokenizerStates.SEPARATOR;
40533
+ continue;
40534
+ }
40535
+ if (n === charset.SPACE ||
40536
+ n === charset.NEWLINE ||
40537
+ n === charset.CARRIAGE_RETURN ||
40538
+ n === charset.TAB) {
40539
+ continue;
40540
+ }
40541
+ if (n === charset.LEFT_CURLY_BRACKET) {
40542
+ this.onToken({
40543
+ token: TokenType.LEFT_BRACE,
40544
+ value: "{",
40545
+ offset: this.offset,
40546
+ });
40547
+ continue;
40548
+ }
40549
+ if (n === charset.RIGHT_CURLY_BRACKET) {
40550
+ this.onToken({
40551
+ token: TokenType.RIGHT_BRACE,
40552
+ value: "}",
40553
+ offset: this.offset,
40554
+ });
40555
+ continue;
40556
+ }
40557
+ if (n === charset.LEFT_SQUARE_BRACKET) {
40558
+ this.onToken({
40559
+ token: TokenType.LEFT_BRACKET,
40560
+ value: "[",
40561
+ offset: this.offset,
40562
+ });
40563
+ continue;
40564
+ }
40565
+ if (n === charset.RIGHT_SQUARE_BRACKET) {
40566
+ this.onToken({
40567
+ token: TokenType.RIGHT_BRACKET,
40568
+ value: "]",
40569
+ offset: this.offset,
40570
+ });
40571
+ continue;
40572
+ }
40573
+ if (n === charset.COLON) {
40574
+ this.onToken({
40575
+ token: TokenType.COLON,
40576
+ value: ":",
40577
+ offset: this.offset,
40578
+ });
40579
+ continue;
40580
+ }
40581
+ if (n === charset.COMMA) {
40582
+ this.onToken({
40583
+ token: TokenType.COMMA,
40584
+ value: ",",
40585
+ offset: this.offset,
40586
+ });
40587
+ continue;
40588
+ }
40589
+ if (n === charset.LATIN_SMALL_LETTER_T) {
40590
+ this.state = TokenizerStates.TRUE1;
40591
+ continue;
40592
+ }
40593
+ if (n === charset.LATIN_SMALL_LETTER_F) {
40594
+ this.state = TokenizerStates.FALSE1;
40595
+ continue;
40596
+ }
40597
+ if (n === charset.LATIN_SMALL_LETTER_N) {
40598
+ this.state = TokenizerStates.NULL1;
40599
+ continue;
40600
+ }
40601
+ if (n === charset.QUOTATION_MARK) {
40602
+ this.bufferedString.reset();
40603
+ this.escapedCharsByteLength = 0;
40604
+ this.state = TokenizerStates.STRING_DEFAULT;
40605
+ continue;
40606
+ }
40607
+ if (n >= charset.DIGIT_ONE && n <= charset.DIGIT_NINE) {
40608
+ this.bufferedNumber.reset();
40609
+ this.bufferedNumber.appendChar(n);
40610
+ this.state = TokenizerStates.NUMBER_AFTER_INITIAL_NON_ZERO;
40611
+ continue;
40612
+ }
40613
+ if (n === charset.DIGIT_ZERO) {
40614
+ this.bufferedNumber.reset();
40615
+ this.bufferedNumber.appendChar(n);
40616
+ this.state = TokenizerStates.NUMBER_AFTER_INITIAL_ZERO;
40617
+ continue;
40618
+ }
40619
+ if (n === charset.HYPHEN_MINUS) {
40620
+ this.bufferedNumber.reset();
40621
+ this.bufferedNumber.appendChar(n);
40622
+ this.state = TokenizerStates.NUMBER_AFTER_INITIAL_MINUS;
40623
+ continue;
40624
+ }
40625
+ break;
40626
+ case TokenizerStates.STRING_DEFAULT:
40627
+ if (n === charset.QUOTATION_MARK) {
40628
+ const string = this.bufferedString.toString();
40629
+ this.state = TokenizerStates.START;
40630
+ this.onToken({
40631
+ token: TokenType.STRING,
40632
+ value: string,
40633
+ offset: this.offset,
40634
+ });
40635
+ this.offset +=
40636
+ this.escapedCharsByteLength +
40637
+ this.bufferedString.byteLength +
40638
+ 1;
40639
+ continue;
40640
+ }
40641
+ if (n === charset.REVERSE_SOLIDUS) {
40642
+ this.state = TokenizerStates.STRING_AFTER_BACKSLASH;
40643
+ continue;
40644
+ }
40645
+ if (n >= 128) {
40646
+ if (n >= 194 && n <= 223) {
40647
+ this.bytes_in_sequence = 2;
40648
+ }
40649
+ else if (n <= 239) {
40650
+ this.bytes_in_sequence = 3;
40651
+ }
40652
+ else {
40653
+ this.bytes_in_sequence = 4;
40654
+ }
40655
+ if (this.bytes_in_sequence <= buffer.length - i) {
40656
+ this.bufferedString.appendBuf(buffer, i, i + this.bytes_in_sequence);
40657
+ i += this.bytes_in_sequence - 1;
40658
+ continue;
40659
+ }
40660
+ this.bytes_remaining = i + this.bytes_in_sequence - buffer.length;
40661
+ this.char_split_buffer.set(buffer.subarray(i));
40662
+ i = buffer.length - 1;
40663
+ this.state = TokenizerStates.STRING_INCOMPLETE_CHAR;
40664
+ continue;
40665
+ }
40666
+ if (n >= charset.SPACE) {
40667
+ this.bufferedString.appendChar(n);
40668
+ continue;
40669
+ }
40670
+ break;
40671
+ case TokenizerStates.STRING_INCOMPLETE_CHAR:
40672
+ this.char_split_buffer.set(buffer.subarray(i, i + this.bytes_remaining), this.bytes_in_sequence - this.bytes_remaining);
40673
+ this.bufferedString.appendBuf(this.char_split_buffer, 0, this.bytes_in_sequence);
40674
+ i = this.bytes_remaining - 1;
40675
+ this.state = TokenizerStates.STRING_DEFAULT;
40676
+ continue;
40677
+ case TokenizerStates.STRING_AFTER_BACKSLASH:
40678
+ const controlChar = escapedSequences[n];
40679
+ if (controlChar) {
40680
+ this.bufferedString.appendChar(controlChar);
40681
+ this.escapedCharsByteLength += 1;
40682
+ this.state = TokenizerStates.STRING_DEFAULT;
40683
+ continue;
40684
+ }
40685
+ if (n === charset.LATIN_SMALL_LETTER_U) {
40686
+ this.unicode = "";
40687
+ this.state = TokenizerStates.STRING_UNICODE_DIGIT_1;
40688
+ continue;
40689
+ }
40690
+ break;
40691
+ case TokenizerStates.STRING_UNICODE_DIGIT_1:
40692
+ case TokenizerStates.STRING_UNICODE_DIGIT_2:
40693
+ case TokenizerStates.STRING_UNICODE_DIGIT_3:
40694
+ if ((n >= charset.DIGIT_ZERO && n <= charset.DIGIT_NINE) ||
40695
+ (n >= charset.LATIN_CAPITAL_LETTER_A &&
40696
+ n <= charset.LATIN_CAPITAL_LETTER_F) ||
40697
+ (n >= charset.LATIN_SMALL_LETTER_A &&
40698
+ n <= charset.LATIN_SMALL_LETTER_F)) {
40699
+ this.unicode += String.fromCharCode(n);
40700
+ this.state += 1;
40701
+ continue;
40702
+ }
40703
+ break;
40704
+ case TokenizerStates.STRING_UNICODE_DIGIT_4:
40705
+ if ((n >= charset.DIGIT_ZERO && n <= charset.DIGIT_NINE) ||
40706
+ (n >= charset.LATIN_CAPITAL_LETTER_A &&
40707
+ n <= charset.LATIN_CAPITAL_LETTER_F) ||
40708
+ (n >= charset.LATIN_SMALL_LETTER_A &&
40709
+ n <= charset.LATIN_SMALL_LETTER_F)) {
40710
+ const intVal = parseInt(this.unicode + String.fromCharCode(n), 16);
40711
+ let unicodeString;
40712
+ if (this.highSurrogate === undefined) {
40713
+ if (intVal >= 0xd800 && intVal <= 0xdbff) {
40714
+ this.highSurrogate = intVal;
40715
+ this.state = TokenizerStates.STRING_DEFAULT;
40716
+ continue;
40717
+ }
40718
+ else {
40719
+ unicodeString = String.fromCharCode(intVal);
40720
+ }
40721
+ }
40722
+ else {
40723
+ if (intVal >= 0xdc00 && intVal <= 0xdfff) {
40724
+ unicodeString = String.fromCharCode(this.highSurrogate, intVal);
40725
+ }
40726
+ else {
40727
+ unicodeString = String.fromCharCode(this.highSurrogate);
40728
+ }
40729
+ this.highSurrogate = undefined;
40730
+ }
40731
+ const unicodeBuffer = this.encoder.encode(unicodeString);
40732
+ this.bufferedString.appendBuf(unicodeBuffer);
40733
+ this.escapedCharsByteLength += 6 - unicodeBuffer.byteLength;
40734
+ this.state = TokenizerStates.STRING_DEFAULT;
40735
+ continue;
40736
+ }
40737
+ break;
40738
+ case TokenizerStates.NUMBER_AFTER_INITIAL_MINUS:
40739
+ if (n === charset.DIGIT_ZERO) {
40740
+ this.bufferedNumber.appendChar(n);
40741
+ this.state = TokenizerStates.NUMBER_AFTER_INITIAL_ZERO;
40742
+ continue;
40743
+ }
40744
+ if (n >= charset.DIGIT_ONE && n <= charset.DIGIT_NINE) {
40745
+ this.bufferedNumber.appendChar(n);
40746
+ this.state = TokenizerStates.NUMBER_AFTER_INITIAL_NON_ZERO;
40747
+ continue;
40748
+ }
40749
+ break;
40750
+ case TokenizerStates.NUMBER_AFTER_INITIAL_ZERO:
40751
+ if (n === charset.FULL_STOP) {
40752
+ this.bufferedNumber.appendChar(n);
40753
+ this.state = TokenizerStates.NUMBER_AFTER_FULL_STOP;
40754
+ continue;
40755
+ }
40756
+ if (n === charset.LATIN_SMALL_LETTER_E ||
40757
+ n === charset.LATIN_CAPITAL_LETTER_E) {
40758
+ this.bufferedNumber.appendChar(n);
40759
+ this.state = TokenizerStates.NUMBER_AFTER_E;
40760
+ continue;
40761
+ }
40762
+ i -= 1;
40763
+ this.state = TokenizerStates.START;
40764
+ this.emitNumber();
40765
+ continue;
40766
+ case TokenizerStates.NUMBER_AFTER_INITIAL_NON_ZERO:
40767
+ if (n >= charset.DIGIT_ZERO && n <= charset.DIGIT_NINE) {
40768
+ this.bufferedNumber.appendChar(n);
40769
+ continue;
40770
+ }
40771
+ if (n === charset.FULL_STOP) {
40772
+ this.bufferedNumber.appendChar(n);
40773
+ this.state = TokenizerStates.NUMBER_AFTER_FULL_STOP;
40774
+ continue;
40775
+ }
40776
+ if (n === charset.LATIN_SMALL_LETTER_E ||
40777
+ n === charset.LATIN_CAPITAL_LETTER_E) {
40778
+ this.bufferedNumber.appendChar(n);
40779
+ this.state = TokenizerStates.NUMBER_AFTER_E;
40780
+ continue;
40781
+ }
40782
+ i -= 1;
40783
+ this.state = TokenizerStates.START;
40784
+ this.emitNumber();
40785
+ continue;
40786
+ case TokenizerStates.NUMBER_AFTER_FULL_STOP:
40787
+ if (n >= charset.DIGIT_ZERO && n <= charset.DIGIT_NINE) {
40788
+ this.bufferedNumber.appendChar(n);
40789
+ this.state = TokenizerStates.NUMBER_AFTER_DECIMAL;
40790
+ continue;
40791
+ }
40792
+ break;
40793
+ case TokenizerStates.NUMBER_AFTER_DECIMAL:
40794
+ if (n >= charset.DIGIT_ZERO && n <= charset.DIGIT_NINE) {
40795
+ this.bufferedNumber.appendChar(n);
40796
+ continue;
40797
+ }
40798
+ if (n === charset.LATIN_SMALL_LETTER_E ||
40799
+ n === charset.LATIN_CAPITAL_LETTER_E) {
40800
+ this.bufferedNumber.appendChar(n);
40801
+ this.state = TokenizerStates.NUMBER_AFTER_E;
40802
+ continue;
40803
+ }
40804
+ i -= 1;
40805
+ this.state = TokenizerStates.START;
40806
+ this.emitNumber();
40807
+ continue;
40808
+ case TokenizerStates.NUMBER_AFTER_E:
40809
+ if (n === charset.PLUS_SIGN || n === charset.HYPHEN_MINUS) {
40810
+ this.bufferedNumber.appendChar(n);
40811
+ this.state = TokenizerStates.NUMBER_AFTER_E_AND_SIGN;
40812
+ continue;
40813
+ }
40814
+ case TokenizerStates.NUMBER_AFTER_E_AND_SIGN:
40815
+ if (n >= charset.DIGIT_ZERO && n <= charset.DIGIT_NINE) {
40816
+ this.bufferedNumber.appendChar(n);
40817
+ this.state = TokenizerStates.NUMBER_AFTER_E_AND_DIGIT;
40818
+ continue;
40819
+ }
40820
+ break;
40821
+ case TokenizerStates.NUMBER_AFTER_E_AND_DIGIT:
40822
+ if (n >= charset.DIGIT_ZERO && n <= charset.DIGIT_NINE) {
40823
+ this.bufferedNumber.appendChar(n);
40824
+ continue;
40825
+ }
40826
+ i -= 1;
40827
+ this.state = TokenizerStates.START;
40828
+ this.emitNumber();
40829
+ continue;
40830
+ case TokenizerStates.TRUE1:
40831
+ if (n === charset.LATIN_SMALL_LETTER_R) {
40832
+ this.state = TokenizerStates.TRUE2;
40833
+ continue;
40834
+ }
40835
+ break;
40836
+ case TokenizerStates.TRUE2:
40837
+ if (n === charset.LATIN_SMALL_LETTER_U) {
40838
+ this.state = TokenizerStates.TRUE3;
40839
+ continue;
40840
+ }
40841
+ break;
40842
+ case TokenizerStates.TRUE3:
40843
+ if (n === charset.LATIN_SMALL_LETTER_E) {
40844
+ this.state = TokenizerStates.START;
40845
+ this.onToken({
40846
+ token: TokenType.TRUE,
40847
+ value: true,
40848
+ offset: this.offset,
40849
+ });
40850
+ this.offset += 3;
40851
+ continue;
40852
+ }
40853
+ break;
40854
+ case TokenizerStates.FALSE1:
40855
+ if (n === charset.LATIN_SMALL_LETTER_A) {
40856
+ this.state = TokenizerStates.FALSE2;
40857
+ continue;
40858
+ }
40859
+ break;
40860
+ case TokenizerStates.FALSE2:
40861
+ if (n === charset.LATIN_SMALL_LETTER_L) {
40862
+ this.state = TokenizerStates.FALSE3;
40863
+ continue;
40864
+ }
40865
+ break;
40866
+ case TokenizerStates.FALSE3:
40867
+ if (n === charset.LATIN_SMALL_LETTER_S) {
40868
+ this.state = TokenizerStates.FALSE4;
40869
+ continue;
40870
+ }
40871
+ break;
40872
+ case TokenizerStates.FALSE4:
40873
+ if (n === charset.LATIN_SMALL_LETTER_E) {
40874
+ this.state = TokenizerStates.START;
40875
+ this.onToken({
40876
+ token: TokenType.FALSE,
40877
+ value: false,
40878
+ offset: this.offset,
40879
+ });
40880
+ this.offset += 4;
40881
+ continue;
40882
+ }
40883
+ break;
40884
+ case TokenizerStates.NULL1:
40885
+ if (n === charset.LATIN_SMALL_LETTER_U) {
40886
+ this.state = TokenizerStates.NULL2;
40887
+ continue;
40888
+ }
40889
+ break;
40890
+ case TokenizerStates.NULL2:
40891
+ if (n === charset.LATIN_SMALL_LETTER_L) {
40892
+ this.state = TokenizerStates.NULL3;
40893
+ continue;
40894
+ }
40895
+ break;
40896
+ case TokenizerStates.NULL3:
40897
+ if (n === charset.LATIN_SMALL_LETTER_L) {
40898
+ this.state = TokenizerStates.START;
40899
+ this.onToken({
40900
+ token: TokenType.NULL,
40901
+ value: null,
40902
+ offset: this.offset,
40903
+ });
40904
+ this.offset += 3;
40905
+ continue;
40906
+ }
40907
+ break;
40908
+ case TokenizerStates.SEPARATOR:
40909
+ this.separatorIndex += 1;
40910
+ if (!this.separatorBytes ||
40911
+ n !== this.separatorBytes[this.separatorIndex]) {
40912
+ break;
40913
+ }
40914
+ if (this.separatorIndex === this.separatorBytes.length - 1) {
40915
+ this.state = TokenizerStates.START;
40916
+ this.onToken({
40917
+ token: TokenType.SEPARATOR,
40918
+ value: this.separator,
40919
+ offset: this.offset + this.separatorIndex,
40920
+ });
40921
+ this.separatorIndex = 0;
40922
+ }
40923
+ continue;
40924
+ case TokenizerStates.BOM:
40925
+ if (n === this.bom[this.bomIndex]) {
40926
+ if (this.bomIndex === this.bom.length - 1) {
40927
+ this.state = TokenizerStates.START;
40928
+ this.bom = undefined;
40929
+ this.bomIndex = 0;
40930
+ continue;
40931
+ }
40932
+ this.bomIndex += 1;
40933
+ continue;
40934
+ }
40935
+ break;
40936
+ case TokenizerStates.ENDED:
40937
+ if (n === charset.SPACE ||
40938
+ n === charset.NEWLINE ||
40939
+ n === charset.CARRIAGE_RETURN ||
40940
+ n === charset.TAB) {
40941
+ continue;
40942
+ }
40943
+ }
40944
+ throw new TokenizerError(`Unexpected "${String.fromCharCode(n)}" at position "${i}" in state ${TokenizerStateToString(this.state)}`);
40945
+ }
40946
+ if (this.emitPartialTokens) {
40947
+ switch (this.state) {
40948
+ case TokenizerStates.TRUE1:
40949
+ case TokenizerStates.TRUE2:
40950
+ case TokenizerStates.TRUE3:
40951
+ this.onToken({
40952
+ token: TokenType.TRUE,
40953
+ value: true,
40954
+ offset: this.offset,
40955
+ partial: true,
40956
+ });
40957
+ break;
40958
+ case TokenizerStates.FALSE1:
40959
+ case TokenizerStates.FALSE2:
40960
+ case TokenizerStates.FALSE3:
40961
+ case TokenizerStates.FALSE4:
40962
+ this.onToken({
40963
+ token: TokenType.FALSE,
40964
+ value: false,
40965
+ offset: this.offset,
40966
+ partial: true,
40967
+ });
40968
+ break;
40969
+ case TokenizerStates.NULL1:
40970
+ case TokenizerStates.NULL2:
40971
+ case TokenizerStates.NULL3:
40972
+ this.onToken({
40973
+ token: TokenType.NULL,
40974
+ value: null,
40975
+ offset: this.offset,
40976
+ partial: true,
40977
+ });
40978
+ break;
40979
+ case TokenizerStates.STRING_DEFAULT: {
40980
+ const string = this.bufferedString.toString();
40981
+ this.onToken({
40982
+ token: TokenType.STRING,
40983
+ value: string,
40984
+ offset: this.offset,
40985
+ partial: true,
40986
+ });
40987
+ break;
40988
+ }
40989
+ case TokenizerStates.NUMBER_AFTER_INITIAL_ZERO:
40990
+ case TokenizerStates.NUMBER_AFTER_INITIAL_NON_ZERO:
40991
+ case TokenizerStates.NUMBER_AFTER_DECIMAL:
40992
+ case TokenizerStates.NUMBER_AFTER_E_AND_DIGIT:
40993
+ try {
40994
+ this.onToken({
40995
+ token: TokenType.NUMBER,
40996
+ value: this.parseNumber(this.bufferedNumber.toString()),
40997
+ offset: this.offset,
40998
+ partial: true,
40999
+ });
41000
+ }
41001
+ catch (_a) {
41002
+ }
41003
+ }
41004
+ }
41005
+ }
41006
+ catch (err) {
41007
+ this.error(err);
41008
+ }
41009
+ }
41010
+ emitNumber() {
41011
+ this.onToken({
41012
+ token: TokenType.NUMBER,
41013
+ value: this.parseNumber(this.bufferedNumber.toString()),
41014
+ offset: this.offset,
41015
+ });
41016
+ this.offset += this.bufferedNumber.byteLength - 1;
41017
+ }
41018
+ parseNumber(numberStr) {
41019
+ return Number(numberStr);
41020
+ }
41021
+ error(err) {
41022
+ if (this.state !== TokenizerStates.ENDED) {
41023
+ this.state = TokenizerStates.ERROR;
41024
+ }
41025
+ this.onError(err);
41026
+ }
41027
+ end() {
41028
+ switch (this.state) {
41029
+ case TokenizerStates.NUMBER_AFTER_INITIAL_ZERO:
41030
+ case TokenizerStates.NUMBER_AFTER_INITIAL_NON_ZERO:
41031
+ case TokenizerStates.NUMBER_AFTER_DECIMAL:
41032
+ case TokenizerStates.NUMBER_AFTER_E_AND_DIGIT:
41033
+ this.state = TokenizerStates.ENDED;
41034
+ this.emitNumber();
41035
+ this.onEnd();
41036
+ break;
41037
+ case TokenizerStates.BOM_OR_START:
41038
+ case TokenizerStates.START:
41039
+ case TokenizerStates.ERROR:
41040
+ case TokenizerStates.SEPARATOR:
41041
+ this.state = TokenizerStates.ENDED;
41042
+ this.onEnd();
41043
+ break;
41044
+ default:
41045
+ this.error(new TokenizerError(`Tokenizer ended in the middle of a token (state: ${TokenizerStateToString(this.state)}). Either not all the data was received or the data was invalid.`));
41046
+ }
41047
+ }
41048
+ onToken(parsedToken) {
41049
+ throw new TokenizerError('Can\'t emit tokens before the "onToken" callback has been set up.');
41050
+ }
41051
+ onError(err) {
41052
+ throw err;
41053
+ }
41054
+ onEnd() {
41055
+ }
41056
+ }
41057
+
41058
+ var TokenParserMode;
41059
+ (function (TokenParserMode) {
41060
+ TokenParserMode[TokenParserMode["OBJECT"] = 0] = "OBJECT";
41061
+ TokenParserMode[TokenParserMode["ARRAY"] = 1] = "ARRAY";
41062
+ })(TokenParserMode || (TokenParserMode = {}));
41063
+
41064
+ var TokenParserState;
41065
+ (function (TokenParserState) {
41066
+ TokenParserState[TokenParserState["VALUE"] = 0] = "VALUE";
41067
+ TokenParserState[TokenParserState["KEY"] = 1] = "KEY";
41068
+ TokenParserState[TokenParserState["COLON"] = 2] = "COLON";
41069
+ TokenParserState[TokenParserState["COMMA"] = 3] = "COMMA";
41070
+ TokenParserState[TokenParserState["ENDED"] = 4] = "ENDED";
41071
+ TokenParserState[TokenParserState["ERROR"] = 5] = "ERROR";
41072
+ TokenParserState[TokenParserState["SEPARATOR"] = 6] = "SEPARATOR";
41073
+ })(TokenParserState || (TokenParserState = {}));
41074
+ function TokenParserStateToString(state) {
41075
+ return ["VALUE", "KEY", "COLON", "COMMA", "ENDED", "ERROR", "SEPARATOR"][state];
41076
+ }
41077
+ const defaultOpts = {
41078
+ paths: undefined,
41079
+ keepStack: true,
41080
+ separator: undefined,
41081
+ emitPartialValues: false,
41082
+ };
41083
+ class TokenParserError extends Error {
41084
+ constructor(message) {
41085
+ super(message);
41086
+ Object.setPrototypeOf(this, TokenParserError.prototype);
41087
+ }
41088
+ }
41089
+ class TokenParser {
41090
+ constructor(opts) {
41091
+ this.state = TokenParserState.VALUE;
41092
+ this.mode = undefined;
41093
+ this.key = undefined;
41094
+ this.value = undefined;
41095
+ this.stack = [];
41096
+ opts = Object.assign(Object.assign({}, defaultOpts), opts);
41097
+ if (opts.paths) {
41098
+ this.paths = opts.paths.map((path) => {
41099
+ if (path === undefined || path === "$*")
41100
+ return undefined;
41101
+ if (!path.startsWith("$"))
41102
+ throw new TokenParserError(`Invalid selector "${path}". Should start with "$".`);
41103
+ const pathParts = path.split(".").slice(1);
41104
+ if (pathParts.includes(""))
41105
+ throw new TokenParserError(`Invalid selector "${path}". ".." syntax not supported.`);
41106
+ return pathParts;
41107
+ });
41108
+ }
41109
+ this.keepStack = opts.keepStack || false;
41110
+ this.separator = opts.separator;
41111
+ if (!opts.emitPartialValues) {
41112
+ this.emitPartial = () => { };
41113
+ }
41114
+ }
41115
+ shouldEmit() {
41116
+ if (!this.paths)
41117
+ return true;
41118
+ return this.paths.some((path) => {
41119
+ var _a;
41120
+ if (path === undefined)
41121
+ return true;
41122
+ if (path.length !== this.stack.length)
41123
+ return false;
41124
+ for (let i = 0; i < path.length - 1; i++) {
41125
+ const selector = path[i];
41126
+ const key = this.stack[i + 1].key;
41127
+ if (selector === "*")
41128
+ continue;
41129
+ if (selector !== (key === null || key === void 0 ? void 0 : key.toString()))
41130
+ return false;
41131
+ }
41132
+ const selector = path[path.length - 1];
41133
+ if (selector === "*")
41134
+ return true;
41135
+ return selector === ((_a = this.key) === null || _a === void 0 ? void 0 : _a.toString());
41136
+ });
41137
+ }
41138
+ push() {
41139
+ this.stack.push({
41140
+ key: this.key,
41141
+ value: this.value,
41142
+ mode: this.mode,
41143
+ emit: this.shouldEmit(),
41144
+ });
41145
+ }
41146
+ pop() {
41147
+ const value = this.value;
41148
+ let emit;
41149
+ ({
41150
+ key: this.key,
41151
+ value: this.value,
41152
+ mode: this.mode,
41153
+ emit,
41154
+ } = this.stack.pop());
41155
+ this.state =
41156
+ this.mode !== undefined ? TokenParserState.COMMA : TokenParserState.VALUE;
41157
+ this.emit(value, emit);
41158
+ }
41159
+ emit(value, emit) {
41160
+ if (!this.keepStack &&
41161
+ this.value &&
41162
+ this.stack.every((item) => !item.emit)) {
41163
+ delete this.value[this.key];
41164
+ }
41165
+ if (emit) {
41166
+ this.onValue({
41167
+ value: value,
41168
+ key: this.key,
41169
+ parent: this.value,
41170
+ stack: this.stack,
41171
+ });
41172
+ }
41173
+ if (this.stack.length === 0) {
41174
+ if (this.separator) {
41175
+ this.state = TokenParserState.SEPARATOR;
41176
+ }
41177
+ else if (this.separator === undefined) {
41178
+ this.end();
41179
+ }
41180
+ }
41181
+ }
41182
+ emitPartial(value) {
41183
+ if (!this.shouldEmit())
41184
+ return;
41185
+ if (this.state === TokenParserState.KEY) {
41186
+ this.onValue({
41187
+ value: undefined,
41188
+ key: value,
41189
+ parent: this.value,
41190
+ stack: this.stack,
41191
+ partial: true,
41192
+ });
41193
+ return;
41194
+ }
41195
+ this.onValue({
41196
+ value: value,
41197
+ key: this.key,
41198
+ parent: this.value,
41199
+ stack: this.stack,
41200
+ partial: true,
41201
+ });
41202
+ }
41203
+ get isEnded() {
41204
+ return this.state === TokenParserState.ENDED;
41205
+ }
41206
+ write({ token, value, partial, }) {
41207
+ try {
41208
+ if (partial) {
41209
+ this.emitPartial(value);
41210
+ return;
41211
+ }
41212
+ if (this.state === TokenParserState.VALUE) {
41213
+ if (token === TokenType.STRING ||
41214
+ token === TokenType.NUMBER ||
41215
+ token === TokenType.TRUE ||
41216
+ token === TokenType.FALSE ||
41217
+ token === TokenType.NULL) {
41218
+ if (this.mode === TokenParserMode.OBJECT) {
41219
+ this.value[this.key] = value;
41220
+ this.state = TokenParserState.COMMA;
41221
+ }
41222
+ else if (this.mode === TokenParserMode.ARRAY) {
41223
+ this.value.push(value);
41224
+ this.state = TokenParserState.COMMA;
41225
+ }
41226
+ this.emit(value, this.shouldEmit());
41227
+ return;
41228
+ }
41229
+ if (token === TokenType.LEFT_BRACE) {
41230
+ this.push();
41231
+ if (this.mode === TokenParserMode.OBJECT) {
41232
+ this.value = this.value[this.key] = {};
41233
+ }
41234
+ else if (this.mode === TokenParserMode.ARRAY) {
41235
+ const val = {};
41236
+ this.value.push(val);
41237
+ this.value = val;
41238
+ }
41239
+ else {
41240
+ this.value = {};
41241
+ }
41242
+ this.mode = TokenParserMode.OBJECT;
41243
+ this.state = TokenParserState.KEY;
41244
+ this.key = undefined;
41245
+ this.emitPartial();
41246
+ return;
41247
+ }
41248
+ if (token === TokenType.LEFT_BRACKET) {
41249
+ this.push();
41250
+ if (this.mode === TokenParserMode.OBJECT) {
41251
+ this.value = this.value[this.key] = [];
41252
+ }
41253
+ else if (this.mode === TokenParserMode.ARRAY) {
41254
+ const val = [];
41255
+ this.value.push(val);
41256
+ this.value = val;
41257
+ }
41258
+ else {
41259
+ this.value = [];
41260
+ }
41261
+ this.mode = TokenParserMode.ARRAY;
41262
+ this.state = TokenParserState.VALUE;
41263
+ this.key = 0;
41264
+ this.emitPartial();
41265
+ return;
41266
+ }
41267
+ if (this.mode === TokenParserMode.ARRAY &&
41268
+ token === TokenType.RIGHT_BRACKET &&
41269
+ this.value.length === 0) {
41270
+ this.pop();
41271
+ return;
41272
+ }
41273
+ }
41274
+ if (this.state === TokenParserState.KEY) {
41275
+ if (token === TokenType.STRING) {
41276
+ this.key = value;
41277
+ this.state = TokenParserState.COLON;
41278
+ this.emitPartial();
41279
+ return;
41280
+ }
41281
+ if (token === TokenType.RIGHT_BRACE &&
41282
+ Object.keys(this.value).length === 0) {
41283
+ this.pop();
41284
+ return;
41285
+ }
41286
+ }
41287
+ if (this.state === TokenParserState.COLON) {
41288
+ if (token === TokenType.COLON) {
41289
+ this.state = TokenParserState.VALUE;
41290
+ return;
41291
+ }
41292
+ }
41293
+ if (this.state === TokenParserState.COMMA) {
41294
+ if (token === TokenType.COMMA) {
41295
+ if (this.mode === TokenParserMode.ARRAY) {
41296
+ this.state = TokenParserState.VALUE;
41297
+ this.key += 1;
41298
+ return;
41299
+ }
41300
+ if (this.mode === TokenParserMode.OBJECT) {
41301
+ this.state = TokenParserState.KEY;
41302
+ return;
41303
+ }
41304
+ }
41305
+ if ((token === TokenType.RIGHT_BRACE &&
41306
+ this.mode === TokenParserMode.OBJECT) ||
41307
+ (token === TokenType.RIGHT_BRACKET &&
41308
+ this.mode === TokenParserMode.ARRAY)) {
41309
+ this.pop();
41310
+ return;
41311
+ }
41312
+ }
41313
+ if (this.state === TokenParserState.SEPARATOR) {
41314
+ if (token === TokenType.SEPARATOR && value === this.separator) {
41315
+ this.state = TokenParserState.VALUE;
41316
+ return;
41317
+ }
41318
+ }
41319
+ if (token === TokenType.SEPARATOR &&
41320
+ this.state !== TokenParserState.SEPARATOR &&
41321
+ Array.from(value)
41322
+ .map((n) => n.charCodeAt(0))
41323
+ .every((n) => n === charset.SPACE ||
41324
+ n === charset.NEWLINE ||
41325
+ n === charset.CARRIAGE_RETURN ||
41326
+ n === charset.TAB)) {
41327
+ return;
41328
+ }
41329
+ throw new TokenParserError(`Unexpected ${TokenType[token]} (${JSON.stringify(value)}) in state ${TokenParserStateToString(this.state)}`);
41330
+ }
41331
+ catch (err) {
41332
+ this.error(err);
41333
+ }
41334
+ }
41335
+ error(err) {
41336
+ if (this.state !== TokenParserState.ENDED) {
41337
+ this.state = TokenParserState.ERROR;
40141
41338
  }
41339
+ this.onError(err);
41340
+ }
41341
+ end() {
41342
+ if ((this.state !== TokenParserState.VALUE &&
41343
+ this.state !== TokenParserState.SEPARATOR) ||
41344
+ this.stack.length > 0) {
41345
+ this.error(new Error(`Parser ended in mid-parsing (state: ${TokenParserStateToString(this.state)}). Either not all the data was received or the data was invalid.`));
41346
+ }
41347
+ else {
41348
+ this.state = TokenParserState.ENDED;
41349
+ this.onEnd();
41350
+ }
41351
+ }
41352
+ onValue(parsedElementInfo) {
41353
+ throw new TokenParserError('Can\'t emit data before the "onValue" callback has been set up.');
41354
+ }
41355
+ onError(err) {
41356
+ throw err;
41357
+ }
41358
+ onEnd() {
41359
+ }
41360
+ }
41361
+
41362
+ class JSONParser {
41363
+ constructor(opts = {}) {
41364
+ this.tokenizer = new Tokenizer(opts);
41365
+ this.tokenParser = new TokenParser(opts);
41366
+ this.tokenizer.onToken = this.tokenParser.write.bind(this.tokenParser);
41367
+ this.tokenizer.onEnd = () => {
41368
+ if (!this.tokenParser.isEnded)
41369
+ this.tokenParser.end();
41370
+ };
41371
+ this.tokenParser.onError = this.tokenizer.error.bind(this.tokenizer);
41372
+ this.tokenParser.onEnd = () => {
41373
+ if (!this.tokenizer.isEnded)
41374
+ this.tokenizer.end();
41375
+ };
41376
+ }
41377
+ get isEnded() {
41378
+ return this.tokenizer.isEnded && this.tokenParser.isEnded;
41379
+ }
41380
+ write(input) {
41381
+ this.tokenizer.write(input);
41382
+ }
41383
+ end() {
41384
+ this.tokenizer.end();
41385
+ }
41386
+ set onToken(cb) {
41387
+ this.tokenizer.onToken = (parsedToken) => {
41388
+ cb(parsedToken);
41389
+ this.tokenParser.write(parsedToken);
41390
+ };
41391
+ }
41392
+ set onValue(cb) {
41393
+ this.tokenParser.onValue = cb;
41394
+ }
41395
+ set onError(cb) {
41396
+ this.tokenizer.onError = cb;
41397
+ }
41398
+ set onEnd(cb) {
41399
+ this.tokenParser.onEnd = () => {
41400
+ if (!this.tokenizer.isEnded)
41401
+ this.tokenizer.end();
41402
+ cb.call(this.tokenParser);
41403
+ };
41404
+ }
41405
+ }
41406
+
41407
+ class JSONStreamParser extends JSONParser {
41408
+ constructor(data) {
41409
+ super();
41410
+ this.onValue = ({ value, stack }) => {
41411
+ if (stack.length === 0)
41412
+ this.json = value;
41413
+ };
41414
+ if (data)
41415
+ this.write(data);
40142
41416
  }
40143
41417
  }
40144
41418
 
@@ -40225,13 +41499,13 @@ void main() {
40225
41499
  this.viewer.models.push(modelImpl);
40226
41500
  this.viewer.syncOptions();
40227
41501
  this.viewer.syncOverlay();
40228
- this.viewer.update();
40229
41502
  this.viewer.emitEvent({ type: "databasechunk", data: scene, file });
41503
+ this.viewer.update(true);
40230
41504
  });
40231
41505
  this.gltfLoader.addEventListener("geometryerror", (data) => {
40232
41506
  this.viewer.emitEvent({ type: "geometryerror", data, file });
40233
41507
  });
40234
- this.gltfLoader.addEventListener("update", (data) => {
41508
+ this.gltfLoader.addEventListener("update", () => {
40235
41509
  this.viewer.update();
40236
41510
  });
40237
41511
  const loadController = {
@@ -40247,13 +41521,13 @@ void main() {
40247
41521
  this.viewer.emitEvent({ type: "geometryprogress", data: progress, file });
40248
41522
  };
40249
41523
  const data = await loader.loadAsync(this.manager.fileURL, progress);
40250
- const extension = new GLTFBinaryExtension(data);
40251
- this.gltf = JSON.parse(extension.content);
40252
- this.glb = extension.body;
40253
- if (/\.glb$/i.test(this.manager.fileURL) && !this.glb) {
40254
- throw new Error("GLTFFileDynamicLoader: Binary buffer chunk not found or type not supported.");
41524
+ const binaryParser = new GLTFBinaryParser(data);
41525
+ const jsonParser = new JSONStreamParser(binaryParser.content);
41526
+ if (!jsonParser.json) {
41527
+ throw new Error("GLTFFileDynamicLoader: JSON content not found or invalid.");
40255
41528
  }
40256
- return this.gltf;
41529
+ this.glb = binaryParser.body;
41530
+ return jsonParser.json;
40257
41531
  },
40258
41532
  loadBinaryData: (ranges, uri = "") => {
40259
41533
  const loader = new RangesLoader();
@@ -40313,24 +41587,27 @@ void main() {
40313
41587
  this.viewer.models.push(modelImpl);
40314
41588
  this.viewer.syncOptions();
40315
41589
  this.viewer.syncOverlay();
40316
- this.viewer.update();
40317
41590
  this.viewer.emitEvent({ type: "databasechunk", data: scene, file: model.file, model });
41591
+ this.viewer.update(true);
40318
41592
  });
40319
41593
  this.gltfLoader.addEventListener("geometryerror", (data) => {
40320
41594
  this.viewer.emitEvent({ type: "geometryerror", data, file: model.file, model });
40321
41595
  });
40322
- this.gltfLoader.addEventListener("update", (data) => {
41596
+ this.gltfLoader.addEventListener("update", () => {
40323
41597
  this.viewer.update();
40324
41598
  });
40325
41599
  const loadController = {
40326
41600
  loadJson: async () => {
40327
- const progress = (progress) => {
41601
+ const jsonParser = new JSONStreamParser();
41602
+ const progress = (progress, chunk) => {
41603
+ jsonParser.write(chunk);
40328
41604
  this.viewer.emitEvent({ type: "geometryprogress", data: progress, file: model.file, model });
40329
41605
  };
40330
- const arrayBuffer = await model.downloadResource(model.database, progress, this.gltfLoader.getAbortController().signal);
40331
- const text = new TextDecoder().decode(arrayBuffer);
40332
- const json = JSON.parse(text);
40333
- return json;
41606
+ await model.downloadResource(model.database, progress, this.gltfLoader.getAbortController().signal);
41607
+ if (!jsonParser.json) {
41608
+ throw new Error("GLTFCloudDynamicLoader: JSON content not found or invalid.");
41609
+ }
41610
+ return jsonParser.json;
40334
41611
  },
40335
41612
  loadBinaryData: (requests) => {
40336
41613
  const ranges = requests.map((request) => ({
@@ -55456,11 +56733,13 @@ js: import "konva/skia-backend";
55456
56733
  this.syncOptions();
55457
56734
  this.syncOverlay();
55458
56735
  this._renderTime = performance.now();
55459
- this.render(this._renderTime);
55460
- if (typeof onProgress === "function")
55461
- onProgress(new ProgressEvent("progress", { lengthComputable: true, loaded: 1, total: 1 }));
56736
+ if (typeof onProgress === "function") {
56737
+ const event = new ProgressEvent("progress", { lengthComputable: true, loaded: 1, total: 1 });
56738
+ onProgress(event);
56739
+ }
55462
56740
  this.emitEvent({ type: "initializeprogress", data: 1, loaded: 1, total: 1 });
55463
56741
  this.emitEvent({ type: "initialize" });
56742
+ this.update(true);
55464
56743
  return Promise.resolve(this);
55465
56744
  }
55466
56745
  dispose() {
@@ -55524,8 +56803,8 @@ js: import "konva/skia-backend";
55524
56803
  }
55525
56804
  this.renderer.setSize(width, height, updateStyle);
55526
56805
  this.composer.setSize(width, height);
55527
- this.update(true);
55528
56806
  this.emitEvent({ type: "resize", width, height });
56807
+ this.update(true);
55529
56808
  }
55530
56809
  update(force = false) {
55531
56810
  const time = performance.now();
@@ -55535,11 +56814,11 @@ js: import "konva/skia-backend";
55535
56814
  this.render(time);
55536
56815
  this.emitEvent({ type: "update", force });
55537
56816
  }
55538
- render(time) {
56817
+ render(time, force = false) {
55539
56818
  var _a, _b;
55540
56819
  if (!this.renderer)
55541
56820
  return;
55542
- if (!this._renderNeeded)
56821
+ if (!this._renderNeeded && !force)
55543
56822
  return;
55544
56823
  if (!time)
55545
56824
  time = performance.now();
@@ -55578,10 +56857,8 @@ js: import "konva/skia-backend";
55578
56857
  if (model && typeof model.database === "string") {
55579
56858
  file = model.file;
55580
56859
  }
55581
- if (!model)
55582
- throw new Error(`Format not supported`);
55583
56860
  let format = params.format;
55584
- if (!format && typeof file["type"] === "string")
56861
+ if (!format && file && typeof file["type"] === "string")
55585
56862
  format = file["type"].split(".").pop();
55586
56863
  if (!format && typeof file === "string")
55587
56864
  format = file.split(".").pop();
@@ -55589,7 +56866,7 @@ js: import "konva/skia-backend";
55589
56866
  format = file.name.split(".").pop();
55590
56867
  const loader = loaders.createLoader(this, model, format);
55591
56868
  if (!loader)
55592
- throw new Error(`Format not supported`);
56869
+ throw new Error(`Format not supported (${format})`);
55593
56870
  this.loaders.push(loader);
55594
56871
  this.emitEvent({ type: "geometrystart", file, model });
55595
56872
  try {
@@ -55601,6 +56878,7 @@ js: import "konva/skia-backend";
55601
56878
  throw error;
55602
56879
  }
55603
56880
  this.emitEvent({ type: "geometryend", file, model });
56881
+ this.update(true);
55604
56882
  return this;
55605
56883
  }
55606
56884
  openGltfFile(file, externalFiles, params = {}) {
@@ -55630,11 +56908,10 @@ js: import "konva/skia-backend";
55630
56908
  this.scene.clear();
55631
56909
  this.helpers.clear();
55632
56910
  this.extents.makeEmpty();
55633
- this.target.set(0, 0, 0);
55634
56911
  this.syncOptions();
55635
56912
  this.syncOverlay();
55636
- this.update(true);
55637
56913
  this.emitEvent({ type: "clear" });
56914
+ this.update(true);
55638
56915
  return this;
55639
56916
  }
55640
56917
  is3D() {
@@ -55746,7 +57023,7 @@ js: import "konva/skia-backend";
55746
57023
  const getVector3FromPoint3d = ({ x, y, z }) => new Vector3(x, y, z);
55747
57024
  const setOrthogonalCamera = (orthogonal_camera) => {
55748
57025
  if (orthogonal_camera) {
55749
- const extentsSize = this.extents.getBoundingSphere(new Sphere()).radius * 2;
57026
+ const extentsSize = this.extents.getSize(new Vector3()).length() || 1;
55750
57027
  const rendererSize = this.renderer.getSize(new Vector2());
55751
57028
  const aspectRatio = rendererSize.x / rendererSize.y;
55752
57029
  const camera = new OrthographicCamera();
@@ -55772,7 +57049,7 @@ js: import "konva/skia-backend";
55772
57049
  };
55773
57050
  const setPerspectiveCamera = (perspective_camera) => {
55774
57051
  if (perspective_camera) {
55775
- const extentsSize = this.extents.getBoundingSphere(new Sphere()).radius * 2;
57052
+ const extentsSize = this.extents.getSize(new Vector3()).length() || 1;
55776
57053
  const rendererSize = this.renderer.getSize(new Vector2());
55777
57054
  const aspectRatio = rendererSize.x / rendererSize.y;
55778
57055
  const camera = new PerspectiveCamera();
@@ -55822,7 +57099,7 @@ js: import "konva/skia-backend";
55822
57099
  this.syncOverlay();
55823
57100
  this.setActiveDragger(draggerName);
55824
57101
  this.emitEvent({ type: "drawviewpoint", data: viewpoint });
55825
- this.update();
57102
+ this.update(true);
55826
57103
  }
55827
57104
  createViewpoint() {
55828
57105
  if (!this.renderer)
@@ -55903,11 +57180,9 @@ js: import "konva/skia-backend";
55903
57180
  }
55904
57181
  return { x: intersectionPoint.x, y: intersectionPoint.y, z: intersectionPoint.z };
55905
57182
  }
55906
- else {
55907
- const point = new Vector3(x, y, -1);
55908
- point.unproject(this.camera);
55909
- return { x: point.x, y: point.y, z: point.z };
55910
- }
57183
+ const point = new Vector3(x, y, -1);
57184
+ point.unproject(this.camera);
57185
+ return { x: point.x, y: point.y, z: point.z };
55911
57186
  }
55912
57187
  worldToScreen(position) {
55913
57188
  if (!this.renderer)