@embedpdf/plugin-scroll 1.0.9 → 1.0.11

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.js CHANGED
@@ -7,167 +7,9 @@ import {
7
7
  createBehaviorEmitter,
8
8
  getPagesWithRotatedSize
9
9
  } from "@embedpdf/core";
10
-
11
- // ../models/dist/index.js
12
- var Rotation = /* @__PURE__ */ ((Rotation22) => {
13
- Rotation22[Rotation22["Degree0"] = 0] = "Degree0";
14
- Rotation22[Rotation22["Degree90"] = 1] = "Degree90";
15
- Rotation22[Rotation22["Degree180"] = 2] = "Degree180";
16
- Rotation22[Rotation22["Degree270"] = 3] = "Degree270";
17
- return Rotation22;
18
- })(Rotation || {});
19
- function swap(size) {
20
- const { width, height } = size;
21
- return {
22
- width: height,
23
- height: width
24
- };
25
- }
26
- function rotatePosition(containerSize, position, rotation) {
27
- let x = position.x;
28
- let y = position.y;
29
- switch (rotation) {
30
- case 0:
31
- x = position.x;
32
- y = position.y;
33
- break;
34
- case 1:
35
- x = containerSize.height - position.y;
36
- y = position.x;
37
- break;
38
- case 2:
39
- x = containerSize.width - position.x;
40
- y = containerSize.height - position.y;
41
- break;
42
- case 3:
43
- x = position.y;
44
- y = containerSize.width - position.x;
45
- break;
46
- }
47
- return {
48
- x,
49
- y
50
- };
51
- }
52
- function scalePosition(position, scaleFactor) {
53
- return {
54
- x: position.x * scaleFactor,
55
- y: position.y * scaleFactor
56
- };
57
- }
58
- function transformPosition(containerSize, position, rotation, scaleFactor) {
59
- return scalePosition(rotatePosition(containerSize, position, rotation), scaleFactor);
60
- }
61
- function rotateRect(containerSize, rect, rotation) {
62
- let x = rect.origin.x;
63
- let y = rect.origin.y;
64
- let size = rect.size;
65
- switch (rotation) {
66
- case 0:
67
- break;
68
- case 1:
69
- x = containerSize.height - rect.origin.y - rect.size.height;
70
- y = rect.origin.x;
71
- size = swap(rect.size);
72
- break;
73
- case 2:
74
- x = containerSize.width - rect.origin.x - rect.size.width;
75
- y = containerSize.height - rect.origin.y - rect.size.height;
76
- break;
77
- case 3:
78
- x = rect.origin.y;
79
- y = containerSize.width - rect.origin.x - rect.size.width;
80
- size = swap(rect.size);
81
- break;
82
- }
83
- return {
84
- origin: {
85
- x,
86
- y
87
- },
88
- size: {
89
- width: size.width,
90
- height: size.height
91
- }
92
- };
93
- }
94
- function scaleRect(rect, scaleFactor) {
95
- return {
96
- origin: {
97
- x: rect.origin.x * scaleFactor,
98
- y: rect.origin.y * scaleFactor
99
- },
100
- size: {
101
- width: rect.size.width * scaleFactor,
102
- height: rect.size.height * scaleFactor
103
- }
104
- };
105
- }
106
- function transformRect(containerSize, rect, rotation, scaleFactor) {
107
- return scaleRect(rotateRect(containerSize, rect, rotation), scaleFactor);
108
- }
109
- var PdfSoftHyphenMarker = "\xAD";
110
- var PdfZeroWidthSpace = "\u200B";
111
- var PdfWordJoiner = "\u2060";
112
- var PdfBomOrZwnbsp = "\uFEFF";
113
- var PdfNonCharacterFFFE = "\uFFFE";
114
- var PdfNonCharacterFFFF = "\uFFFF";
115
- var PdfUnwantedTextMarkers = Object.freeze([
116
- PdfSoftHyphenMarker,
117
- PdfZeroWidthSpace,
118
- PdfWordJoiner,
119
- PdfBomOrZwnbsp,
120
- PdfNonCharacterFFFE,
121
- PdfNonCharacterFFFF
122
- ]);
123
- var PdfUnwantedTextRegex = new RegExp(`[${PdfUnwantedTextMarkers.join("")}]`, "g");
124
- var PdfAnnotationFlagName = Object.freeze({
125
- [
126
- 1
127
- /* INVISIBLE */
128
- ]: "invisible",
129
- [
130
- 2
131
- /* HIDDEN */
132
- ]: "hidden",
133
- [
134
- 4
135
- /* PRINT */
136
- ]: "print",
137
- [
138
- 8
139
- /* NO_ZOOM */
140
- ]: "noZoom",
141
- [
142
- 16
143
- /* NO_ROTATE */
144
- ]: "noRotate",
145
- [
146
- 32
147
- /* NO_VIEW */
148
- ]: "noView",
149
- [
150
- 64
151
- /* READ_ONLY */
152
- ]: "readOnly",
153
- [
154
- 128
155
- /* LOCKED */
156
- ]: "locked",
157
- [
158
- 256
159
- /* TOGGLE_NOVIEW */
160
- ]: "toggleNoView"
161
- });
162
- var PdfAnnotationFlagValue = Object.entries(
163
- PdfAnnotationFlagName
164
- ).reduce(
165
- (acc, [bit, name]) => {
166
- acc[name] = Number(bit);
167
- return acc;
168
- },
169
- {}
170
- );
10
+ import {
11
+ Rotation as Rotation2
12
+ } from "@embedpdf/models";
171
13
 
