@storyteller-platform/align 0.1.8 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/dist/align/__tests__/align.test.cjs +6 -5
  2. package/dist/align/__tests__/align.test.js +6 -5
  3. package/dist/align/align.cjs +133 -81
  4. package/dist/align/align.d.cts +1 -0
  5. package/dist/align/align.d.ts +1 -0
  6. package/dist/align/align.js +133 -81
  7. package/dist/align/getSentenceRanges.cjs +78 -149
  8. package/dist/align/getSentenceRanges.d.cts +1 -1
  9. package/dist/align/getSentenceRanges.d.ts +1 -1
  10. package/dist/align/getSentenceRanges.js +78 -149
  11. package/dist/align/slugify.cjs +2 -0
  12. package/dist/align/slugify.js +2 -0
  13. package/dist/errorAlign/__tests__/errorAlign.test.cjs +100 -0
  14. package/dist/errorAlign/__tests__/errorAlign.test.d.cts +2 -0
  15. package/dist/errorAlign/__tests__/errorAlign.test.d.ts +2 -0
  16. package/dist/errorAlign/__tests__/errorAlign.test.js +77 -0
  17. package/dist/errorAlign/__tests__/native.test.cjs +118 -0
  18. package/dist/errorAlign/__tests__/native.test.d.cts +2 -0
  19. package/dist/errorAlign/__tests__/native.test.d.ts +2 -0
  20. package/dist/errorAlign/__tests__/native.test.js +107 -0
  21. package/dist/errorAlign/backtraceGraph.cjs +298 -0
  22. package/dist/errorAlign/backtraceGraph.d.cts +103 -0
  23. package/dist/errorAlign/backtraceGraph.d.ts +103 -0
  24. package/dist/errorAlign/backtraceGraph.js +270 -0
  25. package/dist/errorAlign/beamSearch.cjs +302 -0
  26. package/dist/errorAlign/beamSearch.d.cts +53 -0
  27. package/dist/errorAlign/beamSearch.d.ts +53 -0
  28. package/dist/errorAlign/beamSearch.js +268 -0
  29. package/dist/errorAlign/core.cjs +33 -0
  30. package/dist/errorAlign/core.d.cts +5 -0
  31. package/dist/errorAlign/core.d.ts +5 -0
  32. package/dist/errorAlign/core.js +11 -0
  33. package/dist/errorAlign/editDistance.cjs +115 -0
  34. package/dist/errorAlign/editDistance.d.cts +46 -0
  35. package/dist/errorAlign/editDistance.d.ts +46 -0
  36. package/dist/errorAlign/editDistance.js +90 -0
  37. package/dist/errorAlign/errorAlign.cjs +159 -0
  38. package/dist/errorAlign/errorAlign.d.cts +15 -0
  39. package/dist/errorAlign/errorAlign.d.ts +15 -0
  40. package/dist/errorAlign/errorAlign.js +145 -0
  41. package/dist/errorAlign/graphMetadata.cjs +97 -0
  42. package/dist/errorAlign/graphMetadata.d.cts +44 -0
  43. package/dist/errorAlign/graphMetadata.d.ts +44 -0
  44. package/dist/errorAlign/graphMetadata.js +64 -0
  45. package/dist/errorAlign/hash.cjs +173 -0
  46. package/dist/errorAlign/hash.d.cts +28 -0
  47. package/dist/errorAlign/hash.d.ts +28 -0
  48. package/dist/errorAlign/hash.js +150 -0
  49. package/dist/errorAlign/native.cjs +60 -0
  50. package/dist/errorAlign/native.d.cts +18 -0
  51. package/dist/errorAlign/native.d.ts +18 -0
  52. package/dist/errorAlign/native.js +24 -0
  53. package/dist/errorAlign/node-gyp-build.d.cjs +1 -0
  54. package/dist/errorAlign/node-gyp-build.d.d.cts +3 -0
  55. package/dist/errorAlign/node-gyp-build.d.d.ts +3 -0
  56. package/dist/errorAlign/node-gyp-build.d.js +0 -0
  57. package/dist/errorAlign/pathToAlignment.cjs +122 -0
  58. package/dist/errorAlign/pathToAlignment.d.cts +11 -0
  59. package/dist/errorAlign/pathToAlignment.d.ts +11 -0
  60. package/dist/errorAlign/pathToAlignment.js +89 -0
  61. package/dist/errorAlign/utils.cjs +301 -0
  62. package/dist/errorAlign/utils.d.cts +107 -0
  63. package/dist/errorAlign/utils.d.ts +107 -0
  64. package/dist/errorAlign/utils.js +248 -0
  65. package/dist/index.d.cts +1 -0
  66. package/dist/index.d.ts +1 -0
  67. package/dist/markup/__tests__/markup.test.cjs +108 -81
  68. package/dist/markup/__tests__/markup.test.js +109 -82
  69. package/dist/markup/__tests__/parseDom.test.cjs +112 -0
  70. package/dist/markup/__tests__/parseDom.test.d.cts +2 -0
  71. package/dist/markup/__tests__/parseDom.test.d.ts +2 -0
  72. package/dist/markup/__tests__/parseDom.test.js +89 -0
  73. package/dist/markup/__tests__/serializeDom.test.cjs +120 -0
  74. package/dist/markup/__tests__/serializeDom.test.d.cts +2 -0
  75. package/dist/markup/__tests__/serializeDom.test.d.ts +2 -0
  76. package/dist/markup/__tests__/serializeDom.test.js +97 -0
  77. package/dist/markup/__tests__/transform.test.cjs +122 -0
  78. package/dist/markup/__tests__/transform.test.d.cts +2 -0
  79. package/dist/markup/__tests__/transform.test.d.ts +2 -0
  80. package/dist/markup/__tests__/transform.test.js +99 -0
  81. package/dist/markup/map.cjs +261 -0
  82. package/dist/markup/map.d.cts +50 -0
  83. package/dist/markup/map.d.ts +50 -0
  84. package/dist/markup/map.js +236 -0
  85. package/dist/markup/markup.cjs +23 -201
  86. package/dist/markup/markup.d.cts +5 -9
  87. package/dist/markup/markup.d.ts +5 -9
  88. package/dist/markup/markup.js +24 -203
  89. package/dist/markup/model.cjs +172 -0
  90. package/dist/markup/model.d.cts +57 -0
  91. package/dist/markup/model.d.ts +57 -0
  92. package/dist/markup/model.js +145 -0
  93. package/dist/markup/parseDom.cjs +59 -0
  94. package/dist/markup/parseDom.d.cts +7 -0
  95. package/dist/markup/parseDom.d.ts +7 -0
  96. package/dist/markup/parseDom.js +35 -0
  97. package/dist/markup/segmentation.cjs +11 -57
  98. package/dist/markup/segmentation.d.cts +6 -2
  99. package/dist/markup/segmentation.d.ts +6 -2
  100. package/dist/markup/segmentation.js +11 -58
  101. package/dist/markup/serializeDom.cjs +87 -0
  102. package/dist/markup/serializeDom.d.cts +7 -0
  103. package/dist/markup/serializeDom.d.ts +7 -0
  104. package/dist/markup/serializeDom.js +63 -0
  105. package/dist/markup/transform.cjs +92 -0
  106. package/dist/markup/transform.d.cts +11 -0
  107. package/dist/markup/transform.d.ts +11 -0
  108. package/dist/markup/transform.js +71 -0
  109. package/dist/types/node-gyp-build.d.cjs +1 -0
  110. package/dist/types/node-gyp-build.d.d.cts +3 -0
  111. package/dist/types/node-gyp-build.d.d.ts +3 -0
  112. package/dist/types/node-gyp-build.d.js +0 -0
  113. package/package.json +11 -4
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var hash_exports = {};
20
+ __export(hash_exports, {
21
+ hash: () => hash
22
+ });
23
+ module.exports = __toCommonJS(hash_exports);
24
+ const MODULUS = (1n << 61n) - 1n;
25
+ const UINT64_MASK = (1n << 64n) - 1n;
26
+ const HASH_INF = 314159;
27
+ const HASH_NAN = 0;
28
+ const XX_PRIME_1 = 11400714785074694791n;
29
+ const XX_PRIME_2 = 14029467366897019727n;
30
+ const XX_PRIME_5 = 2870177450012600261n;
31
+ function rotl64(v, s) {
32
+ return (v << s | v >> 64n - s) & UINT64_MASK;
33
+ }
34
+ function modpow(base, exp, mod) {
35
+ let result = 1n;
36
+ base %= mod;
37
+ while (exp > 0n) {
38
+ if (exp & 1n) result = result * base % mod;
39
+ base = base * base % mod;
40
+ exp >>= 1n;
41
+ }
42
+ return result;
43
+ }
44
+ function hashBigInt(n) {
45
+ const neg = n < 0n;
46
+ const x = (neg ? -n : n) % MODULUS;
47
+ const h = neg ? -Number(x) : Number(x);
48
+ return h === -1 ? -2 : h;
49
+ }
50
+ function hashFloat(x) {
51
+ if (isNaN(x)) return HASH_NAN;
52
+ if (!isFinite(x)) return x > 0 ? HASH_INF : -HASH_INF;
53
+ if (x === 0) return 0;
54
+ const buf = new ArrayBuffer(8);
55
+ const dv = new DataView(buf);
56
+ dv.setFloat64(0, x);
57
+ const hi = dv.getUint32(0);
58
+ const lo = dv.getUint32(4);
59
+ const sign = hi >>> 31 ? -1 : 1;
60
+ const biasedExp = hi >>> 20 & 2047;
61
+ const mantHi = hi & 1048575;
62
+ let m;
63
+ let e;
64
+ if (biasedExp === 0) {
65
+ m = BigInt(mantHi) << 32n | BigInt(lo);
66
+ e = 1 - 1023 - 52;
67
+ } else {
68
+ m = 1n << 52n | BigInt(mantHi) << 32n | BigInt(lo);
69
+ e = biasedExp - 1023 - 52;
70
+ }
71
+ const eMod = (BigInt(e) % 61n + 61n) % 61n;
72
+ const h = m % MODULUS * modpow(2n, eMod, MODULUS) % MODULUS;
73
+ const r = sign * Number(h);
74
+ return r === -1 ? -2 : r;
75
+ }
76
+ function sipRound(v) {
77
+ v[0] = v[0] + v[1] & UINT64_MASK;
78
+ v[1] = rotl64(v[1], 13n) ^ v[0];
79
+ v[0] = rotl64(v[0], 32n);
80
+ v[2] = v[2] + v[3] & UINT64_MASK;
81
+ v[3] = rotl64(v[3], 16n) ^ v[2];
82
+ v[0] = v[0] + v[3] & UINT64_MASK;
83
+ v[3] = rotl64(v[3], 21n) ^ v[0];
84
+ v[2] = v[2] + v[1] & UINT64_MASK;
85
+ v[1] = rotl64(v[1], 17n) ^ v[2];
86
+ v[2] = rotl64(v[2], 32n);
87
+ }
88
+ function siphash13(bytes, k0 = 0n, k1 = 0n) {
89
+ const v = [
90
+ k0 ^ 0x736f6d6570736575n,
91
+ k1 ^ 0x646f72616e646f6dn,
92
+ k0 ^ 0x6c7967656e657261n,
93
+ k1 ^ 0x7465646279746573n
94
+ ];
95
+ const blocks = Math.floor(bytes.length / 8);
96
+ for (let i = 0; i < blocks; i++) {
97
+ let m = 0n;
98
+ for (let j = 0; j < 8; j++) m |= BigInt(bytes[i * 8 + j]) << BigInt(j * 8);
99
+ v[3] ^= m;
100
+ sipRound(v);
101
+ v[0] ^= m;
102
+ }
103
+ const rem = bytes.length % 8;
104
+ const base = blocks * 8;
105
+ let last = BigInt(bytes.length & 255) << 56n;
106
+ for (let i = 0; i < rem; i++)
107
+ last |= BigInt(bytes[base + i]) << BigInt(i * 8);
108
+ v[3] ^= last;
109
+ sipRound(v);
110
+ v[0] ^= last;
111
+ v[2] ^= 0xffn;
112
+ sipRound(v);
113
+ sipRound(v);
114
+ sipRound(v);
115
+ return (v[0] ^ v[1] ^ v[2] ^ v[3]) & UINT64_MASK;
116
+ }
117
+ function encodeString(s) {
118
+ const codePoints = [...s].map((c) => c.codePointAt(0));
119
+ const maxCp = codePoints.reduce((m, cp) => cp > m ? cp : m, 0);
120
+ if (maxCp <= 255) {
121
+ return new Uint8Array(codePoints);
122
+ }
123
+ const bpc = maxCp <= 65535 ? 2 : 4;
124
+ const buf = new Uint8Array(codePoints.length * bpc);
125
+ const dv = new DataView(buf.buffer);
126
+ codePoints.forEach((cp, i) => {
127
+ if (bpc === 2) dv.setUint16(
128
+ i * 2,
129
+ cp,
130
+ /*LE*/
131
+ true
132
+ );
133
+ else dv.setUint32(
134
+ i * 4,
135
+ cp,
136
+ /*LE*/
137
+ true
138
+ );
139
+ });
140
+ return buf;
141
+ }
142
+ function hashString(s) {
143
+ const raw = siphash13(encodeString(s));
144
+ const signed = raw > 0x7fffffffffffffffn ? Number(raw - (1n << 64n)) : Number(raw);
145
+ return signed === -1 ? -2 : signed;
146
+ }
147
+ function hashTuple(items) {
148
+ let acc = XX_PRIME_5;
149
+ for (const item of items) {
150
+ const h = hash(item);
151
+ const lane = h < 0 ? BigInt(h) + (1n << 64n) : BigInt(h);
152
+ acc = acc + lane * XX_PRIME_2 & UINT64_MASK;
153
+ acc = rotl64(acc, 31n);
154
+ acc = acc * XX_PRIME_1 & UINT64_MASK;
155
+ }
156
+ acc = acc + (BigInt(items.length) ^ (XX_PRIME_5 ^ 3527539n)) & UINT64_MASK;
157
+ if (acc === UINT64_MASK) return 1546275796;
158
+ const signed = acc > 0x7fffffffffffffffn ? Number(acc - (1n << 64n)) : Number(acc);
159
+ return signed === -1 ? -2 : signed;
160
+ }
161
+ function hash(value) {
162
+ if (typeof value === "boolean") return value ? 1 : 0;
163
+ if (typeof value === "number")
164
+ return Number.isInteger(value) ? hashBigInt(BigInt(value)) : hashFloat(value);
165
+ if (typeof value === "bigint") return hashBigInt(value);
166
+ if (typeof value === "string") return hashString(value);
167
+ if (Array.isArray(value)) return hashTuple(value);
168
+ throw new TypeError(`unhashable type: ${typeof value}`);
169
+ }
170
+ // Annotate the CommonJS export names for ESM import in node:
171
+ 0 && (module.exports = {
172
+ hash
173
+ });
@@ -0,0 +1,28 @@
1
+ /**
2
+ * TypeScript implementation of Python's built-in hash() function.
3
+ *
4
+ * Matches CPython for:
5
+ * • int / bigint — exact
6
+ * • float — exact
7
+ * • bool — exact (True → 1, False → 0)
8
+ * • str — exact when PYTHONHASHSEED=0; Python randomises by default
9
+ * • tuple — exact, CPython 3.8+ xxHash-based algorithm
10
+ * (pass a readonly array to represent a tuple)
11
+ *
12
+ * hash(None) is intentionally unsupported: Python derives it from object
13
+ * identity (memory address), which cannot be replicated portably.
14
+ */
15
+ type Hashable = number | bigint | string | boolean | readonly Hashable[];
16
+ /**
17
+ * Compute Python's `hash()` for the given value.
18
+ *
19
+ * Supports: `boolean`, `number` (int & float), `bigint`, `string`, and tuples
20
+ * (represented as `readonly` arrays).
21
+ *
22
+ * **String hashing** is deterministic only when `PYTHONHASHSEED=0`.
23
+ * Python randomises string hashes by default, so results will differ from a
24
+ * live Python session unless you `export PYTHONHASHSEED=0` before running it.
25
+ */
26
+ declare function hash(value: Hashable): number;
27
+
28
+ export { type Hashable, hash };
@@ -0,0 +1,28 @@
1
+ /**
2
+ * TypeScript implementation of Python's built-in hash() function.
3
+ *
4
+ * Matches CPython for:
5
+ * • int / bigint — exact
6
+ * • float — exact
7
+ * • bool — exact (True → 1, False → 0)
8
+ * • str — exact when PYTHONHASHSEED=0; Python randomises by default
9
+ * • tuple — exact, CPython 3.8+ xxHash-based algorithm
10
+ * (pass a readonly array to represent a tuple)
11
+ *
12
+ * hash(None) is intentionally unsupported: Python derives it from object
13
+ * identity (memory address), which cannot be replicated portably.
14
+ */
15
+ type Hashable = number | bigint | string | boolean | readonly Hashable[];
16
+ /**
17
+ * Compute Python's `hash()` for the given value.
18
+ *
19
+ * Supports: `boolean`, `number` (int & float), `bigint`, `string`, and tuples
20
+ * (represented as `readonly` arrays).
21
+ *
22
+ * **String hashing** is deterministic only when `PYTHONHASHSEED=0`.
23
+ * Python randomises string hashes by default, so results will differ from a
24
+ * live Python session unless you `export PYTHONHASHSEED=0` before running it.
25
+ */
26
+ declare function hash(value: Hashable): number;
27
+
28
+ export { type Hashable, hash };
@@ -0,0 +1,150 @@
1
+ import "../chunk-BIEQXUOY.js";
2
+ const MODULUS = (1n << 61n) - 1n;
3
+ const UINT64_MASK = (1n << 64n) - 1n;
4
+ const HASH_INF = 314159;
5
+ const HASH_NAN = 0;
6
+ const XX_PRIME_1 = 11400714785074694791n;
7
+ const XX_PRIME_2 = 14029467366897019727n;
8
+ const XX_PRIME_5 = 2870177450012600261n;
9
+ function rotl64(v, s) {
10
+ return (v << s | v >> 64n - s) & UINT64_MASK;
11
+ }
12
+ function modpow(base, exp, mod) {
13
+ let result = 1n;
14
+ base %= mod;
15
+ while (exp > 0n) {
16
+ if (exp & 1n) result = result * base % mod;
17
+ base = base * base % mod;
18
+ exp >>= 1n;
19
+ }
20
+ return result;
21
+ }
22
+ function hashBigInt(n) {
23
+ const neg = n < 0n;
24
+ const x = (neg ? -n : n) % MODULUS;
25
+ const h = neg ? -Number(x) : Number(x);
26
+ return h === -1 ? -2 : h;
27
+ }
28
+ function hashFloat(x) {
29
+ if (isNaN(x)) return HASH_NAN;
30
+ if (!isFinite(x)) return x > 0 ? HASH_INF : -HASH_INF;
31
+ if (x === 0) return 0;
32
+ const buf = new ArrayBuffer(8);
33
+ const dv = new DataView(buf);
34
+ dv.setFloat64(0, x);
35
+ const hi = dv.getUint32(0);
36
+ const lo = dv.getUint32(4);
37
+ const sign = hi >>> 31 ? -1 : 1;
38
+ const biasedExp = hi >>> 20 & 2047;
39
+ const mantHi = hi & 1048575;
40
+ let m;
41
+ let e;
42
+ if (biasedExp === 0) {
43
+ m = BigInt(mantHi) << 32n | BigInt(lo);
44
+ e = 1 - 1023 - 52;
45
+ } else {
46
+ m = 1n << 52n | BigInt(mantHi) << 32n | BigInt(lo);
47
+ e = biasedExp - 1023 - 52;
48
+ }
49
+ const eMod = (BigInt(e) % 61n + 61n) % 61n;
50
+ const h = m % MODULUS * modpow(2n, eMod, MODULUS) % MODULUS;
51
+ const r = sign * Number(h);
52
+ return r === -1 ? -2 : r;
53
+ }
54
+ function sipRound(v) {
55
+ v[0] = v[0] + v[1] & UINT64_MASK;
56
+ v[1] = rotl64(v[1], 13n) ^ v[0];
57
+ v[0] = rotl64(v[0], 32n);
58
+ v[2] = v[2] + v[3] & UINT64_MASK;
59
+ v[3] = rotl64(v[3], 16n) ^ v[2];
60
+ v[0] = v[0] + v[3] & UINT64_MASK;
61
+ v[3] = rotl64(v[3], 21n) ^ v[0];
62
+ v[2] = v[2] + v[1] & UINT64_MASK;
63
+ v[1] = rotl64(v[1], 17n) ^ v[2];
64
+ v[2] = rotl64(v[2], 32n);
65
+ }
66
+ function siphash13(bytes, k0 = 0n, k1 = 0n) {
67
+ const v = [
68
+ k0 ^ 0x736f6d6570736575n,
69
+ k1 ^ 0x646f72616e646f6dn,
70
+ k0 ^ 0x6c7967656e657261n,
71
+ k1 ^ 0x7465646279746573n
72
+ ];
73
+ const blocks = Math.floor(bytes.length / 8);
74
+ for (let i = 0; i < blocks; i++) {
75
+ let m = 0n;
76
+ for (let j = 0; j < 8; j++) m |= BigInt(bytes[i * 8 + j]) << BigInt(j * 8);
77
+ v[3] ^= m;
78
+ sipRound(v);
79
+ v[0] ^= m;
80
+ }
81
+ const rem = bytes.length % 8;
82
+ const base = blocks * 8;
83
+ let last = BigInt(bytes.length & 255) << 56n;
84
+ for (let i = 0; i < rem; i++)
85
+ last |= BigInt(bytes[base + i]) << BigInt(i * 8);
86
+ v[3] ^= last;
87
+ sipRound(v);
88
+ v[0] ^= last;
89
+ v[2] ^= 0xffn;
90
+ sipRound(v);
91
+ sipRound(v);
92
+ sipRound(v);
93
+ return (v[0] ^ v[1] ^ v[2] ^ v[3]) & UINT64_MASK;
94
+ }
95
+ function encodeString(s) {
96
+ const codePoints = [...s].map((c) => c.codePointAt(0));
97
+ const maxCp = codePoints.reduce((m, cp) => cp > m ? cp : m, 0);
98
+ if (maxCp <= 255) {
99
+ return new Uint8Array(codePoints);
100
+ }
101
+ const bpc = maxCp <= 65535 ? 2 : 4;
102
+ const buf = new Uint8Array(codePoints.length * bpc);
103
+ const dv = new DataView(buf.buffer);
104
+ codePoints.forEach((cp, i) => {
105
+ if (bpc === 2) dv.setUint16(
106
+ i * 2,
107
+ cp,
108
+ /*LE*/
109
+ true
110
+ );
111
+ else dv.setUint32(
112
+ i * 4,
113
+ cp,
114
+ /*LE*/
115
+ true
116
+ );
117
+ });
118
+ return buf;
119
+ }
120
+ function hashString(s) {
121
+ const raw = siphash13(encodeString(s));
122
+ const signed = raw > 0x7fffffffffffffffn ? Number(raw - (1n << 64n)) : Number(raw);
123
+ return signed === -1 ? -2 : signed;
124
+ }
125
+ function hashTuple(items) {
126
+ let acc = XX_PRIME_5;
127
+ for (const item of items) {
128
+ const h = hash(item);
129
+ const lane = h < 0 ? BigInt(h) + (1n << 64n) : BigInt(h);
130
+ acc = acc + lane * XX_PRIME_2 & UINT64_MASK;
131
+ acc = rotl64(acc, 31n);
132
+ acc = acc * XX_PRIME_1 & UINT64_MASK;
133
+ }
134
+ acc = acc + (BigInt(items.length) ^ (XX_PRIME_5 ^ 3527539n)) & UINT64_MASK;
135
+ if (acc === UINT64_MASK) return 1546275796;
136
+ const signed = acc > 0x7fffffffffffffffn ? Number(acc - (1n << 64n)) : Number(acc);
137
+ return signed === -1 ? -2 : signed;
138
+ }
139
+ function hash(value) {
140
+ if (typeof value === "boolean") return value ? 1 : 0;
141
+ if (typeof value === "number")
142
+ return Number.isInteger(value) ? hashBigInt(BigInt(value)) : hashFloat(value);
143
+ if (typeof value === "bigint") return hashBigInt(value);
144
+ if (typeof value === "string") return hashString(value);
145
+ if (Array.isArray(value)) return hashTuple(value);
146
+ throw new TypeError(`unhashable type: ${typeof value}`);
147
+ }
148
+ export {
149
+ hash
150
+ };
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var native_exports = {};
30
+ __export(native_exports, {
31
+ computeErrorAlignDistanceMatrix: () => computeErrorAlignDistanceMatrix,
32
+ computeLevenshteinDistanceMatrix: () => computeLevenshteinDistanceMatrix,
33
+ errorAlignBeamSearch: () => errorAlignBeamSearch
34
+ });
35
+ module.exports = __toCommonJS(native_exports);
36
+ var import_node_path = require("node:path");
37
+ var import_node_gyp_build = __toESM(require("node-gyp-build"), 1);
38
+ var import_beamSearch = require("./beamSearch.cjs");
39
+ const import_meta = {};
40
+ const native = (0, import_node_gyp_build.default)(
41
+ process.env["ERROR_ALIGN_NATIVE_BINDING"] || (0, import_node_path.resolve)(import_meta.dirname, "../../")
42
+ );
43
+ function computeLevenshteinDistanceMatrix(ref, hyp, backtrace = false) {
44
+ return native.computeLevenshteinDistanceMatrix(ref, hyp, backtrace);
45
+ }
46
+ function computeErrorAlignDistanceMatrix(ref, hyp, backtrace = false) {
47
+ return native.computeErrorAlignDistanceMatrix(ref, hyp, backtrace);
48
+ }
49
+ function errorAlignBeamSearch(src, beamSize = 100) {
50
+ const endIndices = native.errorAlignBeamSearch(src, beamSize);
51
+ const path = new import_beamSearch.Path(src);
52
+ path.endIndices = endIndices;
53
+ return path;
54
+ }
55
+ // Annotate the CommonJS export names for ESM import in node:
56
+ 0 && (module.exports = {
57
+ computeErrorAlignDistanceMatrix,
58
+ computeLevenshteinDistanceMatrix,
59
+ errorAlignBeamSearch
60
+ });
@@ -0,0 +1,18 @@
1
+ import { Path } from './beamSearch.cjs';
2
+ import { SubgraphMetadata } from './graphMetadata.cjs';
3
+ import './backtraceGraph.cjs';
4
+ import './utils.cjs';
5
+
6
+ declare function computeLevenshteinDistanceMatrix(ref: string | string[], hyp: string | string[]): number[][];
7
+ declare function computeLevenshteinDistanceMatrix(ref: string | string[], hyp: string | string[], backtrace: true): {
8
+ scoreMatrix: number[][];
9
+ backtraceMatrix: number[][];
10
+ };
11
+ declare function computeErrorAlignDistanceMatrix(ref: string | string[], hyp: string | string[]): number[][];
12
+ declare function computeErrorAlignDistanceMatrix(ref: string | string[], hyp: string | string[], backtrace: true): {
13
+ scoreMatrix: number[][];
14
+ backtraceMatrix: number[][];
15
+ };
16
+ declare function errorAlignBeamSearch(src: SubgraphMetadata, beamSize?: number): Path;
17
+
18
+ export { computeErrorAlignDistanceMatrix, computeLevenshteinDistanceMatrix, errorAlignBeamSearch };
@@ -0,0 +1,18 @@
1
+ import { Path } from './beamSearch.js';
2
+ import { SubgraphMetadata } from './graphMetadata.js';
3
+ import './backtraceGraph.js';
4
+ import './utils.js';
5
+
6
+ declare function computeLevenshteinDistanceMatrix(ref: string | string[], hyp: string | string[]): number[][];
7
+ declare function computeLevenshteinDistanceMatrix(ref: string | string[], hyp: string | string[], backtrace: true): {
8
+ scoreMatrix: number[][];
9
+ backtraceMatrix: number[][];
10
+ };
11
+ declare function computeErrorAlignDistanceMatrix(ref: string | string[], hyp: string | string[]): number[][];
12
+ declare function computeErrorAlignDistanceMatrix(ref: string | string[], hyp: string | string[], backtrace: true): {
13
+ scoreMatrix: number[][];
14
+ backtraceMatrix: number[][];
15
+ };
16
+ declare function errorAlignBeamSearch(src: SubgraphMetadata, beamSize?: number): Path;
17
+
18
+ export { computeErrorAlignDistanceMatrix, computeLevenshteinDistanceMatrix, errorAlignBeamSearch };
@@ -0,0 +1,24 @@
1
+ import "../chunk-BIEQXUOY.js";
2
+ import { resolve } from "node:path";
3
+ import requireBinding from "node-gyp-build";
4
+ import { Path } from "./beamSearch.js";
5
+ const native = requireBinding(
6
+ process.env["ERROR_ALIGN_NATIVE_BINDING"] || resolve(import.meta.dirname, "../../")
7
+ );
8
+ function computeLevenshteinDistanceMatrix(ref, hyp, backtrace = false) {
9
+ return native.computeLevenshteinDistanceMatrix(ref, hyp, backtrace);
10
+ }
11
+ function computeErrorAlignDistanceMatrix(ref, hyp, backtrace = false) {
12
+ return native.computeErrorAlignDistanceMatrix(ref, hyp, backtrace);
13
+ }
14
+ function errorAlignBeamSearch(src, beamSize = 100) {
15
+ const endIndices = native.errorAlignBeamSearch(src, beamSize);
16
+ const path = new Path(src);
17
+ path.endIndices = endIndices;
18
+ return path;
19
+ }
20
+ export {
21
+ computeErrorAlignDistanceMatrix,
22
+ computeLevenshteinDistanceMatrix,
23
+ errorAlignBeamSearch
24
+ };
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,3 @@
1
+ declare module "node-gyp-build" {
2
+ export default function requireBinding(dirname: string): unknown
3
+ }
@@ -0,0 +1,3 @@
1
+ declare module "node-gyp-build" {
2
+ export default function requireBinding(dirname: string): unknown
3
+ }
File without changes
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var pathToAlignment_exports = {};
30
+ __export(pathToAlignment_exports, {
31
+ getAlignments: () => getAlignments
32
+ });
33
+ module.exports = __toCommonJS(pathToAlignment_exports);
34
+ var import_node_assert = __toESM(require("node:assert"), 1);
35
+ var import_utils = require("./utils.cjs");
36
+ function getDeleteAlignment(startRefIndex, endRefIndex, subgraphMetadata) {
37
+ const refSlice = (0, import_utils.translateSlice)(
38
+ [startRefIndex, endRefIndex],
39
+ subgraphMetadata.refIndexMap
40
+ );
41
+ (0, import_node_assert.default)(!!refSlice);
42
+ return new import_utils.Alignment(
43
+ "DELETE",
44
+ refSlice,
45
+ null,
46
+ subgraphMetadata.refRaw.slice(...refSlice)
47
+ );
48
+ }
49
+ function getInsertAlignment(startHypIndex, endHypIndex, subgraphMetadata) {
50
+ const hypSlice = (0, import_utils.translateSlice)(
51
+ [startHypIndex, endHypIndex],
52
+ subgraphMetadata.hypIndexMap
53
+ );
54
+ (0, import_node_assert.default)(!!hypSlice);
55
+ return new import_utils.Alignment(
56
+ "INSERT",
57
+ null,
58
+ hypSlice,
59
+ null,
60
+ subgraphMetadata.hypRaw.slice(...hypSlice),
61
+ subgraphMetadata.hypIndexMap[startHypIndex] >= 0,
62
+ subgraphMetadata.hypIndexMap[endHypIndex - 1] >= 0
63
+ );
64
+ }
65
+ function getMatchOrSubstitutionAlignment(startHypIndex, endHypIndex, startRefIndex, endRefIndex, score, subgraphMetadata) {
66
+ const hypSlice = (0, import_utils.translateSlice)(
67
+ [startHypIndex, endHypIndex],
68
+ subgraphMetadata.hypIndexMap
69
+ );
70
+ const refSlice = (0, import_utils.translateSlice)(
71
+ [startRefIndex, endRefIndex],
72
+ subgraphMetadata.refIndexMap
73
+ );
74
+ (0, import_node_assert.default)(!!hypSlice);
75
+ (0, import_node_assert.default)(!!refSlice);
76
+ const isMatchSegment = score === 0;
77
+ const opType = isMatchSegment ? "MATCH" : "SUBSTITUTE";
78
+ return new import_utils.Alignment(
79
+ opType,
80
+ refSlice,
81
+ hypSlice,
82
+ subgraphMetadata.refRaw.slice(...refSlice),
83
+ subgraphMetadata.hypRaw.slice(...hypSlice),
84
+ subgraphMetadata.hypIndexMap[startHypIndex] >= 0,
85
+ subgraphMetadata.hypIndexMap[endHypIndex - 1] >= 0
86
+ );
87
+ }
88
+ function getAlignments(path) {
89
+ const subgraphMetadata = path.src;
90
+ const segmentationIndices = path.endIndices;
91
+ const alignments = [];
92
+ let startHyp = 0;
93
+ let startRef = 0;
94
+ for (let [endHyp, endRef, score] of segmentationIndices) {
95
+ endHyp += 1;
96
+ endRef += 1;
97
+ if (startHyp === endHyp) {
98
+ const alignment = getDeleteAlignment(startRef, endRef, subgraphMetadata);
99
+ alignments.push(alignment);
100
+ } else if (startRef === endRef) {
101
+ const alignment = getInsertAlignment(startHyp, endHyp, subgraphMetadata);
102
+ alignments.push(alignment);
103
+ } else {
104
+ const alignment = getMatchOrSubstitutionAlignment(
105
+ startHyp,
106
+ endHyp,
107
+ startRef,
108
+ endRef,
109
+ score,
110
+ subgraphMetadata
111
+ );
112
+ alignments.push(alignment);
113
+ }
114
+ startHyp = endHyp;
115
+ startRef = endRef;
116
+ }
117
+ return alignments;
118
+ }
119
+ // Annotate the CommonJS export names for ESM import in node:
120
+ 0 && (module.exports = {
121
+ getAlignments
122
+ });
@@ -0,0 +1,11 @@
1
+ import { Path } from './beamSearch.cjs';
2
+ import { Alignment } from './utils.cjs';
3
+ import './backtraceGraph.cjs';
4
+ import './graphMetadata.cjs';
5
+
6
+ /**
7
+ * Get the alignments of the path.
8
+ */
9
+ declare function getAlignments(path: Path): Alignment[];
10
+
11
+ export { getAlignments };
@@ -0,0 +1,11 @@
1
+ import { Path } from './beamSearch.js';
2
+ import { Alignment } from './utils.js';
3
+ import './backtraceGraph.js';
4
+ import './graphMetadata.js';
5
+
6
+ /**
7
+ * Get the alignments of the path.
8
+ */
9
+ declare function getAlignments(path: Path): Alignment[];
10
+
11
+ export { getAlignments };