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

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.js CHANGED
@@ -6224,7 +6224,7 @@ var ThreeDPlugin = class {
6224
6224
  {
6225
6225
  id: "fit-page",
6226
6226
  icon: "fit-page",
6227
- label: "Reset Camera View",
6227
+ label: "Fit to Page",
6228
6228
  type: "button",
6229
6229
  group: "zoom",
6230
6230
  execute: () => instance.fitToPage?.()
@@ -6237,6 +6237,14 @@ var ThreeDPlugin = class {
6237
6237
  group: "zoom",
6238
6238
  execute: () => instance.resetZoom?.()
6239
6239
  },
6240
+ {
6241
+ id: "fit-width",
6242
+ icon: "fit-width",
6243
+ label: "Fit to Width",
6244
+ type: "button",
6245
+ group: "zoom",
6246
+ execute: () => instance.fitToWidth?.()
6247
+ },
6240
6248
  {
6241
6249
  id: "rotate-cw",
6242
6250
  icon: "rotate-cw",
@@ -6268,21 +6276,49 @@ var ThreeDPlugin = class {
6268
6276
  async render(ctx) {
6269
6277
  const container = ctx.container;
6270
6278
  container.innerHTML = "";
6271
- container.style.overflow = "hidden";
6279
+ container.style.overflow = "auto";
6272
6280
  container.style.position = "relative";
6273
6281
  container.style.width = "100%";
6274
6282
  container.style.height = "100%";
6283
+ container.style.padding = "0";
6275
6284
  container.style.background = "#1a1a1a";
6276
- const width = container.clientWidth || 800;
6277
- const height = container.clientHeight || 600;
6285
+ let currentZoom = 1;
6286
+ let isUserZoomed = false;
6287
+ let baseW = Math.max(100, container.clientWidth || 800);
6288
+ let baseH = Math.max(100, container.clientHeight || 600);
6289
+ const updateBaseDimensions = () => {
6290
+ baseW = Math.max(100, container.clientWidth || 800);
6291
+ baseH = Math.max(100, container.clientHeight || 600);
6292
+ };
6293
+ const scrollWrapper = document.createElement("div");
6294
+ scrollWrapper.className = "fp-3d-scroll-wrapper";
6295
+ scrollWrapper.style.minWidth = "100%";
6296
+ scrollWrapper.style.minHeight = "100%";
6297
+ scrollWrapper.style.width = "max-content";
6298
+ scrollWrapper.style.height = "max-content";
6299
+ scrollWrapper.style.display = "flex";
6300
+ scrollWrapper.style.flexDirection = "column";
6301
+ scrollWrapper.style.alignItems = "center";
6302
+ scrollWrapper.style.justifyContent = "flex-start";
6303
+ scrollWrapper.style.boxSizing = "border-box";
6304
+ const sizer = document.createElement("div");
6305
+ sizer.className = "fp-3d-sizer";
6306
+ sizer.style.position = "relative";
6307
+ sizer.style.flexShrink = "0";
6308
+ sizer.style.display = "flex";
6309
+ sizer.style.justifyContent = "center";
6310
+ sizer.style.alignItems = "center";
6311
+ sizer.style.margin = "auto 0";
6278
6312
  const scene = new THREE.Scene();
6279
6313
  scene.background = new THREE.Color(1973796);
6280
- const camera = new THREE.PerspectiveCamera(45, width / height, 0.1, 2e3);
6314
+ const camera = new THREE.PerspectiveCamera(45, baseW / baseH, 0.1, 2e3);
6281
6315
  const renderer = new THREE.WebGLRenderer({ antialias: true });
6282
- renderer.setSize(width, height);
6283
- renderer.setPixelRatio(window.devicePixelRatio);
6316
+ renderer.setSize(baseW, baseH);
6317
+ renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
6284
6318
  renderer.shadowMap.enabled = true;
6285
- container.appendChild(renderer.domElement);
6319
+ sizer.appendChild(renderer.domElement);
6320
+ scrollWrapper.appendChild(sizer);
6321
+ container.appendChild(scrollWrapper);
6286
6322
  const controls = new OrbitControls(camera, renderer.domElement);
6287
6323
  controls.enableDamping = true;
6288
6324
  controls.dampingFactor = 0.05;
@@ -6296,7 +6332,7 @@ var ThreeDPlugin = class {
6296
6332
  scene.add(dirLight2);
6297
6333
  const grid = new THREE.GridHelper(200, 20, 4473924, 2236962);
6298
6334
  scene.add(grid);
6299
- let meshGroup = new THREE.Group();
6335
+ const meshGroup = new THREE.Group();
6300
6336
  let isWireframe = false;
6301
6337
  const ext = ctx.metadata.extension?.toLowerCase();
6302
6338
  const materials = [];
@@ -6352,6 +6388,24 @@ var ThreeDPlugin = class {
6352
6388
  controls.update();
6353
6389
  };
6354
6390
  fitCamera();
6391
+ const applyZoom = () => {
6392
+ if (!isUserZoomed) {
6393
+ updateBaseDimensions();
6394
+ }
6395
+ const boxW = Math.round(baseW * currentZoom);
6396
+ const boxH = Math.round(baseH * currentZoom);
6397
+ sizer.style.width = `${boxW}px`;
6398
+ sizer.style.height = `${boxH}px`;
6399
+ sizer.style.margin = boxH < container.clientHeight ? "auto 0" : "0";
6400
+ renderer.domElement.style.width = `${boxW}px`;
6401
+ renderer.domElement.style.height = `${boxH}px`;
6402
+ renderer.domElement.style.maxWidth = "none";
6403
+ renderer.domElement.style.maxHeight = "none";
6404
+ renderer.setSize(boxW, boxH, false);
6405
+ camera.aspect = boxW / boxH;
6406
+ camera.updateProjectionMatrix();
6407
+ };
6408
+ applyZoom();
6355
6409
  let animId;
6356
6410
  const animate = () => {
6357
6411
  animId = requestAnimationFrame(animate);
@@ -6360,11 +6414,10 @@ var ThreeDPlugin = class {
6360
6414
  };
6361
6415
  animate();
6362
6416
  const resizeObserver = new ResizeObserver(() => {
6363
- const newWidth = container.clientWidth || 800;
6364
- const newHeight = container.clientHeight || 600;
6365
- camera.aspect = newWidth / newHeight;
6366
- camera.updateProjectionMatrix();
6367
- renderer.setSize(newWidth, newHeight);
6417
+ if (!isUserZoomed && currentZoom === 1) {
6418
+ updateBaseDimensions();
6419
+ applyZoom();
6420
+ }
6368
6421
  });
6369
6422
  resizeObserver.observe(container);
6370
6423
  const cleanup = () => {
@@ -6378,22 +6431,51 @@ var ThreeDPlugin = class {
6378
6431
  child.geometry.dispose();
6379
6432
  }
6380
6433
  });
6434
+ scrollWrapper.remove();
6381
6435
  container.innerHTML = "";
6382
6436
  };
6383
6437
  ctx.signal.addEventListener("abort", cleanup);
6384
6438
  return {
6385
6439
  destroy: cleanup,
6386
6440
  zoomIn: () => {
6387
- camera.position.multiplyScalar(0.85);
6388
- controls.update();
6441
+ isUserZoomed = true;
6442
+ currentZoom = Math.min(5, Number((currentZoom * 1.25).toFixed(2)));
6443
+ applyZoom();
6389
6444
  },
6390
6445
  zoomOut: () => {
6391
- camera.position.multiplyScalar(1.15);
6392
- controls.update();
6446
+ currentZoom = Math.max(0.2, Number((currentZoom / 1.25).toFixed(2)));
6447
+ if (currentZoom <= 1) {
6448
+ isUserZoomed = false;
6449
+ }
6450
+ applyZoom();
6451
+ },
6452
+ fitToPage: () => {
6453
+ isUserZoomed = false;
6454
+ currentZoom = 1;
6455
+ updateBaseDimensions();
6456
+ applyZoom();
6457
+ container.scrollTop = 0;
6458
+ container.scrollLeft = 0;
6459
+ fitCamera();
6460
+ },
6461
+ fitToWidth: () => {
6462
+ isUserZoomed = false;
6463
+ currentZoom = 1;
6464
+ updateBaseDimensions();
6465
+ applyZoom();
6466
+ container.scrollTop = 0;
6467
+ container.scrollLeft = 0;
6468
+ fitCamera();
6469
+ },
6470
+ resetZoom: () => {
6471
+ isUserZoomed = false;
6472
+ currentZoom = 1;
6473
+ updateBaseDimensions();
6474
+ applyZoom();
6475
+ container.scrollTop = 0;
6476
+ container.scrollLeft = 0;
6477
+ fitCamera();
6393
6478
  },
6394
- fitToPage: fitCamera,
6395
- fitToWidth: fitCamera,
6396
- resetZoom: fitCamera,
6397
6479
  rotateCW: () => {
6398
6480
  isWireframe = !isWireframe;
6399
6481
  materials.forEach((m) => {