{"version":3,"sources":["https://lively-kernel.org/lively4/gs/components/gs-visual-editor.js"],"names":["Morph","d3","GsVisualEditor","initialize","windowTitle","registerButtons","lively","html","registerKeys","addEventListener","evt","onDblClick","get","value","getAttribute","setupZoom","zoomOuter","zoomInner","lastZoomTransform","json","getJSONAttribute","undefined","zoomIdentity","translate","x","y","scale","k","transform","pick","split","setJSONAttribute","select","zoom","scaleExtent","on","event","applyZoomTransform","style","call","onResetZoom","notify","animate","backgroundColor","duration","onKeyDown","charCode","onPlusButton","parseFloat","onMinusButton","livelyPrepareSave","setAttribute","livelyPreMigrate","livelyMigrate","other","livelyInspect","contentNode","inspector","livelyExample","someJavaScriptProperty","appendChild"],"mappings":";;;;;;;;;;;;AAAOA,W;;AAEAC,Q;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEQ,YAAMC,cAAN,SAA6BF,KAA7B,CAAmC;;AAEhD,cAAMG,UAAN,GAAmB;AACjB,eAAKC,WAAL,GAAmB,gBAAnB;AACA;AACA,eAAKC,eAAL;;AAEAC,iBAAOC,IAAP,CAAYC,YAAZ,CAAyB,IAAzB,EALiB,CAKe;;AAEhCF,iBAAOG,gBAAP,CAAwB,UAAxB,EAAoC,IAApC,EAA0C,UAA1C,EAAsDC,OAAO,KAAKC,UAAL,CAAgBD;AAC7E;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAR6D,WAA7D;;AAYA,eAAKE,GAAL,CAAS,YAAT,EAAuBC,KAAvB,GAA+B,KAAKC,YAAL,CAAkB,aAAlB,KAAoC,CAAnE;;AAEA,eAAKC,SAAL;AACD;;AAED;AACA,YAAIC,SAAJ,GAAgB;AACd,iBAAO,KAAKJ,GAAL,CAAS,aAAT,CAAP;AACD;AACD,YAAIK,SAAJ,GAAgB;AACd,iBAAO,KAAKL,GAAL,CAAS,aAAT,CAAP;AACD;AACD,YAAIM,iBAAJ,GAAwB;AACtB,gBAAMC,OAAO,KAAKC,gBAAL,CAAsB,mBAAtB,CAAb;AACA,cAAI,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ACD;;AA7H+C;;yBAA7B1D,c","file":"gs-visual-editor.js","sourcesContent":["import Morph from 'src/components/widgets/lively-morph.js';\n\nimport d3 from \"src/external/d3.v5.js\";\n\nexport default class GsVisualEditor extends Morph {\n\n  async initialize() {\n    this.windowTitle = \"GsVisualEditor\";\n    debugger;\n    this.registerButtons();    \n\n    lively.html.registerKeys(this); // automatically installs handler for some methods\n\n    lively.addEventListener(\"template\", this, \"dblclick\", evt => this.onDblClick(evt\n    // #Note 1\n    // ``lively.addEventListener`` automatically registers the listener\n    // so that the the handler can be deactivated using:\n    // ``lively.removeEventListener(\"template\", this)``\n    // #Note 1\n    // registering a closure instead of the function allows the class to make \n    // use of a dispatch at runtime. That means the ``onDblClick`` method can be\n    // replaced during development\n\n    ));\n\n    this.get(\"#textField\").value = this.getAttribute(\"data-mydata\") || 0;\n\n    this.setupZoom();\n  }\n\n  /*MD ## Zoom MD*/\n  get zoomOuter() {\n    return this.get('#zoom-outer');\n  }\n  get zoomInner() {\n    return this.get('#zoom-inner');\n  }\n  get lastZoomTransform() {\n    const json = this.getJSONAttribute('lastZoomTransform');\n    if (!json) {\n      return undefined;\n    }\n    return d3.zoomIdentity.translate(json.x, json.y).scale(json.k);\n  }\n  set lastZoomTransform(transform) {\n    const json = transform.pick('xyk'.split(''));\n    this.setJSONAttribute('lastZoomTransform', json);\n    return transform;\n  }\n\n  setupZoom() {\n    // https://github.com/d3/d3-zoom\n    const zoomOuter = d3.select(this.zoomOuter);\n\n    const zoom = d3.zoom().scaleExtent([1 / 30, 30]).on(\"zoom\", () => {\n      const transform = d3.event.transform;\n\n      this.applyZoomTransform(transform);\n      this.lastZoomTransform = transform;\n    });\n\n    zoomOuter.style(\"pointer-events\", \"all\").call(zoom).on('dblclick.zoom', null);\n\n    const lastZoomTransform = this.lastZoomTransform;\n    if (lastZoomTransform) {\n      zoom.transform(zoomOuter, lastZoomTransform);\n    }\n  }\n\n  applyZoomTransform(transform) {\n    const zoomInner = d3.select(this.zoomInner);\n    zoomInner.style(\"transform\", \"translate(\" + transform.x + \"px,\" + transform.y + \"px) scale(\" + transform.k + \")\");\n    zoomInner.style(\"transform-origin\", \"0 0\");\n  }\n\n  'onZoom-reset'() {\n    \n  }\n  /*MD ## --- MD*/\n  onResetZoom() {\n    lively.notify('fahklhaw');\n  }\n  onDblClick() {\n    this.animate([{ backgroundColor: \"lightgray\" }, { backgroundColor: \"red\" }, { backgroundColor: \"lightgray\" }], {\n      duration: 1000\n    });\n  }\n\n  // this method is autmatically registered through the ``registerKeys`` method\n  onKeyDown(evt) {\n    lively.notify(\"Key Down!\" + evt.charCode);\n  }\n\n  // this method is automatically registered as handler through ``registerButtons``\n  onPlusButton() {\n    this.get(\"#textField\").value = parseFloat(this.get(\"#textField\").value) + 1;\n  }\n\n  onMinusButton() {\n    this.get(\"#textField\").value = parseFloat(this.get(\"#textField\").value) - 1;\n  }\n\n  /* Lively-specific API */\n\n  // store something that would be lost\n  livelyPrepareSave() {\n    this.setAttribute(\"data-mydata\", this.get(\"#textField\").value);\n  }\n\n  livelyPreMigrate() {\n    // is called on the old object before the migration\n  }\n\n  livelyMigrate(other) {\n    // whenever a component is replaced with a newer version during development\n    // this method is called on the new object during migration, but before initialization\n    this.lastZoomTransform = other.lastZoomTransform;\n  }\n\n  livelyInspect(contentNode, inspector) {\n    // do nothing\n  }\n\n  async livelyExample() {\n    // this customizes a default instance to a pretty example\n    // this is used by the \n    this.style.backgroundColor = \"lightgray\";\n    this.someJavaScriptProperty = 42;\n    this.appendChild(<div>This is my content</div>);\n  }\n\n}"]}