Skip to content

Commit aee8dc0

Browse files
committed
Move the Default{...}LayerFactory into a new web/default_factory.js file
This first of all removes circular dependencies in the TypeScript definitions. Secondly, it also *slightly* reduces the size of the default viewer (e.g. in the `MOZCENTRAL` build) by not having to bundle code which is completely unused.
1 parent 2645a0c commit aee8dc0

6 files changed

+177
-148
lines changed

web/annotation_layer_builder.js

+1-55
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,10 @@
1818
/** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */
1919
/** @typedef {import("./interfaces").IDownloadManager} IDownloadManager */
2020
/** @typedef {import("./interfaces").IL10n} IL10n */
21-
// eslint-disable-next-line max-len
22-
/** @typedef {import("./interfaces").IPDFAnnotationLayerFactory} IPDFAnnotationLayerFactory */
2321
/** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */
2422

2523
import { AnnotationLayer } from "pdfjs-lib";
2624
import { NullL10n } from "./l10n_utils.js";
27-
import { SimpleLinkService } from "./pdf_link_service.js";
2825

2926
/**
3027
* @typedef {Object} AnnotationLayerBuilderOptions
@@ -146,55 +143,4 @@ class AnnotationLayerBuilder {
146143
}
147144
}
148145

149-
/**
150-
* @implements IPDFAnnotationLayerFactory
151-
*/
152-
class DefaultAnnotationLayerFactory {
153-
/**
154-
* @param {HTMLDivElement} pageDiv
155-
* @param {PDFPageProxy} pdfPage
156-
* @param {AnnotationStorage} [annotationStorage]
157-
* @param {string} [imageResourcesPath] - Path for image resources, mainly
158-
* for annotation icons. Include trailing slash.
159-
* @param {boolean} renderForms
160-
* @param {IL10n} l10n
161-
* @param {boolean} [enableScripting]
162-
* @param {Promise<boolean>} [hasJSActionsPromise]
163-
* @param {Object} [mouseState]
164-
* @param {Promise<Object<string, Array<Object>> | null>}
165-
* [fieldObjectsPromise]
166-
* @param {Map<string, HTMLCanvasElement>} [annotationCanvasMap] - Map some
167-
* annotation ids with canvases used to render them.
168-
* @returns {AnnotationLayerBuilder}
169-
*/
170-
createAnnotationLayerBuilder(
171-
pageDiv,
172-
pdfPage,
173-
annotationStorage = null,
174-
imageResourcesPath = "",
175-
renderForms = true,
176-
l10n = NullL10n,
177-
enableScripting = false,
178-
hasJSActionsPromise = null,
179-
mouseState = null,
180-
fieldObjectsPromise = null,
181-
annotationCanvasMap = null
182-
) {
183-
return new AnnotationLayerBuilder({
184-
pageDiv,
185-
pdfPage,
186-
imageResourcesPath,
187-
renderForms,
188-
linkService: new SimpleLinkService(),
189-
l10n,
190-
annotationStorage,
191-
enableScripting,
192-
hasJSActionsPromise,
193-
fieldObjectsPromise,
194-
mouseState,
195-
annotationCanvasMap,
196-
});
197-
}
198-
}
199-
200-
export { AnnotationLayerBuilder, DefaultAnnotationLayerFactory };
146+
export { AnnotationLayerBuilder };

web/default_factory.js

