Best JavaScript code snippet using puppeteer
TTSizingSVG.js
Source:TTSizingSVG.js
1import React from 'react'2import {drawSVGLineArrow, drawSVGHorizontalLineArrow,drawSVGHorizontalLineArrowText, drawSVGVerticalLineArrowText, drawSVGVerticalLineDashed, drawAngledLineDashed, drawSVGAngledLineArrowText, drawSVGText} from './../lib/svg-functions'3import TTBikeImage from './../assets/Bikes/FitKit3TT.png'4import saddleImage from './../assets/Bikes/saddle.png'5import './Bike.css'6const TTSizingSVG=(props)=> {7 8 const dashColor="red"9 const headTubeCenter={x:486,y:73}10 const headTubeTopTubeIntersection={x:487,y:87}11 const effectiveSeatTubeIntersection={x:242,y:73}12 const bottomBracketCenter={x:302,y:303}13 //const seatTubeCenter={x:250,y:90}14 const topTubeCenter={x: 375, y:82}15 //const seatPostTopTubeIntersection={x:240,y:59}16 //const saddleNose={x:288,y:18}17 const saddlePlane={x1:130,y:12,x2:620}18 //const saddleButt={x:175,y:12}19 const saddleCenter={x:232,y:12}20 //const upperBoundry={x1:130,y:2,x2:600}21 const barCenter={x:512,y:61}22// const hoodTrough={x:565,y:25}23 const spindleCenter={x:315,y:374}24 //const handlebarImageOrigin={x:610,y:70}25 const saddleImageOrigin={x:85, y:30}26 //const stemTubeClamp={x:handlebarImageOrigin.x+30,y:handlebarImageOrigin.y+32}27 //const stemBarClamp={x:handlebarImageOrigin.x+30,y:handlebarImageOrigin.y+13}28 //const padRear={x:495,y:48}29 //const padCenter={x:512,y:45}30 //const extensionsEnd={x:648,y:28}31 const groundPlane={x1:140,y:410,x2:560}32 const lineSpacing=1333return (34<div className="bikeBackground">35<div className="bikeSVG">36<svg width="700" height="413" >37<defs>38 <marker id={props.markerId} markerWidth="10" markerHeight="10" refX="0" refY="3" orient="auto" markerUnits="strokeWidth">39 <path d="M0,0 L0,6 L9,3 z" fill="black" />40 </marker>41 <marker id={"tt12345"} markerWidth="10" markerHeight="10" refX="0" refY="3" orient="auto" markerUnits="strokeWidth">42 <path d="M0,0 L0,6 L9,3 z" fill="orange" />43 </marker>44{props.tab!==2&&45 <marker id={props.id} markerWidth="10" markerHeight="10" refX="0" refY="3" orient="auto" markerUnits="strokeWidth">46 <path d="M0,0 L0,6 L9,3 z" fill="black" />47 </marker>48}49 </defs>50<image width="700" height="413" className="bikeTabImage" href={TTBikeImage} onMouseDown={props.onMouseDown} />51{/* <image x={handlebarImageOrigin.x} y={handlebarImageOrigin.y} width={.1*689} height={.1*350} href={handlebarImage}/> */}52<image x={saddleImageOrigin.x} y={saddleImageOrigin.y} width={.17*186} height={.17*336} href={saddleImage} />53{/*drawSVGHorizontalLineArrowText(bottomBracketCenter.x,headTubeCenter.y,headTubeCenter.x,"black", props.markerId,"frame reach")*/}54{/* drawSVGHorizontalLineArrowText(seatTubeCenter.x,headTubeCenter.y-lineSpacing*2+10,headTubeCenter.x,"black", props.markerId,"effective top tube") */}55{drawSVGHorizontalLineArrowText(effectiveSeatTubeIntersection.x,headTubeTopTubeIntersection.y-14,headTubeTopTubeIntersection.x,"black", props.markerId,"effective top tube")}56{/*drawSVGHorizontalLineArrowText(saddleNose.x,headTubeCenter.y-2*lineSpacing,padRear.x,"black", props.markerId,"saddle nose to pad rear")}*/}57{/*{drawSVGHorizontalLineArrowText(saddleNose.x,headTubeCenter.y-3*lineSpacing,barCenter.x,"black", props.markerId,"saddle nose to bar center")}*/}58{/*drawSVGHorizontalLineArrowText(saddleNose.x,headTubeCenter.y-5*lineSpacing-4,extensionsEnd.x,"black", props.markerId,"saddle nose to end of extensions")}*/}59{/* {drawSVGHorizontalLineArrow(handlebarImageOrigin.x+9,handlebarImageOrigin.y+45,handlebarImageOrigin.x+60,"black", props.markerId)}60{drawSVGHorizontalLineArrow(handlebarImageOrigin.x+25,handlebarImageOrigin.y,handlebarImageOrigin.x+45,"black", props.markerId)} */}61{drawSVGHorizontalLineArrow(saddleImageOrigin.x+6,saddleImageOrigin.y+71,saddleImageOrigin.x+25,"black", props.markerId)}62{drawSVGLineArrow(headTubeCenter.x-15,headTubeCenter.y-4,barCenter.x-9, barCenter.y,"orange", "tt12345")}63{/* drawSVGHorizontalLineArrowText(seatTubeCenter.x,headTubeCenter.y-20,headTubeCenter.x,"orange", "tt12345","bike length (top tube + stem)") */}64{drawSVGHorizontalLineArrowText(effectiveSeatTubeIntersection.x,headTubeCenter.y-lineSpacing,headTubeCenter.x,"orange", "tt12345","bike length (top tube + stem)")}*/}65{/*drawSVGLineArrow(bottomBracketCenter.x,headTubeCenter.y+40,saddleNose.x+8, headTubeCenter.y+40,"black", props.markerId)*/}66{/*drawSVGVerticalLineArrow(saddlePlane.x2-85,saddlePlane.y,padCenter.y-8,"black",props.markerId)*/}67{/*drawSVGVerticalLineArrow(saddlePlane.x2-42,padCenter.y+13,padCenter.y+12,"black", props.markerId)*/}68{/*{drawSVGVerticalLineArrow(stemBarClamp.x-42,stemTubeClamp.y,stemBarClamp.y+8,"black",props.markerId)}*/}69{drawSVGVerticalLineArrowText(topTubeCenter.x,topTubeCenter.y,groundPlane.y,"black", props.markerId,50,0,true,"max standover","height")}70{/*drawSVGVerticalLineArrowText(bottomBracketCenter.x,headTubeCenter.y,bottomBracketCenter.y,"black", props.markerId,100,0,true,"frame","stack")*/}71{/*drawSVGVerticalLineDashed(saddleNose.x,upperBoundry.y,saddleNose.y+100,dashColor, props.markerId)*/}72{/* drawSVGVerticalLineDashed(seatTubeCenter.x,40,seatTubeCenter.y,dashColor, props.markerId) */}73{/* drawSVGVerticalLineDashed(headTubeCenter.x,saddlePlane.y+30,headTubeCenter.y,dashColor, props.markerId) */}74{drawSVGVerticalLineDashed(effectiveSeatTubeIntersection.x,40,effectiveSeatTubeIntersection.y,dashColor, props.markerId)}75{drawSVGVerticalLineDashed(headTubeTopTubeIntersection.x,saddlePlane.y+35,headTubeTopTubeIntersection.y,dashColor, props.markerId)}76{/*{drawSVGVerticalLineDashed(padCenter.x,saddlePlane.y,padCenter.y,dashColor, props.markerId)}*/}77{/*drawSVGVerticalLineDashed(padRear.x,saddlePlane.y,padRear.y,dashColor, props.markerId)*/}78{/* {drawSVGVerticalLineDashed(handlebarImageOrigin.x+9,handlebarImageOrigin.y+15,handlebarImageOrigin.y+45,dashColor, props.markerId)}79{drawSVGVerticalLineDashed(handlebarImageOrigin.x+60,handlebarImageOrigin.y+15,handlebarImageOrigin.y+45,dashColor, props.markerId)}80{drawSVGVerticalLineDashed(handlebarImageOrigin.x+25,handlebarImageOrigin.y,handlebarImageOrigin.y+25,dashColor, props.markerId)}81{drawSVGVerticalLineDashed(handlebarImageOrigin.x+45,handlebarImageOrigin.y,handlebarImageOrigin.y+25,dashColor, props.markerId)} */}82{drawSVGVerticalLineDashed(saddleImageOrigin.x+6,saddleImageOrigin.y+15,saddleImageOrigin.y+75,dashColor, props.markerId)}83{drawSVGVerticalLineDashed(saddleImageOrigin.x+25,saddleImageOrigin.y+15,saddleImageOrigin.y+75,dashColor, props.markerId)}84{/*drawSVGVerticalLineDashed(extensionsEnd.x,upperBoundry.y,extensionsEnd.y+10,dashColor, props.markerId)*/}85{/*drawSVGHorizontalLineDashed(saddlePlane.x1,saddlePlane.y,saddlePlane.x2,dashColor, props.markerId)*/}86{/*drawSVGHorizontalLineDashed(padCenter.x,padCenter.y,saddlePlane.x2-60,dashColor, props.markerId)*/}87{/*drawSVGHorizontalLineDashed(padCenter.x,padCenter.y+13,saddlePlane.x2-40,dashColor, props.markerId)*/}88{/*{drawSVGHorizontalLineDashed(stemTubeClamp.x,stemTubeClamp.y,stemTubeClamp.x-50,dashColor, props.markerId)}*/}89{/*{drawSVGHorizontalLineDashed(stemBarClamp.x,stemBarClamp.y,stemBarClamp.x-50,dashColor, props.markerId)}*/}90{drawAngledLineDashed(bottomBracketCenter.x-60,bottomBracketCenter.y+15,bottomBracketCenter.x,bottomBracketCenter.y,dashColor, props.markerId)}91{drawAngledLineDashed(spindleCenter.x-80,spindleCenter.y+20,spindleCenter.x,spindleCenter.y,dashColor, props.markerId)}92{/*drawAngledLineDashed(saddleButt.x,saddleButt.y,saddlePlane.x1,saddlePlane.y+10,dashColor, props.markerId)*/}93{drawAngledLineDashed(spindleCenter.x,spindleCenter.y,saddleCenter.x,saddleCenter.y,dashColor, props.markerId)}94{drawAngledLineDashed(saddleCenter.x-87,saddleCenter.y+20,saddleCenter.x,saddleCenter.y,dashColor, props.markerId)}95{/*drawAngledLineDashed(padCenter.x,padCenter.y+13,saddlePlane.x2-40,padCenter.y+5,dashColor, props.markerId)*/}96{/* drawAngledLineDashed(seatPostTopTubeIntersection.x-60,seatPostTopTubeIntersection.y+15,seatPostTopTubeIntersection.x,seatPostTopTubeIntersection.y,dashColor, props.markerId) */}97{drawAngledLineDashed(effectiveSeatTubeIntersection.x-60,effectiveSeatTubeIntersection.y+15,effectiveSeatTubeIntersection.x,effectiveSeatTubeIntersection.y,dashColor, props.markerId)}98{/*drawSVGAngledLineArrowText(bottomBracketCenter.x+60,bottomBracketCenter.y-15,spindleCenter.x+60,spindleCenter.y-15,"black", props.markerId,0,null,false,"crank length")*/}99{/*{drawSVGAngledLineArrowText(saddleButt.x,saddleButt.y,bottomBracketCenter.x-60,bottomBracketCenter.y+15,"black", props.markerId,50,0,true,"saddle","to bb")}100{drawSVGAngledLineArrowText(saddleButt.x-20,saddleButt.y,spindleCenter.x-80,spindleCenter.y+20,"black", props.markerId, 80,15,true,"saddle","to pedal")}*/}101{/*drawSVGAngledLineArrowText(saddleCenter.x-60,saddleCenter.y+15,bottomBracketCenter.x-60,bottomBracketCenter.y+15,"black", props.markerId,50,0,true,"saddle","to bb")*/}102{drawSVGAngledLineArrowText(effectiveSeatTubeIntersection.x-60,effectiveSeatTubeIntersection.y+15,bottomBracketCenter.x-60,bottomBracketCenter.y+15,"black", props.markerId,30,0,true,"frame","size")}103{drawSVGAngledLineArrowText(saddleCenter.x-87,saddleCenter.y+20,spindleCenter.x-80,spindleCenter.y+20,"black", props.markerId, 55,15,true,"saddle","to pedal")}104{/*drawSVGLineArrow(saddlePlane.x1,saddlePlane.y,saddlePlane.x1,saddlePlane.y+10-8,"black",props.markerId)*/}105{/*drawSVGText(saddlePlane.x1-45,saddlePlane.y+5,"black", props.markerId,"saddle","angle")*/}106{/*drawSVGText(saddleNose.x+20,headTubeCenter.y+40, "black", props.markerId,"saddle","setback")*/}107{/*drawSVGText(saddlePlane.x2-80,saddlePlane.y+15, "black", props.markerId, "saddle to","pad drop")*/}108{/* drawSVGText(handlebarImageOrigin.x+9,handlebarImageOrigin.y+60,"black", props.markerId,"basebar","width") */}109{/* drawSVGText(handlebarImageOrigin.x+50,handlebarImageOrigin.y,"black", props.markerId,"pad","width") */}110{drawSVGText(saddleImageOrigin.x,saddleImageOrigin.y+87,"black", props.markerId,"saddle","width")}111{/*drawSVGText(saddlePlane.x2-33,padCenter.y,"black", props.markerId,"ext.","angle")*/}112</svg>113</div>114</div>115 )116 }...
TTBikeSVG.js
Source:TTBikeSVG.js
1import React, {Component} from 'react'2import {drawSVGLineArrow, drawSVGHorizontalLineArrow,drawSVGHorizontalLineArrowText, drawSVGVerticalLineArrowText, drawSVGVerticalLineDashed, drawSVGHorizontalLineDashed, drawAngledLineDashed, drawSVGAngledLineArrowText, drawSVGText, drawSVGVerticalLineArrow} from './../lib/svg-functions'3import TTBikeImage from './../assets/Bikes/FitKit3TT.png'4import handlebarImage from './../assets/Bikes/aerobar.png'5import saddleImage from './../assets/Bikes/saddle.png'6import './Bike.css'7class TTBikeSVG extends Component {8 9 render() {10 const dashColor="red"11 const headTubeCenter={x:486,y:73}12 const bottomBracketCenter={x:302,y:303}13 const seatTubeCenter={x:250,y:90}14 const saddleNose={x:288,y:18}15 const saddlePlane={x1:130,y:12,x2:620}16 const saddleButt={x:175,y:12}17 const saddleCenter={x:232,y:12}18 const upperBoundry={x1:130,y:2,x2:600}19// const barCenter={x:510,y:35}20// const hoodTrough={x:565,y:25}21 const spindleCenter={x:315,y:374}22 const handlebarImageOrigin={x:610,y:70}23 const saddleImageOrigin={x:85, y:30}24// const stemTubeClamp={x:handlebarImageOrigin.x+30,y:handlebarImageOrigin.y+32}25// const stemBarClamp={x:handlebarImageOrigin.x+30,y:handlebarImageOrigin.y+13}26 const padRear={x:495,y:48}27 const padCenter={x:512,y:45}28 const extensionsEnd={x:648,y:28}29 const lineSpacing=1330return (31<div className="bikeBackground">32<div className="bikeSVG">33<svg width="700" height="413" >34<defs>35 <marker id={this.props.markerId} markerWidth="10" markerHeight="10" refX="0" refY="3" orient="auto" markerUnits="strokeWidth">36 <path d="M0,0 L0,6 L9,3 z" fill="black" />37 </marker>38 </defs>39<image width="700" height="413" className="bikeTabImage" href={TTBikeImage} onMouseDown={this.props.onMouseDown} />40<image x={handlebarImageOrigin.x} y={handlebarImageOrigin.y} width={.1*689} height={.1*350} href={handlebarImage}/>41<image x={saddleImageOrigin.x} y={saddleImageOrigin.y} width={.17*186} height={.17*336} href={saddleImage} />42{drawSVGHorizontalLineArrowText(bottomBracketCenter.x,headTubeCenter.y,headTubeCenter.x,"black", this.props.markerId,"frame reach")}43{drawSVGHorizontalLineArrowText(seatTubeCenter.x,headTubeCenter.y-lineSpacing,headTubeCenter.x,"black", this.props.markerId,"effective top tube")}44{drawSVGHorizontalLineArrowText(saddleNose.x,headTubeCenter.y-2*lineSpacing,padRear.x,"black", this.props.markerId,"saddle nose to pad rear")}*/}45{/*{drawSVGHorizontalLineArrowText(saddleNose.x,headTubeCenter.y-3*lineSpacing,barCenter.x,"black", this.props.markerId,"saddle nose to bar center")}*/}46{drawSVGHorizontalLineArrowText(saddleNose.x,headTubeCenter.y-5*lineSpacing-4,extensionsEnd.x,"black", this.props.markerId,"saddle nose to end of extensions")}*/}47{drawSVGHorizontalLineArrow(handlebarImageOrigin.x+9,handlebarImageOrigin.y+45,handlebarImageOrigin.x+60,"black", this.props.markerId)}48{drawSVGHorizontalLineArrow(handlebarImageOrigin.x+25,handlebarImageOrigin.y,handlebarImageOrigin.x+45,"black", this.props.markerId)}49{drawSVGHorizontalLineArrow(saddleImageOrigin.x+6,saddleImageOrigin.y+71,saddleImageOrigin.x+25,"black", this.props.markerId)}50{drawSVGLineArrow(bottomBracketCenter.x,headTubeCenter.y+40,saddleNose.x+8, headTubeCenter.y+40,"black", this.props.markerId)}51{drawSVGVerticalLineArrow(saddlePlane.x2-85,saddlePlane.y,padCenter.y-8,"black",this.props.markerId)}52{drawSVGVerticalLineArrow(saddlePlane.x2-42,padCenter.y+13,padCenter.y+12,"black", this.props.markerId)}53{/*{drawSVGVerticalLineArrow(stemBarClamp.x-42,stemTubeClamp.y,stemBarClamp.y+8,"black",this.props.markerId)}*/}54{drawSVGVerticalLineArrowText(bottomBracketCenter.x,headTubeCenter.y,bottomBracketCenter.y,"black", this.props.markerId,100,0,true,"frame","stack")}55{drawSVGVerticalLineDashed(saddleNose.x,upperBoundry.y,saddleNose.y+100,dashColor, this.props.markerId)}56{drawSVGVerticalLineDashed(seatTubeCenter.x,40,seatTubeCenter.y,dashColor, this.props.markerId)}57{drawSVGVerticalLineDashed(headTubeCenter.x,saddlePlane.y,headTubeCenter.y,dashColor, this.props.markerId)}58{/*{drawSVGVerticalLineDashed(padCenter.x,saddlePlane.y,padCenter.y,dashColor, this.props.markerId)}*/}59{drawSVGVerticalLineDashed(padRear.x,saddlePlane.y,padRear.y,dashColor, this.props.markerId)}60{drawSVGVerticalLineDashed(handlebarImageOrigin.x+9,handlebarImageOrigin.y+15,handlebarImageOrigin.y+45,dashColor, this.props.markerId)}61{drawSVGVerticalLineDashed(handlebarImageOrigin.x+60,handlebarImageOrigin.y+15,handlebarImageOrigin.y+45,dashColor, this.props.markerId)}62{drawSVGVerticalLineDashed(handlebarImageOrigin.x+25,handlebarImageOrigin.y,handlebarImageOrigin.y+25,dashColor, this.props.markerId)}63{drawSVGVerticalLineDashed(handlebarImageOrigin.x+45,handlebarImageOrigin.y,handlebarImageOrigin.y+25,dashColor, this.props.markerId)}64{drawSVGVerticalLineDashed(saddleImageOrigin.x+6,saddleImageOrigin.y+15,saddleImageOrigin.y+75,dashColor, this.props.markerId)}65{drawSVGVerticalLineDashed(saddleImageOrigin.x+25,saddleImageOrigin.y+15,saddleImageOrigin.y+75,dashColor, this.props.markerId)}66{drawSVGVerticalLineDashed(extensionsEnd.x,upperBoundry.y,extensionsEnd.y+10,dashColor, this.props.markerId)}67{drawSVGHorizontalLineDashed(saddlePlane.x1,saddlePlane.y,saddlePlane.x2,dashColor, this.props.markerId)}68{drawSVGHorizontalLineDashed(padCenter.x,padCenter.y,saddlePlane.x2-60,dashColor, this.props.markerId)}69{drawSVGHorizontalLineDashed(padCenter.x,padCenter.y+13,saddlePlane.x2-40,dashColor, this.props.markerId)}70{/*{drawSVGHorizontalLineDashed(stemTubeClamp.x,stemTubeClamp.y,stemTubeClamp.x-50,dashColor, this.props.markerId)}*/}71{/*{drawSVGHorizontalLineDashed(stemBarClamp.x,stemBarClamp.y,stemBarClamp.x-50,dashColor, this.props.markerId)}*/}72{drawAngledLineDashed(bottomBracketCenter.x-60,bottomBracketCenter.y+15,bottomBracketCenter.x+60,bottomBracketCenter.y-15,dashColor, this.props.markerId)}73{drawAngledLineDashed(spindleCenter.x-80,spindleCenter.y+20,spindleCenter.x+80,spindleCenter.y-20,dashColor, this.props.markerId)}74{drawAngledLineDashed(saddleButt.x,saddleButt.y,saddlePlane.x1,saddlePlane.y+10,dashColor, this.props.markerId)}75{drawAngledLineDashed(spindleCenter.x,spindleCenter.y,saddleCenter.x,saddleCenter.y,dashColor, this.props.markerId)}76{drawAngledLineDashed(saddleCenter.x-80,saddleCenter.y+20,saddleCenter.x,saddleCenter.y,dashColor, this.props.markerId)}77{drawAngledLineDashed(padCenter.x,padCenter.y+13,saddlePlane.x2-40,padCenter.y+5,dashColor, this.props.markerId)}78{drawSVGAngledLineArrowText(bottomBracketCenter.x+60,bottomBracketCenter.y-15,spindleCenter.x+60,spindleCenter.y-15,"black", this.props.markerId,0,null,false,"crank length")}79{/*{drawSVGAngledLineArrowText(saddleButt.x,saddleButt.y,bottomBracketCenter.x-60,bottomBracketCenter.y+15,"black", this.props.markerId,50,0,true,"saddle","to bb")}80{drawSVGAngledLineArrowText(saddleButt.x-20,saddleButt.y,spindleCenter.x-80,spindleCenter.y+20,"black", this.props.markerId, 80,15,true,"saddle","to pedal")}*/}81{drawSVGAngledLineArrowText(saddleCenter.x-60,saddleCenter.y+15,bottomBracketCenter.x-60,bottomBracketCenter.y+15,"black", this.props.markerId,50,0,true,"saddle","to bb")}82{drawSVGAngledLineArrowText(saddleCenter.x-80,saddleCenter.y+20,spindleCenter.x-80,spindleCenter.y+20,"black", this.props.markerId, 75,15,true,"saddle","to pedal")}83{drawSVGLineArrow(saddlePlane.x1,saddlePlane.y,saddlePlane.x1,saddlePlane.y+10-8,"black",this.props.markerId)}84{drawSVGText(saddlePlane.x1-45,saddlePlane.y+5,"black", this.props.markerId,"saddle","angle")}85{drawSVGText(saddleNose.x+20,headTubeCenter.y+40, "black", this.props.markerId,"saddle","setback")}86{drawSVGText(saddlePlane.x2-80,saddlePlane.y+15, "black", this.props.markerId, "saddle to","pad drop")}87{drawSVGText(handlebarImageOrigin.x+9,handlebarImageOrigin.y+60,"black", this.props.markerId,"basebar","width")}88{drawSVGText(handlebarImageOrigin.x+50,handlebarImageOrigin.y,"black", this.props.markerId,"pad","width")}*/}89{drawSVGText(saddleImageOrigin.x,saddleImageOrigin.y+87,"black", this.props.markerId,"saddle","width")}90{drawSVGText(saddlePlane.x2-33,padCenter.y,"black", this.props.markerId,"ext.","angle")}91</svg>92</div>93</div>94 )95 }96}...
index.js
Source:index.js
...10}11function emptyStrings(length) {12 return Array.from({ length }, () => "");13}14function padCenter(str, length) {15 const leftOver = length - str.length;16 const startPad = Math.floor(leftOver / 2);17 const endPad = startPad + leftOver % 2;18 return str19 .padStart(str.length + startPad)20 .padEnd(str.length + endPad + startPad);21}22function boxedString(str, columnWidth, rowHeight) {23 const vertLength = columnWidth + 2;24 const vertLine = repeatStr(HORIZONTAL, vertLength);25 if (str.length === 0 || str === ".") {26 const whitespace = " ".padEnd(vertLength + 2);27 return repeatStr(whitespace, rowHeight, "\n");28 }29 const paddedString = padCenter(str, columnWidth);30 return `${TOP_LEFT}${vertLine}${TOP_RIGHT}\n${VERTICAL} ${paddedString} ${VERTICAL}\n${BOTTOM_LEFT}${vertLine}${BOTTOM_RIGHT}`;31}32function smallConnectedBox(boxRows, rowIndex, cellIndex, columnWidth) {33 const padValue = columnWidth + 4;34 if (boxRows[rowIndex - 1] && !isBoxEmpty(boxRows[rowIndex - 1][cellIndex])) {35 return padCenter(VERTICAL, padValue);36 } else {37 return padCenter(" ", padValue);38 }39}40function jointPoint(hasTop, hasBottom, hasLeft, hasRight) {41 if (hasTop && hasBottom && hasLeft && hasRight) {42 return "â¼";43 }44 if (hasTop && hasBottom && hasLeft) {45 return "â¤";46 }47 if (hasTop && hasBottom && hasRight) {48 return "â";49 }50 if (hasBottom && hasRight && hasLeft) {51 return "â¬";52 }53 if (hasTop && hasRight && hasLeft) {54 return "â´";55 }56 if (hasRight && hasBottom) {57 return TOP_LEFT;58 }59 if (hasLeft && hasBottom) {60 return TOP_RIGHT;61 }62 if (hasTop && hasRight) {63 return BOTTOM_LEFT;64 }65 if (hasLeft && hasTop) {66 return BOTTOM_RIGHT;67 }68 if (hasLeft && hasRight) {69 return HORIZONTAL;70 }71 if (hasTop && hasBottom) {72 return VERTICAL;73 }74 return "x";75}76function connectedBox(boxRows, rowIndex, cellIndex, columnWidth, rowHeight) {77 if (rowHeight === 1) {78 return smallConnectedBox(boxRows, rowIndex, cellIndex, columnWidth);79 }80 const padValue = columnWidth + 4;81 const leftOver = (padValue - 1) % 2;82 let result = "";83 const hasTop =84 boxRows[rowIndex - 1] && !isBoxEmpty(boxRows[rowIndex - 1][cellIndex]);85 const hasLeft =86 boxRows[rowIndex][cellIndex - 1] &&87 !isBoxEmpty(boxRows[rowIndex][cellIndex - 1]);88 const hasRight =89 boxRows[rowIndex][cellIndex + 1] &&90 !isBoxEmpty(boxRows[rowIndex][cellIndex + 1]);91 const hasBottom =92 boxRows[rowIndex + 1] && !isBoxEmpty(boxRows[rowIndex + 1][cellIndex]);93 if (hasTop) {94 result += padCenter(VERTICAL, padValue);95 } else {96 result += padCenter(" ", padValue);97 }98 if (hasLeft) {99 result += `\n${repeatStr(HORIZONTAL, Math.floor((padValue - 1) / 2))}`;100 } else {101 result += `\n${repeatStr(" ", Math.floor((padValue - 1) / 2))}`;102 }103 result += jointPoint(hasTop, hasBottom, hasLeft, hasRight);104 if (hasRight) {105 result += `${repeatStr(106 HORIZONTAL,107 Math.floor((padValue - 1) / 2) + leftOver108 )}`;109 } else {110 result += `${repeatStr(" ", Math.floor((padValue - 1) / 2) + leftOver)}`;111 }112 if (hasBottom) {113 result += `\n${padCenter(VERTICAL, padValue)}`;114 } else {115 result += `\n${padCenter(" ", padValue)}`;116 }117 return result;118}119function isBoxEmpty(box) {120 return Array.from(box).filter(s => s !== " " && s !== "\n").length === 0;121}122function joinedBoxes(boxes, rowHeight) {123 if (rowHeight === 1) {124 return boxes.join(" ");125 }126 const rows = boxes.reduce((acc, box, index) => {127 const lines = box.split("\n");128 if (index === 0) {129 return [lines[0], lines[1], lines[2]];130 }131 const line =132 isBoxEmpty(box) || isBoxEmpty(boxes[index - 1])133 ? " "134 : repeatStr(HORIZONTAL, 3);135 return [136 acc[0] + " " + lines[0],137 acc[1] + line + lines[1],138 acc[2] + " " + lines[2]139 ];140 }, []);141 return rows.join("\n");142}143function getColumnWidths(boxes) {144 return boxes145 .reduce((acc, curr) =>146 curr.map(147 (cell, index) => (cell.length > acc[index].length ? cell : acc[index])148 )149 )150 .map(s => s.length);151}152function getRowHeights(boxes) {153 return boxes.map(row => {154 const rowEmpty =155 row.filter(cell => cell.length !== 0 && cell !== ".").length === 0;156 return rowEmpty ? 1 : 3;157 });158}159function getMaxColumnCount(boxRows) {160 return boxRows.reduce((max, row) => Math.max(max, row.length), 0);161}162function normalizeInput(str) {163 const rows = str.split("\n").map(s => s.split(","));164 const maxColumnCount = getMaxColumnCount(rows);165 return rows.map(166 row =>167 row.length < maxColumnCount168 ? row.concat(emptyStrings(maxColumnCount - row.length))169 : row170 );171}172function createChart(str) {173 const boxRows = normalizeInput(str);174 const columnWidths = getColumnWidths(boxRows);175 const rowHeights = getRowHeights(boxRows);176 const decoratedBoxes = boxRows.map((row, rowIndex) => {177 return row.map((cell, cellIndex) => {178 if (cell === ".") {179 return connectedBox(180 boxRows,181 rowIndex,182 cellIndex,183 columnWidths[cellIndex],184 rowHeights[rowIndex]185 );186 } else {187 return boxedString(cell, columnWidths[cellIndex], rowHeights[rowIndex]);188 }189 });190 });191 const res = decoratedBoxes.map((boxes, index) => {192 let connectRow = "";193 if (decoratedBoxes[index - 1] && rowHeights[index - 1] !== 1) {194 boxes.forEach((box, cellIndex) => {195 const isLast = cellIndex === boxes.length - 1;196 const upperCell = decoratedBoxes[index - 1][cellIndex];197 if (isBoxEmpty(upperCell) || isBoxEmpty(box)) {198 connectRow += "".padStart(columnWidths[cellIndex] + (isLast ? 4 : 7));199 return;200 }201 connectRow += padCenter(VERTICAL, columnWidths[cellIndex] + 4);202 if (!isLast) {203 connectRow += " ";204 }205 });206 connectRow += "\n";207 }208 return connectRow + joinedBoxes(boxes, rowHeights[index]);209 });210 return res.join("\n");211}...
math.js
Source:math.js
1function empty() {2 return { baseline: undefined, width: 0, lines: [] };3}4function str(str, baseline = 0) {5 let lines = str.split("\n");6 let width = lines[0].length;7 for (let line of lines)8 if (line.length !== width) throw new Error("line not right size");9 return { baseline, width: lines[0].length, lines };10}11function deriv(vin, dfrom = empty(), dto = empty()) {12 let width = Math.max(vin.width, dfrom.width, dto.width);13 let ltop = " /'" + " ".repeat(width);14 let lbottom = "./ " + " ".repeat(width);15 let lfrom = dfrom.lines.map(l => " " + l.padEnd(width, " "));16 let lto = dto.lines.map(l => " " + l.padEnd(width, " "));17 let lcenter = vin.lines.map(l => " | " + l.padEnd(width, " "));18 return {19 baseline: lto.length + vin.baseline + 1,20 width: width + 3,21 lines: [...lto, ltop, ...lcenter, lbottom, ...lfrom]22 };23}24function box(equ) {25 let topline = ",-" + "-".repeat(equ.width) + "-.";26 let centerls = equ.lines.map((l, i) =>27 i === equ.baseline ? ": " + l + " :" : "| " + l + " |"28 );29 let bottomline = "`-" + "-".repeat(equ.width) + "-'";30 let blank = "| " + " ".repeat(equ.width) + " |";31 return {32 baseline: equ.baseline + 2,33 width: equ.width + 4,34 lines: [topline, blank, ...centerls, blank, bottomline]35 };36}37function padcenter(str, w, space) {38 let len = str.length;39 let size = (w - len) / 2;40 if (size < 0) throw new Error("too small width");41 let leftspace = Math.floor(size);42 let rightspace = Math.ceil(size);43 return " ".repeat(leftspace) + str + " ".repeat(rightspace);44}45function frac(e1, e2) {46 let width = Math.max(e1.width, e2.width);47 let divider = "-".repeat(width);48 let tophalf = e1.lines.map(l => padcenter(l, width, " "));49 let bottomhalf = e2.lines.map(l => padcenter(l, width, " "));50 return {51 baseline: tophalf.length,52 width,53 lines: [...tophalf, divider, ...bottomhalf]54 };55}56function hcombine(...items) {57 let bottomSpace =58 Math.max(0, ...items.map(it => it.lines.length - it.baseline)) - 1;59 let topSpace = Math.max(0, ...items.map(it => it.baseline));60 let fv = [61 ...new Array(topSpace).fill(""),62 "", // baseline63 ...new Array(bottomSpace).fill("")64 ];65 for (let item of items) {66 for (let i = 0; i < fv.length; i++) {67 let li = i - topSpace + item.baseline;68 if (li >= item.lines.length || li < 0) {69 fv[i] += " ".repeat(item.width);70 } else {71 fv[i] += item.lines[li];72 }73 }74 }75 return {76 baseline: topSpace,77 width: fv[0].length,78 lines: fv79 };80}81function pow(base, powof) {82 let powl = powof.lines.map(l => " ".repeat(base.width) + l);83 let basel = base.lines.map(l => l + " ".repeat(powof.width));84 return {85 baseline: base.baseline + powof.lines.length,86 width: base.width + powof.width,87 lines: [...powl, ...basel]88 };89}90function paren(equ) {91 let h = equ.lines.length;92 if (h === 1) {93 return {94 baseline: equ.baseline,95 width: equ.width + 2,96 lines: ["(" + equ.lines[0] + ")"]97 };98 }99 return {100 baseline: equ.baseline + 1,101 width: equ.width + 4,102 lines: [103 "/ " + " ".repeat(equ.width) + " \\",104 ...equ.lines.map((l, i) => "| " + l + " |"),105 "\\ " + " ".repeat(equ.width) + " /"106 ]107 };108}109function print(equ) {110 return equ.lines.join("\n");111}112const equ = frac(113 deriv(114 hcombine(115 frac(str("1"), str("2")),116 str(" "),117 str("*"),118 str(" "),119 frac(pow(str("3"), str("2")), str("4")),120 str(" * "),121 paren(122 hcombine(123 pow(str("3"), frac(str("1"), str("2"))),124 str(" + "),125 paren(str("2"))126 )127 ),128 str(" dx")129 )130 ),131 paren(pow(str("2"), str("5")))132);133let added = hcombine(134 paren(equ),135 str(" = "),136 deriv(str("cont"), str("from"), str("to"))137);138console.log(print(box(added)));139/*140 /'141 | 5x dx142 ./143*/144let demo1 = deriv(str("5x dx"));145console.log(print(box(demo1)));146/*147 /'148 | 2149 | 2 3 2 / 2 \150 | x + 2x + 5 + -- + 6 + ( 3 * 4 ) + \ 3 + 4 /151 | 2 152./153*/154let demo2 = deriv(155 hcombine(156 pow(str("x"), str("2")),157 str(" + "),158 str("2x"),159 str(" + "),160 str("5"),161 str(" + "),162 frac(pow(str("3"), str("2")), str("2")),163 str(" + "),164 str("6"),165 str(" + "),166 pow(paren(str(" 3 * 4 ")), str("2")),167 str(" + "),168 paren(hcombine(str("3"), str(" + "), pow(str("4"), str("2")))),169 str(" dx")170 ),171 str("-1"),172 str("1")173);174console.log(print(box(demo2)));175let recurse = (count) => {176 if(count <= 0) return str("1");177 return hcombine(str("1 "), frac(recurse(count - 1), recurse(count - 1)), str(" 1"));178};179let demo3 = recurse(4);...
utils.js
Source:utils.js
...33 * @param Number max total length of output string34 * @param String chr optional. Character to pad with. default: ' '35 * @return String padded str36 */37function padCenter(str, max, chr) {38 str = str != null ? str : ''39 str = String(str)40 var length = max - wcwidth(str)41 if (length <= 0) return str42 var lengthLeft = Math.floor(length/2)43 var lengthRight = length - lengthLeft44 return repeatString(chr || ' ', lengthLeft) + str + repeatString(chr || ' ', lengthRight)45}46/**47 * Pad `str` up to total length `max` with `chr`, on the left.48 * If `str` is longer than `max`, padRight will return `str` unaltered.49 *50 * @param String str string to pad51 * @param Number max total length of output string...
JoystickHandle.js
Source:JoystickHandle.js
1function absolutePosition(el) {2 let pos = { x: 0, y: 0 }3 while ((el = el.parentNode) !== document) {4 pos.x += el.offsetLeft5 pos.y += el.offsetTop6 }7 return pos8}9export default function JoystickHandle(handle) {10 const handleSize = { x: handle.clientWidth, y: handle.clientHeight }11 const handleCenter = { x: handleSize.x / 2, y: handleSize.y / 2 }12 const padPos = absolutePosition(handle)13 const padSize = { x: handle.parentNode.clientWidth - handleSize.x, y: handle.parentNode.clientHeight - handleSize.y }14 const padCenter = { x: padSize.x / 2, y: padSize.y / 2 }15 const clamp = (min, max) => (val) => Math.floor(Math.min(Math.max(val, min), max))16 const clampX = clamp(0, padSize.x)17 const clampY = clamp(0, padSize.y)18 const listeners = []19 handle.addEventListener("mousedown", touchstart, { passive: true })20 handle.addEventListener("touchstart", touchstart, { passive: true })21 let snapBackTimer22 const center = { x: padSize.x / 2, y: padSize.y / 2 }23 let pos = { x: 0, y: 0 }24 update()25 function update() {26 listeners.forEach((listener) => listener(pos))27 const x = ((pos.x / 100) * padSize.x) / 2 + padCenter.x28 const y = ((-pos.y / 100) * padSize.y) / 2 + padCenter.y29 handle.setAttribute("style", `top: ${y}px; left: ${x}px`)30 }31 function handleMove(event) {32 event.preventDefault()33 const clientX = event.clientX || event.touches[0].clientX34 const clientY = event.clientY || event.touches[0].clientY35 pos.x = Math.round(((clampX(clientX - padPos.x - handleCenter.x) / padSize.x) * 2 - 1) * 100)36 pos.y = -Math.round(((clampY(clientY - padPos.y - handleCenter.y) / padSize.y) * 2 - 1) * 100)37 update()38 }39 function backTowardsCenter() {40 if (pos.x || pos.y) {41 pos.x = Math.abs(pos.x) < 5 ? 0 : Math.round(pos.x - pos.x / 5)42 pos.y = Math.abs(pos.y) < 5 ? 0 : Math.round(pos.y - pos.y / 5)43 update()44 snapBackTimer = setTimeout(backTowardsCenter, 20)45 } else {46 snapBackTimer = undefined47 }48 }49 function touchstart() {50 function removeHandler() {51 document.removeEventListener("mousemove", handleMove)52 document.removeEventListener("touchmove", handleMove)53 snapBackTimer = setTimeout(backTowardsCenter, 20)54 }55 snapBackTimer && clearTimeout(snapBackTimer)56 snapBackTimer = undefined57 document.addEventListener("mousemove", handleMove, { passive: false })58 document.addEventListener("touchmove", handleMove, { passive: false })59 document.addEventListener("mouseup", removeHandler, { passive: true, once: true })60 document.addEventListener("touchend", removeHandler, { passive: true, once: true })61 }62 return {63 on(eventName, func) {64 if (eventName === "change") {65 listeners.push(func)66 }67 },68 }...
padCenter.js
Source:padCenter.js
1var test = require('tape')2var padCenter = require('../utils').padCenter3test('pad string with spaces up to len (sides equal)', function(t) {4 t.plan(1)5 t.equal(padCenter('word', 10), ' word ')6})7test('pad string with spaces up to len (sides not equal)', function(t) {8 t.plan(1)9 t.equal(padCenter('words', 10), ' words ')10})11test('pad string with paddingChr of length >1, up to len', function(t) {12 t.plan(1)13 t.equal(padCenter('word', 10, ' .'), ' . word . ')...
Using AI Code Generation
1const puppeteer = require('puppeteer');2(async () => {3 const browser = await puppeteer.launch();4 const page = await browser.newPage();5 await page.pdf({path: 'test.pdf', format: 'A4', printBackground: true});6 await browser.close();7})();
Using AI Code Generation
1const puppeteer = require('puppeteer');2const fs = require('fs');3const path = require('path');4(async () => {5 const browser = await puppeteer.launch();6 const page = await browser.newPage();7 await page.pdf({path: 'google.pdf', format: 'A4'});8 await browser.close();9})();10const puppeteer = require('puppeteer');11const fs = require('fs');12const path = require('path');13(async () => {14 const browser = await puppeteer.launch();15 const page = await browser.newPage();16 await page.emulateMediaFeatures([{name: 'screen', value: 'landscape'}]);17 await page.pdf({path: 'google.pdf', format: 'A4'});18 await browser.close();19})();
Using AI Code Generation
1const puppeteer = require('puppeteer');2const fs = require('fs');3(async () => {4 const browser = await puppeteer.launch();5 const page = await browser.newPage();6 await page.screenshot({path: 'google.png'});7 await browser.close();8})();9const puppeteer = require('puppeteer');10const fs = require('fs');11(async () => {12 const browser = await puppeteer.launch();13 const page = await browser.newPage();14 await page.screenshot({path: 'google.png'});15 await browser.close();16})();17![Screenshot](
Using AI Code Generation
1const puppeteer = require('puppeteer');2const fs = require('fs');3(async () => {4 const browser = await puppeteer.launch();5 const page = await browser.newPage();6 await page.screenshot({path: 'google.png'});7 await browser.close();8})();
Using AI Code Generation
1const puppeteer = require('puppeteer');2const devices = require('puppeteer/DeviceDescriptors');3const iPhone = devices['iPhone 6'];4const iPad = devices['iPad landscape'];5const padCenter = require('./padCenter.js');6const center = padCenter.center;7const pad = padCenter.pad;8(async () => {9 const browser = await puppeteer.launch();10 const page = await browser.newPage();11 await page.emulate(iPad);12 await page.screenshot({path: 'iPad.png'});13 await page.emulate(iPhone);14 await page.screenshot({path: 'iPhone.png'});15 await browser.close();16})();17const puppeteer = require('puppeteer');18const devices = require('puppeteer/DeviceDescriptors');19const iPhone = devices['iPhone 6'];20const iPad = devices['iPad landscape'];21const padCenter = require('./padCenter.js');22const center = padCenter.center;23const pad = padCenter.pad;24(async () => {25 const browser = await puppeteer.launch();26 const page = await browser.newPage();27 await page.emulate(iPad);28 await page.screenshot({path: 'iPad.png'});29 await page.emulate(iPhone);30 await page.screenshot({path: 'iPhone.png'});31 await browser.close();32})();
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!!