System.register(["utils"], function (_export, _context) {
  "use strict";

  var loc, range, fileEnding, replaceFileEndingWith, CodeMirrorCodeProvider, __SystemJSRewritingHack;
  _export("default", void 0);
  return {
    setters: [function (_utils) {
      loc = _utils.loc;
      range = _utils.range;
      fileEnding = _utils.fileEnding;
      replaceFileEndingWith = _utils.replaceFileEndingWith;
    }],
    execute: function () {
      __SystemJSRewritingHack = {};
      _recorder_._https__lively_kernel_org_lively4_lively4_ansgar_src_components_widgets_lively_code_mirror_code_provider_js = _recorder_._https__lively_kernel_org_lively4_lively4_ansgar_src_components_widgets_lively_code_mirror_code_provider_js || {};
      Object.defineProperty(_recorder_._https__lively_kernel_org_lively4_lively4_ansgar_src_components_widgets_lively_code_mirror_code_provider_js, "replaceFileEndingWith", {
        get() {
          return replaceFileEndingWith;
        },
        set(thisIsVererySecretVariableName) {
          replaceFileEndingWith = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._https__lively_kernel_org_lively4_lively4_ansgar_src_components_widgets_lively_code_mirror_code_provider_js, "fileEnding", {
        get() {
          return fileEnding;
        },
        set(thisIsVererySecretVariableName) {
          fileEnding = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._https__lively_kernel_org_lively4_lively4_ansgar_src_components_widgets_lively_code_mirror_code_provider_js, "range", {
        get() {
          return range;
        },
        set(thisIsVererySecretVariableName) {
          range = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      Object.defineProperty(_recorder_._https__lively_kernel_org_lively4_lively4_ansgar_src_components_widgets_lively_code_mirror_code_provider_js, "loc", {
        get() {
          return loc;
        },
        set(thisIsVererySecretVariableName) {
          loc = thisIsVererySecretVariableName;
          return true;
        },
        enumerable: true,
        configurable: true
      });
      _export("default", CodeMirrorCodeProvider = class CodeMirrorCodeProvider {
        constructor(livelyCodeMirror, codeMirror) {
          this.codeMirror = codeMirror;
          this.livelyCodeMirror = livelyCodeMirror;
        }
        get code() {
          return this.livelyCodeMirror.value;
        }
        set code(text) {
          this.livelyCodeMirror.value = text;
          this.livelyCodeMirror.focus();
        }
        get cursor() {
          return loc(this.codeMirror.getCursor());
        }
        set cursor(location) {
          this.selections = [range([location, location])];
        }
        get selections() {
          return this.codeMirror.listSelections().map(range);
        }

        /** 
         * Select the text corresponding to the given nodes in the editor
         */
        set selections(ranges) {
          if (ranges.length === 0) return;
          const selections = ranges.map(range => {
            return {
              anchor: range.asCM()[0],
              head: range.asCM()[1]
            };
          });

          // #TODO: include primary selection
          if (selections.length == 1) {
            this.codeMirror.setSelection(selections[0].anchor, selections[0].head);
          } else {
            this.codeMirror.setSelections(selections);
          }
          this.codeMirror.scrollIntoView({
            from: selections[0].anchor,
            to: selections[0].head
          }, 120);
        }
        get scrollInfo() {
          return this.codeMirror.getScrollInfo();
        }
        set scrollInfo(scrollInfo) {
          this.codeMirror.scrollIntoView({
            left: scrollInfo.left,
            top: scrollInfo.top,
            right: scrollInfo.left + scrollInfo.width,
            bottom: scrollInfo.top + scrollInfo.height
          }, 120);
        }
        get htmlURI() {
          let editor = lively.allParents(this.livelyCodeMirror, undefined, true).find(ele => ele.tagName && ele.tagName === 'LIVELY-EDITOR');
          let jsURI = encodeURI(editor.shadowRoot.querySelector("#filename").value);
          return replaceFileEndingWith.call(jsURI, 'html');
        }
      });
      Object.defineProperty(_recorder_._https__lively_kernel_org_lively4_lively4_ansgar_src_components_widgets_lively_code_mirror_code_provider_js, "CodeMirrorCodeProvider", {
        get() {
          return CodeMirrorCodeProvider;
        },
        set(thisIsVererySecretVariableName) {
          _export("default", CodeMirrorCodeProvider = thisIsVererySecretVariableName);
          return true;
        },
        enumerable: true,
        configurable: true
      });
    }
  };
});