Best JavaScript code snippet using wpt
index.js
Source:index.js
1import { isFunction } from "sapa";2import { CSS_TO_STRING, TAG_TO_STRING } from "elf/core/func";3import { uuid } from "elf/core/math";4const char_list = [/\(/gi, /\)/gi];5const function_list =6 "grayscale,matrix,rotateZ,blur,sepia,linear-gradient,radial-gradient,conic-gradient,circle,inset,polygon,rgb"7 .split(",")8 .map((it) => {9 return new RegExp(it, "gi");10 });11const keyword_list =12 "butt,miter,start,at,black,repeat,lighten,multiply,solid,border-box,visible,absolute,relative,auto"13 .split(",")14 .map((it) => {15 return new RegExp(it, "gi");16 });17function replaceKeyword(str) {18 keyword_list.forEach((ke) => {19 str = str.replace(ke, (str) => {20 return `<span class="keyword">${str}</span>`;21 });22 });23 function_list.forEach((ke) => {24 str = str.replace(ke, (str) => {25 return `<span class="function">${str}</span>`;26 });27 });28 char_list.forEach((ke) => {29 str = str.replace(ke, (str) => {30 return `<span class="char">${str}</span>`;31 });32 });33 return str;34}35function filterKeyName(str) {36 return str37 .split(";")38 .filter((it) => it.trim())39 .map((it) => {40 it = it.trim();41 var [key, value] = it.split(":").map((it) => it.trim());42 if (value === "") {43 return "";44 }45 return /*html*/ `<div class="block"><strong>${key}</strong><span>: </span><span class="value">${replaceKeyword(46 value47 )}</span><span>;</span></div>`;48 })49 .join("")50 .trim();51}52export default class HTMLRenderer {53 #id;54 #renderers = {};55 /**56 *57 * @param {Editor} editor58 */59 constructor(editor) {60 this.editor = editor;61 this.#id = uuid();62 }63 setRendererType(itemType, renderInstance) {64 renderInstance.setRenderer(this);65 this.#renderers[itemType] = renderInstance;66 }67 get id() {68 return this.#id;69 }70 getDefaultRendererInstance() {71 return this.#renderers["rect"];72 }73 getRendererInstance(item) {74 const currentRenderer =75 this.#renderers[item.itemType] ||76 this.editor.getRendererInstance("html", item.itemType) ||77 this.getDefaultRendererInstance() ||78 item;79 currentRenderer.setRenderer(this);80 return currentRenderer;81 }82 /**83 *84 * @param {BaseModel} item85 */86 render(item) {87 if (!item) return;88 const currentRenderer = this.getRendererInstance(item);89 if (currentRenderer) {90 return currentRenderer.render(item);91 }92 }93 renderSVG(item) {94 const currentRenderer = this.getRendererInstance(item);95 if (isFunction(currentRenderer.renderSVG)) {96 return currentRenderer.renderSVG(item);97 }98 return this.getDefaultRendererInstance().renderSVG(item);99 }100 to(type, item) {101 const currentRenderer = this.getRendererInstance(item);102 if (isFunction(currentRenderer[type])) {103 return currentRenderer[type].call(currentRenderer, item);104 }105 const defaultInstance = this.getDefaultRendererInstance();106 if (isFunction(defaultInstance[type])) {107 return defaultInstance[type].call(defaultInstance, item);108 }109 }110 /**111 * css ìì±ì 리í´í´ì¤ë¤.112 *113 * @param {BaseModel} item114 * @param {object} [omit={}] ì ê±°í íë ì ì©115 */116 toCSS(item, omit = {}) {117 const css = this.to("toCSS", item);118 Object.keys(omit).forEach((key) => {119 delete css[key];120 });121 return css;122 }123 toKeyframeCSS(item) {124 return this.to("toKeyframeCSS", item);125 }126 /**127 *128 * @param {BaseModel} item129 */130 toNestedCSS(item) {131 return this.to("toNestedCSS", item);132 }133 /**134 *135 * @param {BaseModel} item136 */137 toTransformCSS(item) {138 return this.to("toTransformCSS", item);139 }140 toGridLayoutCSS(item) {141 return this.to("toGridLayoutCSS", item);142 }143 toLayoutItemCSS(item) {144 return this.to("toLayoutItemCSS", item);145 }146 toLayoutBaseModelCSS(item) {147 return this.to("toLayoutBaseModelCSS", item);148 }149 /**150 *151 * ë ëë§ ë style í그를 리í´íë¤.152 *153 * @param {BaseModel} item154 */155 toStyle(item) {156 const currentRenderer = this.getRendererInstance(item);157 if (isFunction(currentRenderer.toStyle)) {158 return currentRenderer.toStyle(item);159 }160 return this.getDefaultRendererInstance().toStyle(item);161 }162 toStyleData(item) {163 const currentRenderer = this.getRendererInstance(item);164 if (isFunction(currentRenderer.toStyleData)) {165 return currentRenderer.toStyleData(item);166 }167 return this.getDefaultRendererInstance().toStyleData(item);168 }169 /**170 *171 * ë ëë§ ë style í그를 리í´íë¤.172 *173 * @param {BaseModel} item174 */175 toExportStyle(item) {176 const currentRenderer = this.getRendererInstance(item);177 if (isFunction(currentRenderer.toExportStyle)) {178 return currentRenderer.toExportStyle(item);179 }180 return this.getDefaultRendererInstance().toExportStyle(item);181 }182 /**183 *184 * @param {BaseModel} item185 * @param {Dom} currentElement186 */187 update(item, currentElement, editor) {188 const currentRenderer = this.getRendererInstance(item);189 if (isFunction(currentRenderer.update)) {190 return currentRenderer.update(item, currentElement, editor);191 }192 return this.getDefaultRendererInstance().update(193 item,194 currentElement,195 editor196 );197 }198 /**199 * ì½ë ë·°ì© HTML ì½ë를 ë ëë§ íë¤.200 * @param {BaseModel} item201 */202 codeview(item) {203 if (!item) {204 return "";205 }206 const currentProject = item.project;207 let rootVariable = currentProject208 ? CSS_TO_STRING(currentProject.toRootVariableCSS())209 : "";210 // let svgCode = this.renderSVG(currentProject);211 // svgCode = svgCode.replace(/\</g, '<').replace(/\>/g, '>')212 const current = item;213 const cssCode = filterKeyName(214 current ? TAG_TO_STRING(CSS_TO_STRING(this.toCSS(current))) : ""215 );216 const keyframeCode = this.toKeyframeCSS(current);217 const nestedCssCode = current218 ? this.toNestedCSS(current).map((it) => {219 var cssText = it.cssText ? it.cssText : CSS_TO_STRING(it.css);220 return `${it.selector} { 221 ${filterKeyName(TAG_TO_STRING(cssText), " ")}222 }`;223 })224 : [];225 // const selectorCode = current ? current.selectors : [];226 return /*html*/ `227<div >228${cssCode && /*html*/ `<div><pre title='CSS'>${cssCode}</pre></div>`}229${nestedCssCode230 .map((it) => {231 return /*html*/ `<div><pre title='CSS'>${it}</pre></div>`;232 })233 .join("")}234${235 keyframeCode &&236 /*html*/ `<div><pre title='Keyframe'>${keyframeCode}</pre></div>`237}238${239 rootVariable240 ? /*html*/ `<div>241 <label>:root</label>242 <pre>${rootVariable}</pre>243 </div>`244 : ""245}246</div>247 `;248 }...
CodeViewProperty.js
Source:CodeViewProperty.js
1import BaseProperty from "./BaseProperty";2import { LOAD, DEBOUNCE } from "../../../util/Event";3import { EVENT } from "../../../util/UIElement";4import { CSS_TO_STRING, TAG_TO_STRING } from "../../../util/functions/func";5export default class CodeViewProperty extends BaseProperty {6 getTitle() {7 return this.$i18n('code.view.property.title');8 }9 [EVENT(10 'refreshSelectionStyleView', 11 'refreshStyleView',12 'refreshSelection',13 'refreshSVGArea'14 ) + DEBOUNCE(100) ]() {15 this.refreshShowIsNot();16 }17 getBody() {18 return `19 <div class="property-item code-view-item" ref='$body'></div>20 `;21 }22 filterKeyName (str, prefixPadding = '') {23 return str.split(';').filter(it => it.trim()).map(it => {24 it = it.trim();25 var [key, value] = it.split(':')26 return `${prefixPadding}<strong>${key}</strong>:${value};\n` 27 }).join('').trim()28 }29 modifyNewLine (str) {30 return str.replace(/;/gi, ";\n").trim()31 }32 [LOAD('$body')] () {33 var currentProject = this.$selection.currentProject;34 var keyframeCode = currentProject ? currentProject.toKeyframeString() : ''35 var rootVariable = currentProject ? CSS_TO_STRING(currentProject.toRootVariableCSS()) : ''36 var svgCode = currentProject ? currentProject.toSVGString() : '';37 rootVariable = this.filterKeyName(rootVariable.trim());38 keyframeCode = this.modifyNewLine(keyframeCode.trim());39 svgCode = svgCode.replace(/\</g, '<').replace(/\>/g, '>') 40 var current = this.$selection.current;41 var cssCode = current ? TAG_TO_STRING(current.toExport()) : ''42 var nestedCssCode = current ? current.toNestedCSS().map(it => {43 var cssText = it.cssText ? it.cssText : CSS_TO_STRING(it.css)44 return `${it.selector} { 45${this.filterKeyName(TAG_TO_STRING(cssText), ' ')}46}`47 }) : []48 var svgPropertyCode = current ? TAG_TO_STRING(current.toExportSVGCode()) : '' 49 var selectorCode = current ? current.selectors : [];50 cssCode = this.filterKeyName(cssCode.trim())51 // svgPropertyCode = this.filterKeyName(svgPropertyCode.trim())52 return /*html*/`53 <div class=''>54 55 ${cssCode ? 56 /*html*/`<div>57 <pre title='CSS'>${cssCode}</pre>58 </div>` : ''59 }60 61 ${nestedCssCode.map(it => {62 return /*html*/`<div>63 <pre title='CSS'>${it}</pre>64 </div>`65 }).join('')}66 ${svgPropertyCode ? 67 /*html*/`<div>68 <pre title='SVG'>${svgPropertyCode}</pre>69 </div>` : ''70 } 71 ${selectorCode.length ? 72 /*html*/`<div>73 ${selectorCode.map(selector => {74 return `<pre title='${selector.selector}'>${selector.toPropertyString()}</pre>`75 }).join('')}76 77 </div>` : ''78 }79 ${keyframeCode ? 80 /*html*/`<div>81 <pre title='${this.$i18n('code.view.property.keyframe')}'>${keyframeCode}</pre>82 </div>` : ''}83 ${rootVariable ? 84 /*html*/`<div>85 <label>:root</label>86 <pre>${rootVariable}</pre>87 </div>` : ''88 }89 ${svgCode ? 90 /*html*/`<div>91 <pre title='SVG'>${svgCode}</pre>92 </div>` : ''93 }94 </div>95 `96 }...
toHaveKeyframeRule.js
Source:toHaveKeyframeRule.js
1import chalk from 'chalk';2import getCSS from '../utils/getCSS';3import getCodeBlock from '../utils/getCodeBlock';4const findKeyframeCode = (keyframe) => {5 const css = getCSS();6 const keyframeMatches = new RegExp(`@keyframes\\s*${keyframe}\\s*{(.*)`).exec(css);7 const trailingCode = keyframeMatches && keyframeMatches[0];8 if (!trailingCode) return '';9 return getCodeBlock(trailingCode);10};11const toHaveKeyframeRule = (received, keyframeSelector, selector, expected) => {12 const keyframeCode = findKeyframeCode(received);13 const getMessage = value =>14 `Expected keyframe to have ${keyframeSelector} ${selector} matching\n\t${chalk.green(expected)}\nreceived:\n\t${chalk.red(value)}`;15 const error = {16 pass: false,17 message: `Property not found: ${chalk.red(keyframeSelector)} ${chalk.red(selector)}`,18 };19 if (keyframeCode === '') return error;20 const styles = new RegExp(`(?:[^\\d]|^)${keyframeSelector}\\s*{([^}]*)`, 'g').exec(keyframeCode);21 const capture = new RegExp(`(?:[^\\-]|^)${selector}\\s*:\\s*([^;]+)`, 'g');22 const matches = styles && styles[1].match(capture);23 if (!matches) return error;24 const values = matches.map(r => r.replace(capture, '$1').trim());25 const val = values && values[0] && values[values.length - 1];26 return {27 message: getMessage(val),28 pass: values.some(29 v => (expected instanceof RegExp ? v.match(expected) : v === expected),30 ),31 };32};...
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3 if(err) console.log(err);4 else console.log(data);5});6var wpt = require('webpagetest');7var wpt = new WebPageTest('www.webpagetest.org');8 if(err) console.log(err);9 else console.log(data);10});11var wpt = require('webpagetest');12var wpt = new WebPageTest('www.webpagetest.org');13 if(err) console.log(err);14 else console.log(data);15});16var wpt = require('webpagetest');17var wpt = new WebPageTest('www.webpagetest.org');18 if(err) console.log(err);19 else console.log(data);20});21var wpt = require('webpagetest');22var wpt = new WebPageTest('www.webpagetest.org');23 if(err) console.log(err);24 else console.log(data);25});26var wpt = require('webpagetest');27var wpt = new WebPageTest('www.webpagetest.org');28 if(err) console.log(err);29 else console.log(data);30});31var wpt = require('webpagetest');32var wpt = new WebPageTest('www.webpagetest.org');
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var keyframeCode = wpt.keyframeCode(url, function(err, data) {4 if (err) return console.error(err);5 console.log(data);6});7var wpt = require('webpagetest');8var wpt = new WebPageTest('www.webpagetest.org');9var keyframeCode = wpt.keyframeCode(url, function(err, data) {10 if (err) return console.error(err);11 console.log(data);12});13var wpt = require('webpagetest');14var wpt = new WebPageTest('www.webpagetest.org');15var keyframeCode = wpt.keyframeCode(url, function(err, data) {16 if (err) return console.error(err);17 console.log(data);18});19var wpt = require('webpagetest');20var wpt = new WebPageTest('www.webpagetest.org');21var keyframeCode = wpt.keyframeCode(url, function(err, data) {22 if (err) return console.error(err);23 console.log(data);24});25var wpt = require('webpagetest');26var wpt = new WebPageTest('www.webpagetest.org');27var keyframeCode = wpt.keyframeCode(url, function(err, data) {28 if (err) return console.error(err);29 console.log(data);30});
Using AI Code Generation
1wpt.keyframeCode('test', 1000, function(err, data) {2 console.log('error: ', err);3 console.log('data: ', data);4});5wpt.keyframeCode('test', 1000, function(err, data) {6 console.log('error: ', err);7 console.log('data: ', data);8});9wpt.keyframeCode('test', 1000, function(err, data) {10 console.log('error: ', err);11 console.log('data: ', data);12});13wpt.keyframeCode('test', 1000, function(err, data) {14 console.log('error: ', err);15 console.log('data: ', data);16});17wpt.keyframeCode('test', 1000, function(err, data) {18 console.log('error: ', err);19 console.log('data: ', data);20});21wpt.keyframeCode('test', 1000, function(err, data) {22 console.log('error: ', err);23 console.log('data: ', data);24});25wpt.keyframeCode('test', 1000, function(err, data) {26 console.log('error: ', err);27 console.log('data: ', data);28});29wpt.keyframeCode('test', 1000, function(err, data) {30 console.log('error: ', err);31 console.log('data: ', data);32});33wpt.keyframeCode('test', 1000, function(err, data) {34 console.log('error: ', err);35 console.log('data: ', data);36});
Using AI Code Generation
1var wptools = require('wptools');2var video = wptools.video('test.mp4');3video.keyframeCode(function(err, res){4 console.log(res);5});6var wptools = require('wptools');7var video = wptools.video('test.mp4');8video.keyframeCount(function(err, res){9 console.log(res);10});11var wptools = require('wptools');12var video = wptools.video('test.mp4');13video.keyframeTime(function(err, res){14 console.log(res);15});16var wptools = require('wptools');17var video = wptools.video('test.mp4');18video.keyframeTime(function(err, res){19 console.log(res);20});21var wptools = require('wptools');22var video = wptools.video('test.mp4');23video.keyframeTime(function(err, res){24 console.log(res);25});26var wptools = require('wptools');27var video = wptools.video('test.mp4');28video.keyframeTime(function(err, res){29 console.log(res);30});31var wptools = require('wptools');
Using AI Code Generation
1var wpt = require('wpt');2var options = {3};4wpt.runTest(options, function (err, data) {5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 }10});11var wpt = require('wpt');12var options = {13};14wpt.runTest(options, function (err, data) {15 if (err) {16 console.log(err);17 } else {18 console.log(data);19 }20});21var wpt = require('wpt');22var options = {
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!!