Best JavaScript code snippet using wpt
filters.js.uncompressed.js
Source:filters.js.uncompressed.js
...8 // A module that defines a minimal API to create SVG filter definition objects to be used with the9 // dojox/gfx/svgext/Shape.setFilter() API, as well as a set of predefined filters.10 // description:11 // The module defines the following API:12 // - filters.createFilter(config, primitives) : Creates a filter object from the specified config and the13 // given filter primitives.14 // - a set of methods to create the corresponding SVG filter primitives, based on the same15 // naming as the specification (e.g. filters.feGaussianBlur() ). A filter primitive method follows the16 // following signature (taking feGaussianBlur as an example):17 // filters.feGaussianBlur(properties, children?)18 // filters.feGaussianBlur(children)19 // The "properties" parameter must define the primitive attributes as defined by the specification.20 // The "children" array parameter is an array of child filter primitives.21 // In addition to this API, the module provides the following predefined filters:22 // - filters.convolutions.boxBlur3,23 // - filters.convolutions.boxBlur5,24 // - filters.convolutions.verticalEdges,25 // - filters.convolutions.horizontalEdges,26 // - filters.convolutions.allEdges3,27 // - filters.convolutions.edgeEnhance,28 // - filters.shadows.fastSmallDropShadow,29 // - filters.shadows.fastDropShadow,30 // - filters.shadows.fastDropShadowLight,31 // - filters.shadows.dropShadow,32 // - filters.shadows.dropShadowLight,33 // - filters.shadows.smallDropShadow,34 // - filters.shadows.smallDropShadowLight,35 // - filters.blurs.blur1,36 // - filters.blurs.blur2,37 // - filters.blurs.blur4,38 // - filters.blurs.blur8,39 // - filters.blurs.glow,40 // - filters.colors.negate,41 // - filters.colors.sepia,42 // - filters.colors.grayscale,43 // - filters.colors.showRed,44 // - filters.colors.showGreen,45 // - filters.colors.showBlue,46 // - filters.colors.hueRotate60,47 // - filters.colors.hueRotate120,48 // - filters.colors.hueRotate180,49 // - filters.colors.hueRotate270,50 // - filters.miscs.thinEmbossDropShadow,51 // - filters.miscs.embossDropShadow,52 // - filters.miscs.largeEmbossDropShadow,53 // - filters.miscs.thinEmbossDropShadowLight,54 // - filters.miscs.embossDropShadowLight,55 // - filters.miscs.largeEmbossDropShadowLight,56 // - filters.miscs.fuzzy,57 // - filters.miscs.veryFuzzy,58 // - filters.miscs.melting,59 // - filters.miscs.impressionist,60 // - filters.miscs.holes,61 // - filters.miscs.holesComplement,62 // - filters.reliefs.bumpIn,63 // - filters.reliefs.bumpOut,64 // - filters.reliefs.thinEmboss,65 // - filters.reliefs.emboss,66 // - filters.reliefs.largeEmboss,67 // - filters.textures.paper,68 // - filters.textures.swirl,69 // - filters.textures.swirl2,70 // - filters.textures.gold71 // Note: the dojox/gfx/tests/test_filter.html test shows the rendering of all the predefined filters.72 }73 =====*/74 var filters = {}, defaultFilterBBox = {x:"0%", y:"0%", width:"100%", height:"100%"}, lib = {};75 //76 // A minimal facade API to create primitives77 //78 filters.createFilter = function(/*Object*/args, /*Array*/primitives){79 // summary:80 // Creates a filter with the specified primitives.81 // description:82 // This function creates a new filter object configured with the optional 'args' parameter, and83 // adds the filter primitives specified in the 'primitives' array'. The dojox/gfx/filters module84 // provides convenient methods to create the corresponding SVG filter primitives, based on the same85 // naming as the specification (e.g. filters.feGaussianBlur() ).86 // A filter primitive method follows the following signature (taking feGaussianBlur as an example):87 // filters.feGaussianBlur(/*Object*/properties, /*Array?*/children)88 // filters.feGaussianBlur(/*Array?*/children)89 // The "properties" parameter must define the primitive attributes as defined by the specification.90 // The optional "children" array parameter is an array of child filter primitives.91 // args: Object92 // The configuration object for the filter.93 // primitives: Array94 // An array of primitives object.95 var filter = lang.mixin({}, defaultFilterBBox, args);96 if(!filter.primitives){97 filter.primitives = [];98 }99 if(primitives){100 Array.prototype.push.apply(filter.primitives, primitives);101 }102 return filter; /*Object*/103 };104 var _createFePrimitive = function(tag, args, children){105 if(args instanceof Array){106 children = args;107 args = null;108 }109 var fe = lang.mixin({}, args);110 fe.children = children;111 fe.tag = tag;112 return fe;113 };114 var _createFeMerge = function(args, children){115 if(typeof args === "string"){116 // list of primitives to merge via the 'in' property117 var toMerge = [];118 for(var i=0; i<arguments.length; ++i){119 toMerge.push(filters.feMergeNode({"in":arguments[i]}));120 }121 return _createFePrimitive("feMerge", {}, toMerge);122 }123 return _createFePrimitive("feMerge", args, children);124 };125 array.forEach(["feBlend", "feColorMatrix", "feComponentTransfer", "feComposite", "feConvolveMatrix", "feDiffuseLighting",126 "feDisplacementMap", "feFlood", "feGaussianBlur", "feImage", "feMorphology", "feOffset", "feSpecularLighting",127 "feTile", "feTurbulence", "feDistantLight", "fePointLight", "feSpotLight", "feMergeNode", "feFuncA", "feFuncR",128 "feFuncG", "feFuncB"], function(fe){129 filters[fe] = function(args, children){130 return _createFePrimitive(fe, args, children);131 };132 });133 // special case for feMarge to ease syntax134 filters.feMerge = _createFeMerge;135 var createFilter = filters.createFilter;136 //137 // Convolution-based filters138 //139 lib.convolutions = [140 createFilter({_gfxName:"boxBlur3"}, [141 filters.feConvolveMatrix({142 "in":"SourceGraphic","order":3,"divisor":9,"kernelMatrix":"1,1,1,1,1,1,1,1,1"143 })144 ]),145 createFilter({_gfxName:"boxBlur5"}, [146 filters.feConvolveMatrix({147 "in":"SourceGraphic","order":5,"divisor":25,"kernelMatrix":"1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1"148 })149 ]),150 createFilter({_gfxName:"verticalEdges", filterUnits:"objectBoundingBox"}, [151 filters.feConvolveMatrix({152 "in":"SourceGraphic","result":"kernel","order":3,"divisor":1,"kernelMatrix":"-1 0 1 -1 0 1 -1 0 1"153 }),154 filters.feComponentTransfer({155 "in":"kernel"156 }, [157 filters.feFuncA({"type":"table","tableValues":"1,1"})158 ])159 ]),160 createFilter({_gfxName:"horizontalEdges", filterUnits:"objectBoundingBox"}, [161 filters.feConvolveMatrix({162 "in":"SourceGraphic","result":"kernel","order":3,"divisor":1,"kernelMatrix":"1 1 1 0 0 0 -1 -1 -1"163 }),164 filters.feComponentTransfer({165 "in":"kernel"166 }, [167 filters.feFuncA({"type":"table","tableValues":"1,1"})168 ])169 ]),170 createFilter({_gfxName:"allEdges3", filterUnits:"objectBoundingBox"}, [171 filters.feConvolveMatrix({172 "in":"SourceGraphic","result":"kernel","order":3,"divisor":1,"kernelMatrix":"-1 -1 -1 -1 8 -1 -1 -1 -1"173 }),174 filters.feComponentTransfer({175 "in":"kernel"176 },[177 filters.feFuncA({"type":"table","tableValues":"1,1"})178 ])179 ]),180 createFilter({_gfxName: "edgeEnhance", filterUnits:"objectBoundingBox"}, [181 filters.feConvolveMatrix({182 "in": "SourceGraphic","result": "kernel","order": 3,"divisor": -1,"kernelMatrix": "0 1 0 1 -5 1 0 1 0"183 }),184 filters.feComponentTransfer({185 "in": "kernel"186 },[187 filters.feFuncA({"type":"table","tableValues": "1,1"})188 ])189 ])190 ];191 array.forEach(lib.convolutions, function(f){192 lang.mixin(f, defaultFilterBBox);193 });194 //195 // Drop Shadow filters196 //197 lib.shadows = [198 createFilter({_gfxName:"fastSmallDropShadow"}, [199 filters.feColorMatrix({200 "in":"SourceAlpha","type":"matrix","result":"grey",201 "values":"0.2125,0.7154,0.0721,0,0,0.2125,0.7154,0.0721,0,0,0.2125,0.7154,0.0721,0,0,0,0,0,0.7,0"202 }),203 filters.feOffset({"dx":3,"dy":3,"result":"offsetBlur"}),204 filters.feMerge("offsetBlur", "SourceGraphic")205 ]),206 createFilter({_gfxName:"fastDropShadow"}, [207 filters.feColorMatrix({208 "in":"SourceAlpha","type":"matrix","result":"grey",209 "values":"0.2125,0.7154,0.0721,0,0,0.2125,0.7154,0.0721,0,0,0.2125,0.7154,0.0721,0,0,0,0,0,0.7,0"210 }),211 filters.feOffset({"dx":5,"dy":5,"result":"offsetBlur"}),212 filters.feMerge("offsetBlur", "SourceGraphic")213 ]),214 createFilter({_gfxName:"fastDropShadowLight"}, [215 filters.feColorMatrix({216 "in":"SourceAlpha","type":"matrix","result":"grey",217 "values":"0.2125,0.7154,0.0721,0,0,0.2125,0.7154,0.0721,0,0,0.2125,0.7154,0.0721,0,0,0,0,0,0.4,0"218 }),219 filters.feOffset({"dx":5,"dy":5,"result":"offsetBlur"}),220 filters.feMerge("offsetBlur", "SourceGraphic")221 ]),222 createFilter({_gfxName:"dropShadow"}, [223 filters.feGaussianBlur({"in":"SourceAlpha","stdDeviation":4}),224 filters.feOffset({"dx":5,"dy":5,"result":"offsetBlur"}),225 filters.feMerge("offsetBlur","SourceGraphic")226 ]),227 createFilter({_gfxName:"dropShadowLight"}, [228 filters.feGaussianBlur({"in":"SourceAlpha","stdDeviation":4,"result":"blur"}),229 filters.feComponentTransfer({230 "in":"blur","result":"lessblur"231 },[232 filters.feFuncA({"type":"linear","slope":0.5})233 ]),234 filters.feOffset({"in":"lessblur","dx":5,"dy":5,"result":"offsetBlur"}),235 filters.feMerge("offsetBlur", "SourceGraphic")236 ]),237 createFilter({_gfxName:"smallDropShadow"}, [238 filters.feGaussianBlur({"in":"SourceAlpha","stdDeviation":3}),239 filters.feOffset({"dx":2,"dy":2,"result":"offsetBlur"}),240 filters.feMerge("offsetBlur", "SourceGraphic")241 ]),242 createFilter({_gfxName:"smallDropShadowLight"}, [243 filters.feGaussianBlur({"in":"SourceAlpha","stdDeviation":3,"result":"blur"}),244 filters.feComponentTransfer({245 "in":"blur","result":"lessblur"246 },[247 filters.feFuncA({"type":"linear","slope":0.5})248 ]),249 filters.feOffset({"in":"lessblur","dx":2,"dy":2,"result":"offsetBlur"}),250 filters.feMerge("offsetBlur","SourceGraphic")251 ])252 ];253 var defaultDropShadowBBox = {254 x:"-10%",255 y:"-10%",256 width:"125%",257 height:"125%"258 };259 array.forEach(lib.shadows, function(f){260 lang.mixin(f, defaultDropShadowBBox);261 });262 //263 // Blur effects264 //265 lib.blurs = [266 createFilter({267 _gfxName: "blur1",x:"-5%",y:"-5%",width:"110%",height:"110%"268 },[269 filters.feGaussianBlur({"in":"SourceGraphic",stdDeviation:1})270 ]),271 createFilter({272 _gfxName: "blur2",x:"-15%",y:"-15%",width:"130%",height:"130%"273 },[274 filters.feGaussianBlur({"in": "SourceGraphic","stdDeviation": 2})275 ]),276 createFilter({277 _gfxName: "blur4",x:"-15%",y:"-15%",width:"130%",height:"130%"278 },[279 filters.feGaussianBlur({"in": "SourceGraphic","stdDeviation": 4})280 ]),281 createFilter({282 _gfxName: "blur8",x:"-20%",y:"-20%",width:"140%",height:"140%"283 },[284 filters.feGaussianBlur({"in": "SourceGraphic","stdDeviation": 8})285 ]),286 createFilter({287 _gfxName: "glow",x:"-10%",y:"-10%",width:"120%",height:"120%"288 },[289 filters.feGaussianBlur({"in": "SourceGraphic","stdDeviation": 2}),290 filters.feComponentTransfer([291 filters.feFuncA({"type":"linear","slope":10})292 ])293 ])294 ];295 //296 // Colors filters297 //298 lib.colors = [299 createFilter({_gfxName:"negate"}, [300 filters.feComponentTransfer([301 filters.feFuncR({"type":"table","tableValues":"1,0"}),302 filters.feFuncG({"type":"table","tableValues":"1,0"}),303 filters.feFuncB({"type":"table","tableValues":"1,0"})304 ])305 ]),306 createFilter({_gfxName:"sepia"}, [307 filters.feColorMatrix({308 "result":"grey",309 "values":"0.2125,0.7154,0.0721,0,0,0.2125,0.7154,0.0721,0,0,0.2125,0.7154,0.0721,0,0,0,0,0,1,0"310 }),311 filters.feComponentTransfer({312 "in":"grey"313 },[314 filters.feFuncR({"type":"linear","slope":0.5,"intercept":0.5}),315 filters.feFuncB({"type":"table","tableValues":"0,0"})316 ])317 ]),318 createFilter({_gfxName:"grayscale"}, [319 filters.feColorMatrix({320 "values":"0.2125,0.7154,0.0721,0,0,0.2125,0.7154,0.0721,0,0,0.2125,0.7154,0.0721,0,0,0,0,0,1,0"321 })322 ]),323 createFilter({_gfxName:"showRed"}, [324 filters.feComponentTransfer([325 filters.feFuncG({"type":"table","tableValues":"0,0"}),326 filters.feFuncB({"type":"table","tableValues":"0,0"})327 ])328 ]),329 createFilter({_gfxName:"showGreen"}, [330 filters.feComponentTransfer([331 filters.feFuncR({"type":"table","tableValues":"0,0"}),332 filters.feFuncB({"type":"table","tableValues":"0,0"})333 ])334 ]),335 createFilter({_gfxName:"showBlue"}, [336 filters.feComponentTransfer([337 filters.feFuncR({"type":"table","tableValues":"0,0"}),338 filters.feFuncG({"type":"table","tableValues":"0,0"})339 ])340 ]),341 createFilter({_gfxName:"hueRotate60"}, [342 filters.feColorMatrix({"type":"hueRotate","values":60})343 ]),344 createFilter({_gfxName:"hueRotate120"}, [345 filters.feColorMatrix({"type":"hueRotate","values":120})346 ]),347 createFilter({_gfxName:"hueRotate180"}, [348 filters.feColorMatrix({"type":"hueRotate","values":180})349 ]),350 createFilter({_gfxName:"hueRotate270"}, [351 filters.feColorMatrix({"type":"hueRotate","values":270})352 ])353 ];354 array.forEach(lib.colors, function(f){355 lang.mixin(f, defaultFilterBBox);356 });357 lib.miscs = [358 createFilter({359 _gfxName:"thinEmbossDropShadow",360 x:"-5%",y:"-5%",width:"120%",height:"120%"361 }, [362 filters.feGaussianBlur({"in":"SourceAlpha","stdDeviation":1,"result":"blur"}),363 filters.feOffset({"in":"blur",dx:6,dy:6,"result":"offsetBlur"}),364 filters.feSpecularLighting({365 "in":"blur","surfaceScale":8,"specularConstant":1,"specularExponent":12,"result":"specOut"366 }, [367 filters.fePointLight({x:"-5000",y:"-10000",z:"12000"})368 ]),369 filters.feComposite({"in":"specOut","in2":"SourceAlpha","operator":"in","result":"specOut"}),370 filters.feComposite({371 "in":"SourceGraphic","in2":"specOut","operator":"arithmetic","result":"litPaint",372 "k1":0,"k2":1,"k3":1,"k4":0}),373 filters.feMerge("offsetBlur", "litPaint")374 ]),375 createFilter({376 _gfxName:"embossDropShadow",377 x:"-5%",y:"-5%",width:"120%",height:"120%"378 }, [379 filters.feGaussianBlur({"in": "SourceAlpha","stdDeviation":"4","result":"blur"}),380 filters.feOffset({"in":"blur","dx":4,"dy":4,"result":"offsetBlur"}),381 filters.feSpecularLighting({382 "in":"blur","surfaceScale":5,"specularConstant":0.75,"specularExponent":20,383 "lighting-color":"#bbbbbb","result":"specOut"384 }, [filters.fePointLight({x:-5000,y:-10000,z:20000})]),385 filters.feComposite({"in":"specOut","in2":"SourceAlpha","operator":"in","result":"specOut"}),386 filters.feComposite({387 "in":"SourceGraphic","in2":"specOut","operator":"arithmetic",k1:0,k2:1,k3:1,k4:0,"result":"litPaint"388 }),389 filters.feMerge("offsetBlur","litPaint")390 ]),391 createFilter({392 _gfxName:"largeEmbossDropShadow",393 x:"-20%",y:"-20%",width:"140%",height:"140%"394 }, [395 filters.feGaussianBlur({"in":"SourceAlpha","stdDeviation":5,"result":"blur"}),396 filters.feOffset({"in":"blur",dx:6,dy:6,"result":"offsetBlur"}),397 filters.feSpecularLighting({398 "in":"blur","surfaceScale":8,"specularConstant":1,"specularExponent":12,"result":"spec"399 },[400 filters.fePointLight({x:"-5000",y:"-10000",z:"12000"})401 ]),402 filters.feComposite({"in":"spec","in2":"SourceGraphic","operator":"in","result":"specOut"}),403 filters.feComposite({404 "in":"SourceGraphic","in2":"specOut","operator":"arithmetic","result":"litPaint",405 "k1":0,"k2":1,"k3":1,"k4":0406 }),407 filters.feMerge("offsetBlur", "litPaint")408 ]),409 createFilter({410 _gfxName:"thinEmbossDropShadowLight",411 x:"-5%",y:"-5%",width:"120%",height:"120%"412 }, [413 filters.feGaussianBlur({"in":"SourceAlpha","stdDeviation":1,"result":"blur"}),414 filters.feComponentTransfer({"in":"blur",result:"lessblur"415 },[416 filters.feFuncA({type:"linear",slope:"0.5"})417 ]),418 filters.feOffset({"in":"lessblur","dx":"6","dy":"6","result":"offsetBlur"}),419 filters.feSpecularLighting({420 "in":"lessblur","surfaceScale":8,"specularConstant":1,"specularExponent":"12","result":"specOut"421 },[422 filters.fePointLight({x:"-5000",y:"-10000",z:"12000"})423 ]),424 filters.feComposite({"in":"specOut","in2":"SourceAlpha","operator":"in","result":"specOut"}),425 filters.feComposite({426 "in":"SourceGraphic","in2":"specOut","result":"litPaint","operator":"arithmetic",427 "k1":0,"k2":1,"k3":1,"k4":0428 }),429 filters.feMerge("offsetBlur", "litPaint")430 ]),431 createFilter({432 _gfxName: "embossDropShadowLight",433 x: "-5%",y: "-5%",width: "120%",height: "120%"434 }, [435 filters.feGaussianBlur({"in": "SourceAlpha",stdDeviation:"3",result:"blur"}),436 filters.feComponentTransfer({437 "in": "blur",result: "lessblur"438 },[439 filters.feFuncA({type: "linear",slope: "0.5"})440 ]),441 filters.feOffset({"in": "lessblur",dx: "6",dy: "6",result: "offsetBlur"}),442 filters.feSpecularLighting({443 "in": "lessblur",surfaceScale: "8",specularConstant: "1",specularExponent: "12",result: "specOut"444 },[445 filters.fePointLight({x: "-5000",y: "-10000",z: "12000"})446 ]),447 filters.feComposite({"in": "specOut",in2: "SourceAlpha",operator: "in",result: "specOut"}),448 filters.feComposite({449 "in": "SourceGraphic",in2: "specOut",result: "litPaint",operator: "arithmetic",450 k1: "0",k2: "1",k3: "1",k4: "0"451 }),452 filters.feMerge("offsetBlur", "litPaint")453 ]),454 createFilter({455 _gfxName: "largeEmbossDropShadowLight",456 x: "-20%",y: "-20%",width: "140%",height: "140%"457 },[458 filters.feGaussianBlur({"in": "SourceAlpha",stdDeviation: "5",result: "blur"}),459 filters.feComponentTransfer({"in": "blur",result: "lessblur"460 },[461 filters.feFuncA({type: "linear",slope: "0.5"})462 ]),463 filters.feOffset({"in": "lessblur",dx: "6",dy: "6",result: "offsetBlur"}),464 filters.feSpecularLighting({465 "in": "blur",surfaceScale: "8",specularConstant: "1",specularExponent: "12",result: "spec"466 },[467 filters.fePointLight({x: "-5000",y: "-10000",z: "12000"})468 ]),469 filters.feComposite({"in": "spec",in2: "SourceGraphic",operator: "in",result: "specOut"}),470 filters.feComposite({471 "in": "SourceGraphic",in2: "specOut",operator: "arithmetic",k1: "0",k2: "1",k3: "1",k4: "0",472 result: "litPaint"473 }),474 filters.feMerge("offsetBlur", "litPaint")475 ]),476 createFilter({477 _gfxName:"fuzzy",478 x:"-10%", y:"-10%", width:"120%", height:"120%"479 },[480 filters.feTurbulence({type:"fractalNoise",baseFrequency:"0.1",numOctaves:"1",result:"turb2"}),481 filters.feDisplacementMap({482 "in":"SourceGraphic",in2:"turb2",result:"turb2",scale:"20",xChannelSelector:"R",yChannelSelector:"G"483 })484 ]),485 createFilter({486 _gfxName:"veryFuzzy",487 x:"-20%", y:"-20%", width:"140%", height:"140%"488 },[489 filters.feTurbulence({type:"fractalNoise",baseFrequency:"0.1",numOctaves:"1",result:"turb2"}),490 filters.feDisplacementMap({491 "in":"SourceGraphic",in2:"turb2",result:"turb2",scale:"35",xChannelSelector:"R",yChannelSelector:"G"492 })493 ]),494 createFilter({495 _gfxName:"melting",496 x:"-10%", y:"-10%", width:"120%", height:"120%"497 }, [498 filters.feTurbulence({type:"fractalNoise",baseFrequency:"0.1",numOctaves:"2",result:"turb"}),499 filters.feDisplacementMap({500 result:"bended","in":"SourceGraphic",in2:"turb",scale:"25",xChannelSelector:"R",yChannelSelector:"G"501 }),502 filters.feGaussianBlur({"in":"bended",stdDeviation:"1",result:"bb"}),503 filters.feComponentTransfer({"in": "bb",result: "BendedSource"504 },[505 filters.feFuncA({type: "linear",slope: 10,intercept: "-1"})506 ]),507 filters.feComponentTransfer({508 "in": "BendedSource",509 result: "BendedAlpha"510 }, [511 filters.feFuncR({ type: "linear", slope: "0", intercept: "0"}),512 filters.feFuncG({ type: "linear", slope: "0", intercept: "0"}),513 filters.feFuncB({ type: "linear", slope: "0", intercept: "0"}),514 filters.feFuncA({ type: "linear", slope: "1", intercept: "0"})515 ]),516 filters.feGaussianBlur({517 "in": "BendedAlpha", stdDeviation: "1", result: "blur"518 }),519 filters.feSpecularLighting({520 "in": "blur","lighting-color": "rgb(80%, 80%, 80%)","surfaceScale": "5",521 specularConstant: "1",specularExponent: "10",result: "specularOut"522 },[523 filters.fePointLight({ x: "-5000", y: "-10000", z: "20000"})524 ]),525 filters.feComposite({526 "in": "specularOut", in2: "BendedAlpha", operator: "in", result: "specularOut"527 }),528 filters.feComposite({529 "in": "BendedSource",in2: "specularOut",operator: "arithmetic",k1: "0", k2: "1", k3: "1", k4: "0",530 result: "litPaint"531 })532 ]),533 createFilter({534 _gfxName:"impressionist", x:"0%", y:"0%", width:"100%", height:"100%"535 },[536 filters.feMorphology({537 "in":"SourceGraphic", operator:"dilate", radius:"2"538 })539 ]),540 createFilter({541 _gfxName:"holes", x:"0%", y:"0%", width:"100%", height:"100%"542 },[543 filters.feTurbulence({544 type:"fractalNoise", baseFrequency:"0.1", numOctaves:"1", result:"texture"545 }),546 filters.feComponentTransfer({547 "in":"texture", result:"holes"548 },[549 filters.feFuncA({type:"discrete", tableValues:"0,1"})550 ]),551 filters.feComposite({552 "in":"SourceGraphic", in2:"holes", operator:"out"553 })554 ]),555 createFilter({556 _gfxName:"holesComplement", x:"0%", y:"0%", width:"100%", height:"100%"557 },[558 filters.feTurbulence({559 type:"fractalNoise", baseFrequency:"0.1", numOctaves:"1", result:"texture"560 }),561 filters.feComponentTransfer({562 "in":"texture", result:"holes"563 },[564 filters.feFuncA({ type:"discrete", tableValues:"1,0"})565 ]),566 filters.feComposite({"in":"SourceGraphic", in2:"holes", operator:"out"})567 ])568 ];569 570 lib.reliefs = [571 createFilter({572 _gfxName:"bumpIn", x:"0%", y:"0%", width:"100%", height:"100%"573 },[574 filters.feColorMatrix({"in":"SourceGraphic", type:"luminanceToAlpha",result:"lumalpha"}),575 filters.feComponentTransfer({576 "in":"lumalpha", result:"invertedalpha"577 },[578 filters.feFuncA({ type:"table",tableValues:"1,0"})579 ]),580 filters.feDiffuseLighting({581 "in":"invertedalpha","lighting-color":"rgb(60%, 60%, 60%)",result:"diffuse",surfaceScale:"5"582 },[583 filters.feDistantLight({ azimuth:"135",elevation:"60"})584 ]),585 filters.feSpecularLighting({586 "in":"invertedalpha", result:"specular", surfaceScale:"5",specularExponent:"6"587 },[588 filters.feDistantLight({ azimuth:"135",elevation:"30"})589 ]),590 filters.feComposite({ "in":"diffuse",in2:"specular",operator:"arithmetic",k2:"1.0",k3:"1.0"})591 ]),592 createFilter({593 _gfxName:"bumpOut", x:"0%", y:"0%", width:"100%", height:"100%"594 },[595 filters.feColorMatrix({ "in":"SourceGraphic", type:"luminanceToAlpha", result:"lumalpha"}),596 filters.feDiffuseLighting({597 "in":"lumalpha", "lighting-color":"rgb(60%, 60%, 60%)", result:"diffuse", surfaceScale:"5"598 },[599 filters.feDistantLight({ azimuth:"135", elevation:"60"})600 ]),601 filters.feSpecularLighting({602 "in":"lumalpha", result:"specular", surfaceScale:"5", specularExponent:"6"603 },[604 filters.feDistantLight({ azimuth:"135", elevation:"30"})605 ]),606 filters.feComposite({ "in":"diffuse", in2:"specular", operator:"arithmetic", k2:"1.0", k3:"1.0"})607 ]),608 createFilter({609 _gfxName:"thinEmboss", x:"-5%", y:"-5%", width:"110%", height:"110%"610 },[611 filters.feGaussianBlur({ "in":"SourceAlpha", stdDeviation:"1", result:"blur"}),612 filters.feSpecularLighting({613 "in":"blur", surfaceScale:"8", specularConstant:"1", specularExponent:"12", result:"specOut"614 },[615 filters.fePointLight({ x:"-5000", y:"-10000", z:"12000"})616 ]),617 filters.feComposite({ "in":"specOut", in2:"SourceAlpha", operator:"in", result:"specOut"}),618 filters.feComposite({619 "in":"SourceGraphic", in2:"specOut", operator:"arithmetic", k1:"0", k2:"1", k3:"1", k4:"0"620 })621 ]),622 createFilter({623 _gfxName:"emboss", x:"-5%", y:"-5%", width:"110%", height:"110%"624 },[625 filters.feGaussianBlur({ "in":"SourceAlpha", stdDeviation:"3", result:"blur"}),626 filters.feSpecularLighting({627 "in":"blur", surfaceScale:"8", specularConstant:"1", specularExponent:"12", result:"specOut"628 },[629 filters.fePointLight({ x:"-5000", y:"-10000", z:"12000"})630 ]),631 filters.feComposite({ "in":"specOut", in2:"SourceAlpha", operator:"in", result:"specOut"}),632 filters.feComposite({633 "in":"SourceGraphic", in2:"specOut", operator:"arithmetic", k1:"0", k2:"1", k3:"1", k4:"0"634 })635 ]),636 createFilter({637 _gfxName:"largeEmboss", x:"-5%", y:"-5%", width:"110%", height:"110%"638 },[639 filters.feGaussianBlur({ "in":"SourceAlpha", stdDeviation:"5", result:"blur"}),640 filters.feSpecularLighting({641 "in":"blur", surfaceScale:"8", specularConstant:"1", specularExponent:"12", result:"specOut"642 },[643 filters.fePointLight({ x:"-5000", y:"-10000", z:"12000"})644 ]),645 filters.feComposite({ "in":"specOut", in2:"SourceAlpha", operator:"in", result:"specOut"}),646 filters.feComposite({647 "in":"SourceGraphic", in2:"specOut", operator:"arithmetic", k1:"0", k2:"1", k3:"1", k4:"0"648 })649 ])650 ];651 652 lib.textures = [653 createFilter({654 _gfxName: "paper", x:"0%", y:"0%", width:"100%", height:"100%"655 },[656 filters.feTurbulence({ type:"turbulence", baseFrequency:"0.01", numOctaves:"5",result:"texture"}),657 filters.feDiffuseLighting({658 "in":"texture", result:"diffuse", surfaceScale:"-10"659 },[660 filters.feDistantLight({ azimuth:"135", elevation:"60"})661 ]),662 filters.feComposite({ "in":"diffuse", in2:"SourceGraphic", operator:"arithmetic", k1:"1", k2:"0", k3:"0", k4:"0"})663 ]),664 createFilter({665 _gfxName:"swirl", x:"0%", y:"0%", width:"100%", height:"100%"666 },[667 filters.feTurbulence({ type:"turbulence",baseFrequency:"0.05",numOctaves:"1",result:"texture"}),668 filters.feDiffuseLighting({669 "in":"texture",result:"diffuse",surfaceScale:"-10"670 },[671 filters.feDistantLight({ azimuth:"135",elevation:"60"})672 ]),673 filters.feComposite({"in":"diffuse",in2:"SourceGraphic",operator:"arithmetic",k1:"1",k2:"0",k3:"0",k4:"0"})674 ]),675 createFilter({676 _gfxName:"swirl2", x:"0%", y:"0%", width:"100%", height:"100%"677 },[678 filters.feTurbulence({ type:"turbulence",baseFrequency:"0.15",numOctaves:"1",result:"texture"}),679 filters.feDiffuseLighting({680 "in":"texture",result:"diffuse",surfaceScale:"-10"681 },[682 filters.feDistantLight({ azimuth:"135",elevation:"60"})683 ]),684 filters.feComposite({"in":"diffuse",in2:"SourceGraphic",operator:"arithmetic",k1:"1",k2:"0",k3:"0",k4:"0"})685 ]),686 createFilter({687 _gfxName:"gold", x:"-5%", y:"-5%", width:"115%", height:"110%"688 },[689 filters.feTurbulence({ baseFrequency:"0.2", numOctaves:"1", type:"turbulence", result:"turb"}),690 filters.feComposite({691 "in":"SourceGraphic", in2:"turb", operator:"arithmetic", k2:"0.6", k3:"0.4", result:"turb"692 }),693 filters.feComposite({ "in":"turb", in2:"SourceGraphic", operator:"in", result:"bump"}),694 filters.feDiffuseLighting({695 "in":"turb", surfaceScale:"6.0", "lighting-color":"rgb(60%, 50%, 0%)", diffuseConstant:"1.0", result:"diffuse"696 },[697 filters.feDistantLight({ azimuth:"135", elevation:"60"})698 ]),699 filters.feSpecularLighting({700 "in":"bump", surfaceScale:"6.0", specularConstant:"1.0", specularExponent:"10.0", result:"specularOut"...
createFilter.ts
Source:createFilter.ts
...3import { createFilter, normalizePath } from '../';4const resolve = (...parts: string[]) => normalizePath(rawResolve(...parts));5test.beforeEach(() => process.chdir(__dirname));6test('includes by default', (t) => {7 const filter = createFilter();8 t.truthy(filter(resolve('x')));9});10test('excludes IDs that are not included, if include.length > 0', (t) => {11 const filter = createFilter(['y']);12 t.falsy(filter(resolve('x')));13 t.truthy(filter(resolve('y')));14});15test('excludes IDs explicitly', (t) => {16 const filter = createFilter(null, ['y']);17 t.truthy(filter(resolve('x')));18 t.falsy(filter(resolve('y')));19});20test('handles non-array arguments', (t) => {21 const filter = createFilter('foo/*', 'foo/baz');22 t.truthy(filter(resolve('foo/bar')));23 t.falsy(filter(resolve('foo/baz')));24});25test('negation patterns', (t) => {26 const filter = createFilter(['a/!(b)/c']);27 t.truthy(filter(resolve('a/d/c')));28 t.falsy(filter(resolve('a/b/c')));29});30test('excludes non-string IDs', (t) => {31 const filter = createFilter(null, null);32 t.falsy(filter({}));33});34test('excludes strings beginning with NUL', (t) => {35 const filter = createFilter(null, null);36 t.falsy(filter('\0someid'));37});38test('includes with regexp', (t) => {39 const filter = createFilter(['a/!(b)/c', /\.js$/]);40 t.truthy(filter(resolve('a/d/c')));41 t.falsy(filter(resolve('a/b/c')));42 t.truthy(filter(resolve('a.js')));43 t.truthy(filter(resolve('a/b.js')));44 t.falsy(filter(resolve('a/b.jsx')));45});46test('excludes with regexp', (t) => {47 const filter = createFilter(['a/!(b)/c', /\.js$/], /\.js$/);48 t.truthy(filter(resolve('a/d/c')));49 t.falsy(filter(resolve('a/b/c')));50 t.falsy(filter(resolve('a.js')));51 t.falsy(filter(resolve('a/b.js')));52 t.falsy(filter(resolve('a/b.jsx')));53});54test('allows setting an absolute base dir', (t) => {55 const baseDir = resolve('C');56 const filter = createFilter(['y*'], ['yx'], { resolve: baseDir });57 t.falsy(filter(`${baseDir}/x`));58 t.truthy(filter(`${baseDir}/ys`));59 t.falsy(filter(`${baseDir}/yx`));60 t.falsy(filter(resolve('C/d/ys')));61 t.falsy(filter(resolve('ys')));62 t.falsy(filter('ys'));63});64test('allows setting a relative base dir', (t) => {65 const filter = createFilter(['y*'], ['yx'], { resolve: 'C/d' });66 t.falsy(filter(resolve('C/d/x')));67 t.truthy(filter(resolve('C/d/ys')));68 t.falsy(filter(resolve('C/d/yx')));69 t.falsy(filter(`${resolve('C')}/ys`));70 t.falsy(filter(resolve('ys')));71 t.falsy(filter('ys'));72});73test('ignores a falsy resolve value', (t) => {74 const filter = createFilter(['y*'], ['yx'], { resolve: null });75 t.falsy(filter(resolve('x')));76 t.truthy(filter(resolve('ys')));77 t.falsy(filter(resolve('yx')));78 t.falsy(filter(`${resolve('C')}/ys`));79 t.falsy(filter(resolve('C/d/ys')));80 t.falsy(filter('ys'));81});82test('allows preventing resolution against process.cwd()', (t) => {83 const filter = createFilter(['y*'], ['yx'], { resolve: false });84 t.falsy(filter('x'));85 t.truthy(filter('ys'));86 t.falsy(filter('yx'));87 t.falsy(filter(`${resolve('C')}/ys`));88 t.falsy(filter(resolve('C/d/ys')));89 t.falsy(filter(resolve('ys')));90});91test('includes names starting with a "."', (t) => {92 const filter = createFilter(['**/*a']);93 t.truthy(filter(resolve('.a')));94 t.truthy(filter(resolve('.x/a')));95});96test.serial('includes names containing parenthesis', (t) => {97 process.chdir(resolve(__dirname, 'fixtures/folder-with (parens)'));98 const filter = createFilter(['*.ts+(|x)', '**/*.ts+(|x)'], ['*.d.ts', '**/*.d.ts']);99 t.truthy(filter(resolve('folder (test)/src/main.tsx')));100 t.truthy(filter(resolve('.x/(test)a.ts')));101 t.falsy(filter(resolve('.x/(test)a.d.ts')));102});103test('handles relative paths', (t) => {104 const filter = createFilter(['./index.js', './foo/../a.js']);105 t.truthy(filter(resolve('index.js')));106 t.truthy(filter(resolve('a.js')));107 t.falsy(filter(resolve('foo/a.js')));108});109test('does not add current working directory when pattern is an absolute path', (t) => {110 const filter = createFilter([resolve('..', '..', '*')]);111 t.truthy(filter(resolve('..', '..', 'a')));112 t.truthy(filter(resolve('..', '..', 'b')));113 t.falsy(filter(resolve('..', 'c')));114});115test('does not add current working directory when pattern starts with a glob', (t) => {116 const filter = createFilter(['**/*']);117 t.truthy(filter(resolve('a')));118 t.truthy(filter(resolve('..', '..', 'a')));...
Using AI Code Generation
1var editor = CKEDITOR.replace( 'editor1', {2} );3editor.on( 'instanceReady', function( evt ) {4 var editor = evt.editor;5 var filter = editor.filter;6 var pattern = filter.createTextPattern( /foo/ );7 pattern.match = function( text, offset, data ) {8 };9} );10var editor = CKEDITOR.replace( 'editor1', {11} );12editor.on( 'instanceReady', function( evt ) {13 var editor = evt.editor;14 var filter = editor.filter;15 var pattern = filter.createTextPattern( /foo/ );16 pattern.match = function( text, offset, data ) {17 };18} );19var editor = CKEDITOR.replace( 'editor1', {20} );21editor.on( 'instanceReady', function( evt ) {22 var editor = evt.editor;23 var filter = editor.filter;24 var pattern = filter.createTextPattern( /foo/ );25 pattern.match = function( text, offset, data ) {26 };27} );28var editor = CKEDITOR.replace( 'editor1', {29} );30editor.on( 'instanceReady', function( evt ) {31 var editor = evt.editor;32 var filter = editor.filter;33 var pattern = filter.createTextPattern( /foo/ );34 pattern.match = function( text, offset, data ) {35 };36} );37var editor = CKEDITOR.replace( 'editor1', {38} );39editor.on( 'instanceReady', function( evt ) {40 var editor = evt.editor;41 var filter = editor.filter;42 var pattern = filter.createTextPattern(
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var filter = wptoolkit.createFilter();3filter.addFilter('post_type', 'post');4filter.addFilter('post_status', 'publish');5filter.addFilter('posts_per_page', 10);6console.log(filter.getFilterString());7var wptoolkit = require('wptoolkit');8var filter = wptoolkit.createFilter();9filter.addFilter('post_type', 'post');10filter.addFilter('post_status', 'publish');11filter.addFilter('posts_per_page', 10);12console.log(filter.getFilterString());13var wptoolkit = require('wptoolkit');14var filter = wptoolkit.createFilter();15filter.addFilter('post_type', 'post');16filter.addFilter('post_status', 'publish');17filter.addFilter('posts_per_page', 10);18console.log(filter.getFilterString());19var wptoolkit = require('wptoolkit');20var filter = wptoolkit.createFilter();21filter.addFilter('post_type', 'post');22filter.addFilter('post_status', 'publish');23filter.addFilter('posts_per_page', 10);24console.log(filter.getFilterString());25var wptoolkit = require('wptoolkit');26var filter = wptoolkit.createFilter();27filter.addFilter('post_type', 'post');28filter.addFilter('post_status', 'publish');29filter.addFilter('posts_per_page', 10);30console.log(filter.getFilterString());
Using AI Code Generation
1var wptoolkit = require('wptoolkit');2var filter = wptoolkit.createFilter();3filter.set('post_type', 'page');4filter.set('post_status', 'publish');5filter.set('post_parent', 0);6filter.set('posts_per_page', 5);7filter.set('order', 'DESC');8filter.set('orderby', 'date');9filter.set('post__in', [1,2,3,4,5,6]);10filter.set('post__not_in', [1,2,3,4,5,6]);11filter.set('post__in', [1,2,3,4,5,6]);12filter.set('post__not_in', [1,2,3,4,5,6]);13filter.set('post_name__in', ['name1','name2','name3']);14filter.set('post_name__not_in', ['name1','name2','name3']);15filter.set('post_parent__in', [1,2,3,4,5,6]);16filter.set('post_parent__not_in', [1,2,3,4,5,6]);17filter.set('post_author__in', [1,2,3,4,5,6]);18filter.set('post_author__not_in', [1,2,3,4,5,6]);19filter.set('post_date__in', ['2015-02-01 00:00:00','2015-02-02 00:00:00']);20filter.set('post_date__not_in', ['2015-02-01 00:00:00','2015-02-02 00:00:00']);21filter.set('post_date__before', '2015-02-01 00:00:00');22filter.set('post_date__after', '2015-02-02 00:00:00');23filter.set('post_modified__in', ['2015-02-01 00:00:00','2015-02-02 00:00:00']);24filter.set('post_modified__not_in', ['2015-02-01 00:00:00','2015-02-02 00:00:00']);25filter.set('post_modified__before', '2015-02-01 00:00:00
Using AI Code Generation
1var page = require('webpage').create();2var fs = require('fs');3filter.onRequest = function(requestData, networkRequest) {4 console.log('Request to ' + requestData.url);5};6filter.onResponse = function(responseData) {7 console.log('Response to ' + responseData.url);8};9page.onResourceReceived = function(response) {10 console.log('Response (#' + response.id + ', stage "' + response.stage + '"): ' + JSON.stringify(response));11};12page.onResourceRequested = function(requestData, networkRequest) {13 console.log('Request (#' + requestData.id + '): ' + JSON.stringify(requestData));14};15page.open(url, function(status) {16 console.log("Status: " + status);17 if(status === "success") {18 page.render('example.png');19 }20 phantom.exit();21});
Using AI Code Generation
1var wptools = require('wptools');2var filter = wptools.createFilter();3filter.add('filter1', function (page, callback) {4 callback(null, page);5});6filter.add('filter2', function (page, callback) {7 callback(null, page);8});9var wptools = require('wptools');10var filter = wptools.createFilter();11filter.add('filter1', function (page, callback) {12 callback(null, page);13});14filter.add('filter2', function (page, callback) {15 callback(null, page);16});17var wptools = require('wptools');18var filter = wptools.createFilter();19filter.add('filter1', function (page, callback) {20 callback(null, page);21});22filter.add('filter2', function (page, callback) {23 callback(null, page);24});25var wptools = require('wptools');26var filter = wptools.createFilter();27filter.add('filter1', function (page, callback) {28 callback(null, page);29});30filter.add('filter2', function (page, callback) {31 callback(null, page);32});33var wptools = require('wptools');34var filter = wptools.createFilter();35filter.add('filter1', function (page, callback) {36 callback(null, page);37});38filter.add('filter2', function (page, callback) {39 callback(null, page);40});41var wptools = require('wptools');42var filter = wptools.createFilter();43filter.add('filter1', function (page, callback) {44 callback(null, page);45});46filter.add('filter2', function (page, callback) {
Using AI Code Generation
1var data = require('./data.json');2var wptools = require('wptools');3var filter = wptools.createFilter();4filter.addCondition('age', '>', 30);5filter.addCondition('age', '<', 50);6var filteredData = filter.filter(data);7console.log(filteredData);8[{ name: 'John', age: 32, city: 'New York' },9 { name: 'Peter', age: 45, city: 'Paris' }]10var data = require('./data.json');11var wptools = require('wptools');12var filter = wptools.createFilter();13filter.addCondition('age', '>', 30);14filter.addCondition('age', '<', 50);15var filteredData = filter.filter(data);16console.log(filteredData);17[{ name: 'John', age: 32, city: 'New York' },18 { name: 'Peter', age: 45, city: 'Paris' }]
Using AI Code Generation
1var wpt = require('webpagetest');2var test = wpt('www.webpagetest.org');3test.createFilter('label', 'location', 'connection', 'cache', 'auth', 'private', 'block', 'throttle', 'custom', 'script', function(err, data) {4console.log(data);5});6var wpt = require('webpagetest');7var test = wpt('www.webpagetest.org');8test.getLocations(function(err, data) {9console.log(data);10});11var wpt = require('webpagetest');12var test = wpt('www.webpagetest.org');13test.getTesters(function(err, data) {14console.log(data);15});16var wpt = require('webpagetest');17var test = wpt('www.webpagetest.org');18test.getTesters(function(err, data) {19console.log(data);20});21var wpt = require('webpagetest');22var test = wpt('www.webpagetest.org');23test.getTesters(function(err, data) {24console.log(data);25});26var wpt = require('webpagetest');27var test = wpt('www.webpagetest.org');28test.getTesters(function(err, data) {29console.log(data);30});31var wpt = require('webpagetest');32var test = wpt('www.webpagetest.org');33test.getTesters(function(err, data) {34console.log(data);35});36var wpt = require('webpagetest');37var test = wpt('www.webpagetest.org');38test.getTesters(function(err, data) {39console.log(data);40});41var wpt = require('webpagetest');42var test = wpt('www.webpagetest.org');43test.getTesters(function(err, data
Using AI Code Generation
1var wpt = require('webpagetest');2var options = {3};4wpt.createFilter(options, function(err, data) {5 if (err) {6 console.log(err);7 } else {8 console.log(data);9 }10});11var wpt = require('webpagetest');12wpt.getLocations(function(err, data) {13 if (err) {14 console.log(err);15 } else {16 console.log(data);17 }18});19var wpt = require('webpagetest');20wpt.getLocations(function(err, data) {21 if (err) {22 console.log(err);23 } else {24 console.log(data);25 }26});27var wpt = require('webpagetest');28wpt.getTesters(function(err, data) {29 if (err) {30 console.log(err);31 } else {32 console.log(data);33 }34});35var wpt = require('webpagetest');36wpt.getTesters(function(err, data) {37 if (err) {38 console.log(err);39 } else {40 console.log(data);41 }42});43var wpt = require('webpagetest');44wpt.getTesters(function(err, data) {45 if (err) {46 console.log(err);47 } else {48 console.log(data);49 }50});51var wpt = require('webpagetest');52wpt.getTesters(function(err, data) {53 if (err) {54 console.log(err);55 } else {
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!!