@embedpdf/plugin-stage 3.0.0-next.7 → 3.0.0-next.8

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/index.cjs CHANGED
@@ -552,7 +552,7 @@ function createStageCapability(ctx, config = {}) {
552
552
  fitAlign: ctx.getState().fitAlign,
553
553
  direction: ctx.getState().direction
554
554
  });
555
- let hasPlaced = false;
555
+ let placementStarted = false;
556
556
  let gestureDepth = 0;
557
557
  let gestureZoomed = false;
558
558
  let gestureElastic = false;
@@ -560,7 +560,7 @@ function createStageCapability(ctx, config = {}) {
560
560
  const REST_MS = 150;
561
561
  let restRaf = 0;
562
562
  const armRest = () => {
563
- if (!canAnimate || !hasPlaced) return;
563
+ if (!canAnimate || !placementStarted) return;
564
564
  if (ctx.getState().cameraResting) ctx.dispatch({
565
565
  type: "CAMERA_REST",
566
566
  resting: false
@@ -976,8 +976,19 @@ function createStageCapability(ctx, config = {}) {
976
976
  visibleRect
977
977
  };
978
978
  };
979
+ const EMPTY_SCROLL_METRICS = {
980
+ scrollLeft: 0,
981
+ scrollTop: 0,
982
+ scrollWidth: 0,
983
+ scrollHeight: 0,
984
+ clientWidth: 0,
985
+ clientHeight: 0,
986
+ scrollableX: false,
987
+ scrollableY: false
988
+ };
979
989
  let scrollMemo = null;
980
990
  const scrollMetricsNow = () => {
991
+ if (!ctx.getState().placed) return EMPTY_SCROLL_METRICS;
981
992
  const sc = buildScene();
982
993
  const m = _embedpdf_core_stage.scrollMetrics(cam(), sc.itemCount ? stayBounds() : {
983
994
  x: 0,
@@ -990,9 +1001,11 @@ function createStageCapability(ctx, config = {}) {
990
1001
  scrollMemo = m;
991
1002
  return m;
992
1003
  };
1004
+ const EMPTY_VISIBLE_PAGES = [];
993
1005
  let visSig = "";
994
1006
  let vis = [];
995
1007
  const visiblePages = () => {
1008
+ if (!ctx.getState().placed) return EMPTY_VISIBLE_PAGES;
996
1009
  const c = cam();
997
1010
  const v = vp();
998
1011
  const sc = buildScene();
@@ -1093,6 +1106,7 @@ function createStageCapability(ctx, config = {}) {
1093
1106
  label: p.label ?? null
1094
1107
  })),
1095
1108
  pageRect: (pon) => {
1109
+ if (!ctx.getState().placed) return null;
1096
1110
  const meta = ctx.document();
1097
1111
  const index = meta ? meta.pages.findIndex((p) => p.pageObjectNumber === pon) : -1;
1098
1112
  if (index < 0) return null;
@@ -1193,7 +1207,7 @@ function createStageCapability(ctx, config = {}) {
1193
1207
  anchor: currentAnchor()
1194
1208
  }),
1195
1209
  setViewport: (v) => {
1196
- if (!hasPlaced) {
1210
+ if (!placementStarted) {
1197
1211
  ctx.dispatch({
1198
1212
  type: "VP",
1199
1213
  vp: v
@@ -1327,7 +1341,7 @@ function createStageCapability(ctx, config = {}) {
1327
1341
  fitAll: () => api.update({ zoom: { mode: _embedpdf_core_stage.ZoomMode.FitAll } }),
1328
1342
  automatic: () => api.update({ zoom: { mode: _embedpdf_core_stage.ZoomMode.Automatic } }),
1329
1343
  refit: () => {
1330
- if (!hasPlaced) return;
1344
+ if (!placementStarted) return;
1331
1345
  cancelAnim();
1332
1346
  reapply(currentAnchor());
1333
1347
  },
@@ -1454,16 +1468,18 @@ function createStageCapability(ctx, config = {}) {
1454
1468
  });
1455
1469
  },
1456
1470
  placeInitial: () => {
1457
- hasPlaced = true;
1471
+ placementStarted = true;
1458
1472
  const sorted = [...initialViewProviders].sort((a, b) => b.priority - a.priority);
1459
1473
  for (const p of sorted) {
1460
1474
  const view = p.fn();
1461
1475
  if (view) {
1462
1476
  api.applyViewState(view);
1477
+ ctx.dispatch({ type: "PLACED" });
1463
1478
  return;
1464
1479
  }
1465
1480
  }
1466
1481
  api.resetView();
1482
+ ctx.dispatch({ type: "PLACED" });
1467
1483
  },
1468
1484
  resetView: () => goToTarget(0, { behavior: "instant" })
1469
1485
  };
@@ -1499,6 +1515,7 @@ const initialStageState = (config) => {
1499
1515
  y: 0,
1500
1516
  zoom: 1
1501
1517
  },
1518
+ placed: false,
1502
1519
  cameraResting: true,
1503
1520
  vp: {
1504
1521
  width: 0,
@@ -1536,6 +1553,10 @@ const stageReducer = (state, a) => {
1536
1553
  ...state,
1537
1554
  cameraResting: a.resting
1538
1555
  };
1556
+ case "PLACED": return state.placed ? state : {
1557
+ ...state,
1558
+ placed: true
1559
+ };
1539
1560
  case "VP": return {
1540
1561
  ...state,
1541
1562
  vp: a.vp