@hawkeyexl/manni 2.1.0 → 2.3.0

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.
@@ -69,7 +69,7 @@ import {
69
69
  withValueAt,
70
70
  writeEncryptionKey,
71
71
  writeFileAtomic
72
- } from "./chunk-2DC2GSRH.js";
72
+ } from "./chunk-UCLMW3RE.js";
73
73
 
74
74
  // src/meta/core/reencrypt.ts
75
75
  import { extname } from "node:path";
@@ -491,51 +491,12 @@ async function readSource(root, index, range, key) {
491
491
  }
492
492
  }
493
493
 
494
- // src/cite/core/statements.ts
495
- var HTML_COMMENT = { open: "<!--", close: "-->" };
496
- var JSX_COMMENT = { open: "{/*", close: "*/}" };
497
- var LINK_REFERENCE = { open: "[comment]: # (", close: ")" };
498
- var MARKDOWN_FORMS = [HTML_COMMENT, JSX_COMMENT, LINK_REFERENCE];
499
- var MDX_FORMS = [JSX_COMMENT, HTML_COMMENT, LINK_REFERENCE];
500
- var COMMENT_FORMS = [{ open: "<!--", close: "-->" }];
501
- var ASCIIDOC_FORMS = [{ open: "// (", close: ")" }];
502
- var RST_FORMS = [{ open: ".. (", close: ")" }];
503
- var ID = /^[a-z0-9][a-z0-9-]*$/;
504
- var ANY_FENCE = /^(?:[ \t]*(?:`{3,}|~{3,})|-{4,})/;
505
- var MARKDOWN_FENCE = /^(`{3,}|~{3,})/;
506
- var ASCIIDOC_FENCE = /^(-{4,})/;
494
+ // src/shared/code-regions.ts
507
495
  var SKIP_MARKDOWN_FENCE = /^[ \t]*(`{3,}|~{3,})/;
508
- var SKIP_ASCIIDOC_FENCE = ASCIIDOC_FENCE;
496
+ var SKIP_ASCIIDOC_FENCE = /^(-{4,})/;
509
497
  var SPAN_FORMATS = /* @__PURE__ */ new Set(["markdown", "mdx", "asciidoc", "rst"]);
510
- function statementForms(format) {
511
- switch (format) {
512
- case "markdown":
513
- return MARKDOWN_FORMS;
514
- case "mdx":
515
- return MDX_FORMS;
516
- case "html":
517
- case "xml":
518
- return COMMENT_FORMS;
519
- case "asciidoc":
520
- return ASCIIDOC_FORMS;
521
- case "rst":
522
- return RST_FORMS;
523
- default:
524
- return [];
525
- }
526
- }
498
+ var BACKTICK = 96;
527
499
  function fenceFor(format) {
528
- switch (format) {
529
- case "markdown":
530
- case "mdx":
531
- return MARKDOWN_FENCE;
532
- case "asciidoc":
533
- return ASCIIDOC_FENCE;
534
- default:
535
- return void 0;
536
- }
537
- }
538
- function skipFenceFor(format) {
539
500
  switch (format) {
540
501
  case "markdown":
541
502
  case "mdx":
@@ -546,24 +507,23 @@ function skipFenceFor(format) {
546
507
  return void 0;
547
508
  }
548
509
  }
549
- var BACKTICK = 96;
550
510
  function backtickRun(text, i) {
551
511
  let n = 0;
552
512
  while (text.charCodeAt(i + n) === BACKTICK) n++;
553
513
  return n;
554
514
  }
555
- function spanRegions(text, lineStart, out) {
515
+ function spanRegions(line, lineStart, out) {
556
516
  let i = 0;
557
- while (i < text.length) {
558
- const n = backtickRun(text, i);
517
+ while (i < line.length) {
518
+ const n = backtickRun(line, i);
559
519
  if (n === 0) {
560
520
  i++;
561
521
  continue;
562
522
  }
563
523
  let j = i + n;
564
524
  let closer = -1;
565
- while (j < text.length) {
566
- const m = backtickRun(text, j);
525
+ while (j < line.length) {
526
+ const m = backtickRun(line, j);
567
527
  if (m === 0) {
568
528
  j++;
569
529
  continue;
@@ -582,40 +542,87 @@ function spanRegions(text, lineStart, out) {
582
542
  i = closer + n;
583
543
  }
584
544
  }
585
- function closesFence(text, open) {
586
- const trimmed = text.trim();
545
+ function closesFence(line, open) {
546
+ const trimmed = line.trim();
587
547
  let n = 0;
588
548
  while (trimmed.charAt(n) === open.char) n++;
589
549
  return n >= open.length && n === trimmed.length;
590
550
  }
591
- function codeRegions(body, format) {
592
- const fence = skipFenceFor(format);
593
- const spans = SPAN_FORMATS.has(format);
551
+ function codeRegions(text, format, options = {}) {
552
+ const fence = fenceFor(format);
553
+ const spans = options.spans !== false && SPAN_FORMATS.has(format);
594
554
  const out = [];
595
555
  if (fence === void 0 && !spans) return out;
596
556
  let open;
597
557
  let pos = 0;
598
- while (pos < body.length) {
599
- const end = lineEnd(body, pos);
600
- const text = lineText(body, pos, end);
558
+ while (pos < text.length) {
559
+ const nl = text.indexOf("\n", pos);
560
+ const end = nl === -1 ? text.length : nl;
561
+ const raw = text.slice(pos, end);
562
+ const line = raw.endsWith("\r") ? raw.slice(0, -1) : raw;
601
563
  if (open !== void 0) {
602
- if (closesFence(text, open)) {
564
+ if (closesFence(line, open)) {
603
565
  out.push({ start: open.start, end });
604
566
  open = void 0;
605
567
  }
606
568
  } else {
607
- const opener = fence?.exec(text)?.[1];
569
+ const opener = fence?.exec(line)?.[1];
608
570
  if (opener !== void 0) {
609
571
  open = { char: opener.charAt(0), length: opener.length, start: pos };
610
572
  } else if (spans) {
611
- spanRegions(text, pos, out);
573
+ spanRegions(line, pos, out);
612
574
  }
613
575
  }
614
576
  pos = end + 1;
615
577
  }
616
- if (open !== void 0) out.push({ start: open.start, end: body.length });
578
+ if (open !== void 0) out.push({ start: open.start, end: text.length });
617
579
  return out;
618
580
  }
581
+ function codeEndAt(regions, offset) {
582
+ return regions.find((r) => offset >= r.start && offset < r.end)?.end;
583
+ }
584
+
585
+ // src/cite/core/statements.ts
586
+ var HTML_COMMENT = { open: "<!--", close: "-->" };
587
+ var JSX_COMMENT = { open: "{/*", close: "*/}" };
588
+ var LINK_REFERENCE = { open: "[comment]: # (", close: ")" };
589
+ var MARKDOWN_FORMS = [HTML_COMMENT, JSX_COMMENT, LINK_REFERENCE];
590
+ var MDX_FORMS = [JSX_COMMENT, HTML_COMMENT, LINK_REFERENCE];
591
+ var COMMENT_FORMS = [{ open: "<!--", close: "-->" }];
592
+ var ASCIIDOC_FORMS = [{ open: "// (", close: ")" }];
593
+ var RST_FORMS = [{ open: ".. (", close: ")" }];
594
+ var ID = /^[a-z0-9][a-z0-9-]*$/;
595
+ var ANY_FENCE = /^(?:[ \t]*(?:`{3,}|~{3,})|-{4,})/;
596
+ var MARKDOWN_FENCE = /^(`{3,}|~{3,})/;
597
+ var ASCIIDOC_FENCE = /^(-{4,})/;
598
+ function statementForms(format) {
599
+ switch (format) {
600
+ case "markdown":
601
+ return MARKDOWN_FORMS;
602
+ case "mdx":
603
+ return MDX_FORMS;
604
+ case "html":
605
+ case "xml":
606
+ return COMMENT_FORMS;
607
+ case "asciidoc":
608
+ return ASCIIDOC_FORMS;
609
+ case "rst":
610
+ return RST_FORMS;
611
+ default:
612
+ return [];
613
+ }
614
+ }
615
+ function fenceFor2(format) {
616
+ switch (format) {
617
+ case "markdown":
618
+ case "mdx":
619
+ return MARKDOWN_FENCE;
620
+ case "asciidoc":
621
+ return ASCIIDOC_FENCE;
622
+ default:
623
+ return void 0;
624
+ }
625
+ }
619
626
  function lineEnd(content, pos) {
620
627
  const nl = content.indexOf("\n", pos);
621
628
  return nl === -1 ? content.length : nl;
@@ -641,13 +648,12 @@ function parseStatements(body, format, from = { offset: 0, line: 1 }) {
641
648
  const out = [];
642
649
  const fileLine = (bodyOffset) => from.line + lineAt(body, bodyOffset) - 1;
643
650
  const code = codeRegions(body, format);
644
- const codeEndAt = (at2) => code.find((r) => at2 >= r.start && at2 < r.end)?.end;
645
651
  for (const form of statementForms(format)) {
646
652
  let cursor = 0;
647
653
  for (; ; ) {
648
654
  const at2 = body.indexOf(form.open, cursor);
649
655
  if (at2 === -1) break;
650
- const codeEnd = codeEndAt(at2);
656
+ const codeEnd = codeEndAt(code, at2);
651
657
  if (codeEnd !== void 0) {
652
658
  cursor = codeEnd;
653
659
  continue;
@@ -737,7 +743,7 @@ function scanFence(content, offset, fence) {
737
743
  return void 0;
738
744
  }
739
745
  function fencedBlockAfter(content, offset, format) {
740
- const fence = fenceFor(format);
746
+ const fence = fenceFor2(format);
741
747
  if (!fence) return void 0;
742
748
  const block = scanFence(content, offset, fence);
743
749
  if (!block) return void 0;
@@ -755,7 +761,7 @@ function fencedBlockAt(content, offset) {
755
761
  return { start, end, line, text };
756
762
  }
757
763
  function fencedBlocks(content, bodyOffset, format) {
758
- const fence = fenceFor(format);
764
+ const fence = fenceFor2(format);
759
765
  if (!fence) return [];
760
766
  const out = [];
761
767
  let pos = bodyOffset;
@@ -789,7 +795,7 @@ function nextNonBlankLine(text, offset) {
789
795
  return void 0;
790
796
  }
791
797
  function fenceSpanAt(text, line, format) {
792
- const fence = fenceFor(format);
798
+ const fence = fenceFor2(format);
793
799
  if (!fence) return void 0;
794
800
  const block = scanFence(text, offsetOfLine(text, line), fence);
795
801
  if (!block || block.line !== line) return void 0;
@@ -1123,8 +1129,8 @@ import * as Ajv2020Ns from "ajv/dist/2020.js";
1123
1129
  // src/cite/schema/citations.json
1124
1130
  var citations_default = {
1125
1131
  $schema: "https://json-schema.org/draft/2020-12/schema",
1126
- $id: "manni:citations:1.0.0-proposal.3",
1127
- title: "manni citations vocabulary (1.0.0-proposal.3)",
1132
+ $id: "manni:citations:1.0.0-proposal.4",
1133
+ title: "manni citations vocabulary (1.0.0-proposal.4)",
1128
1134
  description: "What do this page's claims rest on? For each claim, the page lines that make it, the source lines it was written from, and a hash of each. A manni common vocabulary: any drift check can implement it, and other schemas may compose on top of it. A pin is a record of the past, not a copy of the present. It says what the lines were when the sentence was written. The check compares that record with the files as they are now. Recompute it on every run and there is nothing to compare against. `source-of-truth` (manni:stewardship) names the file a page answers to; a citation names the lines a sentence answers to. The page root stays open so sibling tools' keys pass untouched. The `citation-` prefix is reserved, so an unrecognized `citation-*` key is rejected and a typo fails loudly.",
1129
1135
  type: "object",
1130
1136
  additionalProperties: true,
@@ -1135,7 +1141,8 @@ var citations_default = {
1135
1141
  items: {
1136
1142
  $ref: "#/$defs/citationEntry"
1137
1143
  },
1138
- description: "The page's citations, one entry per claim or pin. An empty list is not a declaration; a page with no citations omits the key. Ids are unique within a page, and two entries claiming one id is an error. JSON Schema cannot say that over a list whose members may omit the id. So it is a requirement on implementations, stated here so every tool agrees."
1144
+ description: "The page's citations, one entry per claim or pin. An empty list is not a declaration; a page with no citations omits the key. Ids are unique within a page, and two entries claiming one id is an error. JSON Schema cannot say that over a list whose members may omit the id. So it is a requirement on implementations, stated here so every tool agrees.",
1145
+ "x-manni-location": "external"
1139
1146
  }
1140
1147
  },
1141
1148
  patternProperties: {
@@ -1319,7 +1326,7 @@ function subjectOf(entry) {
1319
1326
  function pickExtractor(file, format) {
1320
1327
  if (format !== void 0) {
1321
1328
  const forced = extractorByName(format);
1322
- if (!forced?.implemented) {
1329
+ if (forced === void 0) {
1323
1330
  throw new CiteError(
1324
1331
  `Unknown format "${format}". Supported extensions: ${supportedExtensions().join(", ")}.`
1325
1332
  );
@@ -2581,7 +2588,7 @@ async function prepareRun(opts, action, verb, requireSources = false) {
2581
2588
  }
2582
2589
  const usingStdin = inputs.includes(STDIN_TOKEN);
2583
2590
  const forced = opts.as === void 0 ? void 0 : extractorByName(opts.as);
2584
- if (opts.as !== void 0 && forced?.implemented !== true) {
2591
+ if (opts.as !== void 0 && forced === void 0) {
2585
2592
  throw new CiteError(
2586
2593
  `Unknown format "${opts.as}". Supported extensions: ${supportedExtensions().join(", ")}.`
2587
2594
  );
@@ -3869,7 +3876,7 @@ async function runKeyRotate(opts) {
3869
3876
  if (inputs.length === 0) throw new KeyError(NO_FILES);
3870
3877
  const base = fromCollections && file !== null ? file.dir : cwd;
3871
3878
  const forced = opts.as === void 0 ? void 0 : extractorByName(opts.as);
3872
- if (opts.as !== void 0 && forced?.implemented !== true) {
3879
+ if (opts.as !== void 0 && forced === void 0) {
3873
3880
  throw new KeyError(
3874
3881
  `Unknown format "${opts.as}". Supported extensions: ${supportedExtensions().join(", ")}.`
3875
3882
  );
@@ -4079,6 +4086,8 @@ export {
4079
4086
  isSeverity,
4080
4087
  meetsSeverity,
4081
4088
  reencryptMetadata,
4089
+ codeRegions,
4090
+ codeEndAt,
4082
4091
  CiteError,
4083
4092
  asCiteError,
4084
4093
  spellSource,
@@ -4098,4 +4107,4 @@ export {
4098
4107
  runKeyRotate,
4099
4108
  runKeySet
4100
4109
  };
4101
- //# sourceMappingURL=chunk-UTXTVCBV.js.map
4110
+ //# sourceMappingURL=chunk-ZWPVZUJI.js.map