How to use _hideHighlight method in Playwright Internal

Best JavaScript code snippet using playwright-internal

D3SymbolTreeMap.js

Source:D3SymbolTreeMap.js Github

copy

Full Screen

...238 this._doLayout();239}240D3SymbolTreeMap.prototype._zoomDatum = function(datum) {241 if (this._currentRoot === datum) return; // already here242 this._hideHighlight(datum);243 this._hideInfoBox(datum);244 this._currentRoot = datum;245 this._currentNodes = this._layout.nodes(this._currentRoot);246 this._currentMaxDepth = this._currentRoot.depth + this._maxLevelsToShow;247 console.log('zooming into datum ' + this._currentRoot.n);248 this._doLayout();249}250D3SymbolTreeMap.prototype.setMaxLevels = function(levelsToShow) {251 this._maxLevelsToShow = levelsToShow;252 this._currentNodes = this._layout.nodes(this._currentRoot);253 this._currentMaxDepth = this._currentRoot.depth + this._maxLevelsToShow;254 console.log('setting max levels to show: ' + this._maxLevelsToShow);255 this._doLayout();256}257/**258 * Clone the specified tree, returning an independent copy of the data.259 * Only the original attributes expected to exist prior to invoking260 * _crunchStatsHelper are retained, with the exception of the 'id' attribute261 * (which must be retained for proper transitions).262 * If the optional filter parameter is provided, it will be called with 'this'263 * set to this treemap instance and passed the 'datum' object as an argument.264 * When specified, the copy will retain only the data for which the filter265 * function returns true.266 */267D3SymbolTreeMap.prototype._clone = function(datum, filter) {268 var trackingStats = false;269 if (this.__cloneState === undefined) {270 console.time('_clone');271 trackingStats = true;272 this.__cloneState = {'accepted': 0, 'rejected': 0,273 'forced': 0, 'pruned': 0};274 }275 // Must go depth-first. All parents of children that are accepted by the276 // filter must be preserved!277 var copy = {'n': datum.n, 'k': datum.k};278 var childAccepted = false;279 if (datum.children !== undefined) {280 for (var i = 0; i < datum.children.length; i++) {281 var copiedChild = this._clone(datum.children[i], filter);282 if (copiedChild !== undefined) {283 childAccepted = true; // parent must also be accepted.284 if (copy.children === undefined) copy.children = [];285 copy.children.push(copiedChild);286 }287 }288 }289 // Ignore nodes that don't match the filter, when present.290 var accept = false;291 if (childAccepted) {292 // Parent of an accepted child must also be accepted.293 this.__cloneState.forced++;294 accept = true;295 } else if (filter !== undefined && filter.call(this, datum) !== true) {296 this.__cloneState.rejected++;297 } else if (datum.children === undefined) {298 // Accept leaf nodes that passed the filter299 this.__cloneState.accepted++;300 accept = true;301 } else {302 // Non-leaf node. If no children are accepted, prune it.303 this.__cloneState.pruned++;304 }305 if (accept) {306 if (datum.id !== undefined) copy.id = datum.id;307 if (datum.lastPathElement !== undefined) {308 copy.lastPathElement = datum.lastPathElement;309 }310 if (datum.t !== undefined) copy.t = datum.t;311 if (datum.value !== undefined && datum.children === undefined) {312 copy.value = datum.value;313 }314 } else {315 // Discard the copy we were going to return316 copy = undefined;317 }318 if (trackingStats === true) {319 // We are the fist call in the recursive chain.320 console.timeEnd('_clone');321 var totalAccepted = this.__cloneState.accepted +322 this.__cloneState.forced;323 console.log(324 totalAccepted + ' nodes retained (' +325 this.__cloneState.forced + ' forced by accepted children, ' +326 this.__cloneState.accepted + ' accepted on their own merits), ' +327 this.__cloneState.rejected + ' nodes (and their children) ' +328 'filtered out,' +329 this.__cloneState.pruned + ' nodes pruned because because no ' +330 'children remained.');331 delete this.__cloneState;332 }333 return copy;334}335D3SymbolTreeMap.prototype.filter = function(filter) {336 // Ensure we have a copy of the original root.337 if (this._backupTree === undefined) this._backupTree = this._treeData;338 this._mapContainer.selectAll('div').remove();339 this._setData(this._clone(this._backupTree, filter));340}341D3SymbolTreeMap.prototype._doLayout = function() {342 console.time('_doLayout');343 this._handleInodes();344 this._handleLeaves();345 this._firstTransition = false;346 console.timeEnd('_doLayout');347}348D3SymbolTreeMap.prototype._highlightElement = function(datum, selection) {349 this._showHighlight(datum, selection);350}351D3SymbolTreeMap.prototype._unhighlightElement = function(datum, selection) {352 this._hideHighlight(datum, selection);353}354D3SymbolTreeMap.prototype._handleInodes = function() {355 console.time('_handleInodes');356 var thisTreeMap = this;357 var inodes = this._currentNodes.filter(function(datum){358 return (datum.depth <= thisTreeMap._currentMaxDepth) &&359 datum.children !== undefined;360 });361 var cellsEnter = this._mapContainer.selectAll('div.inode')362 .data(inodes, function(datum) { return datum.id; })363 .enter()364 .append('div').attr('class', 'inode').attr('id', function(datum){365 return 'node-' + datum.id;});366 // Define enter/update/exit for inodes...

Full Screen

Full Screen

D3BlobTreeMap.js

Source:D3BlobTreeMap.js Github

copy

Full Screen

...203 this._doLayout();204}205D3BlobTreeMap.prototype._zoomDatum = function(datum) {206 if (this._currentRoot === datum) return; // already here207 this._hideHighlight(datum);208 this._hideInfoBox(datum);209 this._currentRoot = datum;210 this._currentNodes = this._layout.nodes(this._currentRoot);211 this._currentMaxDepth = this._currentRoot.depth + this._maxLevelsToShow;212 console.log('zooming into datum ' + this._currentRoot.n);213 this._doLayout();214}215D3BlobTreeMap.prototype.setMaxLevels = function(levelsToShow) {216 this._maxLevelsToShow = levelsToShow;217 this._currentNodes = this._layout.nodes(this._currentRoot);218 this._currentMaxDepth = this._currentRoot.depth + this._maxLevelsToShow;219 console.log('setting max levels to show: ' + this._maxLevelsToShow);220 this._doLayout();221}222/**223 * Clone the specified tree, returning an independent copy of the data.224 * Only the original attributes expected to exist prior to invoking225 * _crunchStatsHelper are retained, with the exception of the 'id' attribute226 * (which must be retained for proper transitions).227 * If the optional filter parameter is provided, it will be called with 'this'228 * set to this treemap instance and passed the 'datum' object as an argument.229 * When specified, the copy will retain only the data for which the filter230 * function returns true.231 */232D3BlobTreeMap.prototype._clone = function(datum, filter) {233 var trackingStats = false;234 if (this.__cloneState === undefined) {235 console.time('_clone');236 trackingStats = true;237 this.__cloneState = {'accepted': 0, 'rejected': 0,238 'forced': 0, 'pruned': 0};239 }240 // Must go depth-first. All parents of children that are accepted by the241 // filter must be preserved!242 var copy = {'n': datum.n, 'k': datum.k};243 var childAccepted = false;244 if (datum.children !== undefined) {245 for (var i = 0; i < datum.children.length; i++) {246 var copiedChild = this._clone(datum.children[i], filter);247 if (copiedChild !== undefined) {248 childAccepted = true; // parent must also be accepted.249 if (copy.children === undefined) copy.children = [];250 copy.children.push(copiedChild);251 }252 }253 }254 // Ignore nodes that don't match the filter, when present.255 var accept = false;256 if (childAccepted) {257 // Parent of an accepted child must also be accepted.258 this.__cloneState.forced++;259 accept = true;260 } else if (filter !== undefined && filter.call(this, datum) !== true) {261 this.__cloneState.rejected++;262 } else if (datum.children === undefined) {263 // Accept leaf nodes that passed the filter264 this.__cloneState.accepted++;265 accept = true;266 } else {267 // Non-leaf node. If no children are accepted, prune it.268 this.__cloneState.pruned++;269 }270 if (accept) {271 if (datum.id !== undefined) copy.id = datum.id;272 if (datum.lastPathElement !== undefined) {273 copy.lastPathElement = datum.lastPathElement;274 }275 if (datum.t !== undefined) copy.t = datum.t;276 if (datum.value !== undefined && datum.children === undefined) {277 copy.value = datum.value;278 }279 } else {280 // Discard the copy we were going to return281 copy = undefined;282 }283 if (trackingStats === true) {284 // We are the fist call in the recursive chain.285 console.timeEnd('_clone');286 var totalAccepted = this.__cloneState.accepted +287 this.__cloneState.forced;288 console.log(289 totalAccepted + ' nodes retained (' +290 this.__cloneState.forced + ' forced by accepted children, ' +291 this.__cloneState.accepted + ' accepted on their own merits), ' +292 this.__cloneState.rejected + ' nodes (and their children) ' +293 'filtered out,' +294 this.__cloneState.pruned + ' nodes pruned because because no ' +295 'children remained.');296 delete this.__cloneState;297 }298 return copy;299}300D3BlobTreeMap.prototype.filter = function(filter) {301 // Ensure we have a copy of the original root.302 if (this._backupTree === undefined) this._backupTree = this._treeData;303 this._mapContainer.selectAll('div').remove();304 this._setData(this._clone(this._backupTree, filter));305}306D3BlobTreeMap.prototype._doLayout = function() {307 console.time('_doLayout');308 this._handleInodes();309 this._handleLeaves();310 this._firstTransition = false;311 console.timeEnd('_doLayout');312}313D3BlobTreeMap.prototype._highlightElement = function(datum, selection) {314 this._showHighlight(datum, selection);315}316D3BlobTreeMap.prototype._unhighlightElement = function(datum, selection) {317 this._hideHighlight(datum, selection);318}319D3BlobTreeMap.prototype._handleInodes = function() {320 console.time('_handleInodes');321 var thisTreeMap = this;322 var inodes = this._currentNodes.filter(function(datum){323 return (datum.depth <= thisTreeMap._currentMaxDepth) &&324 datum.children !== undefined;325 });326 var cellsEnter = this._mapContainer.selectAll('div.inode')327 .data(inodes, function(datum) { return datum.id; })328 .enter()329 .append('div').attr('class', 'inode').attr('id', function(datum){330 return 'node-' + datum.id;});331 // Define enter/update/exit for inodes...

Full Screen

Full Screen

AnnotationLayer.js

Source:AnnotationLayer.js Github

copy

Full Screen

...73 this.disabled = true74 this.commentsContainer.children.forEach((otherSprite) => {75 otherSprite.tint = gray76 })77 this._hideHighlight()78 this.selectedSpriteIndex = null79 setTimeout(() => {80 this._filterComments()81 }, shortTimeTransition)82 }83 })84 this.comment.addEventListener('nextComment', () => {85 this.nextComment()86 })87 this.comment.addEventListener('prevComment', () => {88 this.previousComment()89 })90 Globals.controls.$$canvas.addEventListener('mousemove', (e) => {91 if (this.hoveredComment) {92 this.infoBubble.coords = {93 x: e.clientX - this.infoBubble.$$container.offsetWidth / 2,94 y: this.hoveredComment.worldTransform.ty - this.infoBubble.containerHeight - commentLayerHeight / 2,95 }96 }97 })98 Globals.events.on('zoom', this.updateGroups.bind(this))99 this.highlightTween = new TWEEN.Tween(this.highlight)100 }101 set location(location) {102 this._location = location103 this._filterComments()104 }105 get location() {106 return this._location107 }108 _filterComments(filter = false) {109 let selectedIndex = null110 let annotations = this.annotationsData[this.location.name].slice().sort((a, b) => {111 return a.timeStart - b.timeStart112 })113 // filtering by author name114 if (filter) {115 annotations = annotations.filter((annotation) => annotation.author === filter)116 if (!annotations.length) {117 console.error('No annotations for ', filter)118 return119 }120 // start at the first comment by default for a selected author121 selectedIndex = 0122 }123 if (this.hoveredComment) {124 this.hoveredComment = null125 this.infoBubble.author = null126 }127 AnnotationLayer.emptyContainer(this.commentsContainer)128 // populate annotations based on the data for this location129 this.yLevels = [0]130 const commentGroups = []131 this.filteredAnnotations = annotations132 annotations.forEach((annotation, i) => {133 const sprite = new CommentSprite(this, annotation, i)134 // determine what y-position level to put this comment on (above the spectrogram)135 for (let level = 0; level < this.yLevels.length; level++) {136 if (this.yLevels[level] <= sprite.data.timeStart - 1000) {137 sprite.yLevel = level138 this.yLevels[level] = sprite.data.timeEnd139 break140 }141 }142 if (sprite.yLevel === null) {143 sprite.yLevel = this.yLevels.length144 this.yLevels.push(sprite.data.timeEnd)145 }146 this.commentsContainer.addChild(sprite)147 // add to comment overlap groups148 if (i) {149 const group = commentGroups[commentGroups.length - 1]150 if (sprite.data.timeStart <= group.end) {151 group.addComment(sprite)152 } else {153 commentGroups.push(new CommentGroup(this, sprite))154 }155 } else {156 commentGroups.push(new CommentGroup(this, sprite))157 }158 })159 this.commentGroups = []160 AnnotationLayer.emptyContainer(this.commentGroupsContainer)161 commentGroups.forEach((group) => {162 if (group.comments.length > 1) {163 group.initialize(this.commentGroupsContainer, this.commentGroups)164 }165 })166 this.updateGroups()167 this.commentsContainer.children.forEach((sprite) => {168 sprite.y = (this.yLevels.length - sprite.yLevel) * commentLayerHeight - strokeWeight169 })170 const yPos = this.yLevels.length * commentLayerHeight171 this.highlight.y = yPos172 this.commentGroupsContainer.y = yPos - commentPadding * 2173 // handle selection174 if (selectedIndex !== null) {175 this._navigateToComment(selectedIndex)176 }177 }178 async load() {179 this.annotationsData = await getAnnotations()180 }181 update() {182 this._updateYPosition()183 this._updateSpritePositions()184 }185 _updateYPosition() {186 this.y = (window.innerHeight - this.spectrogram.height) / 2 - this.yLevels.length * commentLayerHeight187 }188 _updateSpritePositions() {189 const windowDuration = Globals.timeManager.windowDuration190 const time = Globals.timeManager.currentTime191 if (!windowDuration || !this.commentsContainer.children.length) return192 const windowStart = Globals.timeManager.windowStartTime193 const windowEnd = Globals.timeManager.windowEndTime194 let commentSelected = false195 // update individual sprites196 this.commentsContainer.children.forEach((sprite, spriteIndex) => {197 // if sprite is onscreen, and not consolidated into a group, set position198 // and check if it should be showing in the pinned element199 if (200 (!sprite.group || !sprite.group.consolidated) &&201 sprite.data.timeStart < windowEnd &&202 sprite.data.timeEnd > windowStart203 ) {204 sprite.visible = true205 // position and size206 sprite.update()207 // check if comment involves the current time208 // and set the currently selected sprite209 if (sprite.data.timeStart <= time && sprite.data.timeEnd >= time) {210 if (!sprite.selectable) {211 if (!this.settling && this.positioning === null) {212 this._selectComment(sprite, spriteIndex)213 }214 sprite.selectable = true215 }216 } else {217 if (sprite.selectable) {218 sprite.selectable = false219 if (this.selectedSpriteIndex === spriteIndex && this.positioning === null) {220 // find last (latest) comment that is selectable221 for (let i = this.commentsContainer.children.length - 1; i >= 0; i--) {222 const selectedSprite = this.commentsContainer.getChildAt(i)223 if (selectedSprite.selectable) {224 this._selectComment(selectedSprite, i)225 break226 }227 }228 }229 }230 }231 if (sprite.selectable && !commentSelected) {232 commentSelected = true233 }234 } else {235 sprite.visible = false236 sprite.selectable = false237 }238 })239 // update sprite overlap groups240 this.commentGroups.forEach((group) => {241 if (242 group.consolidated &&243 group.median < windowEnd + strokeWeight / 2 &&244 group.median > windowStart - strokeWeight / 2245 ) {246 group.graphic.visible = true247 group.updatePosition()248 // check if group involves the current time249 // and set the currently selected sprite250 // const firstComment = group.comments[0]251 // if (group.start <= time && group.end > = time) {252 // if (!group.selected && this.positioning === null) {253 // this._selectComment(firstComment, firstComment.index)254 // group.selected = true255 // }256 // } else {257 // group.selected = false258 // }259 // if (group.selected && !commentSelected) {260 // commentSelected = true261 // }262 } else {263 group.selected = false264 group.graphic.visible = false265 }266 })267 // close the comment if it is open but no annotation is selected268 if (!commentSelected && this.comment.annotation !== null) {269 this.comment.annotation = null270 this._hideHighlight()271 if (!this.disabled && this.positioning === null) {272 this.commentsContainer.children.forEach((otherSprite) => {273 otherSprite.tint = blue274 })275 this.commentGroups.forEach((group) => {276 group.tint = blue277 })278 }279 this.selectedSpriteIndex = null280 }281 // position highlight282 if (this.highlightedIndex !== null && this.positioning === null) {283 const selectedSprite = this.commentsContainer.getChildAt(this.highlightedIndex)284 this.highlight.x = selectedSprite.x + commentPadding285 this.highlight.width = selectedSprite.middle.width + strokeWeight286 this.highlight.height = this.spectrogram.height287 }288 // handle comment selectability for the < and > icons in the Comment element289 this.firstCommentSelectable =290 Globals.timeManager.currentTime > this.commentsContainer.getChildAt(0).data.timeStart &&291 ((this.selectedSpriteIndex === 0 && this.positioning !== null) || this.selectedSpriteIndex !== 0)292 const lastCommentIndex = this.commentsContainer.children.length - 1293 this.lastCommentSelectable =294 Globals.timeManager.currentTime < this.commentsContainer.getChildAt(lastCommentIndex).data.timeEnd &&295 ((this.selectedSpriteIndex === lastCommentIndex && this.positioning !== null) ||296 this.selectedSpriteIndex !== lastCommentIndex)297 if (this.comment.firstCommentSelectable !== this.firstCommentSelectable) {298 this.comment.firstCommentSelectable = this.firstCommentSelectable299 }300 if (this.comment.lastCommentSelectable !== this.lastCommentSelectable) {301 this.comment.lastCommentSelectable = this.lastCommentSelectable302 }303 this.settling = false304 }305 _selectComment(sprite, index) {306 if (this.disabled) return307 this.comment.annotation = sprite.data308 this.selectedSpriteIndex = index309 if (!sprite.group || !sprite.group.consolidated) {310 this._showHighlight()311 } else {312 this._hideHighlight()313 }314 sprite.tint = blue315 if (sprite.group) {316 sprite.group.tint = blue317 }318 this.commentsContainer.children.forEach((otherSprite, i) => {319 if (i !== index) {320 otherSprite.tint = gray321 }322 })323 this.commentGroups.forEach((group) => {324 if (group !== sprite.group) {325 group.tint = gray326 }327 })328 this.settling = true329 }330 navigateToCommentAnchor(anchor) {331 const annotation = this.filteredAnnotations.findIndex((x) => x.anchor == anchor)332 if (annotation !== -1) {333 this._navigateToComment(annotation)334 } else {335 console.error('Anchor ' + anchor + ' not found')336 }337 }338 _navigateToComment(index) {339 if (this.disabled) return340 this.selectedSpriteIndex = index341 const sprite = this.commentsContainer.getChildAt(index)342 this._hideHighlight()343 this.positioning = sprite344 Globals.controls.navigateTo(sprite.data.timeStart, AnnotationLayer.getIdealWindowDuration(sprite), () => {345 if (this.positioning !== null) {346 this._selectComment(this.positioning, this.positioning.index)347 }348 this.positioning = null349 this.commentNavSkip = 0350 this.updateGroups()351 })352 }353 nextComment() {354 if (this.positioning !== null) {355 this.commentNavSkip++356 }357 let nextIndex = this.commentsContainer.children.findIndex((sprite) => {358 return sprite.data.timeStart > Globals.timeManager.currentTime359 })360 if (nextIndex !== -1) {361 nextIndex += this.commentNavSkip362 if (nextIndex >= 0 && nextIndex < this.commentsContainer.children.length) {363 this._navigateToComment(nextIndex)364 }365 }366 }367 previousComment() {368 if (this.positioning !== null) {369 this.commentNavSkip--370 }371 let prevIndex =372 this.commentsContainer.children.length -373 1 -374 this.commentsContainer.children375 .slice()376 .reverse()377 .findIndex((sprite) => {378 return sprite.data.timeStart < Globals.timeManager.currentTime379 })380 if (prevIndex !== -1) {381 prevIndex += this.commentNavSkip382 if (prevIndex && prevIndex === this.selectedSpriteIndex) {383 prevIndex--384 }385 if (prevIndex >= 0 && prevIndex < this.commentsContainer.children.length) {386 this._navigateToComment(prevIndex)387 }388 }389 }390 updateGroups() {391 if (!this.spectrogram.windowDuration || !this.annotationsData || !this.commentGroups.length) return392 const minGroupWidth = strokeWeight * 3393 this.commentGroups.forEach((group) => {394 const pixelDuration = Globals.timeManager.durationToPx(group.start, group.end)395 if (!group.consolidated && pixelDuration < minGroupWidth) {396 group.consolidated = true397 } else if (group.consolidated && pixelDuration >= minGroupWidth) {398 group.consolidated = false399 }400 })401 }402 static emptyContainer(container) {403 container.children.forEach((child) => {404 child.filters = null405 Object.values(child.tweener.tweens).forEach((tween) => {406 tween.stop()407 TWEEN.remove(tween)408 })409 child.destroy({ children: true })410 })411 container.removeChildren()412 }413 spritePointerDown(sprite) {414 if (this.disabled) {415 setTimeout(() => {416 Globals.controls.scrub.dragStop()417 }, 100)418 this.comment.startTour(AnnotationLayer.getAuthorID(sprite.data.author))419 } else {420 this._navigateToComment(sprite.index)421 }422 }423 spriteMouseOver(e, obj, sprite = false, filterObj = false) {424 sprite = sprite || obj425 filterObj = filterObj || obj426 if (this.disabled) {427 this.commentsContainer.children.forEach((otherSprite) => {428 otherSprite.tint = otherSprite.data.author === sprite.data.author ? blue : gray429 })430 }431 obj.glowFilter.color = obj.tint432 filterObj.filters = [obj.glowFilter]433 obj.tweens.glow434 .stop()435 .to({ outerStrength: filterConfig.outerStrength }, shortTimeTransition)436 .onComplete(() => {})437 .start()438 this.hoveredComment = filterObj439 this.infoBubble.author = AnnotationLayer.getAuthorID(sprite.data.author)440 this.infoBubble.coords = {441 x: e.data.global.x - this.infoBubble.$$container.offsetWidth / 2,442 y: sprite.worldTransform.ty - this.infoBubble.containerHeight - commentLayerHeight / 2,443 }444 }445 spriteMouseOut(obj, filterObj = false) {446 filterObj = filterObj || obj447 obj.tweens.glow448 .stop()449 .to({ outerStrength: 0 }, shortTimeTransition)450 .onComplete(() => {451 filterObj.filters = null452 })453 .start()454 if (this.hoveredComment === filterObj) {455 if (this.disabled) {456 this.commentsContainer.children.forEach((otherSprite) => {457 otherSprite.tint = gray458 })459 }460 this.hoveredComment = null461 this.infoBubble.author = null462 }463 }464 _showHighlight() {465 this.highlightedIndex = this.selectedSpriteIndex466 this.highlightTween467 .stop()468 .to({ alpha: highlightAlpha }, shortTimeTransition)469 .onStart(() => {470 this.highlight.visible = true471 })472 .onComplete(() => {})473 .start()474 }475 _hideHighlight() {476 this.highlightTween477 .stop()478 .to({ alpha: 0 }, shortTimeTransition)479 .onStart(() => {})480 .onComplete(() => {481 this.highlightedIndex = null482 this.highlight.visible = false483 })484 .start()485 }486 static getAuthorID(name) {487 return Object.values(Config.authors).find((authorObj) => {488 return authorObj.name === name489 }).id...

Full Screen

Full Screen

React3Instance.js

Source:React3Instance.js Github

copy

Full Screen

1import * as THREE from 'three';2import invariant from 'fbjs/lib/invariant';3import warning from 'fbjs/lib/warning';4import ReactUpdates from 'react-dom/lib/ReactUpdates';5import Viewport from './Viewport';6import React3Module from './Module';7import React3Renderer from './React3Renderer';8import ResourceContainer from './Resources/ResourceContainer';9import CameraUtils from './utils/CameraUtils';10import isWebglSupported from './utils/isWebglSupported';11const rendererProperties = [12 'gammaInput',13 'gammaOutput',14];15class React3DInstance {16 constructor(props, rendererInstance: React3Renderer) {17 const {18 mainCamera,19 onAnimate,20 onRecreateCanvas,21 onRendererUpdated,22 onManualRenderTriggerCreated,23 forceManualRender,24 } = props;25 this._parameters = { ...props };26 this._rendererInstance = rendererInstance;27 this._mounted = false;28 this._willUnmount = false;29 this._scene = null;30 this._mainCameraName = mainCamera;31 this._viewports = [];32 /**33 * @type {Array.<React3Module>}34 */35 this._modules = [];36 this._resourceContainers = [];37 this._recreateCanvasCallback = onRecreateCanvas;38 this._rendererUpdatedCallback = onRendererUpdated;39 this._manualRenderTriggerCallback = onManualRenderTriggerCreated;40 this._forceManualRender = forceManualRender;41 this._warnedAboutManualRendering = false;42 this._canvas = null;43 this._onAnimate = onAnimate;44 this._objectsByUUID = {};45 this._materials = [];46 this._geometries = [];47 this._textures = [];48 this._objectsByName = {};49 this._lastRenderMode = null;50 this._renderTrigger = (renderThisFrame) => {51 if (renderThisFrame) {52 this._render();53 } else if (this._renderRequest === null) {54 this._renderRequest = requestAnimationFrame(this._render);55 }56 };57 this.uuid = THREE.Math.generateUUID();58 this.userData = {};59 if (process.env.NODE_ENV !== 'production' || process.env.ENABLE_REACT_ADDON_HOOKS === 'true') {60 this._highlightScene = new THREE.Scene();61 this._highlightGeometry = new THREE.BoxGeometry(1, 1, 1);62 this._highlightMaterial = new THREE.MeshBasicMaterial({63 color: 0x0000ff,64 transparent: true,65 opacity: 0.4,66 });67 this._highlightObjectId = null;68 this._getHighlightBoundingBox = null;69 this._hideHighlight = () => {70 this._highlightObjectId = null;71 this._getHighlightBoundingBox = null;72 };73 this._objectHighlighted = (info) => {74 const { uuid, boundingBoxFunc } = info;75 let obj;76 if (this._highlightObjectId) {77 obj = this._objectsByUUID[this._highlightObjectId];78 obj.userData.events.removeListener('hideHighlight', this._hideHighlight);79 }80 this._highlightObjectId = uuid;81 this._getHighlightBoundingBox = boundingBoxFunc;82 obj = this._objectsByUUID[uuid];83 obj.userData.events.once('hideHighlight', this._hideHighlight);84 };85 }86 }87 _createRenderer() {88 if (!this._canvas) {89 return;90 }91 const parameters = this._parameters;92 const rendererArgs = {93 canvas: this._canvas,94 precision: parameters.precision,95 alpha: parameters.alpha,96 premultipliedAlpha: parameters.premultipliedAlpha,97 antialias: parameters.antialias,98 stencil: parameters.stencil,99 preserveDrawingBuffer: parameters.preserveDrawingBuffer,100 depth: parameters.depth,101 logarithmicDepthBuffer: parameters.logarithmicDepthBuffer,102 };103 if (this._parameters.customRenderer) {104 this._renderer = this._parameters.customRenderer(rendererArgs);105 } else {106 this._renderer = isWebglSupported() ? new THREE.WebGLRenderer(rendererArgs)107 : new THREE.CanvasRenderer(rendererArgs);108 }109 if (this._rendererUpdatedCallback) {110 this._rendererUpdatedCallback(this._renderer);111 }112 const renderer = this._renderer;113 if (parameters.hasOwnProperty('pixelRatio')) {114 renderer.setPixelRatio(parameters.pixelRatio);115 }116 if (parameters.hasOwnProperty('sortObjects')) {117 renderer.sortObjects = parameters.sortObjects;118 }119 const hasClearColor = parameters.hasOwnProperty('clearColor');120 const hasClearAlpha = parameters.hasOwnProperty('clearAlpha');121 if (hasClearColor || hasClearAlpha) {122 let clearColor;123 if (hasClearColor) {124 clearColor = parameters.clearColor;125 } else {126 clearColor = new THREE.Color(0x000000); // default clear color127 }128 if (hasClearAlpha) {129 if (process.env.NODE_ENV !== 'production') {130 warning(parameters.alpha === true, 'The `clearAlpha` property' +131 ' requires the `alpha` property to be `true`.');132 }133 renderer.setClearColor(clearColor, parameters.clearAlpha);134 } else {135 renderer.setClearColor(clearColor);136 }137 }138 if (parameters.hasOwnProperty('shadowMapEnabled')) {139 renderer.shadowMap.enabled = parameters.shadowMapEnabled;140 }141 if (parameters.hasOwnProperty('shadowMapType')) {142 renderer.shadowMap.type = parameters.shadowMapType;143 }144 if (parameters.hasOwnProperty('shadowMapCullFace')) {145 renderer.shadowMap.cullFace = parameters.shadowMapCullFace;146 }147 if (parameters.hasOwnProperty('shadowMapDebug')) {148 renderer.shadowMap.debug = parameters.shadowMapDebug;149 }150 rendererProperties.forEach((propertyName) => {151 if (parameters.hasOwnProperty(propertyName)) {152 renderer[propertyName] = parameters[propertyName];153 }154 });155 renderer.setSize(parameters.width, parameters.height);156 }157 initialize() {158 this.userData.events.on('animate', this._callOnAnimate);159 if (this._forceManualRender) {160 if (process.env.NODE_ENV !== 'production') {161 if (!this._manualRenderTriggerCallback && !this._warnedAboutManualRendering) {162 this._warnedAboutManualRendering = true;163 warning(false,164 'The `forceManualRender` property requires the ' +165 '`onManualRenderTriggerCreated` property to be set.');166 }167 }168 this._renderRequest = null;169 } else {170 this._renderRequest = requestAnimationFrame(this._render);171 }172 if (this._manualRenderTriggerCallback) {173 this._manualRenderTriggerCallback(this._renderTrigger);174 }175 }176 getObjectsByName(objectName) {177 const objectsByName = this._objectsByName[objectName];178 let result;179 if (objectsByName) {180 const idToObjectMap = objectsByName.values;181 result = Object.keys(idToObjectMap)182 .map(name => idToObjectMap[name]);183 } else {184 result = [];185 }186 return result;187 }188 addAnimateListener(callback) {189 this.userData.events.on('animate', callback);190 }191 removeAnimateListener(callback) {192 this.userData.events.removeListener('animate', callback);193 }194 addBeforeRenderListener(callback) {195 this.userData.events.on('preRender', callback);196 }197 removeBeforeRenderListener(callback) {198 this.userData.events.removeListener('preRender', callback);199 }200 _callOnAnimate = () => {201 if (this._onAnimate) {202 ReactUpdates.batchedUpdates(this._onAnimate);203 }204 };205 addChildren(children) {206 for (let i = 0; i < children.length; ++i) {207 const child = children[i];208 if (child instanceof THREE.Scene) {209 this.setScene(child);210 } else if (child instanceof Viewport) {211 this.addViewport(child);212 } else if (child instanceof React3Module) {213 this.addModule(child);214 } else if (child instanceof ResourceContainer) {215 this.addResourceContainer(child);216 } else {217 invariant(false,218 'The react3 component should only contain ' +219 '<viewport/>s or <scene/>s or <resources/>.');220 }221 }222 }223 removeChild(child) {224 if (child instanceof THREE.Scene) {225 if (this._scene === child) {226 this.setScene(null);227 }228 } else if (child instanceof Viewport) {229 this.removeViewport(child);230 } else if (child instanceof React3Module) {231 this.removeModule(child);232 } else if (child instanceof ResourceContainer) {233 this.removeResourceContainer(child);234 } else {235 invariant(false,236 'The react3 component should only contain ' +237 '<viewport/>s or <scene/>s, <module/>s or <resources/>.');238 }239 }240 _render = () => {241 for (let i = 0; i < this._modules.length; ++i) {242 this._modules[i].update();243 }244 if (this._forceManualRender) {245 this._renderRequest = null;246 } else {247 this._renderRequest = requestAnimationFrame(this._render);248 }249 this.userData.events.emit('animate');250 // the scene can be destroyed within the 'animate' event251 if (!this._scene || !this._mounted || !this._renderer) {252 return;253 }254 let mainCamera = null;255 if (this._mainCameraName) {256 const objectsWithMainCameraName = this._objectsByName[this._mainCameraName];257 if (objectsWithMainCameraName) {258 if (process.env.NODE_ENV !== 'production') {259 warning(objectsWithMainCameraName.count < 2,260 `There are multiple objects with name ${this._mainCameraName}`);261 }262 if (objectsWithMainCameraName.count > 0) {263 const values = objectsWithMainCameraName.values;264 mainCamera = values[Object.keys(values)[0]];265 }266 }267 }268 if (mainCamera) {269 if (this._lastRenderMode !== 'camera') {270 this._renderer.autoClear = true;271 this._renderer.setViewport(0, 0, this._parameters.width, this._parameters.height);272 this._lastRenderMode = 'camera';273 }274 CameraUtils.current = mainCamera;275 this.userData.events.emit('preRender');276 this._renderScene(mainCamera);277 CameraUtils.current = null;278 } else if (this._viewports.length > 0) {279 if (this._lastRenderMode !== 'viewport') {280 this._renderer.autoClear = false;281 this._lastRenderMode = 'viewport';282 }283 this._renderer.clear();284 this._viewports.forEach((viewport) => {285 let viewportCamera = null;286 if (viewport.cameraName) {287 const objectsWithViewportCameraName = this._objectsByName[viewport.cameraName];288 if (objectsWithViewportCameraName) {289 if (process.env.NODE_ENV !== 'production') {290 warning(objectsWithViewportCameraName.count < 2,291 `There are multiple objects with name ${viewport.cameraName}`);292 }293 if (objectsWithViewportCameraName.count > 0) {294 const values = objectsWithViewportCameraName.values;295 viewportCamera = values[Object.keys(values)[0]];296 }297 }298 }299 if (!viewportCamera) {300 return;301 }302 if (viewport.onBeforeRender) {303 ReactUpdates.batchedUpdates(viewport.onBeforeRender);304 }305 this._renderer.setViewport(viewport.x, viewport.y, viewport.width, viewport.height);306 CameraUtils.current = viewportCamera;307 this.userData.events.emit('preRender');308 this._renderScene(viewportCamera);309 CameraUtils.current = null;310 });311 }312 };313 _renderScene(camera) {314 this._renderer.render(this._scene, camera);315 if (process.env.NODE_ENV !== 'production' || process.env.ENABLE_REACT_ADDON_HOOKS === 'true') {316 if (this._highlightObjectId !== null) {317 const boundingBoxes = this._getHighlightBoundingBox();318 const highlightScene = this._highlightScene;319 const diff = highlightScene.children.length - boundingBoxes.length;320 if (diff > 0) {321 for (let i = 0; i < diff; i++) {322 highlightScene.remove(highlightScene.children[0]);323 }324 } else if (diff < 0) {325 for (let i = 0; i < -diff; i++) {326 highlightScene.add(new THREE.Mesh(this._highlightGeometry, this._highlightMaterial));327 }328 }329 for (let i = 0; i < boundingBoxes.length; ++i) {330 const boundingBox = boundingBoxes[i];331 const center = boundingBox.min.clone().add(boundingBox.max).multiplyScalar(0.5);332 const size = boundingBox.max.clone().sub(boundingBox.min);333 const highlightCube = highlightScene.children[i];334 highlightCube.position.copy(center);335 highlightCube.scale.copy(size);336 }337 const autoClear = this._renderer.autoClear;338 this._renderer.autoClear = false;339 this._renderer.render(highlightScene, camera);340 this._renderer.autoClear = autoClear;341 }342 }343 }344 setScene(scene) {345 if (process.env.NODE_ENV !== 'production') {346 invariant(!(this._scene && scene), 'There can only be one scene in <react3/>');347 }348 this._scene = scene;349 }350 addViewport(viewport) {351 this._viewports.push(viewport);352 }353 removeViewport(viewport) {354 const index = this._viewports.indexOf(viewport);355 if (process.env.NODE_ENV !== 'production') {356 invariant(index !== -1,357 'A viewport has been removed from ' +358 '<react3/> but it was not present in it...');359 }360 this._viewports.splice(index, 1);361 }362 addResourceContainer(resourceContainer) {363 this._resourceContainers.push(resourceContainer);364 }365 removeResourceContainer(resourceContainer) {366 const index = this._resourceContainers.indexOf(resourceContainer);367 if (process.env.NODE_ENV !== 'production') {368 invariant(index !== -1,369 'A resource container has been removed ' +370 'from <react3/> but it was not present in it...');371 }372 this._resourceContainers.splice(index, 1);373 }374 addModule(module: React3Module) {375 this._modules.push(module);376 }377 removeModule(module: React3Module) {378 const index = this._modules.indexOf(module);379 if (process.env.NODE_ENV !== 'production') {380 invariant(index !== -1,381 'A module has been removed from ' +382 '<react3/> but it was not present in it...');383 }384 this._modules.splice(index, 1);385 }386 updateWidth(newWidth) {387 this._parameters.width = newWidth;388 if (!this._renderer) {389 return;390 }391 this._renderer.setSize(this._parameters.width, this._parameters.height);392 }393 updateOnRecreateCanvas(threeObject, callback) {394 this._recreateCanvasCallback = callback;395 }396 updateOnRendererUpdated(callback) {397 this._rendererUpdatedCallback = callback;398 }399 updateOnManualRenderTriggerCreated(callback) {400 this._manualRenderTriggerCallback = callback;401 if (callback) {402 this._manualRenderTriggerCallback(this._renderTrigger);403 }404 }405 updateForceManualRender(forceManualRender) {406 if (this._forceManualRender === forceManualRender) {407 return;408 }409 this._forceManualRender = forceManualRender;410 if (forceManualRender) {411 // was just set to be forced412 cancelAnimationFrame(this._renderRequest);413 this._renderRequest = null;414 } else {415 // was just restored416 this._renderRequest = requestAnimationFrame(this._render);417 }418 }419 updateHeight(newHeight) {420 this._parameters.height = newHeight;421 if (!this._renderer) {422 return;423 }424 this._renderer.setSize(this._parameters.width, this._parameters.height);425 }426 updatePixelRatio(newPixelRatio) {427 this._parameters.pixelRatio = newPixelRatio;428 if (!this._renderer) {429 return;430 }431 this._renderer.setPixelRatio(newPixelRatio);432 this._renderer.setSize(this._parameters.width, this._parameters.height);433 }434 updateSortObjects(sortObjects) {435 this._parameters.sortObjects = sortObjects;436 if (!this._renderer) {437 return;438 }439 this._renderer.sortObjects = sortObjects;440 }441 updateAntialias(antialias) {442 this._parameters.antialias = antialias;443 // no renderer, this only happens initially or we're about to recreate it anyway.444 // unless something broke, then we have bigger problems...445 if (!this._renderer) {446 return;447 }448 this.refreshRenderer();449 }450 updatePrecision(precision) {451 this._parameters.precision = precision;452 if (!this._renderer) {453 return;454 }455 this.refreshRenderer();456 }457 updateAlpha(alpha) {458 this._parameters.alpha = alpha;459 if (!this._renderer) {460 return;461 }462 this.refreshRenderer();463 }464 updatePremultipliedAlpha(premultipliedAlpha) {465 this._parameters.premultipliedAlpha = premultipliedAlpha;466 if (!this._renderer) {467 return;468 }469 this.refreshRenderer();470 }471 updateStencil(stencil) {472 this._parameters.stencil = stencil;473 if (!this._renderer) {474 return;475 }476 this.refreshRenderer();477 }478 updatePreserveDrawingBuffer(preserveDrawingBuffer) {479 this._parameters.preserveDrawingBuffer = preserveDrawingBuffer;480 if (!this._renderer) {481 return;482 }483 this.refreshRenderer();484 }485 updateDepth(depth) {486 this._parameters.depth = depth;487 if (!this._renderer) {488 return;489 }490 this.refreshRenderer();491 }492 updateLogarithmicDepthBuffer(logarithmicDepthBuffer) {493 this._parameters.logarithmicDepthBuffer = logarithmicDepthBuffer;494 if (!this._renderer) {495 return;496 }497 this.refreshRenderer();498 }499 updateShadowMapEnabled(shadowMapEnabled) {500 this._parameters.shadowMapEnabled = shadowMapEnabled;501 if (!this._renderer) {502 return;503 }504 this._renderer.shadowMap.enabled = shadowMapEnabled;505 this.allMaterialsNeedUpdate(true);506 }507 updateShadowMapType(shadowMapType) {508 this._parameters.shadowMapType = shadowMapType;509 if (!this._renderer) {510 return;511 }512 this._renderer.shadowMap.type = shadowMapType;513 this.allMaterialsNeedUpdate(true);514 }515 updateShadowMapCullFace(shadowMapCullFace) {516 this._parameters.shadowMapCullFace = shadowMapCullFace;517 if (!this._renderer) {518 return;519 }520 this._renderer.shadowMap.cullFace = shadowMapCullFace;521 this.allMaterialsNeedUpdate(true);522 }523 updateShadowMapDebug(shadowMapDebug) {524 this._parameters.shadowMapDebug = shadowMapDebug;525 if (!this._renderer) {526 return;527 }528 this._renderer.shadowMap.debug = shadowMapDebug;529 this.allMaterialsNeedUpdate(true);530 }531 updateCanvas(canvas) {532 this._canvas = canvas;533 if (this._renderer) {534 this.disposeResourcesAndRenderer();535 const extensions = this._renderer.extensions;536 if (extensions && (typeof extensions.get === 'function')) {537 const contextLossExtension = extensions.get('WEBGL_lose_context');538 if (contextLossExtension) {539 // noinspection JSUnresolvedFunction540 contextLossExtension.loseContext();541 }542 }543 }544 this._createRenderer();545 }546 updateGammaInput(gammaInput) {547 this._parameters.gammaInput = gammaInput;548 if (!this._renderer) {549 return;550 }551 this._renderer.gammaInput = gammaInput;552 this.allMaterialsNeedUpdate(true);553 }554 updateGammaOutput(gammaOutput) {555 this._parameters.gammaOutput = gammaOutput;556 if (!this._renderer) {557 return;558 }559 this._renderer.gammaOutput = gammaOutput;560 this.allMaterialsNeedUpdate(true);561 }562 updateContext(context) {563 this._parameters.context = context;564 }565 updateMainCamera(mainCamera) {566 this._parameters.mainCamera = mainCamera;567 this._mainCameraName = mainCamera;568 }569 updateCustomRenderer(customRenderer) {570 this._parameters.customRenderer = customRenderer;571 if (!this._renderer) {572 return;573 }574 this.refreshRenderer();575 }576 updateOnAnimate(onAnimate) {577 this._parameters.onAnimate = onAnimate;578 this._onAnimate = onAnimate;579 }580 updateClearColor(clearColor) {581 this._parameters.clearColor = clearColor;582 if (!this._renderer) {583 return;584 }585 if (this._parameters.hasOwnProperty('clearAlpha')) {586 this._renderer.setClearColor(clearColor, this._parameters.clearAlpha);587 } else {588 this._renderer.setClearColor(clearColor);589 }590 }591 updateClearAlpha(clearAlpha) {592 const parameters = this._parameters;593 if (clearAlpha === undefined) {594 delete parameters.clearAlpha;595 } else {596 parameters.clearAlpha = clearAlpha;597 }598 if (!this._renderer) {599 return;600 }601 let clearColor;602 if (parameters.hasOwnProperty('clearColor')) {603 clearColor = parameters.clearColor;604 } else {605 clearColor = new THREE.Color(0x000000); // default clear color606 }607 if (clearAlpha !== undefined) {608 this._renderer.setClearColor(clearColor, clearAlpha);609 } else {610 this._renderer.setClearColor(clearColor);611 }612 }613 refreshRenderer() {614 let contextLossExtension;615 this.disposeResourcesAndRenderer();616 const extensions = this._renderer.extensions;617 if (extensions && (typeof extensions.get === 'function')) {618 contextLossExtension = extensions.get('WEBGL_lose_context');619 }620 delete this._renderer;621 if (this._rendererUpdatedCallback) {622 this._rendererUpdatedCallback(null);623 }624 this.userData.events.removeListener('animate', this._callOnAnimate);625 this.userData.events.removeAllListeners();626 if (this._renderRequest !== null) {627 cancelAnimationFrame(this._renderRequest);628 this._renderRequest = null;629 }630 if (contextLossExtension && this._canvas) {631 // noinspection JSUnresolvedFunction632 contextLossExtension.loseContext();633 this._recreateCanvasCallback();634 } else {635 this._recreateCanvasCallback();636 }637 }638 disposeResourcesAndRenderer() {639 for (let i = 0; i < this._materials.length; ++i) {640 const material = this._materials[i];641 material.dispose();642 }643 for (let i = 0; i < this._geometries.length; ++i) {644 const geometry = this._geometries[i];645 geometry.dispose();646 }647 for (let i = 0; i < this._textures.length; ++i) {648 const texture = this._textures[i];649 texture.dispose();650 }651 if (typeof this._renderer.dispose === 'function') {652 this._renderer.dispose();653 }654 }655 willUnmount() {656 this._willUnmount = true;657 }658 unmount() {659 this._mounted = false;660 if (this._renderRequest !== null) {661 cancelAnimationFrame(this._renderRequest);662 this._renderRequest = null;663 }664 this.userData.events.removeListener('animate', this._callOnAnimate);665 this.userData.events.removeAllListeners();666 delete this._rendererInstance;667 if (this._renderer) {668 let contextLossExtension;669 const extensions = this._renderer.extensions;670 if (extensions && (typeof extensions.get === 'function')) {671 contextLossExtension = extensions.get('WEBGL_lose_context');672 }673 if (contextLossExtension) {674 // noinspection JSUnresolvedFunction675 contextLossExtension.loseContext();676 }677 this.disposeResourcesAndRenderer();678 delete this._renderer;679 if (this._rendererUpdatedCallback) {680 this._rendererUpdatedCallback(null);681 }682 }683 delete this._parameters;684 invariant(Object.keys(this._objectsByUUID).length === 0,685 'Failed to cleanup some child objects for React3DInstance');686 delete this._objectsByUUID;687 delete this._viewports;688 delete this._scene;689 if (process.env.NODE_ENV !== 'production' || process.env.ENABLE_REACT_ADDON_HOOKS === 'true') {690 delete this._highlightScene;691 delete this._highlightObjectId;692 delete this._getHighlightBoundingBox;693 }694 }695 objectMounted(object) {696 invariant(!this._objectsByUUID[object.uuid],697 'There already is an object with this uuid in the react 3d instance.');698 this._objectsByUUID[object.uuid] = object;699 object.userData.markup._rootInstance = this;700 this._addObjectWithName(object.name, object);701 if (process.env.NODE_ENV !== 'production' || process.env.ENABLE_REACT_ADDON_HOOKS === 'true') {702 object.userData.events.on('highlight', this._objectHighlighted);703 }704 object.userData.events.emit('addedIntoRoot', object);705 const current: THREE.Object3D = object;706 const childrenMarkup = current.userData.markup.childrenMarkup;707 if (object instanceof THREE.Material) {708 this._materials.push(object);709 }710 if (object instanceof THREE.Geometry || object instanceof THREE.BufferGeometry) {711 this._geometries.push(object);712 }713 if (object instanceof THREE.Texture) {714 this._textures.push(object);715 }716 for (let i = 0; i < childrenMarkup.length; ++i) {717 const childMarkup = childrenMarkup[i];718 this.objectMounted(childMarkup.threeObject);719 }720 }721 allMaterialsNeedUpdate(dispose) {722 this._materials.forEach((material) => {723 if (dispose) {724 material.dispose();725 } else {726 material.needsUpdate = true;727 }728 });729 }730 objectRenamed(object, oldName, nextName) {731 this._removeObjectWithName(oldName, object);732 this._addObjectWithName(nextName, object);733 }734 _addObjectWithName(objectName, object) {735 if (!this._objectsByName[objectName]) {736 this._objectsByName[objectName] = {737 count: 0,738 values: {},739 };740 }741 this._objectsByName[objectName].values[object.uuid] = object;742 this._objectsByName[objectName].count++;743 }744 _removeObjectWithName(objectName, object) {745 invariant(this._objectsByName[objectName]746 && this._objectsByName[objectName].values[object.uuid] === object,747 'The object\'s name changed somehow?\'');748 delete this._objectsByName[objectName].values[object.uuid];749 this._objectsByName[objectName].count--;750 if (this._objectsByName[objectName].count === 0) {751 delete this._objectsByName[objectName];752 }753 }754 objectRemoved(object) {755 invariant(this._objectsByUUID[object.uuid] === object,756 'The removed object does not belong here!?');757 if (process.env.NODE_ENV !== 'production' || process.env.ENABLE_REACT_ADDON_HOOKS === 'true') {758 if (this._highlightObjectId === object.uuid) {759 this._highlightObjectId = null;760 }761 object.userData.events.removeListener('highlight', this._objectHighlighted);762 object.userData.events.removeListener('hideHighlight', this._hideHighlight);763 }764 delete this._objectsByUUID[object.uuid];765 if (object instanceof THREE.Material) {766 this._materials.splice(this._materials.indexOf(object), 1);767 }768 if (object instanceof THREE.Geometry || object instanceof THREE.BufferGeometry) {769 this._geometries.splice(this._geometries.indexOf(object), 1);770 }771 if (object instanceof THREE.Texture) {772 this._textures.splice(this._textures.indexOf(object), 1);773 }774 this._removeObjectWithName(object.name, object);775 delete object.userData.markup._rootInstance;776 }777 mountedIntoRoot() {778 this._mounted = true;779 this.objectMounted(this);780 }781}...

Full Screen

Full Screen

view-inspection.js

Source:view-inspection.js Github

copy

Full Screen

...311 }312 hide(notify = true) {313 let { isShowing, isPinned, currentId } = this;314 if (isShowing) {315 this._hideHighlight();316 this._hideTooltip();317 this.isShowing = false;318 this.isPinned = false;319 this.currentId = null;320 if (notify) {321 this.didHide(currentId, isPinned);322 }323 }324 }325 _showHighlight(_node, rect) {326 let { style } = this.highlight;327 let { top, left, width, height } = rect;328 let { scrollX, scrollY } = window;329 style.display = 'block';330 style.top = `${top + scrollY}px`;331 style.left = `${left + scrollX}px`;332 style.width = `${width}px`;333 style.height = `${height}px`;334 }335 _hideHighlight() {336 this.highlight.style.display = 'none';337 }338 _showTooltip(node, highlightRect) {339 this._renderTooltipTitle(node);340 this._renderTooltipCategory(node);341 this._renderTooltipDetails(node);342 this._positionTooltip(highlightRect);343 }344 _hideTooltip() {345 this.tooltip.style.display = 'none';346 }347 _renderTooltipTitle(node) {348 let title = this.tooltip.querySelector('.ember-inspector-tooltip-title');349 title.innerHTML = '';...

Full Screen

Full Screen

PolylineHighlight.js

Source:PolylineHighlight.js Github

copy

Full Screen

...67 groupLayer._showHighlight(event.layer, HOVER_BACK_LAYER_FIELD, map);68 this._decreaseGroupBrightness(event.layer);69 },70 mouseout: function(event) {71 groupLayer._hideHighlight(event.layer, HOVER_BACK_LAYER_FIELD, map);72 this._restoreGroupBrightness();73 }74 }75 this.on(this._hoverHandlers);76 },77 _unregisterHoverHandlers: function() {78 if (!this._hoverHandlers) return;79 this.off(this._hoverHandlers);80 },81 _showHighlight: function(polylineLayer, highlightType, map) {82 const backLayer = polylineLayer[highlightType];83 if (backLayer && !map.hasLayer(backLayer)) {84 /* Рисуем подложку поверх линии, затем переносим наверх линию - чтобы85 получились красивые чистые белые границы без пересечений с другими линиями */...

Full Screen

Full Screen

playwright.js

Source:playwright.js Github

copy

Full Screen

...72 for (const uid of this._sockets.keys()) this._onSocksClosed(uid);73 });74 global._playwrightInstance = this;75 }76 async _hideHighlight() {77 await this._channel.hideHighlight();78 }79 _setSelectors(selectors) {80 const selectorsOwner = _selectors.SelectorsOwner.from(this._initializer.selectors);81 this.selectors._removeChannel(selectorsOwner);82 this.selectors = selectors;83 this.selectors._addChannel(selectorsOwner);84 }85 _enablePortForwarding(redirectPortForTest) {86 this._redirectPortForTest = redirectPortForTest;87 this._channel.on('socksRequested', ({88 uid,89 host,90 port...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { _highlight } = require('@playwright/test/lib/server/trace/recorder/recorderApp');2const { _hideHighlight } = require('@playwright/test/lib/server/trace/recorder/recorderApp');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 await page.click('text=Get Started');8 await page.screenshot({ path: `screenshot.png` });9 await _highlight(page, 1, 'div[class="navbar__inner"]', {10 boundingRect: { x: 22, y: 22, width: 100, height: 100 },11 });12 await _hideHighlight(page);13 await browser.close();14})();

Full Screen

Using AI Code Generation

copy

Full Screen

1+const { Internal } = require('playwright/lib/server/browserType');2+Internal.prototype._hideHighlight = function () { };3+const { chromium } = require('playwright');4+(async () => {5+ const browser = await chromium.launch();6+ const page = await browser.newPage();7+ await browser.close();8+})();9+#### internal._hideHighlight()

Full Screen

Using AI Code Generation

copy

Full Screen

1const { _hideHighlight } = require('playwright/lib/server/trace/recorder/recorderApp');2_hideHighlight();3const { _lastActionCode } = require('playwright/lib/server/trace/recorder/recorderApp');4console.log(_lastActionCode());5const { _allActionCodes } = require('playwright/lib/server/trace/recorder/recorderApp');6console.log(_allActionCodes());7const { _allActionCodesInFile } = require('playwright/lib/server/trace/recorder/recorderApp');8console.log(_allActionCodesInFile());9const { _allActionCodesInFileWithIndentation } = require('playwright/lib/server/trace/recorder/recorderApp');10console.log(_allActionCodesInFileWithIndentation());11const { _allActionCodesInFileWithIndentationAndAsyncWrapper } = require('playwright/lib/server/trace/recorder/recorderApp');12console.log(_allActionCodesInFileWithIndentationAndAsyncWrapper());13const { _allActionCodesInFileWithIndentationAndAsyncWrapperAndAwait } = require('playwright/lib/server/trace/recorder/recorderApp');14console.log(_allActionCodesInFileWithIndentationAnd

Full Screen

Using AI Code Generation

copy

Full Screen

1const { _hideHighlight } = require('playwright/lib/server/supplements/recorder/recorderApp');2_hideHighlight();3const { chromium } = require('playwright');4(async () => {5 const browser = await chromium.launch();6 const context = await browser.newContext();7 const page = await context.newPage();8 await page._hideHighlight();9})();10const { chromium } = require('playwright');11(async () => {12 const browser = await chromium.launch();13 const context = await browser.newContext();14 const page = await context.newPage();15 await page._hideHighlight();16 await browser.close();17})();18const { chromium } = require('playwright');19(async () => {20 const browser = await chromium.launchServer();21 const context = await browser.newContext();22 const page = await context.newPage();23 await page._hideHighlight();24 await browser.close();25})();26const { chromium } = require('playwright');27(async () => {

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful