How to use AnnotationElement method in wpt

Best JavaScript code snippet using wpt

annotation_layer.js

Source:annotation_layer.js Github

copy

Full Screen

...58 create: function AnnotationElementFactory_create(parameters) {59 var subtype = parameters.data.annotationType;60 switch (subtype) {61 case AnnotationType.LINK:62 return new LinkAnnotationElement(parameters);63 case AnnotationType.TEXT:64 return new TextAnnotationElement(parameters);65 case AnnotationType.WIDGET:66 var fieldType = parameters.data.fieldType;67 switch (fieldType) {68 case 'Tx':69 return new TextWidgetAnnotationElement(parameters);70 case 'Btn':71 if (parameters.data.radioButton) {72 return new RadioButtonWidgetAnnotationElement(parameters);73 } else if (parameters.data.checkBox) {74 return new CheckboxWidgetAnnotationElement(parameters);75 } else {76 warn('Unimplemented button widget annotation: pushbutton');77 }78 break;79 case 'Ch':80 return new ChoiceWidgetAnnotationElement(parameters);81 }82 return new WidgetAnnotationElement(parameters);83 case AnnotationType.POPUP:84 return new PopupAnnotationElement(parameters);85 case AnnotationType.HIGHLIGHT:86 return new HighlightAnnotationElement(parameters);87 case AnnotationType.UNDERLINE:88 return new UnderlineAnnotationElement(parameters);89 case AnnotationType.SQUIGGLY:90 return new SquigglyAnnotationElement(parameters);91 case AnnotationType.STRIKEOUT:92 return new StrikeOutAnnotationElement(parameters);93 case AnnotationType.FILEATTACHMENT:94 return new FileAttachmentAnnotationElement(parameters);95 default:96 return new AnnotationElement(parameters);97 }98 }99};100/**101 * @class102 * @alias AnnotationElement103 */104var AnnotationElement = (function AnnotationElementClosure() {105 function AnnotationElement(parameters, isRenderable) {106 this.isRenderable = isRenderable || false;107 this.data = parameters.data;108 this.layer = parameters.layer;109 this.page = parameters.page;110 this.viewport = parameters.viewport;111 this.linkService = parameters.linkService;112 this.downloadManager = parameters.downloadManager;113 this.imageResourcesPath = parameters.imageResourcesPath;114 this.renderInteractiveForms = parameters.renderInteractiveForms;115 if (isRenderable) {116 this.container = this._createContainer();117 }118 }119 AnnotationElement.prototype = /** @lends AnnotationElement.prototype */ {120 /**121 * Create an empty container for the annotation's HTML element.122 *123 * @private124 * @memberof AnnotationElement125 * @returns {HTMLSectionElement}126 */127 _createContainer: function AnnotationElement_createContainer() {128 var data = this.data, page = this.page, viewport = this.viewport;129 var container = document.createElement('section');130 var width = data.rect[2] - data.rect[0];131 var height = data.rect[3] - data.rect[1];132 container.setAttribute('data-annotation-id', data.id);133 // Do *not* modify `data.rect`, since that will corrupt the annotation134 // position on subsequent calls to `_createContainer` (see issue 6804).135 var rect = Util.normalizeRect([136 data.rect[0],137 page.view[3] - data.rect[1] + page.view[1],138 data.rect[2],139 page.view[3] - data.rect[3] + page.view[1]140 ]);141 CustomStyle.setProp('transform', container,142 'matrix(' + viewport.transform.join(',') + ')');143 CustomStyle.setProp('transformOrigin', container,144 -rect[0] + 'px ' + -rect[1] + 'px');145 if (data.borderStyle.width > 0) {146 container.style.borderWidth = data.borderStyle.width + 'px';147 if (data.borderStyle.style !== AnnotationBorderStyleType.UNDERLINE) {148 // Underline styles only have a bottom border, so we do not need149 // to adjust for all borders. This yields a similar result as150 // Adobe Acrobat/Reader.151 width = width - 2 * data.borderStyle.width;152 height = height - 2 * data.borderStyle.width;153 }154 var horizontalRadius = data.borderStyle.horizontalCornerRadius;155 var verticalRadius = data.borderStyle.verticalCornerRadius;156 if (horizontalRadius > 0 || verticalRadius > 0) {157 var radius = horizontalRadius + 'px / ' + verticalRadius + 'px';158 CustomStyle.setProp('borderRadius', container, radius);159 }160 switch (data.borderStyle.style) {161 case AnnotationBorderStyleType.SOLID:162 container.style.borderStyle = 'solid';163 break;164 case AnnotationBorderStyleType.DASHED:165 container.style.borderStyle = 'dashed';166 break;167 case AnnotationBorderStyleType.BEVELED:168 warn('Unimplemented border style: beveled');169 break;170 case AnnotationBorderStyleType.INSET:171 warn('Unimplemented border style: inset');172 break;173 case AnnotationBorderStyleType.UNDERLINE:174 container.style.borderBottomStyle = 'solid';175 break;176 default:177 break;178 }179 if (data.color) {180 container.style.borderColor =181 Util.makeCssRgb(data.color[0] | 0,182 data.color[1] | 0,183 data.color[2] | 0);184 } else {185 // Transparent (invisible) border, so do not draw it at all.186 container.style.borderWidth = 0;187 }188 }189 container.style.left = rect[0] + 'px';190 container.style.top = rect[1] + 'px';191 container.style.width = width + 'px';192 container.style.height = height + 'px';193 return container;194 },195 /**196 * Create a popup for the annotation's HTML element. This is used for197 * annotations that do not have a Popup entry in the dictionary, but198 * are of a type that works with popups (such as Highlight annotations).199 *200 * @private201 * @param {HTMLSectionElement} container202 * @param {HTMLDivElement|HTMLImageElement|null} trigger203 * @param {Object} data204 * @memberof AnnotationElement205 */206 _createPopup:207 function AnnotationElement_createPopup(container, trigger, data) {208 // If no trigger element is specified, create it.209 if (!trigger) {210 trigger = document.createElement('div');211 trigger.style.height = container.style.height;212 trigger.style.width = container.style.width;213 container.appendChild(trigger);214 }215 var popupElement = new PopupElement({216 container: container,217 trigger: trigger,218 color: data.color,219 title: data.title,220 contents: data.contents,221 hideWrapper: true222 });223 var popup = popupElement.render();224 // Position the popup next to the annotation's container.225 popup.style.left = container.style.width;226 container.appendChild(popup);227 },228 /**229 * Render the annotation's HTML element in the empty container.230 *231 * @public232 * @memberof AnnotationElement233 */234 render: function AnnotationElement_render() {235 throw new Error('Abstract method AnnotationElement.render called');236 }237 };238 return AnnotationElement;239})();240/**241 * @class242 * @alias LinkAnnotationElement243 */244var LinkAnnotationElement = (function LinkAnnotationElementClosure() {245 function LinkAnnotationElement(parameters) {246 AnnotationElement.call(this, parameters, true);247 }248 Util.inherit(LinkAnnotationElement, AnnotationElement, {249 /**250 * Render the link annotation's HTML element in the empty container.251 *252 * @public253 * @memberof LinkAnnotationElement254 * @returns {HTMLSectionElement}255 */256 render: function LinkAnnotationElement_render() {257 this.container.className = 'linkAnnotation';258 var link = document.createElement('a');259 addLinkAttributes(link, {260 url: this.data.url,261 target: (this.data.newWindow ? LinkTarget.BLANK : undefined),262 });263 if (!this.data.url) {264 if (this.data.action) {265 this._bindNamedAction(link, this.data.action);266 } else {267 this._bindLink(link, this.data.dest);268 }269 }270 this.container.appendChild(link);271 return this.container;272 },273 /**274 * Bind internal links to the link element.275 *276 * @private277 * @param {Object} link278 * @param {Object} destination279 * @memberof LinkAnnotationElement280 */281 _bindLink: function LinkAnnotationElement_bindLink(link, destination) {282 var self = this;283 link.href = this.linkService.getDestinationHash(destination);284 link.onclick = function() {285 if (destination) {286 self.linkService.navigateTo(destination);287 }288 return false;289 };290 if (destination) {291 link.className = 'internalLink';292 }293 },294 /**295 * Bind named actions to the link element.296 *297 * @private298 * @param {Object} link299 * @param {Object} action300 * @memberof LinkAnnotationElement301 */302 _bindNamedAction:303 function LinkAnnotationElement_bindNamedAction(link, action) {304 var self = this;305 link.href = this.linkService.getAnchorUrl('');306 link.onclick = function() {307 self.linkService.executeNamedAction(action);308 return false;309 };310 link.className = 'internalLink';311 }312 });313 return LinkAnnotationElement;314})();315/**316 * @class317 * @alias TextAnnotationElement318 */319var TextAnnotationElement = (function TextAnnotationElementClosure() {320 function TextAnnotationElement(parameters) {321 var isRenderable = !!(parameters.data.hasPopup ||322 parameters.data.title || parameters.data.contents);323 AnnotationElement.call(this, parameters, isRenderable);324 }325 Util.inherit(TextAnnotationElement, AnnotationElement, {326 /**327 * Render the text annotation's HTML element in the empty container.328 *329 * @public330 * @memberof TextAnnotationElement331 * @returns {HTMLSectionElement}332 */333 render: function TextAnnotationElement_render() {334 this.container.className = 'textAnnotation';335 var image = document.createElement('img');336 image.style.height = this.container.style.height;337 image.style.width = this.container.style.width;338 image.src = this.imageResourcesPath + 'annotation-' +339 this.data.name.toLowerCase() + '.svg';340 image.alt = '[{{type}} Annotation]';341 image.dataset.l10nId = 'text_annotation_type';342 image.dataset.l10nArgs = JSON.stringify({type: this.data.name});343 if (!this.data.hasPopup) {344 this._createPopup(this.container, image, this.data);345 }346 this.container.appendChild(image);347 return this.container;348 }349 });350 return TextAnnotationElement;351})();352/**353 * @class354 * @alias WidgetAnnotationElement355 */356var WidgetAnnotationElement = (function WidgetAnnotationElementClosure() {357 function WidgetAnnotationElement(parameters, isRenderable) {358 AnnotationElement.call(this, parameters, isRenderable);359 }360 Util.inherit(WidgetAnnotationElement, AnnotationElement, {361 /**362 * Render the widget annotation's HTML element in the empty container.363 *364 * @public365 * @memberof WidgetAnnotationElement366 * @returns {HTMLSectionElement}367 */368 render: function WidgetAnnotationElement_render() {369 // Show only the container for unsupported field types.370 return this.container;371 }372 });373 return WidgetAnnotationElement;374})();375/**376 * @class377 * @alias TextWidgetAnnotationElement378 */379var TextWidgetAnnotationElement = (380 function TextWidgetAnnotationElementClosure() {381 var TEXT_ALIGNMENT = ['left', 'center', 'right'];382 function TextWidgetAnnotationElement(parameters) {383 var isRenderable = parameters.renderInteractiveForms ||384 (!parameters.data.hasAppearance && !!parameters.data.fieldValue);385 WidgetAnnotationElement.call(this, parameters, isRenderable);386 }387 Util.inherit(TextWidgetAnnotationElement, WidgetAnnotationElement, {388 /**389 * Render the text widget annotation's HTML element in the empty container.390 *391 * @public392 * @memberof TextWidgetAnnotationElement393 * @returns {HTMLSectionElement}394 */395 render: function TextWidgetAnnotationElement_render() {396 this.container.className = 'textWidgetAnnotation';397 var element = null;398 if (this.renderInteractiveForms) {399 // NOTE: We cannot set the values using `element.value` below, since it400 // prevents the AnnotationLayer rasterizer in `test/driver.js`401 // from parsing the elements correctly for the reference tests.402 if (this.data.multiLine) {403 element = document.createElement('textarea');404 element.textContent = this.data.fieldValue;405 } else {406 element = document.createElement('input');407 element.type = 'text';408 element.setAttribute('value', this.data.fieldValue);409 }410 element.disabled = this.data.readOnly;411 if (this.data.maxLen !== null) {412 element.maxLength = this.data.maxLen;413 }414 if (this.data.comb) {415 var fieldWidth = this.data.rect[2] - this.data.rect[0];416 var combWidth = fieldWidth / this.data.maxLen;417 element.classList.add('comb');418 element.style.letterSpacing = 'calc(' + combWidth + 'px - 1ch)';419 }420 } else {421 element = document.createElement('div');422 element.textContent = this.data.fieldValue;423 element.style.verticalAlign = 'middle';424 element.style.display = 'table-cell';425 var font = null;426 if (this.data.fontRefName) {427 font = this.page.commonObjs.getData(this.data.fontRefName);428 }429 this._setTextStyle(element, font);430 }431 if (this.data.textAlignment !== null) {432 element.style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];433 }434 this.container.appendChild(element);435 return this.container;436 },437 /**438 * Apply text styles to the text in the element.439 *440 * @private441 * @param {HTMLDivElement} element442 * @param {Object} font443 * @memberof TextWidgetAnnotationElement444 */445 _setTextStyle:446 function TextWidgetAnnotationElement_setTextStyle(element, font) {447 // TODO: This duplicates some of the logic in CanvasGraphics.setFont().448 var style = element.style;449 style.fontSize = this.data.fontSize + 'px';450 style.direction = (this.data.fontDirection < 0 ? 'rtl' : 'ltr');451 if (!font) {452 return;453 }454 style.fontWeight = (font.black ?455 (font.bold ? '900' : 'bold') :456 (font.bold ? 'bold' : 'normal'));457 style.fontStyle = (font.italic ? 'italic' : 'normal');458 // Use a reasonable default font if the font doesn't specify a fallback.459 var fontFamily = font.loadedName ? '"' + font.loadedName + '", ' : '';460 var fallbackName = font.fallbackName || 'Helvetica, sans-serif';461 style.fontFamily = fontFamily + fallbackName;462 }463 });464 return TextWidgetAnnotationElement;465})();466/**467 * @class468 * @alias CheckboxWidgetAnnotationElement469 */470var CheckboxWidgetAnnotationElement =471 (function CheckboxWidgetAnnotationElementClosure() {472 function CheckboxWidgetAnnotationElement(parameters) {473 WidgetAnnotationElement.call(this, parameters,474 parameters.renderInteractiveForms);475 }476 Util.inherit(CheckboxWidgetAnnotationElement, WidgetAnnotationElement, {477 /**478 * Render the checkbox widget annotation's HTML element479 * in the empty container.480 *481 * @public482 * @memberof CheckboxWidgetAnnotationElement483 * @returns {HTMLSectionElement}484 */485 render: function CheckboxWidgetAnnotationElement_render() {486 this.container.className = 'buttonWidgetAnnotation checkBox';487 var element = document.createElement('input');488 element.disabled = this.data.readOnly;489 element.type = 'checkbox';490 if (this.data.fieldValue && this.data.fieldValue !== 'Off') {491 element.setAttribute('checked', true);492 }493 this.container.appendChild(element);494 return this.container;495 }496 });497 return CheckboxWidgetAnnotationElement;498})();499/**500 * @class501 * @alias RadioButtonWidgetAnnotationElement502 */503var RadioButtonWidgetAnnotationElement =504 (function RadioButtonWidgetAnnotationElementClosure() {505 function RadioButtonWidgetAnnotationElement(parameters) {506 WidgetAnnotationElement.call(this, parameters,507 parameters.renderInteractiveForms);508 }509 Util.inherit(RadioButtonWidgetAnnotationElement, WidgetAnnotationElement, {510 /**511 * Render the radio button widget annotation's HTML element512 * in the empty container.513 *514 * @public515 * @memberof RadioButtonWidgetAnnotationElement516 * @returns {HTMLSectionElement}517 */518 render: function RadioButtonWidgetAnnotationElement_render() {519 this.container.className = 'buttonWidgetAnnotation radioButton';520 var element = document.createElement('input');521 element.disabled = this.data.readOnly;522 element.type = 'radio';523 element.name = this.data.fieldName;524 if (this.data.fieldValue === this.data.buttonValue) {525 element.setAttribute('checked', true);526 }527 this.container.appendChild(element);528 return this.container;529 }530 });531 return RadioButtonWidgetAnnotationElement;532})();533 /**534 * @class535 * @alias ChoiceWidgetAnnotationElement536 */537var ChoiceWidgetAnnotationElement = (538 function ChoiceWidgetAnnotationElementClosure() {539 function ChoiceWidgetAnnotationElement(parameters) {540 WidgetAnnotationElement.call(this, parameters,541 parameters.renderInteractiveForms);542 }543 Util.inherit(ChoiceWidgetAnnotationElement, WidgetAnnotationElement, {544 /**545 * Render the choice widget annotation's HTML element in the empty546 * container.547 *548 * @public549 * @memberof ChoiceWidgetAnnotationElement550 * @returns {HTMLSectionElement}551 */552 render: function ChoiceWidgetAnnotationElement_render() {553 this.container.className = 'choiceWidgetAnnotation';554 var selectElement = document.createElement('select');555 selectElement.disabled = this.data.readOnly;556 if (!this.data.combo) {557 // List boxes have a size and (optionally) multiple selection.558 selectElement.size = this.data.options.length;559 if (this.data.multiSelect) {560 selectElement.multiple = true;561 }562 }563 // Insert the options into the choice field.564 for (var i = 0, ii = this.data.options.length; i < ii; i++) {565 var option = this.data.options[i];566 var optionElement = document.createElement('option');567 optionElement.textContent = option.displayValue;568 optionElement.value = option.exportValue;569 if (this.data.fieldValue.indexOf(option.displayValue) >= 0) {570 optionElement.setAttribute('selected', true);571 }572 selectElement.appendChild(optionElement);573 }574 this.container.appendChild(selectElement);575 return this.container;576 }577 });578 return ChoiceWidgetAnnotationElement;579})();580/**581 * @class582 * @alias PopupAnnotationElement583 */584var PopupAnnotationElement = (function PopupAnnotationElementClosure() {585 function PopupAnnotationElement(parameters) {586 var isRenderable = !!(parameters.data.title || parameters.data.contents);587 AnnotationElement.call(this, parameters, isRenderable);588 }589 Util.inherit(PopupAnnotationElement, AnnotationElement, {590 /**591 * Render the popup annotation's HTML element in the empty container.592 *593 * @public594 * @memberof PopupAnnotationElement595 * @returns {HTMLSectionElement}596 */597 render: function PopupAnnotationElement_render() {598 this.container.className = 'popupAnnotation';599 var selector = '[data-annotation-id="' + this.data.parentId + '"]';600 var parentElement = this.layer.querySelector(selector);601 if (!parentElement) {602 return this.container;603 }604 var popup = new PopupElement({605 container: this.container,606 trigger: parentElement,607 color: this.data.color,608 title: this.data.title,609 contents: this.data.contents610 });611 // Position the popup next to the parent annotation's container.612 // PDF viewers ignore a popup annotation's rectangle.613 var parentLeft = parseFloat(parentElement.style.left);614 var parentWidth = parseFloat(parentElement.style.width);615 CustomStyle.setProp('transformOrigin', this.container,616 -(parentLeft + parentWidth) + 'px -' +617 parentElement.style.top);618 this.container.style.left = (parentLeft + parentWidth) + 'px';619 this.container.appendChild(popup.render());620 return this.container;621 }622 });623 return PopupAnnotationElement;624})();625/**626 * @class627 * @alias PopupElement628 */629var PopupElement = (function PopupElementClosure() {630 var BACKGROUND_ENLIGHT = 0.7;631 function PopupElement(parameters) {632 this.container = parameters.container;633 this.trigger = parameters.trigger;634 this.color = parameters.color;635 this.title = parameters.title;636 this.contents = parameters.contents;637 this.hideWrapper = parameters.hideWrapper || false;638 this.pinned = false;639 }640 PopupElement.prototype = /** @lends PopupElement.prototype */ {641 /**642 * Render the popup's HTML element.643 *644 * @public645 * @memberof PopupElement646 * @returns {HTMLSectionElement}647 */648 render: function PopupElement_render() {649 var wrapper = document.createElement('div');650 wrapper.className = 'popupWrapper';651 // For Popup annotations we hide the entire section because it contains652 // only the popup. However, for Text annotations without a separate Popup653 // annotation, we cannot hide the entire container as the image would654 // disappear too. In that special case, hiding the wrapper suffices.655 this.hideElement = (this.hideWrapper ? wrapper : this.container);656 this.hideElement.setAttribute('hidden', true);657 var popup = document.createElement('div');658 popup.className = 'popup';659 var color = this.color;660 if (color) {661 // Enlighten the color.662 var r = BACKGROUND_ENLIGHT * (255 - color[0]) + color[0];663 var g = BACKGROUND_ENLIGHT * (255 - color[1]) + color[1];664 var b = BACKGROUND_ENLIGHT * (255 - color[2]) + color[2];665 popup.style.backgroundColor = Util.makeCssRgb(r | 0, g | 0, b | 0);666 }667 var contents = this._formatContents(this.contents);668 var title = document.createElement('h1');669 title.textContent = this.title;670 // Attach the event listeners to the trigger element.671 this.trigger.addEventListener('click', this._toggle.bind(this));672 this.trigger.addEventListener('mouseover', this._show.bind(this, false));673 this.trigger.addEventListener('mouseout', this._hide.bind(this, false));674 popup.addEventListener('click', this._hide.bind(this, true));675 popup.appendChild(title);676 popup.appendChild(contents);677 wrapper.appendChild(popup);678 return wrapper;679 },680 /**681 * Format the contents of the popup by adding newlines where necessary.682 *683 * @private684 * @param {string} contents685 * @memberof PopupElement686 * @returns {HTMLParagraphElement}687 */688 _formatContents: function PopupElement_formatContents(contents) {689 var p = document.createElement('p');690 var lines = contents.split(/(?:\r\n?|\n)/);691 for (var i = 0, ii = lines.length; i < ii; ++i) {692 var line = lines[i];693 p.appendChild(document.createTextNode(line));694 if (i < (ii - 1)) {695 p.appendChild(document.createElement('br'));696 }697 }698 return p;699 },700 /**701 * Toggle the visibility of the popup.702 *703 * @private704 * @memberof PopupElement705 */706 _toggle: function PopupElement_toggle() {707 if (this.pinned) {708 this._hide(true);709 } else {710 this._show(true);711 }712 },713 /**714 * Show the popup.715 *716 * @private717 * @param {boolean} pin718 * @memberof PopupElement719 */720 _show: function PopupElement_show(pin) {721 if (pin) {722 this.pinned = true;723 }724 if (this.hideElement.hasAttribute('hidden')) {725 this.hideElement.removeAttribute('hidden');726 this.container.style.zIndex += 1;727 }728 },729 /**730 * Hide the popup.731 *732 * @private733 * @param {boolean} unpin734 * @memberof PopupElement735 */736 _hide: function PopupElement_hide(unpin) {737 if (unpin) {738 this.pinned = false;739 }740 if (!this.hideElement.hasAttribute('hidden') && !this.pinned) {741 this.hideElement.setAttribute('hidden', true);742 this.container.style.zIndex -= 1;743 }744 }745 };746 return PopupElement;747})();748/**749 * @class750 * @alias HighlightAnnotationElement751 */752var HighlightAnnotationElement = (753 function HighlightAnnotationElementClosure() {754 function HighlightAnnotationElement(parameters) {755 var isRenderable = !!(parameters.data.hasPopup ||756 parameters.data.title || parameters.data.contents);757 AnnotationElement.call(this, parameters, isRenderable);758 }759 Util.inherit(HighlightAnnotationElement, AnnotationElement, {760 /**761 * Render the highlight annotation's HTML element in the empty container.762 *763 * @public764 * @memberof HighlightAnnotationElement765 * @returns {HTMLSectionElement}766 */767 render: function HighlightAnnotationElement_render() {768 this.container.className = 'highlightAnnotation';769 if (!this.data.hasPopup) {770 this._createPopup(this.container, null, this.data);771 }772 return this.container;773 }774 });775 return HighlightAnnotationElement;776})();777/**778 * @class779 * @alias UnderlineAnnotationElement780 */781var UnderlineAnnotationElement = (782 function UnderlineAnnotationElementClosure() {783 function UnderlineAnnotationElement(parameters) {784 var isRenderable = !!(parameters.data.hasPopup ||785 parameters.data.title || parameters.data.contents);786 AnnotationElement.call(this, parameters, isRenderable);787 }788 Util.inherit(UnderlineAnnotationElement, AnnotationElement, {789 /**790 * Render the underline annotation's HTML element in the empty container.791 *792 * @public793 * @memberof UnderlineAnnotationElement794 * @returns {HTMLSectionElement}795 */796 render: function UnderlineAnnotationElement_render() {797 this.container.className = 'underlineAnnotation';798 if (!this.data.hasPopup) {799 this._createPopup(this.container, null, this.data);800 }801 return this.container;802 }803 });804 return UnderlineAnnotationElement;805})();806/**807 * @class808 * @alias SquigglyAnnotationElement809 */810var SquigglyAnnotationElement = (function SquigglyAnnotationElementClosure() {811 function SquigglyAnnotationElement(parameters) {812 var isRenderable = !!(parameters.data.hasPopup ||813 parameters.data.title || parameters.data.contents);814 AnnotationElement.call(this, parameters, isRenderable);815 }816 Util.inherit(SquigglyAnnotationElement, AnnotationElement, {817 /**818 * Render the squiggly annotation's HTML element in the empty container.819 *820 * @public821 * @memberof SquigglyAnnotationElement822 * @returns {HTMLSectionElement}823 */824 render: function SquigglyAnnotationElement_render() {825 this.container.className = 'squigglyAnnotation';826 if (!this.data.hasPopup) {827 this._createPopup(this.container, null, this.data);828 }829 return this.container;830 }831 });832 return SquigglyAnnotationElement;833})();834/**835 * @class836 * @alias StrikeOutAnnotationElement837 */838var StrikeOutAnnotationElement = (839 function StrikeOutAnnotationElementClosure() {840 function StrikeOutAnnotationElement(parameters) {841 var isRenderable = !!(parameters.data.hasPopup ||842 parameters.data.title || parameters.data.contents);843 AnnotationElement.call(this, parameters, isRenderable);844 }845 Util.inherit(StrikeOutAnnotationElement, AnnotationElement, {846 /**847 * Render the strikeout annotation's HTML element in the empty container.848 *849 * @public850 * @memberof StrikeOutAnnotationElement851 * @returns {HTMLSectionElement}852 */853 render: function StrikeOutAnnotationElement_render() {854 this.container.className = 'strikeoutAnnotation';855 if (!this.data.hasPopup) {856 this._createPopup(this.container, null, this.data);857 }858 return this.container;859 }860 });861 return StrikeOutAnnotationElement;862})();863/**864 * @class865 * @alias FileAttachmentAnnotationElement866 */867var FileAttachmentAnnotationElement = (868 function FileAttachmentAnnotationElementClosure() {869 function FileAttachmentAnnotationElement(parameters) {870 AnnotationElement.call(this, parameters, true);871 this.filename = getFilenameFromUrl(parameters.data.file.filename);872 this.content = parameters.data.file.content;873 }874 Util.inherit(FileAttachmentAnnotationElement, AnnotationElement, {875 /**876 * Render the file attachment annotation's HTML element in the empty877 * container.878 *879 * @public880 * @memberof FileAttachmentAnnotationElement881 * @returns {HTMLSectionElement}882 */883 render: function FileAttachmentAnnotationElement_render() {...

Full Screen

Full Screen

LabelView.ts

Source:LabelView.ts Github

copy

Full Screen

1import {TopContextUser} from "./TopContextUser";2import * as SVG from "svg.js";3import {TopContext} from "./TopContext";4import {Label} from "../../Store/Entities/Label";5import {LabelCategory} from "../../Store/Entities/LabelCategory";6import {Base} from "../../Infrastructure/Repository";7import {View} from "../View";8export namespace LabelView {9 const TEXT_CONTAINER_PADDING = 3;10 const TEXT_SIZE = 12;11 export class Entity extends TopContextUser {12 layer: number;13 svgElement: SVG.G = null;14 annotationElement: SVG.G;15 highLightElement: SVG.Rect;16 textElement: SVG.Text = null;17 textWidth: number = null;18 constructor(public readonly id: number,19 public readonly store: Label.Entity,20 public readonly context: TopContext) {21 super();22 this.layer = 1;23 }24 get x() {25 return Math.min(this.highlightElementBox.x, this.annotationElementBox.container.x);26 }27 get globalX(): number {28 //return (this.annotationElement.children()[0].node.getBoundingClientRect() as DOMRect).x + this.annotationElementBox.container.width / 2;29 // 获取left属性,避免部分浏览器中没有x属性30 return (this.annotationElement.children()[0].node.getBoundingClientRect() as DOMRect).left + this.annotationElementBox.container.width / 2;31 }32 get globalY(): number {33 //return (this.annotationElement.children()[0].node.getBoundingClientRect() as DOMRect).y + this.textElement.node.clientHeight / 2;34 // 获取top属性,避免部分浏览器中没有y属性35 return (this.annotationElement.children()[0].node.getBoundingClientRect() as DOMRect).top + this.textElement.node.clientHeight / 2;36 }37 get width() {38 return Math.max(this.highlightElementBox.width, this.annotationElementBox.container.width);39 }40 get highlightElementBox() {41 const startIndexInLine = this.store.startIndex - this.context.attachTo.store.startIndex;42 const endIndexInLine = this.store.endIndex - this.context.attachTo.store.startIndex;43 const parent = this.context.attachTo;44 const firstCharX = parent.xCoordinateOfChar[startIndexInLine];45 const endCharX = parent.xCoordinateOfChar[endIndexInLine];46 return {47 x: firstCharX,48 y: parent.y,49 width: endCharX - firstCharX,50 height: 2051 }52 }53 get annotationElementBox() {54 const highlightElementBox = this.highlightElementBox;55 const middleX = highlightElementBox.x + highlightElementBox.width / 2;56 const textX = middleX - this.textWidth / 2;57 return {58 text: {59 x: textX,60 width: this.textWidth61 },62 container: {63 x: textX - TEXT_CONTAINER_PADDING,64 y: highlightElementBox.y,65 width: this.textWidth + 2 * TEXT_CONTAINER_PADDING66 }67 }68 }69 get category(): LabelCategory.Entity {70 return this.store.category;71 }72 /**73 * Thanks to Alex Hornbake (function for generate curly bracket path)74 * @see http://bl.ocks.org/alexhornbake/600517675 */76 private bracket(x1, y1, x2, y2, width, q = 0.6) {77 //Calculate unit vector78 let dx = x1 - x2;79 let dy = y1 - y2;80 let len = Math.sqrt(dx * dx + dy * dy);81 dx = dx / len;82 dy = dy / len;83 //Calculate Control Points of path,84 let qx1 = x1 + q * width * dy;85 let qy1 = y1 - q * width * dx;86 let qx2 = (x1 - .25 * len * dx) + (1 - q) * width * dy;87 let qy2 = (y1 - .25 * len * dy) - (1 - q) * width * dx;88 let tx1 = (x1 - .5 * len * dx) + width * dy;89 let ty1 = (y1 - .5 * len * dy) - width * dx;90 let qx3 = x2 + q * width * dy;91 let qy3 = y2 - q * width * dx;92 let qx4 = (x1 - .75 * len * dx) + (1 - q) * width * dy;93 let qy4 = (y1 - .75 * len * dy) - (1 - q) * width * dx;94 return this.annotationElement.path(`M${x1},${y1}Q${qx1},${qy1},${qx2},${qy2}T${tx1},${ty1}M${x2},${y2}Q${qx3},${qy3},${qx4},${qy4}T${tx1},${ty1}`)95 .fill('none').stroke({96 color: this.category.borderColor,97 width: 198 });99 }100 initPosition() {101 //this.textWidth = this.textElement.node.clientWidth;102 // 使用document.getElementById().getBoundingClientRect().width 避免在谷歌浏览器下width获取不包含padding103 this.textWidth = document.getElementById(this.textElement.id()).getBoundingClientRect().width;104 }105 preRender() {106 this.svgElement = this.context.svgElement.group();107 this.annotationElement = this.svgElement.group().back();108 this.textElement = this.annotationElement.text(this.category.text).font({size: TEXT_SIZE});109 // to deceive svg.js not to call bbox when call x() and y()110 // bad for svg.js111 this.svgElement.attr('x', "");112 this.svgElement.attr('y', "");113 this.annotationElement.attr('x', "");114 this.annotationElement.attr('y', "");115 this.textElement.attr('x', "");116 this.textElement.attr('y', "");117 }118 removeElement() {119 this.svgElement.remove();120 this.svgElement = null;121 this.textElement.remove();122 this.textElement = null;123 }124 render() {125 this.renderHighlight();126 this.renderAnnotation();127 }128 private renderHighlight() {129 let box = this.highlightElementBox;130 this.highLightElement = this.svgElement.rect(box.width, box.height);131 this.highLightElement.fill({132 color: this.category.color,133 opacity: 0.5134 }).dx(box.x);135 }136 private renderAnnotation() {137 let highLightBox = this.highlightElementBox;138 let annotationBox = this.annotationElementBox;139 this.annotationElement.rect(annotationBox.container.width, TEXT_SIZE + TEXT_CONTAINER_PADDING * 2)140 .radius(3, 3)141 .fill({142 color: this.category.color,143 })144 .stroke(this.category.borderColor).back();145 this.annotationElement.x(annotationBox.container.x);146 this.textElement.front();147 this.textElement.x(3).y(-2);148 this.bracket(149 highLightBox.width - (annotationBox.container.x - highLightBox.x), 26,150 0 - (annotationBox.container.x - highLightBox.x), 26,151 8);152 this.textElement.style({153 '-webkit-user-select': 'none',154 '-khtml-user-select': 'none',155 '-moz-user-select': 'none',156 '-ms-user-select': 'none',157 'user-select': 'none',158 });159 this.annotationElement.y(this.y - 5);160 this.annotationElement.style({cursor: 'pointer'});161 this.annotationElement.addClass('label-view');162 this.annotationElement.on('click', (e) => {163 this.context.attachTo.root.root.emit('labelClicked', this.id);164 e.preventDefault();165 });166 this.annotationElement.on('dblclick', (e) => {167 this.context.attachTo.root.root.emit('labelDblClicked', this.id);168 e.preventDefault();169 });170 this.annotationElement.on('contextmenu', (e) => {171 this.context.attachTo.root.root.emit('labelRightClicked', this.id, e.clientX, e.clientY);172 e.preventDefault();173 });174 }175 }176 export class Repository extends Base.Repository<Entity> {177 root: View;178 constructor(root: View) {179 super(root);180 }181 delete(key: number | Entity): boolean {182 if (typeof key !== "number") {183 key = key.id;184 }185 if (this.has(key)) {186 if (this.has(key))187 this.get(key).removeElement();188 }189 return super.delete(key);190 }191 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var wp = new wptools.page('Barack Obama');3wp.get(function(err, resp){4 if(err){5 console.log(err);6 }else{7 console.log(resp);8 }9});10#### .get(callback)11#### .getAnnotations(callback)12#### .getCategories(callback)13#### .getCoordinates(callback)14#### .getDisambiguation(callback)15#### .getExternalLinks(callback)16#### .getInfobox(callback)17#### .getInterwikiLinks(callback)18#### .getLanguageLinks(callback)19#### .getLinks(callback)20#### .getParse(callback)21#### .getReferences(callback)22#### .getRevisions(callback)23#### .getSections(callback)24#### .getTemplates(callback)25#### .getImages(callback)26#### .getVideoInfo(callback)27#### .getWikibase(callback)28#### .getWikidata(callback)29#### .getWikitext(callback)30#### .getWikipedia(callback)31#### .getWikipediaUrl(callback)32#### .getWikipediaExtract(callback)33#### .getWikipediaFull(callback)34#### .getWikipediaRaw(callback)35#### .getWikipediaRaw(callback)36#### .getWikipediaFullRaw(callback)37#### .getWikipediaFullRaw(callback)38#### .getWikipediaExtended(callback)39#### .getWikipediaExtendedRaw(callback)40#### .getWikipediaFullExtended(callback)41#### .getWikipediaFullExtendedRaw(callback)42#### .getWikipediaRaw(callback)

Full Screen

Using AI Code Generation

copy

Full Screen

1CKEDITOR.plugins.add('annotation', {2 init: function (editor) {3 editor.on('instanceReady', function (evt) {4 var editor = evt.editor;5 editor.textPattern.register(/(\[\[)(.*?)(\]\])/g, function (match, element) {6 var annotationElement = new CKEDITOR.htmlParser.element('annotation');7 annotationElement.add(new CKEDITOR.htmlParser.text(match[2]));8 return annotationElement;9 });10 });11 }12});

Full Screen

Using AI Code Generation

copy

Full Screen

1var text = 'Hello World';2var text2 = 'Hello World';3var text3 = 'Hello World';4var text4 = 'Hello World';5var text5 = 'Hello World';6var text6 = 'Hello World';7var text7 = 'Hello World';8var text8 = 'Hello World';9var text9 = 'Hello World';10var text10 = 'Hello World';11var text11 = 'Hello World';12var text12 = 'Hello World';13var text13 = 'Hello World';14var text14 = 'Hello World';15var text15 = 'Hello World';16var text16 = 'Hello World';17var text17 = 'Hello World';18var text18 = 'Hello World';19var text19 = 'Hello World';20var text20 = 'Hello World';21var text21 = 'Hello World';22var text22 = 'Hello World';23var text23 = 'Hello World';24var text24 = 'Hello World';25var text25 = 'Hello World';26var text26 = 'Hello World';27var text27 = 'Hello World';28var text28 = 'Hello World';29var text29 = 'Hello World';30var text30 = 'Hello World';31var text31 = 'Hello World';32var text32 = 'Hello World';33var text33 = 'Hello World';34var text34 = 'Hello World';35var text35 = 'Hello World';36var text36 = 'Hello World';37var text37 = 'Hello World';38var text38 = 'Hello World';39var text39 = 'Hello World';40var text40 = 'Hello World';41var text41 = 'Hello World';42var text42 = 'Hello World';43var text43 = 'Hello World';44var text44 = 'Hello World';45var text45 = 'Hello World';46var text46 = 'Hello World';47var text47 = 'Hello World';48var text48 = 'Hello World';49var text49 = 'Hello World';50var text50 = 'Hello World';51var text51 = 'Hello World';52var text52 = 'Hello World';53var text53 = 'Hello World';54var text54 = 'Hello World';55var text55 = 'Hello World';56var text56 = 'Hello World';57var text57 = 'Hello World';58var text58 = 'Hello World';59var text59 = 'Hello World';60var text60 = 'Hello World';61var text61 = 'Hello World';62var text62 = 'Hello World';

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptexturize = require('wptexturize');2var wptexturize = new wptexturize();3var text = "I'm a \"wptexturize\" test string.";4console.log(wptexturize.texturize(text));5var wptexturize = require('wptexturize');6var wptexturize = new wptexturize();7var text = "I'm a \"wptexturize\" test string.";8console.log(wptexturize.texturize(text));9var wptexturize = require('wptexturize');10var wptexturize = new wptexturize();11var text = "I'm a \"wptexturize\" test string.";12console.log(wptexturize.texturize(text));13var wptexturize = require('wptexturize');14var wptexturize = new wptexturize();15var text = "I'm a \"wptexturize\" test string.";16console.log(wptexturize.texturize(text));17var wptexturize = require('wptexturize');18var wptexturize = new wptexturize();19var text = "I'm a \"wptexturize\" test string.";20console.log(wptexturize.texturize(text));

Full Screen

Using AI Code Generation

copy

Full Screen

1var AnnotationElement = require('wptextpattern').AnnotationElement;2var annotationElement = new AnnotationElement();3annotationElement.getAnnotationElement('1', '2', '3', '4', '5', '6', '7', '8', '9', '10');4{5 "annotation": {6 }7}8{9 "annotation": {10 }11}

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful