How to use rotationRegExp method in wpt

Best JavaScript code snippet using wpt

testcommon.js

Source:testcommon.js Github

copy

Full Screen

1/*2Distributed under both the W3C Test Suite License [1] and the W3C33-clause BSD License [2]. To contribute to a W3C Test Suite, see the4policies and contribution forms [3].5[1] http://www.w3.org/Consortium/Legal/2008/04-testsuite-license6[2] http://www.w3.org/Consortium/Legal/2008/03-bsd-license7[3] http://www.w3.org/2004/10/27-testcases8 */9'use strict';10const MS_PER_SEC = 1000;11// The recommended minimum precision to use for time values[1].12//13// [1] https://drafts.csswg.org/web-animations/#precision-of-time-values14const TIME_PRECISION = 0.0005; // ms15// Allow implementations to substitute an alternative method for comparing16// times based on their precision requirements.17if (!window.assert_times_equal) {18 window.assert_times_equal = (actual, expected, description) => {19 assert_approx_equals(actual, expected, TIME_PRECISION * 2, description);20 };21}22// Allow implementations to substitute an alternative method for comparing23// a time value based on its precision requirements with a fixed value.24if (!window.assert_time_equals_literal) {25 window.assert_time_equals_literal = (actual, expected, description) => {26 if (Math.abs(expected) === Infinity) {27 assert_equals(actual, expected, description);28 } else {29 assert_approx_equals(actual, expected, TIME_PRECISION, description);30 }31 }32}33// creates div element, appends it to the document body and34// removes the created element during test cleanup35function createDiv(test, doc) {36 return createElement(test, 'div', doc);37}38// creates element of given tagName, appends it to the document body and39// removes the created element during test cleanup40// if tagName is null or undefined, returns div element41function createElement(test, tagName, doc) {42 if (!doc) {43 doc = document;44 }45 const element = doc.createElement(tagName || 'div');46 doc.body.appendChild(element);47 test.add_cleanup(() => {48 element.remove();49 });50 return element;51}52// Creates a style element with the specified rules, appends it to the document53// head and removes the created element during test cleanup.54// |rules| is an object. For example:55// { '@keyframes anim': '' ,56// '.className': 'animation: anim 100s;' };57// or58// { '.className1::before': 'content: ""; width: 0px; transition: all 10s;',59// '.className2::before': 'width: 100px;' };60// The object property name could be a keyframes name, or a selector.61// The object property value is declarations which are property:value pairs62// split by a space.63function createStyle(test, rules, doc) {64 if (!doc) {65 doc = document;66 }67 const extraStyle = doc.createElement('style');68 doc.head.appendChild(extraStyle);69 if (rules) {70 const sheet = extraStyle.sheet;71 for (const selector in rules) {72 sheet.insertRule(`${selector}{${rules[selector]}}`,73 sheet.cssRules.length);74 }75 }76 test.add_cleanup(() => {77 extraStyle.remove();78 });79}80// Create a pseudo element81function getPseudoElement(test, type) {82 createStyle(test, { '@keyframes anim': '',83 [`.pseudo::${type}`]: 'animation: anim 10s; ' +84 'content: \'\';' });85 const div = createDiv(test);86 div.classList.add('pseudo');87 const anims = document.getAnimations();88 assert_true(anims.length >= 1);89 const anim = anims[anims.length - 1];90 anim.cancel();91 return anim.effect.target;92}93// Cubic bezier with control points (0, 0), (x1, y1), (x2, y2), and (1, 1).94function cubicBezier(x1, y1, x2, y2) {95 const xForT = t => {96 const omt = 1-t;97 return 3 * omt * omt * t * x1 + 3 * omt * t * t * x2 + t * t * t;98 };99 const yForT = t => {100 const omt = 1-t;101 return 3 * omt * omt * t * y1 + 3 * omt * t * t * y2 + t * t * t;102 };103 const tForX = x => {104 // Binary subdivision.105 let mint = 0, maxt = 1;106 for (let i = 0; i < 30; ++i) {107 const guesst = (mint + maxt) / 2;108 const guessx = xForT(guesst);109 if (x < guessx) {110 maxt = guesst;111 } else {112 mint = guesst;113 }114 }115 return (mint + maxt) / 2;116 };117 return x => {118 if (x == 0) {119 return 0;120 }121 if (x == 1) {122 return 1;123 }124 return yForT(tForX(x));125 };126}127function stepEnd(nsteps) {128 return x => Math.floor(x * nsteps) / nsteps;129}130function stepStart(nsteps) {131 return x => {132 const result = Math.floor(x * nsteps + 1.0) / nsteps;133 return (result > 1.0) ? 1.0 : result;134 };135}136function framesTiming(nframes) {137 return x => {138 const result = Math.floor(x * nframes) / (nframes - 1);139 return (result > 1.0 && x <= 1.0) ? 1.0 : result;140 };141}142function waitForAnimationFrames(frameCount) {143 return new Promise(resolve => {144 function handleFrame() {145 if (--frameCount <= 0) {146 resolve();147 } else {148 window.requestAnimationFrame(handleFrame); // wait another frame149 }150 }151 window.requestAnimationFrame(handleFrame);152 });153}154// Continually calls requestAnimationFrame until |minDelay| has elapsed155// as recorded using document.timeline.currentTime (i.e. frame time not156// wall-clock time).157function waitForAnimationFramesWithDelay(minDelay) {158 const startTime = document.timeline.currentTime;159 return new Promise(resolve => {160 (function handleFrame() {161 if (document.timeline.currentTime - startTime >= minDelay) {162 resolve();163 } else {164 window.requestAnimationFrame(handleFrame);165 }166 }());167 });168}169// Waits for a requestAnimationFrame callback in the next refresh driver tick.170function waitForNextFrame() {171 const timeAtStart = document.timeline.currentTime;172 return new Promise(resolve => {173 window.requestAnimationFrame(() => {174 if (timeAtStart === document.timeline.currentTime) {175 window.requestAnimationFrame(resolve);176 } else {177 resolve();178 }179 });180 });181}182// Returns 'matrix()' or 'matrix3d()' function string generated from an array.183function createMatrixFromArray(array) {184 return (array.length == 16 ? 'matrix3d' : 'matrix') + `(${array.join()})`;185}186// Returns 'matrix3d()' function string equivalent to187// 'rotate3d(x, y, z, radian)'.188function rotate3dToMatrix3d(x, y, z, radian) {189 return createMatrixFromArray(rotate3dToMatrix(x, y, z, radian));190}191// Returns an array of the 4x4 matrix equivalent to 'rotate3d(x, y, z, radian)'.192// https://drafts.csswg.org/css-transforms-2/#Rotate3dDefined193function rotate3dToMatrix(x, y, z, radian) {194 const sc = Math.sin(radian / 2) * Math.cos(radian / 2);195 const sq = Math.sin(radian / 2) * Math.sin(radian / 2);196 // Normalize the vector.197 const length = Math.sqrt(x*x + y*y + z*z);198 x /= length;199 y /= length;200 z /= length;201 return [202 1 - 2 * (y*y + z*z) * sq,203 2 * (x * y * sq + z * sc),204 2 * (x * z * sq - y * sc),205 0,206 2 * (x * y * sq - z * sc),207 1 - 2 * (x*x + z*z) * sq,208 2 * (y * z * sq + x * sc),209 0,210 2 * (x * z * sq + y * sc),211 2 * (y * z * sq - x * sc),212 1 - 2 * (x*x + y*y) * sq,213 0,214 0,215 0,216 0,217 1218 ];219}220// Compare matrix string like 'matrix(1, 0, 0, 1, 100, 0)' with tolerances.221function assert_matrix_equals(actual, expected, description) {222 const matrixRegExp = /^matrix(?:3d)*\((.+)\)/;223 assert_regexp_match(actual, matrixRegExp,224 'Actual value is not a matrix')225 assert_regexp_match(expected, matrixRegExp,226 'Expected value is not a matrix');227 const actualMatrixArray =228 actual.match(matrixRegExp)[1].split(',').map(Number);229 const expectedMatrixArray =230 expected.match(matrixRegExp)[1].split(',').map(Number);231 assert_equals(actualMatrixArray.length, expectedMatrixArray.length,232 `dimension of the matrix: ${description}`);233 for (let i = 0; i < actualMatrixArray.length; i++) {234 assert_approx_equals(actualMatrixArray[i], expectedMatrixArray[i], 0.0001,235 `expected ${expected} but got ${actual}: ${description}`);236 }237}238// Compare rotate3d vector like '0 1 0 45deg' with tolerances.239function assert_rotate3d_equals(actual, expected, description) {240 const rotationRegExp =/^((([+-]?\d+(\.+\d+)?\s){3})?\d+(\.+\d+)?)deg/;241 assert_regexp_match(actual, rotationRegExp,242 'Actual value is not a rotate3d vector')243 assert_regexp_match(expected, rotationRegExp,244 'Expected value is not a rotate3d vector');245 const actualRotationVector =246 actual.match(rotationRegExp)[1].split(' ').map(Number);247 const expectedRotationVector =248 expected.match(rotationRegExp)[1].split(' ').map(Number);249 assert_equals(actualRotationVector.length, expectedRotationVector.length,250 `dimension of the matrix: ${description}`);251 for (let i = 0; i < actualRotationVector.length; i++) {252 assert_approx_equals(actualRotationVector[i], expectedRotationVector[i], 0.0001,253 `expected ${expected} but got ${actual}: ${description}`);254 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var page = wptools.page('Barack Obama');3page.get(function(err, resp) {4 console.log(resp.infobox.rotation);5 console.log(resp.infobox['rotation']);6 console.log(resp.infobox['rotation (degrees)']);7 console.log(resp.infobox['rotation (degrees)'].value);8 console.log(resp.infobox['rotation (degrees)'].text);9 console.log(resp.infobox['rotation (degrees)'].html);10 console.log(resp.infobox['rotation (degrees)'].html());11 console.log(resp.infobox['rotation (degrees)'].html({links: true}));12 console.log(resp.infobox['rotation (degrees)'].html({links: false}));13 console.log(resp.infobox['rotation (degrees)'].html({images: true}));14 console.log(resp.infobox['rotation (degrees)'].html({images: false}));15 console.log(resp.infobox['rotation (degrees)'].html({sections: true}));16 console.log(resp.infobox['rotation (degrees)'].html({sections: false}));17 console.log(resp.infobox['rotation (degrees)'].html({lists: true}));18 console.log(resp.infobox['rotation (degrees)'].html({lists: false}));19 console.log(resp.infobox['rotation (degrees)'].html({tables: true}));20 console.log(resp.infobox['rotation (degrees)'].html({tables: false}));21 console.log(resp.infobox['rotation (degrees)'].html({templates: true}));22 console.log(resp.infobox['rotation (degrees)'].html({templates: false}));23 console.log(resp.infobox['rotation (degrees)'].html({coordinates: true}));24 console.log(resp.infobox['rotation (degrees)'].html({coordinates: false}));25 console.log(resp.infobox['rotation (degrees)'].html({lang: 'en'}));26 console.log(resp.infobox['rotation (degrees)'].html({lang: 'es'}));27 console.log(resp.infobox['rotation (degrees)'].html({lang: 'fr'}));28 console.log(resp.infobox['rotation (degrees)'].html({lang: 'de'}));29 console.log(resp.infobox['rotation (degrees)'].html({lang: 'it'}));30 console.log(resp.infobox['rotation (degrees)'].html({lang: 'nl'}));

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptextpattern = require('wptextpattern');2var text = 'This is a test';3var pattern = wptextpattern.rotationRegExp('test', 3, 6);4console.log(pattern.exec(text));5console.log(pattern.exec(text));6console.log(pattern.exec(te

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var w = wptools.page('Adele');3w.get(function(err, resp) {4 console.log(w.rotationRegExp());5});6### wptools.getTemplate(template, callback)7var wptools = require('wptools');8var w = wptools.page('Adele');9w.get(function(err, resp) {10 console.log(w.getTemplate('Infobox musical artist'));11});12### wptools.getTemplateParam(template, param, callback)13var wptools = require('wptools');14var w = wptools.page('Adele');15w.get(function(err, resp) {16 console.log(w.getTemplateParam('Infobox musical artist', 'genre'));17});18### wptools.getTemplateParamValue(template, param, callback)19var wptools = require('wptools');20var w = wptools.page('Adele');21w.get(function(err, resp) {22 console.log(w.getTemplateParamValue('Infobox musical artist', 'genre'));23});24### wptools.getTemplateParamValues(template, param, callback)

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3fs.writeFile('rotationDates.csv', rotationDates, function(err) {4 if (err) throw err;5 console.log('Saved!');6});

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