limn-hl 0.1.1 → 0.2.1

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 (73) hide show
  1. package/README.md +105 -174
  2. package/dist/detect.d.ts +7 -1
  3. package/dist/detect.js +657 -499
  4. package/dist/engine.js +45 -1
  5. package/dist/generated/detect.d.ts +8 -0
  6. package/dist/generated/detect.js +31 -0
  7. package/dist/generated/grammars.d.ts +119 -0
  8. package/dist/generated/grammars.js +628 -0
  9. package/dist/generated/lang.d.ts +6 -0
  10. package/dist/{lang/index.js → generated/lang.js} +82 -56
  11. package/dist/{theme/generated.d.ts → generated/themes.d.ts} +1 -1
  12. package/dist/lang.d.ts +1 -0
  13. package/dist/lang.js +1 -0
  14. package/dist/render/ansi.d.ts +1 -1
  15. package/dist/render/html.d.ts +1 -1
  16. package/dist/{theme/index.d.ts → theme.d.ts} +1 -1
  17. package/dist/theme.js +1 -0
  18. package/dist/vm/compile.d.ts +4 -0
  19. package/dist/vm/compile.js +393 -0
  20. package/dist/vm/exec.d.ts +3 -0
  21. package/dist/vm/exec.js +218 -0
  22. package/dist/vm/format.d.ts +260 -0
  23. package/dist/vm/format.js +251 -0
  24. package/dist/vm/index.d.ts +2 -0
  25. package/dist/vm/index.js +2 -0
  26. package/dist/vm/pat.d.ts +4 -0
  27. package/dist/vm/pat.js +816 -0
  28. package/dist/vm/quoted.d.ts +8 -0
  29. package/dist/vm/quoted.js +232 -0
  30. package/dist/vm/scan.d.ts +3 -0
  31. package/dist/vm/scan.js +499 -0
  32. package/dist/wordtable.d.ts +8 -4
  33. package/dist/wordtable.js +107 -30
  34. package/package.json +6 -6
  35. package/dist/lang/clike.d.ts +0 -15
  36. package/dist/lang/clike.js +0 -35
  37. package/dist/lang/clike_helpers.d.ts +0 -8
  38. package/dist/lang/clike_helpers.js +0 -220
  39. package/dist/lang/code.d.ts +0 -45
  40. package/dist/lang/code.js +0 -779
  41. package/dist/lang/config.d.ts +0 -5
  42. package/dist/lang/config.js +0 -164
  43. package/dist/lang/css.d.ts +0 -5
  44. package/dist/lang/css.js +0 -125
  45. package/dist/lang/docs.d.ts +0 -12
  46. package/dist/lang/docs.js +0 -462
  47. package/dist/lang/formats.d.ts +0 -10
  48. package/dist/lang/formats.js +0 -295
  49. package/dist/lang/html.d.ts +0 -11
  50. package/dist/lang/html.js +0 -298
  51. package/dist/lang/index.d.ts +0 -20
  52. package/dist/lang/js.d.ts +0 -9
  53. package/dist/lang/js.js +0 -532
  54. package/dist/lang/js_helpers.d.ts +0 -7
  55. package/dist/lang/js_helpers.js +0 -308
  56. package/dist/lang/json.d.ts +0 -3
  57. package/dist/lang/json.js +0 -136
  58. package/dist/lang/markdown.d.ts +0 -3
  59. package/dist/lang/markdown.js +0 -249
  60. package/dist/lang/python.d.ts +0 -3
  61. package/dist/lang/python.js +0 -335
  62. package/dist/lang/scripting.d.ts +0 -7
  63. package/dist/lang/scripting.js +0 -216
  64. package/dist/lang/shell.d.ts +0 -7
  65. package/dist/lang/shell.js +0 -404
  66. package/dist/lang/specs_gen.d.ts +0 -66
  67. package/dist/lang/specs_gen.js +0 -381
  68. package/dist/lang/terminal.d.ts +0 -9
  69. package/dist/lang/terminal.js +0 -550
  70. package/dist/lang/yaml.d.ts +0 -4
  71. package/dist/lang/yaml.js +0 -176
  72. package/dist/theme/index.js +0 -1
  73. /package/dist/{theme/generated.js → generated/themes.js} +0 -0
