`
}
/** @param {PropertyValues} changedProperties */
firstUpdated(changedProperties) {
super.firstUpdated(changedProperties)
this.headerElement = this.blueprint.querySelector('.ueb-viewport-header')
this.overlayElement = this.blueprint.querySelector('.ueb-viewport-overlay')
this.viewportElement = this.blueprint.querySelector('.ueb-viewport-body')
this.selectorElement = this.blueprint.querySelector('ueb-selector')
this.gridElement = this.viewportElement.querySelector(".ueb-grid")
this.linksContainerElement = this.blueprint.querySelector("[data-links]")
this.linksContainerElement.append(...this.blueprint.getLinks())
this.nodesContainerElement = this.blueprint.querySelector("[data-nodes]")
this.nodesContainerElement.append(...this.blueprint.getNodes())
this.viewportElement.scroll(Configuration.expandGridSize, Configuration.expandGridSize)
}
/** @param {PropertyValues} changedProperties */
willUpdate(changedProperties) {
super.willUpdate(changedProperties)
if (this.headerElement && changedProperties.has("zoom")) {
if (this.headerElement.classList.contains("ueb-zoom-changed")) {
this.headerElement.classList.remove("ueb-zoom-changed")
void this.headerElement.offsetWidth // To trigger the reflow
}
this.headerElement.classList.add("ueb-zoom-changed")
this.headerElement.addEventListener("animationend", this.#removeZoomChanged, { once: true })
}
}
/** @param {PropertyValues} changedProperties */
updated(changedProperties) {
super.updated(changedProperties)
if (changedProperties.has("scrollX") || changedProperties.has("scrollY")) {
this.viewportElement.scroll(this.blueprint.scrollX, this.blueprint.scrollY)
}
if (changedProperties.has("zoom")) {
this.blueprint.style.setProperty("--ueb-scale", this.blueprint.getScale())
const previousZoom = changedProperties.get("zoom")
const minZoom = Math.min(previousZoom, this.blueprint.zoom)
const maxZoom = Math.max(previousZoom, this.blueprint.zoom)
const classes = Utility.range(minZoom, maxZoom)
const getClassName = v => `ueb-zoom-${v}`
if (previousZoom < this.blueprint.zoom) {
this.blueprint.classList.remove(...classes.filter(v => v < 0).map(getClassName))
this.blueprint.classList.add(...classes.filter(v => v > 0).map(getClassName))
} else {
this.blueprint.classList.remove(...classes.filter(v => v > 0).map(getClassName))
this.blueprint.classList.add(...classes.filter(v => v < 0).map(getClassName))
}
}
}
getCommentNodes(justSelected = false) {
return this.blueprint.querySelectorAll(
`ueb-node[data-type="${Configuration.paths.comment}"]${justSelected ? '[data-selected="true"]' : ''}`
+ `, ueb-node[data-type="${Configuration.paths.materialGraphNodeComment}"]${justSelected ? '[data-selected="true"]' : ''}`
)
}
/** @param {PinReferenceEntity} pinReference */
getPin(pinReference) {
return /** @type {PinElement} */(this.blueprint.querySelector(
`ueb-node[data-title="${pinReference.objectName}"] ueb-pin[data-id="${pinReference.pinGuid}"]`
))
}
getCopyInputObject() {
return this.#copyInputObject
}
getPasteInputObject() {
return this.#pasteInputObject
}
getZoomInputObject() {
return this.#zoomInputObject
}
/**
* @param {Number} x
* @param {Number} y
*/
isPointVisible(x, y) {
return false
}
gridTopVisibilityBoundary() {
return this.blueprint.scaleCorrect(this.blueprint.scrollY) - this.blueprint.translateY
}
gridRightVisibilityBoundary() {
return this.gridLeftVisibilityBoundary() + this.blueprint.scaleCorrect(this.viewportSize[0])
}
gridBottomVisibilityBoundary() {
return this.gridTopVisibilityBoundary() + this.blueprint.scaleCorrect(this.viewportSize[1])
}
gridLeftVisibilityBoundary() {
return this.blueprint.scaleCorrect(this.blueprint.scrollX) - this.blueprint.translateX
}
centerViewport(x = 0, y = 0, smooth = true) {
const centerX = this.gridLeftVisibilityBoundary() + this.blueprint.scaleCorrect(this.viewportSize[0] / 2)
const centerY = this.gridTopVisibilityBoundary() + this.blueprint.scaleCorrect(this.viewportSize[1] / 2)
this.blueprint.scrollDelta(
this.blueprint.scaleCorrectReverse(x - centerX),
this.blueprint.scaleCorrectReverse(y - centerY),
smooth
)
}
centerContentInViewport(smooth = true) {
let avgX = 0
let avgY = 0
let minX = Number.MAX_SAFE_INTEGER
let maxX = Number.MIN_SAFE_INTEGER
let minY = Number.MAX_SAFE_INTEGER
let maxY = Number.MIN_SAFE_INTEGER
const nodes = this.blueprint.getNodes()
for (const node of nodes) {
avgX += node.leftBoundary() + node.rightBoundary()
avgY += node.topBoundary() + node.bottomBoundary()
minX = Math.min(minX, node.leftBoundary())
maxX = Math.max(maxX, node.rightBoundary())
minY = Math.min(minY, node.topBoundary())
maxY = Math.max(maxY, node.bottomBoundary())
}
avgX = Math.round(maxX - minX <= this.viewportSize[0]
? (maxX + minX) / 2
: avgX / (2 * nodes.length)
)
avgY = Math.round(maxY - minY <= this.viewportSize[1]
? (maxY + minY) / 2
: avgY / (2 * nodes.length)
)
this.centerViewport(avgX, avgY, smooth)
}
}