{"version":3,"sources":["https://lively-kernel.org/lively4/lively4-livelyenergy/src/client/reactive/components/rewritten/simple-button-anim.js"],"names":["Morph","shake","soundBuffers","Map","set","context","AudioContext","bufferFor","file","response","arrayBuffer","decodeAudioData","play","audioBuffer","source","createBufferSource","connect","start","SimpleButtonAnim","button","get","initialize","registerButtons","args","dragStart","dragEnd","onTarget","event","livelyPreMigrate","livelyMigrate","other","livelyInspect","contentNode","inspector","livelyPrepareSave","livelyExample"],"mappings":"AAAA;;;;;;;;;;;;;;;;;AAEOA,W;;AACEC,W,UAAAA,K;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAET;AACA,YAAMC,eAAe,mEAAIC,GAAJ,GAArB;;;;;;;;;;;;;;;;;AACA,iHAAaC,GAAb,CAAiB,SAAjB,EAA4B,kGAAU,qCAAV,CAA5B;;AACA,iHAAaA,GAAb,CAAiB,WAAjB,EAA8B,kGAAU,uCAAV,CAA9B;;AAEA,YAAMC,UAAU,4EAAIC,YAAJ,GAAhB;;;;;;;;;;;;;;;;;AAEA,eAASC,SAAT,CAAmBC,IAAnB,EAAyB;AAAA;;AACvB,mDAAO,sJAAMA,IAAN,EAAP,WACQC;AAAA;AAAY,mMAASC,WAAT;AAAZ,SADR,aAEQA;AAAA;AAAe,kMAAQC,eAAR,8FAAwBD,WAAxB;AAAf,SAFR;AAGD;;AAED,eAASE,IAAT,CAAcC,WAAd,EAA2B;AAAA;;AACzB,cAAMC,kGAAS,4FAAQC,kBAAR,EAAT,CAAN;AACA,sNAAgBF,WAAhB;AAFyB;AAGzB,mGAAOG,OAAP,+FAAeX,OAAf;AAHyB;AAIzB,mGAAOY,KAAP;AACD;;AAEc,YAAMC,gBAAN,SAA+BlB,KAA/B,CAAqC;AAClD,YAAImB,MAAJ,GAAa;AAAE,uFAAO,KAAKC,GAAL,CAAS,SAAT,CAAP;AAA6B;;AAE5C,cAAMC,UAAN,GAAmB;AACjB,0CAAmB,kBAAnB;AADiB;AAEjB,eAAKC,eAAL;;AAEA,6EAA6B,WAA7B,EAA0C,CAAC,GAAGC,IAAJ;AAAA;AAAa,oGAAKC,SAAL,CAAe,kFAAGD,IAAH,CAAf;AAAb,WAA1C;AACA,6EAA6B,SAA7B,EAAwC,CAAC,GAAGA,IAAJ;AAAA;AAAa,kGAAKE,OAAL,CAAa,kFAAGF,IAAH,CAAb;AAAb,WAAxC;AACD;;AAED;AACA,cAAMG,QAAN,GAAiB;AACf,gGAAM,IAAN;AACD;AACD,cAAMF,SAAN,CAAgBG,KAAhB,EAAuB;AACrB,8FAAK,qFAAM,2GAAaP,GAAb,CAAiB,SAAjB,CAAN,CAAL;AACD;;AAED,cAAMK,OAAN,CAAcE,KAAd,EAAqB;AACnB,8FAAK,qFAAM,2GAAaP,GAAb,CAAiB,WAAjB,CAAN,CAAL;AACD;AACD;;AAEAQ,2BAAmB;AACjB;AACD;;AAEDC,sBAAcC,KAAd,EAAqB;AAAA;;AACnB;AACA;AACA,iJAA8BA,KAA9B;AACD;;AAEDC,sBAAcC,WAAd,EAA2BC,SAA3B,EAAsC;AACpC;AACD;;AAEDC,4BAAoB,CAEnB;;AAGD,cAAMC,aAAN,GAAsB,CACrB;;AA5CiD;;yBAA/BjB,gB","file":"simple-button-anim.js","sourcesContent":["\"enable aexpr\";\n\nimport Morph from 'src/components/widgets/lively-morph.js';\nimport { shake } from 'utils';\n\n// Map<name:String, buffer:AudioBuffer>\nconst soundBuffers = new Map();\nsoundBuffers.set('cube-up', bufferFor('https://lively4/gamedev/cube-up.mp3'));\nsoundBuffers.set('cube-down', bufferFor('https://lively4/gamedev/cube-down.mp3'));\n\nconst context = new AudioContext();\n\nfunction bufferFor(file) {\n  return fetch(file)\n    .then(response => response.arrayBuffer())\n    .then(arrayBuffer => context.decodeAudioData(arrayBuffer));\n}\n\nfunction play(audioBuffer) {\n  const source = context.createBufferSource();\n  source.buffer = audioBuffer;\n  source.connect(context.destination);\n  source.start();\n}\n\nexport default class SimpleButtonAnim extends Morph {\n  get button() { return this.get('#target'); }\n  \n  async initialize() {\n    this.windowTitle = \"SimpleButtonAnim\";\n    this.registerButtons()\n    \n    this.button.addEventListener('dragstart', (...args) => this.dragStart(...args))\n    this.button.addEventListener('dragend', (...args) => this.dragEnd(...args))\n  }\n  \n  // this method is automatically registered as handler through ``registerButtons``\n  async onTarget() {\n    shake(this)\n  }\n  async dragStart(event) {\n    play(await soundBuffers.get('cube-up'))\n  }\n\n  async dragEnd(event) {\n    play(await soundBuffers.get('cube-down'))\n  }\n  /* Lively-specific API */\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.someJavaScriptProperty = other.someJavaScriptProperty\n  }\n  \n  livelyInspect(contentNode, inspector) {\n    // do nothing\n  }\n  \n  livelyPrepareSave() {\n    \n  }\n  \n  \n  async livelyExample() {\n  }\n  \n  \n}"]}