annotation_layer.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. /* Copyright 2017 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. 'use strict';
  16. Object.defineProperty(exports, "__esModule", {
  17. value: true
  18. });
  19. exports.AnnotationLayer = undefined;
  20. var _dom_utils = require('./dom_utils');
  21. var _util = require('../shared/util');
  22. function AnnotationElementFactory() {}
  23. AnnotationElementFactory.prototype = {
  24. create: function AnnotationElementFactory_create(parameters) {
  25. var subtype = parameters.data.annotationType;
  26. switch (subtype) {
  27. case _util.AnnotationType.LINK:
  28. return new LinkAnnotationElement(parameters);
  29. case _util.AnnotationType.TEXT:
  30. return new TextAnnotationElement(parameters);
  31. case _util.AnnotationType.WIDGET:
  32. var fieldType = parameters.data.fieldType;
  33. switch (fieldType) {
  34. case 'Tx':
  35. return new TextWidgetAnnotationElement(parameters);
  36. case 'Btn':
  37. if (parameters.data.radioButton) {
  38. return new RadioButtonWidgetAnnotationElement(parameters);
  39. } else if (parameters.data.checkBox) {
  40. return new CheckboxWidgetAnnotationElement(parameters);
  41. }
  42. (0, _util.warn)('Unimplemented button widget annotation: pushbutton');
  43. break;
  44. case 'Ch':
  45. return new ChoiceWidgetAnnotationElement(parameters);
  46. }
  47. return new WidgetAnnotationElement(parameters);
  48. case _util.AnnotationType.POPUP:
  49. return new PopupAnnotationElement(parameters);
  50. case _util.AnnotationType.LINE:
  51. return new LineAnnotationElement(parameters);
  52. case _util.AnnotationType.HIGHLIGHT:
  53. return new HighlightAnnotationElement(parameters);
  54. case _util.AnnotationType.UNDERLINE:
  55. return new UnderlineAnnotationElement(parameters);
  56. case _util.AnnotationType.SQUIGGLY:
  57. return new SquigglyAnnotationElement(parameters);
  58. case _util.AnnotationType.STRIKEOUT:
  59. return new StrikeOutAnnotationElement(parameters);
  60. case _util.AnnotationType.FILEATTACHMENT:
  61. return new FileAttachmentAnnotationElement(parameters);
  62. default:
  63. return new AnnotationElement(parameters);
  64. }
  65. }
  66. };
  67. var AnnotationElement = function AnnotationElementClosure() {
  68. function AnnotationElement(parameters, isRenderable, ignoreBorder) {
  69. this.isRenderable = isRenderable || false;
  70. this.data = parameters.data;
  71. this.layer = parameters.layer;
  72. this.page = parameters.page;
  73. this.viewport = parameters.viewport;
  74. this.linkService = parameters.linkService;
  75. this.downloadManager = parameters.downloadManager;
  76. this.imageResourcesPath = parameters.imageResourcesPath;
  77. this.renderInteractiveForms = parameters.renderInteractiveForms;
  78. if (isRenderable) {
  79. this.container = this._createContainer(ignoreBorder);
  80. }
  81. }
  82. AnnotationElement.prototype = {
  83. _createContainer: function AnnotationElement_createContainer(ignoreBorder) {
  84. var data = this.data,
  85. page = this.page,
  86. viewport = this.viewport;
  87. var container = document.createElement('section');
  88. var width = data.rect[2] - data.rect[0];
  89. var height = data.rect[3] - data.rect[1];
  90. container.setAttribute('data-annotation-id', data.id);
  91. var rect = _util.Util.normalizeRect([data.rect[0], page.view[3] - data.rect[1] + page.view[1], data.rect[2], page.view[3] - data.rect[3] + page.view[1]]);
  92. _dom_utils.CustomStyle.setProp('transform', container, 'matrix(' + viewport.transform.join(',') + ')');
  93. _dom_utils.CustomStyle.setProp('transformOrigin', container, -rect[0] + 'px ' + -rect[1] + 'px');
  94. if (!ignoreBorder && data.borderStyle.width > 0) {
  95. container.style.borderWidth = data.borderStyle.width + 'px';
  96. if (data.borderStyle.style !== _util.AnnotationBorderStyleType.UNDERLINE) {
  97. width = width - 2 * data.borderStyle.width;
  98. height = height - 2 * data.borderStyle.width;
  99. }
  100. var horizontalRadius = data.borderStyle.horizontalCornerRadius;
  101. var verticalRadius = data.borderStyle.verticalCornerRadius;
  102. if (horizontalRadius > 0 || verticalRadius > 0) {
  103. var radius = horizontalRadius + 'px / ' + verticalRadius + 'px';
  104. _dom_utils.CustomStyle.setProp('borderRadius', container, radius);
  105. }
  106. switch (data.borderStyle.style) {
  107. case _util.AnnotationBorderStyleType.SOLID:
  108. container.style.borderStyle = 'solid';
  109. break;
  110. case _util.AnnotationBorderStyleType.DASHED:
  111. container.style.borderStyle = 'dashed';
  112. break;
  113. case _util.AnnotationBorderStyleType.BEVELED:
  114. (0, _util.warn)('Unimplemented border style: beveled');
  115. break;
  116. case _util.AnnotationBorderStyleType.INSET:
  117. (0, _util.warn)('Unimplemented border style: inset');
  118. break;
  119. case _util.AnnotationBorderStyleType.UNDERLINE:
  120. container.style.borderBottomStyle = 'solid';
  121. break;
  122. default:
  123. break;
  124. }
  125. if (data.color) {
  126. container.style.borderColor = _util.Util.makeCssRgb(data.color[0] | 0, data.color[1] | 0, data.color[2] | 0);
  127. } else {
  128. container.style.borderWidth = 0;
  129. }
  130. }
  131. container.style.left = rect[0] + 'px';
  132. container.style.top = rect[1] + 'px';
  133. container.style.width = width + 'px';
  134. container.style.height = height + 'px';
  135. return container;
  136. },
  137. _createPopup: function AnnotationElement_createPopup(container, trigger, data) {
  138. if (!trigger) {
  139. trigger = document.createElement('div');
  140. trigger.style.height = container.style.height;
  141. trigger.style.width = container.style.width;
  142. container.appendChild(trigger);
  143. }
  144. var popupElement = new PopupElement({
  145. container: container,
  146. trigger: trigger,
  147. color: data.color,
  148. title: data.title,
  149. contents: data.contents,
  150. hideWrapper: true
  151. });
  152. var popup = popupElement.render();
  153. popup.style.left = container.style.width;
  154. container.appendChild(popup);
  155. },
  156. render: function AnnotationElement_render() {
  157. throw new Error('Abstract method AnnotationElement.render called');
  158. }
  159. };
  160. return AnnotationElement;
  161. }();
  162. var LinkAnnotationElement = function LinkAnnotationElementClosure() {
  163. function LinkAnnotationElement(parameters) {
  164. AnnotationElement.call(this, parameters, true);
  165. }
  166. _util.Util.inherit(LinkAnnotationElement, AnnotationElement, {
  167. render: function LinkAnnotationElement_render() {
  168. this.container.className = 'linkAnnotation';
  169. var link = document.createElement('a');
  170. (0, _dom_utils.addLinkAttributes)(link, {
  171. url: this.data.url,
  172. target: this.data.newWindow ? _dom_utils.LinkTarget.BLANK : undefined
  173. });
  174. if (!this.data.url) {
  175. if (this.data.action) {
  176. this._bindNamedAction(link, this.data.action);
  177. } else {
  178. this._bindLink(link, this.data.dest);
  179. }
  180. }
  181. this.container.appendChild(link);
  182. return this.container;
  183. },
  184. _bindLink: function _bindLink(link, destination) {
  185. var _this = this;
  186. link.href = this.linkService.getDestinationHash(destination);
  187. link.onclick = function () {
  188. if (destination) {
  189. _this.linkService.navigateTo(destination);
  190. }
  191. return false;
  192. };
  193. if (destination) {
  194. link.className = 'internalLink';
  195. }
  196. },
  197. _bindNamedAction: function _bindNamedAction(link, action) {
  198. var _this2 = this;
  199. link.href = this.linkService.getAnchorUrl('');
  200. link.onclick = function () {
  201. _this2.linkService.executeNamedAction(action);
  202. return false;
  203. };
  204. link.className = 'internalLink';
  205. }
  206. });
  207. return LinkAnnotationElement;
  208. }();
  209. var TextAnnotationElement = function TextAnnotationElementClosure() {
  210. function TextAnnotationElement(parameters) {
  211. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  212. AnnotationElement.call(this, parameters, isRenderable);
  213. }
  214. _util.Util.inherit(TextAnnotationElement, AnnotationElement, {
  215. render: function TextAnnotationElement_render() {
  216. this.container.className = 'textAnnotation';
  217. var image = document.createElement('img');
  218. image.style.height = this.container.style.height;
  219. image.style.width = this.container.style.width;
  220. image.src = this.imageResourcesPath + 'annotation-' + this.data.name.toLowerCase() + '.svg';
  221. image.alt = '[{{type}} Annotation]';
  222. image.dataset.l10nId = 'text_annotation_type';
  223. image.dataset.l10nArgs = JSON.stringify({ type: this.data.name });
  224. if (!this.data.hasPopup) {
  225. this._createPopup(this.container, image, this.data);
  226. }
  227. this.container.appendChild(image);
  228. return this.container;
  229. }
  230. });
  231. return TextAnnotationElement;
  232. }();
  233. var WidgetAnnotationElement = function WidgetAnnotationElementClosure() {
  234. function WidgetAnnotationElement(parameters, isRenderable) {
  235. AnnotationElement.call(this, parameters, isRenderable);
  236. }
  237. _util.Util.inherit(WidgetAnnotationElement, AnnotationElement, {
  238. render: function WidgetAnnotationElement_render() {
  239. return this.container;
  240. }
  241. });
  242. return WidgetAnnotationElement;
  243. }();
  244. var TextWidgetAnnotationElement = function TextWidgetAnnotationElementClosure() {
  245. var TEXT_ALIGNMENT = ['left', 'center', 'right'];
  246. function TextWidgetAnnotationElement(parameters) {
  247. var isRenderable = parameters.renderInteractiveForms || !parameters.data.hasAppearance && !!parameters.data.fieldValue;
  248. WidgetAnnotationElement.call(this, parameters, isRenderable);
  249. }
  250. _util.Util.inherit(TextWidgetAnnotationElement, WidgetAnnotationElement, {
  251. render: function TextWidgetAnnotationElement_render() {
  252. this.container.className = 'textWidgetAnnotation';
  253. var element = null;
  254. if (this.renderInteractiveForms) {
  255. if (this.data.multiLine) {
  256. element = document.createElement('textarea');
  257. element.textContent = this.data.fieldValue;
  258. } else {
  259. element = document.createElement('input');
  260. element.type = 'text';
  261. element.setAttribute('value', this.data.fieldValue);
  262. }
  263. element.disabled = this.data.readOnly;
  264. if (this.data.maxLen !== null) {
  265. element.maxLength = this.data.maxLen;
  266. }
  267. if (this.data.comb) {
  268. var fieldWidth = this.data.rect[2] - this.data.rect[0];
  269. var combWidth = fieldWidth / this.data.maxLen;
  270. element.classList.add('comb');
  271. element.style.letterSpacing = 'calc(' + combWidth + 'px - 1ch)';
  272. }
  273. } else {
  274. element = document.createElement('div');
  275. element.textContent = this.data.fieldValue;
  276. element.style.verticalAlign = 'middle';
  277. element.style.display = 'table-cell';
  278. var font = null;
  279. if (this.data.fontRefName) {
  280. font = this.page.commonObjs.getData(this.data.fontRefName);
  281. }
  282. this._setTextStyle(element, font);
  283. }
  284. if (this.data.textAlignment !== null) {
  285. element.style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
  286. }
  287. this.container.appendChild(element);
  288. return this.container;
  289. },
  290. _setTextStyle: function TextWidgetAnnotationElement_setTextStyle(element, font) {
  291. var style = element.style;
  292. style.fontSize = this.data.fontSize + 'px';
  293. style.direction = this.data.fontDirection < 0 ? 'rtl' : 'ltr';
  294. if (!font) {
  295. return;
  296. }
  297. style.fontWeight = font.black ? font.bold ? '900' : 'bold' : font.bold ? 'bold' : 'normal';
  298. style.fontStyle = font.italic ? 'italic' : 'normal';
  299. var fontFamily = font.loadedName ? '"' + font.loadedName + '", ' : '';
  300. var fallbackName = font.fallbackName || 'Helvetica, sans-serif';
  301. style.fontFamily = fontFamily + fallbackName;
  302. }
  303. });
  304. return TextWidgetAnnotationElement;
  305. }();
  306. var CheckboxWidgetAnnotationElement = function CheckboxWidgetAnnotationElementClosure() {
  307. function CheckboxWidgetAnnotationElement(parameters) {
  308. WidgetAnnotationElement.call(this, parameters, parameters.renderInteractiveForms);
  309. }
  310. _util.Util.inherit(CheckboxWidgetAnnotationElement, WidgetAnnotationElement, {
  311. render: function CheckboxWidgetAnnotationElement_render() {
  312. this.container.className = 'buttonWidgetAnnotation checkBox';
  313. var element = document.createElement('input');
  314. element.disabled = this.data.readOnly;
  315. element.type = 'checkbox';
  316. if (this.data.fieldValue && this.data.fieldValue !== 'Off') {
  317. element.setAttribute('checked', true);
  318. }
  319. this.container.appendChild(element);
  320. return this.container;
  321. }
  322. });
  323. return CheckboxWidgetAnnotationElement;
  324. }();
  325. var RadioButtonWidgetAnnotationElement = function RadioButtonWidgetAnnotationElementClosure() {
  326. function RadioButtonWidgetAnnotationElement(parameters) {
  327. WidgetAnnotationElement.call(this, parameters, parameters.renderInteractiveForms);
  328. }
  329. _util.Util.inherit(RadioButtonWidgetAnnotationElement, WidgetAnnotationElement, {
  330. render: function RadioButtonWidgetAnnotationElement_render() {
  331. this.container.className = 'buttonWidgetAnnotation radioButton';
  332. var element = document.createElement('input');
  333. element.disabled = this.data.readOnly;
  334. element.type = 'radio';
  335. element.name = this.data.fieldName;
  336. if (this.data.fieldValue === this.data.buttonValue) {
  337. element.setAttribute('checked', true);
  338. }
  339. this.container.appendChild(element);
  340. return this.container;
  341. }
  342. });
  343. return RadioButtonWidgetAnnotationElement;
  344. }();
  345. var ChoiceWidgetAnnotationElement = function ChoiceWidgetAnnotationElementClosure() {
  346. function ChoiceWidgetAnnotationElement(parameters) {
  347. WidgetAnnotationElement.call(this, parameters, parameters.renderInteractiveForms);
  348. }
  349. _util.Util.inherit(ChoiceWidgetAnnotationElement, WidgetAnnotationElement, {
  350. render: function ChoiceWidgetAnnotationElement_render() {
  351. this.container.className = 'choiceWidgetAnnotation';
  352. var selectElement = document.createElement('select');
  353. selectElement.disabled = this.data.readOnly;
  354. if (!this.data.combo) {
  355. selectElement.size = this.data.options.length;
  356. if (this.data.multiSelect) {
  357. selectElement.multiple = true;
  358. }
  359. }
  360. for (var i = 0, ii = this.data.options.length; i < ii; i++) {
  361. var option = this.data.options[i];
  362. var optionElement = document.createElement('option');
  363. optionElement.textContent = option.displayValue;
  364. optionElement.value = option.exportValue;
  365. if (this.data.fieldValue.indexOf(option.displayValue) >= 0) {
  366. optionElement.setAttribute('selected', true);
  367. }
  368. selectElement.appendChild(optionElement);
  369. }
  370. this.container.appendChild(selectElement);
  371. return this.container;
  372. }
  373. });
  374. return ChoiceWidgetAnnotationElement;
  375. }();
  376. var PopupAnnotationElement = function PopupAnnotationElementClosure() {
  377. var IGNORE_TYPES = ['Line'];
  378. function PopupAnnotationElement(parameters) {
  379. var isRenderable = !!(parameters.data.title || parameters.data.contents);
  380. AnnotationElement.call(this, parameters, isRenderable);
  381. }
  382. _util.Util.inherit(PopupAnnotationElement, AnnotationElement, {
  383. render: function PopupAnnotationElement_render() {
  384. this.container.className = 'popupAnnotation';
  385. if (IGNORE_TYPES.indexOf(this.data.parentType) >= 0) {
  386. return this.container;
  387. }
  388. var selector = '[data-annotation-id="' + this.data.parentId + '"]';
  389. var parentElement = this.layer.querySelector(selector);
  390. if (!parentElement) {
  391. return this.container;
  392. }
  393. var popup = new PopupElement({
  394. container: this.container,
  395. trigger: parentElement,
  396. color: this.data.color,
  397. title: this.data.title,
  398. contents: this.data.contents
  399. });
  400. var parentLeft = parseFloat(parentElement.style.left);
  401. var parentWidth = parseFloat(parentElement.style.width);
  402. _dom_utils.CustomStyle.setProp('transformOrigin', this.container, -(parentLeft + parentWidth) + 'px -' + parentElement.style.top);
  403. this.container.style.left = parentLeft + parentWidth + 'px';
  404. this.container.appendChild(popup.render());
  405. return this.container;
  406. }
  407. });
  408. return PopupAnnotationElement;
  409. }();
  410. var PopupElement = function PopupElementClosure() {
  411. var BACKGROUND_ENLIGHT = 0.7;
  412. function PopupElement(parameters) {
  413. this.container = parameters.container;
  414. this.trigger = parameters.trigger;
  415. this.color = parameters.color;
  416. this.title = parameters.title;
  417. this.contents = parameters.contents;
  418. this.hideWrapper = parameters.hideWrapper || false;
  419. this.pinned = false;
  420. }
  421. PopupElement.prototype = {
  422. render: function PopupElement_render() {
  423. var wrapper = document.createElement('div');
  424. wrapper.className = 'popupWrapper';
  425. this.hideElement = this.hideWrapper ? wrapper : this.container;
  426. this.hideElement.setAttribute('hidden', true);
  427. var popup = document.createElement('div');
  428. popup.className = 'popup';
  429. var color = this.color;
  430. if (color) {
  431. var r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  432. var g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  433. var b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  434. popup.style.backgroundColor = _util.Util.makeCssRgb(r | 0, g | 0, b | 0);
  435. }
  436. var contents = this._formatContents(this.contents);
  437. var title = document.createElement('h1');
  438. title.textContent = this.title;
  439. this.trigger.addEventListener('click', this._toggle.bind(this));
  440. this.trigger.addEventListener('mouseover', this._show.bind(this, false));
  441. this.trigger.addEventListener('mouseout', this._hide.bind(this, false));
  442. popup.addEventListener('click', this._hide.bind(this, true));
  443. popup.appendChild(title);
  444. popup.appendChild(contents);
  445. wrapper.appendChild(popup);
  446. return wrapper;
  447. },
  448. _formatContents: function PopupElement_formatContents(contents) {
  449. var p = document.createElement('p');
  450. var lines = contents.split(/(?:\r\n?|\n)/);
  451. for (var i = 0, ii = lines.length; i < ii; ++i) {
  452. var line = lines[i];
  453. p.appendChild(document.createTextNode(line));
  454. if (i < ii - 1) {
  455. p.appendChild(document.createElement('br'));
  456. }
  457. }
  458. return p;
  459. },
  460. _toggle: function PopupElement_toggle() {
  461. if (this.pinned) {
  462. this._hide(true);
  463. } else {
  464. this._show(true);
  465. }
  466. },
  467. _show: function PopupElement_show(pin) {
  468. if (pin) {
  469. this.pinned = true;
  470. }
  471. if (this.hideElement.hasAttribute('hidden')) {
  472. this.hideElement.removeAttribute('hidden');
  473. this.container.style.zIndex += 1;
  474. }
  475. },
  476. _hide: function PopupElement_hide(unpin) {
  477. if (unpin) {
  478. this.pinned = false;
  479. }
  480. if (!this.hideElement.hasAttribute('hidden') && !this.pinned) {
  481. this.hideElement.setAttribute('hidden', true);
  482. this.container.style.zIndex -= 1;
  483. }
  484. }
  485. };
  486. return PopupElement;
  487. }();
  488. var LineAnnotationElement = function LineAnnotationElementClosure() {
  489. var SVG_NS = 'http://www.w3.org/2000/svg';
  490. function LineAnnotationElement(parameters) {
  491. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  492. AnnotationElement.call(this, parameters, isRenderable, true);
  493. }
  494. _util.Util.inherit(LineAnnotationElement, AnnotationElement, {
  495. render: function LineAnnotationElement_render() {
  496. this.container.className = 'lineAnnotation';
  497. var data = this.data;
  498. var width = data.rect[2] - data.rect[0];
  499. var height = data.rect[3] - data.rect[1];
  500. var svg = document.createElementNS(SVG_NS, 'svg:svg');
  501. svg.setAttributeNS(null, 'version', '1.1');
  502. svg.setAttributeNS(null, 'width', width + 'px');
  503. svg.setAttributeNS(null, 'height', height + 'px');
  504. svg.setAttributeNS(null, 'preserveAspectRatio', 'none');
  505. svg.setAttributeNS(null, 'viewBox', '0 0 ' + width + ' ' + height);
  506. var line = document.createElementNS(SVG_NS, 'svg:line');
  507. line.setAttributeNS(null, 'x1', data.rect[2] - data.lineCoordinates[0]);
  508. line.setAttributeNS(null, 'y1', data.rect[3] - data.lineCoordinates[1]);
  509. line.setAttributeNS(null, 'x2', data.rect[2] - data.lineCoordinates[2]);
  510. line.setAttributeNS(null, 'y2', data.rect[3] - data.lineCoordinates[3]);
  511. line.setAttributeNS(null, 'stroke-width', data.borderStyle.width);
  512. line.setAttributeNS(null, 'stroke', 'transparent');
  513. svg.appendChild(line);
  514. this.container.append(svg);
  515. this._createPopup(this.container, line, this.data);
  516. return this.container;
  517. }
  518. });
  519. return LineAnnotationElement;
  520. }();
  521. var HighlightAnnotationElement = function HighlightAnnotationElementClosure() {
  522. function HighlightAnnotationElement(parameters) {
  523. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  524. AnnotationElement.call(this, parameters, isRenderable, true);
  525. }
  526. _util.Util.inherit(HighlightAnnotationElement, AnnotationElement, {
  527. render: function HighlightAnnotationElement_render() {
  528. this.container.className = 'highlightAnnotation';
  529. if (!this.data.hasPopup) {
  530. this._createPopup(this.container, null, this.data);
  531. }
  532. return this.container;
  533. }
  534. });
  535. return HighlightAnnotationElement;
  536. }();
  537. var UnderlineAnnotationElement = function UnderlineAnnotationElementClosure() {
  538. function UnderlineAnnotationElement(parameters) {
  539. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  540. AnnotationElement.call(this, parameters, isRenderable, true);
  541. }
  542. _util.Util.inherit(UnderlineAnnotationElement, AnnotationElement, {
  543. render: function UnderlineAnnotationElement_render() {
  544. this.container.className = 'underlineAnnotation';
  545. if (!this.data.hasPopup) {
  546. this._createPopup(this.container, null, this.data);
  547. }
  548. return this.container;
  549. }
  550. });
  551. return UnderlineAnnotationElement;
  552. }();
  553. var SquigglyAnnotationElement = function SquigglyAnnotationElementClosure() {
  554. function SquigglyAnnotationElement(parameters) {
  555. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  556. AnnotationElement.call(this, parameters, isRenderable, true);
  557. }
  558. _util.Util.inherit(SquigglyAnnotationElement, AnnotationElement, {
  559. render: function SquigglyAnnotationElement_render() {
  560. this.container.className = 'squigglyAnnotation';
  561. if (!this.data.hasPopup) {
  562. this._createPopup(this.container, null, this.data);
  563. }
  564. return this.container;
  565. }
  566. });
  567. return SquigglyAnnotationElement;
  568. }();
  569. var StrikeOutAnnotationElement = function StrikeOutAnnotationElementClosure() {
  570. function StrikeOutAnnotationElement(parameters) {
  571. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  572. AnnotationElement.call(this, parameters, isRenderable, true);
  573. }
  574. _util.Util.inherit(StrikeOutAnnotationElement, AnnotationElement, {
  575. render: function StrikeOutAnnotationElement_render() {
  576. this.container.className = 'strikeoutAnnotation';
  577. if (!this.data.hasPopup) {
  578. this._createPopup(this.container, null, this.data);
  579. }
  580. return this.container;
  581. }
  582. });
  583. return StrikeOutAnnotationElement;
  584. }();
  585. var FileAttachmentAnnotationElement = function FileAttachmentAnnotationElementClosure() {
  586. function FileAttachmentAnnotationElement(parameters) {
  587. AnnotationElement.call(this, parameters, true);
  588. var file = this.data.file;
  589. this.filename = (0, _dom_utils.getFilenameFromUrl)(file.filename);
  590. this.content = file.content;
  591. this.linkService.onFileAttachmentAnnotation({
  592. id: (0, _util.stringToPDFString)(file.filename),
  593. filename: file.filename,
  594. content: file.content
  595. });
  596. }
  597. _util.Util.inherit(FileAttachmentAnnotationElement, AnnotationElement, {
  598. render: function FileAttachmentAnnotationElement_render() {
  599. this.container.className = 'fileAttachmentAnnotation';
  600. var trigger = document.createElement('div');
  601. trigger.style.height = this.container.style.height;
  602. trigger.style.width = this.container.style.width;
  603. trigger.addEventListener('dblclick', this._download.bind(this));
  604. if (!this.data.hasPopup && (this.data.title || this.data.contents)) {
  605. this._createPopup(this.container, trigger, this.data);
  606. }
  607. this.container.appendChild(trigger);
  608. return this.container;
  609. },
  610. _download: function FileAttachmentAnnotationElement_download() {
  611. if (!this.downloadManager) {
  612. (0, _util.warn)('Download cannot be started due to unavailable download manager');
  613. return;
  614. }
  615. this.downloadManager.downloadData(this.content, this.filename, '');
  616. }
  617. });
  618. return FileAttachmentAnnotationElement;
  619. }();
  620. var AnnotationLayer = function AnnotationLayerClosure() {
  621. return {
  622. render: function AnnotationLayer_render(parameters) {
  623. var annotationElementFactory = new AnnotationElementFactory();
  624. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  625. var data = parameters.annotations[i];
  626. if (!data) {
  627. continue;
  628. }
  629. var element = annotationElementFactory.create({
  630. data: data,
  631. layer: parameters.div,
  632. page: parameters.page,
  633. viewport: parameters.viewport,
  634. linkService: parameters.linkService,
  635. downloadManager: parameters.downloadManager,
  636. imageResourcesPath: parameters.imageResourcesPath || (0, _dom_utils.getDefaultSetting)('imageResourcesPath'),
  637. renderInteractiveForms: parameters.renderInteractiveForms || false
  638. });
  639. if (element.isRenderable) {
  640. parameters.div.appendChild(element.render());
  641. }
  642. }
  643. },
  644. update: function AnnotationLayer_update(parameters) {
  645. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  646. var data = parameters.annotations[i];
  647. var element = parameters.div.querySelector('[data-annotation-id="' + data.id + '"]');
  648. if (element) {
  649. _dom_utils.CustomStyle.setProp('transform', element, 'matrix(' + parameters.viewport.transform.join(',') + ')');
  650. }
  651. }
  652. parameters.div.removeAttribute('hidden');
  653. }
  654. };
  655. }();
  656. exports.AnnotationLayer = AnnotationLayer;