{"version":3,"sources":["https://lively-kernel.org/lively4/swd21-particles/src/client/ContextJS/src/contextjs.js"],"names":["withLayers","layers","func","previouslyActiveLayers","currentLayers","cop","LayerStack","push","filter","l","includes","forEach","_emitActivateCallbacks","beforePop","pop","afterPop","_emitDeactivateCallbacks","withoutLayers","beforePush","layer","args","layerName","context","length","basicCreate","GlobalNamedLayers","existing","isLayer","Error","Layer","proceed"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;AAsBA;;;;;;;;AAMA;AACO,WAASA,UAAT,CAAoBC,MAApB,EAA4BC,IAA5B,EAAkC;AACvC,UAAMC,yBAAyBC,eAA/B;AACAC,QAAIC,UAAJ,CAAeC,IAAf,CAAoB,EAACP,YAAYC,MAAb,EAApB;AACAA,WACGO,MADH,CACUC,KAAK,CAACN,uBAAuBO,QAAvB,CAAgCD,CAAhC,CADhB,EAEGE,OAFH,CAEWF,KAAKA,EAAEG,sBAAF,EAFhB;AAGA;AACA,QAAI;AACF,aAAOV,MAAP;AACD,KAFD,SAEU;AACR,YAAMW,YAAYT,eAAlB;AACAC,UAAIC,UAAJ,CAAeQ,GAAf;AACA,YAAMC,WAAWX,eAAjB;AACAH,aACGO,MADH,CACUC,KAAKI,UAAUH,QAAV,CAAmBD,CAAnB,KAAyB,CAACM,SAASL,QAAT,CAAkBD,CAAlB,CADzC,EAEGE,OAFH,CAEWF,KAAKA,EAAEO,wBAAF,EAFhB;AAGD;AACF;;wBAjBehB,U;;AAmBT,WAASiB,aAAT,CAAuBhB,MAAvB,EAA+BC,IAA/B,EAAqC;AAC1C,UAAMgB,aAAad,eAAnB;AACAC,QAAIC,UAAJ,CAAeC,IAAf,CAAoB,EAACU,eAAehB,MAAhB,EAApB;AACAA,WACGO,MADH,CACUC,KAAKS,WAAWR,QAAX,CAAoBD,CAApB,CADf,EAEGE,OAFH,CAEWF,KAAKA,EAAEO,wBAAF,EAFhB;AAGA,QAAI;AACF,aAAOd,MAAP;AACD,KAFD,SAEU;AACR,YAAMW,Y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\n * Copyright (c) 2008-2016 Hasso Plattner Institute\n *\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the Software.\n\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n * THE SOFTWARE.\n */\n'use strict'; \n\nimport * as cop from \"./Layers.js\";\nimport { currentLayers } from \"./Layers.js\";\nexport { proceed, Layer } from \"./Layers.js\";\n\n// Layer Activation\nexport function withLayers(layers, func) {\n  const previouslyActiveLayers = currentLayers();\n  cop.LayerStack.push({withLayers: layers});\n  layers\n    .filter(l => !previouslyActiveLayers.includes(l))\n    .forEach(l => l._emitActivateCallbacks());\n  // console.log(\"callee: \" + withLayers.callee);\n  try {\n    return func();\n  } finally {\n    const beforePop = currentLayers();\n    cop.LayerStack.pop();\n    const afterPop = currentLayers();\n    layers\n      .filter(l => beforePop.includes(l) && !afterPop.includes(l))\n      .forEach(l => l._emitDeactivateCallbacks());\n  }\n}\n\nexport function withoutLayers(layers, func) {\n  const beforePush = currentLayers();\n  cop.LayerStack.push({withoutLayers: layers});\n  layers\n    .filter(l => beforePush.includes(l))\n    .forEach(l => l._emitDeactivateCallbacks());\n  try {\n    return func();\n  } finally {\n    const beforePop = currentLayers();\n    cop.LayerStack.pop();\n    const afterPop = currentLayers();\n    layers\n      .filter(l => !beforePop.includes(l) && afterPop.includes(l))\n      .forEach(l => l._emitActivateCallbacks());\n  }\n}\n\n// Layer creation by name\nexport function layer(...args) {\n  let layerName, context;\n  if (args.length === 2) {\n    [context, layerName] = args;\n  } else if (args.length === 1) {\n    [layerName] = args;\n  }\n  return basicCreate(layerName, context);\n};\n\n// Private helpers\nfunction basicCreate(layerName, context) {\n  if (typeof context === 'undefined')\n    context = cop.GlobalNamedLayers;\n  if (typeof context[layerName] !== 'undefined') {\n    let existing = context[layerName];\n    if (!existing.isLayer /* undefined or falsy */ || !existing.isLayer()) {\n      throw new Error('Will not overwrite existing property ' + layerName);\n    }\n    return existing;\n  } else {\n    return context[layerName] = new cop.Layer(layerName, context);\n  }\n};\n"]}