Move some diff-related methods and consts to gr-diff-utils

In this change some methods and consts from the global Gerrit object are
moved to the gr-diff-utils.js file.

Change-Id: I6b6466b91f7886722b140f2a58c04c5cea2b1717
diff --git a/polygerrit-ui/app/elements/diff/gr-diff/gr-diff-utils.js b/polygerrit-ui/app/elements/diff/gr-diff/gr-diff-utils.js
new file mode 100644
index 0000000..7eee071
--- /dev/null
+++ b/polygerrit-ui/app/elements/diff/gr-diff/gr-diff-utils.js
@@ -0,0 +1,40 @@
+/**
+ * @license
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/** @enum {string} */
+export const DiffSide = {
+  LEFT: 'left',
+  RIGHT: 'right',
+};
+
+/**
+ * Compare two ranges. Either argument may be falsy, but will only return
+ * true if both are falsy or if neither are falsy and have the same position
+ * values.
+ *
+ * @param {Range=} a range 1
+ * @param {Range=} b range 2
+ * @return {boolean}
+ */
+export function rangesEqual(a, b) {
+  if (!a && !b) { return true; }
+  if (!a || !b) { return false; }
+  return a.start_line === b.start_line &&
+      a.start_character === b.start_character &&
+      a.end_line === b.end_line &&
+      a.end_character === b.end_character;
+}
diff --git a/polygerrit-ui/app/elements/diff/gr-diff/gr-diff.js b/polygerrit-ui/app/elements/diff/gr-diff/gr-diff.js
index 0597994..aa42ecd 100644
--- a/polygerrit-ui/app/elements/diff/gr-diff/gr-diff.js
+++ b/polygerrit-ui/app/elements/diff/gr-diff/gr-diff.js
@@ -32,6 +32,7 @@
 import {htmlTemplate} from './gr-diff_html.js';
 import {PatchSetBehavior} from '../../../behaviors/gr-patch-set-behavior/gr-patch-set-behavior.js';
 import {GrDiffLine} from './gr-diff-line.js';
+import {DiffSide, rangesEqual} from './gr-diff-utils.js';
 
 const ERR_COMMENT_ON_EDIT = 'You cannot comment on an edit.';
 const ERR_COMMENT_ON_EDIT_BASE = 'You cannot comment on the base patch set ' +
@@ -46,55 +47,15 @@
   UNIFIED: 'UNIFIED_DIFF',
 };
 
-const DiffSide = {
-  LEFT: 'left',
-  RIGHT: 'right',
-};
-
 const LARGE_DIFF_THRESHOLD_LINES = 10000;
 const FULL_CONTEXT = -1;
 const LIMITED_CONTEXT = 10;
 
-/**
- * Compare two ranges. Either argument may be falsy, but will only return
- * true if both are falsy or if neither are falsy and have the same position
- * values.
- *
- * @param {Gerrit.Range=} a range 1
- * @param {Gerrit.Range=} b range 2
- * @return {boolean}
- */
-Gerrit.rangesEqual = function(a, b) {
-  if (!a && !b) { return true; }
-  if (!a || !b) { return false; }
-  return a.start_line === b.start_line &&
-      a.start_character === b.start_character &&
-      a.end_line === b.end_line &&
-      a.end_character === b.end_character;
-};
-
 function isThreadEl(node) {
   return node.nodeType === Node.ELEMENT_NODE &&
       node.classList.contains('comment-thread');
 }
 
-/**
- * Turn a slot element into the corresponding content element.
- * Slots are only fully supported in Polymer 2 - in Polymer 1, they are
- * replaced with content elements during template parsing. This conversion is
- * not applied for imperatively created slot elements, so this method
- * implements the same behavior as the template parsing for imperative slots.
- */
-Gerrit.slotToContent = function(slot) {
-  if (PolymerElement) {
-    return slot;
-  }
-  const content = document.createElement('content');
-  content.name = slot.name;
-  content.setAttribute('select', `[slot='${slot.name}']`);
-  return content;
-};
-
 const COMMIT_MSG_PATH = '/COMMIT_MSG';
 /**
  * 72 is the inofficial length standard for git commit messages.
@@ -406,7 +367,7 @@
       const i = this._commentRanges
           .findIndex(
               cr => cr.side === removedCommentRange.side &&
-            Gerrit.rangesEqual(cr.range, removedCommentRange.range)
+            rangesEqual(cr.range, removedCommentRange.range)
           );
       this.splice('_commentRanges', i, 1);
     }
@@ -665,7 +626,7 @@
    * diff.
    *
    * @param {!Object} contentEl
-   * @param {!Gerrit.DiffSide} commentSide
+   * @param {!DiffSide} commentSide
    * @return {!Node}
    */
   _getOrCreateThreadGroup(contentEl, commentSide) {
@@ -884,7 +845,7 @@
         // are ignored.
         const slot = document.createElement('slot');
         slot.name = threadEl.getAttribute('slot');
-        dom(threadGroupEl).appendChild(Gerrit.slotToContent(slot));
+        dom(threadGroupEl).appendChild(slot);
         lastEl = threadEl;
       }