# generated by patch-package 6.4.7 on 2021-05-12 22:37:03
#
# command:
#   npx patch-package htmldiff --exclude '^dist/.*'
#
# declared package:
#   htmldiff: github:mblink/htmldiff.js#3e2482bee852bb811f5cc1f2be8f93d6c56ddc0e
#
# store token position + fix tokenizer
# https://github.com/mblink/htmldiff.js/pull/2
#
diff --git a/node_modules/htmldiff/package.json b/node_modules/htmldiff/package.json
index 9872a13..578c718 100644
--- a/node_modules/htmldiff/package.json
+++ b/node_modules/htmldiff/package.json
@@ -13,7 +13,7 @@
   },
   "private": true,
   "license": "MIT",
-  "main": "dist/htmldiff.ts",
+  "main": "dist/htmldiff.js",
   "files": [
     "dist/htmldiff.d.ts",
     "dist/htmldiff.js",
@@ -22,7 +22,9 @@
   ],
   "type": "module",
   "types": "dist/htmldiff.d.ts",
-  "dependencies": {},
+  "dependencies": {
+    "xregexp": "^5.0.2"
+  },
   "devDependencies": {
     "@typescript-eslint/eslint-plugin": "~4.16.1",
     "@typescript-eslint/parser": "~4.16.1",
@@ -35,6 +37,8 @@
   "scripts": {
     "lint": "eslint --config='.eslintrc.cjs' './src/*.ts' --fix",
     "test": "npm run make && mocha -R min",
-    "make": "tsc -p tsconfig.json"
+    "make": "tsc -p tsconfig.json",
+    "prepare": "npm run make",
+    "diff": "git diff -- :/ ':(exclude,top)dist/*'"
   }
 }
diff --git a/node_modules/htmldiff/src/htmldiff.ts b/node_modules/htmldiff/src/htmldiff.ts
index ecfa2e6..5dc3823 100644
--- a/node_modules/htmldiff/src/htmldiff.ts
+++ b/node_modules/htmldiff/src/htmldiff.ts
@@ -25,6 +25,11 @@
  *   htmldiff('<p>this is some text</p>', '<p>this is some more text</p>', 'diff-class')
  *   == '<p>this is some <ins class="diff-class">more </ins>text</p>'
  */
+
+import XRegExp from 'xregexp';
+
+const unicodeLetterExpr = XRegExp('\\p{L}|\\d');
+
 function isEndOfTag(char: string): boolean {
   return char === '>';
 }