172
14
  // src/lib/types.ts
173
15
  var ScrollStrategy = /* @__PURE__ */ ((ScrollStrategy2) => {
@@ -177,6 +19,11 @@ var ScrollStrategy = /* @__PURE__ */ ((ScrollStrategy2) => {
177
19
  })(ScrollStrategy || {});
178
20
 
179
21
  // src/lib/strategies/base-strategy.ts
22
+ import {
23
+ scalePosition,
24
+ transformPosition,
25
+ transformRect
26
+ } from "@embedpdf/models";
180
27
  var BaseScrollStrategy = class {
181
28
  constructor(config) {
182
29
  this.pageGap = config.pageGap ?? 20;
@@ -508,13 +355,15 @@ var ScrollPlugin = class extends BasePlugin {
508
355
  this.id = id;
509
356
  this.config = config;
510
357
  this.currentScale = 1;
511
- this.currentRotation = Rotation.Degree0;
358
+ this.currentRotation = Rotation2.Degree0;
512
359
  this.currentPage = 1;
360
+ this.layoutReady = false;
513
361
  this.layout$ = createBehaviorEmitter();
514
362
  this.scroll$ = createBehaviorEmitter();
515
363
  this.state$ = createBehaviorEmitter();
516
364
  this.scrollerLayout$ = createBehaviorEmitter();
517
365
  this.pageChange$ = createBehaviorEmitter();
366
+ this.layoutReady$ = createBehaviorEmitter();
518
367
  this.viewport = this.registry.getPlugin("viewport").provides();
519
368
  this.strategyConfig = {
520
369
  pageGap: this.config?.pageGap ?? 10,
@@ -619,6 +468,11 @@ var ScrollPlugin = class extends BasePlugin {
619
468
  const pages = getPagesWithRotatedSize(this.coreState.core);
620
469
  this.refreshAll(pages, this.viewport.getMetrics());
621
470
  }
471
+ setLayoutReady() {
472
+ if (this.layoutReady) return;
473
+ this.layoutReady = true;
474
+ this.layoutReady$.emit(true);
475
+ }
622
476
  buildCapability() {
623
477
  return {
624
478
  onStateChange: this.state$.on,
@@ -626,6 +480,7 @@ var ScrollPlugin = class extends BasePlugin {
626
480
  onScroll: this.scroll$.on,
627
481
  onPageChange: this.pageChange$.on,
628
482
  onScrollerData: this.scrollerLayout$.on,
483
+ onLayoutReady: this.layoutReady$.on,
629
484
  getCurrentPage: () => this.currentPage,
630
485
  getTotalPages: () => this.state.totalPages,
631
486
  scrollToPage: (options) => {
@@ -713,6 +568,8 @@ var ScrollPlugin = class extends BasePlugin {
713
568
  this.scroll$.clear();
714
569
  this.pageChange$.clear();
715
570
  this.state$.clear();
571
+ this.scrollerLayout$.clear();
572
+ this.layoutReady$.clear();
716
573
  super.destroy();
717
574
  }
718
575
  };