index.cjs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773
  1. 'use strict';
  2. const defaults = Object.freeze({
  3. ignoreUnknown: false,
  4. respectType: false,
  5. respectFunctionNames: false,
  6. respectFunctionProperties: false,
  7. unorderedObjects: true,
  8. unorderedArrays: false,
  9. unorderedSets: false,
  10. excludeKeys: void 0,
  11. excludeValues: void 0,
  12. replacer: void 0
  13. });
  14. function objectHash(object, options) {
  15. if (options) {
  16. options = { ...defaults, ...options };
  17. } else {
  18. options = defaults;
  19. }
  20. const hasher = createHasher(options);
  21. hasher.dispatch(object);
  22. return hasher.toString();
  23. }
  24. const defaultPrototypesKeys = Object.freeze([
  25. "prototype",
  26. "__proto__",
  27. "constructor"
  28. ]);
  29. function createHasher(options) {
  30. let buff = "";
  31. let context = /* @__PURE__ */ new Map();
  32. const write = (str) => {
  33. buff += str;
  34. };
  35. return {
  36. toString() {
  37. return buff;
  38. },
  39. getContext() {
  40. return context;
  41. },
  42. dispatch(value) {
  43. if (options.replacer) {
  44. value = options.replacer(value);
  45. }
  46. const type = value === null ? "null" : typeof value;
  47. return this[type](value);
  48. },
  49. object(object) {
  50. if (object && typeof object.toJSON === "function") {
  51. return this.object(object.toJSON());
  52. }
  53. const objString = Object.prototype.toString.call(object);
  54. let objType = "";
  55. const objectLength = objString.length;
  56. if (objectLength < 10) {
  57. objType = "unknown:[" + objString + "]";
  58. } else {
  59. objType = objString.slice(8, objectLength - 1);
  60. }
  61. objType = objType.toLowerCase();
  62. let objectNumber = null;
  63. if ((objectNumber = context.get(object)) === void 0) {
  64. context.set(object, context.size);
  65. } else {
  66. return this.dispatch("[CIRCULAR:" + objectNumber + "]");
  67. }
  68. if (typeof Buffer !== "undefined" && Buffer.isBuffer && Buffer.isBuffer(object)) {
  69. write("buffer:");
  70. return write(object.toString("utf8"));
  71. }
  72. if (objType !== "object" && objType !== "function" && objType !== "asyncfunction") {
  73. if (this[objType]) {
  74. this[objType](object);
  75. } else if (!options.ignoreUnknown) {
  76. this.unkown(object, objType);
  77. }
  78. } else {
  79. let keys = Object.keys(object);
  80. if (options.unorderedObjects) {
  81. keys = keys.sort();
  82. }
  83. let extraKeys = [];
  84. if (options.respectType !== false && !isNativeFunction(object)) {
  85. extraKeys = defaultPrototypesKeys;
  86. }
  87. if (options.excludeKeys) {
  88. keys = keys.filter((key) => {
  89. return !options.excludeKeys(key);
  90. });
  91. extraKeys = extraKeys.filter((key) => {
  92. return !options.excludeKeys(key);
  93. });
  94. }
  95. write("object:" + (keys.length + extraKeys.length) + ":");
  96. const dispatchForKey = (key) => {
  97. this.dispatch(key);
  98. write(":");
  99. if (!options.excludeValues) {
  100. this.dispatch(object[key]);
  101. }
  102. write(",");
  103. };
  104. for (const key of keys) {
  105. dispatchForKey(key);
  106. }
  107. for (const key of extraKeys) {
  108. dispatchForKey(key);
  109. }
  110. }
  111. },
  112. array(arr, unordered) {
  113. unordered = unordered === void 0 ? options.unorderedArrays !== false : unordered;
  114. write("array:" + arr.length + ":");
  115. if (!unordered || arr.length <= 1) {
  116. for (const entry of arr) {
  117. this.dispatch(entry);
  118. }
  119. return;
  120. }
  121. const contextAdditions = /* @__PURE__ */ new Map();
  122. const entries = arr.map((entry) => {
  123. const hasher = createHasher(options);
  124. hasher.dispatch(entry);
  125. for (const [key, value] of hasher.getContext()) {
  126. contextAdditions.set(key, value);
  127. }
  128. return hasher.toString();
  129. });
  130. context = contextAdditions;
  131. entries.sort();
  132. return this.array(entries, false);
  133. },
  134. date(date) {
  135. return write("date:" + date.toJSON());
  136. },
  137. symbol(sym) {
  138. return write("symbol:" + sym.toString());
  139. },
  140. unkown(value, type) {
  141. write(type);
  142. if (!value) {
  143. return;
  144. }
  145. write(":");
  146. if (value && typeof value.entries === "function") {
  147. return this.array(
  148. Array.from(value.entries()),
  149. true
  150. /* ordered */
  151. );
  152. }
  153. },
  154. error(err) {
  155. return write("error:" + err.toString());
  156. },
  157. boolean(bool) {
  158. return write("bool:" + bool);
  159. },
  160. string(string) {
  161. write("string:" + string.length + ":");
  162. write(string);
  163. },
  164. function(fn) {
  165. write("fn:");
  166. if (isNativeFunction(fn)) {
  167. this.dispatch("[native]");
  168. } else {
  169. this.dispatch(fn.toString());
  170. }
  171. if (options.respectFunctionNames !== false) {
  172. this.dispatch("function-name:" + String(fn.name));
  173. }
  174. if (options.respectFunctionProperties) {
  175. this.object(fn);
  176. }
  177. },
  178. number(number) {
  179. return write("number:" + number);
  180. },
  181. xml(xml) {
  182. return write("xml:" + xml.toString());
  183. },
  184. null() {
  185. return write("Null");
  186. },
  187. undefined() {
  188. return write("Undefined");
  189. },
  190. regexp(regex) {
  191. return write("regex:" + regex.toString());
  192. },
  193. uint8array(arr) {
  194. write("uint8array:");
  195. return this.dispatch(Array.prototype.slice.call(arr));
  196. },
  197. uint8clampedarray(arr) {
  198. write("uint8clampedarray:");
  199. return this.dispatch(Array.prototype.slice.call(arr));
  200. },
  201. int8array(arr) {
  202. write("int8array:");
  203. return this.dispatch(Array.prototype.slice.call(arr));
  204. },
  205. uint16array(arr) {
  206. write("uint16array:");
  207. return this.dispatch(Array.prototype.slice.call(arr));
  208. },
  209. int16array(arr) {
  210. write("int16array:");
  211. return this.dispatch(Array.prototype.slice.call(arr));
  212. },
  213. uint32array(arr) {
  214. write("uint32array:");
  215. return this.dispatch(Array.prototype.slice.call(arr));
  216. },
  217. int32array(arr) {
  218. write("int32array:");
  219. return this.dispatch(Array.prototype.slice.call(arr));
  220. },
  221. float32array(arr) {
  222. write("float32array:");
  223. return this.dispatch(Array.prototype.slice.call(arr));
  224. },
  225. float64array(arr) {
  226. write("float64array:");
  227. return this.dispatch(Array.prototype.slice.call(arr));
  228. },
  229. arraybuffer(arr) {
  230. write("arraybuffer:");
  231. return this.dispatch(new Uint8Array(arr));
  232. },
  233. url(url) {
  234. return write("url:" + url.toString());
  235. },
  236. map(map) {
  237. write("map:");
  238. const arr = [...map];
  239. return this.array(arr, options.unorderedSets !== false);
  240. },
  241. set(set) {
  242. write("set:");
  243. const arr = [...set];
  244. return this.array(arr, options.unorderedSets !== false);
  245. },
  246. file(file) {
  247. write("file:");
  248. return this.dispatch([file.name, file.size, file.type, file.lastModfied]);
  249. },
  250. blob() {
  251. if (options.ignoreUnknown) {
  252. return write("[blob]");
  253. }
  254. throw new Error(
  255. 'Hashing Blob objects is currently not supported\nUse "options.replacer" or "options.ignoreUnknown"\n'
  256. );
  257. },
  258. domwindow() {
  259. return write("domwindow");
  260. },
  261. bigint(number) {
  262. return write("bigint:" + number.toString());
  263. },
  264. /* Node.js standard native objects */
  265. process() {
  266. return write("process");
  267. },
  268. timer() {
  269. return write("timer");
  270. },
  271. pipe() {
  272. return write("pipe");
  273. },
  274. tcp() {
  275. return write("tcp");
  276. },
  277. udp() {
  278. return write("udp");
  279. },
  280. tty() {
  281. return write("tty");
  282. },
  283. statwatcher() {
  284. return write("statwatcher");
  285. },
  286. securecontext() {
  287. return write("securecontext");
  288. },
  289. connection() {
  290. return write("connection");
  291. },
  292. zlib() {
  293. return write("zlib");
  294. },
  295. context() {
  296. return write("context");
  297. },
  298. nodescript() {
  299. return write("nodescript");
  300. },
  301. httpparser() {
  302. return write("httpparser");
  303. },
  304. dataview() {
  305. return write("dataview");
  306. },
  307. signal() {
  308. return write("signal");
  309. },
  310. fsevent() {
  311. return write("fsevent");
  312. },
  313. tlswrap() {
  314. return write("tlswrap");
  315. }
  316. };
  317. }
  318. const nativeFunc = "[native code] }";
  319. const nativeFuncLength = nativeFunc.length;
  320. function isNativeFunction(f) {
  321. if (typeof f !== "function") {
  322. return false;
  323. }
  324. return Function.prototype.toString.call(f).slice(-nativeFuncLength) === nativeFunc;
  325. }
  326. class WordArray {
  327. constructor(words, sigBytes) {
  328. words = this.words = words || [];
  329. this.sigBytes = sigBytes === void 0 ? words.length * 4 : sigBytes;
  330. }
  331. toString(encoder) {
  332. return (encoder || Hex).stringify(this);
  333. }
  334. concat(wordArray) {
  335. this.clamp();
  336. if (this.sigBytes % 4) {
  337. for (let i = 0; i < wordArray.sigBytes; i++) {
  338. const thatByte = wordArray.words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
  339. this.words[this.sigBytes + i >>> 2] |= thatByte << 24 - (this.sigBytes + i) % 4 * 8;
  340. }
  341. } else {
  342. for (let j = 0; j < wordArray.sigBytes; j += 4) {
  343. this.words[this.sigBytes + j >>> 2] = wordArray.words[j >>> 2];
  344. }
  345. }
  346. this.sigBytes += wordArray.sigBytes;
  347. return this;
  348. }
  349. clamp() {
  350. this.words[this.sigBytes >>> 2] &= 4294967295 << 32 - this.sigBytes % 4 * 8;
  351. this.words.length = Math.ceil(this.sigBytes / 4);
  352. }
  353. clone() {
  354. return new WordArray([...this.words]);
  355. }
  356. }
  357. const Hex = {
  358. stringify(wordArray) {
  359. const hexChars = [];
  360. for (let i = 0; i < wordArray.sigBytes; i++) {
  361. const bite = wordArray.words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
  362. hexChars.push((bite >>> 4).toString(16), (bite & 15).toString(16));
  363. }
  364. return hexChars.join("");
  365. }
  366. };
  367. const Base64 = {
  368. stringify(wordArray) {
  369. const keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  370. const base64Chars = [];
  371. for (let i = 0; i < wordArray.sigBytes; i += 3) {
  372. const byte1 = wordArray.words[i >>> 2] >>> 24 - i % 4 * 8 & 255;
  373. const byte2 = wordArray.words[i + 1 >>> 2] >>> 24 - (i + 1) % 4 * 8 & 255;
  374. const byte3 = wordArray.words[i + 2 >>> 2] >>> 24 - (i + 2) % 4 * 8 & 255;
  375. const triplet = byte1 << 16 | byte2 << 8 | byte3;
  376. for (let j = 0; j < 4 && i * 8 + j * 6 < wordArray.sigBytes * 8; j++) {
  377. base64Chars.push(keyStr.charAt(triplet >>> 6 * (3 - j) & 63));
  378. }
  379. }
  380. return base64Chars.join("");
  381. }
  382. };
  383. const Latin1 = {
  384. parse(latin1Str) {
  385. const latin1StrLength = latin1Str.length;
  386. const words = [];
  387. for (let i = 0; i < latin1StrLength; i++) {
  388. words[i >>> 2] |= (latin1Str.charCodeAt(i) & 255) << 24 - i % 4 * 8;
  389. }
  390. return new WordArray(words, latin1StrLength);
  391. }
  392. };
  393. const Utf8 = {
  394. parse(utf8Str) {
  395. return Latin1.parse(unescape(encodeURIComponent(utf8Str)));
  396. }
  397. };
  398. class BufferedBlockAlgorithm {
  399. constructor() {
  400. this._data = new WordArray();
  401. this._nDataBytes = 0;
  402. this._minBufferSize = 0;
  403. this.blockSize = 512 / 32;
  404. }
  405. reset() {
  406. this._data = new WordArray();
  407. this._nDataBytes = 0;
  408. }
  409. _append(data) {
  410. if (typeof data === "string") {
  411. data = Utf8.parse(data);
  412. }
  413. this._data.concat(data);
  414. this._nDataBytes += data.sigBytes;
  415. }
  416. // eslint-disable-next-line @typescript-eslint/no-unused-vars
  417. _doProcessBlock(_dataWords, _offset) {
  418. }
  419. _process(doFlush) {
  420. let processedWords;
  421. let nBlocksReady = this._data.sigBytes / (this.blockSize * 4);
  422. if (doFlush) {
  423. nBlocksReady = Math.ceil(nBlocksReady);
  424. } else {
  425. nBlocksReady = Math.max((nBlocksReady | 0) - this._minBufferSize, 0);
  426. }
  427. const nWordsReady = nBlocksReady * this.blockSize;
  428. const nBytesReady = Math.min(nWordsReady * 4, this._data.sigBytes);
  429. if (nWordsReady) {
  430. for (let offset = 0; offset < nWordsReady; offset += this.blockSize) {
  431. this._doProcessBlock(this._data.words, offset);
  432. }
  433. processedWords = this._data.words.splice(0, nWordsReady);
  434. this._data.sigBytes -= nBytesReady;
  435. }
  436. return new WordArray(processedWords, nBytesReady);
  437. }
  438. }
  439. class Hasher extends BufferedBlockAlgorithm {
  440. update(messageUpdate) {
  441. this._append(messageUpdate);
  442. this._process();
  443. return this;
  444. }
  445. finalize(messageUpdate) {
  446. if (messageUpdate) {
  447. this._append(messageUpdate);
  448. }
  449. }
  450. }
  451. const H = [
  452. 1779033703,
  453. -1150833019,
  454. 1013904242,
  455. -1521486534,
  456. 1359893119,
  457. -1694144372,
  458. 528734635,
  459. 1541459225
  460. ];
  461. const K = [
  462. 1116352408,
  463. 1899447441,
  464. -1245643825,
  465. -373957723,
  466. 961987163,
  467. 1508970993,
  468. -1841331548,
  469. -1424204075,
  470. -670586216,
  471. 310598401,
  472. 607225278,
  473. 1426881987,
  474. 1925078388,
  475. -2132889090,
  476. -1680079193,
  477. -1046744716,
  478. -459576895,
  479. -272742522,
  480. 264347078,
  481. 604807628,
  482. 770255983,
  483. 1249150122,
  484. 1555081692,
  485. 1996064986,
  486. -1740746414,
  487. -1473132947,
  488. -1341970488,
  489. -1084653625,
  490. -958395405,
  491. -710438585,
  492. 113926993,
  493. 338241895,
  494. 666307205,
  495. 773529912,
  496. 1294757372,
  497. 1396182291,
  498. 1695183700,
  499. 1986661051,
  500. -2117940946,
  501. -1838011259,
  502. -1564481375,
  503. -1474664885,
  504. -1035236496,
  505. -949202525,
  506. -778901479,
  507. -694614492,
  508. -200395387,
  509. 275423344,
  510. 430227734,
  511. 506948616,
  512. 659060556,
  513. 883997877,
  514. 958139571,
  515. 1322822218,
  516. 1537002063,
  517. 1747873779,
  518. 1955562222,
  519. 2024104815,
  520. -2067236844,
  521. -1933114872,
  522. -1866530822,
  523. -1538233109,
  524. -1090935817,
  525. -965641998
  526. ];
  527. const W = [];
  528. class SHA256 extends Hasher {
  529. constructor() {
  530. super(...arguments);
  531. this._hash = new WordArray([...H]);
  532. }
  533. reset() {
  534. super.reset();
  535. this._hash = new WordArray([...H]);
  536. }
  537. _doProcessBlock(M, offset) {
  538. const H2 = this._hash.words;
  539. let a = H2[0];
  540. let b = H2[1];
  541. let c = H2[2];
  542. let d = H2[3];
  543. let e = H2[4];
  544. let f = H2[5];
  545. let g = H2[6];
  546. let h = H2[7];
  547. for (let i = 0; i < 64; i++) {
  548. if (i < 16) {
  549. W[i] = M[offset + i] | 0;
  550. } else {
  551. const gamma0x = W[i - 15];
  552. const gamma0 = (gamma0x << 25 | gamma0x >>> 7) ^ (gamma0x << 14 | gamma0x >>> 18) ^ gamma0x >>> 3;
  553. const gamma1x = W[i - 2];
  554. const gamma1 = (gamma1x << 15 | gamma1x >>> 17) ^ (gamma1x << 13 | gamma1x >>> 19) ^ gamma1x >>> 10;
  555. W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16];
  556. }
  557. const ch = e & f ^ ~e & g;
  558. const maj = a & b ^ a & c ^ b & c;
  559. const sigma0 = (a << 30 | a >>> 2) ^ (a << 19 | a >>> 13) ^ (a << 10 | a >>> 22);
  560. const sigma1 = (e << 26 | e >>> 6) ^ (e << 21 | e >>> 11) ^ (e << 7 | e >>> 25);
  561. const t1 = h + sigma1 + ch + K[i] + W[i];
  562. const t2 = sigma0 + maj;
  563. h = g;
  564. g = f;
  565. f = e;
  566. e = d + t1 | 0;
  567. d = c;
  568. c = b;
  569. b = a;
  570. a = t1 + t2 | 0;
  571. }
  572. H2[0] = H2[0] + a | 0;
  573. H2[1] = H2[1] + b | 0;
  574. H2[2] = H2[2] + c | 0;
  575. H2[3] = H2[3] + d | 0;
  576. H2[4] = H2[4] + e | 0;
  577. H2[5] = H2[5] + f | 0;
  578. H2[6] = H2[6] + g | 0;
  579. H2[7] = H2[7] + h | 0;
  580. }
  581. finalize(messageUpdate) {
  582. super.finalize(messageUpdate);
  583. const nBitsTotal = this._nDataBytes * 8;
  584. const nBitsLeft = this._data.sigBytes * 8;
  585. this._data.words[nBitsLeft >>> 5] |= 128 << 24 - nBitsLeft % 32;
  586. this._data.words[(nBitsLeft + 64 >>> 9 << 4) + 14] = Math.floor(
  587. nBitsTotal / 4294967296
  588. );
  589. this._data.words[(nBitsLeft + 64 >>> 9 << 4) + 15] = nBitsTotal;
  590. this._data.sigBytes = this._data.words.length * 4;
  591. this._process();
  592. return this._hash;
  593. }
  594. }
  595. function sha256(message) {
  596. return new SHA256().finalize(message).toString();
  597. }
  598. function sha256base64(message) {
  599. return new SHA256().finalize(message).toString(Base64);
  600. }
  601. function hash(object, options = {}) {
  602. const hashed = typeof object === "string" ? object : objectHash(object, options);
  603. return sha256base64(hashed).slice(0, 10);
  604. }
  605. function murmurHash(key, seed = 0) {
  606. if (typeof key === "string") {
  607. key = createBuffer(key);
  608. }
  609. let i = 0;
  610. let h1 = seed;
  611. let k1;
  612. let h1b;
  613. const remainder = key.length & 3;
  614. const bytes = key.length - remainder;
  615. const c1 = 3432918353;
  616. const c2 = 461845907;
  617. while (i < bytes) {
  618. k1 = key[i] & 255 | (key[++i] & 255) << 8 | (key[++i] & 255) << 16 | (key[++i] & 255) << 24;
  619. ++i;
  620. k1 = (k1 & 65535) * c1 + (((k1 >>> 16) * c1 & 65535) << 16) & 4294967295;
  621. k1 = k1 << 15 | k1 >>> 17;
  622. k1 = (k1 & 65535) * c2 + (((k1 >>> 16) * c2 & 65535) << 16) & 4294967295;
  623. h1 ^= k1;
  624. h1 = h1 << 13 | h1 >>> 19;
  625. h1b = (h1 & 65535) * 5 + (((h1 >>> 16) * 5 & 65535) << 16) & 4294967295;
  626. h1 = (h1b & 65535) + 27492 + (((h1b >>> 16) + 58964 & 65535) << 16);
  627. }
  628. k1 = 0;
  629. switch (remainder) {
  630. case 3: {
  631. k1 ^= (key[i + 2] & 255) << 16;
  632. break;
  633. }
  634. case 2: {
  635. k1 ^= (key[i + 1] & 255) << 8;
  636. break;
  637. }
  638. case 1: {
  639. k1 ^= key[i] & 255;
  640. k1 = (k1 & 65535) * c1 + (((k1 >>> 16) * c1 & 65535) << 16) & 4294967295;
  641. k1 = k1 << 15 | k1 >>> 17;
  642. k1 = (k1 & 65535) * c2 + (((k1 >>> 16) * c2 & 65535) << 16) & 4294967295;
  643. h1 ^= k1;
  644. }
  645. }
  646. h1 ^= key.length;
  647. h1 ^= h1 >>> 16;
  648. h1 = (h1 & 65535) * 2246822507 + (((h1 >>> 16) * 2246822507 & 65535) << 16) & 4294967295;
  649. h1 ^= h1 >>> 13;
  650. h1 = (h1 & 65535) * 3266489909 + (((h1 >>> 16) * 3266489909 & 65535) << 16) & 4294967295;
  651. h1 ^= h1 >>> 16;
  652. return h1 >>> 0;
  653. }
  654. function createBuffer(val) {
  655. return new TextEncoder().encode(val);
  656. }
  657. function isEqual(object1, object2, hashOptions = {}) {
  658. if (object1 === object2) {
  659. return true;
  660. }
  661. if (objectHash(object1, hashOptions) === objectHash(object2, hashOptions)) {
  662. return true;
  663. }
  664. return false;
  665. }
  666. function diff(obj1, obj2, opts = {}) {
  667. const h1 = _toHashedObject(obj1, opts);
  668. const h2 = _toHashedObject(obj2, opts);
  669. return _diff(h1, h2, opts);
  670. }
  671. function _diff(h1, h2, opts = {}) {
  672. const diffs = [];
  673. const allProps = /* @__PURE__ */ new Set([
  674. ...Object.keys(h1.props || {}),
  675. ...Object.keys(h2.props || {})
  676. ]);
  677. if (h1.props && h2.props) {
  678. for (const prop of allProps) {
  679. const p1 = h1.props[prop];
  680. const p2 = h2.props[prop];
  681. if (p1 && p2) {
  682. diffs.push(..._diff(h1.props?.[prop], h2.props?.[prop], opts));
  683. } else if (p1 || p2) {
  684. diffs.push(
  685. new DiffEntry((p2 || p1).key, p1 ? "removed" : "added", p2, p1)
  686. );
  687. }
  688. }
  689. }
  690. if (allProps.size === 0 && h1.hash !== h2.hash) {
  691. diffs.push(new DiffEntry((h2 || h1).key, "changed", h2, h1));
  692. }
  693. return diffs;
  694. }
  695. function _toHashedObject(obj, opts, key = "") {
  696. if (obj && typeof obj !== "object") {
  697. return new DiffHashedObject(key, obj, objectHash(obj, opts));
  698. }
  699. const props = {};
  700. const hashes = [];
  701. for (const _key in obj) {
  702. props[_key] = _toHashedObject(
  703. obj[_key],
  704. opts,
  705. key ? `${key}.${_key}` : _key
  706. );
  707. hashes.push(props[_key].hash);
  708. }
  709. return new DiffHashedObject(key, obj, `{${hashes.join(":")}}`, props);
  710. }
  711. class DiffEntry {
  712. // eslint-disable-next-line no-useless-constructor
  713. constructor(key, type, newValue, oldValue) {
  714. this.key = key;
  715. this.type = type;
  716. this.newValue = newValue;
  717. this.oldValue = oldValue;
  718. }
  719. toString() {
  720. return this.toJSON();
  721. }
  722. toJSON() {
  723. switch (this.type) {
  724. case "added": {
  725. return `Added \`${this.key}\``;
  726. }
  727. case "removed": {
  728. return `Removed \`${this.key}\``;
  729. }
  730. case "changed": {
  731. return `Changed \`${this.key}\` from \`${this.oldValue?.toString() || "-"}\` to \`${this.newValue.toString()}\``;
  732. }
  733. }
  734. }
  735. }
  736. class DiffHashedObject {
  737. // eslint-disable-next-line no-useless-constructor
  738. constructor(key, value, hash, props) {
  739. this.key = key;
  740. this.value = value;
  741. this.hash = hash;
  742. this.props = props;
  743. }
  744. toString() {
  745. if (this.props) {
  746. return `{${Object.keys(this.props).join(",")}}`;
  747. } else {
  748. return JSON.stringify(this.value);
  749. }
  750. }
  751. toJSON() {
  752. const k = this.key || ".";
  753. if (this.props) {
  754. return `${k}({${Object.keys(this.props).join(",")}})`;
  755. }
  756. return `${k}(${this.value})`;
  757. }
  758. }
  759. exports.diff = diff;
  760. exports.hash = hash;
  761. exports.isEqual = isEqual;
  762. exports.murmurHash = murmurHash;
  763. exports.objectHash = objectHash;
  764. exports.sha256 = sha256;
  765. exports.sha256base64 = sha256base64;