mirror of
https://github.com/barsdeveloper/ueblueprint.git
synced 2026-02-14 17:14:41 +08:00
2 lines
47 KiB
JavaScript
2 lines
47 KiB
JavaScript
class t{constructor(){this.nodes=new Array,this.expandGridSize=400,this.additional=[0,0],this.translateValue=[0,0],this.mousePosition=[0,0]}}const e=String.raw;class n{render(t){return""}getElements(t){let e=document.createElement("div");return e.innerHTML=this.render(t),e.childNodes}}class r extends n{header(t){return e`<div class="ueb-viewport-header"><div class="ueb-viewport-zoom">1:1</div></div>`}overlay(){return e`<div class="ueb-viewport-overlay"></div>`}viewport(t){return e`<div class="ueb-viewport-body"><div class="ueb-grid" style="--ueb-additional-x:${t.additional[0]}--ueb-additional-y:${t.additional[1]}--ueb-translate-x:${t.translateValue[0]}--ueb-translate-y:${t.translateValue[1]}"><div class="ueb-grid-content" data-nodes></div></div></div>`}render(t){return e`${this.header(t)} ${this.overlay(t)} ${this.viewport(t)}`}}class i{constructor(t,e,n){if(this.target=t,this.blueprint=e,this.options=n,n?.wantsFocusCallback){let t=this;this.blueprintfocusHandler=e=>t.blueprintFocused(),this.blueprintunfocusHandler=e=>t.blueprintUnfocused(),this.blueprint.addEventListener("blueprintfocus",this.blueprintfocusHandler),this.blueprint.addEventListener("blueprintunfocus",this.blueprintunfocusHandler)}}unlistenDOMElement(){this.blueprint.removeEventListener("blueprintfocus",this.blueprintfocusHandler),this.blueprint.removeEventListener("blueprintunfocus",this.blueprintunfocusHandler)}blueprintFocused(){}blueprintUnfocused(){}}class s{static sanitize(t){return t instanceof Object&&(t instanceof Boolean||t instanceof Number||t instanceof String)?t.valueOf():t}constructor(t,e=!0,n){void 0===n&&(n=s.sanitize(new t)),this.value=n,this.showDefault=e,this.type=t}}class o{static clamp(t,e,n){return Math.min(Math.max(t,e),n)}static getScale(t){return getComputedStyle(t).getPropertyValue("--ueb-scale")}static objectSet(t,e,n,r=!1){if(e.constructor!=Array&&console.error("Expected keys to be an array."),1==e.length){if(r||e[0]in t)return t[e[0]]=n,!0}else if(e.length>0)return o.objectSet(t[e[0]],e.slice(1),n,r);return!1}static objectGet(t,e,n=null){return e.constructor!=Array&&console.error("Expected keys to be an array."),0!=e.length&&e[0]in t?1==e.length?t[e[0]]:o.objectGet(t[e[0]],e.slice(1),n):n}static equals(t,e){return(t=s.sanitize(t))===(e=s.sanitize(e))}static FirstCapital(t){return t.charAt(0).toUpperCase()+t.substring(1)}static getType(t){let e=t?.constructor;switch(e){case s:return t.type;case Function:return t;default:return e}}}class a extends i{constructor(t,e,n){super(t,e,n),this.movementSpace=this.blueprint?.getGridDOMElement()??document.documentElement}getLocation(t){const e=1/o.getScale(this.target),n=this.movementSpace.getBoundingClientRect();return[(t.clientX-n.x)*e,(t.clientY-n.y)*e]}}class u extends a{constructor(t,e,n){super(t,e,n),this.clickButton=n?.clickButton??0,this.exitAnyButton=n?.exitAnyButton??!0,this.moveEverywhere=n?.moveEverywhere??!1,this.looseTarget=n?.looseTarget??!1,this.started=!1,this.clickedPosition=[0,0];const r=this.moveEverywhere?document.documentElement:this.movementSpace;let i=this;this.mouseDownHandler=t=>{if(this.blueprint.setFocused(!0),t.button===i.clickButton)(i.looseTarget||t.target==t.currentTarget)&&(t.stopPropagation(),i.started=!1,r.addEventListener("mousemove",i.mouseStartedMovingHandler),document.addEventListener("mouseup",i.mouseUpHandler),i.clickedPosition=i.getLocation(t),i.clicked(i.clickedPosition));else i.exitAnyButton||i.mouseUpHandler(t)},this.mouseStartedMovingHandler=t=>{t.preventDefault(),t.stopPropagation(),r.removeEventListener("mousemove",i.mouseStartedMovingHandler),r.addEventListener("mousemove",i.mouseMoveHandler),i.startDrag(),i.started=!0},this.mouseMoveHandler=t=>{t.preventDefault(),t.stopPropagation();const e=i.getLocation(t),n=[t.movementX,t.movementY];i.dragTo(e,n)},this.mouseUpHandler=t=>{i.exitAnyButton&&t.button!=i.clickButton||(r.removeEventListener("mousemove",i.mouseStartedMovingHandler),r.removeEventListener("mousemove",i.mouseMoveHandler),document.removeEventListener("mouseup",i.mouseUpHandler),i.endDrag())},this.target.addEventListener("mousedown",this.mouseDownHandler),2==this.clickButton&&this.target.addEventListener("contextmenu",this.preventDefault)}preventDefault(t){t.preventDefault()}unlistenDOMElement(){super.unlistenDOMElement(),this.target.removeEventListener("mousedown",this.mouseDownHandler),2==this.clickButton&&this.target.removeEventListener("contextmenu",this.preventDefault),blueprintunfocusHandler}clicked(t){}startDrag(){}dragTo(t,e){}endDrag(){}}class l extends u{dragTo(t,e){this.blueprint.scrollDelta([-e[0],-e[1]])}}class c extends HTMLElement{constructor(t,e){super(),this.blueprint=null,this.entity=t,this.template=e}connectedCallback(){this.blueprint=this.closest("u-blueprint"),this.append(...this.template.getElements(this.entity))}}class h{constructor(t=(t=>t),e=null){this.array=new Uint32Array(e),this.comparisonValueSupplier=t,this.length=0,this.currentPosition=0}get(t){return t>=0&&t<this.length?this.array[t]:null}getArray(){return this.array}getPosition(t){let e=0,n=this.length;for(;e<n;){let r=Math.floor((e+n)/2);this.comparisonValueSupplier(this.array[r])<t?e=r+1:n=r}return e}reserve(t){if(this.array.length<t){let e=new Uint32Array(t);e.set(this.array),this.array=e}}insert(t,e=null){let n=this.getPosition(this.comparisonValueSupplier(t));return(n<this.currentPosition||null!=e&&n==this.currentPosition&&this.comparisonValueSupplier(t)<e)&&++this.currentPosition,this.shiftRight(n),this.array[n]=t,++this.length,n}remove(t){let e=this.getPosition(this.comparisonValueSupplier(t));this.array[e]==t&&this.removeAt(e)}removeAt(t){return t<this.currentPosition&&--this.currentPosition,this.shiftLeft(t),--this.length,t}getNext(){return this.currentPosition>=0&&this.currentPosition<this.length?this.get(this.currentPosition):null}getNextValue(){return this.currentPosition>=0&&this.currentPosition<this.length?this.comparisonValueSupplier(this.get(this.currentPosition)):Number.MAX_SAFE_INTEGER}getPrev(){return this.currentPosition>0?this.get(this.currentPosition-1):null}getPrevValue(){return this.currentPosition>0?this.comparisonValueSupplier(this.get(this.currentPosition-1)):Number.MIN_SAFE_INTEGER}shiftLeft(t,e=1){this.array.set(this.array.subarray(t+e),t)}shiftRight(t,e=1){this.array.set(this.array.subarray(t,-e),t+e)}}class d{constructor(t,e,n,r){this.initialPosition=t,this.finalPosition=t,this.metadata=new Array(e.length),this.primaryOrder=new h((t=>this.metadata[t].primaryBoundary)),this.secondaryOrder=new h((t=>this.metadata[t].secondaryBoundary)),this.selectFunc=r,this.rectangles=e,this.primaryOrder.reserve(this.rectangles.length),this.secondaryOrder.reserve(this.rectangles.length),e.forEach(((t,e)=>{let i={primaryBoundary:this.initialPosition[0],secondaryBoundary:this.initialPosition[1],rectangle:e,onSecondaryAxis:!1};this.metadata[e]=i,r(t,!1);const s=n(t);this.initialPosition[1]<s.secondaryInf?i.secondaryBoundary=s.secondaryInf:s.secondarySup<this.initialPosition[1]?i.secondaryBoundary=s.secondarySup:i.onSecondaryAxis=!0,this.initialPosition[0]<s.primaryInf?(i.primaryBoundary=s.primaryInf,this.primaryOrder.insert(e)):s.primarySup<this.initialPosition[0]?(i.primaryBoundary=s.primarySup,this.primaryOrder.insert(e)):s.secondarySup<this.initialPosition[1]||this.initialPosition[1]<s.secondaryInf?this.secondaryOrder.insert(e):r(t,!0)})),this.primaryOrder.currentPosition=this.primaryOrder.getPosition(this.initialPosition[0]),this.secondaryOrder.currentPosition=this.secondaryOrder.getPosition(this.initialPosition[1]),this.computeBoundaries(this.initialPosition)}computeBoundaries(){this.boundaries={primaryN:{v:this.primaryOrder.getPrevValue(),i:this.primaryOrder.getPrev()},primaryP:{v:this.primaryOrder.getNextValue(),i:this.primaryOrder.getNext()},secondaryN:{v:this.secondaryOrder.getPrevValue(),i:this.secondaryOrder.getPrev()},secondaryP:{v:this.secondaryOrder.getNextValue(),i:this.secondaryOrder.getNext()}}}selectTo(t){const e=[Math.sign(t[0]-this.initialPosition[0]),Math.sign(t[1]-this.initialPosition[1])],n=(n,r)=>{if(this.metadata[n].onSecondaryAxis)this.selectFunc(this.rectangles[n],r);else if(r){this.secondaryOrder.insert(n,t[1]);const r=this.metadata[n].secondaryBoundary;Math.sign(t[1]-r)==e[1]&&Math.sign(r-this.initialPosition[1])==e[1]&&this.selectFunc(this.rectangles[n],!0)}else this.selectFunc(this.rectangles[n],!1),this.secondaryOrder.remove(n);this.computeBoundaries(t),this.selectTo(t)};t[0]<this.boundaries.primaryN.v?(--this.primaryOrder.currentPosition,n(this.boundaries.primaryN.i,this.initialPosition[0]>this.boundaries.primaryN.v&&t[0]<this.initialPosition[0])):t[0]>this.boundaries.primaryP.v&&(++this.primaryOrder.currentPosition,n(this.boundaries.primaryP.i,this.initialPosition[0]<this.boundaries.primaryP.v&&this.initialPosition[0]<t[0]));const r=(e,n)=>{this.selectFunc(this.rectangles[e],n),this.computeBoundaries(t),this.selectTo(t)};t[1]<this.boundaries.secondaryN.v?(--this.secondaryOrder.currentPosition,r(this.boundaries.secondaryN.i,this.initialPosition[1]>this.boundaries.secondaryN.v&&t[1]<this.initialPosition[1])):t[1]>this.boundaries.secondaryP.v&&(++this.secondaryOrder.currentPosition,r(this.boundaries.secondaryP.i,this.initialPosition[1]<this.boundaries.secondaryP.v&&this.initialPosition[1]<t[1])),this.finalPosition=t}}class p extends c{constructor(){super({},new n),this.selectionModel=null}connectedCallback(){super.connectedCallback(),this.classList.add("ueb-selector"),this.dataset.selecting="false"}startSelecting(t){t=this.blueprint.compensateTranslation(t),this.style.setProperty("--ueb-select-from-x",t[0]),this.style.setProperty("--ueb-select-from-y",t[1]),this.style.setProperty("--ueb-select-to-x",t[0]),this.style.setProperty("--ueb-select-to-y",t[1]),this.dataset.selecting="true",this.selectionModel=new d(t,this.blueprint.getNodes(),this.blueprint.nodeBoundariesSupplier,this.blueprint.nodeSelectToggleFunction)}doSelecting(t){t=this.blueprint.compensateTranslation(t),this.style.setProperty("--ueb-select-to-x",t[0]),this.style.setProperty("--ueb-select-to-y",t[1]),this.selectionModel.selectTo(t)}finishSelecting(){this.dataset.selecting="false",this.selectionModel=null}}customElements.define("u-selector",p);class f extends a{constructor(t,e,n={}){n.wantsFocusCallback=!0,super(t,e,n);let r=this;this.mousemoveHandler=t=>{r.blueprint.entity.mousePosition=r.getLocation(t)}}blueprintFocused(){this.target.addEventListener("mousemove",this.mousemoveHandler)}blueprintUnfocused(){this.target.removeEventListener("mousemove",this.mousemoveHandler)}}class m{constructor(t={}){const e=(n,r,i)=>{let a=n.concat("");const u=a.length-1;for(let n in i){if(a[u]=n,i[n]?.constructor===Object){r[n]={},e(a,r[n],i[n]);continue}const l=o.objectGet(t,a);if(null!==l){r[n]=l;continue}let c=i[n];if(c instanceof s){if(!c.showDefault)continue;c=c.value}c instanceof Array?r[n]=[]:(c instanceof Function&&(c=s.sanitize(new c)),r[n]=c)}};e([],this,this.getAttributes())}}class g extends m{static attributes={value:String};static generateGuid(t=!0){let e=new Uint32Array(4);!0===t&&crypto.getRandomValues(e);let n="";return e.forEach((t=>{n+=("0".repeat(8)+t.toString(16).toUpperCase()).slice(-8)})),new g({valud:n})}getAttributes(){return g.attributes}toString(){return this.value}}class b extends m{static attributes={namespace:String,key:String,value:String};getAttributes(){return b.attributes}}class y extends m{static attributes={type:String,path:String};getAttributes(){return y.attributes}}class v extends m{static attributes={value:String};getAttributes(){return v.attributes}toString(){return this.value}}class w extends m{static attributes={objectName:v,pinGuid:g};getAttributes(){return w.attributes}}class E extends m{static attributes={PinId:g,PinName:"",PinFriendlyName:new s(b,!1,null),PinToolTip:"",Direction:new s(String,!1,""),PinType:{PinCategory:"",PinSubCategory:"",PinSubCategoryObject:y,PinSubCategoryMemberReference:null,PinValueType:null,ContainerType:y,bIsReference:!1,bIsConst:!1,bIsWeakPointer:!1,bIsUObjectWrapper:!1},LinkedTo:[w],DefaultValue:"",AutogeneratedDefaultValue:"",PersistentGuid:g,bHidden:!1,bNotConnectable:!1,bDefaultValueIsReadOnly:!1,bDefaultValueIsIgnored:!1,bAdvancedView:!1,bOrphanedPin:!1};getAttributes(){return E.attributes}getPinDisplayName(){return this.PinName}isOutput(){if("EGPD_Output"===this.Direction)return!0}}class S extends n{header(t){return e`<div class="ueb-node-header"><span class="ueb-node-name"><span class="ueb-node-symbol"></span> <span class="ueb-node-text">${t.getNodeDisplayName()}</span></span></div>`}body(t){let n=t.CustomProperties.filter((t=>t instanceof E)),r=n.filter((t=>t.isOutput()));return n=n.filter((t=>!t.isOutput())),e`<div class="ueb-node-body"><div class="ueb-node-inputs">${n.map(((t,r)=>e`<div class="ueb-node-input ueb-node-value-${t.type}"><span class="ueb-node-value-icon ${n[r].connected?"ueb-node-value-fill":""}"></span> ${t.getPinDisplayName()}</div>`)).join("")??""}</div><div class="ueb-node-outputs">${r.map(((t,n)=>e`<div class="ueb-node-output ueb-node-value-${t.type}">${t.getPinDisplayName()} <span class="ueb-node-value-icon ${r[n].connected?"ueb-node-value-fill":""}"></span></div>`)).join("")??""}</div></div>`}render(t){return e`<div class="ueb-node-border"><div class="ueb-node-content">${this.header(t)} ${this.body(t)}</div></div>`}}class P extends m{static attributes={MemberParent:y,MemberName:""};getAttributes(){return P.attributes}}class x extends m{static attributes={value:Number};getAttributes(){return x.attributes}constructor(t={}){super(t),this.value=Math.round(this.value)}valueOf(){return this.value}toString(){return this.value.toString()}}class O extends m{static attributes={MemberName:String,MemberGuid:g,bSelfContext:!1};getAttributes(){return O.attributes}}class L extends m{static attributes={Class:y,Name:"",bIsPureFunc:new s(Boolean,!1,!1),VariableReference:new s(O,!1,null),FunctionReference:new s(P,!1,null),EventReference:new s(P,!1,null),TargetType:new s(y,!1,null),NodePosX:x,NodePosY:x,NodeGuid:g,ErrorType:new s(x,!1),ErrorMsg:new s(String,!1,""),CustomProperties:[E]};getAttributes(){return L.attributes}getNodeDisplayName(){return this.Name}}class B extends u{constructor(t,e,n){super(t,e,n),this.stepSize=parseInt(n?.stepSize),this.mousePosition=[0,0]}snapToGrid(t){return[this.stepSize*Math.round(t[0]/this.stepSize),this.stepSize*Math.round(t[1]/this.stepSize)]}startDrag(){(isNaN(this.stepSize)||this.stepSize<=0)&&(this.stepSize=parseInt(getComputedStyle(this.target).getPropertyValue("--ueb-grid-snap")),(isNaN(this.stepSize)||this.stepSize<=0)&&(this.stepSize=1)),this.mousePosition=1!=this.stepSize?this.snapToGrid(this.clickedPosition):this.clickedPosition}dragTo(t,e){const n=1!=this.stepSize?this.snapToGrid(t):t,r=[n[0]-this.mousePosition[0],n[1]-this.mousePosition[1]];0==r[0]&&0==r[1]||(this.target.dispatchDragEvent(r),this.mousePosition=n)}}class N extends c{constructor(...t){super(...t),this.dragObject=null,this.location=[0,0],this.selected=!1;let e=this;this.dragHandler=t=>{e.addLocation(t.detail.value)}}connectedCallback(){super.connectedCallback(),this.dragObject=new B(this,this.blueprint,{looseTarget:!0})}disconnectedCallback(){this.dragObject.unlistenDOMElement()}setLocation(t=[0,0]){this.location=t,this.style.setProperty("--ueb-position-x",this.location[0]),this.style.setProperty("--ueb-position-y",this.location[1])}addLocation(t){this.setLocation([this.location[0]+t[0],this.location[1]+t[1]])}dispatchDragEvent(t){this.selected||(this.blueprint.unselectAll(),this.setSelected(!0));let e=new CustomEvent("uDragSelected",{detail:{instigator:this,value:t},bubbles:!1,cancelable:!0,composed:!1});this.blueprint.dispatchEvent(e)}setSelected(t=!0){this.selected!=t&&(this.selected=t,this.selected?(this.classList.add("ueb-selected"),this.blueprint.addEventListener("uDragSelected",this.dragHandler)):(this.classList.remove("ueb-selected"),this.blueprint.removeEventListener("uDragSelected",this.dragHandler)))}}class M{static#t=new Map;static registerSerializer(t,e){M.#t.set(t,e)}static getSerializer(t){return M.#t.get(o.getType(t))}}class j extends u{constructor(t,e,n){super(t,e,n)}startDrag(){}dragTo(t,e){}endDrag(){this.started}}class A extends N{static fromSerializedObject(t){let e=M.getSerializer(L).read(t);return new A(e)}constructor(t){super(t,new S),this.graphNodeName="n/a",this.dragLinkObjects=Array(),super.setLocation([this.entity.NodePosX,this.entity.NodePosY])}connectedCallback(){this.getAttribute("type")?.trim(),super.connectedCallback(),this.classList.add("ueb-node"),this.selected&&this.classList.add("ueb-selected"),this.style.setProperty("--ueb-position-x",this.location[0]),this.style.setProperty("--ueb-position-y",this.location[1]),this.querySelectorAll(".ueb-node-input, .ueb-node-output").forEach((t=>{this.dragLinkObjects.push(new j(t,this.blueprint,{clickButton:0,moveEverywhere:!0,exitAnyButton:!0,looseTarget:!0}))}))}setLocation(t=[0,0]){this.entity.NodePosX=t[0],this.entity.NodePosY=t[1],super.setLocation(t)}}customElements.define("u-node",A);"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function k(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var T={exports:{}};"undefined"!=typeof self&&self;var z=k(T.exports=function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:r})},n.r=function(t){Object.defineProperty(t,"__esModule",{value:!0})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e,n){function r(t){if(!(this instanceof r))return new r(t);this._=t}var i=r.prototype;function s(t,e){for(var n=0;n<t;n++)e(n)}function o(t,e,n){return function(t,e){s(e.length,(function(n){t(e[n],n,e)}))}((function(n,r,i){e=t(e,n,r,i)}),n),e}function a(t,e){return o((function(e,n,r,i){return e.concat([t(n,r,i)])}),[],e)}function u(t,e){var n={v:0,buf:e};return s(t,(function(){var t;n={v:n.v<<1|(t=n.buf,t[0]>>7),buf:function(t){var e=o((function(t,e,n,r){return t.concat(n===r.length-1?Buffer.from([e,0]).readUInt16BE(0):r.readUInt16BE(n))}),[],t);return Buffer.from(a((function(t){return(t<<1&65535)>>8}),e))}(n.buf)}})),n}function l(){return"undefined"!=typeof Buffer}function c(){if(!l())throw new Error("Buffer global does not exist; please use webpack if you need to parse Buffers in the browser.")}function h(t){c();var e=o((function(t,e){return t+e}),0,t);if(e%8!=0)throw new Error("The bits ["+t.join(", ")+"] add up to "+e+" which is not an even number of bytes; the total should be divisible by 8");var n,i=e/8,s=(n=function(t){return t>48},o((function(t,e){return t||(n(e)?e:t)}),null,t));if(s)throw new Error(s+" bit range requested exceeds 48 bit (6 byte) Number max.");return new r((function(e,n){var r=i+n;return r>e.length?S(n,i.toString()+" bytes"):E(r,o((function(t,e){var n=u(e,t.buf);return{coll:t.coll.concat(n.v),buf:n.buf}}),{coll:[],buf:e.slice(n,r)},t).coll)}))}function d(t,e){return new r((function(n,r){return c(),r+e>n.length?S(r,e+" bytes for "+t):E(r+e,n.slice(r,r+e))}))}function p(t,e){if("number"!=typeof(n=e)||Math.floor(n)!==n||e<0||e>6)throw new Error(t+" requires integer length in range [0, 6].");var n}function f(t){return p("uintBE",t),d("uintBE("+t+")",t).map((function(e){return e.readUIntBE(0,t)}))}function m(t){return p("uintLE",t),d("uintLE("+t+")",t).map((function(e){return e.readUIntLE(0,t)}))}function g(t){return p("intBE",t),d("intBE("+t+")",t).map((function(e){return e.readIntBE(0,t)}))}function b(t){return p("intLE",t),d("intLE("+t+")",t).map((function(e){return e.readIntLE(0,t)}))}function y(t){return t instanceof r}function v(t){return"[object Array]"==={}.toString.call(t)}function w(t){return l()&&Buffer.isBuffer(t)}function E(t,e){return{status:!0,index:t,value:e,furthest:-1,expected:[]}}function S(t,e){return v(e)||(e=[e]),{status:!1,index:-1,value:null,furthest:t,expected:e}}function P(t,e){if(!e)return t;if(t.furthest>e.furthest)return t;var n=t.furthest===e.furthest?function(t,e){if(function(){if(void 0!==r._supportsSet)return r._supportsSet;var t="undefined"!=typeof Set;return r._supportsSet=t,t}()&&Array.from){for(var n=new Set(t),i=0;i<e.length;i++)n.add(e[i]);var s=Array.from(n);return s.sort(),s}for(var o={},a=0;a<t.length;a++)o[t[a]]=!0;for(var u=0;u<e.length;u++)o[e[u]]=!0;var l=[];for(var c in o)({}).hasOwnProperty.call(o,c)&&l.push(c);return l.sort(),l}(t.expected,e.expected):e.expected;return{status:t.status,index:t.index,value:t.value,furthest:e.furthest,expected:n}}var x={};function O(t,e){if(w(t))return{offset:e,line:-1,column:-1};t in x||(x[t]={});for(var n=x[t],r=0,i=0,s=0,o=e;o>=0;){if(o in n){r=n[o].line,0===s&&(s=n[o].lineStart);break}"\n"===t.charAt(o)&&(i++,0===s&&(s=o+1)),o--}var a=r+i,u=e-s;return n[e]={line:a,lineStart:s},{offset:e,line:a+1,column:u+1}}function L(t){if(!y(t))throw new Error("not a parser: "+t)}function B(t,e){return"string"==typeof t?t.charAt(e):t[e]}function N(t){if("number"!=typeof t)throw new Error("not a number: "+t)}function M(t){if("function"!=typeof t)throw new Error("not a function: "+t)}function j(t){if("string"!=typeof t)throw new Error("not a string: "+t)}var A=2,k=3,T=8,z=5*T,C=4*T,D=" ";function G(t,e){return new Array(e+1).join(t)}function F(t,e,n){var r=e-t.length;return r<=0?t:G(n,r)+t}function H(t,e,n,r){return{from:t-e>0?t-e:0,to:t+n>r?r:t+n}}function V(t,e){var n,r,i,s,u,l=e.index,c=l.offset,h=1;if(c===t.length)return"Got the end of the input";if(w(t)){var d=c-c%T,p=c-d,f=H(d,z,C+T,t.length),m=a((function(t){return a((function(t){return F(t.toString(16),2,"0")}),t)}),function(t,e){var n=t.length,r=[],i=0;if(n<=e)return[t.slice()];for(var s=0;s<n;s++)r[i]||r.push([]),r[i].push(t[s]),(s+1)%e==0&&i++;return r}(t.slice(f.from,f.to).toJSON().data,T));s=function(t){return 0===t.from&&1===t.to?{from:t.from,to:t.to}:{from:t.from/T,to:Math.floor(t.to/T)}}(f),r=d/T,n=3*p,p>=4&&(n+=1),h=2,i=a((function(t){return t.length<=4?t.join(" "):t.slice(0,4).join(" ")+" "+t.slice(4).join(" ")}),m),(u=(8*(s.to>0?s.to-1:s.to)).toString(16).length)<2&&(u=2)}else{var g=t.split(/\r\n|[\n\r\u2028\u2029]/);n=l.column-1,r=l.line-1,s=H(r,A,k,g.length),i=g.slice(s.from,s.to),u=s.to.toString().length}var b=r-s.from;return w(t)&&(u=(8*(s.to>0?s.to-1:s.to)).toString(16).length)<2&&(u=2),o((function(e,r,i){var o,a=i===b,l=a?"> ":D;return o=w(t)?F((8*(s.from+i)).toString(16),u,"0"):F((s.from+i+1).toString(),u," "),[].concat(e,[l+o+" | "+r],a?[D+G(" ",u)+" | "+F("",n," ")+G("^",h)]:[])}),[],i).join("\n")}function W(t,e){return["\n","-- PARSING FAILED "+G("-",50),"\n\n",V(t,e),"\n\n",(n=e.expected,1===n.length?"Expected:\n\n"+n[0]:"Expected one of the following: \n\n"+n.join(", ")),"\n"].join("");var n}function _(t){return void 0!==t.flags?t.flags:[t.global?"g":"",t.ignoreCase?"i":"",t.multiline?"m":"",t.unicode?"u":"",t.sticky?"y":""].join("")}function I(){for(var t=[].slice.call(arguments),e=t.length,n=0;n<e;n+=1)L(t[n]);return r((function(n,r){for(var i,s=new Array(e),o=0;o<e;o+=1){if(!(i=P(t[o]._(n,r),i)).status)return i;s[o]=i.value,r=i.index}return P(E(r,s),i)}))}function q(){var t=[].slice.call(arguments);if(0===t.length)throw new Error("seqMap needs at least one argument");var e=t.pop();return M(e),I.apply(null,t).map((function(t){return e.apply(null,t)}))}function $(){var t=[].slice.call(arguments),e=t.length;if(0===e)return K("zero alternates");for(var n=0;n<e;n+=1)L(t[n]);return r((function(e,n){for(var r,i=0;i<t.length;i+=1)if((r=P(t[i]._(e,n),r)).status)return r;return r}))}function R(t,e){return U(t,e).or(Y([]))}function U(t,e){return L(t),L(e),q(t,e.then(t).many(),(function(t,e){return[t].concat(e)}))}function X(t){j(t);var e="'"+t+"'";return r((function(n,r){var i=r+t.length,s=n.slice(r,i);return s===t?E(i,s):S(r,e)}))}function Z(t,e){!function(t){if(!(t instanceof RegExp))throw new Error("not a regexp: "+t);for(var e=_(t),n=0;n<e.length;n++){var r=e.charAt(n);if("i"!==r&&"m"!==r&&"u"!==r&&"s"!==r)throw new Error('unsupported regexp flag "'+r+'": '+t)}}(t),arguments.length>=2?N(e):e=0;var n=function(t){return RegExp("^(?:"+t.source+")",_(t))}(t),i=""+t;return r((function(t,r){var s=n.exec(t.slice(r));if(s){if(0<=e&&e<=s.length){var o=s[0],a=s[e];return E(r+o.length,a)}return S(r,"valid match group (0 to "+s.length+") in "+i)}return S(r,i)}))}function Y(t){return r((function(e,n){return E(n,t)}))}function K(t){return r((function(e,n){return S(n,t)}))}function J(t){if(y(t))return r((function(e,n){var r=t._(e,n);return r.index=n,r.value="",r}));if("string"==typeof t)return J(X(t));if(t instanceof RegExp)return J(Z(t));throw new Error("not a string, regexp, or parser: "+t)}function Q(t){return L(t),r((function(e,n){var r=t._(e,n),i=e.slice(n,r.index);return r.status?S(n,'not "'+i+'"'):E(n,null)}))}function tt(t){return M(t),r((function(e,n){var r=B(e,n);return n<e.length&&t(r)?E(n+1,r):S(n,"a character/byte matching "+t)}))}function et(t,e){arguments.length<2&&(e=t,t=void 0);var n=r((function(t,r){return n._=e()._,n._(t,r)}));return t?n.desc(t):n}function nt(){return K("fantasy-land/empty")}i.parse=function(t){if("string"!=typeof t&&!w(t))throw new Error(".parse must be called with a string or Buffer as its argument");var e,n=this.skip(ot)._(t,0);return e=n.status?{status:!0,value:n.value}:{status:!1,index:O(t,n.furthest),expected:n.expected},delete x[t],e},i.tryParse=function(t){var e=this.parse(t);if(e.status)return e.value;var n=W(t,e),r=new Error(n);throw r.type="ParsimmonError",r.result=e,r},i.assert=function(t,e){return this.chain((function(n){return t(n)?Y(n):K(e)}))},i.or=function(t){return $(this,t)},i.trim=function(t){return this.wrap(t,t)},i.wrap=function(t,e){return q(t,this,e,(function(t,e){return e}))},i.thru=function(t){return t(this)},i.then=function(t){return L(t),I(this,t).map((function(t){return t[1]}))},i.many=function(){var t=this;return r((function(e,n){for(var r=[],i=void 0;;){if(!(i=P(t._(e,n),i)).status)return P(E(n,r),i);if(n===i.index)throw new Error("infinite loop detected in .many() parser --- calling .many() on a parser which can accept zero characters is usually the cause");n=i.index,r.push(i.value)}}))},i.tieWith=function(t){return j(t),this.map((function(e){if(function(t){if(!v(t))throw new Error("not an array: "+t)}(e),e.length){j(e[0]);for(var n=e[0],r=1;r<e.length;r++)j(e[r]),n+=t+e[r];return n}return""}))},i.tie=function(){return this.tieWith("")},i.times=function(t,e){var n=this;return arguments.length<2&&(e=t),N(t),N(e),r((function(r,i){for(var s=[],o=void 0,a=void 0,u=0;u<t;u+=1){if(a=P(o=n._(r,i),a),!o.status)return a;i=o.index,s.push(o.value)}for(;u<e&&(a=P(o=n._(r,i),a),o.status);u+=1)i=o.index,s.push(o.value);return P(E(i,s),a)}))},i.result=function(t){return this.map((function(){return t}))},i.atMost=function(t){return this.times(0,t)},i.atLeast=function(t){return q(this.times(t),this.many(),(function(t,e){return t.concat(e)}))},i.map=function(t){M(t);var e=this;return r((function(n,r){var i=e._(n,r);return i.status?P(E(i.index,t(i.value)),i):i}))},i.contramap=function(t){M(t);var e=this;return r((function(n,r){var i=e.parse(t(n.slice(r)));return i.status?E(r+n.length,i.value):i}))},i.promap=function(t,e){return M(t),M(e),this.contramap(t).map(e)},i.skip=function(t){return I(this,t).map((function(t){return t[0]}))},i.mark=function(){return q(rt,this,rt,(function(t,e,n){return{start:t,value:e,end:n}}))},i.node=function(t){return q(rt,this,rt,(function(e,n,r){return{name:t,value:n,start:e,end:r}}))},i.sepBy=function(t){return R(this,t)},i.sepBy1=function(t){return U(this,t)},i.lookahead=function(t){return this.skip(J(t))},i.notFollowedBy=function(t){return this.skip(Q(t))},i.desc=function(t){v(t)||(t=[t]);var e=this;return r((function(n,r){var i=e._(n,r);return i.status||(i.expected=t),i}))},i.fallback=function(t){return this.or(Y(t))},i.ap=function(t){return q(t,this,(function(t,e){return t(e)}))},i.chain=function(t){var e=this;return r((function(n,r){var i=e._(n,r);return i.status?P(t(i.value)._(n,i.index),i):i}))},i.concat=i.or,i.empty=nt,i.of=Y,i["fantasy-land/ap"]=i.ap,i["fantasy-land/chain"]=i.chain,i["fantasy-land/concat"]=i.concat,i["fantasy-land/empty"]=i.empty,i["fantasy-land/of"]=i.of,i["fantasy-land/map"]=i.map;var rt=r((function(t,e){return E(e,O(t,e))})),it=r((function(t,e){return e>=t.length?S(e,"any character/byte"):E(e+1,B(t,e))})),st=r((function(t,e){return E(t.length,t.slice(e))})),ot=r((function(t,e){return e<t.length?S(e,"EOF"):E(e,null)})),at=Z(/[0-9]/).desc("a digit"),ut=Z(/[0-9]*/).desc("optional digits"),lt=Z(/[a-z]/i).desc("a letter"),ct=Z(/[a-z]*/i).desc("optional letters"),ht=Z(/\s*/).desc("optional whitespace"),dt=Z(/\s+/).desc("whitespace"),pt=X("\r"),ft=X("\n"),mt=X("\r\n"),gt=$(mt,ft,pt).desc("newline"),bt=$(gt,ot);r.all=st,r.alt=$,r.any=it,r.cr=pt,r.createLanguage=function(t){var e={};for(var n in t)({}).hasOwnProperty.call(t,n)&&function(n){e[n]=et((function(){return t[n](e)}))}(n);return e},r.crlf=mt,r.custom=function(t){return r(t(E,S))},r.digit=at,r.digits=ut,r.empty=nt,r.end=bt,r.eof=ot,r.fail=K,r.formatError=W,r.index=rt,r.isParser=y,r.lazy=et,r.letter=lt,r.letters=ct,r.lf=ft,r.lookahead=J,r.makeFailure=S,r.makeSuccess=E,r.newline=gt,r.noneOf=function(t){return tt((function(e){return t.indexOf(e)<0})).desc("none of '"+t+"'")},r.notFollowedBy=Q,r.of=Y,r.oneOf=function(t){for(var e=t.split(""),n=0;n<e.length;n++)e[n]="'"+e[n]+"'";return tt((function(e){return t.indexOf(e)>=0})).desc(e)},r.optWhitespace=ht,r.Parser=r,r.range=function(t,e){return tt((function(n){return t<=n&&n<=e})).desc(t+"-"+e)},r.regex=Z,r.regexp=Z,r.sepBy=R,r.sepBy1=U,r.seq=I,r.seqMap=q,r.seqObj=function(){for(var t,e={},n=0,i=(t=arguments,Array.prototype.slice.call(t)),s=i.length,o=0;o<s;o+=1){var a=i[o];if(!y(a)){if(v(a)&&2===a.length&&"string"==typeof a[0]&&y(a[1])){var u=a[0];if(Object.prototype.hasOwnProperty.call(e,u))throw new Error("seqObj: duplicate key "+u);e[u]=!0,n++;continue}throw new Error("seqObj arguments must be parsers or [string, parser] array pairs.")}}if(0===n)throw new Error("seqObj expects at least one named parser, found zero");return r((function(t,e){for(var n,r={},o=0;o<s;o+=1){var a,u;if(v(i[o])?(a=i[o][0],u=i[o][1]):(a=null,u=i[o]),!(n=P(u._(t,e),n)).status)return n;a&&(r[a]=n.value),e=n.index}return P(E(e,r),n)}))},r.string=X,r.succeed=Y,r.takeWhile=function(t){return M(t),r((function(e,n){for(var r=n;r<e.length&&t(B(e,r));)r++;return E(r,e.slice(n,r))}))},r.test=tt,r.whitespace=dt,r["fantasy-land/empty"]=nt,r["fantasy-land/of"]=Y,r.Binary={bitSeq:h,bitSeqObj:function(t){c();var e={},n=0,r=a((function(t){if(v(t)){var r=t;if(2!==r.length)throw new Error("["+r.join(", ")+"] should be length 2, got length "+r.length);if(j(r[0]),N(r[1]),Object.prototype.hasOwnProperty.call(e,r[0]))throw new Error("duplicate key in bitSeqObj: "+r[0]);return e[r[0]]=!0,n++,r}return N(t),[null,t]}),t);if(n<1)throw new Error("bitSeqObj expects at least one named pair, got ["+t.join(", ")+"]");var i=a((function(t){return t[0]}),r);return h(a((function(t){return t[1]}),r)).map((function(t){return o((function(t,e){return null!==e[0]&&(t[e[0]]=e[1]),t}),{},a((function(e,n){return[e,t[n]]}),i))}))},byte:function(t){if(c(),N(t),t>255)throw new Error("Value specified to byte constructor ("+t+"=0x"+t.toString(16)+") is larger in value than a single byte.");var e=(t>15?"0x":"0x0")+t.toString(16);return r((function(n,r){var i=B(n,r);return i===t?E(r+1,i):S(r,e)}))},buffer:function(t){return d("buffer",t).map((function(t){return Buffer.from(t)}))},encodedString:function(t,e){return d("string",e).map((function(e){return e.toString(t)}))},uintBE:f,uint8BE:f(1),uint16BE:f(2),uint32BE:f(4),uintLE:m,uint8LE:m(1),uint16LE:m(2),uint32LE:m(4),intBE:g,int8BE:g(1),int16BE:g(2),int32BE:g(4),intLE:b,int8LE:b(1),int16LE:b(2),int32LE:b(4),floatBE:d("floatBE",4).map((function(t){return t.readFloatBE(0)})),floatLE:d("floatLE",4).map((function(t){return t.readFloatLE(0)})),doubleBE:d("doubleBE",8).map((function(t){return t.readDoubleBE(0)})),doubleLE:d("doubleLE",8).map((function(t){return t.readDoubleLE(0)}))},t.exports=r}]));let C=z;class D{InlineWhitespace=t=>C.regex(/[^\S\n]+/).desc("inline whitespace");InlineOptWhitespace=t=>C.regex(/[^\S\n]*/).desc("inline optional whitespace");WhitespaceNewline=t=>C.regex(/[^\S\n]*\n\s*/).desc("whitespace with at least a newline");Null=t=>C.seq(C.string("("),t.InlineOptWhitespace,C.string(")")).map((t=>null)).desc("null: ()");None=t=>C.string("None").map((t=>new y({type:"None",path:""}))).desc("none");Boolean=t=>C.alt(C.string("True"),C.string("False")).map((t=>"True"===t)).desc("either True or False");Number=t=>C.regex(/[\-\+]?[0-9]+(?:\.[0-9]+)?/).map(Number).desc("a number");Integer=t=>C.regex(/[\-\+]?[0-9]+/).map((t=>new x({value:t}))).desc("an integer");String=t=>C.regex(/(?:[^"\\]|\\.)*/).wrap(C.string('"'),C.string('"')).desc('string (with possibility to escape the quote using ")');Word=t=>C.regex(/[a-zA-Z]+/).desc("a word");Guid=t=>C.regex(/[0-9a-zA-Z]{32}/).map((t=>new g({value:t}))).desc("32 digit hexadecimal (accepts all the letters for safety) value");PathSymbolEntity=t=>C.regex(/[0-9a-zA-Z_]+/).map((t=>new v({value:t})));ReferencePath=t=>C.seq(C.string("/"),t.PathSymbolEntity.map((t=>t.toString())).sepBy1(C.string(".")).tieWith(".")).tie().atLeast(2).tie().desc('a path (words with possibly underscore, separated by ".", separated by "/")');Reference=t=>C.alt(t.None,t.ReferencePath.map((t=>new y({type:"",path:t}))),C.seqMap(t.Word,C.optWhitespace,C.alt(C.string('"'),C.string("'\"")).chain((e=>t.ReferencePath.skip(C.string(e.split("").reverse().join(""))))),((t,e,n)=>new y({type:t,path:n}))));AttributeName=t=>t.Word.sepBy1(C.string(".")).tieWith(".").desc('words separated by ""');AttributeAnyValue=t=>C.alt(t.Null,t.None,t.Boolean,t.Number,t.Integer,t.String,t.Guid,t.Reference,t.LocalizedText);LocalizedText=t=>C.seqMap(C.string("NSLOCTEXT").skip(C.optWhitespace).skip(C.string("(")),t.String.trim(C.optWhitespace),C.string(","),t.String.trim(C.optWhitespace),C.string(","),t.String.trim(C.optWhitespace),C.string(")"),((t,e,n,r,i,s,o)=>new b({namespace:e,key:r,value:s})));PinReference=t=>C.seqMap(t.PathSymbolEntity,C.whitespace,t.Guid,((t,e,n)=>new w({objectName:t,pinGuid:n})));static getGrammarForType(t,e,n){switch(o.getType(e)){case Boolean:return t.Boolean;case Number:return t.Number;case x:return t.Integer;case String:return t.String;case g:return t.Guid;case y:return t.Reference;case b:return t.LocalizedText;case w:return t.PinReference;case P:return t.FunctionReference;case E:return t.Pin;case Array:return C.seqMap(C.string("("),e.map((e=>D.getGrammarForType(t,o.getType(e)))).reduce(((e,n)=>n&&e!==t.AttributeAnyValue?e.or(n):t.AttributeAnyValue)).trim(C.optWhitespace).sepBy(C.string(",")).skip(C.regex(/,?\s*/)),C.string(")"),((t,e,n)=>e));default:return n}}static CreateAttributeGrammar=(t,e,n,r=C.string("=").trim(C.optWhitespace))=>e.skip(r).chain((e=>{const r=e.split("."),i=n(r);return D.getGrammarForType(t,i,t.AttributeAnyValue).map((t=>e=>o.objectSet(e,r,t,!0)))}));static CreateMultiAttributeGrammar=(t,e,n,r)=>C.seqMap(C.seq(e,C.optWhitespace,C.string("(")),D.CreateAttributeGrammar(t,t.AttributeName,r).trim(C.optWhitespace).sepBy(C.string(",")).skip(C.regex(/,?/).then(C.optWhitespace)),C.string(")"),((t,e,r)=>{let i=new n;return e.forEach((t=>t(i))),i}));FunctionReference=t=>D.CreateMultiAttributeGrammar(t,C.succeed(),P,(t=>o.objectGet(P.attributes,t)));Pin=t=>D.CreateMultiAttributeGrammar(t,C.string("Pin"),E,(t=>o.objectGet(E.attributes,t)));CustomProperties=t=>C.string("CustomProperties").then(C.whitespace).then(t.Pin).map((t=>e=>{let n=o.objectGet(e,["CustomProperties"],[]);n.push(t),o.objectSet(e,["CustomProperties"],n,!0)}));Object=t=>C.seqMap(C.seq(C.string("Begin"),C.whitespace,C.string("Object"),C.whitespace),C.alt(t.CustomProperties,D.CreateAttributeGrammar(t,t.AttributeName,(t=>o.objectGet(L.attributes,t)))).sepBy1(C.whitespace),C.seq(t.WhitespaceNewline,C.string("End"),C.whitespace,C.string("Object")),((t,e,n)=>{let r=new L;return e.forEach((t=>t(r))),r}));MultipleObject=t=>t.Object.sepBy1(C.whitespace).trim(C.optWhitespace)}class G{static grammar=z.createLanguage(new D);constructor(t,e,n,r,i,s){this.entityType=t,this.prefix=e??"",this.separator=n??",",this.trailingSeparator=r??!1,this.attributeValueConjunctionSign=i??"=",this.attributeKeyPrinter=s??(t=>t.join("."))}writeValue(t){if(null===t)return"()";const e=t=>M.getSerializer(o.getType(t)).write(t);switch(t?.constructor){case Function:return this.writeValue(t());case Boolean:return o.FirstCapital(t.toString());case Number:return t.toString();case String:return`"${t}"`}return t instanceof Array?`(${t.map((t=>e(t)+","))})`:t instanceof m?e(t):void 0}subWrite(t,e){let n="",r=t.concat("");const i=r.length-1;for(const t in e){r[i]=t;const s=e[t];e[t]?.constructor===Object?n+=(n.length?this.separator:"")+this.subWrite(r,s):this.showProperty(r,s)&&(n+=(n.length?this.separator:"")+this.prefix+this.attributeKeyPrinter(r)+this.attributeValueConjunctionSign+this.writeValue(s))}return this.trailingSeparator&&n.length&&0===r.length&&(n+=this.separator),n}showProperty(t,e){const n=this.entityType.attributes,r=o.objectGet(n,t);return!(r instanceof s)||(!o.equals(r.value,e)||r.showDefault)}}class F extends G{constructor(){super(L," ","\n",!1)}showProperty(t,e){switch(t.toString()){case"Class":case"Name":case"CustomProperties":return!1}return super.showProperty(t,e)}read(t){const e=G.grammar.Object.parse(t);return e.status?e.value:(console.error("Error when trying to parse the object."),e)}readMultiple(t){const e=G.grammar.MultipleObject.parse(t);return e.status?e.value:(console.error("Error when trying to parse the object."),e)}write(t){return`Begin Object Class=${this.writeValue(t.Class)} Name=${this.writeValue(t.Name)}\n${this.subWrite([],t)+t.CustomProperties.map((t=>this.separator+this.prefix+"CustomProperties "+M.getSerializer(E).write(t))).join("")}\nEnd Object`}}class H extends i{constructor(t,e,n={}){n.wantsFocusCallback=!0,super(t,e,n),this.serializer=new F;let r=this;this.pasteHandle=t=>r.pasted(t.clipboardData.getData("Text"))}blueprintFocused(){document.body.addEventListener("paste",this.pasteHandle)}blueprintUnfocused(){document.body.removeEventListener("paste",this.pasteHandle)}pasted(t){let e=Number.MAX_SAFE_INTEGER,n=Number.MAX_SAFE_INTEGER,r=this.serializer.readMultiple(t).map((t=>{let r=new A(t);return e=Math.min(e,r.location[1]),n=Math.min(n,r.location[0]),r}));r.length>0&&this.blueprint.unselectAll();let i=this.blueprint.entity.mousePosition;this.blueprint.addNode(...r),r.forEach((t=>{const r=[i[0]-n,i[1]-e];t.addLocation(r),t.setSelected(!0)}))}}class V extends u{constructor(t,e,n){super(t,e,n),this.selectorElement=this.blueprint.selectorElement}startDrag(){this.selectorElement.startSelecting(this.clickedPosition)}dragTo(t,e){this.selectorElement.doSelecting(t)}endDrag(){this.started?this.selectorElement.finishSelecting():this.blueprint.unselectAll()}}class W extends i{constructor(t,e,n={}){n.wantsFocusCallback=!0,super(t,e,n);let r=this;this.clickHandler=t=>r.clickedSomewhere(t),this.blueprint.focuse&&document.addEventListener("click",this.clickHandler)}clickedSomewhere(t){t.target.closest("u-blueprint")||this.blueprint.setFocused(!1)}blueprintFocused(){document.addEventListener("click",this.clickHandler)}blueprintUnfocused(){document.removeEventListener("click",this.clickHandler)}}class _ extends a{constructor(t,e,n){n.wantsFocusCallback=!0,super(t,e,n),this.looseTarget=n?.looseTarget??!0;let r=this;this.mouseWheelHandler=t=>{t.preventDefault();const e=r.getLocation(t);r.wheel(Math.sign(t.deltaY),e)},this.mouseParentWheelHandler=t=>t.preventDefault(),this.blueprint.focused&&this.movementSpace.addEventListener("wheel",this.mouseWheelHandler,!1)}blueprintFocused(){this.movementSpace.addEventListener("wheel",this.mouseWheelHandler,!1),this.movementSpace.parentElement?.addEventListener("wheel",this.mouseParentWheelHandler)}blueprintUnfocused(){this.movementSpace.removeEventListener("wheel",this.mouseWheelHandler,!1),this.movementSpace.parentElement?.removeEventListener("wheel",this.mouseParentWheelHandler)}wheel(t,e){}}class I extends _{wheel(t,e){let n=this.blueprint.getZoom();n-=t,this.blueprint.setZoom(n,e)}}class q extends i{constructor(t,e,n={}){n.wantsFocusCallback=!0,super(t,e,n),this.serializer=new F;let r=this;this.copyHandle=t=>r.copied()}blueprintFocused(){document.body.addEventListener("copy",this.copyHandle)}blueprintUnfocused(){document.body.removeEventListener("copy",this.copyHandle)}copied(){const t=this.blueprint.getNodes(!0).map((t=>this.serializer.write(t.entity))).join("\n");navigator.clipboard.writeText(t)}}class $ extends c{constructor(){super(new t,new r),this.gridElement=null,this.viewportElement=null,this.overlayElement=null,this.selectorElement=null,this.nodesContainerElement=null,this.dragObject=null,this.selectObject=null,this.zoom=0,this.headerElement=null,this.focused=!1,this.nodeBoundariesSupplier=t=>{let e=t.getBoundingClientRect(),n=this.nodesContainerElement.getBoundingClientRect();const r=1/this.getScale();return{primaryInf:(e.left-n.left)*r,primarySup:(e.right-n.right)*r,secondaryInf:(e.top-n.top)*r,secondarySup:(e.bottom-n.bottom)*r}},this.nodeSelectToggleFunction=(t,e)=>{t.setSelected(e)}}connectedCallback(){super.connectedCallback(),this.classList.add("ueb",`ueb-zoom-${this.zoom}`),this.headerElement=this.querySelector(".ueb-viewport-header"),console.assert(this.headerElement,"Header element not provided by the template."),this.overlayElement=this.querySelector(".ueb-viewport-overlay"),console.assert(this.overlayElement,"Overlay element not provided by the template."),this.viewportElement=this.querySelector(".ueb-viewport-body"),console.assert(this.viewportElement,"Viewport element not provided by the template."),this.gridElement=this.viewportElement.querySelector(".ueb-grid"),console.assert(this.gridElement,"Grid element not provided by the template."),this.selectorElement=new p,this.nodesContainerElement=this.querySelector("[data-nodes]"),console.assert(this.nodesContainerElement,"Nodes container element not provided by the template."),this.nodesContainerElement.append(this.selectorElement),this.querySelector("[data-nodes]").append(...this.entity.nodes),this.copyObject=new q(this.getGridDOMElement(),this),this.pasteObject=new H(this.getGridDOMElement(),this),this.dragObject=new l(this.getGridDOMElement(),this,{clickButton:2,moveEverywhere:!0,exitAnyButton:!1}),this.zoomObject=new I(this.getGridDOMElement(),this,{looseTarget:!0}),this.selectObject=new V(this.getGridDOMElement(),this,{clickButton:0,moveEverywhere:!0,exitAnyButton:!0}),this.unfocusObject=new W(this.getGridDOMElement(),this),this.mouseTrackingObject=new f(this.getGridDOMElement(),this)}getGridDOMElement(){return this.gridElement}disconnectedCallback(){super.disconnectedCallback(),setSelected(!1),this.dragObject.unlistenDOMElement(),this.selectObject.unlistenDOMElement(),this.pasteObject.unlistenDOMElement()}getScroll(){return[this.viewportElement.scrollLeft,this.viewportElement.scrollTop]}setScroll(t,e=!1){this.scroll=t,e?this.viewportElement.scroll({left:t[0],top:t[1],behavior:"smooth"}):this.viewportElement.scroll(t[0],t[1])}scrollDelta(t,e=!1){const n=this.getScrollMax();let r=this.getScroll(),i=[r[0]+t[0],r[1]+t[1]],s=[0,0];for(let e=0;e<2;++e)t[e]<0&&i[e]<.25*this.entity.expandGridSize?(s[e]=i[e],s[e]>0&&(s[e]=-this.entity.expandGridSize)):t[e]>0&&i[e]>n[e]-.25*this.entity.expandGridSize&&(s[e]=i[e]-n[e],s[e]<0&&(s[e]=this.entity.expandGridSize));0==s[0]&&0==s[1]||(this.seamlessExpand(this.progressiveSnapToGrid(s[0]),this.progressiveSnapToGrid(s[1])),r=this.getScroll(),i=[r[0]+t[0],r[1]+t[1]]),this.setScroll(i,e)}scrollCenter(){const t=this.getScroll(),e=[this.entity.translateValue[0]-t[0],this.entity.translateValue[1]-t[1]],n=this.getViewportSize().map((t=>t/2)),r=[e[0]-n[0],e[1]-n[1]];this.scrollDelta(r,!0)}getExpandGridSize(){return this.entity.expandGridSize}getViewportSize(){return[this.viewportElement.clientWidth,this.viewportElement.clientHeight]}getScrollMax(){return[this.viewportElement.scrollWidth-this.viewportElement.clientWidth,this.viewportElement.scrollHeight-this.viewportElement.clientHeight]}_expand(t,e){t=Math.round(Math.abs(t)),e=Math.round(Math.abs(e)),this.entity.additional=[this.entity.additional[0]+t,this.entity.additional[1]+e],this.gridElement&&(this.gridElement.style.setProperty("--ueb-additional-x",this.entity.additional[0]),this.gridElement.style.setProperty("--ueb-additional-y",this.entity.additional[1]))}_translate(t,e){t=Math.round(t),e=Math.round(e),this.entity.translateValue=[this.entity.translateValue[0]+t,this.entity.translateValue[1]+e],this.gridElement&&(this.gridElement.style.setProperty("--ueb-translate-x",this.entity.translateValue[0]),this.gridElement.style.setProperty("--ueb-translate-y",this.entity.translateValue[1]))}seamlessExpand(t,e){let n=this.getScale(),r=t/n,i=e/n;this._expand(r,i),this._translate(r<0?-r:0,i<0?-i:0),t<0&&(this.viewportElement.scrollLeft-=t),e<0&&(this.viewportElement.scrollTop-=e)}progressiveSnapToGrid(t){return this.entity.expandGridSize*Math.round(t/this.entity.expandGridSize+.5*Math.sign(t))}getZoom(){return this.zoom}setZoom(t,e){if((t=o.clamp(t,-12,0))==this.zoom)return;let n=this.getScale();if(this.classList.remove(`ueb-zoom-${this.zoom}`),this.classList.add(`ueb-zoom-${t}`),this.zoom=t,e){let t=this.getScale()/n,r=[t*e[0],t*e[1]];this.scrollDelta([(r[0]-e[0])*n,(r[1]-e[1])*n])}}getScale(){return parseFloat(getComputedStyle(this.gridElement).getPropertyValue("--ueb-scale"))}compensateTranslation(t){return t[0]-=this.entity.translateValue[0],t[1]-=this.entity.translateValue[1],t}getNodes(t=!1){return t?this.entity.nodes.filter((t=>t.selected)):this.entity.nodes}unselectAll(){this.entity.nodes.forEach((t=>this.nodeSelectToggleFunction(t,!1)))}addNode(...t){[...t].reduce(((t,e)=>(t.push(e),t)),this.entity.nodes),this.nodesContainerElement&&this.nodesContainerElement.append(...t)}setFocused(t=!0){if(this.focused==t)return;let e=new CustomEvent(t?"blueprintfocus":"blueprintunfocus");this.focused=t,this.dataset.focused=this.focused,this.focused||this.unselectAll(),this.dispatchEvent(e)}}customElements.define("u-blueprint",$);class R extends c{constructor(t,e){super(),this.source=t,this.destination=e}render(){return'\n <svg viewBox="0 0 100 100">\n <line x1="0" y1="80" x2="100" y2="20" stroke="black" />\n </svg>\n '}}customElements.define("u-link",R);class U extends G{constructor(t,e,n,r,i,s,o){super(e,n,r,i,s,o),this.wrap=t??(t=>`(${t})`)}read(t){const e=D.getGrammarForType(G.grammar,this.entityType).parse(t);return e.status?e.value:(console.error("Error when trying to parse the entity "+this.entityType.prototype.constructor.name),e)}write(t){return this.wrap(this.subWrite([],t))}}class X extends U{constructor(t,e){super(void 0,e),this.objectWriter=t}write(t){return this.objectWriter(t)}}class Z extends U{constructor(t){super(void 0,t)}write(t){return t.toString()}}M.registerSerializer(L,new F),M.registerSerializer(E,new U((t=>`Pin (${t})`),E,"",",",!0)),M.registerSerializer(P,new U((t=>`(${t})`),P,"",",",!1)),M.registerSerializer(b,new U((t=>`NSLOCTEXT(${t})`),b,"",",",!1,"",(t=>""))),M.registerSerializer(w,new U((t=>t),w,""," ",!1,"",(t=>""))),M.registerSerializer(y,new X((t=>(t.type??"")+(t.path?t.type?`'"${t.path}"'`:t.path:"")))),M.registerSerializer(v,new Z(v)),M.registerSerializer(g,new Z(g)),M.registerSerializer(x,new Z(x));export{$ as Blueprint,R as GraphLink,A as GraphNode};
|