{"version":3,"sources":["https://lively-kernel.org/lively4/lively4-stable//src/client/ContextJS/src/contextjs.js"],"names":["cop","currentLayers","proceed","Layer","basicCreate","layer","withoutLayers","withLayers","layers","func","previouslyActiveLayers","LayerStack","push","filter","l","includes","forEach","_emitActivateCallbacks","beforePop","pop","afterPop","_emitDeactivateCallbacks","beforePush","args","layerName","context","length","GlobalNamedLayers","existing","isLayer","Error"],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;AAsBA;;;;;;;;AAEYA,S;AACHC,mB,aAAAA,a;;iBACAC,O,aAAAA,O;iBAASC,K,aAAAA,K;;;;;;;;;;;;;AAoDTC,sD;;;;;;;;;;;;;2BAXOC,sC;;;;;;;;;;;;;;mCAnBAC,8C;;;;;;;;;;;;;;gCAnBAC,2C;;;;;;;;;;;;;;AALJP,8C;;;;;;;;;;;;;AACHC,wD;;;;;;;;;AAGT;AACO,eAASM,UAAT,CAAoBC,MAApB,EAA4BC,IAA5B,EAAkC;AACvC,cAAMC,yBAAyBT,eAA/B;AACAD,YAAIW,UAAJ,CAAeC,IAAf,CAAoB,EAACL,YAAYC,MAAb,EAApB;AACAA,eACGK,MADH,CACUC,KAAK,CAACJ,uBAAuBK,QAAvB,CAAgCD,CAAhC,CADhB,EAEGE,OAFH,CAEWF,KAAKA,EAAEG,sBAAF,EAFhB;AAGA;AACA,YAAI;AACF,iBAAOR,MAAP;AACD,SAFD,SAEU;AACR,gBAAMS,YAAYjB,eAAlB;AACAD,cAAIW,UAAJ,CAAeQ,GAAf;AACA,gBAAMC,WAAWnB,eAAjB;AACAO,iBACGK,MADH,CACUC,KAAKI,UAAUH,QAAV,CAAmBD,CAAnB,KAAyB,CAACM,SAASL,QAAT,CAAkBD,CAAlB,CADzC,EAEGE,OAFH,CAEWF,KAAKA,EAAEO,wBAAF,EAFhB;AAGD;AACF;;;;AAEM,eAASf,aAAT,CAAuBE,MAAvB,EAA+BC,IAA/B,EAAqC;AAC1C,cAAMa,aAAarB,eAAnB;AACAD,Y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AND,MAMO;AACL,iBAAOH,QAAQD,SAAR,IAAqB,IAAIxB,IAAIG,KAAR,CAAcqB,SAAd,EAAyBC,OAAzB,CAA5B;AACD;AACF","file":"contextjs.js","sourcesContent":["/*\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"]}