Best JavaScript code snippet using wpt
annotation_layer.js
Source:annotation_layer.js
...31 case _util.AnnotationType.WIDGET:32 var fieldType = parameters.data.fieldType;33 switch (fieldType) {34 case 'Tx':35 return new TextWidgetAnnotationElement(parameters);36 case 'Btn':37 if (parameters.data.radioButton) {38 return new RadioButtonWidgetAnnotationElement(parameters);39 } else if (parameters.data.checkBox) {40 return new CheckboxWidgetAnnotationElement(parameters);41 }42 (0, _util.warn)('Unimplemented button widget annotation: pushbutton');43 break;44 case 'Ch':45 return new ChoiceWidgetAnnotationElement(parameters);46 }47 return new WidgetAnnotationElement(parameters);48 case _util.AnnotationType.POPUP:49 return new PopupAnnotationElement(parameters);50 case _util.AnnotationType.LINE:51 return new LineAnnotationElement(parameters);52 case _util.AnnotationType.HIGHLIGHT:53 return new HighlightAnnotationElement(parameters);54 case _util.AnnotationType.UNDERLINE:55 return new UnderlineAnnotationElement(parameters);56 case _util.AnnotationType.SQUIGGLY:57 return new SquigglyAnnotationElement(parameters);58 case _util.AnnotationType.STRIKEOUT:59 return new StrikeOutAnnotationElement(parameters);60 case _util.AnnotationType.FILEATTACHMENT:61 return new FileAttachmentAnnotationElement(parameters);62 default:63 return new AnnotationElement(parameters);64 }65 }66};67var AnnotationElement = function AnnotationElementClosure() {68 function AnnotationElement(parameters, isRenderable, ignoreBorder) {69 this.isRenderable = isRenderable || false;70 this.data = parameters.data;71 this.layer = parameters.layer;72 this.page = parameters.page;73 this.viewport = parameters.viewport;74 this.linkService = parameters.linkService;75 this.downloadManager = parameters.downloadManager;76 this.imageResourcesPath = parameters.imageResourcesPath;77 this.renderInteractiveForms = parameters.renderInteractiveForms;78 if (isRenderable) {79 this.container = this._createContainer(ignoreBorder);80 }81 }82 AnnotationElement.prototype = {83 _createContainer: function AnnotationElement_createContainer(ignoreBorder) {84 var data = this.data,85 page = this.page,86 viewport = this.viewport;87 var container = document.createElement('section');88 var width = data.rect[2] - data.rect[0];89 var height = data.rect[3] - data.rect[1];90 container.setAttribute('data-annotation-id', data.id);91 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]]);92 _dom_utils.CustomStyle.setProp('transform', container, 'matrix(' + viewport.transform.join(',') + ')');93 _dom_utils.CustomStyle.setProp('transformOrigin', container, -rect[0] + 'px ' + -rect[1] + 'px');94 if (!ignoreBorder && data.borderStyle.width > 0) {95 container.style.borderWidth = data.borderStyle.width + 'px';96 if (data.borderStyle.style !== _util.AnnotationBorderStyleType.UNDERLINE) {97 width = width - 2 * data.borderStyle.width;98 height = height - 2 * data.borderStyle.width;99 }100 var horizontalRadius = data.borderStyle.horizontalCornerRadius;101 var verticalRadius = data.borderStyle.verticalCornerRadius;102 if (horizontalRadius > 0 || verticalRadius > 0) {103 var radius = horizontalRadius + 'px / ' + verticalRadius + 'px';104 _dom_utils.CustomStyle.setProp('borderRadius', container, radius);105 }106 switch (data.borderStyle.style) {107 case _util.AnnotationBorderStyleType.SOLID:108 container.style.borderStyle = 'solid';109 break;110 case _util.AnnotationBorderStyleType.DASHED:111 container.style.borderStyle = 'dashed';112 break;113 case _util.AnnotationBorderStyleType.BEVELED:114 (0, _util.warn)('Unimplemented border style: beveled');115 break;116 case _util.AnnotationBorderStyleType.INSET:117 (0, _util.warn)('Unimplemented border style: inset');118 break;119 case _util.AnnotationBorderStyleType.UNDERLINE:120 container.style.borderBottomStyle = 'solid';121 break;122 default:123 break;124 }125 if (data.color) {126 container.style.borderColor = _util.Util.makeCssRgb(data.color[0] | 0, data.color[1] | 0, data.color[2] | 0);127 } else {128 container.style.borderWidth = 0;129 }130 }131 container.style.left = rect[0] + 'px';132 container.style.top = rect[1] + 'px';133 container.style.width = width + 'px';134 container.style.height = height + 'px';135 return container;136 },137 _createPopup: function AnnotationElement_createPopup(container, trigger, data) {138 if (!trigger) {139 trigger = document.createElement('div');140 trigger.style.height = container.style.height;141 trigger.style.width = container.style.width;142 container.appendChild(trigger);143 }144 var popupElement = new PopupElement({145 container: container,146 trigger: trigger,147 color: data.color,148 title: data.title,149 contents: data.contents,150 hideWrapper: true151 });152 var popup = popupElement.render();153 popup.style.left = container.style.width;154 container.appendChild(popup);155 },156 render: function AnnotationElement_render() {157 throw new Error('Abstract method AnnotationElement.render called');158 }159 };160 return AnnotationElement;161}();162var LinkAnnotationElement = function LinkAnnotationElementClosure() {163 function LinkAnnotationElement(parameters) {164 AnnotationElement.call(this, parameters, true);165 }166 _util.Util.inherit(LinkAnnotationElement, AnnotationElement, {167 render: function LinkAnnotationElement_render() {168 this.container.className = 'linkAnnotation';169 var link = document.createElement('a');170 (0, _dom_utils.addLinkAttributes)(link, {171 url: this.data.url,172 target: this.data.newWindow ? _dom_utils.LinkTarget.BLANK : undefined173 });174 if (!this.data.url) {175 if (this.data.action) {176 this._bindNamedAction(link, this.data.action);177 } else {178 this._bindLink(link, this.data.dest);179 }180 }181 this.container.appendChild(link);182 return this.container;183 },184 _bindLink: function _bindLink(link, destination) {185 var _this = this;186 link.href = this.linkService.getDestinationHash(destination);187 link.onclick = function () {188 if (destination) {189 _this.linkService.navigateTo(destination);190 }191 return false;192 };193 if (destination) {194 link.className = 'internalLink';195 }196 },197 _bindNamedAction: function _bindNamedAction(link, action) {198 var _this2 = this;199 link.href = this.linkService.getAnchorUrl('');200 link.onclick = function () {201 _this2.linkService.executeNamedAction(action);202 return false;203 };204 link.className = 'internalLink';205 }206 });207 return LinkAnnotationElement;208}();209var TextAnnotationElement = function TextAnnotationElementClosure() {210 function TextAnnotationElement(parameters) {211 var isRenderable = !!(parameters.data.hasPopup || parameters.data.title || parameters.data.contents);212 AnnotationElement.call(this, parameters, isRenderable);213 }214 _util.Util.inherit(TextAnnotationElement, AnnotationElement, {215 render: function TextAnnotationElement_render() {216 this.container.className = 'textAnnotation';217 var image = document.createElement('img');218 image.style.height = this.container.style.height;219 image.style.width = this.container.style.width;220 image.src = this.imageResourcesPath + 'annotation-' + this.data.name.toLowerCase() + '.svg';221 image.alt = '[{{type}} Annotation]';222 image.dataset.l10nId = 'text_annotation_type';223 image.dataset.l10nArgs = JSON.stringify({ type: this.data.name });224 if (!this.data.hasPopup) {225 this._createPopup(this.container, image, this.data);226 }227 this.container.appendChild(image);228 return this.container;229 }230 });231 return TextAnnotationElement;232}();233var WidgetAnnotationElement = function WidgetAnnotationElementClosure() {234 function WidgetAnnotationElement(parameters, isRenderable) {235 AnnotationElement.call(this, parameters, isRenderable);236 }237 _util.Util.inherit(WidgetAnnotationElement, AnnotationElement, {238 render: function WidgetAnnotationElement_render() {239 return this.container;240 }241 });242 return WidgetAnnotationElement;243}();244var TextWidgetAnnotationElement = function TextWidgetAnnotationElementClosure() {245 var TEXT_ALIGNMENT = ['left', 'center', 'right'];246 function TextWidgetAnnotationElement(parameters) {247 var isRenderable = parameters.renderInteractiveForms || !parameters.data.hasAppearance && !!parameters.data.fieldValue;248 WidgetAnnotationElement.call(this, parameters, isRenderable);249 }250 _util.Util.inherit(TextWidgetAnnotationElement, WidgetAnnotationElement, {251 render: function TextWidgetAnnotationElement_render() {252 this.container.className = 'textWidgetAnnotation';253 var element = null;254 if (this.renderInteractiveForms) {255 if (this.data.multiLine) {256 element = document.createElement('textarea');257 element.textContent = this.data.fieldValue;258 } else {259 element = document.createElement('input');260 element.type = 'text';261 element.setAttribute('value', this.data.fieldValue);262 }263 element.disabled = this.data.readOnly;264 if (this.data.maxLen !== null) {265 element.maxLength = this.data.maxLen;266 }267 if (this.data.comb) {268 var fieldWidth = this.data.rect[2] - this.data.rect[0];269 var combWidth = fieldWidth / this.data.maxLen;270 element.classList.add('comb');271 element.style.letterSpacing = 'calc(' + combWidth + 'px - 1ch)';272 }273 } else {274 element = document.createElement('div');275 element.textContent = this.data.fieldValue;276 element.style.verticalAlign = 'middle';277 element.style.display = 'table-cell';278 var font = null;279 if (this.data.fontRefName) {280 font = this.page.commonObjs.getData(this.data.fontRefName);281 }282 this._setTextStyle(element, font);283 }284 if (this.data.textAlignment !== null) {285 element.style.textAlign = TEXT_ALIGNMENT[this.data.textAlignment];286 }287 this.container.appendChild(element);288 return this.container;289 },290 _setTextStyle: function TextWidgetAnnotationElement_setTextStyle(element, font) {291 var style = element.style;292 style.fontSize = this.data.fontSize + 'px';293 style.direction = this.data.fontDirection < 0 ? 'rtl' : 'ltr';294 if (!font) {295 return;296 }297 style.fontWeight = font.black ? font.bold ? '900' : 'bold' : font.bold ? 'bold' : 'normal';298 style.fontStyle = font.italic ? 'italic' : 'normal';299 var fontFamily = font.loadedName ? '"' + font.loadedName + '", ' : '';300 var fallbackName = font.fallbackName || 'Helvetica, sans-serif';301 style.fontFamily = fontFamily + fallbackName;302 }303 });304 return TextWidgetAnnotationElement;305}();306var CheckboxWidgetAnnotationElement = function CheckboxWidgetAnnotationElementClosure() {307 function CheckboxWidgetAnnotationElement(parameters) {308 WidgetAnnotationElement.call(this, parameters, parameters.renderInteractiveForms);309 }310 _util.Util.inherit(CheckboxWidgetAnnotationElement, WidgetAnnotationElement, {311 render: function CheckboxWidgetAnnotationElement_render() {312 this.container.className = 'buttonWidgetAnnotation checkBox';313 var element = document.createElement('input');314 element.disabled = this.data.readOnly;315 element.type = 'checkbox';316 if (this.data.fieldValue && this.data.fieldValue !== 'Off') {317 element.setAttribute('checked', true);318 }319 this.container.appendChild(element);320 return this.container;321 }322 });323 return CheckboxWidgetAnnotationElement;324}();325var RadioButtonWidgetAnnotationElement = function RadioButtonWidgetAnnotationElementClosure() {326 function RadioButtonWidgetAnnotationElement(parameters) {327 WidgetAnnotationElement.call(this, parameters, parameters.renderInteractiveForms);328 }329 _util.Util.inherit(RadioButtonWidgetAnnotationElement, WidgetAnnotationElement, {330 render: function RadioButtonWidgetAnnotationElement_render() {331 this.container.className = 'buttonWidgetAnnotation radioButton';332 var element = document.createElement('input');333 element.disabled = this.data.readOnly;334 element.type = 'radio';335 element.name = this.data.fieldName;336 if (this.data.fieldValue === this.data.buttonValue) {337 element.setAttribute('checked', true);338 }339 this.container.appendChild(element);340 return this.container;341 }342 });343 return RadioButtonWidgetAnnotationElement;344}();345var ChoiceWidgetAnnotationElement = function ChoiceWidgetAnnotationElementClosure() {346 function ChoiceWidgetAnnotationElement(parameters) {347 WidgetAnnotationElement.call(this, parameters, parameters.renderInteractiveForms);348 }349 _util.Util.inherit(ChoiceWidgetAnnotationElement, WidgetAnnotationElement, {350 render: function ChoiceWidgetAnnotationElement_render() {351 this.container.className = 'choiceWidgetAnnotation';352 var selectElement = document.createElement('select');353 selectElement.disabled = this.data.readOnly;354 if (!this.data.combo) {355 selectElement.size = this.data.options.length;356 if (this.data.multiSelect) {357 selectElement.multiple = true;358 }359 }360 for (var i = 0, ii = this.data.options.length; i < ii; i++) {...
Using AI Code Generation
1function test() {2 var div = document.createElement('div');3 div.id = 'test';4 document.body.appendChild(div);5 var widget = new WidgetAnnotationElement({6 data: {7 defaultAppearanceData: {8 },9 },10 layer: {},11 page: {},12 viewport: {},13 linkService: {},14 });15 widget.appendTo(div);16 widget.render();17}18function test() {19 var pdfManager = {20 ensure: function (obj, prop, args) {21 return Promise.resolve();22 },23 };24 var xref = {};25 var handler = new ChunkedStreamManager();26 var task = new WorkerTask('test');
Using AI Code Generation
1var widgetAnnotationElement = new WidgetAnnotationElement({2});3var widgetAnnotationElement = new WidgetAnnotationElement({4});5var widgetAnnotationElement = new WidgetAnnotationElement({6});7var widgetAnnotationElement = new WidgetAnnotationElement({8});9var textAnnotationElement = new TextAnnotationElement({10});11var textAnnotationElement = new TextAnnotationElement({12});13var linkAnnotationElement = new LinkAnnotationElement({14});15var linkAnnotationElement = new LinkAnnotationElement({16});17var popupAnnotationElement = new PopupAnnotationElement({18});19var popupAnnotationElement = new PopupAnnotationElement({20});
Using AI Code Generation
1var widgetAnnotationElement = new WidgetAnnotationElement();2var annotation = widgetAnnotationElement.getAnnotation();3var rect = widgetAnnotationElement.getRect();4var container = widgetAnnotationElement.getContainer();5var data = widgetAnnotationElement.getData();6var content = widgetAnnotationElement.getContent();7var page = widgetAnnotationElement.getPage();8var layer = widgetAnnotationElement.getLayer();9var transform = widgetAnnotationElement.getTransform();10var borderWidth = widgetAnnotationElement.getBorderWidth();11var hasAppearance = widgetAnnotationElement.hasAppearance();12var loadResources = widgetAnnotationElement.loadResources();13var render = widgetAnnotationElement.render();14var hide = widgetAnnotationElement.hide();15var show = widgetAnnotationElement.show();16var getOperatorList = widgetAnnotationElement.getOperatorList();17var getBounds = widgetAnnotationElement.getBounds();18var save = widgetAnnotationElement.save();19var getClassName = widgetAnnotationElement.getClassName();20var getFieldObjects = widgetAnnotationElement.getFieldObjects();21var getInheritableProperty = widgetAnnotationElement.getInheritableProperty();22var getInheritablePropertyFromParent = widgetAnnotationElement.getInheritablePropertyFromParent();23var getInheritablePropertyFromField = widgetAnnotationElement.getInheritablePropertyFromField();24var getInheritablePropertyFromWidget = widgetAnnotationElement.getInheritablePropertyFromWidget();25var getInheritablePropertyFromAnnotation = widgetAnnotationElement.getInheritablePropertyFromAnnotation();26var getInheritablePropertyFromDict = widgetAnnotationElement.getInheritablePropertyFromDict();27var getInheritablePropertyFromDicts = widgetAnnotationElement.getInheritablePropertyFromDicts();28var getInheritablePropertyFromParentDicts = widgetAnnotationElement.getInheritablePropertyFromParentDicts();29var getInheritablePropertyFromFieldDicts = widgetAnnotationElement.getInheritablePropertyFromFieldDicts();30var getInheritablePropertyFromWidgetDicts = widgetAnnotationElement.getInheritablePropertyFromWidgetDicts();31var getInheritablePropertyFromAnnotationDicts = widgetAnnotationElement.getInheritablePropertyFromAnnotationDicts();32var getInheritablePropertyFromDictsAndParentDicts = widgetAnnotationElement.getInheritablePropertyFromDictsAndParentDicts();33var getInheritablePropertyFromDictsAndFieldDicts = widgetAnnotationElement.getInheritablePropertyFromDictsAndFieldDicts();34var getInheritablePropertyFromDictsAndWidgetDicts = widgetAnnotationElement.getInheritablePropertyFromDictsAndWidgetDicts();
Using AI Code Generation
1function testWidgetAnnotationElement() {2 var element = new WidgetAnnotationElement();3 var result = element.test();4 console.log(result);5 return result;6}7function testWidgetAnnotationElement() {8 var element = new WidgetAnnotationElement();9 var result = element.test();10 console.log(result);11 return result;12}13function testWidgetAnnotationElement() {14 var element = new WidgetAnnotationElement();15 var result = element.test();16 console.log(result);17 return result;18}19function testWidgetAnnotationElement() {20 var element = new WidgetAnnotationElement();21 var result = element.test();22 console.log(result);23 return result;24}25function testWidgetAnnotationElement() {26 var element = new WidgetAnnotationElement();27 var result = element.test();28 console.log(result);29 return result;30}31function testWidgetAnnotationElement() {32 var element = new WidgetAnnotationElement();33 var result = element.test();34 console.log(result);35 return result;36}37function testWidgetAnnotationElement() {38 var element = new WidgetAnnotationElement();39 var result = element.test();40 console.log(result);41 return result;42}43function testWidgetAnnotationElement() {44 var element = new WidgetAnnotationElement();45 var result = element.test();46 console.log(result);47 return result;48}49function testWidgetAnnotationElement() {50 var element = new WidgetAnnotationElement();51 var result = element.test();52 console.log(result);53 return result;54}55function testWidgetAnnotationElement() {56 var element = new WidgetAnnotationElement();57 var result = element.test();58 console.log(result);59 return result;60}61function testWidgetAnnotationElement() {62 var element = new WidgetAnnotationElement();63 var result = element.test();64 console.log(result);65 return result;66}
Using AI Code Generation
1var wpt = require('wpt');2var wae = new wpt.WidgetAnnotationElement();3var params = {4};5var result = wae.add(params);6console.log(result);7 var wae = new wpt.WidgetAnnotationElement();8 var params = {9 };10 var result = wae.add(params);11 console.log(result);
Using AI Code Generation
1var webDriver = require('wptdriver');2build();3driver.findElement(webDriver.By.id('lst-ib')).sendKeys('webdriver');4driver.findElement(webDriver.By.name('btnG')).click();5driver.wait(function() {6return driver.getTitle().then(function(title) {7return title === 'webdriver - Google Search';8});9}, 1000);10driver.findElement(webDriver.By.id('lst-ib')).sendKeys('webdriver');11driver.findElement(webDriver.By.name('btnG')).click();12driver.wait(function() {13return driver.getTitle().then(function(title) {14return title === 'webdriver - Google Search';15});16}, 1000);17driver.findElement(webDriver.By.id('lst-ib')).sendKeys('webdriver');18driver.findElement(webDriver.By.name('btnG')).click();19driver.wait(function() {20return driver.getTitle().then(function(title) {21return title === 'webdriver - Google Search';22});23}, 1000);24driver.findElement(webDriver.By.id('lst-ib')).sendKeys('webdriver');25driver.findElement(webDriver.By.name('btnG')).click();26driver.wait(function() {27return driver.getTitle().then(function(title) {28return title === 'webdriver - Google Search';29});30}, 1000);31driver.findElement(webDriver.By.id('lst-ib')).sendKeys('webdriver');32driver.findElement(webDriver.By.name('btnG')).click();33driver.wait(function() {34return driver.getTitle().then(function(title) {35return title === 'webdriver - Google Search';36});37}, 1000);38driver.findElement(webDriver.By.id('lst-ib')).sendKeys('webdriver');39driver.findElement(webDriver.By.name('btnG')).click();40driver.wait(function() {41return driver.getTitle().then(function(title) {42return title === 'webdriver - Google Search';43});44}, 1000);45driver.findElement(webDriver.By.id('lst-ib')).sendKeys('webdriver');46driver.findElement(webDriver.By.name('btnG')).click();47driver.wait(function() {48return driver.getTitle().then(function(title) {49return title === 'webdriver - Google Search';50});51}, 1000);52driver.findElement(webDriver.By.id('lst-ib')).sendKeys('webdriver');53driver.findElement(webDriver.By.name('btnG')).click();54driver.wait(function() {55return driver.getTitle().then(function(title) {
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!