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