polytypo 1.4.0 → 1.5.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.
Files changed (61) hide show
  1. package/dist/{chunk-6PQMYL2O.cjs → chunk-55BMPPAR.cjs} +3 -3
  2. package/dist/{chunk-6PQMYL2O.cjs.map → chunk-55BMPPAR.cjs.map} +1 -1
  3. package/dist/{chunk-FZ6YRCGR.cjs → chunk-77CWF35X.cjs} +17 -17
  4. package/dist/{chunk-FZ6YRCGR.cjs.map → chunk-77CWF35X.cjs.map} +1 -1
  5. package/dist/{chunk-HTWCCPWI.js → chunk-A57IM245.js} +4 -4
  6. package/dist/{chunk-DCC5OQET.cjs → chunk-EJ3BHHOQ.cjs} +16 -16
  7. package/dist/{chunk-DCC5OQET.cjs.map → chunk-EJ3BHHOQ.cjs.map} +1 -1
  8. package/dist/chunk-ETKYEVE6.js +5838 -0
  9. package/dist/chunk-ETKYEVE6.js.map +1 -0
  10. package/dist/{chunk-BGTMX6VS.js → chunk-F4UOZBYW.js} +2 -2
  11. package/dist/{chunk-GJJNGBRH.cjs → chunk-J2JVIZ6C.cjs} +4 -4
  12. package/dist/{chunk-GJJNGBRH.cjs.map → chunk-J2JVIZ6C.cjs.map} +1 -1
  13. package/dist/chunk-NPY6XGYB.cjs +33 -0
  14. package/dist/{chunk-JYHDIVON.cjs.map → chunk-NPY6XGYB.cjs.map} +1 -1
  15. package/dist/{chunk-NLMP3JVF.js → chunk-OBE7MMRU.js} +2 -2
  16. package/dist/{chunk-47QVJOT4.js → chunk-QBPOFGSD.js} +2 -2
  17. package/dist/{chunk-D3QQYGKW.js → chunk-S4CDIFBW.js} +2 -2
  18. package/dist/chunk-SD4SLSAR.cjs +5838 -0
  19. package/dist/chunk-SD4SLSAR.cjs.map +1 -0
  20. package/dist/{chunk-GPOCFMTF.js → chunk-XP5JTHSC.js} +4 -4
  21. package/dist/chunk-Z5FXQRXU.cjs +31 -0
  22. package/dist/{chunk-QLIPSKVZ.cjs.map → chunk-Z5FXQRXU.cjs.map} +1 -1
  23. package/dist/{chunk-MOXBMEZB.cjs → chunk-ZJRQBQEA.cjs} +13 -13
  24. package/dist/{chunk-MOXBMEZB.cjs.map → chunk-ZJRQBQEA.cjs.map} +1 -1
  25. package/dist/{chunk-UL7KCRXN.js → chunk-ZZ3OK5SL.js} +3 -3
  26. package/dist/{errors-DMxY1LlK.d.cts → errors-C1_sHGgx.d.cts} +8 -1
  27. package/dist/{errors-DMxY1LlK.d.ts → errors-C1_sHGgx.d.ts} +8 -1
  28. package/dist/html.cjs +10 -10
  29. package/dist/html.d.cts +2 -2
  30. package/dist/html.d.ts +2 -2
  31. package/dist/html.js +5 -5
  32. package/dist/index.cjs +17 -17
  33. package/dist/index.d.cts +2 -2
  34. package/dist/index.d.ts +2 -2
  35. package/dist/index.js +7 -7
  36. package/dist/markdown.cjs +10 -10
  37. package/dist/markdown.d.cts +2 -2
  38. package/dist/markdown.d.ts +2 -2
  39. package/dist/markdown.js +5 -5
  40. package/dist/text.cjs +8 -8
  41. package/dist/text.d.cts +2 -2
  42. package/dist/text.d.ts +2 -2
  43. package/dist/text.js +3 -3
  44. package/dist/yaml.cjs +9 -9
  45. package/dist/yaml.d.cts +2 -2
  46. package/dist/yaml.d.ts +2 -2
  47. package/dist/yaml.js +4 -4
  48. package/package.json +1 -1
  49. package/dist/chunk-25RYOB5K.js +0 -5828
  50. package/dist/chunk-25RYOB5K.js.map +0 -1
  51. package/dist/chunk-JYHDIVON.cjs +0 -33
  52. package/dist/chunk-PJ6HB77G.cjs +0 -5828
  53. package/dist/chunk-PJ6HB77G.cjs.map +0 -1
  54. package/dist/chunk-QLIPSKVZ.cjs +0 -31
  55. /package/dist/{chunk-HTWCCPWI.js.map → chunk-A57IM245.js.map} +0 -0
  56. /package/dist/{chunk-BGTMX6VS.js.map → chunk-F4UOZBYW.js.map} +0 -0
  57. /package/dist/{chunk-NLMP3JVF.js.map → chunk-OBE7MMRU.js.map} +0 -0
  58. /package/dist/{chunk-47QVJOT4.js.map → chunk-QBPOFGSD.js.map} +0 -0
  59. /package/dist/{chunk-D3QQYGKW.js.map → chunk-S4CDIFBW.js.map} +0 -0
  60. /package/dist/{chunk-GPOCFMTF.js.map → chunk-XP5JTHSC.js.map} +0 -0
  61. /package/dist/{chunk-UL7KCRXN.js.map → chunk-ZZ3OK5SL.js.map} +0 -0
@@ -1,11 +1,11 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkPJ6HB77Gcjs = require('./chunk-PJ6HB77G.cjs');
3
+ var _chunkSD4SLSARcjs = require('./chunk-SD4SLSAR.cjs');
4
4
 
5
5
  // src/engine/assert-fixed-mode.ts
