Merge pull request #8828 from timvandermeij/es6-annotations

Improve the annotation code by converting to ES6 syntax and removing duplicate code
This commit is contained in:
Tim van der Meij 2017-08-31 00:02:07 +02:00 committed by GitHub
commit a4cc85fc5f
5 changed files with 1402 additions and 1682 deletions

View File

@ -31,8 +31,8 @@
"typogr": "^0.6.6",
"uglify-es": "^3.0.28",
"vinyl-fs": "^2.4.4",
"webpack": "^2.2.1",
"webpack-stream": "^3.2.0",
"webpack": "^3.5.5",
"webpack-stream": "^4.0.0",
"wintersmith": "^2.0.0",
"yargs": "^3.14.0"
},

File diff suppressed because it is too large Load Diff

View File

@ -316,10 +316,9 @@ var Page = (function PageClosure() {
get annotations() {
var annotations = [];
var annotationRefs = this.getInheritedPageProp('Annots') || [];
var annotationFactory = new AnnotationFactory();
for (var i = 0, n = annotationRefs.length; i < n; ++i) {
var annotationRef = annotationRefs[i];
var annotation = annotationFactory.create(this.xref, annotationRef,
var annotation = AnnotationFactory.create(this.xref, annotationRef,
this.pdfManager,
this.idFactory);
if (annotation) {

File diff suppressed because it is too large Load Diff

View File

@ -44,10 +44,9 @@ describe('annotation', function() {
}
IdFactoryMock.prototype = {};
var annotationFactory, pdfManagerMock, idFactoryMock;
var pdfManagerMock, idFactoryMock;
beforeAll(function (done) {
annotationFactory = new AnnotationFactory();
pdfManagerMock = new PDFManagerMock({
docBaseUrl: null,
});
@ -56,7 +55,6 @@ describe('annotation', function() {
});
afterAll(function () {
annotationFactory = null;
pdfManagerMock = null;
idFactoryMock = null;
});
@ -72,7 +70,7 @@ describe('annotation', function() {
{ ref: annotationRef, data: annotationDict, }
]);
var annotation = annotationFactory.create(xref, annotationRef,
var annotation = AnnotationFactory.create(xref, annotationRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK);
@ -92,9 +90,9 @@ describe('annotation', function() {
startObjId: 0,
});
var annotation1 = annotationFactory.create(xref, annotationDict,
var annotation1 = AnnotationFactory.create(xref, annotationDict,
pdfManagerMock, idFactory);
var annotation2 = annotationFactory.create(xref, annotationDict,
var annotation2 = AnnotationFactory.create(xref, annotationDict,
pdfManagerMock, idFactory);
var data1 = annotation1.data, data2 = annotation2.data;
expect(data1.annotationType).toEqual(AnnotationType.LINK);
@ -113,7 +111,7 @@ describe('annotation', function() {
{ ref: annotationRef, data: annotationDict, }
]);
var annotation = annotationFactory.create(xref, annotationRef,
var annotation = AnnotationFactory.create(xref, annotationRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toBeUndefined();
@ -298,7 +296,7 @@ describe('annotation', function() {
{ ref: annotationRef, data: annotationDict, }
]);
var annotation = annotationFactory.create(xref, annotationRef,
var annotation = AnnotationFactory.create(xref, annotationRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK);
@ -326,7 +324,7 @@ describe('annotation', function() {
{ ref: annotationRef, data: annotationDict, }
]);
var annotation = annotationFactory.create(xref, annotationRef,
var annotation = AnnotationFactory.create(xref, annotationRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK);
@ -359,7 +357,7 @@ describe('annotation', function() {
{ ref: annotationRef, data: annotationDict, }
]);
var annotation = annotationFactory.create(xref, annotationRef,
var annotation = AnnotationFactory.create(xref, annotationRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK);
@ -389,7 +387,7 @@ describe('annotation', function() {
{ ref: annotationRef, data: annotationDict, }
]);
var annotation = annotationFactory.create(xref, annotationRef,
var annotation = AnnotationFactory.create(xref, annotationRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK);
@ -418,7 +416,7 @@ describe('annotation', function() {
{ ref: annotationRef, data: annotationDict, }
]);
var annotation = annotationFactory.create(xref, annotationRef,
var annotation = AnnotationFactory.create(xref, annotationRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK);
@ -450,7 +448,7 @@ describe('annotation', function() {
docBaseUrl: 'http://www.example.com/test/pdfs/qwerty.pdf',
});
var annotation = annotationFactory.create(xref, annotationRef,
var annotation = AnnotationFactory.create(xref, annotationRef,
pdfManager, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK);
@ -479,7 +477,7 @@ describe('annotation', function() {
{ ref: annotationRef, data: annotationDict, }
]);
var annotation = annotationFactory.create(xref, annotationRef,
var annotation = AnnotationFactory.create(xref, annotationRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK);
@ -508,7 +506,7 @@ describe('annotation', function() {
{ ref: annotationRef, data: annotationDict, }
]);
var annotation = annotationFactory.create(xref, annotationRef,
var annotation = AnnotationFactory.create(xref, annotationRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK);
@ -548,7 +546,7 @@ describe('annotation', function() {
docBaseUrl: 'http://www.example.com/test/pdfs/qwerty.pdf',
});
var annotation = annotationFactory.create(xref, annotationRef,
var annotation = AnnotationFactory.create(xref, annotationRef,
pdfManager, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK);
@ -583,7 +581,7 @@ describe('annotation', function() {
{ ref: annotationRef, data: annotationDict, }
]);
var annotation = annotationFactory.create(xref, annotationRef,
var annotation = AnnotationFactory.create(xref, annotationRef,
pdfManagerMock,
idFactoryMock);
var data = annotation.data;
@ -635,7 +633,7 @@ describe('annotation', function() {
{ ref: annotationRef, data: annotationDict, }
]);
var annotation = annotationFactory.create(xref, annotationRef,
var annotation = AnnotationFactory.create(xref, annotationRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK);
@ -656,7 +654,7 @@ describe('annotation', function() {
{ ref: annotationRef, data: annotationDict, }
]);
var annotation = annotationFactory.create(xref, annotationRef,
var annotation = AnnotationFactory.create(xref, annotationRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK);
@ -679,7 +677,7 @@ describe('annotation', function() {
{ ref: annotationRef, data: annotationDict, }
]);
var annotation = annotationFactory.create(xref, annotationRef,
var annotation = AnnotationFactory.create(xref, annotationRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK);
@ -709,7 +707,7 @@ describe('annotation', function() {
{ ref: annotationRef, data: annotationDict, }
]);
let annotation = annotationFactory.create(xref, annotationRef,
let annotation = AnnotationFactory.create(xref, annotationRef,
pdfManagerMock, idFactoryMock);
let data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINK);
@ -742,7 +740,7 @@ describe('annotation', function() {
{ ref: widgetRef, data: widgetDict, }
]);
var annotation = annotationFactory.create(xref, widgetRef,
var annotation = AnnotationFactory.create(xref, widgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
@ -759,7 +757,7 @@ describe('annotation', function() {
{ ref: widgetRef, data: widgetDict, }
]);
var annotation = annotationFactory.create(xref, widgetRef,
var annotation = AnnotationFactory.create(xref, widgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
@ -783,7 +781,7 @@ describe('annotation', function() {
{ ref: widgetRef, data: widgetDict, }
]);
var annotation = annotationFactory.create(xref, widgetRef,
var annotation = AnnotationFactory.create(xref, widgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
@ -805,7 +803,7 @@ describe('annotation', function() {
{ ref: widgetRef, data: widgetDict, }
]);
var annotation = annotationFactory.create(xref, widgetRef,
var annotation = AnnotationFactory.create(xref, widgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
@ -837,7 +835,7 @@ describe('annotation', function() {
{ ref: textWidgetRef, data: textWidgetDict, }
]);
var annotation = annotationFactory.create(xref, textWidgetRef,
var annotation = AnnotationFactory.create(xref, textWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
@ -860,7 +858,7 @@ describe('annotation', function() {
{ ref: textWidgetRef, data: textWidgetDict, }
]);
var annotation = annotationFactory.create(xref, textWidgetRef,
var annotation = AnnotationFactory.create(xref, textWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
@ -884,7 +882,7 @@ describe('annotation', function() {
{ ref: textWidgetRef, data: textWidgetDict, }
]);
var annotation = annotationFactory.create(xref, textWidgetRef,
var annotation = AnnotationFactory.create(xref, textWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
@ -903,7 +901,7 @@ describe('annotation', function() {
{ ref: textWidgetRef, data: textWidgetDict, }
]);
var annotation = annotationFactory.create(xref, textWidgetRef,
var annotation = AnnotationFactory.create(xref, textWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
@ -920,7 +918,7 @@ describe('annotation', function() {
{ ref: textWidgetRef, data: textWidgetDict, }
]);
var annotation = annotationFactory.create(xref, textWidgetRef,
var annotation = AnnotationFactory.create(xref, textWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
@ -948,7 +946,7 @@ describe('annotation', function() {
{ ref: textWidgetRef, data: textWidgetDict, }
]);
var annotation = annotationFactory.create(xref, textWidgetRef,
var annotation = AnnotationFactory.create(xref, textWidgetRef,
pdfManagerMock,
idFactoryMock);
var data = annotation.data;
@ -989,7 +987,7 @@ describe('annotation', function() {
{ ref: buttonWidgetRef, data: buttonWidgetDict, }
]);
var annotation = annotationFactory.create(xref, buttonWidgetRef,
var annotation = AnnotationFactory.create(xref, buttonWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
@ -1018,7 +1016,7 @@ describe('annotation', function() {
{ ref: buttonWidgetRef, data: buttonWidgetDict, }
]);
var annotation = annotationFactory.create(xref, buttonWidgetRef,
var annotation = AnnotationFactory.create(xref, buttonWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
@ -1044,7 +1042,7 @@ describe('annotation', function() {
{ ref: buttonWidgetRef, data: buttonWidgetDict, }
]);
var annotation = annotationFactory.create(xref, buttonWidgetRef,
var annotation = AnnotationFactory.create(xref, buttonWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
@ -1078,7 +1076,7 @@ describe('annotation', function() {
{ ref: choiceWidgetRef, data: choiceWidgetDict, }
]);
var annotation = annotationFactory.create(xref, choiceWidgetRef,
var annotation = AnnotationFactory.create(xref, choiceWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
@ -1113,7 +1111,7 @@ describe('annotation', function() {
{ ref: optionOneRef, data: optionOneArr, },
]);
var annotation = annotationFactory.create(xref, choiceWidgetRef,
var annotation = AnnotationFactory.create(xref, choiceWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
@ -1145,7 +1143,7 @@ describe('annotation', function() {
{ ref: optionBarRef, data: optionBarStr, }
]);
var annotation = annotationFactory.create(xref, choiceWidgetRef,
var annotation = AnnotationFactory.create(xref, choiceWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
@ -1173,7 +1171,7 @@ describe('annotation', function() {
{ ref: choiceWidgetRef, data: choiceWidgetDict, },
]);
var annotation = annotationFactory.create(xref, choiceWidgetRef,
var annotation = AnnotationFactory.create(xref, choiceWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
@ -1191,7 +1189,7 @@ describe('annotation', function() {
{ ref: choiceWidgetRef, data: choiceWidgetDict, }
]);
var annotation = annotationFactory.create(xref, choiceWidgetRef,
var annotation = AnnotationFactory.create(xref, choiceWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
@ -1209,7 +1207,7 @@ describe('annotation', function() {
{ ref: choiceWidgetRef, data: choiceWidgetDict, }
]);
var annotation = annotationFactory.create(xref, choiceWidgetRef,
var annotation = AnnotationFactory.create(xref, choiceWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
@ -1223,7 +1221,7 @@ describe('annotation', function() {
{ ref: choiceWidgetRef, data: choiceWidgetDict, }
]);
var annotation = annotationFactory.create(xref, choiceWidgetRef,
var annotation = AnnotationFactory.create(xref, choiceWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
@ -1241,7 +1239,7 @@ describe('annotation', function() {
{ ref: choiceWidgetRef, data: choiceWidgetDict, }
]);
var annotation = annotationFactory.create(xref, choiceWidgetRef,
var annotation = AnnotationFactory.create(xref, choiceWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
@ -1261,7 +1259,7 @@ describe('annotation', function() {
{ ref: choiceWidgetRef, data: choiceWidgetDict, }
]);
var annotation = annotationFactory.create(xref, choiceWidgetRef,
var annotation = AnnotationFactory.create(xref, choiceWidgetRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.WIDGET);
@ -1284,7 +1282,7 @@ describe('annotation', function() {
{ ref: lineRef, data: lineDict, }
]);
var annotation = annotationFactory.create(xref, lineRef, pdfManagerMock,
var annotation = AnnotationFactory.create(xref, lineRef, pdfManagerMock,
idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.LINE);
@ -1337,7 +1335,7 @@ describe('annotation', function() {
fileSpecDict.assignXref(xref);
fileAttachmentDict.assignXref(xref);
var annotation = annotationFactory.create(xref, fileAttachmentRef,
var annotation = AnnotationFactory.create(xref, fileAttachmentRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.FILEATTACHMENT);
@ -1366,7 +1364,7 @@ describe('annotation', function() {
{ ref: popupRef, data: popupDict, }
]);
var annotation = annotationFactory.create(xref, popupRef,
var annotation = AnnotationFactory.create(xref, popupRef,
pdfManagerMock, idFactoryMock);
var data = annotation.data;
expect(data.annotationType).toEqual(AnnotationType.POPUP);