@orkestrel/guide 0.0.25 → 0.0.27

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.
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- let _orkestrel_markdown = require("@orkestrel/markdown");
3
2
  let _orkestrel_contract = require("@orkestrel/contract");
4
- //#region src/core/constants.ts
3
+ let _orkestrel_markdown = require("@orkestrel/markdown");
4
+ // src/core/constants.ts
5
5
  /**
6
6
  * Lists the declaration keywords a documented or exported symbol carries, in the order the
7
7
  * reflection grammar names them — the frozen population `ExportKeyword`, `isExportKeyword`, and
@@ -22,12 +22,32 @@ var EXPORT_KEYWORDS = Object.freeze([
22
22
  /**
23
23
  * Lists the compared sites a {@link Drift} can describe.
24
24
  */
25
- var DRIFT_CATEGORIES = Object.freeze(["summary", "example"]);
25
+ var DRIFT_CATEGORIES = Object.freeze([
26
+ "summary",
27
+ "signature",
28
+ "example"
29
+ ]);
26
30
  /**
27
31
  * Names the `## Surface` heading text a guide's documented exports section is keyed on.
28
32
  */
29
33
  var SURFACE = "Surface";
30
34
  /**
35
+ * Lists the codes a {@link GuideError} carries: a refused Surface `header` or empty `signature`
36
+ * cell, a name two modules of one manifest entry declare (`collision`), and the compiler faults —
37
+ * a failed `compile`, an `empty` emit, a `timeout`, and an output `overflow`.
38
+ */
39
+ var GUIDE_CODES = Object.freeze([
40
+ "header",
41
+ "signature",
42
+ "collision",
43
+ "compile",
44
+ "empty",
45
+ "timeout",
46
+ "overflow"
47
+ ]);
48
+ /** Names the cross-copy identity marker of a Guide error. */
49
+ var GUIDE_ERROR_BRAND = Symbol.for("@orkestrel/guide.GuideError");
50
+ /**
31
51
  * Names the `## Methods` heading text a guide's documented interface-methods section is keyed on.
32
52
  */
33
53
  var METHODS = "Methods";
@@ -40,11 +60,28 @@ var TESTS = "Tests";
40
60
  */
41
61
  var KIND = "Kind";
42
62
  /**
63
+ * Names the header text of the column a `## Surface` table's TypeScript signature is read from.
64
+ */
65
+ var SIGNATURE = "Signature";
66
+ /**
43
67
  * Names the header text of the column a `## Surface` or `## Methods` table's compared
44
68
  * description paragraph is read from.
45
69
  */
46
70
  var SUMMARY = "Summary";
47
71
  /**
72
+ * Names the header text of a `## Surface` or `## Methods` table's first column, the symbol name.
73
+ */
74
+ var NAME = "Name";
75
+ /**
76
+ * Lists the uniform `## Surface` table header, column by column, that guide construction requires.
77
+ */
78
+ var SURFACE_HEADER = Object.freeze([
79
+ NAME,
80
+ KIND,
81
+ SIGNATURE,
82
+ SUMMARY
83
+ ]);
84
+ /**
48
85
  * Names the `## By concept` heading text the manifest's run-map table is keyed on.
49
86
  */
50
87
  var MANIFEST = "By concept";
@@ -74,8 +111,38 @@ var EXTERNAL_SCHEMES = Object.freeze([
74
111
  "mailto:",
75
112
  "tel:"
76
113
  ]);
77
- //#endregion
78
- //#region src/core/validators.ts
114
+ // src/core/errors.ts
115
+ /** Carries a coded refusal of a guide, a manifest entry, or a module compile. */
116
+ var GuideError = class extends Error {
117
+ name = "GuideError";
118
+ code;
119
+ context;
120
+ constructor(message, code, options) {
121
+ super(message, options);
122
+ this.code = code;
123
+ this.context = options?.context;
124
+ _orkestrel_contract.INTRINSICS.define(this, GUIDE_ERROR_BRAND, { value: this });
125
+ }
126
+ };
127
+ /**
128
+ * Checks whether a value carries the Guide error brand and declared members across package copies.
129
+ *
130
+ * @example
131
+ * ```ts
132
+ * isGuideError(new GuideError('Invalid Surface header', 'header')) // true
133
+ * ```
134
+ */
135
+ function isGuideError(value) {
136
+ return (0, _orkestrel_contract.holds)(() => {
137
+ if (!(value instanceof _orkestrel_contract.INTRINSICS.error)) return false;
138
+ if (_orkestrel_contract.INTRINSICS.prototype(value) === _orkestrel_contract.INTRINSICS.error.prototype) return false;
139
+ if (_orkestrel_contract.INTRINSICS.describe(value, GUIDE_ERROR_BRAND)?.value !== value) return false;
140
+ const code = _orkestrel_contract.INTRINSICS.reflect.read(value, "code");
141
+ const context = _orkestrel_contract.INTRINSICS.reflect.read(value, "context");
142
+ return GUIDE_CODES.some((candidate) => candidate === code) && (context === void 0 || (0, _orkestrel_contract.isBoundedJSONRecord)(context)) && typeof _orkestrel_contract.INTRINSICS.reflect.read(value, "name") === "string" && typeof _orkestrel_contract.INTRINSICS.reflect.read(value, "message") === "string";
143
+ });
144
+ }
145
+ // src/core/validators.ts
79
146
  /**
80
147
  * Checks whether `value` is one of the documented {@link ExportKeyword}
81
148
  * literals — the guard behind extracting a Surface table's `Kind` cell into a
@@ -95,7 +162,7 @@ var isExportKeyword = (0, _orkestrel_contract.literalOf)(EXPORT_KEYWORDS);
95
162
  var isDriftCategory = (0, _orkestrel_contract.literalOf)(DRIFT_CATEGORIES);
96
163
  /**
97
164
  * Checks whether `value` is a well-formed {@link SurfaceSymbol} — a `name`
98
- * string paired with a valid {@link ExportKeyword}, and an optional `summary`.
165
+ * string paired with a valid {@link ExportKeyword}, and optional `signature` and `summary` strings.
99
166
  *
100
167
  * @param value - The value to test
101
168
  * @returns True if `value` is a well-formed {@link SurfaceSymbol}; false otherwise
@@ -109,8 +176,9 @@ var isDriftCategory = (0, _orkestrel_contract.literalOf)(DRIFT_CATEGORIES);
109
176
  var isSurfaceSymbol = (0, _orkestrel_contract.recordOf)({
110
177
  name: _orkestrel_contract.isString,
111
178
  keyword: isExportKeyword,
179
+ signature: _orkestrel_contract.isString,
112
180
  summary: _orkestrel_contract.isString
113
- }, ["summary"]);
181
+ }, ["signature", "summary"]);
114
182
  /**
115
183
  * Checks whether `value` is a well-formed {@link MethodEntry} — a `name` string with an
116
184
  * optional `summary`.
@@ -203,8 +271,7 @@ var isManifestEntry = (0, _orkestrel_contract.recordOf)({
203
271
  source: (0, _orkestrel_contract.unionOf)(_orkestrel_contract.isString, (0, _orkestrel_contract.arrayOf)(_orkestrel_contract.isString)),
204
272
  tests: _orkestrel_contract.isString
205
273
  });
206
- //#endregion
207
- //#region src/core/helpers.ts
274
+ // src/core/helpers.ts
208
275
  /**
209
276
  * Extracts aligned physical source-line records in one character traversal.
210
277
  * Real line and block comments and complete template tokens become spaces in
@@ -238,462 +305,468 @@ var isManifestEntry = (0, _orkestrel_contract.recordOf)({
238
305
  */