6
6
  function assertFixedMode(mode, fixed, entryPoint) {
7
7
  if (mode === void 0 || mode === fixed) return;
8
- throw new (0, _chunkPJ6HB77Gcjs.PolytypoError)(
8
+ throw new (0, _chunkSD4SLSARcjs.PolytypoError)(
9
9
  "POLYTYPO_INVALID_MODE",
10
10
  `"${entryPoint}" only supports mode "${fixed}". Received "${String(mode)}" \u2014 import from "polytypo" for the other modes, or omit \`mode\` here.`
11
11
  );
@@ -14,4 +14,4 @@ function assertFixedMode(mode, fixed, entryPoint) {
14
14
 
15
15
 
16
16
  exports.assertFixedMode = assertFixedMode;
17
- //# sourceMappingURL=chunk-6PQMYL2O.cjs.map
17
+ //# sourceMappingURL=chunk-55BMPPAR.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/polytypo-js/polytypo-js/dist/chunk-6PQMYL2O.cjs","../src/engine/assert-fixed-mode.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACMO,SAAS,eAAA,CAAgB,IAAA,EAAe,KAAA,EAAa,UAAA,EAA0B;AACpF,EAAA,GAAA,CAAI,KAAA,IAAS,KAAA,EAAA,GAAa,KAAA,IAAS,KAAA,EAAO,MAAA;AAC1C,EAAA,MAAM,IAAI,oCAAA;AAAA,IACR,uBAAA;AAAA,IACA,CAAA,CAAA,EAAI,UAAU,CAAA,sBAAA,EAAyB,KAAK,CAAA,aAAA,EAAgB,MAAA,CAAO,IAAI,CAAC,CAAA,2EAAA;AAAA,EAE1E,CAAA;AACF;ADLA;AACA;AACE;AACF,0CAAC","file":"/home/runner/work/polytypo-js/polytypo-js/dist/chunk-6PQMYL2O.cjs","sourcesContent":[null,"import { PolytypoError } from \"../errors.js\";\nimport type { Mode } from \"../types.js\";\n\n/**\n * `polytypo/text`, `polytypo/html` and `polytypo/markdown` each fix `mode` at the type level by\n * omitting it from their Options type (AUDIT_REMEDIATION_AND_RELEASE_PLAN.md 5.1, criterion 6).\n * A plain-JS caller — or a TypeScript caller passing a wider-typed variable, which excess-property\n * checking does not catch — can still supply a conflicting `mode` at runtime. That is rejected\n * explicitly here, never silently ignored or overridden.\n */\nexport function assertFixedMode(mode: unknown, fixed: Mode, entryPoint: string): void {\n if (mode === undefined || mode === fixed) return;\n throw new PolytypoError(\n \"POLYTYPO_INVALID_MODE\",\n `\"${entryPoint}\" only supports mode \"${fixed}\". Received \"${String(mode)}\" — ` +\n `import from \"polytypo\" for the other modes, or omit \\`mode\\` here.`,\n );\n}\n"]}
1
+ {"version":3,"sources":["/home/runner/work/polytypo-js/polytypo-js/dist/chunk-55BMPPAR.cjs","../src/engine/assert-fixed-mode.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACMO,SAAS,eAAA,CAAgB,IAAA,EAAe,KAAA,EAAa,UAAA,EAA0B;AACpF,EAAA,GAAA,CAAI,KAAA,IAAS,KAAA,EAAA,GAAa,KAAA,IAAS,KAAA,EAAO,MAAA;AAC1C,EAAA,MAAM,IAAI,oCAAA;AAAA,IACR,uBAAA;AAAA,IACA,CAAA,CAAA,EAAI,UAAU,CAAA,sBAAA,EAAyB,KAAK,CAAA,aAAA,EAAgB,MAAA,CAAO,IAAI,CAAC,CAAA,2EAAA;AAAA,EAE1E,CAAA;AACF;ADLA;AACA;AACE;AACF,0CAAC","file":"/home/runner/work/polytypo-js/polytypo-js/dist/chunk-55BMPPAR.cjs","sourcesContent":[null,"import { PolytypoError } from \"../errors.js\";\nimport type { Mode } from \"../types.js\";\n\n/**\n * `polytypo/text`, `polytypo/html` and `polytypo/markdown` each fix `mode` at the type level by\n * omitting it from their Options type (AUDIT_REMEDIATION_AND_RELEASE_PLAN.md 5.1, criterion 6).\n * A plain-JS caller — or a TypeScript caller passing a wider-typed variable, which excess-property\n * checking does not catch — can still supply a conflicting `mode` at runtime. That is rejected\n * explicitly here, never silently ignored or overridden.\n */\nexport function assertFixedMode(mode: unknown, fixed: Mode, entryPoint: string): void {\n if (mode === undefined || mode === fixed) return;\n throw new PolytypoError(\n \"POLYTYPO_INVALID_MODE\",\n `\"${entryPoint}\" only supports mode \"${fixed}\". Received \"${String(mode)}\" — ` +\n `import from \"polytypo\" for the other modes, or omit \\`mode\\` here.`,\n );\n}\n"]}
@@ -2,17 +2,17 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkGJJNGBRHcjs = require('./chunk-GJJNGBRH.cjs');
5
+ var _chunkJ2JVIZ6Ccjs = require('./chunk-J2JVIZ6C.cjs');
6
6
 
7
7
 
8
8
 
9
- var _chunkDCC5OQETcjs = require('./chunk-DCC5OQET.cjs');
9
+ var _chunkEJ3BHHOQcjs = require('./chunk-EJ3BHHOQ.cjs');
10
10
 
11
11
 
12
12
 
13
13
 
14
14
 
15
- var _chunkPJ6HB77Gcjs = require('./chunk-PJ6HB77G.cjs');
15
+ var _chunkSD4SLSARcjs = require('./chunk-SD4SLSAR.cjs');
16
16
 
17
17
  // src/modes/markdown.ts
18
18
  var _micromark = require('micromark');
@@ -90,7 +90,7 @@ function updateElementStack(stack, tag, caseSensitive) {
90
90
  if (stack[stack.length - 1] === name) stack.pop();
91
91
  return;
92
92
  }
93
- if (!parsed.selfClosing && _chunkGJJNGBRHcjs.isSkippedElement.call(void 0, name)) stack.push(name);
93
+ if (!parsed.selfClosing && _chunkJ2JVIZ6Ccjs.isSkippedElement.call(void 0, name)) stack.push(name);
94
94
  }
95
95
  function tokenize(source, extensions) {
96
96
  return _micromark.postprocess.call(void 0,
@@ -100,12 +100,12 @@ function tokenize(source, extensions) {
100
100
  function resolveDialect(dialect) {
101
101
  if (dialect === "commonmark" || dialect === "mdx") return dialect;
102
102
  if (dialect === void 0) {
103
- throw new (0, _chunkPJ6HB77Gcjs.PolytypoError)(
103
+ throw new (0, _chunkSD4SLSARcjs.PolytypoError)(
104
104
  "POLYTYPO_INVALID_DIALECT",
105
105
  'Mode "markdown" requires a dialect. Expected "commonmark" or "mdx"; there is no default.'
106
106
  );
107
107
  }
108
- throw new (0, _chunkPJ6HB77Gcjs.PolytypoError)(
108
+ throw new (0, _chunkSD4SLSARcjs.PolytypoError)(
109
109
  "POLYTYPO_INVALID_DIALECT",
110
110
  `Unknown dialect "${String(dialect)}". Expected "commonmark" or "mdx".`
111
111
  );
@@ -116,7 +116,7 @@ function extensionsFor(dialect) {
116
116
  return dialect === "mdx" ? [fm, _micromarkextensiongfm.gfm.call(void 0, ), _micromarkextensionmdxjs.mdxjs.call(void 0, )] : [fm, _micromarkextensiongfm.gfm.call(void 0, )];
117
117
  }
118
118
  function markdownSpans(source, dialect) {
119
- const events = _chunkGJJNGBRHcjs.wrapParserErrors.call(void 0, dialect, () => tokenize(source, extensionsFor(dialect)));
119
+ const events = _chunkJ2JVIZ6Ccjs.wrapParserErrors.call(void 0, dialect, () => tokenize(source, extensionsFor(dialect)));
120
120
  const spans = [];
121
121
  const elementStack = [];
122
122
  let skipDepth = 0;
@@ -139,7 +139,7 @@ function markdownSpans(source, dialect) {
139
139
  }
140
140
  if (type === "htmlFlow") {
141
141
  if (kind === "enter" && skipDepth === 0 && elementStack.length === 0) {
142
- for (const span of _chunkGJJNGBRHcjs.htmlFragmentSpans.call(void 0,
142
+ for (const span of _chunkJ2JVIZ6Ccjs.htmlFragmentSpans.call(void 0,
143
143
  source.slice(token.start.offset, token.end.offset),
144
144
  token.start.offset
145
145
  )) {
@@ -158,19 +158,19 @@ function markdownSpans(source, dialect) {
158
158
 
159
159
  // src/engine/markdown-pipeline.ts
160
160
  function runMarkdownPipeline(input, options) {
161
- const narrowTarget = _chunkPJ6HB77Gcjs.resolveNarrowTarget.call(void 0, options.narrowNbsp);
162
- const planned = _chunkPJ6HB77Gcjs.planRules.call(void 0, options.rules);
163
- const locale = _chunkPJ6HB77Gcjs.getLocaleData.call(void 0, options.locale);
161
+ const narrowTarget = _chunkSD4SLSARcjs.resolveNarrowTarget.call(void 0, options.narrowNbsp);
162
+ const planned = _chunkSD4SLSARcjs.planRules.call(void 0, options.rules);
163
+ const locale = _chunkSD4SLSARcjs.getLocaleData.call(void 0, options.locale);
164
164
  const dialect = resolveDialect(options.dialect);
165
165
  const spans = markdownSpans(input, dialect);
166
- return _chunkDCC5OQETcjs.runOverSpans.call(void 0, input, spans, planned, locale, "markdown", narrowTarget);
166
+ return _chunkEJ3BHHOQcjs.runOverSpans.call(void 0, input, spans, planned, locale, "markdown", narrowTarget);
167
167
  }
168
168
  function analyzeMarkdownPipeline(input, options) {
169
- const narrowTarget = _chunkPJ6HB77Gcjs.resolveNarrowTarget.call(void 0, options.narrowNbsp);
170
- const planned = _chunkPJ6HB77Gcjs.planRules.call(void 0, options.rules);
171
- const locale = _chunkPJ6HB77Gcjs.getLocaleData.call(void 0, options.locale);
169
+ const narrowTarget = _chunkSD4SLSARcjs.resolveNarrowTarget.call(void 0, options.narrowNbsp);
170
+ const planned = _chunkSD4SLSARcjs.planRules.call(void 0, options.rules);
171
+ const locale = _chunkSD4SLSARcjs.getLocaleData.call(void 0, options.locale);
172
172
  const dialect = resolveDialect(options.dialect);
173
- return _chunkDCC5OQETcjs.analyzeOverSpans.call(void 0,
173
+ return _chunkEJ3BHHOQcjs.analyzeOverSpans.call(void 0,
174
174
  input,
175
175
  markdownSpans(input, dialect),
176
176
  planned,
@@ -184,4 +184,4 @@ function analyzeMarkdownPipeline(input, options) {
184
184
 
185
185
 
186
186
  exports.runMarkdownPipeline = runMarkdownPipeline; exports.analyzeMarkdownPipeline = analyzeMarkdownPipeline;
187
- //# sourceMappingURL=chunk-FZ6YRCGR.cjs.map
187
+ //# sourceMappingURL=chunk-77CWF35X.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/polytypo-js/polytypo-js/dist/chunk-FZ6YRCGR.cjs","../src/modes/markdown.ts","../src/engine/markdown-pipeline.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;AChBA,sCAA+C;AAC/C,gFAA4B;AAC5B,gEAAoB;AACpB,oEAAsB;AAgBtB,IAAM,oBAAA,kBAA2C,IAAI,GAAA,CAAI;AAAA;AAAA,EAEvD,YAAA;AAAA,EACA,cAAA;AAAA;AAAA,EAEA,UAAA;AAAA;AAAA,EAEA,UAAA;AAAA,EACA,iBAAA;AAAA;AAAA;AAAA,EAGA,UAAA;AAAA,EACA,WAAA;AAAA,EACA,YAAA;AAAA;AAAA;AAAA;AAAA,EAIA,mBAAA;AAAA,EACA,mBAAA;AAAA,EACA,UAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA;AACF,CAAC,CAAA;AAGD,IAAM,oBAAA,kBAA2C,IAAI,GAAA,CAAI;AAAA,EACvD,UAAA;AAAA,EACA,eAAA;AAAA,EACA;AACF,CAAC,CAAA;AAED,IAAM,UAAA,EAAY,EAAA;AAClB,IAAM,aAAA,EAAe,EAAA;AACrB,IAAM,MAAA,EAAQ,EAAA;AACd,IAAM,YAAA,EAAc,EAAA;AACpB,IAAM,SAAA,EAAW,EAAA;AAEjB,SAAS,aAAA,CAAc,IAAA,EAAuB;AAC5C,EAAA,OAAQ,KAAA,GAAQ,GAAA,GAAQ,KAAA,GAAQ,IAAA,GAAU,KAAA,GAAQ,GAAA,GAAQ,KAAA,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cjs","sourcesContent":[null,"import { parse, postprocess, preprocess } from \"micromark\";\nimport { frontmatter } from \"micromark-extension-frontmatter\";\nimport { gfm } from \"micromark-extension-gfm\";\nimport { mdxjs } from \"micromark-extension-mdxjs\";\nimport type { Event, Extension } from \"micromark-util-types\";\nimport { PolytypoError } from \"../errors.js\";\nimport type { Dialect } from \"../types.js\";\nimport { htmlFragmentSpans, isSkippedElement } from \"./html.js\";\nimport { wrapParserErrors } from \"./parse-error.js\";\nimport type { Span } from \"./spans.js\";\n\n/**\n * spec/rules/modes.md 3.7. Each entry is skipped **whole**, including anything that looks\n * processable inside it. The complement is not enumerated: a span is emitted only for a\n * micromark `data` token, which is the tokenizer's own name for \"literal content\", so list\n * markers, emphasis delimiters, heading sequences, table padding, line endings, hard-break\n * spaces, character escapes and character references are outside every span by construction\n * rather than by a second list that could drift from the first.\n */\nconst SKIPPED_TOKEN_TYPES: ReadonlySet<string> = new Set([\n // fenced code blocks (including the info string and the fences) and indented code blocks\n \"codeFenced\",\n \"codeIndented\",\n // inline code spans, including the backticks\n \"codeText\",\n // autolinks `<https://…>`, and GFM's bare-URL form\n \"autolink\",\n \"literalAutolink\",\n // link and image destinations and titles; the definition line of a reference link. The link\n // *text* is a `labelText`, which is not skipped.\n \"resource\",\n \"reference\",\n \"definition\",\n // MDX: expression containers in full, and every JSX attribute — the whole tag is skipped, so\n // attributes never surface. JSX element *children* sit outside the tag tokens and are\n // processable.\n \"mdxFlowExpression\",\n \"mdxTextExpression\",\n \"mdxjsEsm\",\n // modes.md 3.7.3, and it matters: without it the second `---` of a YAML block reads as a setext\n // underline, `title: Une note` becomes a paragraph, and `fr` puts a narrow no-break space in\n // front of the colon of a machine-read metadata field. Covered by conformance fixtures\n // en-us-markdown-{commonmark,mdx}-frontmatter, fr-markdown-{commonmark,mdx}-frontmatter-nbsp,\n // en-us-markdown-commonmark-frontmatter-toml and -frontmatter-unterminated.\n \"frontmatter\",\n]);\n\n/** Token types whose enter/exit also maintains the skipped-element stack. */\nconst RAW_TAG_TOKEN_TYPES: ReadonlySet<string> = new Set([\n \"htmlText\",\n \"mdxJsxTextTag\",\n \"mdxJsxFlowTag\",\n]);\n\nconst LESS_THAN = 0x3c;\nconst GREATER_THAN = 0x3e;\nconst SLASH = 0x2f;\nconst EXCLAMATION = 0x21;\nconst QUESTION = 0x3f;\n\nfunction isAsciiLetter(unit: number): boolean {\n return (unit >= 0x61 && unit <= 0x7a) || (unit >= 0x41 && unit <= 0x5a);\n}\n\nfunction isTagNameUnit(unit: number): boolean {\n // Deliberately permissive: anything that is not a delimiter belongs to the name. Custom\n // elements (`my-callout`) and member expressions (`Foo.Bar`) must come out whole so that they\n // fail the skip-list membership test rather than being truncated into something that passes.\n return (\n unit !== GREATER_THAN &&\n unit !== SLASH &&\n unit !== 0x20 &&\n unit !== 0x09 &&\n unit !== 0x0a &&\n unit !== 0x0d\n );\n}\n\n/** ASCII-only, because HTML tag names are ASCII case-insensitive and `toLowerCase()` is not. */\nfunction asciiLower(value: string): string {\n let out = \"\";\n for (let i = 0; i < value.length; i += 1) {\n const unit = value.charCodeAt(i);\n out += unit >= 0x41 && unit <= 0x5a ? String.fromCharCode(unit + 0x20) : value[i];\n }\n return out;\n}\n\ninterface RawTag {\n readonly name: string;\n readonly closing: boolean;\n readonly selfClosing: boolean;\n}\n\nfunction readTag(tag: string): RawTag | null {\n if (tag.charCodeAt(0) !== LESS_THAN) return null;\n let i = 1;\n const closing = tag.charCodeAt(i) === SLASH;\n if (closing) i += 1;\n // Comments, declarations and processing instructions carry no element name.\n if (tag.charCodeAt(i) === EXCLAMATION || tag.charCodeAt(i) === QUESTION) return null;\n if (!isAsciiLetter(tag.charCodeAt(i))) return null;\n const nameAt = i;\n while (i < tag.length && isTagNameUnit(tag.charCodeAt(i))) i += 1;\n const selfClosing = tag.charCodeAt(tag.length - 2) === SLASH;\n return { name: tag.slice(nameAt, i), closing, selfClosing };\n}\n\n/**\n * modes.md 3.7: raw HTML is \"handed to the html skip list of 3.6\". Inline raw HTML reaches the\n * tokenizer as isolated tags with ordinary markdown content between them, so honouring the\n * subtree rule means tracking which skipped element is currently open. JSX names are compared\n * case-sensitively (`<Code>` is a component, `<code>` is an element); HTML names are not.\n */\nfunction updateElementStack(stack: string[], tag: string, caseSensitive: boolean): void {\n const parsed = readTag(tag);\n if (parsed === null) return;\n const name = caseSensitive ? parsed.name : asciiLower(parsed.name);\n if (parsed.closing) {\n if (stack[stack.length - 1] === name) stack.pop();\n return;\n }\n if (!parsed.selfClosing && isSkippedElement(name)) stack.push(name);\n}\n\nfunction tokenize(source: string, extensions: readonly Extension[]): Event[] {\n return postprocess(\n parse({ extensions: [...extensions] })\n .document()\n .write(preprocess()(source, null, true)),\n );\n}\n\n/**\n * modes.md 3.7.1. The dialect is the caller's, never detected: `\"commonmark\"` is CommonMark 0.31\n * plus GFM, `\"mdx\"` is the same minus indented code blocks and `<…>` autolinks, plus JSX and\n * `{…}` expression containers. Both enable frontmatter and GFM, which 3.7.2 makes normative —\n * §4's promise that table alignment rows survive is empty unless tables are recognised at all.\n */\nexport function resolveDialect(dialect: Dialect | undefined): Dialect {\n if (dialect === \"commonmark\" || dialect === \"mdx\") return dialect;\n if (dialect === undefined) {\n throw new PolytypoError(\n \"POLYTYPO_INVALID_DIALECT\",\n 'Mode \"markdown\" requires a dialect. Expected \"commonmark\" or \"mdx\"; there is no default.',\n );\n }\n throw new PolytypoError(\n \"POLYTYPO_INVALID_DIALECT\",\n `Unknown dialect \"${String(dialect)}\". Expected \"commonmark\" or \"mdx\".`,\n );\n}\n\n// modes.md 3.7.3 names both frontmatter delimiters, `---` (YAML) and `+++` (TOML), and skips\n// either whole. micromark's default matter is YAML alone, so both must be asked for by name: with\n// the default, a `+++` block parses as prose and the machine-read fields inside it get typeset.\nconst FRONTMATTER_MATTERS = [\"yaml\", \"toml\"] as const;\n\nfunction extensionsFor(dialect: Dialect): Extension[] {\n const fm = frontmatter([...FRONTMATTER_MATTERS]);\n return dialect === \"mdx\" ? [fm, gfm(), mdxjs()] : [fm, gfm()];\n}\n\nexport function markdownSpans(source: string, dialect: Dialect): Span[] {\n const events = wrapParserErrors(dialect, () => tokenize(source, extensionsFor(dialect)));\n const spans: Span[] = [];\n const elementStack: string[] = [];\n let skipDepth = 0;\n\n for (const [kind, token] of events) {\n const type = token.type;\n\n if (SKIPPED_TOKEN_TYPES.has(type)) {\n skipDepth += kind === \"enter\" ? 1 : -1;\n continue;\n }\n\n if (RAW_TAG_TOKEN_TYPES.has(type)) {\n if (kind === \"enter\") {\n updateElementStack(\n elementStack,\n source.slice(token.start.offset, token.end.offset),\n type !== \"htmlText\",\n );\n }\n skipDepth += kind === \"enter\" ? 1 : -1;\n continue;\n }\n\n // An HTML block is handed to the `html` extractor rather than skipped whole, so that the\n // prose inside `<div>…</div>` is typeset while the markup is not.\n if (type === \"htmlFlow\") {\n if (kind === \"enter\" && skipDepth === 0 && elementStack.length === 0) {\n for (const span of htmlFragmentSpans(\n source.slice(token.start.offset, token.end.offset),\n token.start.offset,\n )) {\n spans.push(span);\n }\n }\n skipDepth += kind === \"enter\" ? 1 : -1;\n continue;\n }\n\n if (kind === \"enter\" && type === \"data\" && skipDepth === 0 && elementStack.length === 0) {\n spans.push({ start: token.start.offset, end: token.end.offset });\n }\n }\n\n return spans;\n}\n","import { markdownSpans, resolveDialect } from \"../modes/markdown.js\";\nimport type { Options } from \"../types.js\";\nimport { getLocaleData } from \"./locale.js\";\nimport { resolveNarrowTarget } from \"./narrow-target.js\";\nimport { planRules } from \"./rule-runner.js\";\nimport { analyzeOverSpans, runOverSpans } from \"./span-runner.js\";\nimport type { Change } from \"./origin.js\";\n\n/**\n * `markdown` mode only. Imports the Micromark/MDX stack and `parse5` (via `../modes/markdown.js`\n * importing `../modes/html.js` for normative embedded-HTML handling, modes.md 3.7) — both are\n * legitimately reachable from `polytypo/markdown` (AUDIT_REMEDIATION_AND_RELEASE_PLAN.md 5.1).\n *\n * Validation order — `planRules`, then `getLocaleData`, then `resolveDialect`/parsing — mirrors\n * the pre-Stage-5 aggregate `runPipeline` exactly: an unknown-rule error wins over an\n * unknown-locale error, which wins over a missing/invalid dialect, which wins over a parse\n * failure. All four are public, tested behaviour this refactor was not authorised to change.\n */\nexport function runMarkdownPipeline(input: string, options: Partial<Options>): string {\n const narrowTarget = resolveNarrowTarget(options.narrowNbsp);\n const planned = planRules(options.rules);\n const locale = getLocaleData(options.locale);\n const dialect = resolveDialect(options.dialect);\n const spans = markdownSpans(input, dialect);\n return runOverSpans(input, spans, planned, locale, \"markdown\", narrowTarget);\n}\n\n/** analyze.md §1, `markdown` mode. Dialect validation happens here exactly as it does for\n * `runMarkdownPipeline`, so an absent dialect throws POLYTYPO_INVALID_DIALECT from `analyze`\n * too (analyze.md §4 A1). */\nexport function analyzeMarkdownPipeline(input: string, options: Partial<Options>): Change[] {\n const narrowTarget = resolveNarrowTarget(options.narrowNbsp);\n const planned = planRules(options.rules);\n const locale = getLocaleData(options.locale);\n const dialect = resolveDialect(options.dialect);\n return analyzeOverSpans(\n input,\n markdownSpans(input, dialect),\n planned,\n locale,\n \"markdown\",\n narrowTarget,\n );\n}\n"]}
1
+ {"version":3,"sources":["/home/runner/work/polytypo-js/polytypo-js/dist/chunk-77CWF35X.cjs","../src/modes/markdown.ts","../src/engine/markdown-pipeline.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;AChBA,sCAA+C;AAC/C,gFAA4B;AAC5B,gEAAoB;AACpB,oEAAsB;AAgBtB,IAAM,oBAAA,kBAA2C,IAAI,GAAA,CAAI;AAAA;AAAA,EAEvD,YAAA;AAAA,EACA,cAAA;AAAA;AAAA,EAEA,UAAA;AAAA;AAAA,EAEA,UAAA;AAAA,EACA,iBAAA;AAAA;AAAA;AAAA,EAGA,UAAA;AAAA,EACA,WAAA;AAAA,EACA,YAAA;AAAA;AAAA;AAAA;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,EAAA,MAAM,aAAA,EAAe,mDAAA,OAAoB,CAAQ,UAAU,CAAA;AAC3D,EAAA,MAAM,QAAA,EAAU,yCAAA,OAAU,CAAQ,KAAK,CAAA;AACvC,EAAA,MAAM,OAAA,EAAS,6CAAA,OAAc,CAAQ,MAAM,CAAA;AAC3C,EAAA,MAAM,QAAA,EAAU,cAAA,CAAe,OAAA,CAAQ,OAAO,CAAA;AAC9C,EAAA,OAAO,gDAAA;AAAA,IACL,KAAA;AAAA,IACA,aAAA,CAAc,KAAA,EAAO,OAAO,CAAA;AAAA,IAC5B,OAAA;AAAA,IACA,MAAA;AAAA,IACA,UAAA;AAAA,IACA;AAAA,EACF,CAAA;AACF;AF0IA;AACA;AACE;AACA;AACF,6GAAC","file":"/home/runner/work/polytypo-js/polytypo-js/dist/chunk-77CWF35X.cjs","sourcesContent":[null,"import { parse, postprocess, preprocess } from \"micromark\";\nimport { frontmatter } from \"micromark-extension-frontmatter\";\nimport { gfm } from \"micromark-extension-gfm\";\nimport { mdxjs } from \"micromark-extension-mdxjs\";\nimport type { Event, Extension } from \"micromark-util-types\";\nimport { PolytypoError } from \"../errors.js\";\nimport type { Dialect } from \"../types.js\";\nimport { htmlFragmentSpans, isSkippedElement } from \"./html.js\";\nimport { wrapParserErrors } from \"./parse-error.js\";\nimport type { Span } from \"./spans.js\";\n\n/**\n * spec/rules/modes.md 3.7. Each entry is skipped **whole**, including anything that looks\n * processable inside it. The complement is not enumerated: a span is emitted only for a\n * micromark `data` token, which is the tokenizer's own name for \"literal content\", so list\n * markers, emphasis delimiters, heading sequences, table padding, line endings, hard-break\n * spaces, character escapes and character references are outside every span by construction\n * rather than by a second list that could drift from the first.\n */\nconst SKIPPED_TOKEN_TYPES: ReadonlySet<string> = new Set([\n // fenced code blocks (including the info string and the fences) and indented code blocks\n \"codeFenced\",\n \"codeIndented\",\n // inline code spans, including the backticks\n \"codeText\",\n // autolinks `<https://…>`, and GFM's bare-URL form\n \"autolink\",\n \"literalAutolink\",\n // link and image destinations and titles; the definition line of a reference link. The link\n // *text* is a `labelText`, which is not skipped.\n \"resource\",\n \"reference\",\n \"definition\",\n // MDX: expression containers in full, and every JSX attribute — the whole tag is skipped, so\n // attributes never surface. JSX element *children* sit outside the tag tokens and are\n // processable.\n \"mdxFlowExpression\",\n \"mdxTextExpression\",\n \"mdxjsEsm\",\n // modes.md 3.7.3, and it matters: without it the second `---` of a YAML block reads as a setext\n // underline, `title: Une note` becomes a paragraph, and `fr` puts a narrow no-break space in\n // front of the colon of a machine-read metadata field. Covered by conformance fixtures\n // en-us-markdown-{commonmark,mdx}-frontmatter, fr-markdown-{commonmark,mdx}-frontmatter-nbsp,\n // en-us-markdown-commonmark-frontmatter-toml and -frontmatter-unterminated.\n \"frontmatter\",\n]);\n\n/** Token types whose enter/exit also maintains the skipped-element stack. */\nconst RAW_TAG_TOKEN_TYPES: ReadonlySet<string> = new Set([\n \"htmlText\",\n \"mdxJsxTextTag\",\n \"mdxJsxFlowTag\",\n]);\n\nconst LESS_THAN = 0x3c;\nconst GREATER_THAN = 0x3e;\nconst SLASH = 0x2f;\nconst EXCLAMATION = 0x21;\nconst QUESTION = 0x3f;\n\nfunction isAsciiLetter(unit: number): boolean {\n return (unit >= 0x61 && unit <= 0x7a) || (unit >= 0x41 && unit <= 0x5a);\n}\n\nfunction isTagNameUnit(unit: number): boolean {\n // Deliberately permissive: anything that is not a delimiter belongs to the name. Custom\n // elements (`my-callout`) and member expressions (`Foo.Bar`) must come out whole so that they\n // fail the skip-list membership test rather than being truncated into something that passes.\n return (\n unit !== GREATER_THAN &&\n unit !== SLASH &&\n unit !== 0x20 &&\n unit !== 0x09 &&\n unit !== 0x0a &&\n unit !== 0x0d\n );\n}\n\n/** ASCII-only, because HTML tag names are ASCII case-insensitive and `toLowerCase()` is not. */\nfunction asciiLower(value: string): string {\n let out = \"\";\n for (let i = 0; i < value.length; i += 1) {\n const unit = value.charCodeAt(i);\n out += unit >= 0x41 && unit <= 0x5a ? String.fromCharCode(unit + 0x20) : value[i];\n }\n return out;\n}\n\ninterface RawTag {\n readonly name: string;\n readonly closing: boolean;\n readonly selfClosing: boolean;\n}\n\nfunction readTag(tag: string): RawTag | null {\n if (tag.charCodeAt(0) !== LESS_THAN) return null;\n let i = 1;\n const closing = tag.charCodeAt(i) === SLASH;\n if (closing) i += 1;\n // Comments, declarations and processing instructions carry no element name.\n if (tag.charCodeAt(i) === EXCLAMATION || tag.charCodeAt(i) === QUESTION) return null;\n if (!isAsciiLetter(tag.charCodeAt(i))) return null;\n const nameAt = i;\n while (i < tag.length && isTagNameUnit(tag.charCodeAt(i))) i += 1;\n const selfClosing = tag.charCodeAt(tag.length - 2) === SLASH;\n return { name: tag.slice(nameAt, i), closing, selfClosing };\n}\n\n/**\n * modes.md 3.7: raw HTML is \"handed to the html skip list of 3.6\". Inline raw HTML reaches the\n * tokenizer as isolated tags with ordinary markdown content between them, so honouring the\n * subtree rule means tracking which skipped element is currently open. JSX names are compared\n * case-sensitively (`<Code>` is a component, `<code>` is an element); HTML names are not.\n */\nfunction updateElementStack(stack: string[], tag: string, caseSensitive: boolean): void {\n const parsed = readTag(tag);\n if (parsed === null) return;\n const name = caseSensitive ? parsed.name : asciiLower(parsed.name);\n if (parsed.closing) {\n if (stack[stack.length - 1] === name) stack.pop();\n return;\n }\n if (!parsed.selfClosing && isSkippedElement(name)) stack.push(name);\n}\n\nfunction tokenize(source: string, extensions: readonly Extension[]): Event[] {\n return postprocess(\n parse({ extensions: [...extensions] })\n .document()\n .write(preprocess()(source, null, true)),\n );\n}\n\n/**\n * modes.md 3.7.1. The dialect is the caller's, never detected: `\"commonmark\"` is CommonMark 0.31\n * plus GFM, `\"mdx\"` is the same minus indented code blocks and `<…>` autolinks, plus JSX and\n * `{…}` expression containers. Both enable frontmatter and GFM, which 3.7.2 makes normative —\n * §4's promise that table alignment rows survive is empty unless tables are recognised at all.\n */\nexport function resolveDialect(dialect: Dialect | undefined): Dialect {\n if (dialect === \"commonmark\" || dialect === \"mdx\") return dialect;\n if (dialect === undefined) {\n throw new PolytypoError(\n \"POLYTYPO_INVALID_DIALECT\",\n 'Mode \"markdown\" requires a dialect. Expected \"commonmark\" or \"mdx\"; there is no default.',\n );\n }\n throw new PolytypoError(\n \"POLYTYPO_INVALID_DIALECT\",\n `Unknown dialect \"${String(dialect)}\". Expected \"commonmark\" or \"mdx\".`,\n );\n}\n\n// modes.md 3.7.3 names both frontmatter delimiters, `---` (YAML) and `+++` (TOML), and skips\n// either whole. micromark's default matter is YAML alone, so both must be asked for by name: with\n// the default, a `+++` block parses as prose and the machine-read fields inside it get typeset.\nconst FRONTMATTER_MATTERS = [\"yaml\", \"toml\"] as const;\n\nfunction extensionsFor(dialect: Dialect): Extension[] {\n const fm = frontmatter([...FRONTMATTER_MATTERS]);\n return dialect === \"mdx\" ? [fm, gfm(), mdxjs()] : [fm, gfm()];\n}\n\nexport function markdownSpans(source: string, dialect: Dialect): Span[] {\n const events = wrapParserErrors(dialect, () => tokenize(source, extensionsFor(dialect)));\n const spans: Span[] = [];\n const elementStack: string[] = [];\n let skipDepth = 0;\n\n for (const [kind, token] of events) {\n const type = token.type;\n\n if (SKIPPED_TOKEN_TYPES.has(type)) {\n skipDepth += kind === \"enter\" ? 1 : -1;\n continue;\n }\n\n if (RAW_TAG_TOKEN_TYPES.has(type)) {\n if (kind === \"enter\") {\n updateElementStack(\n elementStack,\n source.slice(token.start.offset, token.end.offset),\n type !== \"htmlText\",\n );\n }\n skipDepth += kind === \"enter\" ? 1 : -1;\n continue;\n }\n\n // An HTML block is handed to the `html` extractor rather than skipped whole, so that the\n // prose inside `<div>…</div>` is typeset while the markup is not.\n if (type === \"htmlFlow\") {\n if (kind === \"enter\" && skipDepth === 0 && elementStack.length === 0) {\n for (const span of htmlFragmentSpans(\n source.slice(token.start.offset, token.end.offset),\n token.start.offset,\n )) {\n spans.push(span);\n }\n }\n skipDepth += kind === \"enter\" ? 1 : -1;\n continue;\n }\n\n if (kind === \"enter\" && type === \"data\" && skipDepth === 0 && elementStack.length === 0) {\n spans.push({ start: token.start.offset, end: token.end.offset });\n }\n }\n\n return spans;\n}\n","import { markdownSpans, resolveDialect } from \"../modes/markdown.js\";\nimport type { Options } from \"../types.js\";\nimport { getLocaleData } from \"./locale.js\";\nimport { resolveNarrowTarget } from \"./narrow-target.js\";\nimport { planRules } from \"./rule-runner.js\";\nimport { analyzeOverSpans, runOverSpans } from \"./span-runner.js\";\nimport type { Change } from \"./origin.js\";\n\n/**\n * `markdown` mode only. Imports the Micromark/MDX stack and `parse5` (via `../modes/markdown.js`\n * importing `../modes/html.js` for normative embedded-HTML handling, modes.md 3.7) — both are\n * legitimately reachable from `polytypo/markdown` (AUDIT_REMEDIATION_AND_RELEASE_PLAN.md 5.1).\n *\n * Validation order — `planRules`, then `getLocaleData`, then `resolveDialect`/parsing — mirrors\n * the pre-Stage-5 aggregate `runPipeline` exactly: an unknown-rule error wins over an\n * unknown-locale error, which wins over a missing/invalid dialect, which wins over a parse\n * failure. All four are public, tested behaviour this refactor was not authorised to change.\n */\nexport function runMarkdownPipeline(input: string, options: Partial<Options>): string {\n const narrowTarget = resolveNarrowTarget(options.narrowNbsp);\n const planned = planRules(options.rules);\n const locale = getLocaleData(options.locale);\n const dialect = resolveDialect(options.dialect);\n const spans = markdownSpans(input, dialect);\n return runOverSpans(input, spans, planned, locale, \"markdown\", narrowTarget);\n}\n\n/** analyze.md §1, `markdown` mode. Dialect validation happens here exactly as it does for\n * `runMarkdownPipeline`, so an absent dialect throws POLYTYPO_INVALID_DIALECT from `analyze`\n * too (analyze.md §4 A1). */\nexport function analyzeMarkdownPipeline(input: string, options: Partial<Options>): Change[] {\n const narrowTarget = resolveNarrowTarget(options.narrowNbsp);\n const planned = planRules(options.rules);\n const locale = getLocaleData(options.locale);\n const dialect = resolveDialect(options.dialect);\n return analyzeOverSpans(\n input,\n markdownSpans(input, dialect),\n planned,\n locale,\n \"markdown\",\n narrowTarget,\n );\n}\n"]}
@@ -2,17 +2,17 @@ import {
2
2
  htmlFragmentSpans,
3
3
  isSkippedElement,
4
4
  wrapParserErrors
5
- } from "./chunk-BGTMX6VS.js";
5
+ } from "./chunk-F4UOZBYW.js";
6
6
  import {
7
7
  analyzeOverSpans,
8
8
  runOverSpans
9
- } from "./chunk-NLMP3JVF.js";
9
+ } from "./chunk-OBE7MMRU.js";
10
10
  import {
11
11
  PolytypoError,
12
12
  getLocaleData,
13
13
  planRules,
14
14
  resolveNarrowTarget
15
- } from "./chunk-25RYOB5K.js";
15
+ } from "./chunk-ETKYEVE6.js";
16
16
 
17
17
  // src/modes/markdown.ts
18
18
  import { parse, postprocess, preprocess } from "micromark";
@@ -184,4 +184,4 @@ export {
184
184
  runMarkdownPipeline,
185
185
  analyzeMarkdownPipeline
186
186
  };
187
- //# sourceMappingURL=chunk-HTWCCPWI.js.map
187
+ //# sourceMappingURL=chunk-A57IM245.js.map
@@ -9,7 +9,7 @@
9
9
 
10
10
 
11
11
 
12
- var _chunkPJ6HB77Gcjs = require('./chunk-PJ6HB77G.cjs');
12
+ var _chunkSD4SLSARcjs = require('./chunk-SD4SLSAR.cjs');
13
13
 
14
14
  // src/modes/spans.ts
15
15
  var SPACE = 32;
@@ -38,7 +38,7 @@ function normalizeSpans(spans) {
38
38
  continue;
39
39
  }
40
40
  if (span.start < last.end) {
41
- throw new (0, _chunkPJ6HB77Gcjs.PolytypoError)(
41
+ throw new (0, _chunkSD4SLSARcjs.PolytypoError)(
42
42
  "POLYTYPO_RULE_CONTRACT",
43
43
  `mode extractor produced overlapping spans (${last.start}, ${last.end}) and (${span.start}, ${span.end})`
44
44
  );
@@ -56,9 +56,9 @@ function concatenateSpans(source, spans) {
56
56
  let previous;
57
57
  for (const span of spans) {
58
58
  if (previous !== void 0) {
59
- cp.push(gapIsLineBoundary(source, previous.end, span.start) ? _chunkPJ6HB77Gcjs.LINE_MARKER : _chunkPJ6HB77Gcjs.MARKER);
59
+ cp.push(gapIsLineBoundary(source, previous.end, span.start) ? _chunkSD4SLSARcjs.LINE_MARKER : _chunkSD4SLSARcjs.MARKER);
60
60
  }
61
- for (const value of _chunkPJ6HB77Gcjs.toCodePoints.call(void 0, source.slice(span.start, span.end))) cp.push(value);
61
+ for (const value of _chunkSD4SLSARcjs.toCodePoints.call(void 0, source.slice(span.start, span.end))) cp.push(value);
62
62
  previous = span;
63
63
  }
64
64
  return cp;
@@ -67,7 +67,7 @@ function spanRangesOf(cp) {
67
67
  const ranges = [];
68
68
  let first = 0;
69
69
  for (let i = 0; i < cp.length; i += 1) {
70
- if (_chunkPJ6HB77Gcjs.isMarker.call(void 0, cp[i])) {
70
+ if (_chunkSD4SLSARcjs.isMarker.call(void 0, cp[i])) {
71
71
  ranges.push({ first, last: i - 1 });
72
72
  first = i + 1;
73
73
  }
@@ -86,7 +86,7 @@ function filterBoundaryEdits(cp, edits, ranges) {
86
86
  for (const edit of edits) {
87
87
  let containsMarker = false;
88
88
  for (let i = edit.start; i < edit.end; i += 1) {
89
- if (_chunkPJ6HB77Gcjs.isMarker.call(void 0, cp[i])) {
89
+ if (_chunkSD4SLSARcjs.isMarker.call(void 0, cp[i])) {
90
90
  containsMarker = true;
91
91
  break;
92
92
  }
@@ -111,14 +111,14 @@ function filterBoundaryEdits(cp, edits, ranges) {
111
111
  function splitOnMarker(cp, expected) {
112
112
  const pieces = [[]];
113
113
  for (const value of cp) {
114
- if (_chunkPJ6HB77Gcjs.isMarker.call(void 0, value)) {
114
+ if (_chunkSD4SLSARcjs.isMarker.call(void 0, value)) {
115
115
  pieces.push([]);
116
116
  continue;
117
117
  }
118
118
  pieces[pieces.length - 1].push(value);
119
119
  }
120
120
  if (pieces.length !== expected) {
121
- throw new (0, _chunkPJ6HB77Gcjs.PolytypoError)(
121
+ throw new (0, _chunkSD4SLSARcjs.PolytypoError)(
122
122
  "POLYTYPO_RULE_CONTRACT",
123
123
  `boundary markers did not survive the pipeline: expected ${expected} spans, found ${pieces.length}`
124
124
  );
@@ -140,9 +140,9 @@ function originOfSpans(source, spans) {
140
140
  const origin = [];
141
141
  let previous;
142
142
  for (const span of spans) {
143
- if (previous !== void 0) origin.push(_chunkPJ6HB77Gcjs.NO_ORIGIN);
143
+ if (previous !== void 0) origin.push(_chunkSD4SLSARcjs.NO_ORIGIN);
144
144
  const base = codePointIndexOf[span.start];
145
- const length = _chunkPJ6HB77Gcjs.toCodePoints.call(void 0, source.slice(span.start, span.end)).length;
145
+ const length = _chunkSD4SLSARcjs.toCodePoints.call(void 0, source.slice(span.start, span.end)).length;
146
146
  for (let k = 0; k < length; k += 1) origin.push(base + k);
147
147
  previous = span;
148
148
  }
@@ -153,10 +153,10 @@ function originOfSpans(source, spans) {
153
153
  function runRulesOverSpans(cp, planned, locale, mode, narrowTarget) {
154
154
  let current = cp;
155
155
  for (const id of planned) {
156
- const rule = _chunkPJ6HB77Gcjs.RULES[id];
156
+ const rule = _chunkSD4SLSARcjs.RULES[id];
157
157
  if (rule === void 0) continue;
158
158
  const edits = rule.apply({ cp: current, locale, mode, narrowTarget });
159
- current = _chunkPJ6HB77Gcjs.applyEdits.call(void 0, current, filterBoundaryEdits(current, edits, spanRangesOf(current)), id);
159
+ current = _chunkSD4SLSARcjs.applyEdits.call(void 0, current, filterBoundaryEdits(current, edits, spanRangesOf(current)), id);
160
160
  }
161
161
  return current;
162
162
  }
@@ -175,7 +175,7 @@ function runOverSpans(source, spans, planned, locale, mode, narrowTarget) {
175
175
  let cursor = 0;
176
176
  for (let i = 0; i < normalized.length; i += 1) {
177
177
  const span = normalized[i];
178
- const replacement = _chunkPJ6HB77Gcjs.fromCodePoints.call(void 0, pieces[i]);
178
+ const replacement = _chunkSD4SLSARcjs.fromCodePoints.call(void 0, pieces[i]);
179
179
  const original = source.slice(span.start, span.end);
180
180
  out += source.slice(cursor, span.start);
181
181
  out += replacement === original ? original : replacement;
@@ -186,14 +186,14 @@ function runOverSpans(source, spans, planned, locale, mode, narrowTarget) {
186
186
  function analyzeOverSpans(source, spans, planned, locale, mode, narrowTarget) {
187
187
  const normalized = normalizeSpans(spans);
188
188
  if (normalized.length === 0) return [];
189
- return _chunkPJ6HB77Gcjs.runRulesRecording.call(void 0,
189
+ return _chunkSD4SLSARcjs.runRulesRecording.call(void 0,
190
190
  concatenateSpans(source, normalized),
191
191
  planned,
192
192
  locale,
193
193
  mode,
194
194
  narrowTarget,
195
195
  originOfSpans(source, normalized),
196
- _chunkPJ6HB77Gcjs.toCodePoints.call(void 0, source).length,
196
+ _chunkSD4SLSARcjs.toCodePoints.call(void 0, source).length,
197
197
  (current, edits) => filterBoundaryEdits(current, edits, spanRangesOf(current))
198
198
  );
199
199
  }
@@ -202,4 +202,4 @@ function analyzeOverSpans(source, spans, planned, locale, mode, narrowTarget) {
202
202
 
203
203
 
204
204
  exports.runOverSpans = runOverSpans; exports.analyzeOverSpans = analyzeOverSpans;
205
- //# sourceMappingURL=chunk-DCC5OQET.cjs.map
205
+ //# sourceMappingURL=chunk-EJ3BHHOQ.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/polytypo-js/polytypo-js/dist/chunk-DCC5OQET.cjs","../src/modes/spans.ts","../src/engine/span-runner.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACMA,IAAM,MAAA,EAAQ,EAAA;AAEd,IAAM,iBAAA,kBAAwC,IAAI,GAAA,CAAI;AAAA,EACpD,EAAA;AAAA,EAAM,EAAA;AAAA,EAAM,EAAA;AAAA,EAAM,EAAA;AAAA,EAAM,GAAA;AAAA,EAAM,IAAA;AAAA,EAAQ;AACxC,CAAC,CAAA;AAED,SAAS,iBAAA,CAAkB,MAAA,EAAgB,IAAA,EAAc,EAAA,EAAqB;AAC5E,EAAA,IAAA,CAAA,IAAS,EAAA,EAAI,IAAA,EAAM,EAAA,EAAI,EAAA,EAAI,EAAA,GAAK,CAAA,EAAG;AACjC,IAAA,GAAA,CAAI,gBAAA,CAAiB,GAAA,CAAI,MAAA,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AAA,cAAA,EAAiB,MAAA,CAAO,MAAM,CAAA;AAAA,IAAA;AACnG,EAAA;AAEF,EAAA;AACF;AASO;AACL,EAAA;AACA,EAAA;AACA,EAAA;AACE,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAAW,EAAA;AAEb,EAAA;AAEA,EAAA;AACA,EAAA;AACA,EAAA;AACE,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAAW,EAAA;AAEb,EAAA;AACF;ADlFA;AACA;AEjIA;AAOE,EAAA;AACA,EAAA;AACE,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAA4F,EAAA;AAE9F,EAAA;AACF;AAYO;AAQL,EAAA;AACA,EAAA;AAEA,EAAA;AAAoB,IAAA;AACiB,IAAA;AACnC,IAAA;AACA,IAAA;AACA,IAAA;AACA,EAAA;AAEF,EAAA;AAEA,EAAA;AACA,EAAA;AACA,EAAA;AACE,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAAc,EAAA;AAEhB,EAAA;AACF;AAOO;AAQL,EAAA;AACA,EAAA;AACA,EAAA;AAAO,IAAA;AAC8B,IAAA;AACnC,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACgC,IAAA;AACX,IAAA;AACwD,EAAA;AAEjF;AF4FA;AACA;AACA;AACA;AACA","file":"/home/runner/work/polytypo-js/polytypo-js/dist/chunk-DCC5OQET.cjs","sourcesContent":[null,"import { toCodePoints } from \"../engine/codepoints.js\";\nimport { isMarker, LINE_MARKER, MARKER } from \"../engine/sentinels.js\";\nimport { PolytypoError } from \"../errors.js\";\nimport type { Edit } from \"../types.js\";\nimport { NO_ORIGIN } from \"../engine/origin.js\";\n\n/**\n * The boundary markers are defined in the engine (src/engine/sentinels.ts), which is where all\n * three non-code-point sentinels live and where their disjointness is maintained. They are\n * re-exported here because the mode layer is what writes them into the array.\n *\n * Which marker separates two spans is decided by the **raw source bytes of the gap between\n * them**, so it is decidable without asking the parser anything and is identical in five\n * runtimes: a gap containing a line terminator gives `LINE_MARKER`, anything else `MARKER`.\n */\nexport { LINE_MARKER, MARKER, isMarker } from \"../engine/sentinels.js\";\n\n/** `BREAK` as the rules define it (`spaces.md` 3.1), tested against the gap's raw source. */\n/** U+0020, the one emitted code point whose meaning is positional (modes.md 3.4, 5 item 2). */\nconst SPACE = 0x20;\n\nconst LINE_TERMINATORS: ReadonlySet<number> = new Set([\n 0x0a, 0x0d, 0x0b, 0x0c, 0x85, 0x2028, 0x2029,\n]);\n\nfunction gapIsLineBoundary(source: string, from: number, to: number): boolean {\n for (let i = from; i < to; i += 1) {\n if (LINE_TERMINATORS.has(source.charCodeAt(i))) return true;\n }\n return false;\n}\n\n/**\n * A processable span, identified by its offsets in the **original source**. Offsets are UTF-16\n * indices into the JS source string, which is what every JS parser reports; they are an\n * implementation detail of this runtime and never reach the rules, which index code points.\n */\nexport interface Span {\n readonly start: number;\n readonly end: number;\n}\n\n/** A span's extent in the concatenated code-point array: `s₀` and `s₁` of modes.md 3.4. */\nexport interface SpanRange {\n readonly first: number;\n readonly last: number;\n}\n\n/**\n * Sort, drop empties, and coalesce spans separated by nothing in the source (modes.md 7.5:\n * a parser that reports one text run as two adjacent nodes must not manufacture a boundary).\n * Overlapping spans are an extractor bug and are rejected rather than silently merged.\n */\nexport function normalizeSpans(spans: readonly Span[]): Span[] {\n const sorted = spans.filter((s) => s.end > s.start).sort((a, b) => a.start - b.start);\n const out: Span[] = [];\n for (const span of sorted) {\n const last = out[out.length - 1];\n if (last === undefined) {\n out.push(span);\n continue;\n }\n if (span.start < last.end) {\n throw new PolytypoError(\n \"POLYTYPO_RULE_CONTRACT\",\n `mode extractor produced overlapping spans (${last.start}, ${last.end}) and (${span.start}, ${span.end})`,\n );\n }\n if (span.start === last.end) {\n out[out.length - 1] = { start: last.start, end: span.end };\n continue;\n }\n out.push(span);\n }\n return out;\n}\n\n/** `S₁ ⌢ [marker] ⌢ S₂ ⌢ … ⌢ Sₘ` (modes.md 3.5 step 2). */\nexport function concatenateSpans(source: string, spans: readonly Span[]): number[] {\n const cp: number[] = [];\n let previous: Span | undefined;\n for (const span of spans) {\n if (previous !== undefined) {\n cp.push(gapIsLineBoundary(source, previous.end, span.start) ? LINE_MARKER : MARKER);\n }\n for (const value of toCodePoints(source.slice(span.start, span.end))) cp.push(value);\n previous = span;\n }\n return cp;\n}\n\n/**\n * The span extents of the array as it stands. Recomputed after every rule, because applying\n * edits shifts every index after the first one — the markers themselves are guaranteed to\n * survive, since no edit may contain one.\n */\nexport function spanRangesOf(cp: readonly number[]): SpanRange[] {\n const ranges: SpanRange[] = [];\n let first = 0;\n for (let i = 0; i < cp.length; i += 1) {\n if (isMarker(cp[i] as number)) {\n ranges.push({ first, last: i - 1 });\n first = i + 1;\n }\n }\n ranges.push({ first, last: cp.length - 1 });\n return ranges;\n}\n\nfunction spanContaining(ranges: readonly SpanRange[], p: number): SpanRange | undefined {\n for (const range of ranges) {\n if (p >= range.first && p <= range.last + 1) return range;\n }\n return undefined;\n}\n\n/**\n * modes.md 3.4, two safety nets, both pure functions of `(p, q, r, s₀, s₁)` — so the verdict is\n * identical on every run, which is what makes redistribution deterministic (modes.md 5, point 3).\n *\n * 1. **No edit may contain a marker.** No rule can produce one; one that does is a bug, and the\n * edit is discarded rather than treated as a redistribution question.\n * 2. **The edge-growth rule.** An edit is discarded if it would place code points at an\n * extremity of its span that were not there before: with `d = q - p + 1` the replaced length\n * and `r` the replacement length, discard when `p = s₀ and r > d`, or `q = s₁ and r > d`.\n *\n * The length test is the whole rule and needs no knowledge of Markdown or HTML syntax. It\n * separates exactly the cases that matter: `\"` → `“` at an edge is 1 → 1 and applies; `--` →\n * `␣–␣` at an edge is 2 → 3 and is discarded, while the same edit interior to a span applies;\n * `(c)` → `©` is 3 → 1 and applies, because shrinking is always safe. An insertion has `d = 0`,\n * so it is discarded exactly when its position coincides with a span edge — the rule this one\n * generalises.\n *\n * **Deletion at an edge is not restricted here**, and must not be: `r > d` is false for a\n * deletion, so this filter never sees one. Deletion at an edge is governed by modes.md 3.3's\n * *Edge tests* clause instead — where a rule asks \"am I at the edge of the text I am allowed to\n * modify\" rather than \"what character is here\", the marker behaves as `NONE`. That clause is the\n * one place a rule may treat a span edge as the end of the text, it exists because `spaces` is\n * the only rule that deletes, and 3.3 states the division: **a rule that deletes must treat a\n * span edge as the end of the text; a rule that replaces or inserts must not, and is governed by\n * this filter.** The single test that claims the clause is `spaces.md` 3.2 step 4.\n */\nexport function filterBoundaryEdits(\n cp: readonly number[],\n edits: readonly Edit[],\n ranges: readonly SpanRange[],\n): Edit[] {\n const out: Edit[] = [];\n for (const edit of edits) {\n let containsMarker = false;\n for (let i = edit.start; i < edit.end; i += 1) {\n if (isMarker(cp[i] as number)) {\n containsMarker = true;\n break;\n }\n }\n if (containsMarker) continue;\n\n // `[start, end)` in the engine's half-open form is `cp[p … q]` with p = start, q = end - 1;\n // an insertion is `q = p - 1`, which falls out of the same expression.\n const p = edit.start;\n const q = edit.end - 1;\n const d = edit.end - edit.start;\n const r = edit.replacement.length;\n const span = spanContaining(ranges, p);\n if (span !== undefined && (p === span.first || q === span.last)) {\n if (r > d) continue;\n // The character clause. `r > d` is not the rule, only a formalisation of it that misses\n // `r === d`: `dashes` P3 admits a run of THREE dashes, so `---` -> `␣–␣` is 3 -> 3 and the\n // length test sees nothing while U+0020 lands on both extremities anyway. Testing the\n // character catches it, and only U+0020 needs testing — it is the one code point any rule\n // emits whose meaning comes from its position rather than from itself (modes.md 5 item 2).\n const first = edit.replacement[0];\n const last = edit.replacement[r - 1];\n if (r > 0 && p === span.first && first === SPACE && cp[p] !== SPACE) continue;\n if (r > 0 && q === span.last && last === SPACE && cp[q] !== SPACE) continue;\n }\n\n out.push(edit);\n }\n return out;\n}\n\n/** Redistribute the transformed array back to one piece per span (modes.md 3.5 step 4). */\nexport function splitOnMarker(cp: readonly number[], expected: number): number[][] {\n const pieces: number[][] = [[]];\n for (const value of cp) {\n if (isMarker(value)) {\n pieces.push([]);\n continue;\n }\n (pieces[pieces.length - 1] as number[]).push(value);\n }\n if (pieces.length !== expected) {\n throw new PolytypoError(\n \"POLYTYPO_RULE_CONTRACT\",\n `boundary markers did not survive the pipeline: expected ${expected} spans, found ${pieces.length}`,\n );\n }\n return pieces;\n}\n\n/**\n * The origin map for `concatenateSpans` (analyze.md §2): for every code point of the joined\n * array, the code-point offset of the character it came from IN THE DOCUMENT, and NO_ORIGIN for\n * the markers, which came from nowhere. `Span` bounds are native string indices, so the\n * conversion to code-point offsets happens here and not in the caller — this is the one place\n * that knows both coordinate systems.\n */\nexport function originOfSpans(source: string, spans: readonly Span[]): number[] {\n const codePointIndexOf = new Array<number>(source.length + 1);\n let cpIndex = 0;\n for (let i = 0; i < source.length;) {\n codePointIndexOf[i] = cpIndex;\n const code = source.codePointAt(i) as number;\n const width = code > 0xffff ? 2 : 1;\n if (width === 2) codePointIndexOf[i + 1] = cpIndex;\n i += width;\n cpIndex += 1;\n }\n codePointIndexOf[source.length] = cpIndex;\n\n const origin: number[] = [];\n let previous: Span | undefined;\n for (const span of spans) {\n if (previous !== undefined) origin.push(NO_ORIGIN);\n const base = codePointIndexOf[span.start] as number;\n const length = toCodePoints(source.slice(span.start, span.end)).length;\n for (let k = 0; k < length; k += 1) origin.push(base + k);\n previous = span;\n }\n return origin;\n}\n","import {\n concatenateSpans,\n filterBoundaryEdits,\n normalizeSpans,\n originOfSpans,\n spanRangesOf,\n splitOnMarker,\n type Span,\n} from \"../modes/spans.js\";\nimport { RULES } from \"../rules/registry.js\";\nimport type { LocaleData, Mode, RuleId } from \"../types.js\";\nimport { applyEdits } from \"./edits.js\";\nimport { fromCodePoints, toCodePoints } from \"./codepoints.js\";\nimport type { Change } from \"./origin.js\";\nimport { runRulesRecording } from \"./rule-runner.js\";\n\n/**\n * The same sequence as `runRules` (`./rule-runner.js`), with the two boundary filters of\n * modes.md 3.4 interposed. The span extents are recomputed after every rule, because applying\n * an edit shifts every index after it; the markers themselves always survive, since no edit may\n * contain one.\n */\nfunction runRulesOverSpans(\n cp: readonly number[],\n planned: readonly RuleId[],\n locale: LocaleData,\n mode: Mode,\n narrowTarget: number,\n): readonly number[] {\n let current = cp;\n for (const id of planned) {\n const rule = RULES[id];\n if (rule === undefined) continue;\n const edits = rule.apply({ cp: current, locale, mode, narrowTarget });\n current = applyEdits(current, filterBoundaryEdits(current, edits, spanRangesOf(current)), id);\n }\n return current;\n}\n\n/**\n * modes.md 3.5. The pipeline runs **once**, over the marker-separated concatenation of every\n * processable span — not per span, which would pair quotation marks in isolation, and not over a\n * naive concatenation, which would manufacture adjacencies the document does not have.\n *\n * The output is the input with a set of disjoint substring replacements applied and nothing else\n * (modes.md 4). A span whose content the rules did not change contributes no replacement, so a\n * document needing no changes comes back byte-identical; the parser located the spans and was\n * then discarded, and the document is never serialised.\n */\nexport function runOverSpans(\n source: string,\n spans: readonly Span[],\n planned: readonly RuleId[],\n locale: LocaleData,\n mode: Mode,\n narrowTarget: number,\n): string {\n const normalized = normalizeSpans(spans);\n if (normalized.length === 0) return source;\n\n const transformed = runRulesOverSpans(\n concatenateSpans(source, normalized),\n planned,\n locale,\n mode,\n narrowTarget,\n );\n const pieces = splitOnMarker(transformed, normalized.length);\n\n let out = \"\";\n let cursor = 0;\n for (let i = 0; i < normalized.length; i += 1) {\n const span = normalized[i] as Span;\n const replacement = fromCodePoints(pieces[i] as number[]);\n const original = source.slice(span.start, span.end);\n out += source.slice(cursor, span.start);\n out += replacement === original ? original : replacement;\n cursor = span.end;\n }\n return out + source.slice(cursor);\n}\n\n/**\n * `runOverSpans`, reporting instead of applying (analyze.md §1). The span table supplies the\n * origin map, so every change comes back in DOCUMENT coordinates — analyze.md §6 names a\n * runtime that reports span-local offsets here as the mistake that passes every text-mode test.\n */\nexport function analyzeOverSpans(\n source: string,\n spans: readonly Span[],\n planned: readonly RuleId[],\n locale: LocaleData,\n mode: Mode,\n narrowTarget: number,\n): Change[] {\n const normalized = normalizeSpans(spans);\n if (normalized.length === 0) return [];\n return runRulesRecording(\n concatenateSpans(source, normalized),\n planned,\n locale,\n mode,\n narrowTarget,\n originOfSpans(source, normalized),\n toCodePoints(source).length,\n (current, edits) => filterBoundaryEdits(current, edits, spanRangesOf(current)),\n );\n}\n"]}
1
+ {"version":3,"sources":["/home/runner/work/polytypo-js/polytypo-js/dist/chunk-EJ3BHHOQ.cjs","../src/modes/spans.ts","../src/engine/span-runner.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACMA,IAAM,MAAA,EAAQ,EAAA;AAEd,IAAM,iBAAA,kBAAwC,IAAI,GAAA,CAAI;AAAA,EACpD,EAAA;AAAA,EAAM,EAAA;AAAA,EAAM,EAAA;AAAA,EAAM,EAAA;AAAA,EAAM,GAAA;AAAA,EAAM,IAAA;AAAA,EAAQ;AACxC,CAAC,CAAA;AAED,SAAS,iBAAA,CAAkB,MAAA,EAAgB,IAAA,EAAc,EAAA,EAAqB;AAC5E,EAAA,IAAA,CAAA,IAAS,EAAA,EAAI,IAAA,EAAM,EAAA,EAAI,EAAA,EAAI,EAAA,GAAK,CAAA,EAAG;AACjC,IAAA,GAAA,CAAI,gBAAA,CAAiB,GAAA,CAAI,MAAA,CAAO,UAAA,CAAW,CAAC,CAAC,CAAA,EAAG,OAAO,IAAA;AAAA,EACzD;AACA,EAAA,OAAO,KAAA;AACT;AAuBO,SAAS,cAAA,CAAe,KAAA,EAAgC;AAC7D,EAAA,MAAM,OAAA,EAAS,KAAA,CAAM,MAAA,CAAO,CAAC,CAAA,EAAA,GAAM,CAAA,CAAE,IAAA,EAAM,CAAA,CAAE,KAAK,CAAA,CAAE,IAAA,CAAK,CAAC,CAAA,EAAG,CAAA,EAAA,GAAM,CAAA,CAAE,MAAA,EAAQ,CAAA,CAAE,KAAK,CAAA;AACpF,EAAA,MAAM,IAAA,EAAc,CAAC,CAAA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,IAAA;AAA4F,EAAA;AAE9F,EAAA;AACF;AAYO;AAQL,EAAA;AACA,EAAA;AAEA,EAAA;AAAoB,IAAA;AACiB,IAAA;AACnC,IAAA;AACA,IAAA;AACA,IAAA;AACA,EAAA;AAEF,EAAA;AAEA,EAAA;AACA,EAAA;AACA,EAAA;AACE,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AAAc,EAAA;AAEhB,EAAA;AACF;AAOO;AAQL,EAAA;AACA,EAAA;AACA,EAAA;AAAO,IAAA;AAC8B,IAAA;AACnC,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACgC,IAAA;AACX,IAAA;AACwD,EAAA;AAEjF;AF4FA;AACA;AACA;AACA;AACA","file":"/home/runner/work/polytypo-js/polytypo-js/dist/chunk-EJ3BHHOQ.cjs","sourcesContent":[null,"import { toCodePoints } from \"../engine/codepoints.js\";\nimport { isMarker, LINE_MARKER, MARKER } from \"../engine/sentinels.js\";\nimport { PolytypoError } from \"../errors.js\";\nimport type { Edit } from \"../types.js\";\nimport { NO_ORIGIN } from \"../engine/origin.js\";\n\n/**\n * The boundary markers are defined in the engine (src/engine/sentinels.ts), which is where all\n * three non-code-point sentinels live and where their disjointness is maintained. They are\n * re-exported here because the mode layer is what writes them into the array.\n *\n * Which marker separates two spans is decided by the **raw source bytes of the gap between\n * them**, so it is decidable without asking the parser anything and is identical in five\n * runtimes: a gap containing a line terminator gives `LINE_MARKER`, anything else `MARKER`.\n */\nexport { LINE_MARKER, MARKER, isMarker } from \"../engine/sentinels.js\";\n\n/** `BREAK` as the rules define it (`spaces.md` 3.1), tested against the gap's raw source. */\n/** U+0020, the one emitted code point whose meaning is positional (modes.md 3.4, 5 item 2). */\nconst SPACE = 0x20;\n\nconst LINE_TERMINATORS: ReadonlySet<number> = new Set([\n 0x0a, 0x0d, 0x0b, 0x0c, 0x85, 0x2028, 0x2029,\n]);\n\nfunction gapIsLineBoundary(source: string, from: number, to: number): boolean {\n for (let i = from; i < to; i += 1) {\n if (LINE_TERMINATORS.has(source.charCodeAt(i))) return true;\n }\n return false;\n}\n\n/**\n * A processable span, identified by its offsets in the **original source**. Offsets are UTF-16\n * indices into the JS source string, which is what every JS parser reports; they are an\n * implementation detail of this runtime and never reach the rules, which index code points.\n */\nexport interface Span {\n readonly start: number;\n readonly end: number;\n}\n\n/** A span's extent in the concatenated code-point array: `s₀` and `s₁` of modes.md 3.4. */\nexport interface SpanRange {\n readonly first: number;\n readonly last: number;\n}\n\n/**\n * Sort, drop empties, and coalesce spans separated by nothing in the source (modes.md 7.5:\n * a parser that reports one text run as two adjacent nodes must not manufacture a boundary).\n * Overlapping spans are an extractor bug and are rejected rather than silently merged.\n */\nexport function normalizeSpans(spans: readonly Span[]): Span[] {\n const sorted = spans.filter((s) => s.end > s.start).sort((a, b) => a.start - b.start);\n const out: Span[] = [];\n for (const span of sorted) {\n const last = out[out.length - 1];\n if (last === undefined) {\n out.push(span);\n continue;\n }\n if (span.start < last.end) {\n throw new PolytypoError(\n \"POLYTYPO_RULE_CONTRACT\",\n `mode extractor produced overlapping spans (${last.start}, ${last.end}) and (${span.start}, ${span.end})`,\n );\n }\n if (span.start === last.end) {\n out[out.length - 1] = { start: last.start, end: span.end };\n continue;\n }\n out.push(span);\n }\n return out;\n}\n\n/** `S₁ ⌢ [marker] ⌢ S₂ ⌢ … ⌢ Sₘ` (modes.md 3.5 step 2). */\nexport function concatenateSpans(source: string, spans: readonly Span[]): number[] {\n const cp: number[] = [];\n let previous: Span | undefined;\n for (const span of spans) {\n if (previous !== undefined) {\n cp.push(gapIsLineBoundary(source, previous.end, span.start) ? LINE_MARKER : MARKER);\n }\n for (const value of toCodePoints(source.slice(span.start, span.end))) cp.push(value);\n previous = span;\n }\n return cp;\n}\n\n/**\n * The span extents of the array as it stands. Recomputed after every rule, because applying\n * edits shifts every index after the first one — the markers themselves are guaranteed to\n * survive, since no edit may contain one.\n */\nexport function spanRangesOf(cp: readonly number[]): SpanRange[] {\n const ranges: SpanRange[] = [];\n let first = 0;\n for (let i = 0; i < cp.length; i += 1) {\n if (isMarker(cp[i] as number)) {\n ranges.push({ first, last: i - 1 });\n first = i + 1;\n }\n }\n ranges.push({ first, last: cp.length - 1 });\n return ranges;\n}\n\nfunction spanContaining(ranges: readonly SpanRange[], p: number): SpanRange | undefined {\n for (const range of ranges) {\n if (p >= range.first && p <= range.last + 1) return range;\n }\n return undefined;\n}\n\n/**\n * modes.md 3.4, two safety nets, both pure functions of `(p, q, r, s₀, s₁)` — so the verdict is\n * identical on every run, which is what makes redistribution deterministic (modes.md 5, point 3).\n *\n * 1. **No edit may contain a marker.** No rule can produce one; one that does is a bug, and the\n * edit is discarded rather than treated as a redistribution question.\n * 2. **The edge-growth rule.** An edit is discarded if it would place code points at an\n * extremity of its span that were not there before: with `d = q - p + 1` the replaced length\n * and `r` the replacement length, discard when `p = s₀ and r > d`, or `q = s₁ and r > d`.\n *\n * The length test is the whole rule and needs no knowledge of Markdown or HTML syntax. It\n * separates exactly the cases that matter: `\"` → `“` at an edge is 1 → 1 and applies; `--` →\n * `␣–␣` at an edge is 2 → 3 and is discarded, while the same edit interior to a span applies;\n * `(c)` → `©` is 3 → 1 and applies, because shrinking is always safe. An insertion has `d = 0`,\n * so it is discarded exactly when its position coincides with a span edge — the rule this one\n * generalises.\n *\n * **Deletion at an edge is not restricted here**, and must not be: `r > d` is false for a\n * deletion, so this filter never sees one. Deletion at an edge is governed by modes.md 3.3's\n * *Edge tests* clause instead — where a rule asks \"am I at the edge of the text I am allowed to\n * modify\" rather than \"what character is here\", the marker behaves as `NONE`. That clause is the\n * one place a rule may treat a span edge as the end of the text, it exists because `spaces` is\n * the only rule that deletes, and 3.3 states the division: **a rule that deletes must treat a\n * span edge as the end of the text; a rule that replaces or inserts must not, and is governed by\n * this filter.** The single test that claims the clause is `spaces.md` 3.2 step 4.\n */\nexport function filterBoundaryEdits(\n cp: readonly number[],\n edits: readonly Edit[],\n ranges: readonly SpanRange[],\n): Edit[] {\n const out: Edit[] = [];\n for (const edit of edits) {\n let containsMarker = false;\n for (let i = edit.start; i < edit.end; i += 1) {\n if (isMarker(cp[i] as number)) {\n containsMarker = true;\n break;\n }\n }\n if (containsMarker) continue;\n\n // `[start, end)` in the engine's half-open form is `cp[p … q]` with p = start, q = end - 1;\n // an insertion is `q = p - 1`, which falls out of the same expression.\n const p = edit.start;\n const q = edit.end - 1;\n const d = edit.end - edit.start;\n const r = edit.replacement.length;\n const span = spanContaining(ranges, p);\n if (span !== undefined && (p === span.first || q === span.last)) {\n if (r > d) continue;\n // The character clause. `r > d` is not the rule, only a formalisation of it that misses\n // `r === d`: `dashes` P3 admits a run of THREE dashes, so `---` -> `␣–␣` is 3 -> 3 and the\n // length test sees nothing while U+0020 lands on both extremities anyway. Testing the\n // character catches it, and only U+0020 needs testing — it is the one code point any rule\n // emits whose meaning comes from its position rather than from itself (modes.md 5 item 2).\n const first = edit.replacement[0];\n const last = edit.replacement[r - 1];\n if (r > 0 && p === span.first && first === SPACE && cp[p] !== SPACE) continue;\n if (r > 0 && q === span.last && last === SPACE && cp[q] !== SPACE) continue;\n }\n\n out.push(edit);\n }\n return out;\n}\n\n/** Redistribute the transformed array back to one piece per span (modes.md 3.5 step 4). */\nexport function splitOnMarker(cp: readonly number[], expected: number): number[][] {\n const pieces: number[][] = [[]];\n for (const value of cp) {\n if (isMarker(value)) {\n pieces.push([]);\n continue;\n }\n (pieces[pieces.length - 1] as number[]).push(value);\n }\n if (pieces.length !== expected) {\n throw new PolytypoError(\n \"POLYTYPO_RULE_CONTRACT\",\n `boundary markers did not survive the pipeline: expected ${expected} spans, found ${pieces.length}`,\n );\n }\n return pieces;\n}\n\n/**\n * The origin map for `concatenateSpans` (analyze.md §2): for every code point of the joined\n * array, the code-point offset of the character it came from IN THE DOCUMENT, and NO_ORIGIN for\n * the markers, which came from nowhere. `Span` bounds are native string indices, so the\n * conversion to code-point offsets happens here and not in the caller — this is the one place\n * that knows both coordinate systems.\n */\nexport function originOfSpans(source: string, spans: readonly Span[]): number[] {\n const codePointIndexOf = new Array<number>(source.length + 1);\n let cpIndex = 0;\n for (let i = 0; i < source.length;) {\n codePointIndexOf[i] = cpIndex;\n const code = source.codePointAt(i) as number;\n const width = code > 0xffff ? 2 : 1;\n if (width === 2) codePointIndexOf[i + 1] = cpIndex;\n i += width;\n cpIndex += 1;\n }\n codePointIndexOf[source.length] = cpIndex;\n\n const origin: number[] = [];\n let previous: Span | undefined;\n for (const span of spans) {\n if (previous !== undefined) origin.push(NO_ORIGIN);\n const base = codePointIndexOf[span.start] as number;\n const length = toCodePoints(source.slice(span.start, span.end)).length;\n for (let k = 0; k < length; k += 1) origin.push(base + k);\n previous = span;\n }\n return origin;\n}\n","import {\n concatenateSpans,\n filterBoundaryEdits,\n normalizeSpans,\n originOfSpans,\n spanRangesOf,\n splitOnMarker,\n type Span,\n} from \"../modes/spans.js\";\nimport { RULES } from \"../rules/registry.js\";\nimport type { LocaleData, Mode, RuleId } from \"../types.js\";\nimport { applyEdits } from \"./edits.js\";\nimport { fromCodePoints, toCodePoints } from \"./codepoints.js\";\nimport type { Change } from \"./origin.js\";\nimport { runRulesRecording } from \"./rule-runner.js\";\n\n/**\n * The same sequence as `runRules` (`./rule-runner.js`), with the two boundary filters of\n * modes.md 3.4 interposed. The span extents are recomputed after every rule, because applying\n * an edit shifts every index after it; the markers themselves always survive, since no edit may\n * contain one.\n */\nfunction runRulesOverSpans(\n cp: readonly number[],\n planned: readonly RuleId[],\n locale: LocaleData,\n mode: Mode,\n narrowTarget: number,\n): readonly number[] {\n let current = cp;\n for (const id of planned) {\n const rule = RULES[id];\n if (rule === undefined) continue;\n const edits = rule.apply({ cp: current, locale, mode, narrowTarget });\n current = applyEdits(current, filterBoundaryEdits(current, edits, spanRangesOf(current)), id);\n }\n return current;\n}\n\n/**\n * modes.md 3.5. The pipeline runs **once**, over the marker-separated concatenation of every\n * processable span — not per span, which would pair quotation marks in isolation, and not over a\n * naive concatenation, which would manufacture adjacencies the document does not have.\n *\n * The output is the input with a set of disjoint substring replacements applied and nothing else\n * (modes.md 4). A span whose content the rules did not change contributes no replacement, so a\n * document needing no changes comes back byte-identical; the parser located the spans and was\n * then discarded, and the document is never serialised.\n */\nexport function runOverSpans(\n source: string,\n spans: readonly Span[],\n planned: readonly RuleId[],\n locale: LocaleData,\n mode: Mode,\n narrowTarget: number,\n): string {\n const normalized = normalizeSpans(spans);\n if (normalized.length === 0) return source;\n\n const transformed = runRulesOverSpans(\n concatenateSpans(source, normalized),\n planned,\n locale,\n mode,\n narrowTarget,\n );\n const pieces = splitOnMarker(transformed, normalized.length);\n\n let out = \"\";\n let cursor = 0;\n for (let i = 0; i < normalized.length; i += 1) {\n const span = normalized[i] as Span;\n const replacement = fromCodePoints(pieces[i] as number[]);\n const original = source.slice(span.start, span.end);\n out += source.slice(cursor, span.start);\n out += replacement === original ? original : replacement;\n cursor = span.end;\n }\n return out + source.slice(cursor);\n}\n\n/**\n * `runOverSpans`, reporting instead of applying (analyze.md §1). The span table supplies the\n * origin map, so every change comes back in DOCUMENT coordinates — analyze.md §6 names a\n * runtime that reports span-local offsets here as the mistake that passes every text-mode test.\n */\nexport function analyzeOverSpans(\n source: string,\n spans: readonly Span[],\n planned: readonly RuleId[],\n locale: LocaleData,\n mode: Mode,\n narrowTarget: number,\n): Change[] {\n const normalized = normalizeSpans(spans);\n if (normalized.length === 0) return [];\n return runRulesRecording(\n concatenateSpans(source, normalized),\n planned,\n locale,\n mode,\n narrowTarget,\n originOfSpans(source, normalized),\n toCodePoints(source).length,\n (current, edits) => filterBoundaryEdits(current, edits, spanRangesOf(current)),\n );\n}\n"]}