package/dist/detect.js CHANGED
@@ -1,565 +1,723 @@
1
- const DETECT_MAX_BYTES = 4096;
1
+ import {
2
+ DETECT_BLOB_B64,
3
+ DETECT_FEAT_COUNT,
4
+ DETECT_LANG_BIAS,
5
+ DETECT_LANG_COUNT,
6
+ DETECT_LANG_NAMES,
7
+ DETECT_MAX_BYTES,
8
+ DETECT_PREFIXES,
9
+ DETECT_SHEBANGS
10
+ } from "./generated/detect.js";
11
+ const utf8Buf = new Uint8Array(DETECT_MAX_BYTES + 4);
12
+ const scoresBuf = new Int32Array(DETECT_LANG_COUNT);
13
+ const seenBuf = new Uint32Array(DETECT_FEAT_COUNT + 31 >>> 5);
14
+ const FNV32_OFFSET = 2166136261;
15
+ function fnv32Str(h, s) {
16
+ for (let i = 0;i < s.length; i++) {
17
+ h = Math.imul(h ^ s.charCodeAt(i) & 255, 16777619);
18
+ }
19
+ return h >>> 0;
20
+ }
21
+ function fnv32Bytes(h, b, start, end) {
22
+ for (let i = start;i < end; i++) {
23
+ h = Math.imul(h ^ b[i], 16777619);
24
+ }
25
+ return h >>> 0;
26
+ }
27
+ function fnv32Byte(h, c) {
28
+ return Math.imul(h ^ c, 16777619) >>> 0;
29
+ }
30
+ const H_W = fnv32Str(FNV32_OFFSET, "W:");
31
+ const H_WA = fnv32Str(FNV32_OFFSET, "WA:");
32
+ const H_LW = fnv32Str(FNV32_OFFSET, "LW:");
33
+ const H_LW2 = fnv32Str(FNV32_OFFSET, "LW2:");
34
+ const H_LP = fnv32Str(FNV32_OFFSET, "LP:");
35
+ const H_P = fnv32Str(FNV32_OFFSET, "P:");
36
+ const H_S = fnv32Str(FNV32_OFFSET, "S:");
37
+ const H_T = fnv32Str(FNV32_OFFSET, "T:");
38
+ function decodeBase64(s) {
39
+ let len = s.length;
40
+ let pad = 0;
41
+ if (len > 0 && s.charCodeAt(len - 1) === 61)
42
+ pad++;
43
+ if (len > 1 && s.charCodeAt(len - 2) === 61)
44
+ pad++;
45
+ const out = new Uint8Array((len * 3 >>> 2) - pad);
46
+ const val = (c) => {
47
+ if (c >= 65 && c <= 90)
48
+ return c - 65;
49
+ if (c >= 97 && c <= 122)
50
+ return c - 71;
51
+ if (c >= 48 && c <= 57)
52
+ return c + 4;
53
+ if (c === 43)
54
+ return 62;
55
+ if (c === 47)
56
+ return 63;
57
+ return 0;
58
+ };
59
+ let o = 0;
60
+ for (let i = 0;i < len; i += 4) {
61
+ const a = val(s.charCodeAt(i));
62
+ const b0 = val(s.charCodeAt(i + 1));
63
+ const c = val(s.charCodeAt(i + 2));
64
+ const d = val(s.charCodeAt(i + 3));
65
+ const tri = a << 18 | b0 << 12 | c << 6 | d;
66
+ out[o++] = tri >>> 16 & 255;
67
+ if (o < out.length)
68
+ out[o++] = tri >>> 8 & 255;
69
+ if (o < out.length)
70
+ out[o++] = tri & 255;
71
+ }
72
+ return out;
73
+ }
74
+ let cachedTable = null;
75
+ function ensureTable() {
76
+ if (cachedTable !== null)
77
+ return cachedTable;
78
+ const raw = decodeBase64(DETECT_BLOB_B64);
79
+ const view = new DataView(raw.buffer, raw.byteOffset, raw.byteLength);
80
+ const n = DETECT_FEAT_COUNT;
81
+ const hashes = new Uint32Array(n);
82
+ const offs = new Uint16Array(n);
83
+ for (let i = 0;i < n; i++) {
84
+ hashes[i] = view.getUint32(i * 4, true);
85
+ offs[i] = view.getUint16(n * 4 + i * 2, true);
86
+ }
87
+ const cnts = raw.subarray(n * 6, n * 7);
88
+ const entries = raw.subarray(n * 7);
89
+ cachedTable = { hashes, offs, cnts, entries };
90
+ return cachedTable;
91
+ }
92
+ function encodeUTF8Prefix(src, out, limit) {
93
+ let w = 0;
94
+ const len = src.length;
95
+ for (let i = 0;i < len && w < limit; i++) {
96
+ let cp = src.charCodeAt(i);
97
+ if (cp < 128) {
98
+ out[w++] = cp;
99
+ } else if (cp < 2048) {
100
+ out[w++] = 192 | cp >> 6;
101
+ out[w++] = 128 | cp & 63;
102
+ } else if (cp >= 55296 && cp <= 56319 && i + 1 < len) {
103
+ const lo = src.charCodeAt(i + 1);
104
+ if (lo >= 56320 && lo <= 57343) {
105
+ i++;
106
+ cp = 65536 + (cp - 55296 << 10) + (lo - 56320);
107
+ out[w++] = 240 | cp >> 18;
108
+ out[w++] = 128 | cp >> 12 & 63;
109
+ out[w++] = 128 | cp >> 6 & 63;
110
+ out[w++] = 128 | cp & 63;
111
+ } else {
112
+ out[w++] = 239;
113
+ out[w++] = 191;
114
+ out[w++] = 189;
115
+ }
116
+ } else {
117
+ out[w++] = 224 | cp >> 12;
118
+ out[w++] = 128 | cp >> 6 & 63;
119
+ out[w++] = 128 | cp & 63;
120
+ }
121
+ }
122
+ return w < limit ? w : limit;
123
+ }
124
+ function isASCIIWS(c) {
125
+ return c === 32 || c === 9 || c === 10 || c === 13;
126
+ }
127
+ function isAlpha(c) {
128
+ return c >= 65 && c <= 90 || c >= 97 && c <= 122;
129
+ }
130
+ function isDigit(c) {
131
+ return c >= 48 && c <= 57;
132
+ }
2
133
  function isIdentStart(c) {
3
- return c >= 97 && c <= 122 || c >= 65 && c <= 90 || c === 95 || c >= 128;
134
+ return isAlpha(c) || c === 95;
4
135
  }
5
136
  function isIdentCont(c) {
6
- return c >= 97 && c <= 122 || c >= 65 && c <= 90 || c >= 48 && c <= 57 || c === 95 || c >= 128;
137
+ return isAlpha(c) || isDigit(c) || c === 95;
7
138
  }
