2
0

annotation_layer.js 45 KB

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