@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/angular.js CHANGED
@@ -6188,7 +6188,7 @@ var ThreeDPlugin = class {
6188
6188
  {
6189
6189
  id: "fit-page",
6190
6190
  icon: "fit-page",
6191
- label: "Reset Camera View",
6191
+ label: "Fit to Page",
6192
6192
  type: "button",
6193
6193
  group: "zoom",
6194
6194
  execute: () => instance.fitToPage?.()
@@ -6201,6 +6201,14 @@ var ThreeDPlugin = class {
6201
6201
  group: "zoom",
6202
6202
  execute: () => instance.resetZoom?.()
6203
6203
  },
6204
+ {
6205
+ id: "fit-width",
6206
+ icon: "fit-width",
6207
+ label: "Fit to Width",
6208
+ type: "button",
6209
+ group: "zoom",
6210
+ execute: () => instance.fitToWidth?.()
6211
+ },
6204
6212
  {
6205
6213
  id: "rotate-cw",
6206
6214
  icon: "rotate-cw",
@@ -6232,21 +6240,49 @@ var ThreeDPlugin = class {
6232
6240
  async render(ctx) {
6233
6241
  const container = ctx.container;
6234
6242
  container.innerHTML = "";
6235
- container.style.overflow = "hidden";
6243
+ container.style.overflow = "auto";
6236
6244
  container.style.position = "relative";
6237
6245
  container.style.width = "100%";
6238
6246
  container.style.height = "100%";
6247
+ container.style.padding = "0";
6239
6248
  container.style.background = "#1a1a1a";
6240
- const width = container.clientWidth || 800;
6241
- const height = container.clientHeight || 600;
6249
+ let currentZoom = 1;
6250
+ let isUserZoomed = false;
6251
+ let baseW = Math.max(100, container.clientWidth || 800);
6252
+ let baseH = Math.max(100, container.clientHeight || 600);
6253
+ const updateBaseDimensions = () => {
6254
+ baseW = Math.max(100, container.clientWidth || 800);
6255
+ baseH = Math.max(100, container.clientHeight || 600);
6256
+ };
6257
+ const scrollWrapper = document.createElement("div");
6258
+ scrollWrapper.className = "fp-3d-scroll-wrapper";
6259
+ scrollWrapper.style.minWidth = "100%";
6260
+ scrollWrapper.style.minHeight = "100%";
6261
+ scrollWrapper.style.width = "max-content";
6262
+ scrollWrapper.style.height = "max-content";
6263
+ scrollWrapper.style.display = "flex";
6264
+ scrollWrapper.style.flexDirection = "column";
6265
+ scrollWrapper.style.alignItems = "center";
6266
+ scrollWrapper.style.justifyContent = "flex-start";
6267
+ scrollWrapper.style.boxSizing = "border-box";
6268
+ const sizer = document.createElement("div");
6269
+ sizer.className = "fp-3d-sizer";
6270
+ sizer.style.position = "relative";
6271
+ sizer.style.flexShrink = "0";
6272
+ sizer.style.display = "flex";
6273
+ sizer.style.justifyContent = "center";
6274
+ sizer.style.alignItems = "center";
6275
+ sizer.style.margin = "auto 0";
6242
6276
  const scene = new THREE.Scene();
6243
6277
  scene.background = new THREE.Color(1973796);
6244
- const camera = new THREE.PerspectiveCamera(45, width / height, 0.1, 2e3);
6278
+ const camera = new THREE.PerspectiveCamera(45, baseW / baseH, 0.1, 2e3);
6245
6279
  const renderer = new THREE.WebGLRenderer({ antialias: true });
6246
- renderer.setSize(width, height);
6247
- renderer.setPixelRatio(window.devicePixelRatio);
6280
+ renderer.setSize(baseW, baseH);
6281
+ renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
6248
6282
  renderer.shadowMap.enabled = true;
6249
- container.appendChild(renderer.domElement);
6283
+ sizer.appendChild(renderer.domElement);
6284
+ scrollWrapper.appendChild(sizer);
6285
+ container.appendChild(scrollWrapper);
6250
6286
  const controls = new OrbitControls(camera, renderer.domElement);
6251
6287
  controls.enableDamping = true;
6252
6288
  controls.dampingFactor = 0.05;
@@ -6260,7 +6296,7 @@ var ThreeDPlugin = class {
6260
6296
  scene.add(dirLight2);
6261
6297
  const grid = new THREE.GridHelper(200, 20, 4473924, 2236962);
6262
6298
  scene.add(grid);
6263
- let meshGroup = new THREE.Group();
6299
+ const meshGroup = new THREE.Group();
6264
6300
  let isWireframe = false;
6265
6301
  const ext = ctx.metadata.extension?.toLowerCase();
6266
6302
  const materials = [];
@@ -6316,6 +6352,24 @@ var ThreeDPlugin = class {
6316
6352
  controls.update();
6317
6353
  };
6318
6354
  fitCamera();
6355
+ const applyZoom = () => {
6356
+ if (!isUserZoomed) {
6357
+ updateBaseDimensions();
6358
+ }
6359
+ const boxW = Math.round(baseW * currentZoom);
6360
+ const boxH = Math.round(baseH * currentZoom);
6361
+ sizer.style.width = `${boxW}px`;
6362
+ sizer.style.height = `${boxH}px`;
6363
+ sizer.style.margin = boxH < container.clientHeight ? "auto 0" : "0";
6364
+ renderer.domElement.style.width = `${boxW}px`;
6365
+ renderer.domElement.style.height = `${boxH}px`;
6366
+ renderer.domElement.style.maxWidth = "none";
6367
+ renderer.domElement.style.maxHeight = "none";
6368
+ renderer.setSize(boxW, boxH, false);
6369
+ camera.aspect = boxW / boxH;
6370
+ camera.updateProjectionMatrix();
6371
+ };
6372
+ applyZoom();
6319
6373
  let animId;
6320
6374
  const animate = () => {
6321
6375
  animId = requestAnimationFrame(animate);
@@ -6324,11 +6378,10 @@ var ThreeDPlugin = class {
6324
6378
  };
6325
6379
  animate();
6326
6380
  const resizeObserver = new ResizeObserver(() => {
6327
- const newWidth = container.clientWidth || 800;
6328
- const newHeight = container.clientHeight || 600;
6329
- camera.aspect = newWidth / newHeight;
6330
- camera.updateProjectionMatrix();
6331
- renderer.setSize(newWidth, newHeight);
6381
+ if (!isUserZoomed && currentZoom === 1) {
6382
+ updateBaseDimensions();
6383
+ applyZoom();
6384
+ }
6332
6385
  });
6333
6386
  resizeObserver.observe(container);
6334
6387
  const cleanup = () => {
@@ -6342,22 +6395,51 @@ var ThreeDPlugin = class {
6342
6395
  child.geometry.dispose();
6343
6396
  }
6344
6397
  });
6398
+ scrollWrapper.remove();
6345
6399
  container.innerHTML = "";
6346
6400
  };
6347
6401
  ctx.signal.addEventListener("abort", cleanup);
6348
6402
  return {
6349
6403
  destroy: cleanup,
6350
6404
  zoomIn: () => {
6351
- camera.position.multiplyScalar(0.85);
6352
- controls.update();
6405
+ isUserZoomed = true;
6406
+ currentZoom = Math.min(5, Number((currentZoom * 1.25).toFixed(2)));
6407
+ applyZoom();
6353
6408
  },
6354
6409
  zoomOut: () => {
6355
- camera.position.multiplyScalar(1.15);
6356
- controls.update();
6410
+ currentZoom = Math.max(0.2, Number((currentZoom / 1.25).toFixed(2)));
6411
+ if (currentZoom <= 1) {
6412
+ isUserZoomed = false;
6413
+ }
6414
+ applyZoom();
6415
+ },
6416
+ fitToPage: () => {
6417
+ isUserZoomed = false;
6418
+ currentZoom = 1;
6419
+ updateBaseDimensions();
6420
+ applyZoom();
6421
+ container.scrollTop = 0;
6422
+ container.scrollLeft = 0;
6423
+ fitCamera();
6424
+ },
6425
+ fitToWidth: () => {
6426
+ isUserZoomed = false;
6427
+ currentZoom = 1;
6428
+ updateBaseDimensions();
6429
+ applyZoom();
6430
+ container.scrollTop = 0;
6431
+ container.scrollLeft = 0;
6432
+ fitCamera();
6433
+ },
6434
+ resetZoom: () => {
6435
+ isUserZoomed = false;
6436
+ currentZoom = 1;
6437
+ updateBaseDimensions();
6438
+ applyZoom();
6439
+ container.scrollTop = 0;
6440
+ container.scrollLeft = 0;
6441
+ fitCamera();
6357
6442
  },
6358
- fitToPage: fitCamera,
6359
- fitToWidth: fitCamera,
6360
- resetZoom: fitCamera,
6361
6443
  rotateCW: () => {
6362
6444
  isWireframe = !isWireframe;
6363
6445
  materials.forEach((m) => {