+168
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
/* Copyright 2014 Mozilla Foundation
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
/** @typedef {import("../src/display/api").PDFPageProxy} PDFPageProxy */
17+
// eslint-disable-next-line max-len
18+
/** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */
19+
/** @typedef {import("./interfaces").IDownloadManager} IDownloadManager */
20+
/** @typedef {import("./interfaces").IL10n} IL10n */
21+
// eslint-disable-next-line max-len
22+
/** @typedef {import("./interfaces").IPDFAnnotationLayerFactory} IPDFAnnotationLayerFactory */
23+
/** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */
24+
// eslint-disable-next-line max-len
25+
/** @typedef {import("./interfaces").IPDFStructTreeLayerFactory} IPDFStructTreeLayerFactory */
26+
// eslint-disable-next-line max-len
27+
/** @typedef {import("./interfaces").IPDFTextLayerFactory} IPDFTextLayerFactory */
28+
/** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */
29+
/** @typedef {import("./text_highlighter").TextHighlighter} TextHighlighter */
30+
/** @typedef {import("./ui_utils").EventBus} EventBus */
31+
32+
import { AnnotationLayerBuilder } from "./annotation_layer_builder.js";
33+
import { NullL10n } from "./l10n_utils.js";
34+
import { SimpleLinkService } from "./pdf_link_service.js";
35+
import { StructTreeLayerBuilder } from "./struct_tree_layer_builder.js";
36+
import { TextLayerBuilder } from "./text_layer_builder.js";
37+
import { XfaLayerBuilder } from "./xfa_layer_builder.js";
38+
39+
/**
40+
* @implements IPDFAnnotationLayerFactory
41+
*/
42+
class DefaultAnnotationLayerFactory {
43+
/**
44+
* @param {HTMLDivElement} pageDiv
45+
* @param {PDFPageProxy} pdfPage
46+
* @param {AnnotationStorage} [annotationStorage]
47+
* @param {string} [imageResourcesPath] - Path for image resources, mainly
48+
* for annotation icons. Include trailing slash.
49+
* @param {boolean} renderForms
50+
* @param {IL10n} l10n
51+
* @param {boolean} [enableScripting]
52+
* @param {Promise<boolean>} [hasJSActionsPromise]
53+
* @param {Object} [mouseState]
54+
* @param {Promise<Object<string, Array<Object>> | null>}
55+
* [fieldObjectsPromise]
56+
* @param {Map<string, HTMLCanvasElement>} [annotationCanvasMap] - Map some
57+
* annotation ids with canvases used to render them.
58+
* @returns {AnnotationLayerBuilder}
59+
*/
60+
createAnnotationLayerBuilder(
61+
pageDiv,
62+
pdfPage,
63+
annotationStorage = null,
64+
imageResourcesPath = "",
65+
renderForms = true,
66+
l10n = NullL10n,
67+
enableScripting = false,
68+
hasJSActionsPromise = null,
69+
mouseState = null,
70+
fieldObjectsPromise = null,
71+
annotationCanvasMap = null
72+
) {
73+
return new AnnotationLayerBuilder({
74+
pageDiv,
75+
pdfPage,
76+
imageResourcesPath,
77+
renderForms,
78+
linkService: new SimpleLinkService(),
79+
l10n,
80+
annotationStorage,
81+
enableScripting,
82+
hasJSActionsPromise,
83+
fieldObjectsPromise,
84+
mouseState,
85+
annotationCanvasMap,
86+
});
87+
}
88+
}
89+
90+
/**
91+
* @implements IPDFStructTreeLayerFactory
92+
*/
93+
class DefaultStructTreeLayerFactory {
94+
/**
95+
* @param {PDFPageProxy} pdfPage
96+
* @returns {StructTreeLayerBuilder}
97+
*/
98+
createStructTreeLayerBuilder(pdfPage) {
99+
return new StructTreeLayerBuilder({
100+
pdfPage,
101+
});
102+
}
103+
}
104+
105+
/**
106+
* @implements IPDFTextLayerFactory
107+
*/
108+
class DefaultTextLayerFactory {
109+
/**
110+
* @param {HTMLDivElement} textLayerDiv
111+
* @param {number} pageIndex
112+
* @param {PageViewport} viewport
113+
* @param {boolean} enhanceTextSelection
114+
* @param {EventBus} eventBus
115+
* @param {TextHighlighter} highlighter
116+
* @returns {TextLayerBuilder}
117+
*/
118+
createTextLayerBuilder(
119+
textLayerDiv,
120+
pageIndex,
121+
viewport,
122+
enhanceTextSelection = false,
123+
eventBus,
124+
highlighter
125+
) {
126+
return new TextLayerBuilder({
127+
textLayerDiv,
128+
pageIndex,
129+
viewport,
130+
enhanceTextSelection,
131+
eventBus,
132+
highlighter,
133+
});
134+
}
135+
}
136+
137+
/**
138+
* @implements IPDFXfaLayerFactory
139+
*/
140+
class DefaultXfaLayerFactory {
141+
/**
142+
* @param {HTMLDivElement} pageDiv
143+
* @param {PDFPageProxy} pdfPage
144+
* @param {AnnotationStorage} [annotationStorage]
145+
* @param {Object} [xfaHtml]
146+
*/
147+
createXfaLayerBuilder(
148+
pageDiv,
149+
pdfPage,
150+
annotationStorage = null,
151+
xfaHtml = null
152+
) {
153+
return new XfaLayerBuilder({
154+
pageDiv,
155+
pdfPage,
156+
annotationStorage,
157+
linkService: new SimpleLinkService(),
158+
xfaHtml,
159+
});
160+
}
161+
}
162+
163+
export {
164+
DefaultAnnotationLayerFactory,
165+
DefaultStructTreeLayerFactory,
166+
DefaultTextLayerFactory,
167+
DefaultXfaLayerFactory,
168+
};