@@ -121,6 +126,7 @@ function isWrappable(token: string): boolean {
 type Token = {
   str: string;
   key: string;
+  pos: number;
 };
 
 /**
@@ -131,10 +137,11 @@ type Token = {
  *
  * @return {Object} A token object with a string and key property.
  */
-export function createToken(currentWord: string): Token {
+export function createToken(currentWord: string, currentWordPos: number): Token {
   return {
     str: currentWord,
-    key: getKeyForToken(currentWord)
+    key: getKeyForToken(currentWord),
+    pos: currentWordPos
   };
 }
 
@@ -183,10 +190,13 @@ function makeMatch(startInBefore: number, startInAfter: number, length: number,
 export function htmlToTokens(html: string): Token[] {
   let mode = 'char';
   let currentWord = '';
+  let currentWordPos = 0;
   let currentAtomicTag = '';
   const words = [];
 
-  for (const char of html) {
+  const unicodeChars = Array.from(html);
+  for (let charIdx = 0; charIdx < unicodeChars.length; charIdx++) {
+    const char = unicodeChars[charIdx] as string;
     switch (mode){
       case 'tag': {
         const atomicTag = isStartOfAtomicTag(currentWord);
@@ -199,8 +209,9 @@ export function htmlToTokens(html: string): Token[] {
           currentWord += char;
         } else if (isEndOfTag(char)){
           currentWord += '>';
-          words.push(createToken(currentWord));
+          words.push(createToken(currentWord, currentWordPos));
           currentWord = '';
+          currentWordPos = charIdx + 1;
           if (isWhitespace(char)){
             mode = 'whitespace';
           } else {
@@ -214,8 +225,9 @@ export function htmlToTokens(html: string): Token[] {
       case 'atomic_tag':
         if (isEndOfTag(char) && isEndOfAtomicTag(currentWord, currentAtomicTag)){
           currentWord += '>';
-          words.push(createToken(currentWord));
+          words.push(createToken(currentWord, currentWordPos));
           currentWord = '';
+          currentWordPos = charIdx + 1;
           currentAtomicTag = '';
           mode = 'char';
         } else {
@@ -226,49 +238,72 @@ export function htmlToTokens(html: string): Token[] {
         currentWord += char;
         if (isEndOfHTMLComment(currentWord)){
           currentWord = '';
+          currentWordPos = charIdx + 1;
           mode = 'char';
         }
         break;
       case 'char':
         if (isStartOfTag(char)){
           if (currentWord){
-            words.push(createToken(currentWord));
+            words.push(createToken(currentWord, currentWordPos));
           }
           currentWord = '<';
+          currentWordPos = charIdx;
           mode = 'tag';
         } else if (/\s/.test(char)){
           if (currentWord){
-            words.push(createToken(currentWord));
+            words.push(createToken(currentWord, currentWordPos));
           }
           currentWord = char;
+          currentWordPos = charIdx;
           mode = 'whitespace';
-        } else if (/[\w\d#@]/.test(char)){
+        } else if (unicodeLetterExpr.test(char)) {
           currentWord += char;
-        } else if (/&/.test(char)){
+        } else if (char == '&'){
           if (currentWord){
-            words.push(createToken(currentWord));
+            words.push(createToken(currentWord, currentWordPos));
           }
           currentWord = char;
+          currentWordPos = charIdx;
+          mode = 'entity';
         } else {
+          if (currentWord){
+            words.push(createToken(currentWord, currentWordPos));
+          }
+          words.push(createToken(char, charIdx));
+          currentWord = '';
+          currentWordPos = charIdx + 1;
+        }
+        break;
+      case 'entity':
+        if (char == ';') {
           currentWord += char;
-          words.push(createToken(currentWord));
+          words.push(createToken(currentWord, currentWordPos));
           currentWord = '';
+          currentWordPos = charIdx + 1;
+          mode = 'char';
+        }
+        else {
+          currentWord += char;
         }
         break;
       case 'whitespace':
         if (isStartOfTag(char)){
           if (currentWord){
-            words.push(createToken(currentWord));
+            words.push(createToken(currentWord, currentWordPos));
           }
           currentWord = '<';
+          currentWordPos = charIdx;
           mode = 'tag';
         } else if (isWhitespace(char)){
           currentWord += char;
         } else {
           if (currentWord){
-            words.push(createToken(currentWord));
+            words.push(createToken(currentWord, currentWordPos));
           }
-          currentWord = char;
+          currentWord = '';
+          currentWordPos = charIdx;
+          charIdx--; // seek back
           mode = 'char';
         }
         break;
@@ -277,7 +312,7 @@ export function htmlToTokens(html: string): Token[] {
     }
   }
   if (currentWord){
-    words.push(createToken(currentWord));
+    words.push(createToken(currentWord, currentWordPos));
   }
   return words;
 }
@@ -654,8 +689,10 @@ export function findMatchingBlocks(segment: Segment): Match[] {
   return nodeToArray(matches);
 }
 
+type OperationAction = 'none' | 'equal' | 'insert' | 'delete' | 'replace';
+
 type Operation = {
-  action: 'equal' | 'insert' | 'delete' | 'replace';
+  action: OperationAction;
   startInBefore: number;
   endInBefore?: number;
   startInAfter: number;
@@ -690,7 +727,7 @@ export function calculateOperations(beforeTokens: Token[], afterTokens: Token[])
   matches.push(makeMatch(beforeTokens.length, afterTokens.length, 0, segment));
 
   matches.forEach(match => {
-    let actionUpToMatchPositions: 'equal' | 'insert' | 'delete' | 'replace' | 'none'  = 'none';
+    let actionUpToMatchPositions: OperationAction  = 'none';
     if (positionInBefore === match.startInBefore){
       if (positionInAfter !== match.startInAfter){
         actionUpToMatchPositions = 'insert';
@@ -896,7 +933,7 @@ function wrap(tag: string, content: string[], opIndex: number, dataPrefix: strin
 }
 
 /**
- * OPS.equal/insert/delete/replace are functions that render an operation into
+ * renderHandler.equal/insert/delete/replace are functions that render an operation into
  * HTML content.
  *
  * @param {Object} op The operation that applies to a prticular list of tokens. Has the
@@ -915,10 +952,11 @@ function wrap(tag: string, content: string[], opIndex: number, dataPrefix: strin
  *
  * @return {string} The rendering of that operation.
  */
-const OPS: {
-  [K in 'equal' | 'insert' | 'delete' | 'replace'] : (op: Operation, beforeTokens: Token[], afterTokens: Token[], opIndex: number, dataPrefix: string, className: string) => string
+const renderHandler: {
+  [action in OperationAction] : (op: Operation, beforeTokens: Token[], afterTokens: Token[], opIndex: number, dataPrefix: string, className: string) => string
 } = {
   // eslint-disable-next-line @typescript-eslint/no-unused-vars
+  none: () => '',
   'equal': function(op: Operation, beforeTokens: Token[], afterTokens: Token[], opIndex: number, dataPrefix: string, className: string){
     const tokens = op.endInAfter ?
       afterTokens.slice(op.startInAfter, op.endInAfter + 1) :
@@ -946,8 +984,8 @@ const OPS: {
     return wrap('del', val, opIndex, dataPrefix, className);
   },
   'replace': function(op: Operation, beforeTokens: Token[], afterTokens: Token[], opIndex: number, dataPrefix: string, className: string){
-    return OPS.delete.apply(null, [op, beforeTokens, afterTokens, opIndex, dataPrefix, className])
-      + OPS.insert.apply(null, [op, beforeTokens, afterTokens, opIndex, dataPrefix, className]);
+    return renderHandler.delete.apply(null, [op, beforeTokens, afterTokens, opIndex, dataPrefix, className])
+      + renderHandler.insert.apply(null, [op, beforeTokens, afterTokens, opIndex, dataPrefix, className]);
   }
 };
 
@@ -972,7 +1010,7 @@ const OPS: {
  */
 export function renderOperations(beforeTokens: Token[], afterTokens: Token[], operations: Operation[], dataPrefix: string, className: string){
   return operations.reduce(function(rendering: string, op: Operation, index: number){
-    return rendering + OPS[op.action](
+    return rendering + renderHandler[op.action](
       op, beforeTokens, afterTokens, index, dataPrefix, className);
   }, '');
 }
diff --git a/node_modules/htmldiff/test/html_to_tokens.spec.js b/node_modules/htmldiff/test/html_to_tokens.spec.js
index 6a4fbfa..2a54b3d 100644
--- a/node_modules/htmldiff/test/html_to_tokens.spec.js
+++ b/node_modules/htmldiff/test/html_to_tokens.spec.js
@@ -8,8 +8,11 @@ describe('htmlToTokens', function(){
     cut = htmlToTokens;
 
     tokenize = function(tokens){
+      let tokenIdx = 0;
       return tokens.map(function(token){
-        return createToken(token);
+        const res = createToken(token, tokenIdx);
+        tokenIdx += token.length;
+        return res;
       });
     };
   });
