{"version":3,"sources":["https://lively-kernel.org/lively4/lively4-petrinet/src/components/demo/lively-petrinet.js"],"names":["Morph","ContextMenu","pt","LivelyPetrinet","initialize","registerButtons","updateConnectorPosition","initializeConnectors","connector","fromComponent","getComponentFrom","toComponent","error","addConnector","remove","detachedCallback","places","from","querySelectorAll","transitions","probTransitions","codeTransitions","connectors","id","allComponents","component","livelyExample","addPlace","addTransition","updateAllConnectors","updateConnector","newConnector","appendChild","connectPetrinetComponents","position","transition","initializeElement","place","addCodeTransition","codeTransition","element","setPosition"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;AAEOA,W;;AACAC,iB;;AACCC,Q,wBAAAA,E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIO,YAAMC,cAAN,SAA6BH,KAA7B,CAAmC;;AAIhD;;AAEA,cAAMI,UAAN,GAAmB;AACjB,0CAAmB,gBAAnB;AADiB;AAEjB,eAAKC,eAAL;AACA,4CAAqB,KAArB;AACA,6CAAsB,oFAAY;AAAM,kHAAKC,uBAAL;AAAN,WAAZ,EAAkD,IAAlD,CAAtB;AAED;;AAGD;AACA,cAAMC,oBAAN,GAA6B;AAC3B,eAAK,MAAMC,SAAX,eAAwB,IAAxB,iBAAyC;AAAA;AAAA;;AACvC,kBAAMC,oGAAgB,KAAKC,gBAAL,oGAAsBF,SAAtB,sBAAhB,CAAN;AACA,kBAAMG,kGAAc,KAAKD,gBAAL,oGAAsBF,SAAtB,oBAAd,CAAN;AACA,gBAAI,iGAACC,aAAD,KAAkB,6FAACE,WAAD,CAAtB,EAAoC;AAAA;;AAClC,wFAAOC,KAAP,CAAa,yCAAb;AACD;AACD,kGAAM,KAAKC,YAAL,iGAAkBJ,aAAlB,+FAAiCE,WAAjC,EAAN;AANuC;AAOvC,+GAAUG,MAAV;AAED;AACF;;AAEDC,2BAAmB;AACjB,6GAAc,IAAd;AACD;;AAID;;;AAIA,YAAIC,MAAJ,GAAa;AACX,yFAAO,wEA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eAAKF,WAAL,oGAAiBO,cAAjB;AACA,mHAAOA,cAAP;AACD;;AAGD,cAAMH,iBAAN,CAAwBI,OAAxB,EAAiCN,QAAjC,EAA2C;AAAA;AAAA;;AACvC,oFAAOO,WAAP,sFAAmBD,OAAnB,0FAA4BN,QAA5B;AACH;;AAnI+C;;yBAA7B/B,c","file":"lively-petrinet.js","sourcesContent":["\"enable aexpr\";\n\nimport Morph from 'src/components/widgets/lively-morph.js';\nimport ContextMenu from 'src/client/contextmenu.js';\nimport {pt} from 'src/client/graphics.js';\n\n\n\nexport default class LivelyPetrinet extends Morph {\n  \n  \n  \n  // Initialization\n  \n  async initialize() {\n    this.windowTitle = \"LivelyPetrinet\";\n    this.registerButtons();\n    this.mouseIsOnNode = false;\n    this.positionUpdate = setInterval(() => this.updateConnectorPosition(), 1000);\n    \n  }\n  \n  \n  // The connectors don't behave probperly when reloaded, because they are not connected to the components with the previous data-lively-id anymore. So we remove them and create new connectors instead (updating didnt properly work)\n  async initializeConnectors() {\n    for (const connector of this.connectors) {\n      const fromComponent = this.getComponentFrom(connector.fromComponentId);\n      const toComponent = this.getComponentFrom(connector.toComponentId);\n      if (!fromComponent || !toComponent) {\n        lively.error(\"Connector is not connected to component\");\n      }\n      await this.addConnector(fromComponent, toComponent);\n      connector.remove();\n      \n    }\n  }\n  \n  detachedCallback() {\n    clearInterval(this.positionUpdate);\n  }\n  \n  \n  \n  // Access Methods\n  \n  \n  \n  get places() {\n    return Array.from(this.querySelectorAll(\"lively-petrinet-place\"));\n  }\n  \n  get transitions() {\n    const probTransitions = Array.from(this.querySelectorAll(\"lively-petrinet-prob-transition\"));\n    const codeTransitions = Array.from(this.querySelectorAll(\"lively-petrinet-code-transition\"));\n    return [...probTransitions, ...codeTransitions]\n  }\n  \n  get connectors() {\n    return Array.from(this.querySelectorAll(\"lively-petrinet-edge\"))\n  }\n  \n  \n  getComponentFrom(id) {\n    const allComponents = [...this.places, ...this.transitions];\n    for (const component of allComponents) {\n      if (component.componentId == id) {\n        return component;\n      }\n    }\n  }\n  \n  \n  // Lively Methods\n  \n  \n  async livelyExample() {\n    await this.addPlace(pt(100, 100));\n    this.places[0].addToken();\n    await this.addPlace(pt(500, 300));\n    await this.addTransition(pt(300, 200));\n    this.addConnector(this.places[0], this.transitions[0]);\n    this.addConnector(this.transitions[0],this.places[1]);\n  }\n  \n  \n  \n  // Connector Creation\n  \n\n  updateAllConnectors() {\n    for (const connector of this.connectors) {\n      connector.updateConnector();\n    }\n  }\n  \n  \n  // Add And Delete Elements\n  \n  \n  \n  async addConnector(fromComponent, toComponent) {\n    const newConnector = await(<lively-petrinet-edge></lively-petrinet-edge>);\n    this.appendChild(newConnector);\n    await newConnector.connectPetrinetComponents(fromComponent, toComponent);\n    // The connector has some weird behaviour, in that it is not 100% connected to the elements in the beginning. We fix this by manually updating its position.\n    return newConnector;\n  }\n  \n  updateConnectorPosition() {\n    for (const connector of this.connectors) {\n      connector.updateConnector();\n    }\n  }\n  \n  async addTransition(position) {\n    var transition = await (<lively-petrinet-prob-transition></lively-petrinet-prob-transition>);\n    this.initializeElement(transition, position);\n    this.appendChild(transition);\n    return transition;\n  }\n  \n  \n  async addPlace(position) {\n      var place = await (<lively-petrinet-place></lively-petrinet-place>);\n      this.initializeElement(place, position);\n      this.appendChild(place);\n      return place;\n  }\n  \n  async addCodeTransition(position) {\n    var codeTransition = await (<lively-petrinet-code-transition></lively-petrinet-code-transition>);\n    this.initializeElement(codeTransition, position);\n    this.appendChild(codeTransition);\n    return codeTransition;\n  }\n  \n  \n  async initializeElement(element, position) {\n      lively.setPosition(element, position);\n  }\n\n}"]}