@files-preview-app/preview-file 1.3.18 → 1.3.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/angular.cjs CHANGED
@@ -6221,7 +6221,7 @@ var ThreeDPlugin = class {
6221
6221
  {
6222
6222
  id: "fit-page",
6223
6223
  icon: "fit-page",
6224
- label: "Reset Camera View",
6224
+ label: "Fit to Page",
6225
6225
  type: "button",
6226
6226
  group: "zoom",
6227
6227
  execute: () => instance.fitToPage?.()
@@ -6234,6 +6234,14 @@ var ThreeDPlugin = class {
6234
6234
  group: "zoom",
6235
6235
  execute: () => instance.resetZoom?.()
6236
6236
  },
6237
+ {
6238
+ id: "fit-width",
6239
+ icon: "fit-width",
6240
+ label: "Fit to Width",
6241
+ type: "button",
6242
+ group: "zoom",
6243
+ execute: () => instance.fitToWidth?.()
6244
+ },
6237
6245
  {
6238
6246
  id: "rotate-cw",
6239
6247
  icon: "rotate-cw",
@@ -6265,21 +6273,48 @@ var ThreeDPlugin = class {
6265
6273
  async render(ctx) {
6266
6274
  const container = ctx.container;
6267
6275
  container.innerHTML = "";
6268
- container.style.overflow = "hidden";
6276
+ container.style.overflow = "auto";
6269
6277
  container.style.position = "relative";
6270
6278
  container.style.width = "100%";
6271
6279
  container.style.height = "100%";
6280
+ container.style.padding = "0";
6272
6281
  container.style.background = "#1a1a1a";
6273
- const width = container.clientWidth || 800;
6274
- const height = container.clientHeight || 600;
6282
+ let currentZoom = 1;
6283
+ let isUserZoomed = false;
6284
+ let baseW = Math.max(100, container.clientWidth || 800);
6285
+ let baseH = Math.max(100, container.clientHeight || 600);
6286
+ const updateBaseDimensions = () => {
6287
+ baseW = Math.max(100, container.clientWidth || 800);
6288
+ baseH = Math.max(100, container.clientHeight || 600);
6289
+ };
6290
+ const scrollWrapper = document.createElement("div");
6291
+ scrollWrapper.className = "fp-3d-scroll-wrapper";
6292
+ scrollWrapper.style.minWidth = "100%";
6293
+ scrollWrapper.style.minHeight = "100%";
6294
+ scrollWrapper.style.width = "max-content";
6295
+ scrollWrapper.style.height = "max-content";
6296
+ scrollWrapper.style.display = "flex";
6297
+ scrollWrapper.style.alignItems = "flex-start";
6298
+ scrollWrapper.style.justifyContent = "flex-start";
6299
+ scrollWrapper.style.boxSizing = "border-box";
6300
+ const sizer = document.createElement("div");
6301
+ sizer.className = "fp-3d-sizer";
6302
+ sizer.style.position = "relative";
6303
+ sizer.style.flexShrink = "0";
6304
+ sizer.style.display = "flex";
6305
+ sizer.style.justifyContent = "center";
6306
+ sizer.style.alignItems = "center";
6307
+ sizer.style.margin = "auto";
6275
6308
  const scene = new THREE__namespace.Scene();
6276
6309
  scene.background = new THREE__namespace.Color(1973796);
6277
- const camera = new THREE__namespace.PerspectiveCamera(45, width / height, 0.1, 2e3);
6310
+ const camera = new THREE__namespace.PerspectiveCamera(45, baseW / baseH, 0.1, 2e3);
6278
6311
  const renderer = new THREE__namespace.WebGLRenderer({ antialias: true });
6279
- renderer.setSize(width, height);
6280
- renderer.setPixelRatio(window.devicePixelRatio);
6312
+ renderer.setSize(baseW, baseH);
6313
+ renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
6281
6314
  renderer.shadowMap.enabled = true;
6282
- container.appendChild(renderer.domElement);
6315
+ sizer.appendChild(renderer.domElement);
6316
+ scrollWrapper.appendChild(sizer);
6317
+ container.appendChild(scrollWrapper);
6283
6318
  const controls = new OrbitControls_js.OrbitControls(camera, renderer.domElement);
6284
6319
  controls.enableDamping = true;
6285
6320
  controls.dampingFactor = 0.05;
@@ -6293,7 +6328,7 @@ var ThreeDPlugin = class {
6293
6328
  scene.add(dirLight2);
6294
6329
  const grid = new THREE__namespace.GridHelper(200, 20, 4473924, 2236962);
6295
6330
  scene.add(grid);
6296
- let meshGroup = new THREE__namespace.Group();
6331
+ const meshGroup = new THREE__namespace.Group();
6297
6332
  let isWireframe = false;
6298
6333
  const ext = ctx.metadata.extension?.toLowerCase();
6299
6334
  const materials = [];
@@ -6349,6 +6384,26 @@ var ThreeDPlugin = class {
6349
6384
  controls.update();
6350
6385
  };
6351
6386
  fitCamera();
6387
+ const applyZoom = () => {
6388
+ if (!isUserZoomed) {
6389
+ updateBaseDimensions();
6390
+ }
6391
+ const boxW = Math.round(baseW * currentZoom);
6392
+ const boxH = Math.round(baseH * currentZoom);
6393
+ sizer.style.width = `${boxW}px`;
6394
+ sizer.style.height = `${boxH}px`;
6395
+ const marginV = boxH < container.clientHeight ? "auto" : "0";
6396
+ const marginH = boxW < container.clientWidth ? "auto" : "0";
6397
+ sizer.style.margin = `${marginV} ${marginH}`;
6398
+ renderer.domElement.style.width = `${boxW}px`;
6399
+ renderer.domElement.style.height = `${boxH}px`;
6400
+ renderer.domElement.style.maxWidth = "none";
6401
+ renderer.domElement.style.maxHeight = "none";
6402
+ renderer.setSize(boxW, boxH, false);
6403
+ camera.aspect = boxW / boxH;
6404
+ camera.updateProjectionMatrix();
6405
+ };
6406
+ applyZoom();
6352
6407
  let animId;
6353
6408
  const animate = () => {
6354
6409
  animId = requestAnimationFrame(animate);
@@ -6357,11 +6412,10 @@ var ThreeDPlugin = class {
6357
6412
  };
6358
6413
  animate();
6359
6414
  const resizeObserver = new ResizeObserver(() => {
6360
- const newWidth = container.clientWidth || 800;
6361
- const newHeight = container.clientHeight || 600;
6362
- camera.aspect = newWidth / newHeight;
6363
- camera.updateProjectionMatrix();
6364
- renderer.setSize(newWidth, newHeight);
6415
+ if (!isUserZoomed && currentZoom === 1) {
6416
+ updateBaseDimensions();
6417
+ applyZoom();
6418
+ }
6365
6419
  });
6366
6420
  resizeObserver.observe(container);
6367
6421
  const cleanup = () => {
@@ -6375,22 +6429,57 @@ var ThreeDPlugin = class {
6375
6429
  child.geometry.dispose();
6376
6430
  }
6377
6431
  });
6432
+ scrollWrapper.remove();
6378
6433
  container.innerHTML = "";
6379
6434
  };
6380
6435
  ctx.signal.addEventListener("abort", cleanup);
6381
6436
  return {
6382
6437
  destroy: cleanup,
6383
6438
  zoomIn: () => {
6384
- camera.position.multiplyScalar(0.85);
6385
- controls.update();
6439
+ isUserZoomed = true;
6440
+ currentZoom = Math.min(5, Number((currentZoom * 1.25).toFixed(2)));
6441
+ applyZoom();
6386
6442
  },
6387
6443
  zoomOut: () => {
6388
- camera.position.multiplyScalar(1.15);
6389
- controls.update();
6444
+ currentZoom = Math.max(0.2, Number((currentZoom / 1.25).toFixed(2)));
6445
+ if (currentZoom <= 1) {
6446
+ isUserZoomed = false;
6447
+ }
6448
+ applyZoom();
6449
+ },
6450
+ getZoom: () => currentZoom,
6451
+ setZoom: (level) => {
6452
+ isUserZoomed = level !== 1;
6453
+ currentZoom = Math.max(0.2, Math.min(5, level));
6454
+ applyZoom();
6455
+ },
6456
+ fitToPage: () => {
6457
+ isUserZoomed = false;
6458
+ currentZoom = 1;
6459
+ updateBaseDimensions();
6460
+ applyZoom();
6461
+ container.scrollTop = 0;
6462
+ container.scrollLeft = 0;
6463
+ fitCamera();
6464
+ },
6465
+ fitToWidth: () => {
6466
+ isUserZoomed = false;
6467
+ currentZoom = 1;
6468
+ updateBaseDimensions();
6469
+ applyZoom();
6470
+ container.scrollTop = 0;
6471
+ container.scrollLeft = 0;
6472
+ fitCamera();
6473
+ },
6474
+ resetZoom: () => {
6475
+ isUserZoomed = false;
6476
+ currentZoom = 1;
6477
+ updateBaseDimensions();
6478
+ applyZoom();
6479
+ container.scrollTop = 0;
6480
+ container.scrollLeft = 0;
6481
+ fitCamera();
6390
6482
  },
6391
- fitToPage: fitCamera,
6392
- fitToWidth: fitCamera,
6393
- resetZoom: fitCamera,
6394
6483
  rotateCW: () => {
6395
6484
  isWireframe = !isWireframe;
6396
6485
  materials.forEach((m) => {