@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/react.cjs CHANGED
@@ -6174,7 +6174,7 @@ var ThreeDPlugin = class {
6174
6174
  {
6175
6175
  id: "fit-page",
6176
6176
  icon: "fit-page",
6177
- label: "Reset Camera View",
6177
+ label: "Fit to Page",
6178
6178
  type: "button",
6179
6179
  group: "zoom",
6180
6180
  execute: () => instance.fitToPage?.()
@@ -6187,6 +6187,14 @@ var ThreeDPlugin = class {
6187
6187
  group: "zoom",
6188
6188
  execute: () => instance.resetZoom?.()
6189
6189
  },
6190
+ {
6191
+ id: "fit-width",
6192
+ icon: "fit-width",
6193
+ label: "Fit to Width",
6194
+ type: "button",
6195
+ group: "zoom",
6196
+ execute: () => instance.fitToWidth?.()
6197
+ },
6190
6198
  {
6191
6199
  id: "rotate-cw",
6192
6200
  icon: "rotate-cw",
@@ -6218,21 +6226,48 @@ var ThreeDPlugin = class {
6218
6226
  async render(ctx) {
6219
6227
  const container = ctx.container;
6220
6228
  container.innerHTML = "";
6221
- container.style.overflow = "hidden";
6229
+ container.style.overflow = "auto";
6222
6230
  container.style.position = "relative";
6223
6231
  container.style.width = "100%";
6224
6232
  container.style.height = "100%";
6233
+ container.style.padding = "0";
6225
6234
  container.style.background = "#1a1a1a";
6226
- const width = container.clientWidth || 800;
6227
- const height = container.clientHeight || 600;
6235
+ let currentZoom = 1;
6236
+ let isUserZoomed = false;
6237
+ let baseW = Math.max(100, container.clientWidth || 800);
6238
+ let baseH = Math.max(100, container.clientHeight || 600);
6239
+ const updateBaseDimensions = () => {
6240
+ baseW = Math.max(100, container.clientWidth || 800);
6241
+ baseH = Math.max(100, container.clientHeight || 600);
6242
+ };
6243
+ const scrollWrapper = document.createElement("div");
6244
+ scrollWrapper.className = "fp-3d-scroll-wrapper";
6245
+ scrollWrapper.style.minWidth = "100%";
6246
+ scrollWrapper.style.minHeight = "100%";
6247
+ scrollWrapper.style.width = "max-content";
6248
+ scrollWrapper.style.height = "max-content";
6249
+ scrollWrapper.style.display = "flex";
6250
+ scrollWrapper.style.alignItems = "flex-start";
6251
+ scrollWrapper.style.justifyContent = "flex-start";
6252
+ scrollWrapper.style.boxSizing = "border-box";
6253
+ const sizer = document.createElement("div");
6254
+ sizer.className = "fp-3d-sizer";
6255
+ sizer.style.position = "relative";
6256
+ sizer.style.flexShrink = "0";
6257
+ sizer.style.display = "flex";
6258
+ sizer.style.justifyContent = "center";
6259
+ sizer.style.alignItems = "center";
6260
+ sizer.style.margin = "auto";
6228
6261
  const scene = new THREE__namespace.Scene();
6229
6262
  scene.background = new THREE__namespace.Color(1973796);
6230
- const camera = new THREE__namespace.PerspectiveCamera(45, width / height, 0.1, 2e3);
6263
+ const camera = new THREE__namespace.PerspectiveCamera(45, baseW / baseH, 0.1, 2e3);
6231
6264
  const renderer = new THREE__namespace.WebGLRenderer({ antialias: true });
6232
- renderer.setSize(width, height);
6233
- renderer.setPixelRatio(window.devicePixelRatio);
6265
+ renderer.setSize(baseW, baseH);
6266
+ renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
6234
6267
  renderer.shadowMap.enabled = true;
6235
- container.appendChild(renderer.domElement);
6268
+ sizer.appendChild(renderer.domElement);
6269
+ scrollWrapper.appendChild(sizer);
6270
+ container.appendChild(scrollWrapper);
6236
6271
  const controls = new OrbitControls_js.OrbitControls(camera, renderer.domElement);
6237
6272
  controls.enableDamping = true;
6238
6273
  controls.dampingFactor = 0.05;
@@ -6246,7 +6281,7 @@ var ThreeDPlugin = class {
6246
6281
  scene.add(dirLight2);
6247
6282
  const grid = new THREE__namespace.GridHelper(200, 20, 4473924, 2236962);
6248
6283
  scene.add(grid);
6249
- let meshGroup = new THREE__namespace.Group();
6284
+ const meshGroup = new THREE__namespace.Group();
6250
6285
  let isWireframe = false;
6251
6286
  const ext = ctx.metadata.extension?.toLowerCase();
6252
6287
  const materials = [];
@@ -6302,6 +6337,26 @@ var ThreeDPlugin = class {
6302
6337
  controls.update();
6303
6338
  };
6304
6339
  fitCamera();
6340
+ const applyZoom = () => {
6341
+ if (!isUserZoomed) {
6342
+ updateBaseDimensions();
6343
+ }
6344
+ const boxW = Math.round(baseW * currentZoom);
6345
+ const boxH = Math.round(baseH * currentZoom);
6346
+ sizer.style.width = `${boxW}px`;
6347
+ sizer.style.height = `${boxH}px`;
6348
+ const marginV = boxH < container.clientHeight ? "auto" : "0";
6349
+ const marginH = boxW < container.clientWidth ? "auto" : "0";
6350
+ sizer.style.margin = `${marginV} ${marginH}`;
6351
+ renderer.domElement.style.width = `${boxW}px`;
6352
+ renderer.domElement.style.height = `${boxH}px`;
6353
+ renderer.domElement.style.maxWidth = "none";
6354
+ renderer.domElement.style.maxHeight = "none";
6355
+ renderer.setSize(boxW, boxH, false);
6356
+ camera.aspect = boxW / boxH;
6357
+ camera.updateProjectionMatrix();
6358
+ };
6359
+ applyZoom();
6305
6360
  let animId;
6306
6361
  const animate = () => {
6307
6362
  animId = requestAnimationFrame(animate);
@@ -6310,11 +6365,10 @@ var ThreeDPlugin = class {
6310
6365
  };
6311
6366
  animate();
6312
6367
  const resizeObserver = new ResizeObserver(() => {
6313
- const newWidth = container.clientWidth || 800;
6314
- const newHeight = container.clientHeight || 600;
6315
- camera.aspect = newWidth / newHeight;
6316
- camera.updateProjectionMatrix();
6317
- renderer.setSize(newWidth, newHeight);
6368
+ if (!isUserZoomed && currentZoom === 1) {
6369
+ updateBaseDimensions();
6370
+ applyZoom();
6371
+ }
6318
6372
  });
6319
6373
  resizeObserver.observe(container);
6320
6374
  const cleanup = () => {
@@ -6328,22 +6382,57 @@ var ThreeDPlugin = class {
6328
6382
  child.geometry.dispose();
6329
6383
  }
6330
6384
  });
6385
+ scrollWrapper.remove();
6331
6386
  container.innerHTML = "";
6332
6387
  };
6333
6388
  ctx.signal.addEventListener("abort", cleanup);
6334
6389
  return {
6335
6390
  destroy: cleanup,
6336
6391
  zoomIn: () => {
6337
- camera.position.multiplyScalar(0.85);
6338
- controls.update();
6392
+ isUserZoomed = true;
6393
+ currentZoom = Math.min(5, Number((currentZoom * 1.25).toFixed(2)));
6394
+ applyZoom();
6339
6395
  },
6340
6396
  zoomOut: () => {
6341
- camera.position.multiplyScalar(1.15);
6342
- controls.update();
6397
+ currentZoom = Math.max(0.2, Number((currentZoom / 1.25).toFixed(2)));
6398
+ if (currentZoom <= 1) {
6399
+ isUserZoomed = false;
6400
+ }
6401
+ applyZoom();
6402
+ },
6403
+ getZoom: () => currentZoom,
6404
+ setZoom: (level) => {
6405
+ isUserZoomed = level !== 1;
6406
+ currentZoom = Math.max(0.2, Math.min(5, level));
6407
+ applyZoom();
6408
+ },
6409
+ fitToPage: () => {
6410
+ isUserZoomed = false;
6411
+ currentZoom = 1;
6412
+ updateBaseDimensions();
6413
+ applyZoom();
6414
+ container.scrollTop = 0;
6415
+ container.scrollLeft = 0;
6416
+ fitCamera();
6417
+ },
6418
+ fitToWidth: () => {
6419
+ isUserZoomed = false;
6420
+ currentZoom = 1;
6421
+ updateBaseDimensions();
6422
+ applyZoom();
6423
+ container.scrollTop = 0;
6424
+ container.scrollLeft = 0;
6425
+ fitCamera();
6426
+ },
6427
+ resetZoom: () => {
6428
+ isUserZoomed = false;
6429
+ currentZoom = 1;
6430
+ updateBaseDimensions();
6431
+ applyZoom();
6432
+ container.scrollTop = 0;
6433
+ container.scrollLeft = 0;
6434
+ fitCamera();
6343
6435
  },
6344
- fitToPage: fitCamera,
6345
- fitToWidth: fitCamera,
6346
- resetZoom: fitCamera,
6347
6436
  rotateCW: () => {
6348
6437
  isWireframe = !isWireframe;
6349
6438
  materials.forEach((m) => {