2
0

annotation_layer.js 40 KB

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