239
306
  function extractSourceLines(source) {
240
307
  const lines = [];
241
- let characters = [];
242
- let jsdocCharacters = [];
308
+ const tokens = [];
243
309
  const identifier = /#?[$_\p{ID_Start}][$_\u200C\u200D\p{ID_Continue}]*/uy;
244
- const templates = [];
245
- const parentheses = [];
246
- let start = 0;
247
- let mode = "code";
248
- let escaped = false;
249
- let regexClass = false;
250
- let operandExpected = true;
251
- let memberExpected = false;
252
- let pendingRole;
253
- let restricted;
254
- let separated = false;
255
- let blockTemplate = false;
256
- let lineTemplate = false;
257
- let jsdoc = false;
258
- let jsdocPresent = false;
259
- for (let offset = 0; offset < source.length; offset += 1) {
260
- const character = source[offset];
261
- if (character === void 0) continue;
310
+ const numeric = /[A-Za-z0-9_$.]+/y;
311
+ const final = source.split("").reduce((state, character, offset) => {
312
+ if (offset < state.offset) return state;
262
313
  const next = source[offset + 1];
263
314
  const crlf = character === "\r" && next === "\n";
264
315
  if (character === "\n" || crlf) {
265
- const code = characters.join("");
266
- const present = jsdocPresent || jsdoc;
316
+ const parts = tokens.slice(state.token);
317
+ const code = parts.map((part) => part.code).join("");
267
318
  lines.push({
268
- source: source.slice(start, offset),
319
+ source: source.slice(state.start, offset),
269
320
  code,
270
- jsdoc: present ? jsdocCharacters.join("").padEnd(code.length, " ") : void 0
321
+ jsdoc: state.present || state.jsdoc ? parts.map((part) => part.jsdoc ?? " ".repeat(part.code.length)).join("") : void 0
271
322
  });
272
- characters = [];
273
- jsdocCharacters = [];
274
- jsdocPresent = jsdoc;
275
- if (mode !== "template") separated = true;
276
- if (restricted !== void 0) {
277
- operandExpected = true;
278
- memberExpected = false;
279
- pendingRole = void 0;
280
- restricted = void 0;
281
- }
282
- if (crlf) offset += 1;
283
- start = offset + 1;
284
- if (mode === "line") mode = lineTemplate ? "templateCode" : "code";
285
- else if (mode === "regex") {
286
- mode = "code";
287
- operandExpected = true;
288
- regexClass = false;
289
- } else if (mode === "templateLine" || mode === "templateRegex") {
290
- mode = "templateCode";
291
- operandExpected = true;
292
- regexClass = false;
293
- } else if (mode === "single" || mode === "double") {
294
- if (!escaped) {
295
- mode = "code";
296
- operandExpected = true;
297
- }
298
- } else if (mode === "templateSingle" || mode === "templateDouble") {
299
- if (!escaped) {
300
- mode = "templateCode";
301
- operandExpected = true;
302
- }
303
- }
304
- escaped = false;
305
- continue;
306
- }
307
- if (mode === "line" || mode === "templateLine") {
308
- characters.push(" ");
309
- continue;
323
+ const regular = state.mode === "single" || state.mode === "double";
324
+ const quoted = state.mode === "templateSingle" || state.mode === "templateDouble";
325
+ const reset = state.mode === "regex" || state.mode === "templateLine" || state.mode === "templateRegex";
326
+ const mode = state.mode === "line" ? state.line ? "templateCode" : "code" : state.mode === "regex" ? "code" : state.mode === "templateLine" || state.mode === "templateRegex" ? "templateCode" : regular && !state.escaped ? "code" : quoted && !state.escaped ? "templateCode" : state.mode;
327
+ return {
328
+ ...state,
329
+ offset: offset + (crlf ? 2 : 1),
330
+ start: offset + (crlf ? 2 : 1),
331
+ token: tokens.length,
332
+ mode,
333
+ escaped: false,
334
+ regex: reset ? false : state.regex,
335
+ operand: state.restricted !== void 0 || reset || (regular || quoted) && !state.escaped ? true : state.operand,
336
+ member: state.restricted !== void 0 ? false : state.member,
337
+ role: state.restricted !== void 0 ? void 0 : state.role,
338
+ restricted: void 0,
339
+ separated: state.mode !== "template" ? true : state.separated,
340
+ present: state.jsdoc
341
+ };
310
342
  }
311
- if (mode === "block" || mode === "templateBlock") {
312
- characters.push(" ");
313
- if (jsdoc) jsdocCharacters.push(character);
314
- if (character === "*" && next === "/") {
315
- characters.push(" ");
316
- if (jsdoc) {
317
- jsdocCharacters.push("/");
318
- jsdoc = false;
319
- }
320
- offset += 1;
321
- mode = blockTemplate ? "templateCode" : "code";
322
- }
323
- continue;
343
+ if (state.mode === "line" || state.mode === "templateLine") {
344
+ tokens.push({ code: " " });
345
+ return state;
324
346
  }
325
- if (mode === "single" || mode === "double") {
326
- characters.push(character);
327
- if (escaped) {
328
- escaped = false;
329
- continue;
330
- }
331
- if (character === "\\") {
332
- escaped = true;
333
- continue;
334
- }
335
- if (mode === "single" && character === "'" || mode === "double" && character === "\"") {
336
- mode = "code";
337
- operandExpected = false;
338
- }
339
- continue;
340
- }
341
- if (mode === "regex") {
342
- characters.push(character);
343
- if (escaped) {
344
- escaped = false;
345
- continue;
346
- }
347
- if (character === "\\") {
348
- escaped = true;
349
- continue;
350
- }
351
- if (character === "[") regexClass = true;
352
- else if (character === "]") regexClass = false;
353
- else if (character === "/" && !regexClass) {
354
- mode = "code";
355
- operandExpected = false;
356
- }
357
- continue;
347
+ if (state.mode === "block" || state.mode === "templateBlock") {
348
+ const closes = character === "*" && next === "/";
349
+ tokens.push({
350
+ code: closes ? " " : " ",
351
+ ...state.jsdoc ? { jsdoc: closes ? "*/" : character } : {}
352
+ });
353
+ return closes ? {
354
+ ...state,
355
+ offset: offset + 2,
356
+ jsdoc: false,
357
+ mode: state.block ? "templateCode" : "code"
358
+ } : state;
358
359
  }
359
- if (mode === "templateSingle" || mode === "templateDouble") {
360
- characters.push(" ");
361
- if (escaped) {
362
- escaped = false;
363
- continue;
364
- }
365
- if (character === "\\") {
366
- escaped = true;
367
- continue;
368
- }
369
- if (mode === "templateSingle" && character === "'" || mode === "templateDouble" && character === "\"") {
370
- mode = "templateCode";
371
- operandExpected = false;
372
- }
373
- continue;
360
+ if (state.mode === "single" || state.mode === "double" || state.mode === "templateSingle" || state.mode === "templateDouble") {
361
+ const template = state.mode === "templateSingle" || state.mode === "templateDouble";
362
+ tokens.push({ code: template ? " " : character });
363
+ if (state.escaped) return {
364
+ ...state,
365
+ escaped: false
366
+ };
367
+ if (character === "\\") return {
368
+ ...state,
369
+ escaped: true
370
+ };
371
+ return (state.mode === "single" || state.mode === "templateSingle" ? character === "'" : character === "\"") ? {
372
+ ...state,
373
+ mode: template ? "templateCode" : "code",
374
+ operand: false
375
+ } : state;
374
376
  }
375
- if (mode === "templateRegex") {
376
- characters.push(" ");
377
- if (escaped) {
378
- escaped = false;
379
- continue;
380
- }
381
- if (character === "\\") {
382
- escaped = true;
383
- continue;
384
- }
385
- if (character === "[") regexClass = true;
386
- else if (character === "]") regexClass = false;
387
- else if (character === "/" && !regexClass) {
388
- mode = "templateCode";
389
- operandExpected = false;
390
- }
391
- continue;
377
+ if (state.mode === "regex" || state.mode === "templateRegex") {
378
+ tokens.push({ code: state.mode === "templateRegex" ? " " : character });
379
+ if (state.escaped) return {
380
+ ...state,
381
+ escaped: false
382
+ };
383
+ if (character === "\\") return {
384
+ ...state,
385
+ escaped: true
386
+ };
387
+ if (character === "[") return {
388
+ ...state,
389
+ regex: true
390
+ };
391
+ if (character === "]") return {
392
+ ...state,
393
+ regex: false
394
+ };
395
+ if (character === "/" && !state.regex) return {
396
+ ...state,
397
+ mode: state.mode === "templateRegex" ? "templateCode" : "code",
398
+ operand: false
399
+ };
400
+ return state;
392
401
  }
393
- if (mode === "template") {
394
- characters.push(" ");
395
- if (escaped) {
396
- escaped = false;
397
- continue;
398
- }
399
- if (character === "\\") {
400
- escaped = true;
401
- continue;
402
- }
403
- if (character === "$" && next === "{") {
404
- characters.push(" ");
405
- offset += 1;
406
- const index = templates.length - 1;
407
- if (index >= 0) templates[index] = 1;
408
- mode = "templateCode";
409
- operandExpected = true;
410
- memberExpected = false;
411
- pendingRole = void 0;
412
- continue;
413
- }
402
+ if (state.mode === "template") {
403
+ const interpolation = !state.escaped && character === "$" && next === "{";
404
+ tokens.push({ code: interpolation ? " " : " " });
405
+ if (state.escaped) return {
406
+ ...state,
407
+ escaped: false
408
+ };
409
+ if (character === "\\") return {
410
+ ...state,
411
+ escaped: true
412
+ };
413
+ if (interpolation) return {
414
+ ...state,
415
+ offset: offset + 2,
416
+ templates: state.templates === void 0 ? void 0 : {
417
+ ...state.templates,
418
+ depth: 1
419
+ },
420
+ mode: "templateCode",
421
+ operand: true,
422
+ member: false,
423
+ role: void 0
424
+ };
414
425
  if (character === "`") {
415
- templates.pop();
416
- mode = templates.length === 0 ? "code" : "templateCode";
417
- operandExpected = false;
426
+ const templates = state.templates?.previous;
427
+ return {
428
+ ...state,
429
+ templates,
430
+ mode: templates === void 0 ? "code" : "templateCode",
431
+ operand: false
432
+ };
418
433
  }
419
- continue;
434
+ return state;
420
435
  }
421
- const templateCode = mode === "templateCode";
436
+ const template = state.mode === "templateCode";
422
437
  if (character === "/" && next === "/") {
423
- characters.push(" ", " ");
424
- offset += 1;
425
- lineTemplate = templateCode;
426
- mode = templateCode ? "templateLine" : "line";
427
- continue;
438
+ tokens.push({ code: " " });
439
+ return {
440
+ ...state,
441
+ offset: offset + 2,
442
+ line: template,
443
+ mode: template ? "templateLine" : "line"
444
+ };
428
445
  }
429
446
  if (character === "/" && next === "*") {
430
- characters.push(" ", " ");
431
- if (!templateCode && source[offset + 2] === "*") {
432
- const column = offset - start;
433
- const width = jsdocCharacters.join("").length;
434
- jsdocCharacters.push(" ".repeat(column - width), "/", "*");
435
- jsdoc = true;
436
- jsdocPresent = true;
437
- }
438
- offset += 1;
439
- blockTemplate = templateCode;
440
- mode = templateCode ? "templateBlock" : "block";
441
- continue;
442
- }
443
- if (character === "'") {
444
- characters.push(templateCode ? " " : character);
445
- mode = templateCode ? "templateSingle" : "single";
446
- escaped = false;
447
- separated = false;
448
- restricted = void 0;
449
- continue;
450
- }
451
- if (character === "\"") {
452
- characters.push(templateCode ? " " : character);
453
- mode = templateCode ? "templateDouble" : "double";
454
- escaped = false;
455
- separated = false;
456
- restricted = void 0;
457
- continue;
447
+ const jsdoc = !template && source[offset + 2] === "*";
448
+ tokens.push({
449
+ code: " ",
450
+ ...jsdoc ? { jsdoc: "/*" } : {}
451
+ });
452
+ return {
453
+ ...state,
454
+ offset: offset + 2,
455
+ block: template,
456
+ mode: template ? "templateBlock" : "block",
457
+ jsdoc: jsdoc || state.jsdoc,
458
+ present: jsdoc || state.present
459
+ };
458
460
  }
459
- if (character === "`") {
460
- characters.push(" ");
461
- templates.push(0);
462
- mode = "template";
463
- escaped = false;
464
- separated = false;
465
- restricted = void 0;
466
- continue;
461
+ if (character === "'" || character === "\"" || character === "`") {
462
+ tokens.push({ code: template || character === "`" ? " " : character });
463
+ return {
464
+ ...state,
465
+ mode: character === "`" ? "template" : character === "'" ? template ? "templateSingle" : "single" : template ? "templateDouble" : "double",
466
+ templates: character === "`" ? {
467
+ depth: 0,
468
+ previous: state.templates
469
+ } : state.templates,
470
+ escaped: false,
471
+ separated: false,
472
+ restricted: void 0
473
+ };
467
474
  }
468
- const visible = templateCode ? " " : character;
469
- if (character === "/" && next === "=" && !operandExpected) {
470
- characters.push(visible, templateCode ? " " : "=");
471
- offset += 1;
472
- operandExpected = true;
473
- memberExpected = false;
474
- pendingRole = void 0;
475
- separated = false;
476
- restricted = void 0;
477
- continue;
475
+ const visible = template ? " " : character;
476
+ if (character === "/" && next === "=" && !state.operand) {
477
+ tokens.push({ code: template ? " " : "/=" });
478
+ return {
479
+ ...state,
480
+ offset: offset + 2,
481
+ operand: true,
482
+ member: false,
483
+ role: void 0,
484
+ separated: false,
485
+ restricted: void 0
486
+ };
478
487
  }
479
488
  if (character === "/") {
480
- characters.push(visible);
481
- if (operandExpected) {
482
- mode = templateCode ? "templateRegex" : "regex";
483
- escaped = false;
484
- regexClass = false;
485
- } else {
486
- operandExpected = true;
487
- memberExpected = false;
488
- pendingRole = void 0;
489
- }
490
- separated = false;
491
- restricted = void 0;
492
- continue;
489
+ tokens.push({ code: visible });
490
+ return state.operand ? {
491
+ ...state,
492
+ mode: template ? "templateRegex" : "regex",
493
+ escaped: false,
494
+ regex: false,
495
+ separated: false,
496
+ restricted: void 0
497
+ } : {
498
+ ...state,
499
+ operand: true,
500
+ member: false,
501
+ role: void 0,
502
+ separated: false,
503
+ restricted: void 0
504
+ };
493
505
  }
494
506
  identifier.lastIndex = offset;
495
- const identifierMatch = identifier.exec(source);
496
- if (identifierMatch !== null) {
497
- const token = identifierMatch[0];
498
- characters.push(templateCode ? " ".repeat(token.length) : token);
499
- if (token.startsWith("#")) {
500
- operandExpected = false;
501
- memberExpected = false;
502
- pendingRole = void 0;
503
- restricted = void 0;
504
- separated = false;
505
- offset += token.length - 1;
506
- continue;
507
- }
508
- const frame = parentheses[parentheses.length - 1];
509
- const label = restricted === "label";
510
- restricted = void 0;
511
- separated = false;
512
- if (memberExpected) {
513
- memberExpected = false;
514
- operandExpected = false;
515
- pendingRole = void 0;
516
- } else if (label) {
517
- operandExpected = false;
518
- pendingRole = void 0;
519
- restricted = "complete";
520
- } else if (/^(?:if|while|with)$/.test(token)) {
521
- pendingRole = "statement";
522
- operandExpected = true;
523
- } else if (token === "for") {
524
- pendingRole = "for";
525
- operandExpected = true;
526
- } else if (token === "export") {
527
- pendingRole = "export";
528
- operandExpected = true;
529
- } else if (token === "default" && pendingRole === "export") {
530
- pendingRole = void 0;
531
- operandExpected = true;
532
- } else if (/^(?:switch|catch)$/.test(token)) {
533
- pendingRole = "block";
534
- operandExpected = true;
535
- } else if (token === "await" && pendingRole === "for") operandExpected = true;
536
- else if (/^(?:return|throw|case|delete|void|typeof|new|await|yield|else|do|extends)$/.test(token)) {
537
- pendingRole = void 0;
538
- operandExpected = true;
539
- } else if (/^(?:in|instanceof)$/.test(token)) {
540
- pendingRole = void 0;
541
- operandExpected = true;
542
- } else if (/^(?:break|continue)$/.test(token)) {
543
- pendingRole = void 0;
544
- operandExpected = false;
545
- restricted = "label";
546
- } else if (token === "debugger") {
547
- pendingRole = void 0;
548
- operandExpected = false;
549
- restricted = "complete";
550
- } else if (token === "of" && frame?.role === "for" && frame.phase === "left" && !frame.binding && !operandExpected) {
551
- frame.phase = "right";
552
- operandExpected = true;
553
- pendingRole = void 0;
554
- } else if (/^(?:const|let|var)$/.test(token) && frame?.role === "for" && frame.phase === "left") {
555
- frame.binding = true;
556
- operandExpected = true;
557
- pendingRole = void 0;
558
- } else {
559
- if (frame?.binding === true) frame.binding = false;
560
- operandExpected = false;
561
- pendingRole = void 0;
562
- }
563
- offset += token.length - 1;
564
- continue;
507
+ const matched = identifier.exec(source);
508
+ if (matched !== null) {
509
+ const token = matched[0];
510
+ tokens.push({ code: template ? " ".repeat(token.length) : token });
511
+ const stepped = {
512
+ ...state,
513
+ offset: offset + token.length,
514
+ restricted: void 0,
515
+ separated: false
516
+ };
517
+ const frame = state.parentheses;
518
+ if (token.startsWith("#")) return {
519
+ ...stepped,
520
+ operand: false,
521
+ member: false,
522
+ role: void 0
523
+ };
524
+ if (state.member) return {
525
+ ...stepped,
526
+ member: false,
527
+ operand: false,
528
+ role: void 0
529
+ };
530
+ if (state.restricted === "label") return {
531
+ ...stepped,
532
+ operand: false,
533
+ role: void 0,
534
+ restricted: "complete"
535
+ };
536
+ if (/^(?:if|while|with)$/.test(token)) return {
537
+ ...stepped,
538
+ role: "statement",
539
+ operand: true
540
+ };
541
+ if (token === "for") return {
542
+ ...stepped,
543
+ role: "for",
544
+ operand: true
545
+ };
546
+ if (token === "export") return {
547
+ ...stepped,
548
+ role: "export",
549
+ operand: true
550
+ };
551
+ if (token === "default" && state.role === "export") return {
552
+ ...stepped,
553
+ role: void 0,
554
+ operand: true
555
+ };
556
+ if (/^(?:switch|catch)$/.test(token)) return {
557
+ ...stepped,
558
+ role: "block",
559
+ operand: true
560
+ };
561
+ if (token === "await" && state.role === "for") return {
562
+ ...stepped,
563
+ operand: true
564
+ };
565
+ if (/^(?:return|throw|case|delete|void|typeof|new|await|yield|else|do|extends|in|instanceof)$/.test(token)) return {
566
+ ...stepped,
567
+ role: void 0,
568
+ operand: true
569
+ };
570
+ if (/^(?:break|continue)$/.test(token)) return {
571
+ ...stepped,
572
+ role: void 0,
573
+ operand: false,
574
+ restricted: "label"
575
+ };
576
+ if (token === "debugger") return {
577
+ ...stepped,
578
+ role: void 0,
579
+ operand: false,
580
+ restricted: "complete"
581
+ };
582
+ if (token === "of" && frame?.role === "for" && frame.phase === "left" && !frame.binding && !state.operand) return {
583
+ ...stepped,
584
+ parentheses: {
585
+ ...frame,
586
+ phase: "right"
587
+ },
588
+ operand: true,
589
+ role: void 0
590
+ };
591
+ if (/^(?:const|let|var)$/.test(token) && frame?.role === "for" && frame.phase === "left") return {
592
+ ...stepped,
593
+ parentheses: {
594
+ ...frame,
595
+ binding: true
596
+ },
597
+ operand: true,
598
+ role: void 0
599
+ };
600
+ return {
601
+ ...stepped,
602
+ parentheses: frame?.binding === true ? {
603
+ ...frame,
604
+ binding: false
605
+ } : frame,
606
+ operand: false,
607
+ role: void 0
608
+ };
565
609
  }
566
610
  if (/[0-9]/.test(character)) {
567
- let end = offset + 1;
568
- while (end < source.length) {
569
- const part = source[end];
570
- if (part === void 0 || !/[A-Za-z0-9_$.]/.test(part)) break;
571
- end += 1;
572
- }
573
- const token = source.slice(offset, end);
574
- characters.push(templateCode ? " ".repeat(token.length) : token);
575
- operandExpected = false;
576
- memberExpected = false;
577
- pendingRole = void 0;
578
- restricted = void 0;
579
- separated = false;
580
- offset = end - 1;
581
- continue;
582
- }
583
- if (character === "!" && next === "=" && source[offset + 2] === "=" || character === "=" && next === "=" && source[offset + 2] === "=") {
584
- characters.push(visible, templateCode ? " " : source.slice(offset + 1, offset + 3));
585
- offset += 2;
586
- operandExpected = true;
587
- memberExpected = false;
588
- pendingRole = void 0;
589
- restricted = void 0;
590
- separated = false;
591
- continue;
611
+ numeric.lastIndex = offset;
612
+ const token = numeric.exec(source)?.[0] ?? character;
613
+ tokens.push({ code: template ? " ".repeat(token.length) : token });
614
+ return {
615
+ ...state,
616
+ offset: offset + token.length,
617
+ operand: false,
618
+ member: false,
619
+ role: void 0,
620
+ restricted: void 0,
621
+ separated: false
622
+ };
592
623
  }
593
624
  if ((character === "!" || character === "=") && next === "=") {
594
- characters.push(visible, templateCode ? " " : "=");
595
- offset += 1;
596
- operandExpected = true;
597
- memberExpected = false;
598
- pendingRole = void 0;
599
- restricted = void 0;
600
- separated = false;
601
- continue;
625
+ const width = source[offset + 2] === "=" ? 3 : 2;
626
+ tokens.push({ code: template ? " ".repeat(width) : source.slice(offset, offset + width) });
627
+ return {
628
+ ...state,
629
+ offset: offset + width,
630
+ operand: true,
631
+ member: false,
632
+ role: void 0,
633
+ restricted: void 0,
634
+ separated: false
635
+ };
602
636
  }
603
637
  if (character === "+" && next === "+" || character === "-" && next === "-") {
604
- characters.push(visible, templateCode ? " " : next);
605
- offset += 1;
606
- if (separated) operandExpected = true;
607
- memberExpected = false;
608
- pendingRole = void 0;
609
- restricted = void 0;
610
- separated = false;
611
- continue;
638
+ tokens.push({ code: template ? " " : character + next });
639
+ return {
640
+ ...state,
641
+ offset: offset + 2,
642
+ operand: state.separated ? true : state.operand,
643
+ member: false,
644
+ role: void 0,
645
+ restricted: void 0,
646
+ separated: false
647
+ };
612
648
  }
613
649
  if (character === "." && next === "." && source[offset + 2] === ".") {
614
- characters.push(visible, templateCode ? " " : "..");
615
- offset += 2;
616
- operandExpected = true;
617
- memberExpected = false;
618
- pendingRole = void 0;
619
- restricted = void 0;
620
- separated = false;
621
- continue;
650
+ tokens.push({ code: template ? " " : "..." });
651
+ return {
652
+ ...state,
653
+ offset: offset + 3,
654
+ operand: true,
655
+ member: false,
656
+ role: void 0,
657
+ restricted: void 0,
658
+ separated: false
659
+ };
622
660
  }
623
661
  if (character === "?" && next === ".") {
624
- characters.push(visible, templateCode ? " " : ".");
625
- offset += 1;
626
- operandExpected = false;
627
- memberExpected = true;
628
- pendingRole = void 0;
629
- restricted = void 0;
630
- separated = false;
631
- continue;
662
+ tokens.push({ code: template ? " " : "?." });
663
+ return {
664
+ ...state,
665
+ offset: offset + 2,
666
+ operand: false,
667
+ member: true,
668
+ role: void 0,
669
+ restricted: void 0,
670
+ separated: false
671
+ };
632
672
  }
633
- characters.push(visible);
634
- if (/\s/.test(character)) continue;
635
- separated = false;
636
- restricted = void 0;
637
- if (character === "(") {
638
- parentheses.push({
639
- role: pendingRole ?? "plain",
673
+ tokens.push({ code: visible });
674
+ if (/\s/.test(character)) return state;
675
+ const stepped = {
676
+ ...state,
677
+ separated: false,
678
+ restricted: void 0,
679
+ role: void 0,
680
+ member: false
681
+ };
682
+ const frame = state.parentheses;
683
+ if (character === "(") return {
684
+ ...stepped,
685
+ parentheses: {
686
+ role: state.role ?? "plain",
640
687
  phase: "left",
641
- binding: false
642
- });
643
- operandExpected = true;
644
- memberExpected = false;
645
- pendingRole = void 0;
646
- continue;
647
- }
648
- if (character === ")") {
649
- const frame = parentheses.pop();
650
- operandExpected = frame?.role === "statement" || frame?.role === "for";
651
- memberExpected = false;
652
- pendingRole = void 0;
653
- continue;
654
- }
655
- if (character === ";") {
656
- const frame = parentheses[parentheses.length - 1];
657
- if (frame?.role === "for" && frame.phase === "left") frame.phase = "classic";
658
- operandExpected = true;
659
- memberExpected = false;
660
- pendingRole = void 0;
661
- continue;
662
- }
663
- if (character === ".") {
664
- operandExpected = false;
665
- memberExpected = true;
666
- pendingRole = void 0;
667
- continue;
668
- }
669
- if (character === "]" || character === "}") {
670
- const frame = parentheses[parentheses.length - 1];
671
- if (frame?.role === "for" && frame.phase === "left" && frame.binding) frame.binding = false;
672
- }
673
- if (character === "]") operandExpected = false;
674
- else if (character === "}") {
675
- const index = templates.length - 1;
676
- const depth = templates[index];
677
- if (templateCode && index >= 0 && depth !== void 0) {
678
- templates[index] = depth - 1;
679
- if (depth === 1) mode = "template";
680
- }
681
- operandExpected = false;
682
- } else if (character === "{") {
683
- const index = templates.length - 1;
684
- const depth = templates[index];
685
- if (templateCode && index >= 0 && depth !== void 0) templates[index] = depth + 1;
686
- operandExpected = true;
687
- } else if (character !== "!") operandExpected = true;
688
- memberExpected = false;
689
- pendingRole = void 0;
690
- }
691
- const code = characters.join("");
692
- const present = jsdocPresent || jsdoc;
688
+ binding: false,
689
+ previous: frame
690
+ },
691
+ operand: true
692
+ };
693
+ if (character === ")") return {
694
+ ...stepped,
695
+ parentheses: frame?.previous,
696
+ operand: frame?.role === "statement" || frame?.role === "for"
697
+ };
698
+ if (character === ";") return {
699
+ ...stepped,
700
+ parentheses: frame?.role === "for" && frame.phase === "left" ? {
701
+ ...frame,
702
+ phase: "classic"
703
+ } : frame,
704
+ operand: true
705
+ };
706
+ if (character === ".") return {
707
+ ...stepped,
708
+ operand: false,
709
+ member: true
710
+ };
711
+ const parentheses = (character === "]" || character === "}") && frame?.role === "for" && frame.phase === "left" && frame.binding ? {
712
+ ...frame,
713
+ binding: false
714
+ } : frame;
715
+ if (character === "]") return {
716
+ ...stepped,
717
+ parentheses,
718
+ operand: false
719
+ };
720
+ const top = state.templates;
721
+ if (character === "}") return {
722
+ ...stepped,
723
+ parentheses,
724
+ operand: false,
725
+ templates: template && top !== void 0 ? {
726
+ ...top,
727
+ depth: top.depth - 1
728
+ } : top,
729
+ mode: template && top?.depth === 1 ? "template" : state.mode
730
+ };
731
+ if (character === "{") return {
732
+ ...stepped,
733
+ parentheses,
734
+ operand: true,
735
+ templates: template && top !== void 0 ? {
736
+ ...top,
737
+ depth: top.depth + 1
738
+ } : top
739
+ };
740
+ return {
741
+ ...stepped,
742
+ parentheses,
743
+ operand: character !== "!" ? true : state.operand
744
+ };
745
+ }, {
746
+ offset: 0,
747
+ start: 0,
748
+ token: 0,
749
+ mode: "code",
750
+ escaped: false,
751
+ regex: false,
752
+ operand: true,
753
+ member: false,
754
+ role: void 0,
755
+ restricted: void 0,
756
+ separated: false,
757
+ block: false,
758
+ line: false,
759
+ jsdoc: false,
760
+ present: false,
761
+ parentheses: void 0,
762
+ templates: void 0
763
+ });
764
+ const parts = tokens.slice(final.token);
765
+ const code = parts.map((part) => part.code).join("");
693
766
  lines.push({
694
- source: source.slice(start),
767
+ source: source.slice(final.start),
695
768
  code,
696
- jsdoc: present ? jsdocCharacters.join("").padEnd(code.length, " ") : void 0
769
+ jsdoc: final.present || final.jsdoc ? parts.map((part) => part.jsdoc ?? " ".repeat(part.code.length)).join("") : void 0
697
770
  });
698
771
  return lines;
699
772
  }
@@ -845,7 +918,7 @@ function findUnlisted(fences, languages) {
845
918
  *
846
919
  * @example
847
920
  * ```ts
848
- * findMissingSymbols([{ name: 'X', keyword: 'class' }], []) // ['class X']
921
+ * findMissingSymbols([{ name: 'X', keyword: 'class', signature: '`new () => X`' }], []) // ['class X']
849
922
  * ```
850
923
  */
851
924
  function findMissingSymbols(symbols, source) {
@@ -909,9 +982,7 @@ function findUnexampled(names, fences, examples) {
909
982
  */
910
983
  function extractFenceImports(fence) {
911
984
  const results = [];
912
- const pattern = /import\s+(?:type\s+)?\{([^}]*)\}\s*from\s*['"]([^'"]+)['"]/gs;
913
- let match;
914
- while ((match = pattern.exec(fence)) !== null) {
985
+ for (const match of fence.matchAll(/import\s+(?:type\s+)?\{([^}]*)\}\s*from\s*['"]([^'"]+)['"]/gs)) {
915
986
  const body = match[1];
916
987
  const specifier = match[2];
917
988
  if (body === void 0 || specifier === void 0) continue;
@@ -1068,11 +1139,11 @@ function normalizeIdentifier(code) {
1068
1139
  * ```
1069
1140
  */
1070
1141
  function extractCellText(cell) {
1071
- let text = "";
1072
- for (const node of cell) if ((0, _orkestrel_markdown.isCodeSpanNode)(node)) text += `\`${node.value}\``;
1073
- else if ((0, _orkestrel_markdown.isEmphasisNode)(node) || (0, _orkestrel_markdown.isLinkNode)(node) || (0, _orkestrel_markdown.isImageNode)(node)) text += extractCellText(node.children);
1074
- else text += (0, _orkestrel_markdown.flattenText)(node);
1075
- return text;
1142
+ return Iterator.from(cell).map((node) => {
1143
+ if ((0, _orkestrel_markdown.isCodeSpanNode)(node)) return `\`${node.value}\``;
1144
+ if ((0, _orkestrel_markdown.isEmphasisNode)(node) || (0, _orkestrel_markdown.isLinkNode)(node) || (0, _orkestrel_markdown.isImageNode)(node)) return extractCellText(node.children);
1145
+ return (0, _orkestrel_markdown.flattenText)(node);
1146
+ }).toArray().join("");
1076
1147
  }
1077
1148
  /**
1078
1149
  * Builds one table cell's inline content from its compared text — the inverse of
@@ -1101,26 +1172,22 @@ function extractCellText(cell) {
1101
1172
  */
1102
1173
  function buildCell(text) {
1103
1174
  const nodes = [];
1104
- const spans = /`([^`]+)`/g;
1105
- let cursor = 0;
1106
- let span;
1107
- while ((span = spans.exec(text)) !== null) {
1175
+ const cursor = Iterator.from(text.matchAll(/`([^`]+)`/g)).reduce((previous, span) => {
1108
1176
  const value = span[1];
1109
- if (value === void 0) continue;
1110
- if (span.index > cursor) nodes.push({
1177
+ if (value === void 0) return previous;
1178
+ if (span.index > previous) nodes.push({
1111
1179
  element: "text",
1112
- value: text.slice(cursor, span.index)
1180
+ value: text.slice(previous, span.index)
1113
1181
  });
1114
- if (value.trim() === value) nodes.push({
1182
+ nodes.push(value.trim() === value ? {
1115
1183
  element: "codeSpan",
1116
1184
  value
1117
- });
1118
- else nodes.push({
1185
+ } : {
1119
1186
  element: "text",
1120
1187
  value: span[0]
1121
1188
  });
1122
- cursor = span.index + span[0].length;
1123
- }
1189
+ return span.index + span[0].length;
1190
+ }, 0);
1124
1191
  if (cursor < text.length) nodes.push({
1125
1192
  element: "text",
1126
1193
  value: text.slice(cursor)
@@ -1144,7 +1211,7 @@ function buildCell(text) {
1144
1211
  * ```
1145
1212
  */
1146
1213
  function findColumnIndex(table, header) {
1147
- for (let index = 0; index < table.header.length; index += 1) {
1214
+ for (const index of table.header.keys()) {
1148
1215
  const cell = table.header[index];
1149
1216
  if (cell !== void 0 && (0, _orkestrel_markdown.flattenText)({
1150
1217
  element: "paragraph",
@@ -1245,6 +1312,293 @@ function extractHidden(source) {
1245
1312
  return symbols;
1246
1313
  }
1247
1314
  /**
1315
+ * Computes the bracket depth of every character of projected declaration code: an opening `(`,
1316
+ * `[`, `{`, or `<` and its closing partner carry the depth outside the pair, the characters
1317
+ * between them one more, and every character of a quoted string, its quotes included, `-1`.
1318
+ *
1319
+ * @remarks
1320
+ * The `>` of an `=>` arrow closes nothing. A backslash escapes the next character inside a
1321
+ * quoted string. Template literal text is outside the reading, because
1322
+ * {@link extractSourceLines} masks it to spaces in the code this function reads.
1323
+ *
1324
+ * @param code - The projected code of one declaration
1325
+ * @returns One depth per UTF-16 code unit of `code`
1326
+ *
1327
+ * @example
1328
+ * ```ts
1329
+ * computeDepths("f(a, 'b')") // [0, 0, 1, 1, 1, -1, -1, -1, 0]
1330
+ * ```
1331
+ */
1332
+ function computeDepths(code) {
1333
+ const depths = [];
1334
+ code.split("").reduce((state, character, index) => {
1335
+ if (state.quote !== void 0) {
1336
+ depths.push(-1);
1337
+ if (state.escaped) return {
1338
+ ...state,
1339
+ escaped: false
1340
+ };
1341
+ if (character === "\\") return {
1342
+ ...state,
1343
+ escaped: true
1344
+ };
1345
+ return character === state.quote ? {
1346
+ ...state,
1347
+ quote: void 0
1348
+ } : state;
1349
+ }
1350
+ if (character === "'" || character === "\"") {
1351
+ depths.push(-1);
1352
+ return {
1353
+ ...state,
1354
+ quote: character
1355
+ };
1356
+ }
1357
+ if (")]}".includes(character) || character === ">" && code[index - 1] !== "=") {
1358
+ const depth = Math.max(0, state.depth - 1);
1359
+ depths.push(depth);
1360
+ return {
1361
+ ...state,
1362
+ depth
1363
+ };
1364
+ }
1365
+ depths.push(state.depth);
1366
+ return "([{<".includes(character) ? {
1367
+ ...state,
1368
+ depth: state.depth + 1
1369
+ } : state;
1370
+ }, {
1371
+ depth: 0,
1372
+ quote: void 0,
1373
+ escaped: false
1374
+ });
1375
+ return depths;
1376
+ }
1377
+ /**
1378
+ * Finds the index of the bracket closing the opener at `start`: the first later character whose
1379
+ * {@link computeDepths} depth equals the opener's.
1380
+ *
1381
+ * @param depths - The depths {@link computeDepths} returned for the code
1382
+ * @param start - The index of an opening `(`, `[`, `{`, or `<`
1383
+ * @returns The closing bracket's index, or `undefined` when the opener never closes
1384
+ *
1385
+ * @example
1386
+ * ```ts
1387
+ * findClosing(computeDepths('<T>(x: T)'), 3) // 8
1388
+ * ```
1389
+ */
1390
+ function findClosing(depths, start) {
1391
+ const depth = depths[start];
1392
+ if (depth === void 0 || depth < 0) return void 0;
1393
+ const index = depths.findIndex((value, position) => position > start && value === depth);
1394
+ return index < 0 ? void 0 : index;
1395
+ }
1396
+ /**
1397
+ * Finds every index at which `separator` sits at `depth` outside quoted text, in code order.
1398
+ *
1399
+ * @param code - The projected code to search
1400
+ * @param depths - The depths {@link computeDepths} returned for `code`
1401
+ * @param separator - The single character to find
1402
+ * @param depth - The bracket depth the separator must sit at
1403
+ * @returns The separator indices, in code order
1404
+ *
1405
+ * @example
1406
+ * ```ts
1407
+ * findSeparators('a, f(b, c)', computeDepths('a, f(b, c)'), ',', 0) // [1]
1408
+ * ```
1409
+ */
1410
+ function findSeparators(code, depths, separator, depth) {
1411
+ return depths.keys().filter((index) => depths[index] === depth && code[index] === separator).toArray();
1412
+ }
1413
+ /**
1414
+ * Renders one emitted interface member as its signature entry: a property as its name, an
1415
+ * optional one with `?`, a method as `name()` or `name?()`, an accessor as its name, and a call,
1416
+ * construct, or index signature as its own text with whitespace collapsed.
1417
+ *
1418
+ * @remarks
1419
+ * `code` is the member's projected code and `source` its text at the same columns, both without
1420
+ * the terminating `;`. A leading `readonly` modifier never enters a name. A computed name keeps
1421
+ * its brackets, and a quoted name keeps its quotes.
1422
+ *
1423
+ * @param code - The member's projected code
1424
+ * @param source - The member's source text, aligned with `code`
1425
+ * @returns The member's entry, or `undefined` when the member is empty
1426
+ *
1427
+ * @example
1428
+ * ```ts
1429
+ * renderMember('readonly name?: string', 'readonly name?: string') // 'name?'
1430
+ * renderMember('walk(depth: number): void', 'walk(depth: number): void') // 'walk()'
1431
+ * renderMember('[key: string]: number', '[key: string]: number') // '[key: string]: number'
1432
+ * ```
1433
+ */
1434
+ function renderMember(code, source) {
1435
+ const text = source.replace(/\s+/g, " ").trim();
1436
+ if (text.length === 0) return void 0;
1437
+ const leading = code.length - code.trimStart().length;
1438
+ const modifier = leading + (/^readonly\s+/.exec(code.slice(leading))?.[0].length ?? 0);
1439
+ const rest = code.slice(modifier);
1440
+ if (/^(?:new\s*)?[(<]/.test(rest)) return text;
1441
+ const depths = computeDepths(rest);
1442
+ const bracket = rest.startsWith("[") ? findClosing(depths, 0) : void 0;
1443
+ if (bracket !== void 0 && findSeparators(rest, depths, ":", 1).some((index) => index < bracket)) return text;
1444
+ const accessor = /^(?:get|set)\s+(?=[^\s(:?<])/.exec(rest)?.[0].length ?? 0;
1445
+ const named = rest.slice(accessor);
1446
+ const computed = named.startsWith("[") ? findClosing(computeDepths(named), 0) : void 0;
1447
+ const length = computed === void 0 ? /^(?:"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|[^\s?(:<]+)/.exec(named)?.[0].length ?? 0 : computed + 1;
1448
+ if (length === 0) return text;
1449
+ const offset = modifier + accessor;
1450
+ const tail = named.slice(length);
1451
+ const optional = tail.startsWith("?");
1452
+ const method = accessor === 0 && /^\??\s*[(<]/.test(tail);
1453
+ return `${source.slice(offset, offset + length)}${optional ? "?" : ""}${method ? "()" : ""}`;
1454
+ }
1455
+ /**
1456
+ * Extracts one emitted declaration's signature: the symbol its column-zero `export` head names,
1457
+ * carrying the type text the compiler emitted for it.
1458
+ *
1459
+ * @remarks
1460
+ * `code` is the declaration's projected code and `source` its text at the same columns, each
1461
+ * physical line trimmed and the lines joined with single spaces. The forms:
1462
+ *
1463
+ * - `function`: `<T>(params) => RET` from `NAME<T>(params): RET`.
1464
+ * - `class`: `new <T>(params) => YIELD` per `constructor(params)`, several as an intersection of
1465
+ * parenthesized signatures, none as `new <T>() => YIELD`. `YIELD` is the first `implements`
1466
+ * type, else the class's own name with its type parameter names. Every other member is ignored.
1467
+ * - `interface`: `{ entries }` from {@link renderMember} over its own members, in emitted order,
1468
+ * each entry once, or `{}` when it declares none. The `extends` clause is not read.
1469
+ * - `type`: the text after `=` to the terminating `;`, type parameters omitted.
1470
+ * - `const`: the text after `NAME:` to the `;`, or after `NAME =` for a literal the compiler
1471
+ * emitted as the constant's type.
1472
+ *
1473
+ * @param code - The declaration's projected code
1474
+ * @param source - The declaration's source text, aligned with `code`
1475
+ * @returns The declared symbol with its signature, or `undefined` when no supported head opens it
1476
+ *
1477
+ * @example
1478
+ * ```ts
1479
+ * const text = 'export declare function walk<T>(node: T): void;'
1480
+ * extractSignature(text, text) // { name: 'walk', keyword: 'function', signature: '<T>(node: T) => void' }
1481
+ * ```
1482
+ */
1483
+ function extractSignature(code, source) {
1484
+ const head = /^export (?:declare )?(?:abstract )?(function|class|interface|type|const(?! enum\b)) ([^\s<(:=;{]+)/.exec(code);
1485
+ const keyword = head?.[1];
1486
+ const name = head?.[2];
1487
+ if (head === null || name === void 0 || !isExportKeyword(keyword)) return void 0;
1488
+ const depths = computeDepths(code);
1489
+ const start = head[0].length;
1490
+ const generic = code[start] === "<" ? findClosing(depths, start) : void 0;
1491
+ const typed = generic === void 0 ? start : generic + 1;
1492
+ const generics = source.slice(start, typed);
1493
+ const end = findSeparators(code, depths, ";", 0).find((index) => index >= typed) ?? code.length;
1494
+ if (keyword === "function") {
1495
+ const close = code[typed] === "(" ? findClosing(depths, typed) : void 0;
1496
+ if (close === void 0) return void 0;
1497
+ const colon = /^\s*:/.exec(code.slice(close + 1))?.[0].length;
1498
+ if (colon === void 0) return void 0;
1499
+ const returns = source.slice(close + 1 + colon, end).trim();
1500
+ return {
1501
+ name,
1502
+ keyword,
1503
+ signature: `${generics}(${source.slice(typed + 1, close)}) => ${returns}`
1504
+ };
1505
+ }
1506
+ if (keyword === "const" || keyword === "type") {
1507
+ const assigned = (keyword === "const" ? /^\s*[:=]/ : /^\s*=/).exec(code.slice(typed));
1508
+ if (assigned === null) return void 0;
1509
+ return {
1510
+ name,
1511
+ keyword,
1512
+ signature: source.slice(typed + assigned[0].length, end).trim()
1513
+ };
1514
+ }
1515
+ const open = findSeparators(code, depths, "{", 0).find((index) => index >= typed);
1516
+ const close = open === void 0 ? void 0 : findClosing(depths, open);
1517
+ if (open === void 0 || close === void 0) return void 0;
1518
+ const boundaries = [
1519
+ open,
1520
+ ...findSeparators(code, depths, ";", 1).filter((index) => index > open && index < close),
1521
+ close
1522
+ ];
1523
+ const members = boundaries.slice(0, -1).map((boundary, position) => {
1524
+ const next = boundaries[position + 1] ?? close;
1525
+ return {
1526
+ code: code.slice(boundary + 1, next),
1527
+ source: source.slice(boundary + 1, next)
1528
+ };
1529
+ });
1530
+ if (keyword === "interface") {
1531
+ const entries = Array.from(new Set(members.map((member) => renderMember(member.code, member.source)).filter((entry) => entry !== void 0)));
1532
+ return {
1533
+ name,
1534
+ keyword,
1535
+ signature: entries.length === 0 ? "{}" : `{ ${entries.join(", ")} }`
1536
+ };
1537
+ }
1538
+ const heritage = /\bimplements\b/.exec(code.slice(typed, open));
1539
+ const implemented = heritage === null || depths[typed + heritage.index] !== 0 ? void 0 : typed + heritage.index + heritage[0].length;
1540
+ const comma = implemented === void 0 ? void 0 : findSeparators(code, depths, ",", 0).find((index) => index > implemented && index < open);
1541
+ const parameters = generic === void 0 ? [] : [start, ...findSeparators(code, depths, ",", 1).filter((index) => index < generic)].map((boundary, position, list) => /^\s*(?:(?:const|in|out)\s+)*([^\s=,>]+)/.exec(code.slice(boundary + 1, list[position + 1] ?? generic))?.[1] ?? "");
1542
+ const yielded = implemented === void 0 ? `${name}${parameters.length === 0 ? "" : `<${parameters.join(", ")}>`}` : source.slice(implemented, comma ?? open).trim();
1543
+ const constructors = members.filter((member) => /^\s*(?:(?:public|private|protected)\s+)?constructor\s*\(/.test(member.code)).map((member) => {
1544
+ const parenthesis = member.code.indexOf("(");
1545
+ const closed = findClosing(computeDepths(member.code), parenthesis) ?? member.code.length;
1546
+ return `new ${generics}(${member.source.slice(parenthesis + 1, closed)}) => ${yielded}`;
1547
+ });
1548
+ return {
1549
+ name,
1550
+ keyword,
1551
+ signature: constructors.length === 0 ? `new ${generics}() => ${yielded}` : constructors.length === 1 ? constructors[0] ?? "" : constructors.map((entry) => `(${entry})`).join(" & ")
1552
+ };
1553
+ }
1554
+ /**
1555
+ * Extracts every signature one compiler-emitted declaration file declares: each column-zero
1556
+ * `export` head read through {@link extractSignature}, an overload set's emitted heads joined in
1557
+ * order as an intersection of parenthesized signatures.
1558
+ *
1559
+ * @remarks
1560
+ * The text is read through {@link extractSourceLines}, so comment and template payload never
1561
+ * opens or closes a bracket. Each physical line is trimmed and a declaration's lines are joined
1562
+ * with single spaces, so a multi-line emitted type reads as one line. A head the projector does
1563
+ * not support, such as an `enum` or a re-export, contributes nothing. Every other repeated head
1564
+ * keeps its first signature.
1565
+ *
1566
+ * @param declaration - The emitted `.d.ts` text
1567
+ * @returns The declared symbols with their signatures, in first-seen order
1568
+ *
1569
+ * @example
1570
+ * ```ts
1571
+ * extractSignatures('export declare function open(id: string): boolean;\nexport declare function open(ids: readonly string[]): boolean;\n')
1572
+ * // [{ name: 'open', keyword: 'function', signature: '((id: string) => boolean) & ((ids: readonly string[]) => boolean)' }]
1573
+ * ```
1574
+ */
1575
+ function extractSignatures(declaration) {
1576
+ const records = extractSourceLines(declaration).map((line) => {
1577
+ const start = line.code.length - line.code.trimStart().length;
1578
+ const end = line.code.trimEnd().length;
1579
+ return {
1580
+ code: line.code.slice(start, end),
1581
+ source: line.source.slice(start, end),
1582
+ head: start === 0 && line.code.startsWith("export ")
1583
+ };
1584
+ }).filter((record) => record.code.length > 0);
1585
+ const heads = records.keys().filter((index) => records[index]?.head === true).toArray();
1586
+ const symbols = heads.map((head, position) => {
1587
+ const segment = records.slice(head, heads[position + 1] ?? records.length);
1588
+ return extractSignature(segment.map((record) => record.code).join(" "), segment.map((record) => record.source).join(" "));
1589
+ }).filter((symbol) => symbol !== void 0);
1590
+ return Array.from(new Set(symbols.map(computeSymbolKey))).flatMap((key) => {
1591
+ const declared = symbols.filter((symbol) => computeSymbolKey(symbol) === key);
1592
+ const [first] = declared;
1593
+ if (first === void 0) return [];
1594
+ if (first.keyword !== "function" || declared.length === 1) return [first];
1595
+ return [{
1596
+ ...first,
1597
+ signature: declared.map((symbol) => `(${symbol.signature ?? ""})`).join(" & ")
1598
+ }];
1599
+ });
1600
+ }
1601
+ /**
1248
1602
  * Joins the declaration head starting at `start` into one space-separated
1249
1603
  * line, consuming lines until the first that opens a body: one that ends with
1250
1604
  * `{`, or one that closes an empty body with `{}` or `{ }`.
@@ -1267,7 +1621,10 @@ function extractHidden(source) {
1267
1621
  */
1268
1622
  function joinHead(lines, start) {
1269
1623
  const parts = [];
1270
- for (let index = start; index < lines.length; index += 1) {
1624
+ for (const distance of Array.prototype.keys.call({ get length() {
1625
+ return Math.max(0, Math.ceil(lines.length - start));
1626
+ } })) {
1627
+ const index = start + distance;
1271
1628
  const line = lines[index];
1272
1629
  if (line === void 0) break;
1273
1630
  const text = line.trimEnd();
@@ -1343,7 +1700,7 @@ function collectDeclarations(source) {
1343
1700
  const grammar = /^export (class|interface) ([^\s<]+)(?:<.*>)?(?: .*)? \{(?:\s*\})?$/;
1344
1701
  const lines = extractSourceLines(source);
1345
1702
  const projected = lines.map((line) => line.code);
1346
- for (let index = 0; index < projected.length; index += 1) {
1703
+ for (const index of projected.keys()) {
1347
1704
  const line = projected[index];
1348
1705
  if (line === void 0 || !opener.test(line)) continue;
1349
1706
  const head = joinHead(projected, index);
@@ -1355,12 +1712,14 @@ function collectDeclarations(source) {
1355
1712
  const key = `${keyword} ${name}`;
1356
1713
  const known = declarations.get(key);
1357
1714
  if (known !== void 0 && (known.body.length > 0 || known.bases.length > 0)) continue;
1358
- let depth = 0;
1359
- let flat = "";
1360
- for (const character of head.text.slice(`export ${key}`.length, head.text.lastIndexOf("{"))) if (character === "<") depth += 1;
1361
- else if (character === ">") depth = Math.max(0, depth - 1);
1362
- else if (depth === 0) flat += character;
1363
- const clause = flat.replace(/\bimplements\b[\s\S]*$/, "").match(/\bextends\b([\s\S]*)$/)?.[1];
1715
+ const visible = [];
1716
+ Iterator.from(head.text.slice(`export ${key}`.length, head.text.lastIndexOf("{"))).reduce((depth, character) => {
1717
+ if (character === "<") return depth + 1;
1718
+ if (character === ">") return Math.max(0, depth - 1);
1719
+ if (depth === 0) visible.push(character);
1720
+ return depth;
1721
+ }, 0);
1722
+ const clause = visible.join("").replace(/\bimplements\b[\s\S]*$/, "").match(/\bextends\b([\s\S]*)$/)?.[1];
1364
1723
  const bases = clause === void 0 ? [] : clause.split(",").map((base) => base.trim()).filter(_orkestrel_contract.isNonEmptyString);
1365
1724
  if (head.text.endsWith("}")) {
1366
1725
  declarations.set(key, {
@@ -1369,14 +1728,11 @@ function collectDeclarations(source) {
1369
1728
  });
1370
1729
  continue;
1371
1730
  }
1372
- for (let close = head.end + 1; close < projected.length; close += 1) {
1373
- if (projected[close] !== "}") continue;
1374
- declarations.set(key, {
1375
- body: lines.slice(head.end + 1, close).map((record) => record.source),
1376
- bases
1377
- });
1378
- break;
1379
- }
1731
+ const close = Array.prototype.keys.call({ length: projected.length - head.end - 1 }).map((distance) => head.end + 1 + distance).find((candidate) => projected[candidate] === "}");
1732
+ if (close !== void 0) declarations.set(key, {
1733
+ body: lines.slice(head.end + 1, close).map((record) => record.source),
1734
+ bases
1735
+ });
1380
1736
  }
1381
1737
  return declarations;
1382
1738
  }
@@ -1461,24 +1817,123 @@ function extractMemberMethods(lines) {
1461
1817
  * ```
1462
1818
  */
1463
1819
  function selectSectionBlocks(document, heading) {
1464
- const blocks = [];
1465
- let active = false;
1820
+ const scanned = [];
1466
1821
  for (const block of document.children) {
1822
+ const active = scanned.at(-1)?.active ?? false;
1467
1823
  if ((0, _orkestrel_markdown.isHeadingNode)(block) && block.level <= 2) {
1468
1824
  if (block.level === 2 && (0, _orkestrel_markdown.flattenText)(block).trim() === heading) {
1469
- active = true;
1825
+ scanned.push({
1826
+ block,
1827
+ active: true,
1828
+ heading: true
1829
+ });
1470
1830
  continue;
1471
1831
  }
1472
1832
  if (active) break;
1473
1833
  }
1474
- if (active) blocks.push(block);
1834
+ scanned.push({
1835
+ block,
1836
+ active,
1837
+ heading: false
1838
+ });
1475
1839
  }
1476
- return blocks;
1840
+ return scanned.filter((entry) => entry.active && !entry.heading).map((entry) => entry.block);
1841
+ }
1842
+ /**
1843
+ * Validates every `## Surface` table a guide carries: each header must be exactly
1844
+ * {@link SURFACE_HEADER}, and each row that keys a symbol must carry a non-empty `Signature` cell.
1845
+ *
1846
+ * @remarks
1847
+ * Reads each `## Surface` section through {@link selectSectionBlocks}, a repeated section
1848
+ * included, and refuses at the first offending table in document order, through {@link GuideError} with code
1849
+ * `header` for a nonuniform header and `signature` for a keyed empty cell. Header and row text in
1850
+ * the message is JSON-encoded and capped at 200 characters.
1851
+ *
1852
+ * @param document - The parsed guide document
1853
+ * @throws {@link GuideError} at the first nonuniform header or keyed empty Signature cell
1854
+ *
1855
+ * @example
1856
+ * ```ts
1857
+ * validateSurface(createMarkdown('## Surface\n\n| Name | Kind |\n| --- | --- |').document)
1858
+ * // throws GuideError: ## Surface table 1 has header "Name | Kind"; expected "Name | Kind | Signature | Summary".
1859
+ * ```
1860
+ */
1861
+ function validateSurface(document) {
1862
+ const expected = SURFACE_HEADER.join(" | ");
1863
+ const signed = SURFACE_HEADER.indexOf(SIGNATURE);
1864
+ const tables = new Set(document.children.flatMap((block, start) => (0, _orkestrel_markdown.isHeadingNode)(block) && block.level === 2 && (0, _orkestrel_markdown.flattenText)(block).trim() === "Surface" ? selectSectionBlocks({
1865
+ ...document,
1866
+ children: document.children.slice(start)
1867
+ }, SURFACE) : []).filter(_orkestrel_markdown.isTableNode));
1868
+ for (const [index, table] of Array.from(tables).entries()) {
1869
+ const header = table.header.map((children) => (0, _orkestrel_markdown.flattenText)({
1870
+ element: "paragraph",
1871
+ children
1872
+ }).trim());
1873
+ if (header.length !== SURFACE_HEADER.length || !SURFACE_HEADER.every((name, column) => header[column] === name)) throw new GuideError(`## Surface table ${index + 1} has header ${JSON.stringify(header.join(" | ").slice(0, 200))}; expected ${JSON.stringify(expected)}.`, "header");
1874
+ for (const position of table.rows.keys()) {
1875
+ const symbol = extractRowSymbol(table, position);
1876
+ if (symbol === void 0) continue;
1877
+ const cell = table.rows[position]?.[signed];
1878
+ if (cell !== void 0 && (0, _orkestrel_markdown.flattenText)({
1879
+ element: "paragraph",
1880
+ children: cell
1881
+ }).trim().length > 0) continue;
1882
+ throw new GuideError(`## Surface table ${index + 1} row ${position + 1} (${JSON.stringify(`${symbol.keyword} ${symbol.name}`.slice(0, 200))}) has an empty Signature cell; expected a non-empty TypeScript signature code span under ${JSON.stringify(expected)}.`, "signature");
1883
+ }
1884
+ }
1885
+ }
1886
+ /**
1887
+ * Validates that the modules one manifest entry spans declare disjoint exports: one name exported
1888
+ * from two modules, whatever its keyword, is one capability split across environments.
1889
+ *
1890
+ * @remarks
1891
+ * Each source file answers for the most specific listed module directory that contains it, so a
1892
+ * nested module listed beside its parent never collides with itself. Logic that serves several
1893
+ * environments lives once in its layer's `core` directory, such as `src/core` or `app/core`;
1894
+ * environments whose internals differ each export a distinct name. Every colliding name is
1895
+ * reported in one refusal, in key order, each with every module that declares it; name and module
1896
+ * text is JSON-encoded and capped at 200 characters.
1897
+ *
1898
+ * @param files - The workspace-relative inventory the modules are read from
1899
+ * @param module - The manifest entry's source scope
1900
+ * @throws {@link GuideError} with code `collision` naming each name and the modules that declare it
1901
+ *
1902
+ * @example
1903
+ * ```ts
1904
+ * validateModules(
1905
+ * { 'src/core/a.ts': 'export function open() {}', 'src/server/a.ts': 'export function open() {}' },
1906
+ * ['src/core', 'src/server'],
1907
+ * )
1908
+ * // throws GuideError: "open" is declared in "src/core" and "src/server"; …
1909
+ * ```
1910
+ */
1911
+ function validateModules(files, module) {
1912
+ const directories = normalizeDirectories(module);
1913
+ const declared = selectModuleKeys(files, directories).flatMap((key) => {
1914
+ const owner = directories.filter((directory) => directory === "." || key.startsWith(`${directory}/`)).reduce((current, directory) => directory.length > current.length ? directory : current, "");
1915
+ return extractExports(files[key] ?? "").map((symbol) => ({
1916
+ key: symbol.name,
1917
+ owner
1918
+ }));
1919
+ });
1920
+ const collisions = Array.from(new Set(declared.map((entry) => entry.key))).sort().map((key) => ({
1921
+ key,
1922
+ owners: directories.filter((directory) => declared.some((entry) => entry.key === key && entry.owner === directory))
1923
+ })).filter((collision) => collision.owners.length > 1);
1924
+ if (collisions.length === 0) return;
1925
+ const named = collisions.map((collision) => `${JSON.stringify(collision.key.slice(0, 200))} is declared in ${collision.owners.map((owner) => JSON.stringify(owner.slice(0, 200))).join(" and ")}`);
1926
+ const cores = Array.from(new Set(collisions.flatMap((collision) => collision.owners.filter((owner) => owner !== ".").map((owner) => `${owner.replace(/\/.*$/u, "").slice(0, 200)}/core`)))).sort();
1927
+ throw new GuideError(`${named.join("; ")}; one name exported from two environments is a conflict. Declare logic both environments share once in ${cores.join(" or ")}, and give each environment's own logic a distinct name.`, "collision", { context: { collisions: collisions.map((collision) => ({
1928
+ name: collision.key,
1929
+ modules: collision.owners
1930
+ })) } });
1477
1931
  }
1478
1932
  /**
1479
1933
  * Extracts one `## Surface` table row's symbol — its column 0 code span as the name, its
1480
- * {@link KIND} column as the keyword, and its {@link SUMMARY} column as the compared summary
1481
- * when the table has that column. A row with no code-span name and a row whose `Kind` text is
1934
+ * {@link KIND} column as the keyword, and its exact `Signature` and {@link SUMMARY} columns as
1935
+ * normalized text when those columns exist. Empty cells remain absent. A row with no code-span
1936
+ * name and a row whose `Kind` text is
1482
1937
  * no {@link ExportKeyword} have no symbol to key, so each returns `undefined`.
1483
1938
  *
1484
1939
  * @param table - The table to read
@@ -1505,9 +1960,13 @@ function extractRowSymbol(table, row) {
1505
1960
  }).trim();
1506
1961
  if (!isExportKeyword(keyword)) return void 0;
1507
1962
  const summary = extractRowSummary(table, row);
1963
+ const signed = findColumnIndex(table, SIGNATURE);
1964
+ const signatureCell = signed === void 0 ? void 0 : cells[signed];
1965
+ const signature = signatureCell === void 0 ? "" : normalizeSummary(extractCellText(signatureCell));
1508
1966
  return {
1509
1967
  name,
1510
1968
  keyword,
1969
+ ...signature.length === 0 ? {} : { signature },
1511
1970
  ...summary === void 0 ? {} : { summary }
1512
1971
  };
1513
1972
  }
@@ -1568,7 +2027,8 @@ function extractRowSummary(table, row) {
1568
2027
  * symbol on, so this reader skips it and {@link extractUnnamed} reports it; a row with an
1569
2028
  * unrecognized `Kind` text is skipped. A row also carries its {@link SUMMARY} column's compared
1570
2029
  * text when the table has that column; a table without it leaves every row's summary absent,
1571
- * which {@link findDrift} reports.
2030
+ * which {@link findDrift} reports. The exact `Signature` column contributes normalized signature
2031
+ * text, including code spans, when present and non-empty; no other header supplies it.
1572
2032
  *
1573
2033
  * @remarks
1574
2034
  * The heading boundary compares {@link extractCellText} with the raw value from
@@ -1576,7 +2036,7 @@ function extractRowSummary(table, row) {
1576
2036
  * Surrounding spaces, emphasis, and links preserve that identity. This reader refuses a heading
1577
2037
  * carrying any other visible text or an additional code span. Entries retain encounter order, and
1578
2038
  * the first-seen name + keyword wins: a genuine heading before its table row keeps the heading's
1579
- * summary-less class entry, while a table row before that heading keeps its `Summary`.
2039
+ * class entry without signature or summary, while a preceding table row keeps both cells.
1580
2040
  *
1581
2041
  * @param document - The parsed guide document
1582
2042
  * @returns The documented surface, in encounter order
@@ -1591,7 +2051,7 @@ function extractSurface(document) {
1591
2051
  const seen = /* @__PURE__ */ new Set();
1592
2052
  for (const block of selectSectionBlocks(document, SURFACE)) {
1593
2053
  if ((0, _orkestrel_markdown.isTableNode)(block)) {
1594
- for (let row = 0; row < block.rows.length; row += 1) {
2054
+ for (const row of block.rows.keys()) {
1595
2055
  const symbol = extractRowSymbol(block, row);
1596
2056
  if (symbol === void 0) continue;
1597
2057
  const key = computeSymbolKey(symbol);
@@ -1635,7 +2095,7 @@ function extractMethods(document) {
1635
2095
  const groups = [];
1636
2096
  for (const [table, name] of collectGroups(document)) {
1637
2097
  const methods = [];
1638
- for (let row = 0; row < table.rows.length; row += 1) {
2098
+ for (const row of table.rows.keys()) {
1639
2099
  const entry = extractRowEntry(table, row);
1640
2100
  if (entry !== void 0) methods.push(entry);
1641
2101
  }
@@ -1662,20 +2122,19 @@ function extractMethods(document) {
1662
2122
  * ```
1663
2123
  */
1664
2124
  function collectGroups(document) {
1665
- const groups = /* @__PURE__ */ new Map();
1666
- let current;
1667
- for (const block of selectSectionBlocks(document, METHODS)) {
2125
+ const groups = [];
2126
+ selectSectionBlocks(document, METHODS).reduce((current, block) => {
1668
2127
  if ((0, _orkestrel_markdown.isHeadingNode)(block) && block.level === 4) {
1669
- const rawInterface = findFirstCode(block.children);
1670
- current = rawInterface === void 0 ? void 0 : normalizeIdentifier(rawInterface);
1671
- continue;
2128
+ const name = findFirstCode(block.children);
2129
+ return name === void 0 ? void 0 : normalizeIdentifier(name);
1672
2130
  }
1673
2131
  if ((0, _orkestrel_markdown.isTableNode)(block) && current !== void 0) {
1674
- groups.set(block, current);
1675
- current = void 0;
2132
+ groups.push([block, current]);
2133
+ return;
1676
2134
  }
1677
- }
1678
- return groups;
2135
+ return current;
2136
+ }, void 0);
2137
+ return new Map(groups);
1679
2138
  }
1680
2139
  /**
1681
2140
  * Extracts every `## Surface` or `## Methods` table row whose first cell carries no code span.
@@ -1828,18 +2287,11 @@ function unwrapComment(comment) {
1828
2287
  * ```
1829
2288
  */
1830
2289
  function normalizeSummary(text) {
1831
- const parts = text.split(/((?<!`)`[^`]+`(?!`))/);
1832
- let normalized = "";
1833
- for (let index = 0; index < parts.length; index += 1) {
1834
- const part = parts[index] ?? "";
1835
- if (index % 2 === 0) {
1836
- normalized += part.replace(/\{@link\s+[^}|]*\|\s*([^}]*?)\s*\}/g, "`$1`").replace(/\{@link\s+(?:import\([^)]*\)\.|[^}|#\s]*[@/][^}|#\s]*#)?([^}|]*?)\s*\}/g, "`$1`");
1837
- continue;
1838
- }
2290
+ return text.split(/((?<!`)`[^`]+`(?!`))/).map((part, index) => {
2291
+ if (index % 2 === 0) return part.replace(/\{@link\s+[^}|]*\|\s*([^}]*?)\s*\}/g, "`$1`").replace(/\{@link\s+(?:import\([^)]*\)\.|[^}|#\s]*[@/][^}|#\s]*#)?([^}|]*?)\s*\}/g, "`$1`");
1839
2292
  const value = part.slice(1, -1).replace(/\s+/g, " ").trim();
1840
- normalized += `\`${value.length === 0 ? " " : value}\``;
1841
- }
1842
- return normalized.replace(/\s+/g, " ").trim();
2293
+ return `\`${value.length === 0 ? " " : value}\``;
2294
+ }).join("").replace(/\s+/g, " ").trim();
1843
2295
  }
1844
2296
  /**
1845
2297
  * Wraps one paragraph into greedy lines no longer than `width` characters. Every run of
@@ -1856,18 +2308,27 @@ function normalizeSummary(text) {
1856
2308
  * ```
1857
2309
  */
1858
2310
  function wrapText(text, width) {
2311
+ const words = text.split(/\s+/).filter((word) => word.length > 0);
1859
2312
  const lines = [];
1860
- let current = "";
1861
- for (const word of text.split(/\s+/)) {
1862
- if (word.length === 0) continue;
1863
- if (current.length === 0) current = word;
1864
- else if (current.length + 1 + word.length <= width) current += ` ${word}`;
1865
- else {
1866
- lines.push(current);
1867
- current = word;
1868
- }
1869
- }
1870
- if (current.length > 0) lines.push(current);
2313
+ const final = words.reduce((previous, word, index) => {
2314
+ if (index === previous.start) return {
2315
+ start: index,
2316
+ length: word.length
2317
+ };
2318
+ if (previous.length + 1 + word.length <= width) return {
2319
+ start: previous.start,
2320
+ length: previous.length + 1 + word.length
2321
+ };
2322
+ lines.push(words.slice(previous.start, index).join(" "));
2323
+ return {
2324
+ start: index,
2325
+ length: word.length
2326
+ };
2327
+ }, {
2328
+ start: 0,
2329
+ length: 0
2330
+ });
2331
+ if (words.length > 0) lines.push(words.slice(final.start).join(" "));
1871
2332
  return lines;
1872
2333
  }
1873
2334
  /**
@@ -1912,18 +2373,16 @@ function buildComment(lines, indent) {
1912
2373
  */
1913
2374
  function maskFences(text) {
1914
2375
  const masked = [];
1915
- let marker;
1916
- for (const line of text.split("\n")) {
2376
+ text.split("\n").reduce((marker, line) => {
1917
2377
  const fence = /^[ \t]*(`{3,}|~{3,})/.exec(line)?.[1];
1918
2378
  if (marker === void 0) {
1919
2379
  masked.push(line);
1920
- marker = fence;
1921
- continue;
2380
+ return fence;
1922
2381
  }
1923
- const closing = fence !== void 0 && fence.startsWith(marker);
1924
- masked.push(closing ? line : " ".repeat(line.length));
1925
- if (closing) marker = void 0;
1926
- }
2382
+ const closed = fence !== void 0 && fence.startsWith(marker);
2383
+ masked.push(closed ? line : " ".repeat(line.length));
2384
+ return closed ? void 0 : marker;
2385
+ }, void 0);
1927
2386
  return masked.join("\n");
1928
2387
  }
1929
2388
  /**
@@ -1949,67 +2408,67 @@ function maskFences(text) {
1949
2408
  */
1950
2409
  function extractSourceComments(lines) {
1951
2410
  const comments = [];
1952
- let block = false;
1953
- let eligible = false;
1954
- let span = [];
1955
- let pending;
1956
- for (const line of lines) {
2411
+ Iterator.from(lines).reduce((previous, line) => {
1957
2412
  const projection = line.jsdoc;
1958
2413
  const first = projection?.indexOf("/**") ?? -1;
1959
- if (pending !== void 0) {
1960
- if (!block && first >= 0 && line.source.slice(0, first).trim() === "") pending = void 0;
1961
- else {
1962
- comments.push({
1963
- text: pending,
1964
- line
1965
- });
1966
- pending = void 0;
1967
- }
1968
- }
1969
- if (projection === void 0) continue;
1970
- let cursor = 0;
1971
- if (block) {
1972
- const close = projection.indexOf("*/");
1973
- const end = close < 0 ? projection.length : close + 2;
1974
- span.push(projection.slice(0, end));
1975
- if (close < 0) continue;
1976
- block = false;
1977
- const opener = projection.indexOf("/**", close + 2);
1978
- const endOfGap = opener < 0 ? line.source.length : opener;
1979
- const whitespace = line.source.slice(close + 2, endOfGap).trim() === "";
1980
- if (opener < 0) {
1981
- pending = eligible && whitespace ? normalizeComment(span.join("\n")) : void 0;
1982
- continue;
1983
- }
1984
- eligible = eligible && whitespace;
1985
- span = [];
1986
- cursor = opener;
1987
- } else {
1988
- if (first < 0) continue;
1989
- eligible = line.source.slice(0, first).trim() === "";
1990
- span = [];
1991
- cursor = first;
1992
- }
1993
- while (cursor < projection.length) {
1994
- const close = projection.indexOf("*/", cursor + 2);
1995
- const end = close < 0 ? projection.length : close + 2;
1996
- span.push(projection.slice(cursor, end));
1997
- if (close < 0) {
1998
- block = true;
1999
- break;
2000
- }
2001
- const opener = projection.indexOf("/**", close + 2);
2002
- const endOfGap = opener < 0 ? line.source.length : opener;
2003
- const whitespace = line.source.slice(close + 2, endOfGap).trim() === "";
2004
- if (opener < 0) {
2005
- pending = eligible && whitespace ? normalizeComment(span.join("\n")) : void 0;
2006
- break;
2007
- }
2008
- eligible = eligible && whitespace;
2009
- span = [];
2010
- cursor = opener;
2011
- }
2012
- }
2414
+ if (previous.pending !== void 0 && !(!previous.block && first >= 0 && line.source.slice(0, first).trim() === "")) comments.push({
2415
+ text: previous.pending,
2416
+ line
2417
+ });
2418
+ const state = {
2419
+ ...previous,
2420
+ pending: void 0
2421
+ };
2422
+ if (projection === void 0) return state;
2423
+ const close = state.block ? projection.indexOf("*/") : -1;
2424
+ const end = close < 0 ? projection.length : close + 2;
2425
+ if (state.block) state.span.push(projection.slice(0, end));
2426
+ if (state.block && close < 0) return state;
2427
+ const opener = state.block ? projection.indexOf("/**", close + 2) : first;
2428
+ const whitespace = state.block ? line.source.slice(close + 2, opener < 0 ? line.source.length : opener).trim() === "" : line.source.slice(0, first).trim() === "";
2429
+ const eligible = state.block ? state.eligible && whitespace : whitespace;
2430
+ if (opener < 0) return state.block ? {
2431
+ ...state,
2432
+ block: false,
2433
+ pending: eligible ? normalizeComment(state.span.join("\n")) : void 0
2434
+ } : state;
2435
+ const spans = /\/\*(?=\*)[\s\S]*?(?:\*\/|$)/g;
2436
+ spans.lastIndex = opener;
2437
+ return Iterator.from(projection.matchAll(spans)).reduce((current, match) => {
2438
+ const cursor = match.index;
2439
+ const closing = projection.indexOf("*/", cursor + 2);
2440
+ const finish = closing < 0 ? projection.length : closing + 2;
2441
+ const span = [projection.slice(cursor, finish)];
2442
+ if (closing < 0) return {
2443
+ ...current,
2444
+ span,
2445
+ block: true
2446
+ };
2447
+ const next = projection.indexOf("/**", closing + 2);
2448
+ const gap = line.source.slice(closing + 2, next < 0 ? line.source.length : next).trim() === "";
2449
+ if (next < 0) return {
2450
+ ...current,
2451
+ span,
2452
+ block: false,
2453
+ pending: current.eligible && gap ? normalizeComment(span.join("\n")) : void 0
2454
+ };
2455
+ return {
2456
+ ...current,
2457
+ span,
2458
+ block: false,
2459
+ eligible: current.eligible && gap
2460
+ };
2461
+ }, {
2462
+ ...state,
2463
+ block: false,
2464
+ eligible
2465
+ });
2466
+ }, {
2467
+ block: false,
2468
+ eligible: false,
2469
+ span: [],
2470
+ pending: void 0
2471
+ });
2013
2472
  return comments;
2014
2473
  }
2015
2474
  /**
@@ -2108,28 +2567,24 @@ function extractBodyLines(lines) {
2108
2567
  * ```
2109
2568
  */
2110
2569
  function collectKeys(lines) {
2111
- const keys = /* @__PURE__ */ new Map();
2112
- let owner;
2113
- for (const line of lines) {
2570
+ const keys = [];
2571
+ Iterator.from(lines).reduce((owner, line) => {
2114
2572
  const head = /^export (?:async )?(?:abstract )?(function\*?|class|const|interface|type) (\w+)/.exec(line.code);
2115
2573
  const keyword = head?.[1]?.replace(/\*$/, "");
2116
2574
  const name = head?.[2];
2117
2575
  if ((0, _orkestrel_contract.isNonEmptyString)(keyword) && (0, _orkestrel_contract.isNonEmptyString)(name) && isExportKeyword(keyword)) {
2118
- keys.set(line, computeSymbolKey({
2576
+ keys.push([line, computeSymbolKey({
2119
2577
  name,
2120
2578
  keyword
2121
- }));
2122
- owner = keyword === "class" || keyword === "interface" ? name : void 0;
2123
- continue;
2124
- }
2125
- if (line.code === "}") {
2126
- owner = void 0;
2127
- continue;
2579
+ })]);
2580
+ return keyword === "class" || keyword === "interface" ? name : void 0;
2128
2581
  }
2582
+ if (line.code === "}") return void 0;
2129
2583
  const member = /^\t(?:async )?\*?(\w+)\??(?:<.*>)?\(/.exec(line.code)?.[1];
2130
- if (owner !== void 0 && (0, _orkestrel_contract.isNonEmptyString)(member)) keys.set(line, `${owner}.${member}`);
2131
- }
2132
- return keys;
2584
+ if (owner !== void 0 && (0, _orkestrel_contract.isNonEmptyString)(member)) keys.push([line, `${owner}.${member}`]);
2585
+ return owner;
2586
+ }, void 0);
2587
+ return new Map(keys);
2133
2588
  }
2134
2589
  /**
2135
2590
  * Collects the `@example` blocks one doc block's unwrapped text carries, each named for the
@@ -2150,9 +2605,7 @@ function collectKeys(lines) {
2150
2605
  function collectExamples(comment, name) {
2151
2606
  const examples = [];
2152
2607
  const masked = maskFences(comment);
2153
- const tags = /^[ \t]*@example(?=[ \t]|$)[ \t]*(.*)$/gm;
2154
- let tag;
2155
- while ((tag = tags.exec(masked)) !== null) {
2608
+ for (const tag of masked.matchAll(/^[ \t]*@example(?=[ \t]|$)[ \t]*(.*)$/gm)) {
2156
2609
  const title = (tag[1] ?? "").trim();
2157
2610
  const start = tag.index + tag[0].length;
2158
2611
  const rest = comment.slice(start).replace(/^\n/, "");
@@ -2277,20 +2730,17 @@ function extractFences(document) {
2277
2730
  * ```
2278
2731
  */
2279
2732
  function collectFences(document) {
2280
- const fences = /* @__PURE__ */ new Map();
2281
- let title = "";
2282
- for (const node of (0, _orkestrel_markdown.walkNodes)(document)) {
2283
- if ((0, _orkestrel_markdown.isHeadingNode)(node)) {
2284
- title = (0, _orkestrel_markdown.flattenText)(node).trim();
2285
- continue;
2286
- }
2287
- if ((0, _orkestrel_markdown.isCodeBlockNode)(node)) fences.set(node, {
2733
+ const fences = [];
2734
+ Iterator.from((0, _orkestrel_markdown.walkNodes)(document)).reduce((title, node) => {
2735
+ if ((0, _orkestrel_markdown.isHeadingNode)(node)) return (0, _orkestrel_markdown.flattenText)(node).trim();
2736
+ if ((0, _orkestrel_markdown.isCodeBlockNode)(node)) fences.push([node, {
2288
2737
  language: node.lang,
2289
2738
  code: node.code,
2290
2739
  ...title.length === 0 ? {} : { title }
2291
- });
2292
- }
2293
- return fences;
2740
+ }]);
2741
+ return title;
2742
+ }, "");
2743
+ return new Map(fences);
2294
2744
  }
2295
2745
  /**
2296
2746
  * Extracts the guide's tagline — the text of the blockquote following the document's H1,
@@ -2306,17 +2756,30 @@ function collectFences(document) {
2306
2756
  * ```
2307
2757
  */
2308
2758
  function extractTagline(document) {
2309
- let opened = false;
2759
+ const scanned = [];
2310
2760
  for (const block of document.children) {
2761
+ const opened = scanned.at(-1)?.opened ?? false;
2311
2762
  if ((0, _orkestrel_markdown.isHeadingNode)(block)) {
2312
- if (opened) return void 0;
2313
- opened = block.level === 1;
2763
+ if (opened) break;
2764
+ scanned.push({
2765
+ block,
2766
+ opened: block.level === 1,
2767
+ selected: void 0
2768
+ });
2314
2769
  continue;
2315
2770
  }
2316
- if (!opened || !(0, _orkestrel_markdown.isBlockquoteNode)(block)) continue;
2317
- const text = normalizeSummary(block.children.filter(_orkestrel_markdown.isParagraphNode).map((paragraph) => extractCellText(paragraph.children)).join(" "));
2318
- return text.length === 0 ? void 0 : text;
2771
+ const selected = opened && (0, _orkestrel_markdown.isBlockquoteNode)(block) ? block : void 0;
2772
+ scanned.push({
2773
+ block,
2774
+ opened,
2775
+ selected
2776
+ });
2777
+ if (selected !== void 0) break;
2319
2778
  }
2779
+ const selected = scanned.find((entry) => entry.selected !== void 0)?.selected;
2780
+ if (selected === void 0) return void 0;
2781
+ const text = normalizeSummary(selected.children.filter(_orkestrel_markdown.isParagraphNode).map((paragraph) => extractCellText(paragraph.children)).join(" "));
2782
+ return text.length === 0 ? void 0 : text;
2320
2783
  }
2321
2784
  /**
2322
2785
  * Computes the drift between one compared key's guide text and source text. A pair agrees
@@ -2427,8 +2890,9 @@ function formatDrift(drift) {
2427
2890
  }
2428
2891
  /**
2429
2892
  * Finds every disagreement between a guide and the source it documents, naming both sites:
2430
- * each `## Surface` row against its declaration's description paragraph, each `## Methods`
2431
- * row against its member's, and the first titled guide fence of a heading against the
2893
+ * each `## Surface` row against its declaration's description paragraph, each present
2894
+ * `Signature` cell against the declaration's computed signature written as a code span, each
2895
+ * `## Methods` row against its member's, and the first titled guide fence of a heading against the
2432
2896
  * `@example` block of the same title. An example's compared text is its language on the first
2433
2897
  * line and its body beneath, so a fence that names another language drifts on its own.
2434
2898
  *
@@ -2439,11 +2903,14 @@ function formatDrift(drift) {
2439
2903
  * pair where one side carries none, and a pair where neither side carries text are all drift.
2440
2904
  * The pairing is per title across the whole document, not per heading: the first fence a title
2441
2905
  * reaches is the compared one, and every later fence of that title is outside the comparison,
2442
- * whether it sits under the same heading or under a second heading of the same text.
2906
+ * whether it sits under the same heading or under a second heading of the same text. A signature
2907
+ * is compared only when both sides carry one, so an H3 entity heading, which carries no cell, and
2908
+ * a source reflected without emitted declarations stay outside that comparison.
2443
2909
  *
2444
2910
  * @param guide - The parsed guide
2445
2911
  * @param source - The reflected source the guide documents
2446
- * @returns One entry per disagreement: Surface rows, then Methods rows, then examples
2912
+ * @returns One entry per disagreement: each Surface row's summary then signature, then Methods
2913
+ * rows, then examples
2447
2914
  *
2448
2915
  * @example
2449
2916
  * ```ts
@@ -2459,6 +2926,13 @@ function findDrift(guide, source) {
2459
2926
  if (match === void 0) continue;
2460
2927
  const drift = computeDrift(key, "summary", symbol.summary, match.summary);
2461
2928
  if (drift !== void 0) drifts.push(drift);
2929
+ if (symbol.signature === void 0 || match.signature === void 0) continue;
2930
+ const computed = normalizeSummary(extractCellText([{
2931
+ element: "codeSpan",
2932
+ value: match.signature
2933
+ }]));
2934
+ const signed = computeDrift(key, "signature", symbol.signature, computed);
2935
+ if (signed !== void 0) drifts.push(signed);
2462
2936
  }
2463
2937
  for (const group of guide.methods()) {
2464
2938
  const members = new Map(source.methods(group.interface).map((entry) => [entry.name, entry]));
@@ -2506,26 +2980,26 @@ function collectTitles(guide, source) {
2506
2980
  return titled;
2507
2981
  }
2508
2982
  /**
2509
- * Builds a copy of `table` with one cell's inline content rebuilt from `text` through
2510
- * {@link buildCell}. Every other cell keeps its own nodes, so a rewrite touches the one cell it
2511
- * names and the header and the alignment row travel unchanged.
2983
+ * Builds a copy of `table` with one cell's inline content replaced by `cell`. Every other cell
2984
+ * keeps its own nodes, so a rewrite touches the one cell it names and the header and the
2985
+ * alignment row travel unchanged.
2512
2986
  *
2513
2987
  * @param table - The table to copy
2514
2988
  * @param row - The index of the row to rewrite within {@link TableNode.rows}
2515
2989
  * @param column - The index of the cell to rewrite within that row
2516
- * @param text - The cell's new compared text
2990
+ * @param cell - The cell's new inline content, such as {@link buildCell} returns
2517
2991
  * @returns The rewritten table
2518
2992
  *
2519
2993
  * @example
2520
2994
  * ```ts
2521
- * buildTable(table, 0, 2, 'Walks the tree.').rows[0]?.[2] // [{ element: 'text', value: 'Walks the tree.' }]
2995
+ * buildTable(table, 0, 3, buildCell('Walks the tree.')).rows[0]?.[3] // [{ element: 'text', value: 'Walks the tree.' }]
2522
2996
  * ```
2523
2997
  */
2524
- function buildTable(table, row, column, text) {
2998
+ function buildTable(table, row, column, cell) {
2525
2999
  return {
2526
3000
  element: "table",
2527
3001
  header: table.header,
2528
- rows: table.rows.map((cells, index) => index === row ? cells.map((cell, position) => position === column ? buildCell(text) : cell) : cells),
3002
+ rows: table.rows.map((cells, index) => index === row ? cells.map((current, position) => position === column ? cell : current) : cells),
2529
3003
  align: table.align
2530
3004
  };
2531
3005
  }
@@ -2568,10 +3042,10 @@ function spliceSpan(source, span, replacement) {
2568
3042
  return source.slice(0, span.start) + replacement + source.slice(span.end);
2569
3043
  }
2570
3044
  /**
2571
- * Renders a `## Surface` table from the symbols a source declares — a `Name`, {@link KIND}, and
2572
- * {@link SUMMARY} table with one row per symbol, the name as a code span, the keyword as its
2573
- * text, and the summary through {@link buildCell}. A symbol carrying no summary renders an empty
2574
- * cell, which {@link extractSurface} reads back as an absent summary.
3045
+ * Renders a uniform `Name | Kind | Signature | Summary` table with one row per symbol, the name
3046
+ * as a code span, the keyword as text, and the signature and summary through {@link buildCell}.
3047
+ * An absent signature or summary renders an empty cell, which {@link extractSurface} reads back
3048
+ * as absent. Guide construction refuses an empty signature cell.
2575
3049
  *
2576
3050
  * @remarks
2577
3051
  * The render carries no `## Surface` heading, because a guide documents its surface in several
@@ -2586,7 +3060,7 @@ function spliceSpan(source, span, replacement) {
2586
3060
  * @example
2587
3061
  * ```ts
2588
3062
  * renderSurface([{ name: 'walk', keyword: 'function', summary: 'Walks the tree.' }])
2589
- * // '| Name | Kind | Summary |\n| --- | --- | --- |\n| `walk` | function | Walks the tree. |'
3063
+ * // '| Name | Kind | Signature | Summary |\n| --- | --- | --- | --- |\n| `walk` | function | | Walks the tree. |'
2590
3064
  * ```
2591
3065
  */
2592
3066
  function renderSurface(symbols) {
@@ -2595,12 +3069,16 @@ function renderSurface(symbols) {
2595
3069
  header: [
2596
3070
  [{
2597
3071
  element: "text",
2598
- value: "Name"
3072
+ value: NAME
2599
3073
  }],
2600
3074
  [{
2601
3075
  element: "text",
2602
3076
  value: KIND
2603
3077
  }],
3078
+ [{
3079
+ element: "text",
3080
+ value: SIGNATURE
3081
+ }],
2604
3082
  [{
2605
3083
  element: "text",
2606
3084
  value: SUMMARY
@@ -2615,9 +3093,11 @@ function renderSurface(symbols) {
2615
3093
  element: "text",
2616
3094
  value: symbol.keyword
2617
3095
  }],
3096
+ buildCell(symbol.signature ?? ""),
2618
3097
  buildCell(symbol.summary ?? "")
2619
3098
  ]),
2620
3099
  align: [
3100
+ null,
2621
3101
  null,
2622
3102
  null,
2623
3103
  null
@@ -2656,7 +3136,7 @@ function renderMethods(group) {
2656
3136
  element: "table",
2657
3137
  header: [[{
2658
3138
  element: "text",
2659
- value: "Name"
3139
+ value: NAME
2660
3140
  }], [{
2661
3141
  element: "text",
2662
3142
  value: SUMMARY
@@ -2708,62 +3188,58 @@ function renderExample(example) {
2708
3188
  /**
2709
3189
  * Replaces one compared cell in a guide's text and returns the whole guide back. `key` names the
2710
3190
  * row the way {@link findDrift} names it — a {@link computeSymbolKey} key for a `## Surface` row,
2711
- * an `Owner.member` key for a `## Methods` row — and the row's {@link SUMMARY} cell becomes
2712
- * `summary`. Only the table's own source region is rewritten, so every byte outside it travels
2713
- * unchanged; a key reaching no cell returns `undefined`, and a row already carrying the summary
2714
- * returns the guide byte for byte.
3191
+ * an `Owner.member` key for a `## Methods` row — and the row's cell under the `column` header
3192
+ * becomes `cell`. Only the table's own source region is rewritten, so every byte outside it
3193
+ * travels unchanged; a key reaching no cell returns `undefined`, and a row already carrying that
3194
+ * cell returns the guide byte for byte.
2715
3195
  *
2716
3196
  * @remarks
2717
- * A row the key does not reach, a table carrying no {@link SUMMARY} column, and a document whose
2718
- * parse recorded no region for the table are each a miss, and a miss returns `undefined` rather
2719
- * than throwing, so a caller reports the key it could not place — the one meaning `undefined`
2720
- * carries in every replacer here. A row already carrying `summary` returns the guide byte for
2721
- * byte, because a rewrite would re-pad the whole table for no change; that identity reads both
2722
- * sides through {@link normalizeSummary}, so a caller passing text the compared form still moves
2723
- * is a fixed point on the second run rather than a row rewritten forever. The rewritten table
2724
- * renders one-space padded whatever padding it carried, so the checkout's formatter re-aligns it.
3197
+ * A row the key does not reach, a table carrying no `column` header, and a document whose parse
3198
+ * recorded no region for the table are each a miss, and a miss returns `undefined` rather than
3199
+ * throwing, so a caller reports the key it could not place — the one meaning `undefined` carries
3200
+ * in every replacer here. A row already carrying `cell` returns the guide byte for byte, because
3201
+ * a rewrite would re-pad the whole table for no change; that identity reads both cells through
3202
+ * {@link extractCellText} and {@link normalizeSummary}, so a caller passing text the compared form
3203
+ * still moves is a fixed point on the second run rather than a row rewritten forever. The
3204
+ * rewritten table renders one-space padded whatever padding it carried, so the checkout's
3205
+ * formatter re-aligns it, and a code span renders with every `|` written `\|` and a longer
3206
+ * backtick fence when its text holds a backtick.
2725
3207
  *
2726
3208
  * @param guide - The guide's markdown source
2727
3209
  * @param key - The compared key naming the row
2728
- * @param summary - The row's new compared text
3210
+ * @param column - The header text of the column to write, {@link SUMMARY} or {@link SIGNATURE}
3211
+ * @param cell - The cell's new inline content, such as {@link buildCell} returns
2729
3212
  * @returns The guide's text with that cell replaced, or `undefined` when the key reaches no cell
2730
3213
  *
2731
3214
  * @example
2732
3215
  * ```ts
2733
- * replaceCell('## Surface\n\n| Name | Kind | Summary |\n| --- | --- | --- |\n| `walk` | function | Walks. |', 'function walk', 'Walks a tree.')
2734
- * // '## Surface\n\n| Name | Kind | Summary |\n| --- | --- | --- |\n| `walk` | function | Walks a tree. |'
3216
+ * replaceCell('## Surface\n\n| Name | Kind | Signature | Summary |\n| --- | --- | --- | --- |\n| `walk` | function | `() => void` | Walks. |', 'function walk', SUMMARY, buildCell('Walks a tree.'))
3217
+ * // '## Surface\n\n| Name | Kind | Signature | Summary |\n| --- | --- | --- | --- |\n| `walk` | function | `() => void` | Walks a tree. |'
2735
3218
  * ```
2736
3219
  */
2737
- function replaceCell(guide, key, summary) {
3220
+ function replaceCell(guide, key, column, cell) {
2738
3221
  const markdown = (0, _orkestrel_markdown.createMarkdown)(guide);
2739
3222
  const document = markdown.document;
2740
- let located;
2741
- let index = -1;
2742
- for (const block of selectSectionBlocks(document, SURFACE)) {
2743
- if (located !== void 0 || !(0, _orkestrel_markdown.isTableNode)(block)) continue;
2744
- for (let row = 0; row < block.rows.length && located === void 0; row += 1) {
2745
- const symbol = extractRowSymbol(block, row);
2746
- if (symbol === void 0 || computeSymbolKey(symbol) !== key) continue;
2747
- located = block;
2748
- index = row;
2749
- }
2750
- }
2751
- for (const [table, owner] of collectGroups(document)) {
2752
- if (located !== void 0) break;
2753
- for (let row = 0; row < table.rows.length && located === void 0; row += 1) {
2754
- const entry = extractRowEntry(table, row);
2755
- if (entry === void 0 || `${owner}.${entry.name}` !== key) continue;
2756
- located = table;
2757
- index = row;
2758
- }
2759
- }
2760
- if (located === void 0) return void 0;
2761
- const column = findColumnIndex(located, SUMMARY);
2762
- if (column === void 0) return void 0;
2763
- if ((extractRowSummary(located, index) ?? "") === normalizeSummary(summary)) return guide;
2764
- const span = markdown.span(located);
3223
+ const surface = Iterator.from(selectSectionBlocks(document, SURFACE)).filter(_orkestrel_markdown.isTableNode).flatMap((table) => table.rows.keys().map((index) => ({
3224
+ table,
3225
+ index,
3226
+ symbol: extractRowSymbol(table, index)
3227
+ }))).find((row) => row.symbol !== void 0 && computeSymbolKey(row.symbol) === key);
3228
+ const groups = collectGroups(document);
3229
+ const selected = surface ?? Iterator.from(groups).flatMap(([table, owner]) => table.rows.keys().map((index) => ({
3230
+ table,
3231
+ index,
3232
+ owner,
3233
+ entry: extractRowEntry(table, index)
3234
+ }))).find((row) => row.entry !== void 0 && `${row.owner}.${row.entry.name}` === key);
3235
+ if (selected === void 0) return void 0;
3236
+ const { table, index } = selected;
3237
+ const position = findColumnIndex(table, column);
3238
+ if (position === void 0) return void 0;
3239
+ if (normalizeSummary(extractCellText(table.rows[index]?.[position] ?? [])) === normalizeSummary(extractCellText(cell))) return guide;
3240
+ const span = markdown.span(table);
2765
3241
  if (span === void 0) return void 0;
2766
- return spliceSpan(guide, span, (0, _orkestrel_markdown.renderMarkdown)(buildTable(located, index, column, summary)));
3242
+ return spliceSpan(guide, span, (0, _orkestrel_markdown.renderMarkdown)(buildTable(table, index, position, cell)));
2767
3243
  }
2768
3244
  /**
2769
3245
  * Replaces one titled fence in a guide's text and returns the whole guide back. The first fence
@@ -2792,14 +3268,9 @@ function replaceCell(guide, key, summary) {
2792
3268
  */
2793
3269
  function replaceFence(guide, title, example) {
2794
3270
  const markdown = (0, _orkestrel_markdown.createMarkdown)(guide);
2795
- let located;
2796
- let current;
2797
- for (const [node, fence] of collectFences(markdown.document)) {
2798
- if (located !== void 0 || fence.title !== title) continue;
2799
- located = node;
2800
- current = fence;
2801
- }
2802
- if (located === void 0 || current === void 0) return void 0;
3271
+ const selected = Iterator.from(collectFences(markdown.document)).find(([, fence]) => fence.title === title);
3272
+ if (selected === void 0) return void 0;
3273
+ const [located, current] = selected;
2803
3274
  if (current.code === example.code && current.language === example.language) return guide;
2804
3275
  const span = markdown.span(located);
2805
3276
  if (span === void 0) return void 0;
@@ -2849,9 +3320,7 @@ function replaceSummary(comment, summary, width = 100) {
2849
3320
  const indent = /^[ \t]*/.exec(comment)?.[0] ?? "";
2850
3321
  const wrapped = wrapText(summary, width - indent.length - 3);
2851
3322
  if (wrapped.length === 0) return void 0;
2852
- const masked = maskFences(content.join("\n")).split("\n");
2853
- let tag = -1;
2854
- for (let index = 0; index < masked.length && tag < 0; index += 1) if (/^[ \t]*@\w/.test(masked[index] ?? "")) tag = index;
3323
+ const tag = maskFences(content.join("\n")).split("\n").findIndex((line) => /^[ \t]*@\w/.test(line));
2855
3324
  if (normalizeSummary(content.slice(0, tag < 0 ? content.length : tag).join("\n")) === normalizeSummary(summary)) return comment;
2856
3325
  const tail = tag < 0 ? [] : content.slice(tag);
2857
3326
  if (tail.length === 0 && wrapped.length === 1 && content.length === 1) {
@@ -2907,17 +3376,17 @@ function replaceExample(comment, example) {
2907
3376
  const content = unwrapComment(comment);
2908
3377
  const masked = maskFences(content.join("\n")).split("\n");
2909
3378
  const title = example.title ?? "";
2910
- let start = -1;
2911
- for (let index = 0; index < masked.length && start < 0; index += 1) {
2912
- const tag = /^[ \t]*@example(?=[ \t]|$)[ \t]*(.*)$/.exec(masked[index] ?? "");
2913
- if (tag !== null && (tag[1] ?? "").trim() === title) start = index;
2914
- }
3379
+ const start = masked.findIndex((line) => {
3380
+ const tag = /^[ \t]*@example(?=[ \t]|$)[ \t]*(.*)$/.exec(line);
3381
+ return tag !== null && (tag[1] ?? "").trim() === title;
3382
+ });
2915
3383
  if (start < 0) return void 0;
2916
3384
  const current = collectExamples(content.join("\n"), example.name).find((entry) => (entry.title ?? "") === title);
2917
3385
  if (current !== void 0 && current.code === example.code && current.language === example.language) return comment;
2918
- let end = content.length;
2919
- for (let index = start + 1; index < masked.length && end === content.length; index += 1) if (/^[ \t]*@\w/.test(masked[index] ?? "")) end = index;
2920
- while (end > start + 1 && (content[end - 1] ?? "").length === 0) end -= 1;
3386
+ const next = masked.findIndex((line, index) => index > start && /^[ \t]*@\w/.test(line));
3387
+ const boundary = next < 0 ? content.length : next;
3388
+ const last = content.findLastIndex((line, index) => index > start && index < boundary && line.length > 0);
3389
+ const end = last < 0 ? start + 1 : last + 1;
2921
3390
  const indent = /^[ \t]*/.exec(comment)?.[0] ?? "";
2922
3391
  const body = [
2923
3392
  `\`\`\`${example.language ?? ""}`,
@@ -2975,52 +3444,56 @@ function replaceExample(comment, example) {
2975
3444
  function locateComment(text, key) {
2976
3445
  const lines = extractSourceLines(text);
2977
3446
  const keys = collectKeys(lines);
2978
- const offsets = [];
2979
- const positions = /* @__PURE__ */ new Map();
2980
- let offset = 0;
2981
- for (let index = 0; index < lines.length; index += 1) {
2982
- const line = lines[index];
2983
- if (line === void 0) continue;
2984
- offsets.push(offset);
2985
- positions.set(line, index);
3447
+ const records = [];
3448
+ for (const [index, line] of lines.entries()) {
3449
+ const offset = records.at(-1)?.next ?? 0;
2986
3450
  const after = offset + line.source.length;
2987
- offset = after + (text.startsWith("\r\n", after) ? 2 : 1);
3451
+ records.push({
3452
+ line,
3453
+ index,
3454
+ offset,
3455
+ next: after + (text.startsWith("\r\n", after) ? 2 : 1)
3456
+ });
2988
3457
  }
3458
+ const offsets = records.map((record) => record.offset);
3459
+ const positions = new Map(records.map((record) => [record.line, record.index]));
2989
3460
  for (const comment of extractSourceComments(lines)) {
2990
3461
  if (keys.get(comment.line) !== key) continue;
2991
3462
  const close = (positions.get(comment.line) ?? 0) - 1;
2992
3463
  const closing = lines[close]?.jsdoc;
2993
3464
  const end = closing === void 0 ? -1 : closing.lastIndexOf("*/");
2994
3465
  if (end < 0) continue;
2995
- let first = close;
2996
- while (first > 0 && lines[first - 1]?.jsdoc !== void 0) first -= 1;
2997
- let inside = false;
2998
- let line = -1;
2999
- let column = -1;
3000
- for (let index = first; index <= close; index += 1) {
3466
+ const first = lines.keys().take(close).map((index) => close - index).find((index) => lines[index - 1]?.jsdoc === void 0) ?? 0;
3467
+ const found = Array.prototype.keys.call({ length: close - first + 1 }).map((distance) => first + distance).reduce((state, index) => {
3001
3468
  const projection = lines[index]?.jsdoc ?? "";
3002
- let cursor = 0;
3003
- while (cursor < projection.length) {
3004
- const at = projection.indexOf(inside ? "*/" : "/**", cursor);
3005
- if (at < 0) break;
3006
- if (!inside) {
3007
- line = index;
3008
- column = at;
3009
- }
3010
- cursor = at + (inside ? 2 : 3);
3011
- inside = !inside;
3012
- }
3013
- }
3014
- if (line < 0) continue;
3015
- const start = (lines[line]?.source ?? "").slice(0, column).trim() === "" ? 0 : column;
3469
+ return Iterator.from(projection.matchAll(/(?=\/\*\*|\*\/)/g)).reduce((current, match) => {
3470
+ const at = match.index;
3471
+ if (at < current.cursor || !projection.startsWith(current.inside ? "*/" : "/**", at)) return current;
3472
+ return {
3473
+ inside: !current.inside,
3474
+ line: current.inside ? current.line : index,
3475
+ column: current.inside ? current.column : at,
3476
+ cursor: at + (current.inside ? 2 : 3)
3477
+ };
3478
+ }, {
3479
+ ...state,
3480
+ cursor: 0
3481
+ });
3482
+ }, {
3483
+ inside: false,
3484
+ line: -1,
3485
+ column: -1,
3486
+ cursor: 0
3487
+ });
3488
+ if (found.line < 0) continue;
3489
+ const start = (lines[found.line]?.source ?? "").slice(0, found.column).trim() === "" ? 0 : found.column;
3016
3490
  return {
3017
- start: (offsets[line] ?? 0) + start,
3491
+ start: (offsets[found.line] ?? 0) + start,
3018
3492
  end: (offsets[close] ?? 0) + end + 2
3019
3493
  };
3020
3494
  }
3021
3495
  }
3022
- //#endregion
3023
- //#region src/core/parsers.ts
3496
+ // src/core/parsers.ts
3024
3497
  /**
3025
3498
  * Parses a `## By concept` manifest table into its {@link ManifestEntry} rows —
3026
3499
  * each row's Concept cell (flattened text), Spec / Tests cells (a single link
@@ -3072,11 +3545,10 @@ function parseManifest(markdown, directory) {
3072
3545
  }
3073
3546
  return entries;
3074
3547
  }
3075
- //#endregion
3076
- //#region src/core/shapers.ts
3548
+ // src/core/shapers.ts
3077
3549
  /**
3078
3550
  * Shapes a {@link SurfaceSymbol} — a documented / exported symbol's `name`
3079
- * paired with its {@link ExportKeyword} and its optional compared `summary`.
3551
+ * paired with its {@link ExportKeyword}, optional `signature`, and optional compared `summary`.
3080
3552
  *
3081
3553
  * @example
3082
3554
  * ```ts
@@ -3090,6 +3562,7 @@ function parseManifest(markdown, directory) {
3090
3562
  var surfaceSymbolShape = (0, _orkestrel_contract.objectShape)({
3091
3563
  name: (0, _orkestrel_contract.stringShape)(),
3092
3564
  keyword: (0, _orkestrel_contract.literalShape)(EXPORT_KEYWORDS),
3565
+ signature: (0, _orkestrel_contract.optionalShape)((0, _orkestrel_contract.stringShape)()),
3093
3566
  summary: (0, _orkestrel_contract.optionalShape)((0, _orkestrel_contract.stringShape)())
3094
3567
  });
3095
3568
  /**
@@ -3183,8 +3656,7 @@ var manifestEntryShape = (0, _orkestrel_contract.objectShape)({
3183
3656
  source: (0, _orkestrel_contract.unionShape)((0, _orkestrel_contract.stringShape)(), (0, _orkestrel_contract.arrayShape)((0, _orkestrel_contract.stringShape)())),
3184
3657
  tests: (0, _orkestrel_contract.stringShape)()
3185
3658
  });
3186
- //#endregion
3187
- //#region src/core/Guide.ts
3659
+ // src/core/Guide.ts
3188
3660
  /**
3189
3661
  * Presents a pure, structured view over one parsed guide — the documented
3190
3662
  * projections (`sections` / `tagline` / `surface` / `methods` / `unnamed` / `links` /
@@ -3194,14 +3666,16 @@ var manifestEntryShape = (0, _orkestrel_contract.objectShape)({
3194
3666
  * Parses `source` once through `@orkestrel/markdown` and never touches the
3195
3667
  * filesystem — `Guide` reads only the markdown text it is given and records
3196
3668
  * nothing about where the guide came from. Every accessor returns the same
3197
- * cached, readonly array on every call.
3669
+ * cached, readonly array on every call. Before caching, refuses the first Surface table with
3670
+ * a header other than `Name | Kind | Signature | Summary` or a keyed empty Signature cell,
3671
+ * through {@link validateSurface}.
3198
3672
  *
3199
3673
  * @example
3200
3674
  * ```ts
3201
3675
  * import { Guide } from '@orkestrel/guide'
3202
3676
  *
3203
- * const guide = new Guide('## Surface\n\n| Name | Kind |\n| --- | --- |\n| `X` | class |')
3204
- * guide.surface() // [{ name: 'X', keyword: 'class' }]
3677
+ * const guide = new Guide('## Surface\n\n| Name | Kind | Signature | Summary |\n| --- | --- | --- | --- |\n| `X` | class | `new () => X` | |')
3678
+ * guide.surface() // [{ name: 'X', keyword: 'class', signature: '`new () => X`' }]
3205
3679
  * ```
3206
3680
  */
3207
3681
  var Guide = class {
@@ -3215,6 +3689,7 @@ var Guide = class {
3215
3689
  #fences;
3216
3690
  constructor(source) {
3217
3691
  const document = (0, _orkestrel_markdown.createMarkdown)(source).document;
3692
+ validateSurface(document);
3218
3693
  this.#sections = document.children.filter(_orkestrel_markdown.isHeadingNode).filter((heading) => heading.level === 2).map((heading) => (0, _orkestrel_markdown.flattenText)(heading).trim());
3219
3694
  this.#tagline = extractTagline(document);
3220
3695
  this.#surface = extractSurface(document);
@@ -3249,8 +3724,7 @@ var Guide = class {
3249
3724
  return this.#fences;
3250
3725
  }
3251
3726
  };
3252
- //#endregion
3253
- //#region src/core/sources/Source.ts
3727
+ // src/core/sources/Source.ts
3254
3728
  /**
3255
3729
  * Reflects, as a pure `SourceInterface`, a module scope's intentional direct declarations,
3256
3730
  * conventional barrel-reachable surface, and member methods over a consumer-supplied file
@@ -3316,12 +3790,15 @@ var Source = class {
3316
3790
  #hidden;
3317
3791
  #declarations;
3318
3792
  #origins = /* @__PURE__ */ new Map();
3793
+ #emitted;
3794
+ #signed = /* @__PURE__ */ new Map();
3319
3795
  constructor(options) {
3320
3796
  this.#files = options.files;
3321
3797
  this.#directories = normalizeDirectories(options.module);
3798
+ this.#emitted = options.declarations;
3322
3799
  }
3323
3800
  exports() {
3324
- if (this.#exports === void 0) this.#exports = this.#scanSymbols(extractExports);
3801
+ if (this.#exports === void 0) this.#exports = this.#scanSymbols((key, text) => this.#scanExports(key, text));
3325
3802
  return this.#exports;
3326
3803
  }
3327
3804
  surface() {
@@ -3339,7 +3816,7 @@ var Source = class {
3339
3816
  return Object.keys(this.#files).some((key) => key === relative || key.startsWith(`${relative}/`));
3340
3817
  }
3341
3818
  hidden() {
3342
- if (this.#hidden === void 0) this.#hidden = this.#scanSymbols(extractHidden);
3819
+ if (this.#hidden === void 0) this.#hidden = this.#scanSymbols((_key, text) => extractHidden(text));
3343
3820
  return this.#hidden;
3344
3821
  }
3345
3822
  examples(name) {
@@ -3405,7 +3882,7 @@ var Source = class {
3405
3882
  visited.add(path);
3406
3883
  const text = this.#files[path];
3407
3884
  if (text === void 0) continue;
3408
- for (const symbol of extractExports(text)) {
3885
+ for (const symbol of this.#scanExports(path, text)) {
3409
3886
  const identity = computeSymbolKey(symbol);
3410
3887
  if (seen.has(identity)) continue;
3411
3888
  seen.add(identity);
@@ -3428,7 +3905,7 @@ var Source = class {
3428
3905
  for (const key of selectModuleKeys(this.#files, this.#directories)) {
3429
3906
  const text = this.#files[key];
3430
3907
  if (text === void 0) continue;
3431
- for (const symbol of scan(text)) {
3908
+ for (const symbol of scan(key, text)) {
3432
3909
  const identity = computeSymbolKey(symbol);
3433
3910
  if (seen.has(identity)) continue;
3434
3911
  seen.add(identity);
@@ -3437,6 +3914,23 @@ var Source = class {
3437
3914
  }
3438
3915
  return symbols.sort((a, b) => a.name === b.name ? 0 : a.name < b.name ? -1 : 1);
3439
3916
  }
3917
+ #scanExports(key, text) {
3918
+ const cached = this.#signed.get(key);
3919
+ if (cached !== void 0) return cached;
3920
+ const declaration = this.#emitted?.[`${key.slice(0, -3)}.d.ts`];
3921
+ const signatures = new Map((declaration === void 0 ? [] : extractSignatures(declaration)).map((symbol) => [computeSymbolKey(symbol), symbol.signature]));
3922
+ const symbols = extractExports(text).map((symbol) => {
3923
+ const signature = signatures.get(computeSymbolKey(symbol));
3924
+ return signature === void 0 ? symbol : {
3925
+ name: symbol.name,
3926
+ keyword: symbol.keyword,
3927
+ signature,
3928
+ ...symbol.summary === void 0 ? {} : { summary: symbol.summary }
3929
+ };
3930
+ });
3931
+ this.#signed.set(key, symbols);
3932
+ return symbols;
3933
+ }
3440
3934
  #members(keyword, name, visited) {
3441
3935
  if (visited.has(name)) return [];
3442
3936
  visited.add(name);
@@ -3469,8 +3963,7 @@ var Source = class {
3469
3963
  return declarations;
3470
3964
  }
3471
3965
  };
3472
- //#endregion
3473
- //#region src/core/sources/SourceManager.ts
3966
+ // src/core/sources/SourceManager.ts
3474
3967
  /**
3475
3968
  * Resolves a consumer-owned import-specifier policy into pure source views and
3476
3969
  * caches those views by module, so aliases for one module share one entity.
@@ -3524,8 +4017,7 @@ var SourceManager = class {
3524
4017
  return views;
3525
4018
  }
3526
4019
  };
3527
- //#endregion
3528
- //#region src/core/Parity.ts
4020
+ // src/core/Parity.ts
3529
4021
  /**
3530
4022
  * Composes generic guide-parity inspection and explicit in-memory rewrites over a caller inventory.
3531
4023
  */
@@ -3539,7 +4031,8 @@ var Parity = class Parity {
3539
4031
  modules: { ...options.modules },
3540
4032
  languages: [...options.languages],
3541
4033
  language: options.language,
3542
- ...options.pitch === void 0 ? {} : { pitch: { ...options.pitch } }
4034
+ ...options.pitch === void 0 ? {} : { pitch: { ...options.pitch } },
4035
+ ...options.declarations === void 0 ? {} : { declarations: { ...options.declarations } }
3543
4036
  };
3544
4037
  this.#rows = this.#createRows(this.#options.files);
3545
4038
  }
@@ -3640,17 +4133,31 @@ var Parity = class Parity {
3640
4133
  for (const entry of this.#options.entries) {
3641
4134
  const text = files[entry.spec];
3642
4135
  if (text === void 0) continue;
4136
+ const guide = this.#attribute(entry.spec, () => new Guide(text));
4137
+ this.#attribute(entry.spec, () => validateModules(files, entry.source));
3643
4138
  rows.push({
3644
4139
  entry,
3645
- guide: new Guide(text),
4140
+ guide,
3646
4141
  source: new Source({
3647
4142
  files,
3648
- module: entry.source
4143
+ module: entry.source,
4144
+ ...this.#options.declarations === void 0 ? {} : { declarations: this.#options.declarations }
3649
4145
  })
3650
4146
  });
3651
4147
  }
3652
4148
  return rows;
3653
4149
  }
4150
+ #attribute(spec, step) {
4151
+ try {
4152
+ return step();
4153
+ } catch (error) {
4154
+ if (!isGuideError(error)) throw error;
4155
+ throw new GuideError(`${JSON.stringify(spec.slice(0, 200))}: ${error.message}`, error.code, {
4156
+ cause: error,
4157
+ ...error.context === void 0 ? {} : { context: error.context }
4158
+ });
4159
+ }
4160
+ }
3654
4161
  #inspectInput(findings) {
3655
4162
  if (this.#options.entries.length === 0) findings.push({ text: "The manifest has no guide entries." });
3656
4163
  for (const entry of this.#options.entries) {
@@ -3825,21 +4332,19 @@ var Parity = class Parity {
3825
4332
  files: this.#options.files,
3826
4333
  modules: this.#options.modules
3827
4334
  });
3828
- let compared = false;
3829
- for (const fence of row.guide.fences()) {
3830
- if (fence.language !== this.#options.language) continue;
3831
- for (const imported of extractFenceImports(fence.code)) {
4335
+ if (!Iterator.from(row.guide.fences()).reduce((previous, fence) => {
4336
+ if (fence.language !== this.#options.language) return previous;
4337
+ return Iterator.from(extractFenceImports(fence.code)).reduce((matched, imported) => {
3832
4338
  const source = sources.source(imported.specifier);
3833
- if (source === void 0) continue;
3834
- compared = true;
4339
+ if (source === void 0) return matched;
3835
4340
  const surface = source.surface().map((symbol) => symbol.name);
3836
4341
  for (const name of findMissing(imported.names, surface)) findings.push({
3837
4342
  spec: row.entry.spec,
3838
4343
  text: `${row.entry.spec} imports missing ${name} from ${imported.specifier}.`
3839
4344
  });
3840
- }
3841
- }
3842
- if (!compared) findings.push({
4345
+ return true;
4346
+ }, previous);
4347
+ }, false)) findings.push({
3843
4348
  spec: row.entry.spec,
3844
4349
  text: `${row.entry.spec} has no mapped self import.`
3845
4350
  });
@@ -3869,8 +4374,8 @@ var Parity = class Parity {
3869
4374
  });
3870
4375
  return;
3871
4376
  }
3872
- const left = new Guide(readme).tagline();
3873
- const right = new Guide(spec).tagline();
4377
+ const left = this.#attribute(pitch.readme, () => new Guide(readme)).tagline();
4378
+ const right = this.#attribute(pitch.spec, () => new Guide(spec)).tagline();
3874
4379
  if (left !== void 0 && left === right) return;
3875
4380
  findings.push({
3876
4381
  spec: pitch.spec,
@@ -3882,11 +4387,22 @@ var Parity = class Parity {
3882
4387
  const current = files.get(row.entry.spec);
3883
4388
  if (current === void 0) return "the guide inventory text is absent";
3884
4389
  if (drift.category === "summary") {
3885
- const replacement = replaceCell(current, drift.key, drift.source);
4390
+ const replacement = replaceCell(current, drift.key, SUMMARY, buildCell(drift.source));
3886
4391
  if (replacement === void 0) return "the guide summary cell or its provenance is unavailable";
3887
4392
  files.set(row.entry.spec, replacement);
3888
4393
  return;
3889
4394
  }
4395
+ if (drift.category === "signature") {
4396
+ const signature = row.source.surface().find((symbol) => computeSymbolKey(symbol) === drift.key)?.signature;
4397
+ if (signature === void 0) return "the computed signature is unavailable";
4398
+ const replacement = replaceCell(current, drift.key, SIGNATURE, [{
4399
+ element: "codeSpan",
4400
+ value: signature
4401
+ }]);
4402
+ if (replacement === void 0) return "the guide signature cell or its provenance is unavailable";
4403
+ files.set(row.entry.spec, replacement);
4404
+ return;
4405
+ }
3890
4406
  const example = collectTitles(row.guide, row.source).get(drift.key);
3891
4407
  if (example === void 0) return "the paired source example is unavailable";
3892
4408
  const replacement = replaceFence(current, drift.key, example);
@@ -3894,6 +4410,7 @@ var Parity = class Parity {
3894
4410
  files.set(row.entry.spec, replacement);
3895
4411
  }
3896
4412
  #rewriteSource(row, drift, files) {
4413
+ if (drift.category === "signature") return "a signature is computed from the source declaration";
3897
4414
  if (drift.guide === void 0) return "guide authority is absent";
3898
4415
  if (drift.category === "summary") {
3899
4416
  const located = this.#locateSource(row.entry, drift.key, files);
@@ -3941,17 +4458,16 @@ var Parity = class Parity {
3941
4458
  for (const path of selectModuleKeys(inventory, normalizeDirectories(row.entry.source))) {
3942
4459
  const text = files.get(path);
3943
4460
  if (text === void 0) continue;
3944
- let selected;
3945
- for (const key of keys) {
4461
+ const selected = keys.reduce((previous, key) => {
3946
4462
  const span = locateComment(text, key);
3947
- if (span === void 0) continue;
4463
+ if (span === void 0) return previous;
3948
4464
  const example = collectExamples(normalizeComment(text.slice(span.start, span.end)), target.name).find((entry) => entry.title === title);
3949
- if (example === void 0) continue;
3950
- if (selected === void 0 || span.start < selected.span.start) selected = {
4465
+ if (example === void 0) return previous;
4466
+ return previous === void 0 || span.start < previous.span.start ? {
3951
4467
  span,
3952
4468
  example
3953
- };
3954
- }
4469
+ } : previous;
4470
+ }, void 0);
3955
4471
  if (selected !== void 0) return {
3956
4472
  path,
3957
4473
  text,
@@ -3960,8 +4476,7 @@ var Parity = class Parity {
3960
4476
  }
3961
4477
  }
3962
4478
  };
3963
- //#endregion
3964
- //#region src/core/factories.ts
4479
+ // src/core/factories.ts
3965
4480
  /**
3966
4481
  * Creates a structured {@link GuideInterface} view over one guide's markdown
3967
4482
  * source — parses once and caches its `sections` / `surface` / `methods` /
@@ -3969,13 +4484,16 @@ var Parity = class Parity {
3969
4484
  *
3970
4485
  * @param source - The guide's markdown source text
3971
4486
  * @returns A working {@link GuideInterface}
4487
+ * @throws {@link GuideError} when a Surface header is nonuniform or a keyed Signature cell is empty.
3972
4488
  *
3973
4489
  * @example Construct a Guide from markdown text
3974
4490
  * ```ts
3975
4491
  * import { createGuide } from '@orkestrel/guide'
3976
4492
  *
3977
- * const guide = createGuide('## Surface\n\n| Name | Kind |\n| --- | --- |\n| `X` | class |')
3978
- * guide.surface() // [{ name: 'X', keyword: 'class' }]
4493
+ * const guide = createGuide(
4494
+ * '## Surface\n\n| Name | Kind | Signature | Summary |\n| --- | --- | --- | --- |\n| `X` | class | `new () => X` | |',
4495
+ * )
4496
+ * guide.surface() // [{ name: 'X', keyword: 'class', signature: '`new () => X`' }]
3979
4497
  * guide.sections() // ['Surface']
3980
4498
  * ```
3981
4499
  */
@@ -4147,17 +4665,22 @@ function createMethodGroupContract() {
4147
4665
  function createManifestEntryContract() {
4148
4666
  return (0, _orkestrel_contract.createContract)(manifestEntryShape);
4149
4667
  }
4150
- //#endregion
4151
4668
  exports.DRIFT_CATEGORIES = DRIFT_CATEGORIES;
4152
4669
  exports.EXPORT_KEYWORDS = EXPORT_KEYWORDS;
4153
4670
  exports.EXTERNAL_SCHEMES = EXTERNAL_SCHEMES;
4671
+ exports.GUIDE_CODES = GUIDE_CODES;
4672
+ exports.GUIDE_ERROR_BRAND = GUIDE_ERROR_BRAND;
4154
4673
  exports.Guide = Guide;
4674
+ exports.GuideError = GuideError;
4155
4675
  exports.KIND = KIND;
4156
4676
  exports.MANIFEST = MANIFEST;
4157
4677
  exports.METHODS = METHODS;
4678
+ exports.NAME = NAME;
4158
4679
  exports.Parity = Parity;
4680
+ exports.SIGNATURE = SIGNATURE;
4159
4681
  exports.SUMMARY = SUMMARY;
4160
4682
  exports.SURFACE = SURFACE;
4683
+ exports.SURFACE_HEADER = SURFACE_HEADER;
4161
4684
  exports.Source = Source;
4162
4685
  exports.SourceManager = SourceManager;
4163
4686
  exports.TESTS = TESTS;
@@ -4174,6 +4697,7 @@ exports.collectKeys = collectKeys;
4174
4697
  exports.collectSummaries = collectSummaries;
4175
4698
  exports.collectTitles = collectTitles;
4176
4699
  exports.compareMembership = compareMembership;
4700
+ exports.computeDepths = computeDepths;
4177
4701
  exports.computeDrift = computeDrift;
4178
4702
  exports.computeModuleKey = computeModuleKey;
4179
4703
  exports.computeSymbolKey = computeSymbolKey;
@@ -4205,17 +4729,21 @@ exports.extractMethods = extractMethods;
4205
4729
  exports.extractRowEntry = extractRowEntry;
4206
4730
  exports.extractRowSummary = extractRowSummary;
4207
4731
  exports.extractRowSymbol = extractRowSymbol;
4732
+ exports.extractSignature = extractSignature;
4733
+ exports.extractSignatures = extractSignatures;
4208
4734
  exports.extractSourceComments = extractSourceComments;
4209
4735
  exports.extractSourceLines = extractSourceLines;
4210
4736
  exports.extractSurface = extractSurface;
4211
4737
  exports.extractTagline = extractTagline;
4212
4738
  exports.extractTests = extractTests;
4213
4739
  exports.extractUnnamed = extractUnnamed;
4740
+ exports.findClosing = findClosing;
4214
4741
  exports.findColumnIndex = findColumnIndex;
4215
4742
  exports.findDrift = findDrift;
4216
4743
  exports.findFirstCode = findFirstCode;
4217
4744
  exports.findMissing = findMissing;
4218
4745
  exports.findMissingSymbols = findMissingSymbols;
4746
+ exports.findSeparators = findSeparators;
4219
4747
  exports.findUnexampled = findUnexampled;
4220
4748
  exports.findUnlisted = findUnlisted;
4221
4749
  exports.formatDrift = formatDrift;
@@ -4227,6 +4755,7 @@ exports.isDrift = isDrift;
4227
4755
  exports.isDriftCategory = isDriftCategory;
4228
4756
  exports.isExportKeyword = isExportKeyword;
4229
4757
  exports.isExternalLink = isExternalLink;
4758
+ exports.isGuideError = isGuideError;
4230
4759
  exports.isManifestEntry = isManifestEntry;
4231
4760
  exports.isMethodEntry = isMethodEntry;
4232
4761
  exports.isMethodGroup = isMethodGroup;
@@ -4244,6 +4773,7 @@ exports.normalizeIdentifier = normalizeIdentifier;
4244
4773
  exports.normalizeSummary = normalizeSummary;
4245
4774
  exports.parseManifest = parseManifest;
4246
4775
  exports.renderExample = renderExample;
4776
+ exports.renderMember = renderMember;
4247
4777
  exports.renderMethods = renderMethods;
4248
4778
  exports.renderSurface = renderSurface;
4249
4779
  exports.replaceCell = replaceCell;
@@ -4258,6 +4788,8 @@ exports.sourceExampleShape = sourceExampleShape;
4258
4788
  exports.spliceSpan = spliceSpan;
4259
4789
  exports.surfaceSymbolShape = surfaceSymbolShape;
4260
4790
  exports.unwrapComment = unwrapComment;
4791
+ exports.validateModules = validateModules;
4792
+ exports.validateSurface = validateSurface;
4261
4793
  exports.wrapText = wrapText;
4262
4794
 
4263
4795
  //# sourceMappingURL=index.cjs.map