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