annotation_layer.js 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2017 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. 'use strict';
  23. Object.defineProperty(exports, "__esModule", {
  24. value: true
  25. });
  26. exports.AnnotationLayer = undefined;
  27. var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
  28. 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; }; }();
  29. var _dom_utils = require('./dom_utils');
  30. var _util = require('../shared/util');
  31. 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; }
  32. 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; }
  33. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  34. var AnnotationElementFactory = function () {
  35. function AnnotationElementFactory() {
  36. _classCallCheck(this, AnnotationElementFactory);
  37. }
  38. _createClass(AnnotationElementFactory, null, [{
  39. key: 'create',
  40. value: function create(parameters) {
  41. var subtype = parameters.data.annotationType;
  42. switch (subtype) {
  43. case _util.AnnotationType.LINK:
  44. return new LinkAnnotationElement(parameters);
  45. case _util.AnnotationType.TEXT:
  46. return new TextAnnotationElement(parameters);
  47. case _util.AnnotationType.WIDGET:
  48. var fieldType = parameters.data.fieldType;
  49. switch (fieldType) {
  50. case 'Tx':
  51. return new TextWidgetAnnotationElement(parameters);
  52. case 'Btn':
  53. if (parameters.data.radioButton) {
  54. return new RadioButtonWidgetAnnotationElement(parameters);
  55. } else if (parameters.data.checkBox) {
  56. return new CheckboxWidgetAnnotationElement(parameters);
  57. }
  58. return new PushButtonWidgetAnnotationElement(parameters);
  59. case 'Ch':
  60. return new ChoiceWidgetAnnotationElement(parameters);
  61. }
  62. return new WidgetAnnotationElement(parameters);
  63. case _util.AnnotationType.POPUP:
  64. return new PopupAnnotationElement(parameters);
  65. case _util.AnnotationType.LINE:
  66. return new LineAnnotationElement(parameters);
  67. case _util.AnnotationType.SQUARE:
  68. return new SquareAnnotationElement(parameters);
  69. case _util.AnnotationType.CIRCLE:
  70. return new CircleAnnotationElement(parameters);
  71. case _util.AnnotationType.POLYLINE:
  72. return new PolylineAnnotationElement(parameters);
  73. case _util.AnnotationType.POLYGON:
  74. return new PolygonAnnotationElement(parameters);
  75. case _util.AnnotationType.HIGHLIGHT:
  76. return new HighlightAnnotationElement(parameters);
  77. case _util.AnnotationType.UNDERLINE:
  78. return new UnderlineAnnotationElement(parameters);
  79. case _util.AnnotationType.SQUIGGLY:
  80. return new SquigglyAnnotationElement(parameters);
  81. case _util.AnnotationType.STRIKEOUT:
  82. return new StrikeOutAnnotationElement(parameters);
  83. case _util.AnnotationType.STAMP:
  84. return new StampAnnotationElement(parameters);
  85. case _util.AnnotationType.FILEATTACHMENT:
  86. return new FileAttachmentAnnotationElement(parameters);
  87. default:
  88. return new AnnotationElement(parameters);
  89. }
  90. }
  91. }]);
  92. return AnnotationElementFactory;
  93. }();
  94. var AnnotationElement = function () {
  95. function AnnotationElement(parameters) {
  96. var isRenderable = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  97. var ignoreBorder = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  98. _classCallCheck(this, AnnotationElement);
  99. this.isRenderable = isRenderable;
  100. this.data = parameters.data;
  101. this.layer = parameters.layer;
  102. this.page = parameters.page;
  103. this.viewport = parameters.viewport;
  104. this.linkService = parameters.linkService;
  105. this.downloadManager = parameters.downloadManager;
  106. this.imageResourcesPath = parameters.imageResourcesPath;
  107. this.renderInteractiveForms = parameters.renderInteractiveForms;
  108. this.svgFactory = parameters.svgFactory;
  109. if (isRenderable) {
  110. this.container = this._createContainer(ignoreBorder);
  111. }
  112. }
  113. _createClass(AnnotationElement, [{
  114. key: '_createContainer',
  115. value: function _createContainer() {
  116. var ignoreBorder = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  117. var data = this.data,
  118. page = this.page,
  119. viewport = this.viewport;
  120. var container = document.createElement('section');
  121. var width = data.rect[2] - data.rect[0];
  122. var height = data.rect[3] - data.rect[1];
  123. container.setAttribute('data-annotation-id', data.id);
  124. 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]]);
  125. container.style.transform = 'matrix(' + viewport.transform.join(',') + ')';
  126. container.style.transformOrigin = -rect[0] + 'px ' + -rect[1] + 'px';
  127. if (!ignoreBorder && data.borderStyle.width > 0) {
  128. container.style.borderWidth = data.borderStyle.width + 'px';
  129. if (data.borderStyle.style !== _util.AnnotationBorderStyleType.UNDERLINE) {
  130. width = width - 2 * data.borderStyle.width;
  131. height = height - 2 * data.borderStyle.width;
  132. }
  133. var horizontalRadius = data.borderStyle.horizontalCornerRadius;
  134. var verticalRadius = data.borderStyle.verticalCornerRadius;
  135. if (horizontalRadius > 0 || verticalRadius > 0) {
  136. var radius = horizontalRadius + 'px / ' + verticalRadius + 'px';
  137. container.style.borderRadius = radius;
  138. }
  139. switch (data.borderStyle.style) {
  140. case _util.AnnotationBorderStyleType.SOLID:
  141. container.style.borderStyle = 'solid';
  142. break;
  143. case _util.AnnotationBorderStyleType.DASHED:
  144. container.style.borderStyle = 'dashed';
  145. break;
  146. case _util.AnnotationBorderStyleType.BEVELED:
  147. (0, _util.warn)('Unimplemented border style: beveled');
  148. break;
  149. case _util.AnnotationBorderStyleType.INSET:
  150. (0, _util.warn)('Unimplemented border style: inset');
  151. break;
  152. case _util.AnnotationBorderStyleType.UNDERLINE:
  153. container.style.borderBottomStyle = 'solid';
  154. break;
  155. default:
  156. break;
  157. }
  158. if (data.color) {
  159. container.style.borderColor = _util.Util.makeCssRgb(data.color[0] | 0, data.color[1] | 0, data.color[2] | 0);
  160. } else {
  161. container.style.borderWidth = 0;
  162. }
  163. }
  164. container.style.left = rect[0] + 'px';
  165. container.style.top = rect[1] + 'px';
  166. container.style.width = width + 'px';
  167. container.style.height = height + 'px';
  168. return container;
  169. }
  170. }, {
  171. key: '_createPopup',
  172. value: function _createPopup(container, trigger, data) {
  173. if (!trigger) {
  174. trigger = document.createElement('div');
  175. trigger.style.height = container.style.height;
  176. trigger.style.width = container.style.width;
  177. container.appendChild(trigger);
  178. }
  179. var popupElement = new PopupElement({
  180. container: container,
  181. trigger: trigger,
  182. color: data.color,
  183. title: data.title,
  184. contents: data.contents,
  185. hideWrapper: true
  186. });
  187. var popup = popupElement.render();
  188. popup.style.left = container.style.width;
  189. container.appendChild(popup);
  190. }
  191. }, {
  192. key: 'render',
  193. value: function render() {
  194. (0, _util.unreachable)('Abstract method `AnnotationElement.render` called');
  195. }
  196. }]);
  197. return AnnotationElement;
  198. }();
  199. var LinkAnnotationElement = function (_AnnotationElement) {
  200. _inherits(LinkAnnotationElement, _AnnotationElement);
  201. function LinkAnnotationElement(parameters) {
  202. _classCallCheck(this, LinkAnnotationElement);
  203. var isRenderable = !!(parameters.data.url || parameters.data.dest || parameters.data.action);
  204. return _possibleConstructorReturn(this, (LinkAnnotationElement.__proto__ || Object.getPrototypeOf(LinkAnnotationElement)).call(this, parameters, isRenderable));
  205. }
  206. _createClass(LinkAnnotationElement, [{
  207. key: 'render',
  208. value: function render() {
  209. this.container.className = 'linkAnnotation';
  210. var data = this.data,
  211. linkService = this.linkService;
  212. var link = document.createElement('a');
  213. (0, _dom_utils.addLinkAttributes)(link, {
  214. url: data.url,
  215. target: data.newWindow ? _dom_utils.LinkTarget.BLANK : linkService.externalLinkTarget,
  216. rel: linkService.externalLinkRel
  217. });
  218. if (!data.url) {
  219. if (data.action) {
  220. this._bindNamedAction(link, data.action);
  221. } else {
  222. this._bindLink(link, data.dest);
  223. }
  224. }
  225. this.container.appendChild(link);
  226. return this.container;
  227. }
  228. }, {
  229. key: '_bindLink',
  230. value: function _bindLink(link, destination) {
  231. var _this2 = this;
  232. link.href = this.linkService.getDestinationHash(destination);
  233. link.onclick = function () {
  234. if (destination) {
  235. _this2.linkService.navigateTo(destination);
  236. }
  237. return false;
  238. };
  239. if (destination) {
  240. link.className = 'internalLink';
  241. }
  242. }
  243. }, {
  244. key: '_bindNamedAction',
  245. value: function _bindNamedAction(link, action) {
  246. var _this3 = this;
  247. link.href = this.linkService.getAnchorUrl('');
  248. link.onclick = function () {
  249. _this3.linkService.executeNamedAction(action);
  250. return false;
  251. };
  252. link.className = 'internalLink';
  253. }
  254. }]);
  255. return LinkAnnotationElement;
  256. }(AnnotationElement);
  257. var TextAnnotationElement = function (_AnnotationElement2) {
  258. _inherits(TextAnnotationElement, _AnnotationElement2);
  259. function TextAnnotationElement(parameters) {
  260. _classCallCheck(this, TextAnnotationElement);
  261. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  262. return _possibleConstructorReturn(this, (TextAnnotationElement.__proto__ || Object.getPrototypeOf(TextAnnotationElement)).call(this, parameters, isRenderable));
  263. }
  264. _createClass(TextAnnotationElement, [{
  265. key: 'render',
  266. value: function render() {
  267. this.container.className = 'textAnnotation';
  268. var image = document.createElement('img');
  269. image.style.height = this.container.style.height;
  270. image.style.width = this.container.style.width;
  271. image.src = this.imageResourcesPath + 'annotation-' + this.data.name.toLowerCase() + '.svg';
  272. image.alt = '[{{type}} Annotation]';
  273. image.dataset.l10nId = 'text_annotation_type';
  274. image.dataset.l10nArgs = JSON.stringify({ type: this.data.name });
  275. if (!this.data.hasPopup) {
  276. this._createPopup(this.container, image, this.data);
  277. }
  278. this.container.appendChild(image);
  279. return this.container;
  280. }
  281. }]);
  282. return TextAnnotationElement;
  283. }(AnnotationElement);
  284. var WidgetAnnotationElement = function (_AnnotationElement3) {
  285. _inherits(WidgetAnnotationElement, _AnnotationElement3);
  286. function WidgetAnnotationElement() {
  287. _classCallCheck(this, WidgetAnnotationElement);
  288. return _possibleConstructorReturn(this, (WidgetAnnotationElement.__proto__ || Object.getPrototypeOf(WidgetAnnotationElement)).apply(this, arguments));
  289. }
  290. _createClass(WidgetAnnotationElement, [{
  291. key: 'render',
  292. value: function render() {
  293. return this.container;
  294. }
  295. }]);
  296. return WidgetAnnotationElement;
  297. }(AnnotationElement);
  298. var TextWidgetAnnotationElement = function (_WidgetAnnotationElem) {
  299. _inherits(TextWidgetAnnotationElement, _WidgetAnnotationElem);
  300. function TextWidgetAnnotationElement(parameters) {
  301. _classCallCheck(this, TextWidgetAnnotationElement);
  302. var isRenderable = parameters.renderInteractiveForms || !parameters.data.hasAppearance && !!parameters.data.fieldValue;
  303. return _possibleConstructorReturn(this, (TextWidgetAnnotationElement.__proto__ || Object.getPrototypeOf(TextWidgetAnnotationElement)).call(this, parameters, isRenderable));
  304. }
  305. _createClass(TextWidgetAnnotationElement, [{
  306. key: 'render',
  307. value: function render() {
  308. var TEXT_ALIGNMENT = ['left', 'center', 'right'];
  309. this.container.className = 'textWidgetAnnotation';
  310. var element = null;
  311. if (this.renderInteractiveForms) {
  312. if (this.data.multiLine) {
  313. element = document.createElement('textarea');
  314. element.textContent = this.data.fieldValue;
  315. } else {
  316. element = document.createElement('input');
  317. element.type = 'text';
  318. element.setAttribute('value', this.data.fieldValue);
  319. }
  320. element.disabled = this.data.readOnly;
  321. if (this.data.maxLen !== null) {
  322. element.maxLength = this.data.maxLen;
  323. }
  324. if (this.data.comb) {
  325. var fieldWidth = this.data.rect[2] - this.data.rect[0];
  326. var combWidth = fieldWidth / this.data.maxLen;
  327. element.classList.add('comb');
  328. element.style.letterSpacing = 'calc(' + combWidth + 'px - 1ch)';
  329. }
  330. } else {
  331. element = document.createElement('div');
  332. element.textContent = this.data.fieldValue;
  333. element.style.verticalAlign = 'middle';
  334. element.style.display = 'table-cell';
  335. var font = null;
  336. if (this.data.fontRefName) {
  337. font = this.page.commonObjs.getData(this.data.fontRefName);
  338. }
  339. this._setTextStyle(element, font);
  340. }
  341. if (this.data.textAlignment !== null) {
  342. element.style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];
  343. }
  344. this.container.appendChild(element);
  345. return this.container;
  346. }
  347. }, {
  348. key: '_setTextStyle',
  349. value: function _setTextStyle(element, font) {
  350. var style = element.style;
  351. style.fontSize = this.data.fontSize + 'px';
  352. style.direction = this.data.fontDirection < 0 ? 'rtl' : 'ltr';
  353. if (!font) {
  354. return;
  355. }
  356. style.fontWeight = font.black ? font.bold ? '900' : 'bold' : font.bold ? 'bold' : 'normal';
  357. style.fontStyle = font.italic ? 'italic' : 'normal';
  358. var fontFamily = font.loadedName ? '"' + font.loadedName + '", ' : '';
  359. var fallbackName = font.fallbackName || 'Helvetica, sans-serif';
  360. style.fontFamily = fontFamily + fallbackName;
  361. }
  362. }]);
  363. return TextWidgetAnnotationElement;
  364. }(WidgetAnnotationElement);
  365. var CheckboxWidgetAnnotationElement = function (_WidgetAnnotationElem2) {
  366. _inherits(CheckboxWidgetAnnotationElement, _WidgetAnnotationElem2);
  367. function CheckboxWidgetAnnotationElement(parameters) {
  368. _classCallCheck(this, CheckboxWidgetAnnotationElement);
  369. return _possibleConstructorReturn(this, (CheckboxWidgetAnnotationElement.__proto__ || Object.getPrototypeOf(CheckboxWidgetAnnotationElement)).call(this, parameters, parameters.renderInteractiveForms));
  370. }
  371. _createClass(CheckboxWidgetAnnotationElement, [{
  372. key: 'render',
  373. value: function render() {
  374. this.container.className = 'buttonWidgetAnnotation checkBox';
  375. var element = document.createElement('input');
  376. element.disabled = this.data.readOnly;
  377. element.type = 'checkbox';
  378. if (this.data.fieldValue && this.data.fieldValue !== 'Off') {
  379. element.setAttribute('checked', true);
  380. }
  381. this.container.appendChild(element);
  382. return this.container;
  383. }
  384. }]);
  385. return CheckboxWidgetAnnotationElement;
  386. }(WidgetAnnotationElement);
  387. var RadioButtonWidgetAnnotationElement = function (_WidgetAnnotationElem3) {
  388. _inherits(RadioButtonWidgetAnnotationElement, _WidgetAnnotationElem3);
  389. function RadioButtonWidgetAnnotationElement(parameters) {
  390. _classCallCheck(this, RadioButtonWidgetAnnotationElement);
  391. return _possibleConstructorReturn(this, (RadioButtonWidgetAnnotationElement.__proto__ || Object.getPrototypeOf(RadioButtonWidgetAnnotationElement)).call(this, parameters, parameters.renderInteractiveForms));
  392. }
  393. _createClass(RadioButtonWidgetAnnotationElement, [{
  394. key: 'render',
  395. value: function render() {
  396. this.container.className = 'buttonWidgetAnnotation radioButton';
  397. var element = document.createElement('input');
  398. element.disabled = this.data.readOnly;
  399. element.type = 'radio';
  400. element.name = this.data.fieldName;
  401. if (this.data.fieldValue === this.data.buttonValue) {
  402. element.setAttribute('checked', true);
  403. }
  404. this.container.appendChild(element);
  405. return this.container;
  406. }
  407. }]);
  408. return RadioButtonWidgetAnnotationElement;
  409. }(WidgetAnnotationElement);
  410. var PushButtonWidgetAnnotationElement = function (_LinkAnnotationElemen) {
  411. _inherits(PushButtonWidgetAnnotationElement, _LinkAnnotationElemen);
  412. function PushButtonWidgetAnnotationElement() {
  413. _classCallCheck(this, PushButtonWidgetAnnotationElement);
  414. return _possibleConstructorReturn(this, (PushButtonWidgetAnnotationElement.__proto__ || Object.getPrototypeOf(PushButtonWidgetAnnotationElement)).apply(this, arguments));
  415. }
  416. _createClass(PushButtonWidgetAnnotationElement, [{
  417. key: 'render',
  418. value: function render() {
  419. var container = _get(PushButtonWidgetAnnotationElement.prototype.__proto__ || Object.getPrototypeOf(PushButtonWidgetAnnotationElement.prototype), 'render', this).call(this);
  420. container.className = 'buttonWidgetAnnotation pushButton';
  421. return container;
  422. }
  423. }]);
  424. return PushButtonWidgetAnnotationElement;
  425. }(LinkAnnotationElement);
  426. var ChoiceWidgetAnnotationElement = function (_WidgetAnnotationElem4) {
  427. _inherits(ChoiceWidgetAnnotationElement, _WidgetAnnotationElem4);
  428. function ChoiceWidgetAnnotationElement(parameters) {
  429. _classCallCheck(this, ChoiceWidgetAnnotationElement);
  430. return _possibleConstructorReturn(this, (ChoiceWidgetAnnotationElement.__proto__ || Object.getPrototypeOf(ChoiceWidgetAnnotationElement)).call(this, parameters, parameters.renderInteractiveForms));
  431. }
  432. _createClass(ChoiceWidgetAnnotationElement, [{
  433. key: 'render',
  434. value: function render() {
  435. this.container.className = 'choiceWidgetAnnotation';
  436. var selectElement = document.createElement('select');
  437. selectElement.disabled = this.data.readOnly;
  438. if (!this.data.combo) {
  439. selectElement.size = this.data.options.length;
  440. if (this.data.multiSelect) {
  441. selectElement.multiple = true;
  442. }
  443. }
  444. for (var i = 0, ii = this.data.options.length; i < ii; i++) {
  445. var option = this.data.options[i];
  446. var optionElement = document.createElement('option');
  447. optionElement.textContent = option.displayValue;
  448. optionElement.value = option.exportValue;
  449. if (this.data.fieldValue.includes(option.displayValue)) {
  450. optionElement.setAttribute('selected', true);
  451. }
  452. selectElement.appendChild(optionElement);
  453. }
  454. this.container.appendChild(selectElement);
  455. return this.container;
  456. }
  457. }]);
  458. return ChoiceWidgetAnnotationElement;
  459. }(WidgetAnnotationElement);
  460. var PopupAnnotationElement = function (_AnnotationElement4) {
  461. _inherits(PopupAnnotationElement, _AnnotationElement4);
  462. function PopupAnnotationElement(parameters) {
  463. _classCallCheck(this, PopupAnnotationElement);
  464. var isRenderable = !!(parameters.data.title || parameters.data.contents);
  465. return _possibleConstructorReturn(this, (PopupAnnotationElement.__proto__ || Object.getPrototypeOf(PopupAnnotationElement)).call(this, parameters, isRenderable));
  466. }
  467. _createClass(PopupAnnotationElement, [{
  468. key: 'render',
  469. value: function render() {
  470. var IGNORE_TYPES = ['Line', 'Square', 'Circle', 'PolyLine', 'Polygon'];
  471. this.container.className = 'popupAnnotation';
  472. if (IGNORE_TYPES.includes(this.data.parentType)) {
  473. return this.container;
  474. }
  475. var selector = '[data-annotation-id="' + this.data.parentId + '"]';
  476. var parentElement = this.layer.querySelector(selector);
  477. if (!parentElement) {
  478. return this.container;
  479. }
  480. var popup = new PopupElement({
  481. container: this.container,
  482. trigger: parentElement,
  483. color: this.data.color,
  484. title: this.data.title,
  485. contents: this.data.contents
  486. });
  487. var parentLeft = parseFloat(parentElement.style.left);
  488. var parentWidth = parseFloat(parentElement.style.width);
  489. this.container.style.transformOrigin = -(parentLeft + parentWidth) + 'px -' + parentElement.style.top;
  490. this.container.style.left = parentLeft + parentWidth + 'px';
  491. this.container.appendChild(popup.render());
  492. return this.container;
  493. }
  494. }]);
  495. return PopupAnnotationElement;
  496. }(AnnotationElement);
  497. var PopupElement = function () {
  498. function PopupElement(parameters) {
  499. _classCallCheck(this, PopupElement);
  500. this.container = parameters.container;
  501. this.trigger = parameters.trigger;
  502. this.color = parameters.color;
  503. this.title = parameters.title;
  504. this.contents = parameters.contents;
  505. this.hideWrapper = parameters.hideWrapper || false;
  506. this.pinned = false;
  507. }
  508. _createClass(PopupElement, [{
  509. key: 'render',
  510. value: function render() {
  511. var BACKGROUND_ENLIGHT = 0.7;
  512. var wrapper = document.createElement('div');
  513. wrapper.className = 'popupWrapper';
  514. this.hideElement = this.hideWrapper ? wrapper : this.container;
  515. this.hideElement.setAttribute('hidden', true);
  516. var popup = document.createElement('div');
  517. popup.className = 'popup';
  518. var color = this.color;
  519. if (color) {
  520. var r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];
  521. var g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];
  522. var b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];
  523. popup.style.backgroundColor = _util.Util.makeCssRgb(r | 0, g | 0, b | 0);
  524. }
  525. var contents = this._formatContents(this.contents);
  526. var title = document.createElement('h1');
  527. title.textContent = this.title;
  528. this.trigger.addEventListener('click', this._toggle.bind(this));
  529. this.trigger.addEventListener('mouseover', this._show.bind(this, false));
  530. this.trigger.addEventListener('mouseout', this._hide.bind(this, false));
  531. popup.addEventListener('click', this._hide.bind(this, true));
  532. popup.appendChild(title);
  533. popup.appendChild(contents);
  534. wrapper.appendChild(popup);
  535. return wrapper;
  536. }
  537. }, {
  538. key: '_formatContents',
  539. value: function _formatContents(contents) {
  540. var p = document.createElement('p');
  541. var lines = contents.split(/(?:\r\n?|\n)/);
  542. for (var i = 0, ii = lines.length; i < ii; ++i) {
  543. var line = lines[i];
  544. p.appendChild(document.createTextNode(line));
  545. if (i < ii - 1) {
  546. p.appendChild(document.createElement('br'));
  547. }
  548. }
  549. return p;
  550. }
  551. }, {
  552. key: '_toggle',
  553. value: function _toggle() {
  554. if (this.pinned) {
  555. this._hide(true);
  556. } else {
  557. this._show(true);
  558. }
  559. }
  560. }, {
  561. key: '_show',
  562. value: function _show() {
  563. var pin = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
  564. if (pin) {
  565. this.pinned = true;
  566. }
  567. if (this.hideElement.hasAttribute('hidden')) {
  568. this.hideElement.removeAttribute('hidden');
  569. this.container.style.zIndex += 1;
  570. }
  571. }
  572. }, {
  573. key: '_hide',
  574. value: function _hide() {
  575. var unpin = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  576. if (unpin) {
  577. this.pinned = false;
  578. }
  579. if (!this.hideElement.hasAttribute('hidden') && !this.pinned) {
  580. this.hideElement.setAttribute('hidden', true);
  581. this.container.style.zIndex -= 1;
  582. }
  583. }
  584. }]);
  585. return PopupElement;
  586. }();
  587. var LineAnnotationElement = function (_AnnotationElement5) {
  588. _inherits(LineAnnotationElement, _AnnotationElement5);
  589. function LineAnnotationElement(parameters) {
  590. _classCallCheck(this, LineAnnotationElement);
  591. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  592. return _possibleConstructorReturn(this, (LineAnnotationElement.__proto__ || Object.getPrototypeOf(LineAnnotationElement)).call(this, parameters, isRenderable, true));
  593. }
  594. _createClass(LineAnnotationElement, [{
  595. key: 'render',
  596. value: function render() {
  597. this.container.className = 'lineAnnotation';
  598. var data = this.data;
  599. var width = data.rect[2] - data.rect[0];
  600. var height = data.rect[3] - data.rect[1];
  601. var svg = this.svgFactory.create(width, height);
  602. var line = this.svgFactory.createElement('svg:line');
  603. line.setAttribute('x1', data.rect[2] - data.lineCoordinates[0]);
  604. line.setAttribute('y1', data.rect[3] - data.lineCoordinates[1]);
  605. line.setAttribute('x2', data.rect[2] - data.lineCoordinates[2]);
  606. line.setAttribute('y2', data.rect[3] - data.lineCoordinates[3]);
  607. line.setAttribute('stroke-width', data.borderStyle.width);
  608. line.setAttribute('stroke', 'transparent');
  609. svg.appendChild(line);
  610. this.container.append(svg);
  611. this._createPopup(this.container, line, data);
  612. return this.container;
  613. }
  614. }]);
  615. return LineAnnotationElement;
  616. }(AnnotationElement);
  617. var SquareAnnotationElement = function (_AnnotationElement6) {
  618. _inherits(SquareAnnotationElement, _AnnotationElement6);
  619. function SquareAnnotationElement(parameters) {
  620. _classCallCheck(this, SquareAnnotationElement);
  621. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  622. return _possibleConstructorReturn(this, (SquareAnnotationElement.__proto__ || Object.getPrototypeOf(SquareAnnotationElement)).call(this, parameters, isRenderable, true));
  623. }
  624. _createClass(SquareAnnotationElement, [{
  625. key: 'render',
  626. value: function render() {
  627. this.container.className = 'squareAnnotation';
  628. var data = this.data;
  629. var width = data.rect[2] - data.rect[0];
  630. var height = data.rect[3] - data.rect[1];
  631. var svg = this.svgFactory.create(width, height);
  632. var borderWidth = data.borderStyle.width;
  633. var square = this.svgFactory.createElement('svg:rect');
  634. square.setAttribute('x', borderWidth / 2);
  635. square.setAttribute('y', borderWidth / 2);
  636. square.setAttribute('width', width - borderWidth);
  637. square.setAttribute('height', height - borderWidth);
  638. square.setAttribute('stroke-width', borderWidth);
  639. square.setAttribute('stroke', 'transparent');
  640. square.setAttribute('fill', 'none');
  641. svg.appendChild(square);
  642. this.container.append(svg);
  643. this._createPopup(this.container, square, data);
  644. return this.container;
  645. }
  646. }]);
  647. return SquareAnnotationElement;
  648. }(AnnotationElement);
  649. var CircleAnnotationElement = function (_AnnotationElement7) {
  650. _inherits(CircleAnnotationElement, _AnnotationElement7);
  651. function CircleAnnotationElement(parameters) {
  652. _classCallCheck(this, CircleAnnotationElement);
  653. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  654. return _possibleConstructorReturn(this, (CircleAnnotationElement.__proto__ || Object.getPrototypeOf(CircleAnnotationElement)).call(this, parameters, isRenderable, true));
  655. }
  656. _createClass(CircleAnnotationElement, [{
  657. key: 'render',
  658. value: function render() {
  659. this.container.className = 'circleAnnotation';
  660. var data = this.data;
  661. var width = data.rect[2] - data.rect[0];
  662. var height = data.rect[3] - data.rect[1];
  663. var svg = this.svgFactory.create(width, height);
  664. var borderWidth = data.borderStyle.width;
  665. var circle = this.svgFactory.createElement('svg:ellipse');
  666. circle.setAttribute('cx', width / 2);
  667. circle.setAttribute('cy', height / 2);
  668. circle.setAttribute('rx', width / 2 - borderWidth / 2);
  669. circle.setAttribute('ry', height / 2 - borderWidth / 2);
  670. circle.setAttribute('stroke-width', borderWidth);
  671. circle.setAttribute('stroke', 'transparent');
  672. circle.setAttribute('fill', 'none');
  673. svg.appendChild(circle);
  674. this.container.append(svg);
  675. this._createPopup(this.container, circle, data);
  676. return this.container;
  677. }
  678. }]);
  679. return CircleAnnotationElement;
  680. }(AnnotationElement);
  681. var PolylineAnnotationElement = function (_AnnotationElement8) {
  682. _inherits(PolylineAnnotationElement, _AnnotationElement8);
  683. function PolylineAnnotationElement(parameters) {
  684. _classCallCheck(this, PolylineAnnotationElement);
  685. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  686. var _this15 = _possibleConstructorReturn(this, (PolylineAnnotationElement.__proto__ || Object.getPrototypeOf(PolylineAnnotationElement)).call(this, parameters, isRenderable, true));
  687. _this15.containerClassName = 'polylineAnnotation';
  688. _this15.svgElementName = 'svg:polyline';
  689. return _this15;
  690. }
  691. _createClass(PolylineAnnotationElement, [{
  692. key: 'render',
  693. value: function render() {
  694. this.container.className = this.containerClassName;
  695. var data = this.data;
  696. var width = data.rect[2] - data.rect[0];
  697. var height = data.rect[3] - data.rect[1];
  698. var svg = this.svgFactory.create(width, height);
  699. var vertices = data.vertices;
  700. var points = [];
  701. for (var i = 0, ii = vertices.length; i < ii; i++) {
  702. var x = vertices[i].x - data.rect[0];
  703. var y = data.rect[3] - vertices[i].y;
  704. points.push(x + ',' + y);
  705. }
  706. points = points.join(' ');
  707. var borderWidth = data.borderStyle.width;
  708. var polyline = this.svgFactory.createElement(this.svgElementName);
  709. polyline.setAttribute('points', points);
  710. polyline.setAttribute('stroke-width', borderWidth);
  711. polyline.setAttribute('stroke', 'transparent');
  712. polyline.setAttribute('fill', 'none');
  713. svg.appendChild(polyline);
  714. this.container.append(svg);
  715. this._createPopup(this.container, polyline, data);
  716. return this.container;
  717. }
  718. }]);
  719. return PolylineAnnotationElement;
  720. }(AnnotationElement);
  721. var PolygonAnnotationElement = function (_PolylineAnnotationEl) {
  722. _inherits(PolygonAnnotationElement, _PolylineAnnotationEl);
  723. function PolygonAnnotationElement(parameters) {
  724. _classCallCheck(this, PolygonAnnotationElement);
  725. var _this16 = _possibleConstructorReturn(this, (PolygonAnnotationElement.__proto__ || Object.getPrototypeOf(PolygonAnnotationElement)).call(this, parameters));
  726. _this16.containerClassName = 'polygonAnnotation';
  727. _this16.svgElementName = 'svg:polygon';
  728. return _this16;
  729. }
  730. return PolygonAnnotationElement;
  731. }(PolylineAnnotationElement);
  732. var HighlightAnnotationElement = function (_AnnotationElement9) {
  733. _inherits(HighlightAnnotationElement, _AnnotationElement9);
  734. function HighlightAnnotationElement(parameters) {
  735. _classCallCheck(this, HighlightAnnotationElement);
  736. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  737. return _possibleConstructorReturn(this, (HighlightAnnotationElement.__proto__ || Object.getPrototypeOf(HighlightAnnotationElement)).call(this, parameters, isRenderable, true));
  738. }
  739. _createClass(HighlightAnnotationElement, [{
  740. key: 'render',
  741. value: function render() {
  742. this.container.className = 'highlightAnnotation';
  743. if (!this.data.hasPopup) {
  744. this._createPopup(this.container, null, this.data);
  745. }
  746. return this.container;
  747. }
  748. }]);
  749. return HighlightAnnotationElement;
  750. }(AnnotationElement);
  751. var UnderlineAnnotationElement = function (_AnnotationElement10) {
  752. _inherits(UnderlineAnnotationElement, _AnnotationElement10);
  753. function UnderlineAnnotationElement(parameters) {
  754. _classCallCheck(this, UnderlineAnnotationElement);
  755. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  756. return _possibleConstructorReturn(this, (UnderlineAnnotationElement.__proto__ || Object.getPrototypeOf(UnderlineAnnotationElement)).call(this, parameters, isRenderable, true));
  757. }
  758. _createClass(UnderlineAnnotationElement, [{
  759. key: 'render',
  760. value: function render() {
  761. this.container.className = 'underlineAnnotation';
  762. if (!this.data.hasPopup) {
  763. this._createPopup(this.container, null, this.data);
  764. }
  765. return this.container;
  766. }
  767. }]);
  768. return UnderlineAnnotationElement;
  769. }(AnnotationElement);
  770. var SquigglyAnnotationElement = function (_AnnotationElement11) {
  771. _inherits(SquigglyAnnotationElement, _AnnotationElement11);
  772. function SquigglyAnnotationElement(parameters) {
  773. _classCallCheck(this, SquigglyAnnotationElement);
  774. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  775. return _possibleConstructorReturn(this, (SquigglyAnnotationElement.__proto__ || Object.getPrototypeOf(SquigglyAnnotationElement)).call(this, parameters, isRenderable, true));
  776. }
  777. _createClass(SquigglyAnnotationElement, [{
  778. key: 'render',
  779. value: function render() {
  780. this.container.className = 'squigglyAnnotation';
  781. if (!this.data.hasPopup) {
  782. this._createPopup(this.container, null, this.data);
  783. }
  784. return this.container;
  785. }
  786. }]);
  787. return SquigglyAnnotationElement;
  788. }(AnnotationElement);
  789. var StrikeOutAnnotationElement = function (_AnnotationElement12) {
  790. _inherits(StrikeOutAnnotationElement, _AnnotationElement12);
  791. function StrikeOutAnnotationElement(parameters) {
  792. _classCallCheck(this, StrikeOutAnnotationElement);
  793. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  794. return _possibleConstructorReturn(this, (StrikeOutAnnotationElement.__proto__ || Object.getPrototypeOf(StrikeOutAnnotationElement)).call(this, parameters, isRenderable, true));
  795. }
  796. _createClass(StrikeOutAnnotationElement, [{
  797. key: 'render',
  798. value: function render() {
  799. this.container.className = 'strikeoutAnnotation';
  800. if (!this.data.hasPopup) {
  801. this._createPopup(this.container, null, this.data);
  802. }
  803. return this.container;
  804. }
  805. }]);
  806. return StrikeOutAnnotationElement;
  807. }(AnnotationElement);
  808. var StampAnnotationElement = function (_AnnotationElement13) {
  809. _inherits(StampAnnotationElement, _AnnotationElement13);
  810. function StampAnnotationElement(parameters) {
  811. _classCallCheck(this, StampAnnotationElement);
  812. var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);
  813. return _possibleConstructorReturn(this, (StampAnnotationElement.__proto__ || Object.getPrototypeOf(StampAnnotationElement)).call(this, parameters, isRenderable, true));
  814. }
  815. _createClass(StampAnnotationElement, [{
  816. key: 'render',
  817. value: function render() {
  818. this.container.className = 'stampAnnotation';
  819. if (!this.data.hasPopup) {
  820. this._createPopup(this.container, null, this.data);
  821. }
  822. return this.container;
  823. }
  824. }]);
  825. return StampAnnotationElement;
  826. }(AnnotationElement);
  827. var FileAttachmentAnnotationElement = function (_AnnotationElement14) {
  828. _inherits(FileAttachmentAnnotationElement, _AnnotationElement14);
  829. function FileAttachmentAnnotationElement(parameters) {
  830. _classCallCheck(this, FileAttachmentAnnotationElement);
  831. var _this22 = _possibleConstructorReturn(this, (FileAttachmentAnnotationElement.__proto__ || Object.getPrototypeOf(FileAttachmentAnnotationElement)).call(this, parameters, true));
  832. var file = _this22.data.file;
  833. _this22.filename = (0, _dom_utils.getFilenameFromUrl)(file.filename);
  834. _this22.content = file.content;
  835. _this22.linkService.onFileAttachmentAnnotation({
  836. id: (0, _util.stringToPDFString)(file.filename),
  837. filename: file.filename,
  838. content: file.content
  839. });
  840. return _this22;
  841. }
  842. _createClass(FileAttachmentAnnotationElement, [{
  843. key: 'render',
  844. value: function render() {
  845. this.container.className = 'fileAttachmentAnnotation';
  846. var trigger = document.createElement('div');
  847. trigger.style.height = this.container.style.height;
  848. trigger.style.width = this.container.style.width;
  849. trigger.addEventListener('dblclick', this._download.bind(this));
  850. if (!this.data.hasPopup && (this.data.title || this.data.contents)) {
  851. this._createPopup(this.container, trigger, this.data);
  852. }
  853. this.container.appendChild(trigger);
  854. return this.container;
  855. }
  856. }, {
  857. key: '_download',
  858. value: function _download() {
  859. if (!this.downloadManager) {
  860. (0, _util.warn)('Download cannot be started due to unavailable download manager');
  861. return;
  862. }
  863. this.downloadManager.downloadData(this.content, this.filename, '');
  864. }
  865. }]);
  866. return FileAttachmentAnnotationElement;
  867. }(AnnotationElement);
  868. var AnnotationLayer = function () {
  869. function AnnotationLayer() {
  870. _classCallCheck(this, AnnotationLayer);
  871. }
  872. _createClass(AnnotationLayer, null, [{
  873. key: 'render',
  874. value: function render(parameters) {
  875. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  876. var data = parameters.annotations[i];
  877. if (!data) {
  878. continue;
  879. }
  880. var element = AnnotationElementFactory.create({
  881. data: data,
  882. layer: parameters.div,
  883. page: parameters.page,
  884. viewport: parameters.viewport,
  885. linkService: parameters.linkService,
  886. downloadManager: parameters.downloadManager,
  887. imageResourcesPath: parameters.imageResourcesPath || '',
  888. renderInteractiveForms: parameters.renderInteractiveForms || false,
  889. svgFactory: new _dom_utils.DOMSVGFactory()
  890. });
  891. if (element.isRenderable) {
  892. parameters.div.appendChild(element.render());
  893. }
  894. }
  895. }
  896. }, {
  897. key: 'update',
  898. value: function update(parameters) {
  899. for (var i = 0, ii = parameters.annotations.length; i < ii; i++) {
  900. var data = parameters.annotations[i];
  901. var element = parameters.div.querySelector('[data-annotation-id="' + data.id + '"]');
  902. if (element) {
  903. element.style.transform = 'matrix(' + parameters.viewport.transform.join(',') + ')';
  904. }
  905. }
  906. parameters.div.removeAttribute('hidden');
  907. }
  908. }]);
  909. return AnnotationLayer;
  910. }();
  911. exports.AnnotationLayer = AnnotationLayer;