"enable aexpr";

System.register(['active-expression-rewriting', 'reactive-jsx', 'lang', 'src/external/focalStorage.js', './../contextmenu.js', 'utils', 'active-group'], function (_export, _context) {
  "use strict";

  var _setLocal, _getAndCallMember, _traceMember, _getLocal, _getGlobal, _getMember, _setMember, _childText, _childExpression, _children, _attributeStringLiteral, _attributes, _element, focalStorage, ContextMenu, through, uuid, fileName, hintForLabel, getTempKeyFor, asDragImageFor, trackInstance;

  return {
    setters: [function (_activeExpressionRewriting) {
      _setLocal = _activeExpressionRewriting.setLocal;
      _getAndCallMember = _activeExpressionRewriting.getAndCallMember;
      _traceMember = _activeExpressionRewriting.traceMember;
      _getLocal = _activeExpressionRewriting.getLocal;
      _getGlobal = _activeExpressionRewriting.getGlobal;
      _getMember = _activeExpressionRewriting.getMember;
      _setMember = _activeExpressionRewriting.setMember;
    }, function (_reactiveJsx) {
      _childText = _reactiveJsx.childText;
      _childExpression = _reactiveJsx.childExpression;
      _children = _reactiveJsx.children;
      _attributeStringLiteral = _reactiveJsx.attributeStringLiteral;
      _attributes = _reactiveJsx.attributes;
      _element = _reactiveJsx.element;
    }, function (_lang) {}, function (_srcExternalFocalStorageJs) {
      focalStorage = _srcExternalFocalStorageJs.default;
    }, function (_contextmenuJs) {
      ContextMenu = _contextmenuJs.default;
    }, function (_utils) {
      through = _utils.through;
      uuid = _utils.uuid;
      fileName = _utils.fileName;
      hintForLabel = _utils.hintForLabel;
      getTempKeyFor = _utils.getTempKeyFor;
      asDragImageFor = _utils.asDragImageFor;
    }, function (_activeGroup) {
      trackInstance = _activeGroup.trackInstance;
    }],
    execute: function () {
      _recorder_._src_client_triples_triples_js = _recorder_._src_client_triples_triples_js || {};
      let _scope = {};

      _setMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'isExternalURL', (self.__expressionAnalysisMode__ ? _getLocal(_scope, 'isExternalURL', isExternalURL) : void 0, isExternalURL));

      _setMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'isInternalURL', (self.__expressionAnalysisMode__ ? _getLocal(_scope, 'isInternalURL', isInternalURL) : void 0, isInternalURL));

      _setMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'parseMarkdown', (self.__expressionAnalysisMode__ ? _getLocal(_scope, 'parseMarkdown', parseMarkdown) : void 0, parseMarkdown));

      _setMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'getJSYaml', (self.__expressionAnalysisMode__ ? _getLocal(_scope, 'getJSYaml', getJSYaml) : void 0, getJSYaml));

      _setMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'focalStorage', (self.__expressionAnalysisMode__ ? _getLocal(_scope, 'focalStorage', focalStorage) : void 0, focalStorage));

      _setMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'ContextMenu', (self.__expressionAnalysisMode__ ? _getLocal(_scope, 'ContextMenu', ContextMenu) : void 0, ContextMenu));

      _setMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'asDragImageFor', (self.__expressionAnalysisMode__ ? _getLocal(_scope, 'asDragImageFor', asDragImageFor) : void 0, asDragImageFor));

      _setMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'getTempKeyFor', (self.__expressionAnalysisMode__ ? _getLocal(_scope, 'getTempKeyFor', getTempKeyFor) : void 0, getTempKeyFor));

      _setMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'hintForLabel', (self.__expressionAnalysisMode__ ? _getLocal(_scope, 'hintForLabel', hintForLabel) : void 0, hintForLabel));

      _setMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'fileName', (self.__expressionAnalysisMode__ ? _getLocal(_scope, 'fileName', fileName) : void 0, fileName));

      _setMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'uuid', (self.__expressionAnalysisMode__ ? _getLocal(_scope, 'uuid', uuid) : void 0, uuid));

      _setMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'through', (self.__expressionAnalysisMode__ ? _getLocal(_scope, 'through', through) : void 0, through));

      _setMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'trackInstance', (self.__expressionAnalysisMode__ ? _getLocal(_scope, 'trackInstance', trackInstance) : void 0, trackInstance));

      async function getJSYaml() {
        await (self.__expressionAnalysisMode__ ? _traceMember(lively, 'loadJavaScriptThroughDOM') : void 0, (self.__expressionAnalysisMode__ ? _getGlobal('lively') : void 0, lively).loadJavaScriptThroughDOM("esprima", "https://lively-kernel.org/lively4/foo/src/external/esprima.js"));
        await (self.__expressionAnalysisMode__ ? _traceMember(lively, 'loadJavaScriptThroughDOM') : void 0, (self.__expressionAnalysisMode__ ? _getGlobal('lively') : void 0, lively).loadJavaScriptThroughDOM("js-yaml", "https://lively-kernel.org/lively4/foo/src/external/js-yaml.js"));
        return self.__expressionAnalysisMode__ ? _getGlobal('jsyaml') : void 0, jsyaml;
      }

      // #TODO: unused
      async function parseMarkdown(markdown, filename) {
        let _scope2 = {};

        try {
          let _scope3 = {};

          const frontmatterSeparator = "---\r\n";
          if (self.__expressionAnalysisMode__ ? _traceMember(markdown, 'startsWith') : void 0, (self.__expressionAnalysisMode__ ? _getLocal(_scope2, 'markdown', markdown) : void 0, markdown).startsWith((self.__expressionAnalysisMode__ ? _getLocal(_scope3, 'frontmatterSeparator', frontmatterSeparator) : void 0, frontmatterSeparator))) {
            let _scope4 = {};

            const parts = (self.__expressionAnalysisMode__ ? _traceMember(markdown, 'split') : void 0, (self.__expressionAnalysisMode__ ? _getLocal(_scope2, 'markdown', markdown) : void 0, markdown).split((self.__expressionAnalysisMode__ ? _getLocal(_scope3, 'frontmatterSeparator', frontmatterSeparator) : void 0, frontmatterSeparator)));
            if (_getMember((self.__expressionAnalysisMode__ ? _getLocal(_scope4, 'parts', parts) : void 0, parts), 'length') >= 3) {
              let _scope5 = {};
              if (self.__expressionAnalysisMode__) _traceMember(parts, 'shift');

              (self.__expressionAnalysisMode__ ? _getLocal(_scope4, 'parts', parts) : void 0, parts).shift(); // empty
              const frontmatterString = (self.__expressionAnalysisMode__ ? _traceMember(parts, 'shift') : void 0, (self.__expressionAnalysisMode__ ? _getLocal(_scope4, 'parts', parts) : void 0, parts).shift());
              return {
                textContent: (self.__expressionAnalysisMode__ ? _traceMember(parts, 'join') : void 0, (self.__expressionAnalysisMode__ ? _getLocal(_scope4, 'parts', parts) : void 0, parts).join((self.__expressionAnalysisMode__ ? _getLocal(_scope3, 'frontmatterSeparator', frontmatterSeparator) : void 0, frontmatterSeparator))),
                metadata: _getAndCallMember((await _getAndCallMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'getJSYaml', [])), 'load', [(self.__expressionAnalysisMode__ ? _getLocal(_scope5, 'frontmatterString', frontmatterString) : void 0, frontmatterString)])
              };
            }
          }
        } catch (e) {
          if (self.__expressionAnalysisMode__) _traceMember(lively, 'notify');

          (self.__expressionAnalysisMode__ ? _getGlobal('lively') : void 0, lively).notify("failed frontmatter parsing", "", (self.__expressionAnalysisMode__ ? _getGlobal('undefined') : void 0, undefined), (self.__expressionAnalysisMode__ ? _getGlobal('undefined') : void 0, undefined), "red");
        }
        return {
          textContent: markdown,
          metadata: {}
        };
      }

      class Knot {
        constructor(fileName, content) {
          let _scope6 = {};

          _setMember(this, 'fileName', (self.__expressionAnalysisMode__ ? _getLocal(_scope6, 'fileName', fileName) : void 0, fileName));
          _setMember(this, 'content', (self.__expressionAnalysisMode__ ? _getLocal(_scope6, 'content', content) : void 0, content));

          if (new.target === _getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'Knot')) {
            _getAndCallMember(_getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'trackInstance'), 'call', [_getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'Knot'), this]);
          }
        }
        get url() {
          return _getMember(this, 'fileName');
        }
        getMetadata() {
          return _getMember(this, 'metadata');
        }
        label() {
          if (_getAndCallMember(_getMember(this, 'fileName'), 'endsWith', ['.md'])) {
            let _scope7 = {};

            const firstLine = _getMember(_getAndCallMember(_getMember(this, 'content'), 'split', ['\n']), 0);
            return self.__expressionAnalysisMode__ ? _traceMember(firstLine, 'replace') : void 0, (self.__expressionAnalysisMode__ ? _getLocal(_scope7, 'firstLine', firstLine) : void 0, firstLine).replace(/^#\s/, '');
          }
          return _getMember(this, 'fileName');
        }
        isTriple() {
          return false;
        }
        async save(newContent) {
          let _scope8 = {};

          _setMember(this, 'content', (self.__expressionAnalysisMode__ ? _getLocal(_scope8, 'newContent', newContent) : void 0, newContent));
          await _getAndCallMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('lively') : void 0, lively), 'files'), 'saveFile', [_getMember(this, 'url'), (self.__expressionAnalysisMode__ ? _getLocal(_scope8, 'newContent', newContent) : void 0, newContent)]);
        }
        async openViewInWindow() {
          let _scope9 = {};

          const knotView = await (self.__expressionAnalysisMode__ ? _traceMember(lively, 'openComponentInWindow') : void 0, (self.__expressionAnalysisMode__ ? _getGlobal('lively') : void 0, lively).openComponentInWindow("knot-view"));
          if (self.__expressionAnalysisMode__) _traceMember(knotView, 'loadKnotForURL');
          (self.__expressionAnalysisMode__ ? _getLocal(_scope9, 'knotView', knotView) : void 0, knotView).loadKnotForURL(_getMember(this, 'url'));
        }
        collectContextMenuItems() {
          return [["Knot View", evt => {
            _getAndCallMember(_getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'ContextMenu'), 'hide', []);
            if (self.__expressionAnalysisMode__) _traceMember(this, 'openViewInWindow');
            this.openViewInWindow();
          }, "", '<i class="fa fa-window-maximize" aria-hidden="true"></i>'], ["Danger Zone", [["Delete", async evt => {
            let _scope10 = {};

            _getAndCallMember(_getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'ContextMenu'), 'hide', []);
            const graph = await _getAndCallMember(_getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'Graph'), 'getInstance', []);

            const label = (self.__expressionAnalysisMode__ ? _traceMember(this, 'label') : void 0, this.label());
            if (await (self.__expressionAnalysisMode__ ? _traceMember(graph, 'deleteKnot') : void 0, (self.__expressionAnalysisMode__ ? _getLocal(_scope10, 'graph', graph) : void 0, graph).deleteKnot(this))) {
              if (self.__expressionAnalysisMode__) _traceMember(lively, 'notify');

              // #TODO: use reactivity to update views and search results
              (self.__expressionAnalysisMode__ ? _getGlobal('lively') : void 0, lively).notify(`${(self.__expressionAnalysisMode__ ? _getLocal(_scope10, 'label', label) : void 0, label)} deleted!`, null, 4, null, "red");
            } else {
              if (self.__expressionAnalysisMode__) _traceMember(lively, 'notify');

              (self.__expressionAnalysisMode__ ? _getGlobal('lively') : void 0, lively).notify('did not delete knot ' + (self.__expressionAnalysisMode__ ? _getLocal(_scope10, 'label', label) : void 0, label), _getMember(this, 'url'));
            }
          }, "Delete for good", '<i class="fa fa-trash" aria-hidden="true"></i>']]]];
        }

        toListItem() {
          let _scope11 = {};

          const listItem = _element('li', _attributes(_attributeStringLiteral('tabindex', '1'), _attributeStringLiteral('draggable', 'true')), _children(_childExpression((self.__expressionAnalysisMode__ ? _traceMember(this, 'label') : void 0, this.label()))), {
            file: 'https://lively-kernel.org/lively4/lively4-eslint/src/client/triples/triples.js',
            end: {
              column: 74,
              line: 90
            },
            start: {
              column: 21,
              line: 90
            }
          });
          _setMember((self.__expressionAnalysisMode__ ? _getLocal(_scope11, 'listItem', listItem) : void 0, listItem), 'knot', this);

          if (self.__expressionAnalysisMode__) _traceMember(listItem, 'addEventListener');
          (self.__expressionAnalysisMode__ ? _getLocal(_scope11, 'listItem', listItem) : void 0, listItem).addEventListener('keydown', event => {
            let _scope12 = {};

            if (_getMember((self.__expressionAnalysisMode__ ? _getLocal(_scope12, 'event', event) : void 0, event), 'keyCode') == 13) {
              if (self.__expressionAnalysisMode__) _traceMember(this, 'openViewInWindow');
              // ENTER
              this.openViewInWindow();
              if (self.__expressionAnalysisMode__) _traceMember(event, 'stopPropagation');
              (self.__expressionAnalysisMode__ ? _getLocal(_scope12, 'event', event) : void 0, event).stopPropagation();
              if (self.__expressionAnalysisMode__) _traceMember(event, 'preventDefault');
              (self.__expressionAnalysisMode__ ? _getLocal(_scope12, 'event', event) : void 0, event).preventDefault();
            }
          });
          if (self.__expressionAnalysisMode__) _traceMember(listItem, 'addEventListener');
          (self.__expressionAnalysisMode__ ? _getLocal(_scope11, 'listItem', listItem) : void 0, listItem).addEventListener("dblclick", event => {
            let _scope13 = {};
            if (self.__expressionAnalysisMode__) _traceMember(this, 'openViewInWindow');

            this.openViewInWindow();
            if (self.__expressionAnalysisMode__) _traceMember(event, 'stopPropagation');
            (self.__expressionAnalysisMode__ ? _getLocal(_scope13, 'event', event) : void 0, event).stopPropagation();
            if (self.__expressionAnalysisMode__) _traceMember(event, 'preventDefault');
            (self.__expressionAnalysisMode__ ? _getLocal(_scope13, 'event', event) : void 0, event).preventDefault();
          });
          if (self.__expressionAnalysisMode__) _traceMember(listItem, 'addEventListener');
          (self.__expressionAnalysisMode__ ? _getLocal(_scope11, 'listItem', listItem) : void 0, listItem).addEventListener("contextmenu", event => {
            let _scope14 = {};

            _getAndCallMember(_getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'ContextMenu'), 'openIn', [_getMember((self.__expressionAnalysisMode__ ? _getGlobal('document') : void 0, document), 'body'), (self.__expressionAnalysisMode__ ? _getLocal(_scope14, 'event', event) : void 0, event), this, (self.__expressionAnalysisMode__ ? _getGlobal('undefined') : void 0, undefined), (self.__expressionAnalysisMode__ ? _traceMember(this, 'collectContextMenuItems') : void 0, this.collectContextMenuItems())]);
            if (self.__expressionAnalysisMode__) _traceMember(event, 'stopPropagation');
            (self.__expressionAnalysisMode__ ? _getLocal(_scope14, 'event', event) : void 0, event).stopPropagation();
            if (self.__expressionAnalysisMode__) _traceMember(event, 'preventDefault');
            (self.__expressionAnalysisMode__ ? _getLocal(_scope14, 'event', event) : void 0, event).preventDefault();
          });

          return self.__expressionAnalysisMode__ ? _getLocal(_scope11, 'listItem', listItem) : void 0, listItem;
        }

        asDataForDrag(evt) {
          var _context2;

          let _scope15 = {};

          const dt = _getMember((self.__expressionAnalysisMode__ ? _getLocal(_scope15, 'evt', evt) : void 0, evt), 'dataTransfer');
          //listItem.style.color = "blue";
          if (self.__expressionAnalysisMode__) _traceMember(dt, 'setData');
          (self.__expressionAnalysisMode__ ? _getLocal(_scope15, 'dt', dt) : void 0, dt).setData("knot/url", _getMember(this, 'url'));
          if (self.__expressionAnalysisMode__) _traceMember(dt, 'setData');
          (self.__expressionAnalysisMode__ ? _getLocal(_scope15, 'dt', dt) : void 0, dt).setData("text/uri-list", _getMember(this, 'url'));
          if (self.__expressionAnalysisMode__) _traceMember(dt, 'setData');
          (self.__expressionAnalysisMode__ ? _getLocal(_scope15, 'dt', dt) : void 0, dt).setData("text/plain", _getMember(this, 'url'));
          if (self.__expressionAnalysisMode__) _traceMember(dt, 'setData');
          (self.__expressionAnalysisMode__ ? _getLocal(_scope15, 'dt', dt) : void 0, dt).setData("javascript/object", _getAndCallMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'getTempKeyFor', [this]));
          const mimeType = 'text/plain';
          const filename = (_context2 = _getMember(this, 'url'), _getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js').fileName).call(_context2);
          const url = _getMember(this, 'url');
          if (self.__expressionAnalysisMode__) _traceMember(dt, 'setData');
          (self.__expressionAnalysisMode__ ? _getLocal(_scope15, 'dt', dt) : void 0, dt).setData("DownloadURL", `${(self.__expressionAnalysisMode__ ? _getLocal(_scope15, 'mimeType', mimeType) : void 0, mimeType)}:${(self.__expressionAnalysisMode__ ? _getLocal(_scope15, 'filename', filename) : void 0, filename)}:${(self.__expressionAnalysisMode__ ? _getLocal(_scope15, 'url', url) : void 0, url)}`);

          // #TODO: remove duplication
          const dragInfo = _element('div', _attributes(_attributeStringLiteral('style', 'width: 150px;')), _children(_childText('\n      '), _childExpression(_getAndCallMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'hintForLabel', [(self.__expressionAnalysisMode__ ? _traceMember(this, 'label') : void 0, this.label())])), _childText('\n    ')), {
            file: 'https://lively-kernel.org/lively4/lively4-eslint/src/client/triples/triples.js',
            end: {
              column: 10,
              line: 129
            },
            start: {
              column: 21,
              line: 127
            }
          });
          (_context2 = (self.__expressionAnalysisMode__ ? _getLocal(_scope15, 'dragInfo', dragInfo) : void 0, dragInfo), _getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js').asDragImageFor).call(_context2, (self.__expressionAnalysisMode__ ? _getLocal(_scope15, 'evt', evt) : void 0, evt), 50, 60);
        }
      }

      _export('Knot', Knot);

      _setMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'Knot', (self.__expressionAnalysisMode__ ? _getLocal(_scope, 'Knot', Knot) : void 0, Knot));

      class Triple extends _getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'Knot') {
        constructor(fileName, content) {
          let _scope16 = {};

          try {
            if (self.__expressionAnalysisMode__) _traceMember(JSON, 'parse');

            (self.__expressionAnalysisMode__ ? _getGlobal('JSON') : void 0, JSON).parse((self.__expressionAnalysisMode__ ? _getLocal(_scope16, 'content', content) : void 0, content));
          } catch (e) {
            debugger;
            if (self.__expressionAnalysisMode__) _traceMember(console, 'log');
            (self.__expressionAnalysisMode__ ? _getGlobal('console') : void 0, console).log((self.__expressionAnalysisMode__ ? _getLocal(_scope16, 'fileName', fileName) : void 0, fileName));
          }

          super((self.__expressionAnalysisMode__ ? _getLocal(_scope16, 'fileName', fileName) : void 0, fileName), (self.__expressionAnalysisMode__ ? _traceMember(JSON, 'parse') : void 0, (self.__expressionAnalysisMode__ ? _getGlobal('JSON') : void 0, JSON).parse((self.__expressionAnalysisMode__ ? _getLocal(_scope16, 'content', content) : void 0, content))));

          // track this Triple for ROQs after full initialization
        }

        label() {
          if (_getMember(this, 'predicate')) {
            return 't: ' + _getAndCallMember(_getMember(this, 'predicate'), 'label', []);
          }
          return _getAndCallMember(_getMember(this, 'filename'), 'replace', ['.triple.json', '']);
        }
        isTriple() {
          return true;
        }
      }

      _export('Triple', Triple);

      _setMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'Triple', (self.__expressionAnalysisMode__ ? _getLocal(_scope, 'Triple', Triple) : void 0, Triple));

      const DEFAULT_FOLDER_URL = 'https://lively4/notes/';

      _export('DEFAULT_FOLDER_URL', DEFAULT_FOLDER_URL);

      _setMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'DEFAULT_FOLDER_URL', (self.__expressionAnalysisMode__ ? _getLocal(_scope, 'DEFAULT_FOLDER_URL', DEFAULT_FOLDER_URL) : void 0, DEFAULT_FOLDER_URL));

      const TAG_URL = _getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'DEFAULT_FOLDER_URL') + 'tag.md';

      _export('TAG_URL', TAG_URL);

      _setMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'TAG_URL', (self.__expressionAnalysisMode__ ? _getLocal(_scope, 'TAG_URL', TAG_URL) : void 0, TAG_URL));

      const IS_A_URL = _getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'DEFAULT_FOLDER_URL') + 'is_a.md';

      _export('IS_A_URL', IS_A_URL);

      _setMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'IS_A_URL', (self.__expressionAnalysisMode__ ? _getLocal(_scope, 'IS_A_URL', IS_A_URL) : void 0, IS_A_URL));

      const SAME_AS_URL = _getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'DEFAULT_FOLDER_URL') + 'same_as.md';

      _export('SAME_AS_URL', SAME_AS_URL);

      _setMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'SAME_AS_URL', (self.__expressionAnalysisMode__ ? _getLocal(_scope, 'SAME_AS_URL', SAME_AS_URL) : void 0, SAME_AS_URL));

      const CONTAINS_URL = _getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'DEFAULT_FOLDER_URL') + 'contains.md';

      _export('CONTAINS_URL', CONTAINS_URL);

      _setMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'CONTAINS_URL', (self.__expressionAnalysisMode__ ? _getLocal(_scope, 'CONTAINS_URL', CONTAINS_URL) : void 0, CONTAINS_URL));

      const ROOT_KNOWLEDGE_BASES_KEY = 'triple-notes-root-knowledge-bases';

      _setMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'ROOT_KNOWLEDGE_BASES_KEY', (self.__expressionAnalysisMode__ ? _getLocal(_scope, 'ROOT_KNOWLEDGE_BASES_KEY', ROOT_KNOWLEDGE_BASES_KEY) : void 0, ROOT_KNOWLEDGE_BASES_KEY));

      const PREFERRED_KNOWLEDGE_BASE_KEY = 'triple-notes-preferred-knowledge-base';

      _setMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'PREFERRED_KNOWLEDGE_BASE_KEY', (self.__expressionAnalysisMode__ ? _getLocal(_scope, 'PREFERRED_KNOWLEDGE_BASE_KEY', PREFERRED_KNOWLEDGE_BASE_KEY) : void 0, PREFERRED_KNOWLEDGE_BASE_KEY));

      function isInternalURL(url) {
        let _scope17 = {};

        const origin = _getMember((self.__expressionAnalysisMode__ ? _getLocal(_scope17, 'url', url) : void 0, url), 'origin');
        return (self.__expressionAnalysisMode__ ? _getLocal(_scope17, 'origin', origin) : void 0, origin) === 'https://lively4' || (self.__expressionAnalysisMode__ ? _getLocal(_scope17, 'origin', origin) : void 0, origin) === 'https://localhost:8800';
      }
      function isExternalURL(url) {
        let _scope18 = {};
        return !_getAndCallMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'isInternalURL', [(self.__expressionAnalysisMode__ ? _getLocal(_scope18, 'url', url) : void 0, url)]);
      }

      class Graph {
        constructor() {
          _setMember(this, 'knots', []);
          _setMember(this, 'loadedDirectoryPromises', new (self.__expressionAnalysisMode__ ? _getGlobal('Map') : void 0, Map)());
          // url string -> Promise for Knot
          _setMember(this, 'requestedKnots', new (self.__expressionAnalysisMode__ ? _getGlobal('Map') : void 0, Map)());
        }
        async prepare() {
          let _scope19 = {};

          const rootKnowledgeBases = await (self.__expressionAnalysisMode__ ? _traceMember(this, 'getRootKnowledgeBases') : void 0, this.getRootKnowledgeBases());
          return self.__expressionAnalysisMode__ ? _traceMember(Promise, 'all') : void 0, (self.__expressionAnalysisMode__ ? _getGlobal('Promise') : void 0, Promise).all((self.__expressionAnalysisMode__ ? _traceMember(rootKnowledgeBases, 'map') : void 0, (self.__expressionAnalysisMode__ ? _getLocal(_scope19, 'rootKnowledgeBases', rootKnowledgeBases) : void 0, rootKnowledgeBases).map(this.loadFromDir.bind(this))));
        }

        async getRootKnowledgeBases() {
          return (await _getAndCallMember(_getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'focalStorage'), 'getItem', [_getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'ROOT_KNOWLEDGE_BASES_KEY')])) || [_getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'DEFAULT_FOLDER_URL')];
        }

        async addRootKnowledgeBase(urlString) {
          let _scope20 = {},
              _scope22 = {};

          try {
            let _scope21 = {};

            new (self.__expressionAnalysisMode__ ? _getGlobal('URL') : void 0, URL)((self.__expressionAnalysisMode__ ? _getLocal(_scope20, 'urlString', urlString) : void 0, urlString));
            const stats = (self.__expressionAnalysisMode__ ? _traceMember(JSON, 'parse') : void 0, (self.__expressionAnalysisMode__ ? _getGlobal('JSON') : void 0, JSON).parse((await _getAndCallMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('lively') : void 0, lively), 'files'), 'statFile', [(self.__expressionAnalysisMode__ ? _getLocal(_scope20, 'urlString', urlString) : void 0, urlString)]))));
            if (!(self.__expressionAnalysisMode__ ? _getLocal(_scope21, 'stats', stats) : void 0, stats) || _getMember((self.__expressionAnalysisMode__ ? _getLocal(_scope21, 'stats', stats) : void 0, stats), 'type') !== "directory") {
              throw new (self.__expressionAnalysisMode__ ? _getGlobal('Error') : void 0, Error)((self.__expressionAnalysisMode__ ? _getLocal(_scope21, 'stats', stats) : void 0, stats));
            }
          } catch (e) {
            if (self.__expressionAnalysisMode__) _traceMember(lively, 'notify');

            (self.__expressionAnalysisMode__ ? _getGlobal('lively') : void 0, lively).notify(`Knowledge base ${(self.__expressionAnalysisMode__ ? _getLocal(_scope20, 'urlString', urlString) : void 0, urlString)} not valid.`, _getMember((self.__expressionAnalysisMode__ ? _getLocal(_scope22, 'e', e) : void 0, e), 'message'), (self.__expressionAnalysisMode__ ? _getGlobal('undefined') : void 0, undefined), (self.__expressionAnalysisMode__ ? _getGlobal('undefined') : void 0, undefined), "red");
            return;
          }

          const rootKnowledgeBases = (await (self.__expressionAnalysisMode__ ? _traceMember(this, 'getRootKnowledgeBases') : void 0, this.getRootKnowledgeBases())) || [];
          if (!(self.__expressionAnalysisMode__ ? _traceMember(rootKnowledgeBases, 'includes') : void 0, (self.__expressionAnalysisMode__ ? _getLocal(_scope20, 'rootKnowledgeBases', rootKnowledgeBases) : void 0, rootKnowledgeBases).includes((self.__expressionAnalysisMode__ ? _getLocal(_scope20, 'urlString', urlString) : void 0, urlString)))) {
            if (self.__expressionAnalysisMode__) _traceMember(rootKnowledgeBases, 'push');

            (self.__expressionAnalysisMode__ ? _getLocal(_scope20, 'rootKnowledgeBases', rootKnowledgeBases) : void 0, rootKnowledgeBases).push((self.__expressionAnalysisMode__ ? _getLocal(_scope20, 'urlString', urlString) : void 0, urlString));
            await _getAndCallMember(_getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'focalStorage'), 'setItem', [_getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'ROOT_KNOWLEDGE_BASES_KEY'), (self.__expressionAnalysisMode__ ? _getLocal(_scope20, 'rootKnowledgeBases', rootKnowledgeBases) : void 0, rootKnowledgeBases)]);
            return await (self.__expressionAnalysisMode__ ? _traceMember(this, 'loadFromDir') : void 0, this.loadFromDir((self.__expressionAnalysisMode__ ? _getLocal(_scope20, 'urlString', urlString) : void 0, urlString)));
          }
        }

        async removeRootKnowledgeBase(urlString) {
          let _scope23 = {};

          let rootKnowledgeBases = (await (self.__expressionAnalysisMode__ ? _traceMember(this, 'getRootKnowledgeBases') : void 0, this.getRootKnowledgeBases())) || [];
          if (self.__expressionAnalysisMode__ ? _traceMember(rootKnowledgeBases, 'includes') : void 0, (self.__expressionAnalysisMode__ ? _getLocal(_scope23, 'rootKnowledgeBases', rootKnowledgeBases) : void 0, rootKnowledgeBases).includes((self.__expressionAnalysisMode__ ? _getLocal(_scope23, 'urlString', urlString) : void 0, urlString))) {
            // remove via filter
            rootKnowledgeBases = (self.__expressionAnalysisMode__ ? _traceMember(rootKnowledgeBases, 'filter') : void 0, (self.__expressionAnalysisMode__ ? _getLocal(_scope23, 'rootKnowledgeBases', rootKnowledgeBases) : void 0, rootKnowledgeBases).filter(rootBase => {
              let _scope24 = {};
              return (self.__expressionAnalysisMode__ ? _getLocal(_scope24, 'rootBase', rootBase) : void 0, rootBase) !== (self.__expressionAnalysisMode__ ? _getLocal(_scope23, 'urlString', urlString) : void 0, urlString);
            })), true ? _setLocal(_scope23, 'rootKnowledgeBases', rootKnowledgeBases) : void 0, rootKnowledgeBases;
            await _getAndCallMember(_getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'focalStorage'), 'setItem', [_getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'ROOT_KNOWLEDGE_BASES_KEY'), (self.__expressionAnalysisMode__ ? _getLocal(_scope23, 'rootKnowledgeBases', rootKnowledgeBases) : void 0, rootKnowledgeBases)]);
            return true;
          } else {
            return false;
          }
        }

        getKnots() {
          return _getMember(this, 'knots');
        }
        hasKnotWithURL(url) {
          let _scope26 = {};

          return !!_getAndCallMember((self.__expressionAnalysisMode__ ? _traceMember(this, 'getKnots') : void 0, this.getKnots()), 'find', [knot => {
            let _scope25 = {};
            return _getMember((self.__expressionAnalysisMode__ ? _getLocal(_scope25, 'knot', knot) : void 0, knot), 'url') === (self.__expressionAnalysisMode__ ? _getLocal(_scope26, 'url', url) : void 0, url);
          }]);
        }
        get triples() {
          return _getAndCallMember(_getMember(this, 'knots'), 'filter', [knot => {
            let _scope27 = {};
            return self.__expressionAnalysisMode__ ? _traceMember(knot, 'isTriple') : void 0, (self.__expressionAnalysisMode__ ? _getLocal(_scope27, 'knot', knot) : void 0, knot).isTriple();
          }]);
        }
        async deleteKnot(knot) {
          let _scope28 = {};

          // check for triples on top of the knot
          const referingTriples = _getAndCallMember(_getAndCallMember((self.__expressionAnalysisMode__ ? _traceMember(this, 'query') : void 0, this.query((self.__expressionAnalysisMode__ ? _getLocal(_scope28, 'knot', knot) : void 0, knot), _getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), '_'), _getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), '_'))), 'concat', [(self.__expressionAnalysisMode__ ? _traceMember(this, 'query') : void 0, this.query(_getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), '_'), (self.__expressionAnalysisMode__ ? _getLocal(_scope28, 'knot', knot) : void 0, knot), _getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), '_')))]), 'concat', [(self.__expressionAnalysisMode__ ? _traceMember(this, 'query') : void 0, this.query(_getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), '_'), _getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), '_'), (self.__expressionAnalysisMode__ ? _getLocal(_scope28, 'knot', knot) : void 0, knot)))]);
          if (_getMember((self.__expressionAnalysisMode__ ? _getLocal(_scope28, 'referingTriples', referingTriples) : void 0, referingTriples), 'length') > 0) {
            if (self.__expressionAnalysisMode__) _traceMember(lively, 'notify');

            (self.__expressionAnalysisMode__ ? _getGlobal('lively') : void 0, lively).notify('Deletion aborted!', `${_getMember((self.__expressionAnalysisMode__ ? _getLocal(_scope28, 'referingTriples', referingTriples) : void 0, referingTriples), 'length')} triples refer to this knot.`);
            return false;
          }

          let url = _getMember((self.__expressionAnalysisMode__ ? _getLocal(_scope28, 'knot', knot) : void 0, knot), 'url');
          if (!(self.__expressionAnalysisMode__ ? _traceMember(window, 'confirm') : void 0, (self.__expressionAnalysisMode__ ? _getGlobal('window') : void 0, window).confirm("delete knot " + (self.__expressionAnalysisMode__ ? _getLocal(_scope28, 'url', url) : void 0, url)))) {
            return false;
          }

          let index = _getAndCallMember(_getMember(this, 'knots'), 'indexOf', [(self.__expressionAnalysisMode__ ? _getLocal(_scope28, 'knot', knot) : void 0, knot)]);
          if ((self.__expressionAnalysisMode__ ? _getLocal(_scope28, 'index', index) : void 0, index) > -1) {
            _getAndCallMember(_getMember(this, 'knots'), 'splice', [(self.__expressionAnalysisMode__ ? _getLocal(_scope28, 'index', index) : void 0, index), 1]);
            if (self.__expressionAnalysisMode__) _traceMember(lively, 'notify');
            (self.__expressionAnalysisMode__ ? _getGlobal('lively') : void 0, lively).notify(`Removed knot ${(self.__expressionAnalysisMode__ ? _getLocal(_scope28, 'url', url) : void 0, url)} in local graph instance.`);
          } else {
            if (self.__expressionAnalysisMode__) _traceMember(lively, 'notify');

            (self.__expressionAnalysisMode__ ? _getGlobal('lively') : void 0, lively).notify(`Did not find knot ${(self.__expressionAnalysisMode__ ? _getLocal(_scope28, 'url', url) : void 0, url)} in local graph instance.`);
          }

          let urlURL = new (self.__expressionAnalysisMode__ ? _getGlobal('URL') : void 0, URL)((self.__expressionAnalysisMode__ ? _getLocal(_scope28, 'url', url) : void 0, url));
          if (!_getAndCallMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'isInternalURL', [(self.__expressionAnalysisMode__ ? _getLocal(_scope28, 'urlURL', urlURL) : void 0, urlURL)])) {
            var result = await _getAndCallMember((self.__expressionAnalysisMode__ ? _getGlobal('fetch') : void 0, fetch)((self.__expressionAnalysisMode__ ? _getLocal(_scope28, 'url', url) : void 0, url), { method: 'DELETE' }), 'then', [r => {
              let _scope29 = {};
              return self.__expressionAnalysisMode__ ? _traceMember(r, 'text') : void 0, (self.__expressionAnalysisMode__ ? _getLocal(_scope29, 'r', r) : void 0, r).text();
            }]);
            if (self.__expressionAnalysisMode__) _traceMember(lively, 'notify');
            (self.__expressionAnalysisMode__ ? _getGlobal('lively') : void 0, lively).notify(`Deleted knot ${(self.__expressionAnalysisMode__ ? _getLocal(_scope28, 'url', url) : void 0, url)} in remote storage`, (self.__expressionAnalysisMode__ ? _getLocal(_scope28, 'result', result) : void 0, result));
          }

          if (self.__expressionAnalysisMode__) _traceMember(lively, 'notify');
          (self.__expressionAnalysisMode__ ? _getGlobal('lively') : void 0, lively).notify('Knot removed from graph.');

          return true;
        }

        async createReferree(triple, propName) {
          let _scope30 = {};

          let subjectUrlString = _getMember(_getMember((self.__expressionAnalysisMode__ ? _getLocal(_scope30, 'triple', triple) : void 0, triple), 'content'), (self.__expressionAnalysisMode__ ? _getLocal(_scope30, 'propName', propName) : void 0, propName));
          let subjectUrl = new (self.__expressionAnalysisMode__ ? _getGlobal('URL') : void 0, URL)((self.__expressionAnalysisMode__ ? _getLocal(_scope30, 'subjectUrlString', subjectUrlString) : void 0, subjectUrlString), _getMember((self.__expressionAnalysisMode__ ? _getLocal(_scope30, 'triple', triple) : void 0, triple), 'fileName'));
          let searchString = (self.__expressionAnalysisMode__ ? _traceMember(subjectUrl, 'toString') : void 0, (self.__expressionAnalysisMode__ ? _getLocal(_scope30, 'subjectUrl', subjectUrl) : void 0, subjectUrl).toString());

          let subject = await (self.__expressionAnalysisMode__ ? _traceMember(this, 'requestKnot') : void 0, this.requestKnot((self.__expressionAnalysisMode__ ? _getLocal(_scope30, 'subjectUrl', subjectUrl) : void 0, subjectUrl)));
          //let subject = this.knots.find(knot => knot.fileName === searchString);
          if (self.__expressionAnalysisMode__ ? _getLocal(_scope30, 'subject', subject) : void 0, subject) {
            _setMember((self.__expressionAnalysisMode__ ? _getLocal(_scope30, 'triple', triple) : void 0, triple), (self.__expressionAnalysisMode__ ? _getLocal(_scope30, 'propName', propName) : void 0, propName), (self.__expressionAnalysisMode__ ? _getLocal(_scope30, 'subject', subject) : void 0, subject));
          } else {
            throw new (self.__expressionAnalysisMode__ ? _getGlobal('Error') : void 0, Error)(`${(self.__expressionAnalysisMode__ ? _getLocal(_scope30, 'searchString', searchString) : void 0, searchString)} ${_getMember((self.__expressionAnalysisMode__ ? _getLocal(_scope30, 'triple', triple) : void 0, triple), 'fileName')} external referrees not yet implemented!`);
          }
        }
        async linkUpTriple(triple) {
          let _scope31 = {};

          return self.__expressionAnalysisMode__ ? _traceMember(Promise, 'all') : void 0, (self.__expressionAnalysisMode__ ? _getGlobal('Promise') : void 0, Promise).all([(self.__expressionAnalysisMode__ ? _traceMember(this, 'createReferree') : void 0, this.createReferree((self.__expressionAnalysisMode__ ? _getLocal(_scope31, 'triple', triple) : void 0, triple), 'subject')), (self.__expressionAnalysisMode__ ? _traceMember(this, 'createReferree') : void 0, this.createReferree((self.__expressionAnalysisMode__ ? _getLocal(_scope31, 'triple', triple) : void 0, triple), 'predicate')), (self.__expressionAnalysisMode__ ? _traceMember(this, 'createReferree') : void 0, this.createReferree((self.__expressionAnalysisMode__ ? _getLocal(_scope31, 'triple', triple) : void 0, triple), 'object'))]);
        }

        static async getInstance() {
          if (!_getMember(this, 'instance')) {
            _setMember(this, 'instance', new (_getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'Graph'))());
          }

          await _getAndCallMember(_getMember(this, 'instance'), 'prepare', []);

          return _getMember(this, 'instance');
        }
        static clearInstance() {
          _setMember(this, 'instance', (self.__expressionAnalysisMode__ ? _getGlobal('undefined') : void 0, undefined));
        }

        query(s, p, o) {
          let _scope32 = {};

          return _getAndCallMember(_getAndCallMember(_getAndCallMember(_getMember(this, 'triples'), 'filter', [triple => {
            let _scope33 = {};
            return (self.__expressionAnalysisMode__ ? _getLocal(_scope32, 's', s) : void 0, s) === _getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), '_') || _getMember((self.__expressionAnalysisMode__ ? _getLocal(_scope33, 'triple', triple) : void 0, triple), 'subject') === (self.__expressionAnalysisMode__ ? _getLocal(_scope32, 's', s) : void 0, s);
          }]), 'filter', [triple => {
            let _scope34 = {};
            return (self.__expressionAnalysisMode__ ? _getLocal(_scope32, 'p', p) : void 0, p) === _getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), '_') || _getMember((self.__expressionAnalysisMode__ ? _getLocal(_scope34, 'triple', triple) : void 0, triple), 'predicate') === (self.__expressionAnalysisMode__ ? _getLocal(_scope32, 'p', p) : void 0, p);
          }]), 'filter', [triple => {
            let _scope35 = {};
            return (self.__expressionAnalysisMode__ ? _getLocal(_scope32, 'o', o) : void 0, o) === _getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), '_') || _getMember((self.__expressionAnalysisMode__ ? _getLocal(_scope35, 'triple', triple) : void 0, triple), 'object') === (self.__expressionAnalysisMode__ ? _getLocal(_scope32, 'o', o) : void 0, o);
          }]);
        }

        getUrlsByKnot(knot) {
          let _scope36 = {};

          // TODO: we simply return the single reference url for now
          return [_getMember((self.__expressionAnalysisMode__ ? _getLocal(_scope36, 'knot', knot) : void 0, knot), 'fileName')];
        }

        // returns a promise for the Knot
        async requestKnot(url) {
          let _scope37 = {};

          const filePath = (self.__expressionAnalysisMode__ ? _traceMember(url, 'toString') : void 0, (self.__expressionAnalysisMode__ ? _getLocal(_scope37, 'url', url) : void 0, url).toString());
          if (!_getAndCallMember(_getMember(this, 'requestedKnots'), 'has', [(self.__expressionAnalysisMode__ ? _getLocal(_scope37, 'filePath', filePath) : void 0, filePath)])) {
            _getAndCallMember(_getMember(this, 'requestedKnots'), 'set', [(self.__expressionAnalysisMode__ ? _getLocal(_scope37, 'filePath', filePath) : void 0, filePath), (self.__expressionAnalysisMode__ ? _traceMember(this, 'loadSingleKnot') : void 0, this.loadSingleKnot((self.__expressionAnalysisMode__ ? _getLocal(_scope37, 'url', url) : void 0, url)))]);
          }
          return _getAndCallMember(_getMember(this, 'requestedKnots'), 'get', [(self.__expressionAnalysisMode__ ? _getLocal(_scope37, 'filePath', filePath) : void 0, filePath)]);
        }

        async loadSingleKnot(urlOrString) {
          let _scope38 = {};

          const url = new (self.__expressionAnalysisMode__ ? _getGlobal('URL') : void 0, URL)((self.__expressionAnalysisMode__ ? _getLocal(_scope38, 'urlOrString', urlOrString) : void 0, urlOrString));

          let fileName = (self.__expressionAnalysisMode__ ? _traceMember(url, 'toString') : void 0, (self.__expressionAnalysisMode__ ? _getLocal(_scope38, 'url', url) : void 0, url).toString());
          let text = _getAndCallMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'isExternalURL', [(self.__expressionAnalysisMode__ ? _getLocal(_scope38, 'url', url) : void 0, url)]) ? _getMember((self.__expressionAnalysisMode__ ? _getLocal(_scope38, 'url', url) : void 0, url), 'hostname') + _getMember((self.__expressionAnalysisMode__ ? _getLocal(_scope38, 'url', url) : void 0, url), 'pathname') : await _getAndCallMember(_getAndCallMember((self.__expressionAnalysisMode__ ? _getGlobal('fetch') : void 0, fetch)((self.__expressionAnalysisMode__ ? _getLocal(_scope38, 'url', url) : void 0, url)), 'then', [r => {
            let _scope39 = {};
            return self.__expressionAnalysisMode__ ? _traceMember(r, 'text') : void 0, (self.__expressionAnalysisMode__ ? _getLocal(_scope39, 'r', r) : void 0, r).text();
          }]), 'catch', [err => {
            let _scope40 = {};
            return `ERROR loading this knot: ${(self.__expressionAnalysisMode__ ? _getLocal(_scope40, 'err', err) : void 0, err)}`;
          }]);

          // deserializeKnot
          const isTriple = (self.__expressionAnalysisMode__ ? _traceMember(fileName, 'endsWith') : void 0, (self.__expressionAnalysisMode__ ? _getLocal(_scope38, 'fileName', fileName) : void 0, fileName).endsWith(".triple.json"));

          let knot;
          if (self.__expressionAnalysisMode__ ? _getLocal(_scope38, 'isTriple', isTriple) : void 0, isTriple) {
            knot = new (_getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'Triple'))((self.__expressionAnalysisMode__ ? _getLocal(_scope38, 'fileName', fileName) : void 0, fileName), (self.__expressionAnalysisMode__ ? _getLocal(_scope38, 'text', text) : void 0, text)), true ? _setLocal(_scope38, 'knot', knot) : void 0, knot;
            await (self.__expressionAnalysisMode__ ? _traceMember(this, 'linkUpTriple') : void 0, this.linkUpTriple((self.__expressionAnalysisMode__ ? _getLocal(_scope38, 'knot', knot) : void 0, knot)));
            _getAndCallMember(_getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'trackInstance'), 'call', [_getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'Triple'), (self.__expressionAnalysisMode__ ? _getLocal(_scope38, 'knot', knot) : void 0, knot)]);
          } else {
            knot = new (_getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'Knot'))((self.__expressionAnalysisMode__ ? _getLocal(_scope38, 'fileName', fileName) : void 0, fileName), (self.__expressionAnalysisMode__ ? _getLocal(_scope38, 'text', text) : void 0, text)), true ? _setLocal(_scope38, 'knot', knot) : void 0, knot;
          }

          _getAndCallMember(_getMember(this, 'knots'), 'push', [(self.__expressionAnalysisMode__ ? _getLocal(_scope38, 'knot', knot) : void 0, knot)]);

          return self.__expressionAnalysisMode__ ? _getLocal(_scope38, 'knot', knot) : void 0, knot;
        }

        async loadFromDir(directory) {
          let _scope41 = {};

          if (!_getAndCallMember(_getMember(this, 'loadedDirectoryPromises'), 'has', [(self.__expressionAnalysisMode__ ? _getLocal(_scope41, 'directory', directory) : void 0, directory)])) {
            _getAndCallMember(_getMember(this, 'loadedDirectoryPromises'), 'set', [(self.__expressionAnalysisMode__ ? _getLocal(_scope41, 'directory', directory) : void 0, directory), new (self.__expressionAnalysisMode__ ? _getGlobal('Promise') : void 0, Promise)(async resolve => {
              let _scope42 = {};

              const progress = await (self.__expressionAnalysisMode__ ? _traceMember(lively, 'showProgress') : void 0, (self.__expressionAnalysisMode__ ? _getGlobal('lively') : void 0, lively).showProgress(`loading dir ${(self.__expressionAnalysisMode__ ? _getLocal(_scope41, 'directory', directory) : void 0, directory)}`));
              _setMember((self.__expressionAnalysisMode__ ? _getLocal(_scope42, 'progress', progress) : void 0, progress), 'value', 0);

              const directoryURL = new (self.__expressionAnalysisMode__ ? _getGlobal('URL') : void 0, URL)((self.__expressionAnalysisMode__ ? _getLocal(_scope41, 'directory', directory) : void 0, directory));
              const json = await _getAndCallMember((self.__expressionAnalysisMode__ ? _getGlobal('fetch') : void 0, fetch)((self.__expressionAnalysisMode__ ? _getLocal(_scope41, 'directory', directory) : void 0, directory), { method: 'OPTIONS' }), 'then', [r => {
                let _scope43 = {};
                return self.__expressionAnalysisMode__ ? _traceMember(r, 'json') : void 0, (self.__expressionAnalysisMode__ ? _getLocal(_scope43, 'r', r) : void 0, r).json();
              }]);
              const fileNames = _getAndCallMember(_getAndCallMember(_getMember((self.__expressionAnalysisMode__ ? _getLocal(_scope42, 'json', json) : void 0, json), 'contents'), 'filter', [desc => {
                let _scope44 = {};
                return _getMember((self.__expressionAnalysisMode__ ? _getLocal(_scope44, 'desc', desc) : void 0, desc), 'type') === "file";
              }]), 'map', [desc => {
                let _scope45 = {};
                return _getMember((self.__expressionAnalysisMode__ ? _getLocal(_scope45, 'desc', desc) : void 0, desc), 'name');
              }]);

              const total = _getMember((self.__expressionAnalysisMode__ ? _getLocal(_scope42, 'fileNames', fileNames) : void 0, fileNames), 'length');
              let i = 0;
              const pool = new (self.__expressionAnalysisMode__ ? _getGlobal('Set') : void 0, Set)();
              const limit = 100;
              const arr = [1, 2, 3, 4, 5, 6];
              let ii = 0;
              const groups = (self.__expressionAnalysisMode__ ? _traceMember(fileNames, 'groupBy') : void 0, (self.__expressionAnalysisMode__ ? _getLocal(_scope42, 'fileNames', fileNames) : void 0, fileNames).groupBy((...args) => {
                return _getAndCallMember(((ii += 1, true ? _setLocal(_scope42, 'ii', ii) : void 0, ii) - 1) / (self.__expressionAnalysisMode__ ? _getLocal(_scope42, 'limit', limit) : void 0, limit), 'floor', []);
              }));
              for (let group of (self.__expressionAnalysisMode__ ? _traceMember(Object, 'values') : void 0, (self.__expressionAnalysisMode__ ? _getGlobal('Object') : void 0, Object).values((self.__expressionAnalysisMode__ ? _getLocal(_scope42, 'groups', groups) : void 0, groups)))) {
                let _scope46 = {};

                await (self.__expressionAnalysisMode__ ? _traceMember(Promise, 'all') : void 0, (self.__expressionAnalysisMode__ ? _getGlobal('Promise') : void 0, Promise).all((self.__expressionAnalysisMode__ ? _traceMember(group, 'map') : void 0, (self.__expressionAnalysisMode__ ? _getLocal(_scope46, 'group', group) : void 0, group).map(fileName => {
                  let _scope47 = {};

                  const knotURL = new (self.__expressionAnalysisMode__ ? _getGlobal('URL') : void 0, URL)((self.__expressionAnalysisMode__ ? _getLocal(_scope47, 'fileName', fileName) : void 0, fileName), (self.__expressionAnalysisMode__ ? _getLocal(_scope42, 'directoryURL', directoryURL) : void 0, directoryURL));
                  const prom = (self.__expressionAnalysisMode__ ? _traceMember(this, 'requestKnot') : void 0, this.requestKnot((self.__expressionAnalysisMode__ ? _getLocal(_scope47, 'knotURL', knotURL) : void 0, knotURL)));
                  _setMember((self.__expressionAnalysisMode__ ? _getLocal(_scope42, 'progress', progress) : void 0, progress), 'value', ((i += 1, true ? _setLocal(_scope42, 'i', i) : void 0, i) - 1) / (self.__expressionAnalysisMode__ ? _getLocal(_scope42, 'total', total) : void 0, total));
                  return self.__expressionAnalysisMode__ ? _getLocal(_scope47, 'prom', prom) : void 0, prom;
                }))));
              }

              await (self.__expressionAnalysisMode__ ? _getLocal(_scope42, 'resolve', resolve) : void 0, resolve)();
              await (self.__expressionAnalysisMode__ ? _traceMember(progress, 'remove') : void 0, (self.__expressionAnalysisMode__ ? _getLocal(_scope42, 'progress', progress) : void 0, progress).remove());
            })]);
          }
          return _getAndCallMember(_getMember(this, 'loadedDirectoryPromises'), 'get', [(self.__expressionAnalysisMode__ ? _getLocal(_scope41, 'directory', directory) : void 0, directory)]);
        }

        escapeSpecialCharacters(str) {
          let _scope48 = {};

          return self.__expressionAnalysisMode__ ? _traceMember(str, 'replace') : void 0, (self.__expressionAnalysisMode__ ? _getLocal(_scope48, 'str', str) : void 0, str).replace(/[^A-Za-z0-9-]/g, '_');
        }

        async fileForNameExists(name) {
          let _scope49 = {};

          const url = new (self.__expressionAnalysisMode__ ? _getGlobal('URL') : void 0, URL)(`${(self.__expressionAnalysisMode__ ? _traceMember(this, 'escapeSpecialCharacters') : void 0, this.escapeSpecialCharacters((self.__expressionAnalysisMode__ ? _getGlobal('str') : void 0, str)))}.md`, _getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'DEFAULT_FOLDER_URL'));
          return _getMember((await (self.__expressionAnalysisMode__ ? _getGlobal('fetch') : void 0, fetch)((self.__expressionAnalysisMode__ ? _getLocal(_scope49, 'url', url) : void 0, url))), 'status') === 200;
        }

        async getOrCreateKnotForTitle(name, defaultText = '# Default Text') {
          let _scope50 = {};

          const escapedName = (self.__expressionAnalysisMode__ ? _traceMember(this, 'escapeSpecialCharacters') : void 0, this.escapeSpecialCharacters((self.__expressionAnalysisMode__ ? _getLocal(_scope50, 'name', name) : void 0, name)));
          const proposedURL = `${_getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'DEFAULT_FOLDER_URL')}${(self.__expressionAnalysisMode__ ? _getLocal(_scope50, 'escapedName', escapedName) : void 0, escapedName)}.md`;

          const existingKnot = _getAndCallMember((self.__expressionAnalysisMode__ ? _traceMember(this, 'getKnots') : void 0, this.getKnots()), 'find', [knot => {
            let _scope51 = {};

            return _getMember((self.__expressionAnalysisMode__ ? _getLocal(_scope51, 'knot', knot) : void 0, knot), 'url') === (self.__expressionAnalysisMode__ ? _getLocal(_scope50, 'proposedURL', proposedURL) : void 0, proposedURL);
          }]);
          if (self.__expressionAnalysisMode__ ? _getLocal(_scope50, 'existingKnot', existingKnot) : void 0, existingKnot) {
            if (self.__expressionAnalysisMode__) _traceMember(lively, 'success');

            (self.__expressionAnalysisMode__ ? _getGlobal('lively') : void 0, lively).success('EXISTS IN MEMORY');
            return self.__expressionAnalysisMode__ ? _getLocal(_scope50, 'existingKnot', existingKnot) : void 0, existingKnot;
          }

          const fileExists = _getMember((await (self.__expressionAnalysisMode__ ? _getGlobal('fetch') : void 0, fetch)((self.__expressionAnalysisMode__ ? _getLocal(_scope50, 'proposedURL', proposedURL) : void 0, proposedURL))), 'status') === 200;
          if (self.__expressionAnalysisMode__ ? _getLocal(_scope50, 'fileExists', fileExists) : void 0, fileExists) {
            if (self.__expressionAnalysisMode__) _traceMember(lively, 'success');

            (self.__expressionAnalysisMode__ ? _getGlobal('lively') : void 0, lively).success('EXISTS REMOTELY');
            return self.__expressionAnalysisMode__ ? _traceMember(this, 'requestKnot') : void 0, this.requestKnot((self.__expressionAnalysisMode__ ? _getLocal(_scope50, 'proposedURL', proposedURL) : void 0, proposedURL));
          }

          if (self.__expressionAnalysisMode__) _traceMember(lively, 'warn');
          (self.__expressionAnalysisMode__ ? _getGlobal('lively') : void 0, lively).warn('NON EXISTENT');
          return self.__expressionAnalysisMode__ ? _traceMember(this, 'createKnot') : void 0, this.createKnot(_getMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'DEFAULT_FOLDER_URL'), (self.__expressionAnalysisMode__ ? _getLocal(_scope50, 'name', name) : void 0, name), 'md');
        }

        async getNonCollidableURL(directory, name, fileEnding) {
          let _scope52 = {};

          const maxTries = 10;
          const fileName = (self.__expressionAnalysisMode__ ? _traceMember(this, 'escapeSpecialCharacters') : void 0, this.escapeSpecialCharacters((self.__expressionAnalysisMode__ ? _getLocal(_scope52, 'name', name) : void 0, name)));
          let offset = 0;
          let i = 0;

          for (; i < maxTries; i++) {
            let _scope53 = {};

            let bust = (self.__expressionAnalysisMode__ ? _getLocal(_scope52, 'offset', offset) : void 0, offset) === 0 ? '' : (self.__expressionAnalysisMode__ ? _getLocal(_scope52, 'offset', offset) : void 0, offset);
            let url = new (self.__expressionAnalysisMode__ ? _getGlobal('URL') : void 0, URL)(`${(self.__expressionAnalysisMode__ ? _getLocal(_scope52, 'fileName', fileName) : void 0, fileName)}${(self.__expressionAnalysisMode__ ? _getLocal(_scope53, 'bust', bust) : void 0, bust)}.${(self.__expressionAnalysisMode__ ? _getLocal(_scope52, 'fileEnding', fileEnding) : void 0, fileEnding)}`, (self.__expressionAnalysisMode__ ? _getLocal(_scope52, 'directory', directory) : void 0, directory));
            let fileExists = _getMember((await (self.__expressionAnalysisMode__ ? _getGlobal('fetch') : void 0, fetch)((self.__expressionAnalysisMode__ ? _getLocal(_scope53, 'url', url) : void 0, url))), 'status') === 200;
            if (self.__expressionAnalysisMode__ ? _getLocal(_scope53, 'fileExists', fileExists) : void 0, fileExists) {
              (offset += 1, true ? _setLocal(_scope52, 'offset', offset) : void 0, offset) - 1;
            } else {
              return self.__expressionAnalysisMode__ ? _getLocal(_scope53, 'url', url) : void 0, url;
            }
          }
          throw new (self.__expressionAnalysisMode__ ? _getGlobal('Error') : void 0, Error)('too many tries for '); // TODO: improve error message
        }
        async createKnot(directory, name, fileEnding) {
          let _scope54 = {};

          if ((self.__expressionAnalysisMode__ ? _getLocal(_scope54, 'fileEnding', fileEnding) : void 0, fileEnding) !== 'md') {
            throw new (self.__expressionAnalysisMode__ ? _getGlobal('Error') : void 0, Error)('only .md files supported by now, instead found ', +(self.__expressionAnalysisMode__ ? _getLocal(_scope54, 'fileEnding', fileEnding) : void 0, fileEnding));
          }

          let url = await (self.__expressionAnalysisMode__ ? _traceMember(this, 'getNonCollidableURL') : void 0, this.getNonCollidableURL((self.__expressionAnalysisMode__ ? _getLocal(_scope54, 'directory', directory) : void 0, directory), (self.__expressionAnalysisMode__ ? _getLocal(_scope54, 'name', name) : void 0, name), (self.__expressionAnalysisMode__ ? _getLocal(_scope54, 'fileEnding', fileEnding) : void 0, fileEnding)));
          let content = `# ${(self.__expressionAnalysisMode__ ? _getLocal(_scope54, 'name', name) : void 0, name)}

`;
          await _getAndCallMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('lively') : void 0, lively), 'files'), 'saveFile', [(self.__expressionAnalysisMode__ ? _getLocal(_scope54, 'url', url) : void 0, url), (self.__expressionAnalysisMode__ ? _getLocal(_scope54, 'content', content) : void 0, content)]);

          return self.__expressionAnalysisMode__ ? _traceMember(this, 'requestKnot') : void 0, this.requestKnot((self.__expressionAnalysisMode__ ? _getLocal(_scope54, 'url', url) : void 0, url));
        }
        async createTriple(subjectUrlString, predicateURLString, objectURLString, knowledgeBaseURLString) {
          let _scope55 = {};

          await (self.__expressionAnalysisMode__ ? _traceMember(this, 'requestKnot') : void 0, this.requestKnot((self.__expressionAnalysisMode__ ? _getLocal(_scope55, 'subjectUrlString', subjectUrlString) : void 0, subjectUrlString)));
          await (self.__expressionAnalysisMode__ ? _traceMember(this, 'requestKnot') : void 0, this.requestKnot((self.__expressionAnalysisMode__ ? _getLocal(_scope55, 'predicateURLString', predicateURLString) : void 0, predicateURLString)));
          await (self.__expressionAnalysisMode__ ? _traceMember(this, 'requestKnot') : void 0, this.requestKnot((self.__expressionAnalysisMode__ ? _getLocal(_scope55, 'objectURLString', objectURLString) : void 0, objectURLString)));

          const url = await (self.__expressionAnalysisMode__ ? _traceMember(this, 'getNonCollidableURL') : void 0, this.getNonCollidableURL((self.__expressionAnalysisMode__ ? _getLocal(_scope55, 'knowledgeBaseURLString', knowledgeBaseURLString) : void 0, knowledgeBaseURLString), 'triple-' + _getAndCallMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'uuid', []), 'triple.json'));
          const content = (self.__expressionAnalysisMode__ ? _traceMember(JSON, 'stringify') : void 0, (self.__expressionAnalysisMode__ ? _getGlobal('JSON') : void 0, JSON).stringify({
            subject: subjectUrlString,
            predicate: predicateURLString,
            object: objectURLString
          }));
          await _getAndCallMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('lively') : void 0, lively), 'files'), 'saveFile', [(self.__expressionAnalysisMode__ ? _getLocal(_scope55, 'url', url) : void 0, url), (self.__expressionAnalysisMode__ ? _getLocal(_scope55, 'content', content) : void 0, content)]);

          //await invalidateFetchCache(knowledgeBaseURLString);

          return self.__expressionAnalysisMode__ ? _traceMember(this, 'requestKnot') : void 0, this.requestKnot((self.__expressionAnalysisMode__ ? _getLocal(_scope55, 'url', url) : void 0, url));
        }

      }

      // wild card for querying

      _export('Graph', Graph);

      _setMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), 'Graph', (self.__expressionAnalysisMode__ ? _getLocal(_scope, 'Graph', Graph) : void 0, Graph));

      const _ = {};

      _export('_', _);

      _setMember(_getMember((self.__expressionAnalysisMode__ ? _getGlobal('_recorder_') : void 0, _recorder_), '_src_client_triples_triples_js'), '_', (self.__expressionAnalysisMode__ ? _getLocal(_scope, '_', _) : void 0, _));
    }
  };
});