2
0

annotation_layer.js 40 KB

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