@files-preview-app/preview-file 1.3.17 → 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/react.js CHANGED
@@ -6141,7 +6141,7 @@ var ThreeDPlugin = class {
6141
6141
  {
6142
6142
  id: "fit-page",
6143
6143
  icon: "fit-page",
6144
- label: "Reset Camera View",
6144
+ label: "Fit to Page",
6145
6145
  type: "button",
6146
6146
  group: "zoom",
6147
6147
  execute: () => instance.fitToPage?.()
@@ -6154,6 +6154,14 @@ var ThreeDPlugin = class {
6154
6154
  group: "zoom",
6155
6155
  execute: () => instance.resetZoom?.()
6156
6156
  },
6157
+ {
6158
+ id: "fit-width",
6159
+ icon: "fit-width",
6160
+ label: "Fit to Width",
6161
+ type: "button",
6162
+ group: "zoom",
6163
+ execute: () => instance.fitToWidth?.()
6164
+ },
6157
6165
  {
6158
6166
  id: "rotate-cw",
6159
6167
  icon: "rotate-cw",
@@ -6185,21 +6193,49 @@ var ThreeDPlugin = class {
6185
6193
  async render(ctx) {
6186
6194
  const container = ctx.container;
6187
6195
  container.innerHTML = "";
6188
- container.style.overflow = "hidden";
6196
+ container.style.overflow = "auto";
6189
6197
  container.style.position = "relative";
6190
6198
  container.style.width = "100%";
6191
6199
  container.style.height = "100%";
6200
+ container.style.padding = "0";
6192
6201
  container.style.background = "#1a1a1a";
6193
- const width = container.clientWidth || 800;
6194
- const height = container.clientHeight || 600;
6202
+ let currentZoom = 1;
6203
+ let isUserZoomed = false;
6204
+ let baseW = Math.max(100, container.clientWidth || 800);
6205
+ let baseH = Math.max(100, container.clientHeight || 600);
6206
+ const updateBaseDimensions = () => {
6207
+ baseW = Math.max(100, container.clientWidth || 800);
6208
+ baseH = Math.max(100, container.clientHeight || 600);
6209
+ };
6210
+ const scrollWrapper = document.createElement("div");
6211
+ scrollWrapper.className = "fp-3d-scroll-wrapper";
6212
+ scrollWrapper.style.minWidth = "100%";
6213
+ scrollWrapper.style.minHeight = "100%";
6214
+ scrollWrapper.style.width = "max-content";
6215
+ scrollWrapper.style.height = "max-content";
6216
+ scrollWrapper.style.display = "flex";
6217
+ scrollWrapper.style.flexDirection = "column";
6218
+ scrollWrapper.style.alignItems = "center";
6219
+ scrollWrapper.style.justifyContent = "flex-start";
6220
+ scrollWrapper.style.boxSizing = "border-box";
6221
+ const sizer = document.createElement("div");
6222
+ sizer.className = "fp-3d-sizer";
6223
+ sizer.style.position = "relative";
6224
+ sizer.style.flexShrink = "0";
6225
+ sizer.style.display = "flex";
6226
+ sizer.style.justifyContent = "center";
6227
+ sizer.style.alignItems = "center";
6228
+ sizer.style.margin = "auto 0";
6195
6229
  const scene = new THREE.Scene();
6196
6230
  scene.background = new THREE.Color(1973796);
6197
- const camera = new THREE.PerspectiveCamera(45, width / height, 0.1, 2e3);
6231
+ const camera = new THREE.PerspectiveCamera(45, baseW / baseH, 0.1, 2e3);
6198
6232
  const renderer = new THREE.WebGLRenderer({ antialias: true });
6199
- renderer.setSize(width, height);
6200
- renderer.setPixelRatio(window.devicePixelRatio);
6233
+ renderer.setSize(baseW, baseH);
6234
+ renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
6201
6235
  renderer.shadowMap.enabled = true;
6202
- container.appendChild(renderer.domElement);
6236
+ sizer.appendChild(renderer.domElement);
6237
+ scrollWrapper.appendChild(sizer);
6238
+ container.appendChild(scrollWrapper);
6203
6239
  const controls = new OrbitControls(camera, renderer.domElement);
6204
6240
  controls.enableDamping = true;
6205
6241
  controls.dampingFactor = 0.05;
@@ -6213,7 +6249,7 @@ var ThreeDPlugin = class {
6213
6249
  scene.add(dirLight2);
6214
6250
  const grid = new THREE.GridHelper(200, 20, 4473924, 2236962);
6215
6251
  scene.add(grid);
6216
- let meshGroup = new THREE.Group();
6252
+ const meshGroup = new THREE.Group();
6217
6253
  let isWireframe = false;
6218
6254
  const ext = ctx.metadata.extension?.toLowerCase();
6219
6255
  const materials = [];
@@ -6269,6 +6305,24 @@ var ThreeDPlugin = class {
6269
6305
  controls.update();
6270
6306
  };
6271
6307
  fitCamera();
6308
+ const applyZoom = () => {
6309
+ if (!isUserZoomed) {
6310
+ updateBaseDimensions();
6311
+ }
6312
+ const boxW = Math.round(baseW * currentZoom);
6313
+ const boxH = Math.round(baseH * currentZoom);
6314
+ sizer.style.width = `${boxW}px`;
6315
+ sizer.style.height = `${boxH}px`;
6316
+ sizer.style.margin = boxH < container.clientHeight ? "auto 0" : "0";
6317
+ renderer.domElement.style.width = `${boxW}px`;
6318
+ renderer.domElement.style.height = `${boxH}px`;
6319
+ renderer.domElement.style.maxWidth = "none";
6320
+ renderer.domElement.style.maxHeight = "none";
6321
+ renderer.setSize(boxW, boxH, false);
6322
+ camera.aspect = boxW / boxH;
6323
+ camera.updateProjectionMatrix();
6324
+ };
6325
+ applyZoom();
6272
6326
  let animId;
6273
6327
  const animate = () => {
6274
6328
  animId = requestAnimationFrame(animate);
@@ -6277,11 +6331,10 @@ var ThreeDPlugin = class {
6277
6331
  };
6278
6332
  animate();
6279
6333
  const resizeObserver = new ResizeObserver(() => {
6280
- const newWidth = container.clientWidth || 800;
6281
- const newHeight = container.clientHeight || 600;
6282
- camera.aspect = newWidth / newHeight;
6283
- camera.updateProjectionMatrix();
6284
- renderer.setSize(newWidth, newHeight);
6334
+ if (!isUserZoomed && currentZoom === 1) {
6335
+ updateBaseDimensions();
6336
+ applyZoom();
6337
+ }
6285
6338
  });
6286
6339
  resizeObserver.observe(container);
6287
6340
  const cleanup = () => {
@@ -6295,22 +6348,51 @@ var ThreeDPlugin = class {
6295
6348
  child.geometry.dispose();
6296
6349
  }
6297
6350
  });
6351
+ scrollWrapper.remove();
6298
6352
  container.innerHTML = "";
6299
6353
  };
6300
6354
  ctx.signal.addEventListener("abort", cleanup);
6301
6355
  return {
6302
6356
  destroy: cleanup,
6303
6357
  zoomIn: () => {
6304
- camera.position.multiplyScalar(0.85);
6305
- controls.update();
6358
+ isUserZoomed = true;
6359
+ currentZoom = Math.min(5, Number((currentZoom * 1.25).toFixed(2)));
6360
+ applyZoom();
6306
6361
  },
6307
6362
  zoomOut: () => {
6308
- camera.position.multiplyScalar(1.15);
6309
- controls.update();
6363
+ currentZoom = Math.max(0.2, Number((currentZoom / 1.25).toFixed(2)));
6364
+ if (currentZoom <= 1) {
6365
+ isUserZoomed = false;
6366
+ }
6367
+ applyZoom();
6368
+ },
6369
+ fitToPage: () => {
6370
+ isUserZoomed = false;
6371
+ currentZoom = 1;
6372
+ updateBaseDimensions();
6373
+ applyZoom();
6374
+ container.scrollTop = 0;
6375
+ container.scrollLeft = 0;
6376
+ fitCamera();
6377
+ },
6378
+ fitToWidth: () => {
6379
+ isUserZoomed = false;
6380
+ currentZoom = 1;
6381
+ updateBaseDimensions();
6382
+ applyZoom();
6383
+ container.scrollTop = 0;
6384
+ container.scrollLeft = 0;
6385
+ fitCamera();
6386
+ },
6387
+ resetZoom: () => {
6388
+ isUserZoomed = false;
6389
+ currentZoom = 1;
6390
+ updateBaseDimensions();
6391
+ applyZoom();
6392
+ container.scrollTop = 0;
6393
+ container.scrollLeft = 0;
6394
+ fitCamera();
6310
6395
  },
6311
- fitToPage: fitCamera,
6312
- fitToWidth: fitCamera,
6313
- resetZoom: fitCamera,
6314
6396
  rotateCW: () => {
6315
6397
  isWireframe = !isWireframe;
6316
6398
  materials.forEach((m) => {