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