@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/index.cjs CHANGED
@@ -6255,7 +6255,7 @@ var ThreeDPlugin = class {
6255
6255
  {
6256
6256
  id: "fit-page",
6257
6257
  icon: "fit-page",
6258
- label: "Reset Camera View",
6258
+ label: "Fit to Page",
6259
6259
  type: "button",
6260
6260
  group: "zoom",
6261
6261
  execute: () => instance.fitToPage?.()
@@ -6268,6 +6268,14 @@ var ThreeDPlugin = class {
6268
6268
  group: "zoom",
6269
6269
  execute: () => instance.resetZoom?.()
6270
6270
  },
6271
+ {
6272
+ id: "fit-width",
6273
+ icon: "fit-width",
6274
+ label: "Fit to Width",
6275
+ type: "button",
6276
+ group: "zoom",
6277
+ execute: () => instance.fitToWidth?.()
6278
+ },
6271
6279
  {
6272
6280
  id: "rotate-cw",
6273
6281
  icon: "rotate-cw",
@@ -6299,21 +6307,48 @@ var ThreeDPlugin = class {
6299
6307
  async render(ctx) {
6300
6308
  const container = ctx.container;
6301
6309
  container.innerHTML = "";
6302
- container.style.overflow = "hidden";
6310
+ container.style.overflow = "auto";
6303
6311
  container.style.position = "relative";
6304
6312
  container.style.width = "100%";
6305
6313
  container.style.height = "100%";
6314
+ container.style.padding = "0";
6306
6315
  container.style.background = "#1a1a1a";
6307
- const width = container.clientWidth || 800;
6308
- const height = container.clientHeight || 600;
6316
+ let currentZoom = 1;
6317
+ let isUserZoomed = false;
6318
+ let baseW = Math.max(100, container.clientWidth || 800);
6319
+ let baseH = Math.max(100, container.clientHeight || 600);
6320
+ const updateBaseDimensions = () => {
6321
+ baseW = Math.max(100, container.clientWidth || 800);
6322
+ baseH = Math.max(100, container.clientHeight || 600);
6323
+ };
6324
+ const scrollWrapper = document.createElement("div");
6325
+ scrollWrapper.className = "fp-3d-scroll-wrapper";
6326
+ scrollWrapper.style.minWidth = "100%";
6327
+ scrollWrapper.style.minHeight = "100%";
6328
+ scrollWrapper.style.width = "max-content";
6329
+ scrollWrapper.style.height = "max-content";
6330
+ scrollWrapper.style.display = "flex";
6331
+ scrollWrapper.style.alignItems = "flex-start";
6332
+ scrollWrapper.style.justifyContent = "flex-start";
6333
+ scrollWrapper.style.boxSizing = "border-box";
6334
+ const sizer = document.createElement("div");
6335
+ sizer.className = "fp-3d-sizer";
6336
+ sizer.style.position = "relative";
6337
+ sizer.style.flexShrink = "0";
6338
+ sizer.style.display = "flex";
6339
+ sizer.style.justifyContent = "center";
6340
+ sizer.style.alignItems = "center";
6341
+ sizer.style.margin = "auto";
6309
6342
  const scene = new THREE__namespace.Scene();
6310
6343
  scene.background = new THREE__namespace.Color(1973796);
6311
- const camera = new THREE__namespace.PerspectiveCamera(45, width / height, 0.1, 2e3);
6344
+ const camera = new THREE__namespace.PerspectiveCamera(45, baseW / baseH, 0.1, 2e3);
6312
6345
  const renderer = new THREE__namespace.WebGLRenderer({ antialias: true });
6313
- renderer.setSize(width, height);
6314
- renderer.setPixelRatio(window.devicePixelRatio);
6346
+ renderer.setSize(baseW, baseH);
6347
+ renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
6315
6348
  renderer.shadowMap.enabled = true;
6316
- container.appendChild(renderer.domElement);
6349
+ sizer.appendChild(renderer.domElement);
6350
+ scrollWrapper.appendChild(sizer);
6351
+ container.appendChild(scrollWrapper);
6317
6352
  const controls = new OrbitControls_js.OrbitControls(camera, renderer.domElement);
6318
6353
  controls.enableDamping = true;
6319
6354
  controls.dampingFactor = 0.05;
@@ -6327,7 +6362,7 @@ var ThreeDPlugin = class {
6327
6362
  scene.add(dirLight2);
6328
6363
  const grid = new THREE__namespace.GridHelper(200, 20, 4473924, 2236962);
6329
6364
  scene.add(grid);
6330
- let meshGroup = new THREE__namespace.Group();
6365
+ const meshGroup = new THREE__namespace.Group();
6331
6366
  let isWireframe = false;
6332
6367
  const ext = ctx.metadata.extension?.toLowerCase();
6333
6368
  const materials = [];
@@ -6383,6 +6418,26 @@ var ThreeDPlugin = class {
6383
6418
  controls.update();
6384
6419
  };
6385
6420
  fitCamera();
6421
+ const applyZoom = () => {
6422
+ if (!isUserZoomed) {
6423
+ updateBaseDimensions();
6424
+ }
6425
+ const boxW = Math.round(baseW * currentZoom);
6426
+ const boxH = Math.round(baseH * currentZoom);
6427
+ sizer.style.width = `${boxW}px`;
6428
+ sizer.style.height = `${boxH}px`;
6429
+ const marginV = boxH < container.clientHeight ? "auto" : "0";
6430
+ const marginH = boxW < container.clientWidth ? "auto" : "0";
6431
+ sizer.style.margin = `${marginV} ${marginH}`;
6432
+ renderer.domElement.style.width = `${boxW}px`;
6433
+ renderer.domElement.style.height = `${boxH}px`;
6434
+ renderer.domElement.style.maxWidth = "none";
6435
+ renderer.domElement.style.maxHeight = "none";
6436
+ renderer.setSize(boxW, boxH, false);
6437
+ camera.aspect = boxW / boxH;
6438
+ camera.updateProjectionMatrix();
6439
+ };
6440
+ applyZoom();
6386
6441
  let animId;
6387
6442
  const animate = () => {
6388
6443
  animId = requestAnimationFrame(animate);
@@ -6391,11 +6446,10 @@ var ThreeDPlugin = class {
6391
6446
  };
6392
6447
  animate();
6393
6448
  const resizeObserver = new ResizeObserver(() => {
6394
- const newWidth = container.clientWidth || 800;
6395
- const newHeight = container.clientHeight || 600;
6396
- camera.aspect = newWidth / newHeight;
6397
- camera.updateProjectionMatrix();
6398
- renderer.setSize(newWidth, newHeight);
6449
+ if (!isUserZoomed && currentZoom === 1) {
6450
+ updateBaseDimensions();
6451
+ applyZoom();
6452
+ }
6399
6453
  });
6400
6454
  resizeObserver.observe(container);
6401
6455
  const cleanup = () => {
@@ -6409,22 +6463,57 @@ var ThreeDPlugin = class {
6409
6463
  child.geometry.dispose();
6410
6464
  }
6411
6465
  });
6466
+ scrollWrapper.remove();
6412
6467
  container.innerHTML = "";
6413
6468
  };
6414
6469
  ctx.signal.addEventListener("abort", cleanup);
6415
6470
  return {
6416
6471
  destroy: cleanup,
6417
6472
  zoomIn: () => {
6418
- camera.position.multiplyScalar(0.85);
6419
- controls.update();
6473
+ isUserZoomed = true;
6474
+ currentZoom = Math.min(5, Number((currentZoom * 1.25).toFixed(2)));
6475
+ applyZoom();
6420
6476
  },
6421
6477
  zoomOut: () => {
6422
- camera.position.multiplyScalar(1.15);
6423
- controls.update();
6478
+ currentZoom = Math.max(0.2, Number((currentZoom / 1.25).toFixed(2)));
6479
+ if (currentZoom <= 1) {
6480
+ isUserZoomed = false;
6481
+ }
6482
+ applyZoom();
6483
+ },
6484
+ getZoom: () => currentZoom,
6485
+ setZoom: (level) => {
6486
+ isUserZoomed = level !== 1;
6487
+ currentZoom = Math.max(0.2, Math.min(5, level));
6488
+ applyZoom();
6489
+ },
6490
+ fitToPage: () => {
6491
+ isUserZoomed = false;
6492
+ currentZoom = 1;
6493
+ updateBaseDimensions();
6494
+ applyZoom();
6495
+ container.scrollTop = 0;
6496
+ container.scrollLeft = 0;
6497
+ fitCamera();
6498
+ },
6499
+ fitToWidth: () => {
6500
+ isUserZoomed = false;
6501
+ currentZoom = 1;
6502
+ updateBaseDimensions();
6503
+ applyZoom();
6504
+ container.scrollTop = 0;
6505
+ container.scrollLeft = 0;
6506
+ fitCamera();
6507
+ },
6508
+ resetZoom: () => {
6509
+ isUserZoomed = false;
6510
+ currentZoom = 1;
6511
+ updateBaseDimensions();
6512
+ applyZoom();
6513
+ container.scrollTop = 0;
6514
+ container.scrollLeft = 0;
6515
+ fitCamera();
6424
6516
  },
6425
- fitToPage: fitCamera,
6426
- fitToWidth: fitCamera,
6427
- resetZoom: fitCamera,
6428
6517
  rotateCW: () => {
6429
6518
  isWireframe = !isWireframe;
6430
6519
  materials.forEach((m) => {