@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.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,48 @@ 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.alignItems = "flex-start";
6218
+ scrollWrapper.style.justifyContent = "flex-start";
6219
+ scrollWrapper.style.boxSizing = "border-box";
6220
+ const sizer = document.createElement("div");
6221
+ sizer.className = "fp-3d-sizer";
6222
+ sizer.style.position = "relative";
6223
+ sizer.style.flexShrink = "0";
6224
+ sizer.style.display = "flex";
6225
+ sizer.style.justifyContent = "center";
6226
+ sizer.style.alignItems = "center";
6227
+ sizer.style.margin = "auto";
6195
6228
  const scene = new THREE.Scene();
6196
6229
  scene.background = new THREE.Color(1973796);
6197
- const camera = new THREE.PerspectiveCamera(45, width / height, 0.1, 2e3);
6230
+ const camera = new THREE.PerspectiveCamera(45, baseW / baseH, 0.1, 2e3);
6198
6231
  const renderer = new THREE.WebGLRenderer({ antialias: true });
6199
- renderer.setSize(width, height);
6200
- renderer.setPixelRatio(window.devicePixelRatio);
6232
+ renderer.setSize(baseW, baseH);
6233
+ renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
6201
6234
  renderer.shadowMap.enabled = true;
6202
- container.appendChild(renderer.domElement);
6235
+ sizer.appendChild(renderer.domElement);
6236
+ scrollWrapper.appendChild(sizer);
6237
+ container.appendChild(scrollWrapper);
6203
6238
  const controls = new OrbitControls(camera, renderer.domElement);
6204
6239
  controls.enableDamping = true;
6205
6240
  controls.dampingFactor = 0.05;
@@ -6213,7 +6248,7 @@ var ThreeDPlugin = class {
6213
6248
  scene.add(dirLight2);
6214
6249
  const grid = new THREE.GridHelper(200, 20, 4473924, 2236962);
6215
6250
  scene.add(grid);
6216
- let meshGroup = new THREE.Group();
6251
+ const meshGroup = new THREE.Group();
6217
6252
  let isWireframe = false;
6218
6253
  const ext = ctx.metadata.extension?.toLowerCase();
6219
6254
  const materials = [];
@@ -6269,6 +6304,26 @@ var ThreeDPlugin = class {
6269
6304
  controls.update();
6270
6305
  };
6271
6306
  fitCamera();
6307
+ const applyZoom = () => {
6308
+ if (!isUserZoomed) {
6309
+ updateBaseDimensions();
6310
+ }
6311
+ const boxW = Math.round(baseW * currentZoom);
6312
+ const boxH = Math.round(baseH * currentZoom);
6313
+ sizer.style.width = `${boxW}px`;
6314
+ sizer.style.height = `${boxH}px`;
6315
+ const marginV = boxH < container.clientHeight ? "auto" : "0";
6316
+ const marginH = boxW < container.clientWidth ? "auto" : "0";
6317
+ sizer.style.margin = `${marginV} ${marginH}`;
6318
+ renderer.domElement.style.width = `${boxW}px`;
6319
+ renderer.domElement.style.height = `${boxH}px`;
6320
+ renderer.domElement.style.maxWidth = "none";
6321
+ renderer.domElement.style.maxHeight = "none";
6322
+ renderer.setSize(boxW, boxH, false);
6323
+ camera.aspect = boxW / boxH;
6324
+ camera.updateProjectionMatrix();
6325
+ };
6326
+ applyZoom();
6272
6327
  let animId;
6273
6328
  const animate = () => {
6274
6329
  animId = requestAnimationFrame(animate);
@@ -6277,11 +6332,10 @@ var ThreeDPlugin = class {
6277
6332
  };
6278
6333
  animate();
6279
6334
  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);
6335
+ if (!isUserZoomed && currentZoom === 1) {
6336
+ updateBaseDimensions();
6337
+ applyZoom();
6338
+ }
6285
6339
  });
6286
6340
  resizeObserver.observe(container);
6287
6341
  const cleanup = () => {
@@ -6295,22 +6349,57 @@ var ThreeDPlugin = class {
6295
6349
  child.geometry.dispose();
6296
6350
  }
6297
6351
  });
6352
+ scrollWrapper.remove();
6298
6353
  container.innerHTML = "";
6299
6354
  };
6300
6355
  ctx.signal.addEventListener("abort", cleanup);
6301
6356
  return {
6302
6357
  destroy: cleanup,
6303
6358
  zoomIn: () => {
6304
- camera.position.multiplyScalar(0.85);
6305
- controls.update();
6359
+ isUserZoomed = true;
6360
+ currentZoom = Math.min(5, Number((currentZoom * 1.25).toFixed(2)));
6361
+ applyZoom();
6306
6362
  },
6307
6363
  zoomOut: () => {
6308
- camera.position.multiplyScalar(1.15);
6309
- controls.update();
6364
+ currentZoom = Math.max(0.2, Number((currentZoom / 1.25).toFixed(2)));
6365
+ if (currentZoom <= 1) {
6366
+ isUserZoomed = false;
6367
+ }
6368
+ applyZoom();
6369
+ },
6370
+ getZoom: () => currentZoom,
6371
+ setZoom: (level) => {
6372
+ isUserZoomed = level !== 1;
6373
+ currentZoom = Math.max(0.2, Math.min(5, level));
6374
+ applyZoom();
6375
+ },
6376
+ fitToPage: () => {
6377
+ isUserZoomed = false;
6378
+ currentZoom = 1;
6379
+ updateBaseDimensions();
6380
+ applyZoom();
6381
+ container.scrollTop = 0;
6382
+ container.scrollLeft = 0;
6383
+ fitCamera();
6384
+ },
6385
+ fitToWidth: () => {
6386
+ isUserZoomed = false;
6387
+ currentZoom = 1;
6388
+ updateBaseDimensions();
6389
+ applyZoom();
6390
+ container.scrollTop = 0;
6391
+ container.scrollLeft = 0;
6392
+ fitCamera();
6393
+ },
6394
+ resetZoom: () => {
6395
+ isUserZoomed = false;
6396
+ currentZoom = 1;
6397
+ updateBaseDimensions();
6398
+ applyZoom();
6399
+ container.scrollTop = 0;
6400
+ container.scrollLeft = 0;
6401
+ fitCamera();
6310
6402
  },
6311
- fitToPage: fitCamera,
6312
- fitToWidth: fitCamera,
6313
- resetZoom: fitCamera,
6314
6403
  rotateCW: () => {
6315
6404
  isWireframe = !isWireframe;
6316
6405
  materials.forEach((m) => {