How to use contentBounds method in wpt

Best JavaScript code snippet using wpt

viewport.js

Source:viewport.js Github

copy

Full Screen

1/**2 * 3 * Copyright (c) 2018 - present, byteAgenten GmbH, Germany. All rights reserved.4 * 5 * This source code is licensed under the MIT license found in the6 * LICENSE file in the root directory of this source tree.7 */8var _ = require('iag/client/util/language-utils');9var Util = require('iag/client/util/util');10var MIN_ZOOM_FACTOR = 0.01;11var MAX_ZOOM_FACTOR = 99.99;12function sanitizeZoomLevel(level) {13 return Math.max(MIN_ZOOM_FACTOR, Math.min(MAX_ZOOM_FACTOR, level));14}15var InitialState = {16 x: 0,17 y: 0,18 width: 0,19 height: 0,20 zoomLevel: 1,21 viewBounds: null,22 contentBounds: null23};24var ViewportProto = {25 get center() {26 return {27 x: this.contentBounds.x + (this.contentBounds.width / 2),28 y: this.contentBounds.y + (this.contentBounds.height / 2)29 };30 },31 change: function (state) {32 return Viewport.of(this, state);33 },34 resize: function () {35 return this.change({36 width: this.viewBounds.width / this.zoomLevel,37 height: this.viewBounds.height / this.zoomLevel38 });39 },40 moveBy: function (dx, dy) {41 return this.change({42 x: this.x + dx,43 y: this.y + dy44 });45 },46 centerAt: function (x, y) {47 return this.change({48 x: x - (this.width / 2),49 y: y - (this.height / 2)50 });51 },52 zoomTo: function (zoomLevel, target) {53 zoomLevel = sanitizeZoomLevel(zoomLevel);54 target = target || { x: this.x + (this.width / 2), y: this.y + (this.height / 2) };55 var viewBounds = this.viewBounds;56 var width = viewBounds.width / zoomLevel;57 var height = viewBounds.height / zoomLevel;58 var x = this.x - ((width - this.width) * ((target.x - this.x) / this.width));59 var y = this.y - ((height - this.height) * ((target.y - this.y) / this.height));60 return this.change({61 zoomLevel: zoomLevel,62 x: x,63 y: y,64 width: width,65 height: height66 });67 },68 zoomIn: function (factor, target) {69 return this.zoomTo(this.zoomLevel * factor, target);70 },71 zoomOut: function (factor, target) {72 return this.zoomTo(this.zoomLevel / factor, target);73 },74 zoomToFit: function (padding) {75 padding = padding || 0;76 var contentBounds = this.contentBounds;77 var viewBounds = this.viewBounds;78 var xRatio = viewBounds.width / (contentBounds.width + padding);79 var yRatio = viewBounds.height / (contentBounds.height + padding);80 var zoomLevel = Math.min(xRatio, yRatio);81 var center = this.center;82 return this.zoomTo(zoomLevel).centerAt(center.x, center.y);83 },84 zoomToOriginal: function () {85 var center = this.center;86 return this.zoomTo(1).centerAt(center.x, center.y);87 },88 zoomToElements: function (elements, padding) {89 var bounds = Util.getCombinedElementsBoundingBox(elements, padding);90 return this.setBounds(bounds);91 },92 setBounds: function (bounds) {93 var viewBounds = this.viewBounds;94 // Adjust the side with the higher zoom factor to preserve the current aspect ratio95 var horizontalZoom = viewBounds.width / bounds.width;96 var verticalZoom = viewBounds.height / bounds.height;97 var zoomLevel = sanitizeZoomLevel(Math.min(horizontalZoom, verticalZoom));98 var width = viewBounds.width / zoomLevel;99 var x = bounds.x - ((width - bounds.width) / 2);100 var height = viewBounds.height / zoomLevel;101 var y = bounds.y - ((height - bounds.height) / 2);102 return this.change({103 zoomLevel: zoomLevel,104 x: x,105 y: y,106 width: width,107 height: height108 });109 },110 sanitize: function () {111 var contentBounds = this.contentBounds;112 // Prevent moving out of content bounds113 var x = this.x;114 var y = this.y;115 x = Math.max(contentBounds.x - (this.width / 2), x);116 x = Math.min(contentBounds.x2 - (this.width / 2), x);117 y = Math.max(contentBounds.y - (this.height / 2), y);118 y = Math.min(contentBounds.y2 - (this.height / 2), y);119 return this.change({120 x: x,121 y: y122 });123 },124 toPx: function (point) {125 return {126 x: point.x * this.zoomLevel,127 y: point.y * this.zoomLevel128 };129 },130 fromPx: function (point) {131 return {132 x: point.x / this.zoomLevel,133 y: point.y / this.zoomLevel134 };135 }136};137function Viewport(state) {138 return _.assign(Object.create(ViewportProto), state || InitialState);139}140_.assign(Viewport, {141 of: function (viewport, state) {142 return Viewport(_.assign({}, viewport, state));143 }144});...

Full Screen

Full Screen

main.js

Source:main.js Github

copy

Full Screen

1// Modules to control application life and create native browser window and view2const { app, BrowserView, BrowserWindow } = require('electron')3const path = require('path')4const {ipcMain} = require('electron');5// This method will be called when Electron has finished6// initialization and is ready to create browser windows.7// Some APIs can only be used after this event occurs.8app.whenReady().then(() => {9 ipcMain.on('set-title', handleSetTitle)10 const win = new BrowserWindow({ 11 width: 1000, 12 height: 850,13 webPreferences: {14 preload: path.join(__dirname, 'preload.js')15 }16 })17 18 ////////////////////////////19 //Views/////////////////////20 ////////////////////////////21 const viewo = new BrowserView()22 const viewp = new BrowserView()23 const viewg = new BrowserView()24 const viewl = new BrowserView()25 26 function handleSetTitle (event, title) {27 var webContents = title28 29 var win = BrowserWindow.getFocusedWindow()30 if (webContents == "mytroy") {31 32 33 var contentBounds = win.getContentBounds()34 var widthsubtract = contentBounds.width - 144;35 win.setBrowserView(viewo)36 viewo.setBounds({ x: 144, y: 0, width: widthsubtract, height: contentBounds.height })37 viewo.webContents.loadURL('https://my.troy.edu/')38 39 40 }41 if (webContents == "office"){42 43 44 var contentBounds = win.getContentBounds()45 var widthsubtract = contentBounds.width - 144;46 47 win.setBrowserView(viewp)48 viewp.setBounds({ x: 144, y: 0, width: widthsubtract, height: contentBounds.height })49 viewp.webContents.loadURL('https://my.troy.edu/go/mail/')50 }51 if (webContents == "canvas") {52 53 54 var contentBounds = win.getContentBounds()55 var widthsubtract = contentBounds.width - 144;56 win.setBrowserView(viewg)57 viewg.setBounds({ x: 144, y: 0, width: widthsubtract, height: contentBounds.height })58 viewg.webContents.loadURL('https://my.troy.edu/go/canvas/')59 }60 if (webContents == "library") {61 62 63 var contentBounds = win.getContentBounds()64 var widthsubtract = contentBounds.width - 144;65 win.setBrowserView(viewl)66 viewl.setBounds({ x: 144, y: 0, width: widthsubtract, height: contentBounds.height })67 viewl.webContents.loadURL('https://my.troy.edu/libraries/')68 }69 70 ////////////////////////////71 //TABS//////////////////////72 ////////////////////////////73 if (webContents == "btnt1") {74 win.setBrowserView(viewo);75 var contentBounds = win.getContentBounds()76 var widthsubtract = contentBounds.width - 144;77 viewo.setBounds({ x: 144, y: 0, width: widthsubtract, height: contentBounds.height })78 }79 80 if (webContents == "btnt") {81 win.setBrowserView(viewp);82 var contentBounds = win.getContentBounds()83 var widthsubtract = contentBounds.width - 144;84 viewp.setBounds({ x: 144, y: 0, width: widthsubtract, height: contentBounds.height })85 }86 87 if (webContents == "btnt2"){88 win.setBrowserView(viewg);89 var contentBounds = win.getContentBounds()90 var widthsubtract = contentBounds.width - 144;91 viewg.setBounds({ x: 144, y: 0, width: widthsubtract, height: contentBounds.height })92 }93 if (webContents == "libtab"){94 win.setBrowserView(viewl);95 var contentBounds = win.getContentBounds()96 var widthsubtract = contentBounds.width - 144;97 viewl.setBounds({ x: 144, y: 0, width: widthsubtract, height: contentBounds.height })98 }99 }100 101 win.removeMenu(true)102 win.loadFile('frontpage.html')103 104 app.on('activate', function () {105 // On macOS it's common to re-create a window in the app when the106 // dock icon is clicked and there are no other windows open.107 if (BrowserWindow.getAllWindows().length === 0) createWindow()108 })109})110// Quit when all windows are closed, except on macOS. There, it's common111// for applications and their menu bar to stay active until the user quits112// explicitly with Cmd + Q.113app.on('window-all-closed', function () {114 if (process.platform !== 'darwin') app.quit()115})116//Gets the event title and depending on the title load certain URL's.117//Gets the event title and depending on the title load certain URL's.118// In this file you can include the rest of your app's specific main process...

Full Screen

Full Screen

preview.es6

Source:preview.es6 Github

copy

Full Screen

1'use strict';2import {asArray} from 'widjet-utils';3export default class PreviewElement extends HTMLElement {4 get margins() {5 return this.hasAttribute('margins')6 ? this.parseMargins(this.getAttribute('margins'))7 : [0, 0, 0, 0];8 }9 constructor(options = {}) {10 super();11 if (options.margins) {12 this.setAttribute('margins', options.margins.join(' '));13 }14 }15 connectedCallback() {16 requestAnimationFrame(() => {17 const containerBounds = this.getBoundingClientRect();18 let contentBounds = {};19 asArray(this.children).forEach(n => {20 const bounds = n.getBoundingClientRect();21 contentBounds.left = contentBounds.left22 ? Math.min(bounds.left, contentBounds.left)23 : bounds.left;24 contentBounds.top = contentBounds.top25 ? Math.min(bounds.top, contentBounds.top)26 : bounds.top;27 contentBounds.right = contentBounds.right28 ? Math.max(bounds.right, contentBounds.right)29 : bounds.right;30 contentBounds.bottom = contentBounds.bottom31 ? Math.max(bounds.bottom, contentBounds.bottom)32 : bounds.bottom;33 });34 const margins = this.margins;35 const viewport = [36 0 - margins[3],37 0 - margins[0],38 (contentBounds.right - containerBounds.left) + (margins[1] + margins[3]),39 (contentBounds.bottom - containerBounds.top) + (margins[0] + margins[2]),40 ];41 const content = this.innerHTML;42 this.innerHTML = `43 <svg viewBox="${viewport.join(' ')}">44 <foreignObject x="0" y="0" width="${viewport[2]}" height="${viewport[3]}">45 <body xmlns="http://www.w3.org/1999/xhtml">${content}</body>46 </foreignObject>47 </svg>48 `;49 });50 }51 parseMargins(string) {52 const values = string.split(' ').map(n => parseInt(n, 10));53 switch (values.length) {54 case 1: return new Array(4).fill(values[0]);55 case 2: return [values[0], values[1], values[0], values[1]];56 case 3: return [values[0], values[1], values[2], values[1]];57 case 4: return values;58 default: return [0, 0, 0, 0];59 }60 }61}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var page = require('webpage').create();2var system = require('system');3var url = system.args[1];4var res = system.args[2];5page.open(url, function(status) {6 if (status !== 'success') {7 console.log('Unable to access network');8 } else {9 var clipRect = page.evaluate(function() {10 return document.querySelector('body').getBoundingClientRect();11 });12 page.clipRect = {13 };14 page.render(res);15 }16 phantom.exit();17});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3var page = wptools.page('Albert Einstein');4page.contentBounds(function(err, bounds) {5 console.log(bounds);6 fs.writeFile('bounds.json', JSON.stringify(bounds), function(err){7 if(err) {8 console.log(err);9 } else {10 console.log('The file was saved!');11 }12 });13});

Full Screen

Using AI Code Generation

copy

Full Screen

1var button = document.querySelector('wptb-element-button');2var contentBounds = button.contentBounds;3console.log(contentBounds);4### `contentBounds() => Promise<ContentBounds>`5### `setButtonColor(color: string) => Promise<void>`6### `setButtonFontSize(fontSize: number) => Promise<void>`7### `setButtonPadding(padding: number) => Promise<void>`8### `setButtonText(text: string) => Promise<void>`9### `setTextColor(color: string) => Promise<void>`10### `setTextFontFamily(fontFamily: string) => Promise<void>`11### `setTextFontStyle(fontStyle: string) => Promise<void>`12### `setTextFontWeight(fontWeight: string) => Promise<void>`13### `setTextTextAlign(textAlign: string) => Promise<void>`14### `setTextTextDecoration(textDecoration: string) => Promise<void>`15### `setTextTextTransform(textTransform: string) => Promise<void>`

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptDriver = require('wpt-driver');2wptDriver.init({browser: 'chrome'});3 if (err) {4 console.log(err);5 } else {6 wptDriver.contentBounds(function(err, bounds) {7 console.log(bounds);8 });9 }10});11var wptDriver = require('wpt-driver');12wptDriver.init({browser: 'chrome'});13 if (err) {14 console.log(err);15 } else {16 wptDriver.contentSize(function(err, size) {17 console.log(size);18 });19 }20});21var wptDriver = require('wpt-driver');22wptDriver.init({browser: 'chrome'});23 if (err) {24 console.log(err);25 } else {26 wptDriver.cookies(function(err, cookies) {27 console.log(cookies);28 });29 }30});31var wptDriver = require('wpt-driver');32wptDriver.init({browser: 'chrome'});33wptDriver.deleteAllCookies(function(err) {34 if (err) {35 console.log(err);36 }37});38var wptDriver = require('wpt-driver');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wptoolkit');2var doc = app.activeDocument;3var selectedLayer = doc.activeLayer;4var bounds = wpt.contentBounds(selectedLayer);5$.writeln('contentBounds: ' + bounds);6var wpt = require('wptoolkit');7var doc = app.activeDocument;8var selectedLayer = doc.activeLayer;9var bounds = wpt.contentBounds(selectedLayer);10$.writeln('contentBounds: ' + bounds);11var wpt = require('wptoolkit');12var doc = app.activeDocument;13var selectedLayer = doc.activeLayer;14var bounds = wpt.contentBounds(selectedLayer);15$.writeln('contentBounds: ' + bounds);16var wpt = require('wptoolkit');17var doc = app.activeDocument;18var selectedLayer = doc.activeLayer;19var bounds = wpt.contentBounds(selectedLayer);20$.writeln('contentBounds: ' + bounds);

Full Screen

Using AI Code Generation

copy

Full Screen

1var doc = app.activeDocument;2var bounds = doc.contentBounds;3app.activeDocument.selection[0].geometricBounds = bounds;4var doc = app.activeDocument;5var bounds = doc.contentBounds;6app.activeDocument.selection[0].geometricBounds = bounds;7var doc = app.activeDocument;8var bounds = doc.contentBounds;9app.activeDocument.selection[0].geometricBounds = bounds;10var doc = app.activeDocument;11var bounds = doc.contentBounds;12app.activeDocument.selection[0].geometricBounds = bounds;13var doc = app.activeDocument;14var bounds = doc.contentBounds;15app.activeDocument.selection[0].geometricBounds = bounds;

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