8
- function hasPrefixFold(s, prefix) {
9
- if (s.length < prefix.length) {
10
- return false;
139
+ function indexOfByte(b, needle, from, to) {
140
+ for (let i = from;i < to; i++) {
141
+ if (b[i] === needle)
142
+ return i;
11
143
  }
144
+ return -1;
145
+ }
146
+ function startsWithASCII(b, from, to, prefix, fold) {
147
+ if (to - from < prefix.length)
148
+ return false;
12
149
  for (let i = 0;i < prefix.length; i++) {
13
- let a = s.charCodeAt(i);
14
- let b = prefix.charCodeAt(i);
15
- if (a >= 65 && a <= 90)
16
- a += 32;
17
- if (b >= 65 && b <= 90)
18
- b += 32;
19
- if (a !== b) {
20
- return false;
150
+ let a = b[from + i];
151
+ let p = prefix.charCodeAt(i);
152
+ if (fold) {
153
+ if (a >= 65 && a <= 90)
154
+ a += 32;
155
+ if (p >= 65 && p <= 90)
156
+ p += 32;
21
157
  }
158
+ if (a !== p)
159
+ return false;
22
160
  }
23
161
  return true;
24
162
  }
25
- const HTTP_METHODS = [
26
- "GET ",
27
- "POST ",
28
- "PUT ",
29
- "DELETE ",
30
- "PATCH ",
31
- "HEAD ",
32
- "OPTIONS ",
33
- "HTTP/"
34
- ];
35
- function startsWithHTTPMethod(s) {
36
- for (const m of HTTP_METHODS) {
37
- if (s.startsWith(m)) {
163
+ function containsASCII(b, from, to, needle) {
164
+ const nl = needle.length;
165
+ if (nl === 0)
166
+ return true;
167
+ const limit = to - nl;
168
+ const first = needle.charCodeAt(0);
169
+ outer:
170
+ for (let i = from;i <= limit; i++) {
171
+ if (b[i] !== first)
172
+ continue;
173
+ for (let j = 1;j < nl; j++) {
174
+ if (b[i + j] !== needle.charCodeAt(j))
175
+ continue outer;
176
+ }
38
177
  return true;
39
178
  }
40
- }
41
179
  return false;
42
180
  }
43
- function isSimpleKey(s) {
44
- if (s === "") {
45
- return false;
46
- }
47
- for (let i = 0;i < s.length; i++) {
48
- const ch = s.charCodeAt(i);
49
- if (isIdentCont(ch) || ch === 45 || ch === 46) {
50
- continue;
181
+ function checkFastPrefix(b, n) {
182
+ let ts = 0;
183
+ while (ts < n && isASCIIWS(b[ts]))
184
+ ts++;
185
+ let te = n;
186
+ while (te > ts && isASCIIWS(b[te - 1]))
187
+ te--;
188
+ if (ts >= te)
189
+ return "plain";
190
+ if (te - ts >= 2 && b[ts] === 35 && b[ts + 1] === 33) {
191
+ const nl = indexOfByte(b, 10, ts, te);
192
+ const le = nl >= 0 ? nl : te;
193
+ for (let i = 0;i < DETECT_SHEBANGS.length; i++) {
194
+ const r = DETECT_SHEBANGS[i];
195
+ if (containsASCII(b, ts, le, r[0]))
196
+ return r[1];
51
197
  }
52
- return false;
53
198
  }
54
- return true;
199
+ for (let i = 0;i < DETECT_PREFIXES.length; i++) {
200
+ const r = DETECT_PREFIXES[i];
201
+ if (startsWithASCII(b, ts, te, r[0], r[2]))
202
+ return r[1];
203
+ }
204
+ return "";
55
205
  }
56
- var L;
57
- ((L) => {
58
- L[L["Go"] = 0] = "Go";
59
- L[L["JS"] = 1] = "JS";
60
- L[L["TS"] = 2] = "TS";
61
- L[L["JSX"] = 3] = "JSX";
62
- L[L["TSX"] = 4] = "TSX";
63
- L[L["Py"] = 5] = "Py";
64
- L[L["Rs"] = 6] = "Rs";
65
- L[L["C"] = 7] = "C";
66
- L[L["CPP"] = 8] = "CPP";
67
- L[L["CS"] = 9] = "CS";
68
- L[L["Java"] = 10] = "Java";
69
- L[L["Kt"] = 11] = "Kt";
70
- L[L["Swift"] = 12] = "Swift";
71
- L[L["Zig"] = 13] = "Zig";
72
- L[L["Dart"] = 14] = "Dart";
73
- L[L["PHP"] = 15] = "PHP";
74
- L[L["SQL"] = 16] = "SQL";
75
- L[L["Rb"] = 17] = "Rb";
76
- L[L["Lua"] = 18] = "Lua";
77
- L[L["Nix"] = 19] = "Nix";
78
- L[L["JSON"] = 20] = "JSON";
79
- L[L["YAML"] = 21] = "YAML";
80
- L[L["TOML"] = 22] = "TOML";
81
- L[L["INI"] = 23] = "INI";
82
- L[L["HTML"] = 24] = "HTML";
83
- L[L["XML"] = 25] = "XML";
84
- L[L["CSS"] = 26] = "CSS";
85
- L[L["SCSS"] = 27] = "SCSS";
86
- L[L["Vue"] = 28] = "Vue";
87
- L[L["Svelte"] = 29] = "Svelte";
88
- L[L["Astro"] = 30] = "Astro";
89
- L[L["MD"] = 31] = "MD";
90
- L[L["Bash"] = 32] = "Bash";
91
- L[L["Docker"] = 33] = "Docker";
92
- L[L["Make"] = 34] = "Make";
93
- L[L["Diff"] = 35] = "Diff";
94
- L[L["Count"] = 36] = "Count";
95
- })(L ||= {});
96
- const NAMES = [
97
- "go",
98
- "js",
99
- "ts",
100
- "jsx",
101
- "tsx",
102
- "py",
103
- "rs",
104
- "c",
105
- "cpp",
106
- "cs",
107
- "java",
108
- "kt",
109
- "swift",
110
- "zig",
111
- "dart",
112
- "php",
113
- "sql",
114
- "rb",
115
- "lua",
116
- "nix",
117
- "json",
118
- "yaml",
119
- "toml",
120
- "ini",
121
- "html",
122
- "xml",
123
- "css",
124
- "scss",
125
- "vue",
126
- "svelte",
127
- "astro",
128
- "md",
129
- "bash",
130
- "docker",
131
- "make",
132
- "diff"
133
- ];
134
- export function detect(src) {
135
- if (src.length > DETECT_MAX_BYTES) {
136
- src = src.slice(0, DETECT_MAX_BYTES);
206
+ function isqrtInt(x) {
207
+ if (x <= 0)
208
+ return 0;
209
+ let r = Math.floor(Math.sqrt(x));
210
+ while ((r + 1) * (r + 1) <= x)
211
+ r++;
212
+ while (r * r > x)
213
+ r--;
214
+ return r;
215
+ }
216
+ function detectImpl(src, reg) {
217
+ const b = utf8Buf;
218
+ const n = encodeUTF8Prefix(src, b, DETECT_MAX_BYTES);
219
+ const fast = checkFastPrefix(b, n);
220
+ if (fast !== "" && (reg === null || fast === "plain" || reg.lookup(fast) !== undefined)) {
221
+ return fast;
137
222
  }
138
- const trimmed = src.trim();
139
- if (trimmed === "") {
223
+ let ts = 0;
224
+ while (ts < n && isASCIIWS(b[ts]))
225
+ ts++;
226
+ let te = n;
227
+ while (te > ts && isASCIIWS(b[te - 1]))
228
+ te--;
229
+ if (ts >= te)
140
230
  return "plain";
141
- }
142
- if (trimmed.startsWith("#!")) {
143
- const nl = trimmed.indexOf(`
144
- `);
145
- const shebang = nl >= 0 ? trimmed.slice(0, nl) : trimmed;
146
- if (shebang.includes("bash") || shebang.includes("/sh") || shebang.includes("zsh")) {
147
- return "bash";
148
- }
149
- if (shebang.includes("python"))
150
- return "py";
151
- if (shebang.includes("node") || shebang.includes("deno") || shebang.includes("bun")) {
152
- return "js";
231
+ const { hashes, offs, cnts, entries } = ensureTable();
232
+ scoresBuf.fill(0);
233
+ seenBuf.fill(0);
234
+ let hits = 0;
235
+ const addHash = (h) => {
236
+ let lo = 0;
237
+ let hi = DETECT_FEAT_COUNT;
238
+ let id = -1;
239
+ while (lo < hi) {
240
+ const mid = lo + hi >>> 1;
241
+ const v = hashes[mid];
242
+ if (v < h)
243
+ lo = mid + 1;
244
+ else if (v > h)
245
+ hi = mid;
246
+ else {
247
+ id = mid;
248
+ break;
249
+ }
153
250
  }
154
- if (shebang.includes("ruby"))
155
- return "rb";
156
- if (shebang.includes("lua"))
157
- return "lua";
158
- if (shebang.includes("php"))
159
- return "php";
160
- }
161
- if (trimmed.startsWith("<?php"))
162
- return "php";
163
- if (trimmed.startsWith("<?xml"))
164
- return "xml";
165
- if (hasPrefixFold(trimmed, "<!doctype html"))
166
- return "html";
167
- if (startsWithHTTPMethod(trimmed))
168
- return "http";
169
- if (trimmed.startsWith(`---
170
- `) && trimmed.indexOf(`
171
- ---`, 4) >= 0) {
172
- if (trimmed.includes("client:") || trimmed.includes("set:html") || trimmed.includes("<")) {
173
- return "astro";
251
+ if (id < 0)
252
+ return;
253
+ const word = id >>> 5;
254
+ const bit = 1 << (id & 31);
255
+ if ((seenBuf[word] & bit) !== 0)
256
+ return;
257
+ seenBuf[word] = seenBuf[word] | bit;
258
+ hits++;
259
+ let idx = offs[id] * 2;
260
+ const end = idx + cnts[id] * 2;
261
+ for (;idx < end; idx += 2) {
262
+ const lang = entries[idx];
263
+ const rawW = entries[idx + 1];
264
+ const w = rawW >= 128 ? rawW - 256 : rawW;
265
+ scoresBuf[lang] = scoresBuf[lang] + w;
174
266
  }
267
+ };
268
+ const addKey = (k) => {
269
+ addHash(fnv32Str(FNV32_OFFSET, k));
270
+ };
271
+ const firstB = b[ts];
272
+ const lastB = b[te - 1];
273
+ if (firstB === 123 && lastB === 125)
274
+ addKey("F:wrap_brace");
275
+ else if (firstB === 91 && lastB === 93)
276
+ addKey("F:wrap_bracket");
277
+ else if (firstB === 60 && lastB === 62)
278
+ addKey("F:wrap_angle");
279
+ if (ts + 4 <= n && b[ts] === 45 && b[ts + 1] === 45 && b[ts + 2] === 45 && b[ts + 3] === 10 && containsASCII(b, ts + 4, n, `
280
+ ---`)) {
281
+ addKey("F:frontmatter");
175
282
  }
176
- const scores = new Int32Array(36 /* Count */);
177
- if (trimmed.startsWith("{") && trimmed.endsWith("}") || trimmed.startsWith("[") && trimmed.endsWith("]")) {
178
- scores[20 /* JSON */] += 25;
179
- }
180
- const n = src.length;
181
283
  let i = 0;
284
+ let nonEmptyLines = 0;
285
+ let semiEOLLines = 0;
286
+ let colonEOLLines = 0;
287
+ let braceEOLLines = 0;
288
+ let tabIndentLines = 0;
289
+ let space2IndentLines = 0;
290
+ let space4IndentLines = 0;
291
+ let keyColonLines = 0;
292
+ let keyEqLines = 0;
293
+ let dotKeyEqLines = 0;
294
+ let digitBOLLines = 0;
295
+ let col0PMLines = 0;
296
+ let bracketLines = 0;
297
+ let quotedColonHits = 0;
298
+ let braceCount = 0;
299
+ let braceDepth = 0;
300
+ let maxBraceDepth = 0;
301
+ let punctChars = 0;
302
+ let alphaChars = 0;
303
+ let nonASCIIBytes = 0;
304
+ let nonWSChars = 0;
305
+ let wordCount = 0;
306
+ let lowerWordCount = 0;
307
+ let upperWordCount = 0;
308
+ let camelWordCount = 0;
309
+ let snakeWordCount = 0;
310
+ let prosePunctHits = 0;
311
+ let tsHits = 0;
312
+ let dottedQuadHits = 0;
313
+ let upperTags = 0;
314
+ let closeTags = 0;
182
315
  let atLineStart = true;
183
- let hasJSXTag = false;
184
316
  while (i < n) {
317
+ let c = b[i];
185
318
  if (atLineStart) {
186
319
  const lineStartPos = i;
187
- while (i < n && (src.charCodeAt(i) === 32 || src.charCodeAt(i) === 9)) {
320
+ let indentSpaces = 0;
321
+ if (c === 9)
322
+ tabIndentLines++;
323
+ while (i < n && (b[i] === 32 || b[i] === 9)) {
324
+ if (b[i] === 32)
325
+ indentSpaces++;
188
326
  i++;
189
327
  }
190
328
  if (i >= n)
191
329
  break;
330
+ if (b[i] === 10 || b[i] === 13) {
331
+ i++;
332
+ continue;
333
+ }
192
334
  atLineStart = false;
193
- const ch = src.charCodeAt(i);
194
- if (ch === 35) {
195
- if (src.startsWith("# ", i) || src.startsWith("## ", i) || src.startsWith("### ", i)) {
196
- scores[31 /* MD */] += 35;
197
- } else if (src.startsWith("#include ", i)) {
198
- scores[7 /* C */] += 80;
199
- scores[8 /* CPP */] += 80;
200
- }
201
- } else if (ch === 96) {
202
- if (src.startsWith("```", i)) {
203
- scores[31 /* MD */] += 50;
204
- }
205
- } else if (ch === 64) {
206
- if (src.startsWith("@import ", i) || src.startsWith("@media ", i) || src.startsWith("@layer ", i)) {
207
- scores[26 /* CSS */] += 45;
208
- scores[27 /* SCSS */] += 45;
209
- } else if (src.startsWith("@mixin ", i) || src.startsWith("@include ", i) || src.startsWith("@use ", i)) {
210
- scores[27 /* SCSS */] += 90;
211
- } else if (src.startsWith("@@ ", i)) {
212
- scores[35 /* Diff */] += 150;
213
- }
214
- } else if (ch === 46) {
215
- if (src.startsWith(".PHONY:", i)) {
216
- scores[34 /* Make */] += 120;
217
- }
218
- } else if (ch === 43 || ch === 45) {
219
- if (i === lineStartPos && i + 1 < n && src.charCodeAt(i + 1) !== ch) {
220
- scores[35 /* Diff */] += 6;
221
- }
222
- } else if (ch === 36) {
223
- scores[27 /* SCSS */] += 35;
224
- } else if (ch === 91) {
225
- const nl = src.indexOf(`
226
- `, i);
227
- const tl = (nl >= 0 ? src.slice(i, nl) : src.slice(i)).trim();
228
- if (tl.length > 2 && tl.endsWith("]") && !tl.includes(",") && !tl.includes('"') && !tl.includes("'")) {
229
- scores[22 /* TOML */] += 25;
230
- scores[23 /* INI */] += 25;
231
- }
232
- } else if (ch === 70 || ch === 82 || ch === 69 || ch === 87) {
233
- if (src.startsWith("FROM ", i) || src.startsWith("RUN ", i) || src.startsWith("ENTRYPOINT ", i) || src.startsWith("WORKDIR ", i)) {
234
- scores[33 /* Docker */] += 120;
235
- }
236
- } else if (ch === 100) {
237
- if (src.startsWith("diff --git ", i)) {
238
- scores[35 /* Diff */] += 150;
239
- }
240
- } else if (ch === 105) {
241
- if (src.startsWith("ifneq ", i) || src.startsWith("ifeq ", i)) {
242
- scores[34 /* Make */] += 120;
243
- } else if (src.startsWith("import java.", i) || src.startsWith("import javax.", i)) {
244
- scores[10 /* Java */] += 200;
245
- } else if (src.startsWith("import 'package:", i)) {
246
- scores[14 /* Dart */] += 150;
247
- }
248
- } else if (ch === 112) {
249
- if (src.startsWith("package ", i)) {
250
- scores[0 /* Go */] += 70;
251
- scores[10 /* Java */] += 40;
252
- scores[11 /* Kt */] += 40;
335
+ nonEmptyLines++;
336
+ if (indentSpaces === 2)
337
+ space2IndentLines++;
338
+ else if (indentSpaces === 4)
339
+ space4IndentLines++;
340
+ const nl = indexOfByte(b, 10, i, n);
341
+ const le = nl >= 0 ? nl : n;
342
+ let rle = le;
343
+ while (rle > i && (b[rle - 1] === 32 || b[rle - 1] === 9 || b[rle - 1] === 13)) {
344
+ rle--;
345
+ }
346
+ if (rle > i) {
347
+ const endCh = b[rle - 1];
348
+ if (endCh === 59)
349
+ semiEOLLines++;
350
+ else if (endCh === 58)
351
+ colonEOLLines++;
352
+ else if (endCh === 123 || endCh === 125)
353
+ braceEOLLines++;
354
+ }
355
+ const c0 = b[i];
356
+ if (isDigit(c0)) {
357
+ digitBOLLines++;
358
+ } else if (isIdentStart(c0)) {
359
+ let j = i + 1;
360
+ while (j < le && isIdentCont(b[j]))
361
+ j++;
362
+ if (j - i <= 24) {
363
+ addHash(fnv32Bytes(H_LW, b, i, j));
364
+ let k = j;
365
+ let hasDot = false;
366
+ while (k < le && (b[k] === 45 || b[k] === 46)) {
367
+ if (b[k] === 46)
368
+ hasDot = true;
369
+ k++;
370
+ while (k < le && isIdentCont(b[k]))
371
+ k++;
372
+ }
373
+ let ks = k;
374
+ while (ks < le && (b[ks] === 32 || b[ks] === 9))
375
+ ks++;
376
+ if (ks < le && b[ks] === 58 && (ks + 1 === le || b[ks + 1] === 32 || b[ks + 1] === 9 || b[ks + 1] === 13)) {
377
+ keyColonLines++;
378
+ } else if (ks < le && b[ks] === 61 && (ks + 1 === le || b[ks + 1] !== 61)) {
379
+ keyEqLines++;
380
+ if (hasDot)
381
+ dotKeyEqLines++;
382
+ }
383
+ if (j - i <= 14) {
384
+ let k2 = j;
385
+ while (k2 < le && (b[k2] === 32 || b[k2] === 9))
386
+ k2++;
387
+ if (k2 > j && k2 < le) {
388
+ const c2 = b[k2];
389
+ if (isIdentStart(c2)) {
390
+ let k3 = k2 + 1;
391
+ while (k3 < le && isIdentCont(b[k3]))
392
+ k3++;
393
+ if (k3 - k2 <= 14) {
394
+ addHash(fnv32Bytes(fnv32Byte(fnv32Bytes(H_LW2, b, i, j), 32), b, k2, k3));
395
+ }
396
+ } else if (c2 === 34) {
397
+ addHash(fnv32Byte(fnv32Byte(fnv32Bytes(H_LW2, b, i, j), 32), 34));
398
+ } else if (c2 === 123) {
399
+ addHash(fnv32Byte(fnv32Byte(fnv32Bytes(H_LW2, b, i, j), 32), 123));
400
+ }
401
+ }
402
+ }
253
403
  }
254
- } else if (ch === 117) {
255
- if (src.startsWith("using System", i)) {
256
- scores[9 /* CS */] += 180;
404
+ } else if (c0 >= 33 && c0 < 128) {
405
+ if (c0 === 91 && rle - i >= 3 && b[rle - 1] === 93 && indexOfByte(b, 44, i + 1, rle - 1) < 0 && indexOfByte(b, 34, i + 1, rle - 1) < 0 && indexOfByte(b, 123, i + 1, rle - 1) < 0) {
406
+ bracketLines++;
257
407
  }
258
- }
259
- const nl = src.indexOf(`
260
- `, i);
261
- const line = nl >= 0 ? src.slice(i, nl) : src.slice(i);
262
- const colon = line.indexOf(":");
263
- if (colon > 0 && isSimpleKey(line.slice(0, colon))) {
264
- if (colon + 1 === line.length || line.charCodeAt(colon + 1) === 32) {
265
- scores[21 /* YAML */] += 14;
408
+ let j = i;
409
+ while (j < le && j - i < 3 && b[j] >= 33 && b[j] < 128 && !isIdentCont(b[j])) {
410
+ j++;
266
411
  }
267
- }
268
- const eq = line.indexOf("=");
269
- if (eq > 0 && isSimpleKey(line.slice(0, eq).trim())) {
270
- if (line.includes('"') || line.includes("'") || line.includes("[")) {
271
- scores[22 /* TOML */] += 8;
272
- } else {
273
- scores[23 /* INI */] += 8;
412
+ if (j > i) {
413
+ let h = fnv32Bytes(H_LP, b, i, j);
414
+ if (j < rle && (b[j] === 32 || b[j] === 9)) {
415
+ h = fnv32Byte(h, 32);
416
+ }
417
+ addHash(h);
418
+ if (i === lineStartPos && (c0 === 43 || c0 === 45) && j - i === 1) {
419
+ col0PMLines++;
420
+ }
274
421
  }
275
422
  }
276
- if (line.includes('":')) {
277
- scores[20 /* JSON */] += 8;
278
- }
279
- if (line.includes(";") && line.includes("=") && !line.includes("{")) {
280
- scores[19 /* Nix */] += 8;
281
- }
423
+ c = b[i];
282
424
  }
283
- const ch = src.charCodeAt(i);
284
- if (ch === 10) {
425
+ if (c === 10) {
285
426
  atLineStart = true;
286
427
  i++;
287
428
  continue;
288
429
  }
289
- if (isIdentStart(ch)) {
290
- const start = i;
430
+ if (c === 32 || c === 9 || c === 13) {
291
431
  i++;
292
- while (i < n && isIdentCont(src.charCodeAt(i))) {
293
- i++;
432
+ continue;
433
+ }
434
+ nonWSChars++;
435
+ if (c >= 128) {
436
+ let j = i + 1;
437
+ while (j < n && b[j] >= 128)
438
+ j++;
439
+ const run = j - i;
440
+ nonASCIIBytes += run;
441
+ nonWSChars += run - 1;
442
+ i = j;
443
+ continue;
444
+ }
445
+ if (isIdentStart(c)) {
446
+ let j = i + 1;
447
+ let hasUpper = c >= 65 && c <= 90;
448
+ let hasLower = c >= 97 && c <= 122;
449
+ let hasUnder = c === 95;
450
+ while (j < n && isIdentCont(b[j])) {
451
+ const cj = b[j];
452
+ if (cj >= 65 && cj <= 90)
453
+ hasUpper = true;
454
+ else if (cj >= 97 && cj <= 122)
455
+ hasLower = true;
456
+ else if (cj === 95)
457
+ hasUnder = true;
458
+ j++;
294
459
  }
295
- const w = src.slice(start, i);
296
- switch (w) {
297
- case "func":
298
- scores[0 /* Go */] += 45;
299
- scores[12 /* Swift */] += 45;
300
- break;
301
- case "fmt":
302
- if (i < n && src.charCodeAt(i) === 46)
303
- scores[0 /* Go */] += 80;
304
- break;
305
- case "chan":
306
- case "defer":
307
- case "fallthrough":
308
- case "go":
309
- scores[0 /* Go */] += 40;
310
- break;
311
- case "const":
312
- case "let":
313
- case "async":
314
- case "await":
315
- case "export":
316
- case "import":
317
- scores[1 /* JS */] += 10;
318
- scores[2 /* TS */] += 10;
319
- break;
320
- case "function":
321
- case "typeof":
322
- case "undefined":
323
- scores[1 /* JS */] += 25;
324
- scores[2 /* TS */] += 20;
325
- break;
326
- case "console":
327
- if (src.startsWith(".log", i)) {
328
- scores[1 /* JS */] += 40;
329
- scores[2 /* TS */] += 30;
330
- }
331
- break;
332
- case "document":
333
- if (i < n && src.charCodeAt(i) === 46)
334
- scores[1 /* JS */] += 25;
335
- break;
336
- case "interface":
337
- scores[2 /* TS */] += 45;
338
- scores[4 /* TSX */] += 35;
339
- break;
340
- case "satisfies":
341
- scores[2 /* TS */] += 60;
342
- break;
343
- case "className":
344
- if (i < n && src.charCodeAt(i) === 61) {
345
- scores[3 /* JSX */] += 60;
346
- scores[4 /* TSX */] += 65;
460
+ const wlen = j - i;
461
+ alphaChars += wlen;
462
+ nonWSChars += wlen - 1;
463
+ wordCount++;
464
+ if (hasLower && !hasUpper && !hasUnder)
465
+ lowerWordCount++;
466
+ if (hasUpper && hasLower)
467
+ camelWordCount++;
468
+ if (hasUpper && !hasLower && wlen >= 2)
469
+ upperWordCount++;
470
+ if (hasUnder && wlen >= 3)
471
+ snakeWordCount++;
472
+ if (wlen <= 24) {
473
+ addHash(fnv32Bytes(H_W, b, i, j));
474
+ if (j < n) {
475
+ const nx = b[j];
476
+ if (nx === 33) {
477
+ addHash(fnv32Byte(fnv32Bytes(H_WA, b, i, j), 33));
478
+ } else if (nx === 58) {
479
+ if (j + 1 < n && b[j + 1] === 58) {
480
+ addHash(fnv32Byte(fnv32Byte(fnv32Bytes(H_WA, b, i, j), 58), 58));
481
+ } else {
482
+ addHash(fnv32Byte(fnv32Bytes(H_WA, b, i, j), 58));
483
+ }
484
+ } else if (nx === 40) {
485
+ addHash(fnv32Byte(fnv32Bytes(H_WA, b, i, j), 40));
486
+ } else if (nx === 46 && j + 1 < n && isAlpha(b[j + 1])) {
487
+ addHash(fnv32Byte(fnv32Bytes(H_WA, b, i, j), 46));
488
+ } else if (nx === 61 && (j + 1 >= n || b[j + 1] !== 61)) {
489
+ addHash(fnv32Byte(fnv32Bytes(H_WA, b, i, j), 61));
490
+ } else if (nx === 60 && j + 1 < n && isAlpha(b[j + 1])) {
491
+ addHash(fnv32Byte(fnv32Bytes(H_WA, b, i, j), 60));
492
+ } else if ((nx === 34 || nx === 39) && wlen === 1) {
493
+ addHash(fnv32Byte(fnv32Bytes(H_WA, b, i, j), 34));
494
+ } else if (nx === 45 && j + 1 < n && b[j + 1] === 62) {
495
+ addHash(fnv32Byte(fnv32Byte(fnv32Bytes(H_WA, b, i, j), 45), 62));
496
+ } else if (nx === 45 && j + 1 < n && isAlpha(b[j + 1]) && wlen <= 6) {
497
+ addHash(fnv32Byte(fnv32Bytes(H_WA, b, i, j), 45));
347
498
  }
348
- break;
349
- case "def":
350
- case "None":
351
- case "True":
352
- case "False":
353
- scores[5 /* Py */] += 25;
354
- break;
355
- case "__init__":
356
- scores[5 /* Py */] += 100;
357
- break;
358
- case "elif":
359
- scores[5 /* Py */] += 30;
360
- scores[32 /* Bash */] += 30;
361
- break;
362
- case "self":
363
- if (i < n && src.charCodeAt(i) === 46)
364
- scores[5 /* Py */] += 35;
365
- break;
366
- case "mut":
367
- case "pub":
368
- case "crate":
369
- case "match":
370
- scores[6 /* Rs */] += 30;
371
- break;
372
- case "println":
373
- if (i < n && src.charCodeAt(i) === 33)
374
- scores[6 /* Rs */] += 90;
375
- break;
376
- case "impl":
377
- scores[6 /* Rs */] += 45;
378
- break;
379
- case "std":
380
- if (src.startsWith("::", i))
381
- scores[8 /* CPP */] += 90;
382
- break;
383
- case "iostream":
384
- case "vector":
385
- scores[8 /* CPP */] += 80;
386
- break;
387
- case "template":
388
- if (i < n && src.charCodeAt(i) === 60)
389
- scores[8 /* CPP */] += 70;
390
- break;
391
- case "nullptr":
392
- scores[8 /* CPP */] += 60;
393
- break;
394
- case "Console":
395
- if (i < n && src.charCodeAt(i) === 46)
396
- scores[9 /* CS */] += 90;
397
- break;
398
- case "System":
399
- if (src.startsWith(".out.", i))
400
- scores[10 /* Java */] += 100;
401
- break;
402
- case "main":
403
- if (start >= 19 && src.startsWith("public static void ", start - 19)) {
404
- scores[10 /* Java */] += 150;
405
- }
406
- break;
407
- case "companion":
408
- if (src.startsWith(" object", i))
409
- scores[11 /* Kt */] += 120;
410
- break;
411
- case "fun":
412
- scores[11 /* Kt */] += 40;
413
- break;
414
- case "val":
415
- case "when":
416
- case "object":
417
- scores[11 /* Kt */] += 25;
418
- break;
419
- case "guard":
420
- if (src.startsWith(" let ", i))
421
- scores[12 /* Swift */] += 120;
422
- break;
423
- case "comptime":
424
- scores[13 /* Zig */] += 120;
425
- break;
426
- case "orelse":
427
- scores[13 /* Zig */] += 80;
428
- break;
429
- case "BuildContext":
430
- scores[14 /* Dart */] += 120;
431
- break;
432
- case "Widget":
433
- scores[14 /* Dart */] += 90;
434
- break;
435
- case "SELECT":
436
- case "select":
437
- scores[16 /* SQL */] += 60;
438
- break;
439
- case "FROM":
440
- case "WHERE":
441
- scores[16 /* SQL */] += 40;
442
- break;
443
- case "pkgs":
444
- scores[19 /* Nix */] += 80;
445
- break;
446
- case "mkDerivation":
447
- scores[19 /* Nix */] += 150;
448
- break;
449
- case "nixpkgs":
450
- scores[19 /* Nix */] += 90;
451
- break;
452
- case "local":
453
- scores[18 /* Lua */] += 35;
454
- break;
455
- case "elseif":
456
- scores[18 /* Lua */] += 60;
457
- break;
458
- case "attr_accessor":
459
- scores[17 /* Rb */] += 120;
460
- break;
461
- case "end":
462
- if (i < n && src.charCodeAt(i) === 10)
463
- scores[17 /* Rb */] += 25;
464
- break;
465
- case "echo":
466
- scores[32 /* Bash */] += 25;
467
- break;
468
- case "then":
469
- case "fi":
470
- case "done":
471
- scores[32 /* Bash */] += 30;
472
- break;
473
- case "esac":
474
- scores[32 /* Bash */] += 80;
475
- break;
476
- case "struct":
477
- case "enum":
478
- scores[6 /* Rs */] += 10;
479
- scores[0 /* Go */] += 10;
480
- scores[13 /* Zig */] += 15;
481
- scores[12 /* Swift */] += 10;
482
- break;
483
- case "nil":
484
- scores[0 /* Go */] += 15;
485
- scores[18 /* Lua */] += 15;
486
- scores[17 /* Rb */] += 15;
487
- scores[12 /* Swift */] += 15;
488
- break;
489
- case "xmlns":
490
- if (i < n && src.charCodeAt(i) === 61)
491
- scores[25 /* XML */] += 70;
492
- break;
499
+ }
493
500
  }
501
+ i = j;
494
502
  continue;
495
503
  }
496
- if (ch === 58) {
497
- if (i + 1 < n && src.charCodeAt(i + 1) === 61) {
498
- scores[0 /* Go */] += 40;
499
- i += 2;
500
- continue;
504
+ if (isDigit(c)) {
505
+ let j = i + 1;
506
+ let dots = 0;
507
+ while (j < n && (isDigit(b[j]) || b[j] === 46 || b[j] === 95 || b[j] === 120 || b[j] === 88)) {
508
+ if (b[j] === 46)
509
+ dots++;
510
+ j++;
501
511
  }
502
- if (src.startsWith(": string", i) || src.startsWith(": number", i) || src.startsWith(": boolean", i)) {
503
- scores[2 /* TS */] += 40;
504
- scores[4 /* TSX */] += 30;
512
+ if (dots === 3 && j - i <= 15)
513
+ dottedQuadHits++;
514
+ if (j - i === 4 && i + 9 < n && (b[i + 4] === 45 || b[i + 4] === 47 || b[i + 4] === 46) && isDigit(b[i + 5]) && isDigit(b[i + 6]) && b[i + 7] === b[i + 4]) {
515
+ tsHits++;
516
+ } else if (j - i === 2 && i + 7 < n && b[i + 2] === 58 && isDigit(b[i + 3]) && isDigit(b[i + 4]) && b[i + 5] === 58) {
517
+ tsHits++;
518
+ } else if (j - i === 6 && i + 12 < n && b[i + 6] === 32 && isDigit(b[i + 7]) && isDigit(b[i + 8]) && isDigit(b[i + 12])) {
519
+ tsHits++;
505
520
  }
506
- } else if (ch === 47) {
507
- if (i + 1 < n && src.charCodeAt(i + 1) === 62) {
508
- hasJSXTag = true;
509
- i += 2;
521
+ nonWSChars += j - i - 1;
522
+ i = j;
523
+ continue;
524
+ }
525
+ if (c === 34 || c === 39) {
526
+ const q = c;
527
+ punctChars++;
528
+ if (i + 2 < n && b[i + 1] === q && b[i + 2] === q) {
529
+ addHash(fnv32Byte(fnv32Byte(fnv32Byte(H_S, q), q), q));
530
+ i += 3;
510
531
  continue;
511
532
  }
512
- } else if (ch === 60) {
513
- if (src.startsWith("<template>", i)) {
514
- scores[28 /* Vue */] += 120;
515
- } else if (src.startsWith("<script setup", i)) {
516
- scores[28 /* Vue */] += 150;
517
- } else if (src.startsWith("<html", i)) {
518
- scores[24 /* HTML */] += 80;
519
- } else if (src.startsWith("<div", i) || src.startsWith("<span", i)) {
520
- scores[24 /* HTML */] += 35;
521
- } else if (src.startsWith("<svg", i)) {
522
- scores[25 /* XML */] += 70;
533
+ addHash(fnv32Byte(H_S, q));
534
+ let j = i + 1;
535
+ while (j < n && j - i < 80 && b[j] !== q && b[j] !== 10) {
536
+ if (b[j] === 92 && j + 1 < n) {
537
+ j += 2;
538
+ continue;
539
+ }
540
+ j++;
523
541
  }
524
- } else if (ch === 123) {
525
- if (src.startsWith("{#if ", i) || src.startsWith("{#each ", i)) {
526
- scores[29 /* Svelte */] += 140;
542
+ if (j < n && b[j] === q) {
543
+ let k = j + 1;
544
+ while (k < n && (b[k] === 32 || b[k] === 9))
545
+ k++;
546
+ if (k < n && b[k] === 58)
547
+ quotedColonHits++;
548
+ i = j + 1;
549
+ continue;
527
550
  }
528
- } else if (ch === 64) {
529
- if (src.startsWith("@import(", i)) {
530
- scores[13 /* Zig */] += 120;
531
- } else if (src.startsWith("@State ", i)) {
532
- scores[12 /* Swift */] += 80;
551
+ i++;
552
+ continue;
553
+ }
554
+ punctChars++;
555
+ if (c === 123) {
556
+ braceCount++;
557
+ braceDepth++;
558
+ if (braceDepth > maxBraceDepth)
559
+ maxBraceDepth = braceDepth;
560
+ } else if (c === 125) {
561
+ braceCount++;
562
+ if (braceDepth > 0)
563
+ braceDepth--;
564
+ }
565
+ if ((c === 46 || c === 44) && i + 1 < n && b[i + 1] === 32)
566
+ prosePunctHits++;
567
+ if ((c === 64 || c === 36 || c === 35 || c === 92 || c === 58 || c === 37) && i + 1 < n) {
568
+ const nx = b[i + 1];
569
+ if (isAlpha(nx) || nx === 95) {
570
+ let j = i + 2;
571
+ while (j < n && (isIdentCont(b[j]) || (c === 64 || c === 35 || c === 36) && b[j] === 45)) {
572
+ j++;
573
+ }
574
+ if (j - i <= 24) {
575
+ addHash(fnv32Bytes(H_P, b, i, j));
576
+ addHash(fnv32Byte(H_S, c));
577
+ i = j;
578
+ continue;
579
+ }
533
580
  }
534
- } else if (ch === 38) {
535
- if (src.startsWith("&mut ", i)) {
536
- scores[6 /* Rs */] += 70;
581
+ }
582
+ if (c === 60 && i + 1 < n) {
583
+ const nx = b[i + 1];
584
+ if (nx === 47 && i + 2 < n && isAlpha(b[i + 2])) {
585
+ closeTags++;
586
+ addHash(fnv32Byte(fnv32Byte(H_S, 60), 47));
587
+ i += 2;
588
+ continue;
589
+ } else if (isAlpha(nx)) {
590
+ let j = i + 1;
591
+ while (j < n && (isIdentCont(b[j]) || b[j] === 45 || b[j] === 58))
592
+ j++;
593
+ if (j < n && (b[j] === 32 || b[j] === 9 || b[j] === 10 || b[j] === 13 || b[j] === 62 || b[j] === 47)) {
594
+ if (nx >= 65 && nx <= 90)
595
+ upperTags++;
596
+ if (j - (i + 1) <= 20) {
597
+ addHash(fnv32Bytes(H_T, b, i + 1, j));
598
+ const col = indexOfByte(b, 58, i + 1, j);
599
+ if (col > i + 1)
600
+ addHash(fnv32Bytes(H_T, b, i + 1, col + 1));
601
+ }
602
+ }
537
603
  }
538
- } else if (ch === 118) {
539
- if (src.startsWith("v-for=", i) || src.startsWith("v-if=", i)) {
540
- scores[28 /* Vue */] += 90;
604
+ }
605
+ let j = i + 1;
606
+ while (j < n && j - i < 3 && b[j] >= 33 && b[j] < 128 && !isIdentCont(b[j]) && b[j] !== 34 && b[j] !== 39) {
607
+ j++;
608
+ }
609
+ if (c >= 33 && c < 128) {
610
+ const symLen = j - i;
611
+ addHash(fnv32Bytes(H_S, b, i, j));
612
+ if (symLen === 3 && (b[i] !== b[i + 1] || b[i + 1] !== b[i + 2])) {
613
+ addHash(fnv32Bytes(H_S, b, i, i + 2));
541
614
  }
542
- } else if (ch === 111) {
543
- if (src.startsWith("on:click", i)) {
544
- scores[29 /* Svelte */] += 90;
615
+ if (symLen >= 2 && b[i] !== b[i + 1]) {
616
+ addHash(fnv32Byte(H_S, b[i]));
545
617
  }
546
618
  }
547
- i++;
619
+ nonWSChars += j - i - 1;
620
+ i = j;
548
621
  }
549
- if ((scores[1 /* JS */] > 0 || scores[2 /* TS */] > 0) && hasJSXTag) {
550
- if (scores[2 /* TS */] > scores[1 /* JS */]) {
551
- scores[4 /* TSX */] += scores[2 /* TS */] + 30;
552
- } else {
553
- scores[3 /* JSX */] += scores[1 /* JS */] + 30;
622
+ if (nonEmptyLines <= 1)
623
+ addKey("F:single_line");
624
+ else if (nonEmptyLines <= 4)
625
+ addKey("F:few_lines");
626
+ if (nonEmptyLines > 0) {
627
+ if (semiEOLLines >= 2 || semiEOLLines / nonEmptyLines >= 0.35)
628
+ addKey("F:semi_eol");
629
+ if (colonEOLLines >= 2 || colonEOLLines / nonEmptyLines >= 0.25)
630
+ addKey("F:colon_eol");
631
+ if (braceEOLLines >= 2)
632
+ addKey("F:brace_eol");
633
+ if (tabIndentLines >= 2)
634
+ addKey("F:tab_indent");
635
+ if (space2IndentLines >= 2 || nonEmptyLines <= 5 && space2IndentLines >= 1)
636
+ addKey("F:space2_indent");
637
+ if (space4IndentLines >= 2 || nonEmptyLines <= 5 && space4IndentLines >= 1)
638
+ addKey("F:space4_indent");
639
+ if (col0PMLines >= 1)
640
+ addKey("F:col0_pm");
641
+ if (col0PMLines >= 3)
642
+ addKey("F:col0_pm_many");
643
+ if (keyColonLines >= 2 || nonEmptyLines <= 5 && keyColonLines >= 1)
644
+ addKey("F:key_colon");
645
+ if (keyEqLines >= 2 || nonEmptyLines <= 5 && keyEqLines >= 1)
646
+ addKey("F:key_eq");
647
+ if (dotKeyEqLines >= 2 || nonEmptyLines <= 5 && dotKeyEqLines >= 1)
648
+ addKey("F:dot_key_eq");
649
+ if (digitBOLLines >= 2)
650
+ addKey("F:digit_bol");
651
+ if (digitBOLLines >= 2 && digitBOLLines / nonEmptyLines >= 0.5)
652
+ addKey("F:digit_bol_most");
653
+ }
654
+ if (bracketLines >= 1)
655
+ addKey("F:bracket_line");
656
+ if (quotedColonHits >= 1)
657
+ addKey("F:quoted_colon");
658
+ if (quotedColonHits >= 3)
659
+ addKey("F:quoted_colon_many");
660
+ if (braceCount === 0)
661
+ addKey("F:no_braces");
662
+ else if (braceCount >= 4)
663
+ addKey("F:many_braces");
664
+ if (maxBraceDepth >= 2)
665
+ addKey("F:brace_depth_2");
666
+ if (maxBraceDepth >= 3)
667
+ addKey("F:brace_depth_3");
668
+ if (tsHits >= 1)
669
+ addKey("F:timestamp");
670
+ if (tsHits >= 3)
671
+ addKey("F:timestamp_many");
672
+ if (dottedQuadHits >= 1)
673
+ addKey("F:dotted_quad");
674
+ if (upperTags >= 1)
675
+ addKey("F:upper_tag");
676
+ if (closeTags >= 1)
677
+ addKey("F:close_tag");
678
+ if (nonWSChars > 0) {
679
+ const punctRatio = punctChars / nonWSChars;
680
+ const textRatio = (alphaChars + nonASCIIBytes) / nonWSChars;
681
+ if (punctRatio < 0.06)
682
+ addKey("F:punct_very_low");
683
+ else if (punctRatio < 0.14)
684
+ addKey("F:punct_low");
685
+ else if (punctRatio > 0.3)
686
+ addKey("F:punct_high");
687
+ if (textRatio > 0.78 && punctRatio < 0.08 && (prosePunctHits >= 2 || nonASCIIBytes >= 12)) {
688
+ addKey("F:prose_like");
689
+ }
690
+ if (wordCount >= 4 && lowerWordCount / wordCount >= 0.65 && punctRatio < 0.08 && braceCount === 0) {
691
+ addKey("F:prose_sentence");
554
692
  }
555
693
  }
694
+ if (wordCount >= 5) {
695
+ if (camelWordCount / wordCount >= 0.2)
696
+ addKey("F:camel_case");
697
+ if (snakeWordCount / wordCount >= 0.2)
698
+ addKey("F:snake_case");
699
+ if (upperWordCount / wordCount >= 0.25)
700
+ addKey("F:upper_words");
701
+ }
702
+ const mul = hits > 0 ? isqrtInt(hits * 256) : 16;
556
703
  let bestIdx = -1;
557
- let bestScore = 24;
558
- for (let idx = 0;idx < scores.length; idx++) {
559
- if (scores[idx] > bestScore) {
560
- bestScore = scores[idx];
561
- bestIdx = idx;
704
+ let bestVal = 0;
705
+ for (let c = 0;c < DETECT_LANG_COUNT; c++) {
706
+ const name = DETECT_LANG_NAMES[c];
707
+ if (reg !== null && name !== "plain" && reg.lookup(name) === undefined) {
708
+ continue;
709
+ }
710
+ const val = scoresBuf[c] * 256 + DETECT_LANG_BIAS[c] * mul;
711
+ if (bestIdx < 0 || val > bestVal) {
712
+ bestIdx = c;
713
+ bestVal = val;
562
714
  }
563
715
  }
564
- return bestIdx < 0 ? "plain" : NAMES[bestIdx];
716
+ return bestIdx >= 0 ? DETECT_LANG_NAMES[bestIdx] : "plain";
717
+ }
718
+ export function detect(src) {
719
+ return detectImpl(src, null);
720
+ }
721
+ export function detectIn(src, reg) {
722
+ return detectImpl(src, reg);
565
723
  }