web/pdf_viewer.component.js

+5-11
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,25 @@
1414
*/
1515

1616
import {
17-
AnnotationLayerBuilder,
1817
DefaultAnnotationLayerFactory,
19-
} from "./annotation_layer_builder.js";
20-
import {
2118
DefaultStructTreeLayerFactory,
22-
StructTreeLayerBuilder,
23-
} from "./struct_tree_layer_builder.js";
24-
import {
2519
DefaultTextLayerFactory,
26-
TextLayerBuilder,
27-
} from "./text_layer_builder.js";
28-
import {
2920
DefaultXfaLayerFactory,
30-
XfaLayerBuilder,
31-
} from "./xfa_layer_builder.js";
21+
} from "./default_factory.js";
3222
import { EventBus, ProgressBar } from "./ui_utils.js";
3323
import { PDFLinkService, SimpleLinkService } from "./pdf_link_service.js";
3424
import { PDFSinglePageViewer, PDFViewer } from "./pdf_viewer.js";
25+
import { AnnotationLayerBuilder } from "./annotation_layer_builder.js";
3526
import { DownloadManager } from "./download_manager.js";
3627
import { GenericL10n } from "./genericl10n.js";
3728
import { NullL10n } from "./l10n_utils.js";
3829
import { PDFFindController } from "./pdf_find_controller.js";
3930
import { PDFHistory } from "./pdf_history.js";
4031
import { PDFPageView } from "./pdf_page_view.js";
4132
import { PDFScriptingManager } from "./pdf_scripting_manager.js";
33+
import { StructTreeLayerBuilder } from "./struct_tree_layer_builder.js";
34+
import { TextLayerBuilder } from "./text_layer_builder.js";
35+
import { XfaLayerBuilder } from "./xfa_layer_builder.js";
4236

4337
// eslint-disable-next-line no-unused-vars
4438
const pdfjsVersion = PDFJSDev.eval("BUNDLE_VERSION");

web/struct_tree_layer_builder.js

+1-18
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
*/
1515

1616
/** @typedef {import("../src/display/api").PDFPageProxy} PDFPageProxy */
17-
// eslint-disable-next-line max-len
18-
/** @typedef {import("./interfaces").IPDFStructTreeLayerFactory} IPDFStructTreeLayerFactory */
1917

