annotation_layer.js 32 KB

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