@embedpdf/plugin-scroll 1.0.9 → 1.0.10
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 +7 -166
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +9 -162
- package/dist/index.js.map +1 -1
- package/package.json +7 -6
package/dist/index.cjs
CHANGED
|
@@ -30,167 +30,7 @@ module.exports = __toCommonJS(index_exports);
|
|
|
30
30
|
|
|
31
31
|
// src/lib/scroll-plugin.ts
|
|
32
32
|
var import_core = require("@embedpdf/core");
|
|
33
|
-
|
|
34
|
-
// ../models/dist/index.js
|
|
35
|
-
var Rotation = /* @__PURE__ */ ((Rotation22) => {
|
|
36
|
-
Rotation22[Rotation22["Degree0"] = 0] = "Degree0";
|
|
37
|
-
Rotation22[Rotation22["Degree90"] = 1] = "Degree90";
|
|
38
|
-
Rotation22[Rotation22["Degree180"] = 2] = "Degree180";
|
|
39
|
-
Rotation22[Rotation22["Degree270"] = 3] = "Degree270";
|
|
40
|
-
return Rotation22;
|
|
41
|
-
})(Rotation || {});
|
|
42
|
-
function swap(size) {
|
|
43
|
-
const { width, height } = size;
|
|
44
|
-
return {
|
|
45
|
-
width: height,
|
|
46
|
-
height: width
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
function rotatePosition(containerSize, position, rotation) {
|
|
50
|
-
let x = position.x;
|
|
51
|
-
let y = position.y;
|
|
52
|
-
switch (rotation) {
|
|
53
|
-
case 0:
|
|
54
|
-
x = position.x;
|
|
55
|
-
y = position.y;
|
|
56
|
-
break;
|
|
57
|
-
case 1:
|
|
58
|
-
x = containerSize.height - position.y;
|
|
59
|
-
y = position.x;
|
|
60
|
-
break;
|
|
61
|
-
case 2:
|
|
62
|
-
x = containerSize.width - position.x;
|
|
63
|
-
y = containerSize.height - position.y;
|
|
64
|
-
break;
|
|
65
|
-
case 3:
|
|
66
|
-
x = position.y;
|
|
67
|
-
y = containerSize.width - position.x;
|
|
68
|
-
break;
|
|
69
|
-
}
|
|
70
|
-
return {
|
|
71
|
-
x,
|
|
72
|
-
y
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
function scalePosition(position, scaleFactor) {
|
|
76
|
-
return {
|
|
77
|
-
x: position.x * scaleFactor,
|
|
78
|
-
y: position.y * scaleFactor
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
function transformPosition(containerSize, position, rotation, scaleFactor) {
|
|
82
|
-
return scalePosition(rotatePosition(containerSize, position, rotation), scaleFactor);
|
|
83
|
-
}
|
|
84
|
-
function rotateRect(containerSize, rect, rotation) {
|
|
85
|
-
let x = rect.origin.x;
|
|
86
|
-
let y = rect.origin.y;
|
|
87
|
-
let size = rect.size;
|
|
88
|
-
switch (rotation) {
|
|
89
|
-
case 0:
|
|
90
|
-
break;
|
|
91
|
-
case 1:
|
|
92
|
-
x = containerSize.height - rect.origin.y - rect.size.height;
|
|
93
|
-
y = rect.origin.x;
|
|
94
|
-
size = swap(rect.size);
|
|
95
|
-
break;
|
|
96
|
-
case 2:
|
|
97
|
-
x = containerSize.width - rect.origin.x - rect.size.width;
|
|
98
|
-
y = containerSize.height - rect.origin.y - rect.size.height;
|
|
99
|
-
break;
|
|
100
|
-
case 3:
|
|
101
|
-
x = rect.origin.y;
|
|
102
|
-
y = containerSize.width - rect.origin.x - rect.size.width;
|
|
103
|
-
size = swap(rect.size);
|
|
104
|
-
break;
|
|
105
|
-
}
|
|
106
|
-
return {
|
|
107
|
-
origin: {
|
|
108
|
-
x,
|
|
109
|
-
y
|
|
110
|
-
},
|
|
111
|
-
size: {
|
|
112
|
-
width: size.width,
|
|
113
|
-
height: size.height
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
function scaleRect(rect, scaleFactor) {
|
|
118
|
-
return {
|
|
119
|
-
origin: {
|
|
120
|
-
x: rect.origin.x * scaleFactor,
|
|
121
|
-
y: rect.origin.y * scaleFactor
|
|
122
|
-
},
|
|
123
|
-
size: {
|
|
124
|
-
width: rect.size.width * scaleFactor,
|
|
125
|
-
height: rect.size.height * scaleFactor
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
function transformRect(containerSize, rect, rotation, scaleFactor) {
|
|
130
|
-
return scaleRect(rotateRect(containerSize, rect, rotation), scaleFactor);
|
|
131
|
-
}
|
|
132
|
-
var PdfSoftHyphenMarker = "\xAD";
|
|
133
|
-
var PdfZeroWidthSpace = "\u200B";
|
|
134
|
-
var PdfWordJoiner = "\u2060";
|
|
135
|
-
var PdfBomOrZwnbsp = "\uFEFF";
|
|
136
|
-
var PdfNonCharacterFFFE = "\uFFFE";
|
|
137
|
-
var PdfNonCharacterFFFF = "\uFFFF";
|
|
138
|
-
var PdfUnwantedTextMarkers = Object.freeze([
|
|
139
|
-
PdfSoftHyphenMarker,
|
|
140
|
-
PdfZeroWidthSpace,
|
|
141
|
-
PdfWordJoiner,
|
|
142
|
-
PdfBomOrZwnbsp,
|
|
143
|
-
PdfNonCharacterFFFE,
|
|
144
|
-
PdfNonCharacterFFFF
|
|
145
|
-
]);
|
|
146
|
-
var PdfUnwantedTextRegex = new RegExp(`[${PdfUnwantedTextMarkers.join("")}]`, "g");
|
|
147
|
-
var PdfAnnotationFlagName = Object.freeze({
|
|
148
|
-
[
|
|
149
|
-
1
|
|
150
|
-
/* INVISIBLE */
|
|
151
|
-
]: "invisible",
|
|
152
|
-
[
|
|
153
|
-
2
|
|
154
|
-
/* HIDDEN */
|
|
155
|
-
]: "hidden",
|
|
156
|
-
[
|
|
157
|
-
4
|
|
158
|
-
/* PRINT */
|
|
159
|
-
]: "print",
|
|
160
|
-
[
|
|
161
|
-
8
|
|
162
|
-
/* NO_ZOOM */
|
|
163
|
-
]: "noZoom",
|
|
164
|
-
[
|
|
165
|
-
16
|
|
166
|
-
/* NO_ROTATE */
|
|
167
|
-
]: "noRotate",
|
|
168
|
-
[
|
|
169
|
-
32
|
|
170
|
-
/* NO_VIEW */
|
|
171
|
-
]: "noView",
|
|
172
|
-
[
|
|
173
|
-
64
|
|
174
|
-
/* READ_ONLY */
|
|
175
|
-
]: "readOnly",
|
|
176
|
-
[
|
|
177
|
-
128
|
|
178
|
-
/* LOCKED */
|
|
179
|
-
]: "locked",
|
|
180
|
-
[
|
|
181
|
-
256
|
|
182
|
-
/* TOGGLE_NOVIEW */
|
|
183
|
-
]: "toggleNoView"
|
|
184
|
-
});
|
|
185
|
-
var PdfAnnotationFlagValue = Object.entries(
|
|
186
|
-
PdfAnnotationFlagName
|
|
187
|
-
).reduce(
|
|
188
|
-
(acc, [bit, name]) => {
|
|
189
|
-
acc[name] = Number(bit);
|
|
190
|
-
return acc;
|
|
191
|
-
},
|
|
192
|
-
{}
|
|
193
|
-
);
|
|
33
|
+
var import_models2 = require("@embedpdf/models");
|
|
194
34
|
|
|
195
35
|
// src/lib/types.ts
|
|
196
36
|
var ScrollStrategy = /* @__PURE__ */ ((ScrollStrategy2) => {
|
|
@@ -200,6 +40,7 @@ var ScrollStrategy = /* @__PURE__ */ ((ScrollStrategy2) => {
|
|
|
200
40
|
})(ScrollStrategy || {});
|
|
201
41
|
|
|
202
42
|
// src/lib/strategies/base-strategy.ts
|
|
43
|
+
var import_models = require("@embedpdf/models");
|
|
203
44
|
var BaseScrollStrategy = class {
|
|
204
45
|
constructor(config) {
|
|
205
46
|
this.pageGap = config.pageGap ?? 20;
|
|
@@ -320,9 +161,9 @@ var BaseScrollStrategy = class {
|
|
|
320
161
|
getScrollPositionForPage(pageNumber, virtualItems, scale, rotation, pageCoordinates) {
|
|
321
162
|
const pageRect = this.getRectLocationForPage(pageNumber, virtualItems);
|
|
322
163
|
if (!pageRect) return null;
|
|
323
|
-
const scaledBasePosition = scalePosition(pageRect.origin, scale);
|
|
164
|
+
const scaledBasePosition = (0, import_models.scalePosition)(pageRect.origin, scale);
|
|
324
165
|
if (pageCoordinates) {
|
|
325
|
-
const rotatedSize = transformPosition(
|
|
166
|
+
const rotatedSize = (0, import_models.transformPosition)(
|
|
326
167
|
{
|
|
327
168
|
width: pageRect.size.width,
|
|
328
169
|
height: pageRect.size.height
|
|
@@ -347,8 +188,8 @@ var BaseScrollStrategy = class {
|
|
|
347
188
|
getRectPositionForPage(pageNumber, virtualItems, scale, rotation, rect) {
|
|
348
189
|
const pageRect = this.getRectLocationForPage(pageNumber, virtualItems);
|
|
349
190
|
if (!pageRect) return null;
|
|
350
|
-
const scaledBasePosition = scalePosition(pageRect.origin, scale);
|
|
351
|
-
const rotatedSize = transformRect(
|
|
191
|
+
const scaledBasePosition = (0, import_models.scalePosition)(pageRect.origin, scale);
|
|
192
|
+
const rotatedSize = (0, import_models.transformRect)(
|
|
352
193
|
{
|
|
353
194
|
width: pageRect.size.width,
|
|
354
195
|
height: pageRect.size.height
|
|
@@ -531,7 +372,7 @@ var ScrollPlugin = class extends import_core.BasePlugin {
|
|
|
531
372
|
this.id = id;
|
|
532
373
|
this.config = config;
|
|
533
374
|
this.currentScale = 1;
|
|
534
|
-
this.currentRotation = Rotation.Degree0;
|
|
375
|
+
this.currentRotation = import_models2.Rotation.Degree0;
|
|
535
376
|
this.currentPage = 1;
|
|
536
377
|
this.layout$ = (0, import_core.createBehaviorEmitter)();
|
|
537
378
|
this.scroll$ = (0, import_core.createBehaviorEmitter)();
|