2018
const PDF_ROLE_TO_HTML_ROLE = {
2119
// Document level structure types
@@ -138,19 +136,4 @@ class StructTreeLayerBuilder {
138136
}
139137
}
140138

141-
/**
142-
* @implements IPDFStructTreeLayerFactory
143-
*/
144-
class DefaultStructTreeLayerFactory {
145-
/**
146-
* @param {PDFPageProxy} pdfPage
147-
* @returns {StructTreeLayerBuilder}
148-
*/
149-
createStructTreeLayerBuilder(pdfPage) {
150-
return new StructTreeLayerBuilder({
151-
pdfPage,
152-
});
153-
}
154-
}
155-
156-
export { DefaultStructTreeLayerFactory, StructTreeLayerBuilder };
139+
export { StructTreeLayerBuilder };

web/text_layer_builder.js

+1-35
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
// eslint-disable-next-line max-len
1717
/** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */
18-
// eslint-disable-next-line max-len
19-
/** @typedef {import("./interfaces").IPDFTextLayerFactory} IPDFTextLayerFactory */
2018
/** @typedef {import("./text_highlighter").TextHighlighter} TextHighlighter */
2119
/** @typedef {import("./ui_utils").EventBus} EventBus */
2220

@@ -221,36 +219,4 @@ class TextLayerBuilder {
221219
}
222220
}
223221

224-
/**
225-
* @implements IPDFTextLayerFactory
226-
*/
227-
class DefaultTextLayerFactory {
228-
/**
229-
* @param {HTMLDivElement} textLayerDiv
230-
* @param {number} pageIndex
231-
* @param {PageViewport} viewport
232-
* @param {boolean} enhanceTextSelection
233-
* @param {EventBus} eventBus
234-
* @param {TextHighlighter} highlighter
235-
* @returns {TextLayerBuilder}
236-
*/
237-
createTextLayerBuilder(
238-
textLayerDiv,
239-
pageIndex,
240-
viewport,
241-
enhanceTextSelection = false,
242-
eventBus,
243-
highlighter
244-
) {
245-
return new TextLayerBuilder({
246-
textLayerDiv,
247-
pageIndex,
248-
viewport,
249-
enhanceTextSelection,
250-
eventBus,
251-
highlighter,
252-
});
253-
}
254-
}
255-
256-
export { DefaultTextLayerFactory, TextLayerBuilder };
222+
export { TextLayerBuilder };

web/xfa_layer_builder.js

+1-29
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
// eslint-disable-next-line max-len
1818
/** @typedef {import("../src/display/display_utils").PageViewport} PageViewport */
1919
/** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */
20-
/** @typedef {import("./interfaces").IPDFXfaLayerFactory} IPDFXfaLayerFactory */
2120

22-
import { SimpleLinkService } from "./pdf_link_service.js";
2321
import { XfaLayer } from "pdfjs-lib";
2422

2523
/**
@@ -124,30 +122,4 @@ class XfaLayerBuilder {
124122
}
125123
}
126124

127-
/**
128-
* @implements IPDFXfaLayerFactory
129-
*/
130-
class DefaultXfaLayerFactory {
131-
/**
132-
* @param {HTMLDivElement} pageDiv
133-
* @param {PDFPageProxy} pdfPage
134-
* @param {AnnotationStorage} [annotationStorage]
135-
* @param {Object} [xfaHtml]
136-
*/
137-
createXfaLayerBuilder(
138-
pageDiv,
139-
pdfPage,
140-
annotationStorage = null,
141-
xfaHtml = null
142-
) {
143-
return new XfaLayerBuilder({
144-
pageDiv,
145-
pdfPage,
146-
annotationStorage,
147-
linkService: new SimpleLinkService(),
148-
xfaHtml,
149-
});
150-
}
151-
}
152-
153-
export { DefaultXfaLayerFactory, XfaLayerBuilder };
125+
export { XfaLayerBuilder };

0 commit comments

Comments
 (0)