@file-viewer/renderer-mindmap 2.1.16 → 2.1.18

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.
Files changed (2) hide show
  1. package/dist/xmind.js +54 -0
  2. package/package.json +3 -3
package/dist/xmind.js CHANGED
@@ -530,6 +530,58 @@ export default async function renderXMind(buffer, target, _type = 'xmind', conte
530
530
  }
531
531
  return getZoomState();
532
532
  };
533
+ const applyXMindFit = (request) => {
534
+ var _a, _b;
535
+ const sheet = sheets[activeSheetIndex];
536
+ if (!sheet) {
537
+ return {
538
+ applied: false,
539
+ mode: request.mode,
540
+ resize: request.resize,
541
+ source: request.source,
542
+ reason: 'not-ready',
543
+ provider: 'view-state',
544
+ };
545
+ }
546
+ const availableWidth = Math.max(1, (request.viewportWidth || stage.clientWidth) - CANVAS_PADDING);
547
+ const availableHeight = Math.max(1, (request.viewportHeight || stage.clientHeight) - CANVAS_PADDING);
548
+ const widthScale = availableWidth / sheet.width;
549
+ const heightScale = availableHeight / sheet.height;
550
+ const containScale = Math.min(widthScale, heightScale);
551
+ const requestedScale = (() => {
552
+ switch (request.mode) {
553
+ case 'cover':
554
+ return Math.max(widthScale, heightScale);
555
+ case 'width':
556
+ return widthScale;
557
+ case 'height':
558
+ return heightScale;
559
+ case 'actual':
560
+ return 1;
561
+ case 'scale-down':
562
+ return Math.min(1, containScale);
563
+ case 'auto':
564
+ case 'contain':
565
+ default:
566
+ return containScale;
567
+ }
568
+ })();
569
+ zoom = clampZoom(Math.min((_a = request.maxScale) !== null && _a !== void 0 ? _a : 2.5, Math.max((_b = request.minScale) !== null && _b !== void 0 ? _b : 0.25, requestedScale)));
570
+ panX = (stage.clientWidth - sheet.width * zoom) / 2;
571
+ panY = (stage.clientHeight - sheet.height * zoom) / 2;
572
+ applyZoom();
573
+ zoomEmitter.emit();
574
+ const state = emitViewStateChange('fit', request.source);
575
+ return {
576
+ applied: true,
577
+ mode: request.mode,
578
+ resize: request.resize,
579
+ scale: state.scale,
580
+ source: request.source,
581
+ provider: 'view-state',
582
+ state,
583
+ };
584
+ };
533
585
  const scrollToNode = (node) => {
534
586
  userAdjustedViewport = true;
535
587
  panX = stage.clientWidth / 2 - (node.x + node.width / 2) * zoom;
@@ -642,6 +694,7 @@ export default async function renderXMind(buffer, target, _type = 'xmind', conte
642
694
  zoomOut: () => setZoomAtStageCenter(zoom - 0.15),
643
695
  resetZoom: () => fitSheetToStage(true),
644
696
  setZoom,
697
+ fit: applyXMindFit,
645
698
  getState: getZoomState,
646
699
  subscribe: zoomEmitter.subscribe,
647
700
  });
@@ -685,6 +738,7 @@ export default async function renderXMind(buffer, target, _type = 'xmind', conte
685
738
  }
686
739
  return getXMindViewState();
687
740
  },
741
+ fit: applyXMindFit,
688
742
  subscribe: viewStateEmitter.subscribe,
689
743
  });
690
744
  const getPanTargetElement = (targetValue) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@file-viewer/renderer-mindmap",
3
- "version": "2.1.16",
3
+ "version": "2.1.18",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "Standalone XMind and mind map renderer plugin for Flyfish File Viewer.",
@@ -33,7 +33,7 @@
33
33
  },
34
34
  "funding": {
35
35
  "type": "individual",
36
- "url": "https://dev.flyfish.group/shop"
36
+ "url": "https://dev.flyfish.group/donate?source=npm"
37
37
  },
38
38
  "main": "./dist/index.js",
39
39
  "module": "./dist/index.js",
@@ -53,7 +53,7 @@
53
53
  "LICENSE"
54
54
  ],
55
55
  "dependencies": {
56
- "@file-viewer/core": "^2.1.16",
56
+ "@file-viewer/core": "^2.1.18",
57
57
  "@ljheee/xmind-parser": "^1.1.3",
58
58
  "@panzoom/panzoom": "^4.6.2",
59
59
  "jszip": "^3.10.1"