@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.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,48 @@ 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.alignItems = "flex-start";
6301
+ scrollWrapper.style.justifyContent = "flex-start";
6302
+ scrollWrapper.style.boxSizing = "border-box";
6303
+ const sizer = document.createElement("div");
6304
+ sizer.className = "fp-3d-sizer";
6305
+ sizer.style.position = "relative";
6306
+ sizer.style.flexShrink = "0";
6307
+ sizer.style.display = "flex";
6308
+ sizer.style.justifyContent = "center";
6309
+ sizer.style.alignItems = "center";
6310
+ sizer.style.margin = "auto";
6278
6311
  const scene = new THREE.Scene();
6279
6312
  scene.background = new THREE.Color(1973796);
6280
- const camera = new THREE.PerspectiveCamera(45, width / height, 0.1, 2e3);
6313
+ const camera = new THREE.PerspectiveCamera(45, baseW / baseH, 0.1, 2e3);
6281
6314
  const renderer = new THREE.WebGLRenderer({ antialias: true });
6282
- renderer.setSize(width, height);
6283
- renderer.setPixelRatio(window.devicePixelRatio);
6315
+ renderer.setSize(baseW, baseH);
6316
+ renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
6284
6317
  renderer.shadowMap.enabled = true;
6285
- container.appendChild(renderer.domElement);
6318
+ sizer.appendChild(renderer.domElement);
6319
+ scrollWrapper.appendChild(sizer);
6320
+ container.appendChild(scrollWrapper);
6286
6321
  const controls = new OrbitControls(camera, renderer.domElement);
6287
6322
  controls.enableDamping = true;
6288
6323
  controls.dampingFactor = 0.05;
@@ -6296,7 +6331,7 @@ var ThreeDPlugin = class {
6296
6331
  scene.add(dirLight2);
6297
6332
  const grid = new THREE.GridHelper(200, 20, 4473924, 2236962);
6298
6333
  scene.add(grid);
6299
- let meshGroup = new THREE.Group();
6334
+ const meshGroup = new THREE.Group();
6300
6335
  let isWireframe = false;
6301
6336
  const ext = ctx.metadata.extension?.toLowerCase();
6302
6337
  const materials = [];
@@ -6352,6 +6387,26 @@ var ThreeDPlugin = class {
6352
6387
  controls.update();
6353
6388
  };
6354
6389
  fitCamera();
6390
+ const applyZoom = () => {
6391
+ if (!isUserZoomed) {
6392
+ updateBaseDimensions();
6393
+ }
6394
+ const boxW = Math.round(baseW * currentZoom);
6395
+ const boxH = Math.round(baseH * currentZoom);
6396
+ sizer.style.width = `${boxW}px`;
6397
+ sizer.style.height = `${boxH}px`;
6398
+ const marginV = boxH < container.clientHeight ? "auto" : "0";
6399
+ const marginH = boxW < container.clientWidth ? "auto" : "0";
6400
+ sizer.style.margin = `${marginV} ${marginH}`;
6401
+ renderer.domElement.style.width = `${boxW}px`;
6402
+ renderer.domElement.style.height = `${boxH}px`;
6403
+ renderer.domElement.style.maxWidth = "none";
6404
+ renderer.domElement.style.maxHeight = "none";
6405
+ renderer.setSize(boxW, boxH, false);
6406
+ camera.aspect = boxW / boxH;
6407
+ camera.updateProjectionMatrix();
6408
+ };
6409
+ applyZoom();
6355
6410
  let animId;
6356
6411
  const animate = () => {
6357
6412
  animId = requestAnimationFrame(animate);
@@ -6360,11 +6415,10 @@ var ThreeDPlugin = class {
6360
6415
  };
6361
6416
  animate();
6362
6417
  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);
6418
+ if (!isUserZoomed && currentZoom === 1) {
6419
+ updateBaseDimensions();
6420
+ applyZoom();
6421
+ }
6368
6422
  });
6369
6423
  resizeObserver.observe(container);
6370
6424
  const cleanup = () => {
@@ -6378,22 +6432,57 @@ var ThreeDPlugin = class {
6378
6432
  child.geometry.dispose();
6379
6433
  }
6380
6434
  });
6435
+ scrollWrapper.remove();
6381
6436
  container.innerHTML = "";
6382
6437
  };
6383
6438
  ctx.signal.addEventListener("abort", cleanup);
6384
6439
  return {
6385
6440
  destroy: cleanup,
6386
6441
  zoomIn: () => {
6387
- camera.position.multiplyScalar(0.85);
6388
- controls.update();
6442
+ isUserZoomed = true;
6443
+ currentZoom = Math.min(5, Number((currentZoom * 1.25).toFixed(2)));
6444
+ applyZoom();
6389
6445
  },
6390
6446
  zoomOut: () => {
6391
- camera.position.multiplyScalar(1.15);
6392
- controls.update();
6447
+ currentZoom = Math.max(0.2, Number((currentZoom / 1.25).toFixed(2)));
6448
+ if (currentZoom <= 1) {
6449
+ isUserZoomed = false;
6450
+ }
6451
+ applyZoom();
6452
+ },
6453
+ getZoom: () => currentZoom,
6454
+ setZoom: (level) => {
6455
+ isUserZoomed = level !== 1;
6456
+ currentZoom = Math.max(0.2, Math.min(5, level));
6457
+ applyZoom();
6458
+ },
6459
+ fitToPage: () => {
6460
+ isUserZoomed = false;
6461
+ currentZoom = 1;
6462
+ updateBaseDimensions();
6463
+ applyZoom();
6464
+ container.scrollTop = 0;
6465
+ container.scrollLeft = 0;
6466
+ fitCamera();
6467
+ },
6468
+ fitToWidth: () => {
6469
+ isUserZoomed = false;
6470
+ currentZoom = 1;
6471
+ updateBaseDimensions();
6472
+ applyZoom();
6473
+ container.scrollTop = 0;
6474
+ container.scrollLeft = 0;
6475
+ fitCamera();
6476
+ },
6477
+ resetZoom: () => {
6478
+ isUserZoomed = false;
6479
+ currentZoom = 1;
6480
+ updateBaseDimensions();
6481
+ applyZoom();
6482
+ container.scrollTop = 0;
6483
+ container.scrollLeft = 0;
6484
+ fitCamera();
6393
6485
  },
6394
- fitToPage: fitCamera,
6395
- fitToWidth: fitCamera,
6396
- resetZoom: fitCamera,
6397
6486
  rotateCW: () => {
6398
6487
  isWireframe = !isWireframe;
6399
6488
  materials.forEach((m) => {