@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/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,48 @@ 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.alignItems = "flex-start";
6265
+ scrollWrapper.style.justifyContent = "flex-start";
6266
+ scrollWrapper.style.boxSizing = "border-box";
6267
+ const sizer = document.createElement("div");
6268
+ sizer.className = "fp-3d-sizer";
6269
+ sizer.style.position = "relative";
6270
+ sizer.style.flexShrink = "0";
6271
+ sizer.style.display = "flex";
6272
+ sizer.style.justifyContent = "center";
6273
+ sizer.style.alignItems = "center";
6274
+ sizer.style.margin = "auto";
6242
6275
  const scene = new THREE.Scene();
6243
6276
  scene.background = new THREE.Color(1973796);
6244
- const camera = new THREE.PerspectiveCamera(45, width / height, 0.1, 2e3);
6277
+ const camera = new THREE.PerspectiveCamera(45, baseW / baseH, 0.1, 2e3);
6245
6278
  const renderer = new THREE.WebGLRenderer({ antialias: true });
6246
- renderer.setSize(width, height);
6247
- renderer.setPixelRatio(window.devicePixelRatio);
6279
+ renderer.setSize(baseW, baseH);
6280
+ renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
6248
6281
  renderer.shadowMap.enabled = true;
6249
- container.appendChild(renderer.domElement);
6282
+ sizer.appendChild(renderer.domElement);
6283
+ scrollWrapper.appendChild(sizer);
6284
+ container.appendChild(scrollWrapper);
6250
6285
  const controls = new OrbitControls(camera, renderer.domElement);
6251
6286
  controls.enableDamping = true;
6252
6287
  controls.dampingFactor = 0.05;
@@ -6260,7 +6295,7 @@ var ThreeDPlugin = class {
6260
6295
  scene.add(dirLight2);
6261
6296
  const grid = new THREE.GridHelper(200, 20, 4473924, 2236962);
6262
6297
  scene.add(grid);
6263
- let meshGroup = new THREE.Group();
6298
+ const meshGroup = new THREE.Group();
6264
6299
  let isWireframe = false;
6265
6300
  const ext = ctx.metadata.extension?.toLowerCase();
6266
6301
  const materials = [];
@@ -6316,6 +6351,26 @@ var ThreeDPlugin = class {
6316
6351
  controls.update();
6317
6352
  };
6318
6353
  fitCamera();
6354
+ const applyZoom = () => {
6355
+ if (!isUserZoomed) {
6356
+ updateBaseDimensions();
6357
+ }
6358
+ const boxW = Math.round(baseW * currentZoom);
6359
+ const boxH = Math.round(baseH * currentZoom);
6360
+ sizer.style.width = `${boxW}px`;
6361
+ sizer.style.height = `${boxH}px`;
6362
+ const marginV = boxH < container.clientHeight ? "auto" : "0";
6363
+ const marginH = boxW < container.clientWidth ? "auto" : "0";
6364
+ sizer.style.margin = `${marginV} ${marginH}`;
6365
+ renderer.domElement.style.width = `${boxW}px`;
6366
+ renderer.domElement.style.height = `${boxH}px`;
6367
+ renderer.domElement.style.maxWidth = "none";
6368
+ renderer.domElement.style.maxHeight = "none";
6369
+ renderer.setSize(boxW, boxH, false);
6370
+ camera.aspect = boxW / boxH;
6371
+ camera.updateProjectionMatrix();
6372
+ };
6373
+ applyZoom();
6319
6374
  let animId;
6320
6375
  const animate = () => {
6321
6376
  animId = requestAnimationFrame(animate);
@@ -6324,11 +6379,10 @@ var ThreeDPlugin = class {
6324
6379
  };
6325
6380
  animate();
6326
6381
  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);
6382
+ if (!isUserZoomed && currentZoom === 1) {
6383
+ updateBaseDimensions();
6384
+ applyZoom();
6385
+ }
6332
6386
  });
6333
6387
  resizeObserver.observe(container);
6334
6388
  const cleanup = () => {
@@ -6342,22 +6396,57 @@ var ThreeDPlugin = class {
6342
6396
  child.geometry.dispose();
6343
6397
  }
6344
6398
  });
6399
+ scrollWrapper.remove();
6345
6400
  container.innerHTML = "";
6346
6401
  };
6347
6402
  ctx.signal.addEventListener("abort", cleanup);
6348
6403
  return {
6349
6404
  destroy: cleanup,
6350
6405
  zoomIn: () => {
6351
- camera.position.multiplyScalar(0.85);
6352
- controls.update();
6406
+ isUserZoomed = true;
6407
+ currentZoom = Math.min(5, Number((currentZoom * 1.25).toFixed(2)));
6408
+ applyZoom();
6353
6409
  },
6354
6410
  zoomOut: () => {
6355
- camera.position.multiplyScalar(1.15);
6356
- controls.update();
6411
+ currentZoom = Math.max(0.2, Number((currentZoom / 1.25).toFixed(2)));
6412
+ if (currentZoom <= 1) {
6413
+ isUserZoomed = false;
6414
+ }
6415
+ applyZoom();
6416
+ },
6417
+ getZoom: () => currentZoom,
6418
+ setZoom: (level) => {
6419
+ isUserZoomed = level !== 1;
6420
+ currentZoom = Math.max(0.2, Math.min(5, level));
6421
+ applyZoom();
6422
+ },
6423
+ fitToPage: () => {
6424
+ isUserZoomed = false;
6425
+ currentZoom = 1;
6426
+ updateBaseDimensions();
6427
+ applyZoom();
6428
+ container.scrollTop = 0;
6429
+ container.scrollLeft = 0;
6430
+ fitCamera();
6431
+ },
6432
+ fitToWidth: () => {
6433
+ isUserZoomed = false;
6434
+ currentZoom = 1;
6435
+ updateBaseDimensions();
6436
+ applyZoom();
6437
+ container.scrollTop = 0;
6438
+ container.scrollLeft = 0;
6439
+ fitCamera();
6440
+ },
6441
+ resetZoom: () => {
6442
+ isUserZoomed = false;
6443
+ currentZoom = 1;
6444
+ updateBaseDimensions();
6445
+ applyZoom();
6446
+ container.scrollTop = 0;
6447
+ container.scrollLeft = 0;
6448
+ fitCamera();
6357
6449
  },
6358
- fitToPage: fitCamera,
6359
- fitToWidth: fitCamera,
6360
- resetZoom: fitCamera,
6361
6450
  rotateCW: () => {
6362
6451
  isWireframe = !isWireframe;
6363
6452
  materials.forEach((m) => {