polytypo 1.12.0 → 1.13.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.
- package/README.md +18 -0
- package/dist/{chunk-MDYQWNEL.js → chunk-6PEHEU6F.js} +2 -2
- package/dist/{chunk-5XVEBCNU.js → chunk-ANHMGSED.js} +8 -7
- package/dist/chunk-ANHMGSED.js.map +1 -0
- package/dist/chunk-CJIH6CFO.cjs +34 -0
- package/dist/chunk-CJIH6CFO.cjs.map +1 -0
- package/dist/{chunk-IOW5V47B.js → chunk-E2HHFHG2.js} +8 -7
- package/dist/chunk-E2HHFHG2.js.map +1 -0
- package/dist/{chunk-BS2J3F7M.js → chunk-EL7R55TV.js} +2 -2
- package/dist/{chunk-ZLR7P7VH.cjs → chunk-FDNDYPPY.cjs} +3 -3
- package/dist/{chunk-ZLR7P7VH.cjs.map → chunk-FDNDYPPY.cjs.map} +1 -1
- package/dist/{chunk-3H6XONGO.js → chunk-MCQOMIWF.js} +2 -2
- package/dist/chunk-MDIDDG32.cjs +38 -0
- package/dist/chunk-MDIDDG32.cjs.map +1 -0
- package/dist/{chunk-QDF6EDLT.js → chunk-MF6PJO7O.js} +330 -9
- package/dist/chunk-MF6PJO7O.js.map +1 -0
- package/dist/chunk-OPHUDB2T.cjs +36 -0
- package/dist/chunk-OPHUDB2T.cjs.map +1 -0
- package/dist/{chunk-PMCNXHAP.js → chunk-OWTDZ6UD.js} +10 -9
- package/dist/{chunk-PMCNXHAP.js.map → chunk-OWTDZ6UD.js.map} +1 -1
- package/dist/{chunk-S3EQ4IDS.js → chunk-R5VKBH3P.js} +9 -2
- package/dist/chunk-R5VKBH3P.js.map +1 -0
- package/dist/{chunk-FRT6ATZR.cjs → chunk-TUDHJRJN.cjs} +6 -6
- package/dist/{chunk-FRT6ATZR.cjs.map → chunk-TUDHJRJN.cjs.map} +1 -1
- package/dist/{chunk-QZEJRXXP.cjs → chunk-W52W6XGA.cjs} +4 -4
- package/dist/{chunk-QZEJRXXP.cjs.map → chunk-W52W6XGA.cjs.map} +1 -1
- package/dist/{chunk-R2AZYV4E.cjs → chunk-WQEB33J2.cjs} +324 -3
- package/dist/chunk-WQEB33J2.cjs.map +1 -0
- package/dist/{chunk-VQB2LXMW.cjs → chunk-WWKSWVMX.cjs} +22 -21
- package/dist/chunk-WWKSWVMX.cjs.map +1 -0
- package/dist/{errors-DeHxbXRn.d.ts → errors-DrNAlWLt.d.cts} +12 -1
- package/dist/{errors-DeHxbXRn.d.cts → errors-DrNAlWLt.d.ts} +12 -1
- package/dist/html.cjs +9 -10
- package/dist/html.cjs.map +1 -1
- package/dist/html.d.cts +3 -3
- package/dist/html.d.ts +3 -3
- package/dist/html.js +4 -5
- package/dist/html.js.map +1 -1
- package/dist/index.cjs +17 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +7 -8
- package/dist/index.js.map +1 -1
- package/dist/markdown.cjs +10 -11
- package/dist/markdown.cjs.map +1 -1
- package/dist/markdown.d.cts +3 -3
- package/dist/markdown.d.ts +3 -3
- package/dist/markdown.js +5 -6
- package/dist/markdown.js.map +1 -1
- package/dist/text.cjs +8 -8
- package/dist/text.cjs.map +1 -1
- package/dist/text.d.cts +2 -2
- package/dist/text.d.ts +2 -2
- package/dist/text.js +3 -3
- package/dist/text.js.map +1 -1
- package/dist/yaml.cjs +9 -10
- package/dist/yaml.cjs.map +1 -1
- package/dist/yaml.d.cts +3 -3
- package/dist/yaml.d.ts +3 -3
- package/dist/yaml.js +4 -5
- package/dist/yaml.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-5XVEBCNU.js.map +0 -1
- package/dist/chunk-GLMNIX54.cjs +0 -31
- package/dist/chunk-GLMNIX54.cjs.map +0 -1
- package/dist/chunk-IOW5V47B.js.map +0 -1
- package/dist/chunk-IQIHJIZW.cjs +0 -35
- package/dist/chunk-IQIHJIZW.cjs.map +0 -1
- package/dist/chunk-OTHSRFQL.cjs +0 -33
- package/dist/chunk-OTHSRFQL.cjs.map +0 -1
- package/dist/chunk-QDF6EDLT.js.map +0 -1
- package/dist/chunk-R2AZYV4E.cjs.map +0 -1
- package/dist/chunk-S3EQ4IDS.js.map +0 -1
- package/dist/chunk-SUX5QWB6.js +0 -218
- package/dist/chunk-SUX5QWB6.js.map +0 -1
- package/dist/chunk-VQB2LXMW.cjs.map +0 -1
- package/dist/chunk-X7L2QLB6.cjs +0 -218
- package/dist/chunk-X7L2QLB6.cjs.map +0 -1
- /package/dist/{chunk-MDYQWNEL.js.map → chunk-6PEHEU6F.js.map} +0 -0
- /package/dist/{chunk-BS2J3F7M.js.map → chunk-EL7R55TV.js.map} +0 -0
- /package/dist/{chunk-3H6XONGO.js.map → chunk-MCQOMIWF.js.map} +0 -0
package/README.md
CHANGED
|
@@ -126,6 +126,24 @@ scalar containing `''` among them, which is how an apostrophe is written inside
|
|
|
126
126
|
The block is also processed separately from the body, which shows up in exactly one place: an
|
|
127
127
|
unbalanced quotation mark in `title` cannot pair with a mark in your first paragraph.
|
|
128
128
|
|
|
129
|
+
`text` mode takes a `protect` option for strings with holes in them, such as template literals or
|
|
130
|
+
ICU messages: ranges of the input that are never edited and that the rules read as content. Offsets
|
|
131
|
+
are Unicode code points, `[start, end)`, ascending and non-overlapping:
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
import { transform } from "polytypo/text";
|
|
135
|
+
|
|
136
|
+
transform("${x} - Rules", { locale: "en-US", protect: [{ start: 0, end: 4 }] });
|
|
137
|
+
// ${x}—Rules
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Text next to a hole converts less than the same text would unsplit, never more: a character
|
|
141
|
+
polytypo would insert beside the hole is not written. A hole containing a line break counts as a
|
|
142
|
+
line break to the rules. A malformed list throws `POLYTYPO_INVALID_OPTION`, and so does a non-empty
|
|
143
|
+
list in `html`, `markdown` or `yaml` mode. An empty list is the same as no option. Running the
|
|
144
|
+
output through again is a fixed point only if you move the ranges to where the edits left them;
|
|
145
|
+
`transform` does not return them. `analyze()` takes the same option.
|
|
146
|
+
|
|
129
147
|
`analyze()` runs the same pipeline and reports what it would do instead of doing it — one record
|
|
130
148
|
per edit, each with the rule that made it and code-point offsets into the input you passed (into
|
|
131
149
|
the **document**, in `html`, `markdown` and `yaml` mode, not into a span):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
PolytypoError
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-MF6PJO7O.js";
|
|
4
4
|
|
|
5
5
|
// src/modes/yaml.ts
|
|
6
6
|
var TAB = 9;
|
|
@@ -370,4 +370,4 @@ export {
|
|
|
370
370
|
resolveYamlKeys,
|
|
371
371
|
resolveFrontmatterKeys
|
|
372
372
|
};
|
|
373
|
-
//# sourceMappingURL=chunk-
|
|
373
|
+
//# sourceMappingURL=chunk-6PEHEU6F.js.map
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
resolveYamlKeys,
|
|
3
3
|
yamlSpans
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-6PEHEU6F.js";
|
|
5
5
|
import {
|
|
6
6
|
analyzeOverSpans,
|
|
7
|
-
|
|
8
|
-
} from "./chunk-SUX5QWB6.js";
|
|
9
|
-
import {
|
|
7
|
+
assertNoProtect,
|
|
10
8
|
getLocaleData,
|
|
11
9
|
planRules,
|
|
12
|
-
resolveNarrowTarget
|
|
13
|
-
|
|
10
|
+
resolveNarrowTarget,
|
|
11
|
+
runOverSpans
|
|
12
|
+
} from "./chunk-MF6PJO7O.js";
|
|
14
13
|
|
|
15
14
|
// src/engine/yaml-pipeline.ts
|
|
16
15
|
function runYamlPipeline(input, options) {
|
|
@@ -18,6 +17,7 @@ function runYamlPipeline(input, options) {
|
|
|
18
17
|
const planned = planRules(options.rules);
|
|
19
18
|
const locale = getLocaleData(options.locale);
|
|
20
19
|
const keys = resolveYamlKeys(options.keys);
|
|
20
|
+
assertNoProtect(options.protect, "yaml");
|
|
21
21
|
return runOverSpans(input, yamlSpans(input, keys), planned, locale, "yaml", narrowTarget);
|
|
22
22
|
}
|
|
23
23
|
function analyzeYamlPipeline(input, options) {
|
|
@@ -25,6 +25,7 @@ function analyzeYamlPipeline(input, options) {
|
|
|
25
25
|
const planned = planRules(options.rules);
|
|
26
26
|
const locale = getLocaleData(options.locale);
|
|
27
27
|
const keys = resolveYamlKeys(options.keys);
|
|
28
|
+
assertNoProtect(options.protect, "yaml");
|
|
28
29
|
return analyzeOverSpans(input, yamlSpans(input, keys), planned, locale, "yaml", narrowTarget);
|
|
29
30
|
}
|
|
30
31
|
|
|
@@ -32,4 +33,4 @@ export {
|
|
|
32
33
|
runYamlPipeline,
|
|
33
34
|
analyzeYamlPipeline
|
|
34
35
|
};
|
|
35
|
-
//# sourceMappingURL=chunk-
|
|
36
|
+
//# sourceMappingURL=chunk-ANHMGSED.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/engine/yaml-pipeline.ts"],"sourcesContent":["import { yamlSpans } from \"../modes/yaml.js\";\nimport type { Options } from \"../types.js\";\nimport { getLocaleData } from \"./locale.js\";\nimport { resolveNarrowTarget } from \"./narrow-target.js\";\nimport { resolveYamlKeys } from \"./yaml-keys.js\";\nimport { assertNoProtect } from \"./protect.js\";\nimport { planRules } from \"./rule-runner.js\";\nimport { analyzeOverSpans, runOverSpans } from \"./span-runner.js\";\nimport type { Change } from \"./origin.js\";\n\n/**\n * `yaml` mode only, and the only mode pipeline with **no parser dependency at all** — span\n * selection is the specified scan of modes.md 3.8, not a library. There is likewise no\n * `POLYTYPO_MALFORMED_INPUT` counterpart here: with no declared grammar to violate, a file that\n * is not YAML yields few spans or none and comes back byte for byte (modes.md 3.8.3). The only\n * throw this mode adds is `keys`, which is about the call and not the input.\n */\nexport function runYamlPipeline(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 keys = resolveYamlKeys(options.keys);\n assertNoProtect(options.protect, \"yaml\");\n return runOverSpans(input, yamlSpans(input, keys), planned, locale, \"yaml\", narrowTarget);\n}\n\n/** analyze.md §1, `yaml` mode: offsets are into the document, not into a span (analyze.md §6). */\nexport function analyzeYamlPipeline(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 keys = resolveYamlKeys(options.keys);\n assertNoProtect(options.protect, \"yaml\");\n return analyzeOverSpans(input, yamlSpans(input, keys), planned, locale, \"yaml\", narrowTarget);\n}\n"],"mappings":";;;;;;;;;;;;;;AAiBO,SAAS,gBAAgB,OAAe,SAAmC;AAChF,QAAM,eAAe,oBAAoB,QAAQ,UAAU;AAC3D,QAAM,UAAU,UAAU,QAAQ,KAAK;AACvC,QAAM,SAAS,cAAc,QAAQ,MAAM;AAC3C,QAAM,OAAO,gBAAgB,QAAQ,IAAI;AACzC,kBAAgB,QAAQ,SAAS,MAAM;AACvC,SAAO,aAAa,OAAO,UAAU,OAAO,IAAI,GAAG,SAAS,QAAQ,QAAQ,YAAY;AAC1F;AAGO,SAAS,oBAAoB,OAAe,SAAqC;AACtF,QAAM,eAAe,oBAAoB,QAAQ,UAAU;AAC3D,QAAM,UAAU,UAAU,QAAQ,KAAK;AACvC,QAAM,SAAS,cAAc,QAAQ,MAAM;AAC3C,QAAM,OAAO,gBAAgB,QAAQ,IAAI;AACzC,kBAAgB,QAAQ,SAAS,MAAM;AACvC,SAAO,iBAAiB,OAAO,UAAU,OAAO,IAAI,GAAG,SAAS,QAAQ,QAAQ,YAAY;AAC9F;","names":[]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkW52W6XGAcjs = require('./chunk-W52W6XGA.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
var _chunkWQEB33J2cjs = require('./chunk-WQEB33J2.cjs');
|
|
12
|
+
|
|
13
|
+
// src/engine/html-pipeline.ts
|
|
14
|
+
function runHtmlPipeline(input, options) {
|
|
15
|
+
const narrowTarget = _chunkWQEB33J2cjs.resolveNarrowTarget.call(void 0, options.narrowNbsp);
|
|
16
|
+
const planned = _chunkWQEB33J2cjs.planRules.call(void 0, options.rules);
|
|
17
|
+
const locale = _chunkWQEB33J2cjs.getLocaleData.call(void 0, options.locale);
|
|
18
|
+
_chunkWQEB33J2cjs.assertNoProtect.call(void 0, options.protect, "html");
|
|
19
|
+
const spans = _chunkW52W6XGAcjs.htmlSpans.call(void 0, input);
|
|
20
|
+
return _chunkWQEB33J2cjs.runOverSpans.call(void 0, input, spans, planned, locale, "html", narrowTarget);
|
|
21
|
+
}
|
|
22
|
+
function analyzeHtmlPipeline(input, options) {
|
|
23
|
+
const narrowTarget = _chunkWQEB33J2cjs.resolveNarrowTarget.call(void 0, options.narrowNbsp);
|
|
24
|
+
const planned = _chunkWQEB33J2cjs.planRules.call(void 0, options.rules);
|
|
25
|
+
const locale = _chunkWQEB33J2cjs.getLocaleData.call(void 0, options.locale);
|
|
26
|
+
_chunkWQEB33J2cjs.assertNoProtect.call(void 0, options.protect, "html");
|
|
27
|
+
return _chunkWQEB33J2cjs.analyzeOverSpans.call(void 0, input, _chunkW52W6XGAcjs.htmlSpans.call(void 0, input), planned, locale, "html", narrowTarget);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
exports.runHtmlPipeline = runHtmlPipeline; exports.analyzeHtmlPipeline = analyzeHtmlPipeline;
|
|
34
|
+
//# sourceMappingURL=chunk-CJIH6CFO.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/polytypo-js/polytypo-js/dist/chunk-CJIH6CFO.cjs","../src/engine/html-pipeline.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACMO,SAAS,eAAA,CAAgB,KAAA,EAAe,OAAA,EAAmC;AAChF,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,+CAAA,OAAgB,CAAQ,OAAA,EAAS,MAAM,CAAA;AACvC,EAAA,MAAM,MAAA,EAAQ,yCAAA,KAAe,CAAA;AAC7B,EAAA,OAAO,4CAAA,KAAa,EAAO,KAAA,EAAO,OAAA,EAAS,MAAA,EAAQ,MAAA,EAAQ,YAAY,CAAA;AACzE;AAGO,SAAS,mBAAA,CAAoB,KAAA,EAAe,OAAA,EAAqC;AACtF,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,+CAAA,OAAgB,CAAQ,OAAA,EAAS,MAAM,CAAA;AACvC,EAAA,OAAO,gDAAA,KAAiB,EAAO,yCAAA,KAAe,CAAA,EAAG,OAAA,EAAS,MAAA,EAAQ,MAAA,EAAQ,YAAY,CAAA;AACxF;ADNA;AACA;AACE;AACA;AACF,6FAAC","file":"/home/runner/work/polytypo-js/polytypo-js/dist/chunk-CJIH6CFO.cjs","sourcesContent":[null,"import { htmlSpans } from \"../modes/html.js\";\nimport type { Options } from \"../types.js\";\nimport { getLocaleData } from \"./locale.js\";\nimport { resolveNarrowTarget } from \"./narrow-target.js\";\nimport { assertNoProtect } from \"./protect.js\";\nimport { planRules } from \"./rule-runner.js\";\nimport { analyzeOverSpans, runOverSpans } from \"./span-runner.js\";\nimport type { Change } from \"./origin.js\";\n\n/**\n * `html` mode only. Imports `parse5` (via `../modes/html.js`) and nothing from\n * `../modes/markdown.js` or the Micromark/MDX stack — this is what makes `polytypo/html`'s\n * module graph exclude the Markdown parser (AUDIT_REMEDIATION_AND_RELEASE_PLAN.md 5.1).\n *\n * Validation order — `planRules` before `getLocaleData` before parsing — mirrors the pre-Stage-5\n * aggregate `runPipeline` exactly (an unknown-rule error must win over an unknown-locale error,\n * and both must win over a parse failure, since that is public, tested behaviour).\n */\nexport function runHtmlPipeline(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 assertNoProtect(options.protect, \"html\");\n const spans = htmlSpans(input);\n return runOverSpans(input, spans, planned, locale, \"html\", narrowTarget);\n}\n\n/** analyze.md §1, `html` mode: offsets are into the document, not into a span (analyze.md §6). */\nexport function analyzeHtmlPipeline(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 assertNoProtect(options.protect, \"html\");\n return analyzeOverSpans(input, htmlSpans(input), planned, locale, \"html\", narrowTarget);\n}\n"]}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
htmlSpans
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-MCQOMIWF.js";
|
|
4
4
|
import {
|
|
5
5
|
analyzeOverSpans,
|
|
6
|
-
|
|
7
|
-
} from "./chunk-SUX5QWB6.js";
|
|
8
|
-
import {
|
|
6
|
+
assertNoProtect,
|
|
9
7
|
getLocaleData,
|
|
10
8
|
planRules,
|
|
11
|
-
resolveNarrowTarget
|
|
12
|
-
|
|
9
|
+
resolveNarrowTarget,
|
|
10
|
+
runOverSpans
|
|
11
|
+
} from "./chunk-MF6PJO7O.js";
|
|
13
12
|
|
|
14
13
|
// src/engine/html-pipeline.ts
|
|
15
14
|
function runHtmlPipeline(input, options) {
|
|
16
15
|
const narrowTarget = resolveNarrowTarget(options.narrowNbsp);
|
|
17
16
|
const planned = planRules(options.rules);
|
|
18
17
|
const locale = getLocaleData(options.locale);
|
|
18
|
+
assertNoProtect(options.protect, "html");
|
|
19
19
|
const spans = htmlSpans(input);
|
|
20
20
|
return runOverSpans(input, spans, planned, locale, "html", narrowTarget);
|
|
21
21
|
}
|
|
@@ -23,6 +23,7 @@ function analyzeHtmlPipeline(input, options) {
|
|
|
23
23
|
const narrowTarget = resolveNarrowTarget(options.narrowNbsp);
|
|
24
24
|
const planned = planRules(options.rules);
|
|
25
25
|
const locale = getLocaleData(options.locale);
|
|
26
|
+
assertNoProtect(options.protect, "html");
|
|
26
27
|
return analyzeOverSpans(input, htmlSpans(input), planned, locale, "html", narrowTarget);
|
|
27
28
|
}
|
|
28
29
|
|
|
@@ -30,4 +31,4 @@ export {
|
|
|
30
31
|
runHtmlPipeline,
|
|
31
32
|
analyzeHtmlPipeline
|
|
32
33
|
};
|
|
33
|
-
//# sourceMappingURL=chunk-
|
|
34
|
+
//# sourceMappingURL=chunk-E2HHFHG2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/engine/html-pipeline.ts"],"sourcesContent":["import { htmlSpans } from \"../modes/html.js\";\nimport type { Options } from \"../types.js\";\nimport { getLocaleData } from \"./locale.js\";\nimport { resolveNarrowTarget } from \"./narrow-target.js\";\nimport { assertNoProtect } from \"./protect.js\";\nimport { planRules } from \"./rule-runner.js\";\nimport { analyzeOverSpans, runOverSpans } from \"./span-runner.js\";\nimport type { Change } from \"./origin.js\";\n\n/**\n * `html` mode only. Imports `parse5` (via `../modes/html.js`) and nothing from\n * `../modes/markdown.js` or the Micromark/MDX stack — this is what makes `polytypo/html`'s\n * module graph exclude the Markdown parser (AUDIT_REMEDIATION_AND_RELEASE_PLAN.md 5.1).\n *\n * Validation order — `planRules` before `getLocaleData` before parsing — mirrors the pre-Stage-5\n * aggregate `runPipeline` exactly (an unknown-rule error must win over an unknown-locale error,\n * and both must win over a parse failure, since that is public, tested behaviour).\n */\nexport function runHtmlPipeline(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 assertNoProtect(options.protect, \"html\");\n const spans = htmlSpans(input);\n return runOverSpans(input, spans, planned, locale, \"html\", narrowTarget);\n}\n\n/** analyze.md §1, `html` mode: offsets are into the document, not into a span (analyze.md §6). */\nexport function analyzeHtmlPipeline(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 assertNoProtect(options.protect, \"html\");\n return analyzeOverSpans(input, htmlSpans(input), planned, locale, \"html\", narrowTarget);\n}\n"],"mappings":";;;;;;;;;;;;;AAkBO,SAAS,gBAAgB,OAAe,SAAmC;AAChF,QAAM,eAAe,oBAAoB,QAAQ,UAAU;AAC3D,QAAM,UAAU,UAAU,QAAQ,KAAK;AACvC,QAAM,SAAS,cAAc,QAAQ,MAAM;AAC3C,kBAAgB,QAAQ,SAAS,MAAM;AACvC,QAAM,QAAQ,UAAU,KAAK;AAC7B,SAAO,aAAa,OAAO,OAAO,SAAS,QAAQ,QAAQ,YAAY;AACzE;AAGO,SAAS,oBAAoB,OAAe,SAAqC;AACtF,QAAM,eAAe,oBAAoB,QAAQ,UAAU;AAC3D,QAAM,UAAU,UAAU,QAAQ,KAAK;AACvC,QAAM,SAAS,cAAc,QAAQ,MAAM;AAC3C,kBAAgB,QAAQ,SAAS,MAAM;AACvC,SAAO,iBAAiB,OAAO,UAAU,KAAK,GAAG,SAAS,QAAQ,QAAQ,YAAY;AACxF;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
PolytypoError
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-MF6PJO7O.js";
|
|
4
4
|
|
|
5
5
|
// src/engine/assert-fixed-mode.ts
|
|
6
6
|
function assertFixedMode(mode, fixed, entryPoint) {
|
|
@@ -14,4 +14,4 @@ function assertFixedMode(mode, fixed, entryPoint) {
|
|
|
14
14
|
export {
|
|
15
15
|
assertFixedMode
|
|
16
16
|
};
|
|
17
|
-
//# sourceMappingURL=chunk-
|
|
17
|
+
//# sourceMappingURL=chunk-EL7R55TV.js.map
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkWQEB33J2cjs = require('./chunk-WQEB33J2.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,
|
|
8
|
+
throw new (0, _chunkWQEB33J2cjs.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-
|
|
17
|
+
//# sourceMappingURL=chunk-FDNDYPPY.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/polytypo-js/polytypo-js/dist/chunk-
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/polytypo-js/polytypo-js/dist/chunk-FDNDYPPY.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-FDNDYPPY.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,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
PolytypoError
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-MF6PJO7O.js";
|
|
4
4
|
|
|
5
5
|
// src/modes/html.ts
|
|
6
6
|
import { parse, parseFragment } from "parse5";
|
|
@@ -144,4 +144,4 @@ export {
|
|
|
144
144
|
htmlSpans,
|
|
145
145
|
htmlFragmentSpans
|
|
146
146
|
};
|
|
147
|
-
//# sourceMappingURL=chunk-
|
|
147
|
+
//# sourceMappingURL=chunk-MCQOMIWF.js.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _chunkWQEB33J2cjs = require('./chunk-WQEB33J2.cjs');
|
|
13
|
+
|
|
14
|
+
// src/engine/text-pipeline.ts
|
|
15
|
+
function runTextPipeline(input, options) {
|
|
16
|
+
const narrowTarget = _chunkWQEB33J2cjs.resolveNarrowTarget.call(void 0, options.narrowNbsp);
|
|
17
|
+
const planned = _chunkWQEB33J2cjs.planRules.call(void 0, options.rules);
|
|
18
|
+
const locale = _chunkWQEB33J2cjs.getLocaleData.call(void 0, options.locale);
|
|
19
|
+
const holes = _chunkWQEB33J2cjs.resolveProtect.call(void 0, options.protect, _chunkWQEB33J2cjs.toCodePoints.call(void 0, input).length);
|
|
20
|
+
if (holes.length > 0) return _chunkWQEB33J2cjs.runProtected.call(void 0, input, holes, planned, locale, narrowTarget);
|
|
21
|
+
return _chunkWQEB33J2cjs.fromCodePoints.call(void 0, _chunkWQEB33J2cjs.runRules.call(void 0, _chunkWQEB33J2cjs.toCodePoints.call(void 0, input), planned, locale, "text", narrowTarget));
|
|
22
|
+
}
|
|
23
|
+
function analyzeTextPipeline(input, options) {
|
|
24
|
+
const narrowTarget = _chunkWQEB33J2cjs.resolveNarrowTarget.call(void 0, options.narrowNbsp);
|
|
25
|
+
const planned = _chunkWQEB33J2cjs.planRules.call(void 0, options.rules);
|
|
26
|
+
const locale = _chunkWQEB33J2cjs.getLocaleData.call(void 0, options.locale);
|
|
27
|
+
const cp = _chunkWQEB33J2cjs.toCodePoints.call(void 0, input);
|
|
28
|
+
const holes = _chunkWQEB33J2cjs.resolveProtect.call(void 0, options.protect, cp.length);
|
|
29
|
+
if (holes.length > 0) return _chunkWQEB33J2cjs.analyzeProtected.call(void 0, input, holes, planned, locale, narrowTarget);
|
|
30
|
+
const origin = cp.map((_value, index) => index);
|
|
31
|
+
return _chunkWQEB33J2cjs.runRulesRecording.call(void 0, cp, planned, locale, "text", narrowTarget, origin, cp.length);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
exports.runTextPipeline = runTextPipeline; exports.analyzeTextPipeline = analyzeTextPipeline;
|
|
38
|
+
//# sourceMappingURL=chunk-MDIDDG32.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/polytypo-js/polytypo-js/dist/chunk-MDIDDG32.cjs","../src/engine/text-pipeline.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACMO,SAAS,eAAA,CAAgB,KAAA,EAAe,OAAA,EAAmC;AAChF,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,MAAA,EAAQ,8CAAA,OAAe,CAAQ,OAAA,EAAS,4CAAA,KAAkB,CAAA,CAAE,MAAM,CAAA;AACxE,EAAA,GAAA,CAAI,KAAA,CAAM,OAAA,EAAS,CAAA,EAAG,OAAO,4CAAA,KAAa,EAAO,KAAA,EAAO,OAAA,EAAS,MAAA,EAAQ,YAAY,CAAA;AACrF,EAAA,OAAO,8CAAA,wCAAe,4CAAS,KAAkB,CAAA,EAAG,OAAA,EAAS,MAAA,EAAQ,MAAA,EAAQ,YAAY,CAAC,CAAA;AAC5F;AAGO,SAAS,mBAAA,CAAoB,KAAA,EAAe,OAAA,EAAqC;AACtF,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,GAAA,EAAK,4CAAA,KAAkB,CAAA;AAC7B,EAAA,MAAM,MAAA,EAAQ,8CAAA,OAAe,CAAQ,OAAA,EAAS,EAAA,CAAG,MAAM,CAAA;AACvD,EAAA,GAAA,CAAI,KAAA,CAAM,OAAA,EAAS,CAAA,EAAG,OAAO,gDAAA,KAAiB,EAAO,KAAA,EAAO,OAAA,EAAS,MAAA,EAAQ,YAAY,CAAA;AACzF,EAAA,MAAM,OAAA,EAAS,EAAA,CAAG,GAAA,CAAI,CAAC,MAAA,EAAQ,KAAA,EAAA,GAAU,KAAK,CAAA;AAC9C,EAAA,OAAO,iDAAA,EAAkB,EAAI,OAAA,EAAS,MAAA,EAAQ,MAAA,EAAQ,YAAA,EAAc,MAAA,EAAQ,EAAA,CAAG,MAAM,CAAA;AACvF;ADNA;AACA;AACE;AACA;AACF,6FAAC","file":"/home/runner/work/polytypo-js/polytypo-js/dist/chunk-MDIDDG32.cjs","sourcesContent":[null,"import type { Options } from \"../types.js\";\nimport { fromCodePoints, toCodePoints } from \"./codepoints.js\";\nimport type { Change } from \"./origin.js\";\nimport { getLocaleData } from \"./locale.js\";\nimport { resolveNarrowTarget } from \"./narrow-target.js\";\nimport { planRules, runRules, runRulesRecording } from \"./rule-runner.js\";\nimport { analyzeProtected, resolveProtect, runProtected } from \"./protect.js\";\n\n/**\n * `text` mode only. Deliberately imports nothing from `../modes/html.js` or\n * `../modes/markdown.js` (or their parser dependencies) — this is what makes `polytypo/text`'s\n * module graph exclude `parse5` and the Micromark stack (AUDIT_REMEDIATION_AND_RELEASE_PLAN.md\n * 5.1).\n *\n * Validation order — `planRules` before `getLocaleData` — mirrors the pre-Stage-5 aggregate\n * `runPipeline` exactly (an unknown-rule error must win over an unknown-locale error when both\n * are present, since that is public, tested behaviour, not an implementation detail this\n * refactor was authorised to change).\n */\nexport function runTextPipeline(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 holes = resolveProtect(options.protect, toCodePoints(input).length);\n if (holes.length > 0) return runProtected(input, holes, planned, locale, narrowTarget);\n return fromCodePoints(runRules(toCodePoints(input), planned, locale, \"text\", narrowTarget));\n}\n\n/** analyze.md §1: the same pipeline as `runTextPipeline`, reporting instead of applying. */\nexport function analyzeTextPipeline(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 cp = toCodePoints(input);\n const holes = resolveProtect(options.protect, cp.length);\n if (holes.length > 0) return analyzeProtected(input, holes, planned, locale, narrowTarget);\n const origin = cp.map((_value, index) => index);\n return runRulesRecording(cp, planned, locale, \"text\", narrowTarget, origin, cp.length);\n}\n"]}
|
|
@@ -5778,11 +5778,18 @@ function applyEditsToOrigin(origin, edits) {
|
|
|
5778
5778
|
for (let i = cursor; i < origin.length; i += 1) out.push(origin[i]);
|
|
5779
5779
|
return out;
|
|
5780
5780
|
}
|
|
5781
|
+
function endOf(origin, edit, inputLength) {
|
|
5782
|
+
for (let i = edit.end - 1; i >= edit.start; i -= 1) {
|
|
5783
|
+
const value = origin[i];
|
|
5784
|
+
if (value !== NO_ORIGIN) return value + 1;
|
|
5785
|
+
}
|
|
5786
|
+
return originAt(origin, edit.end, inputLength);
|
|
5787
|
+
}
|
|
5781
5788
|
function recordChanges(cp, edits, origin, inputLength, ruleId) {
|
|
5782
5789
|
return edits.map((edit) => ({
|
|
5783
5790
|
ruleId,
|
|
5784
5791
|
start: originAt(origin, edit.start, inputLength),
|
|
5785
|
-
end:
|
|
5792
|
+
end: endOf(origin, edit, inputLength),
|
|
5786
5793
|
before: fromCodePoints(cp.slice(edit.start, edit.end)),
|
|
5787
5794
|
after: fromCodePoints(edit.replacement)
|
|
5788
5795
|
}));
|
|
@@ -5831,20 +5838,334 @@ function runRulesRecording(cp, planned, locale, mode, narrowTarget, origin, inpu
|
|
|
5831
5838
|
return changes;
|
|
5832
5839
|
}
|
|
5833
5840
|
|
|
5841
|
+
// src/modes/spans.ts
|
|
5842
|
+
var SPACE5 = 32;
|
|
5843
|
+
var LINE_TERMINATORS = /* @__PURE__ */ new Set([
|
|
5844
|
+
10,
|
|
5845
|
+
13,
|
|
5846
|
+
11,
|
|
5847
|
+
12,
|
|
5848
|
+
133,
|
|
5849
|
+
8232,
|
|
5850
|
+
8233
|
|
5851
|
+
]);
|
|
5852
|
+
function gapIsLineBoundary(source, from, to) {
|
|
5853
|
+
for (let i = from; i < to; i += 1) {
|
|
5854
|
+
if (LINE_TERMINATORS.has(source.charCodeAt(i))) return true;
|
|
5855
|
+
}
|
|
5856
|
+
return false;
|
|
5857
|
+
}
|
|
5858
|
+
function normalizeSpans(spans) {
|
|
5859
|
+
const sorted = spans.filter((s) => s.end > s.start).sort((a, b) => a.start - b.start);
|
|
5860
|
+
const out = [];
|
|
5861
|
+
for (const span of sorted) {
|
|
5862
|
+
const last = out[out.length - 1];
|
|
5863
|
+
if (last === void 0) {
|
|
5864
|
+
out.push(span);
|
|
5865
|
+
continue;
|
|
5866
|
+
}
|
|
5867
|
+
if (span.start < last.end) {
|
|
5868
|
+
throw new PolytypoError(
|
|
5869
|
+
"POLYTYPO_RULE_CONTRACT",
|
|
5870
|
+
`mode extractor produced overlapping spans (${last.start}, ${last.end}) and (${span.start}, ${span.end})`
|
|
5871
|
+
);
|
|
5872
|
+
}
|
|
5873
|
+
if (span.start === last.end) {
|
|
5874
|
+
out[out.length - 1] = { start: last.start, end: span.end };
|
|
5875
|
+
continue;
|
|
5876
|
+
}
|
|
5877
|
+
out.push(span);
|
|
5878
|
+
}
|
|
5879
|
+
return out;
|
|
5880
|
+
}
|
|
5881
|
+
function concatenateSpans(source, spans) {
|
|
5882
|
+
const cp = [];
|
|
5883
|
+
let previous;
|
|
5884
|
+
for (const span of spans) {
|
|
5885
|
+
if (previous !== void 0) {
|
|
5886
|
+
cp.push(gapIsLineBoundary(source, previous.end, span.start) ? LINE_MARKER : MARKER);
|
|
5887
|
+
}
|
|
5888
|
+
for (const value of toCodePoints(source.slice(span.start, span.end))) cp.push(value);
|
|
5889
|
+
previous = span;
|
|
5890
|
+
}
|
|
5891
|
+
return cp;
|
|
5892
|
+
}
|
|
5893
|
+
function spanRangesOf(cp) {
|
|
5894
|
+
const ranges = [];
|
|
5895
|
+
let first = 0;
|
|
5896
|
+
for (let i = 0; i < cp.length; i += 1) {
|
|
5897
|
+
if (isMarker(cp[i])) {
|
|
5898
|
+
ranges.push({ first, last: i - 1 });
|
|
5899
|
+
first = i + 1;
|
|
5900
|
+
}
|
|
5901
|
+
}
|
|
5902
|
+
ranges.push({ first, last: cp.length - 1 });
|
|
5903
|
+
return ranges;
|
|
5904
|
+
}
|
|
5905
|
+
function spanContaining(ranges, p) {
|
|
5906
|
+
for (const range of ranges) {
|
|
5907
|
+
if (p >= range.first && p <= range.last + 1) return range;
|
|
5908
|
+
}
|
|
5909
|
+
return void 0;
|
|
5910
|
+
}
|
|
5911
|
+
function filterBoundaryEdits(cp, edits, ranges) {
|
|
5912
|
+
const out = [];
|
|
5913
|
+
for (const edit of edits) {
|
|
5914
|
+
let containsMarker = false;
|
|
5915
|
+
for (let i = edit.start; i < edit.end; i += 1) {
|
|
5916
|
+
if (isMarker(cp[i])) {
|
|
5917
|
+
containsMarker = true;
|
|
5918
|
+
break;
|
|
5919
|
+
}
|
|
5920
|
+
}
|
|
5921
|
+
if (containsMarker) continue;
|
|
5922
|
+
const p = edit.start;
|
|
5923
|
+
const q = edit.end - 1;
|
|
5924
|
+
const d = edit.end - edit.start;
|
|
5925
|
+
const r = edit.replacement.length;
|
|
5926
|
+
const span = spanContaining(ranges, p);
|
|
5927
|
+
if (span !== void 0 && (p === span.first || q === span.last)) {
|
|
5928
|
+
if (r > d) continue;
|
|
5929
|
+
const first = edit.replacement[0];
|
|
5930
|
+
const last = edit.replacement[r - 1];
|
|
5931
|
+
if (r > 0 && p === span.first && first === SPACE5 && cp[p] !== SPACE5) continue;
|
|
5932
|
+
if (r > 0 && q === span.last && last === SPACE5 && cp[q] !== SPACE5) continue;
|
|
5933
|
+
}
|
|
5934
|
+
out.push(edit);
|
|
5935
|
+
}
|
|
5936
|
+
return out;
|
|
5937
|
+
}
|
|
5938
|
+
function splitOnMarker(cp, expected) {
|
|
5939
|
+
const pieces = [[]];
|
|
5940
|
+
for (const value of cp) {
|
|
5941
|
+
if (isMarker(value)) {
|
|
5942
|
+
pieces.push([]);
|
|
5943
|
+
continue;
|
|
5944
|
+
}
|
|
5945
|
+
pieces[pieces.length - 1].push(value);
|
|
5946
|
+
}
|
|
5947
|
+
if (pieces.length !== expected) {
|
|
5948
|
+
throw new PolytypoError(
|
|
5949
|
+
"POLYTYPO_RULE_CONTRACT",
|
|
5950
|
+
`boundary markers did not survive the pipeline: expected ${expected} spans, found ${pieces.length}`
|
|
5951
|
+
);
|
|
5952
|
+
}
|
|
5953
|
+
return pieces;
|
|
5954
|
+
}
|
|
5955
|
+
function originOfSpans(source, spans) {
|
|
5956
|
+
const codePointIndexOf = new Array(source.length + 1);
|
|
5957
|
+
let cpIndex = 0;
|
|
5958
|
+
for (let i = 0; i < source.length; ) {
|
|
5959
|
+
codePointIndexOf[i] = cpIndex;
|
|
5960
|
+
const code = source.codePointAt(i);
|
|
5961
|
+
const width = code > 65535 ? 2 : 1;
|
|
5962
|
+
if (width === 2) codePointIndexOf[i + 1] = cpIndex;
|
|
5963
|
+
i += width;
|
|
5964
|
+
cpIndex += 1;
|
|
5965
|
+
}
|
|
5966
|
+
codePointIndexOf[source.length] = cpIndex;
|
|
5967
|
+
const origin = [];
|
|
5968
|
+
let previous;
|
|
5969
|
+
for (const span of spans) {
|
|
5970
|
+
if (previous !== void 0) origin.push(NO_ORIGIN);
|
|
5971
|
+
const base = codePointIndexOf[span.start];
|
|
5972
|
+
const length = toCodePoints(source.slice(span.start, span.end)).length;
|
|
5973
|
+
for (let k = 0; k < length; k += 1) origin.push(base + k);
|
|
5974
|
+
previous = span;
|
|
5975
|
+
}
|
|
5976
|
+
return origin;
|
|
5977
|
+
}
|
|
5978
|
+
|
|
5979
|
+
// src/engine/span-runner.ts
|
|
5980
|
+
function runRulesOverSpans(cp, planned, locale, mode, narrowTarget) {
|
|
5981
|
+
let current = cp;
|
|
5982
|
+
for (const id of planned) {
|
|
5983
|
+
const rule = RULES[id];
|
|
5984
|
+
if (rule === void 0) continue;
|
|
5985
|
+
const edits = rule.apply({ cp: current, locale, mode, narrowTarget });
|
|
5986
|
+
current = applyEdits(current, filterBoundaryEdits(current, edits, spanRangesOf(current)), id);
|
|
5987
|
+
}
|
|
5988
|
+
return current;
|
|
5989
|
+
}
|
|
5990
|
+
function replacementsOfUnit(source, spans, planned, locale, mode, narrowTarget) {
|
|
5991
|
+
const normalized = normalizeSpans(spans);
|
|
5992
|
+
if (normalized.length === 0) return [];
|
|
5993
|
+
const transformed = runRulesOverSpans(
|
|
5994
|
+
concatenateSpans(source, normalized),
|
|
5995
|
+
planned,
|
|
5996
|
+
locale,
|
|
5997
|
+
mode,
|
|
5998
|
+
narrowTarget
|
|
5999
|
+
);
|
|
6000
|
+
const pieces = splitOnMarker(transformed, normalized.length);
|
|
6001
|
+
return normalized.map((span, i) => ({ span, text: fromCodePoints(pieces[i]) }));
|
|
6002
|
+
}
|
|
6003
|
+
function emit2(source, replacements) {
|
|
6004
|
+
let out = "";
|
|
6005
|
+
let cursor = 0;
|
|
6006
|
+
for (const { span, text } of replacements) {
|
|
6007
|
+
const original = source.slice(span.start, span.end);
|
|
6008
|
+
out += source.slice(cursor, span.start);
|
|
6009
|
+
out += text === original ? original : text;
|
|
6010
|
+
cursor = span.end;
|
|
6011
|
+
}
|
|
6012
|
+
return out + source.slice(cursor);
|
|
6013
|
+
}
|
|
6014
|
+
function runOverSpans(source, spans, planned, locale, mode, narrowTarget) {
|
|
6015
|
+
return emit2(source, replacementsOfUnit(source, spans, planned, locale, mode, narrowTarget));
|
|
6016
|
+
}
|
|
6017
|
+
function runOverUnits(source, units, planned, locale, mode, narrowTarget) {
|
|
6018
|
+
const replacements = units.flatMap((spans) => replacementsOfUnit(source, spans, planned, locale, mode, narrowTarget)).sort((a, b) => a.span.start - b.span.start);
|
|
6019
|
+
return emit2(source, replacements);
|
|
6020
|
+
}
|
|
6021
|
+
function analyzeOverUnits(source, units, planned, locale, mode, narrowTarget) {
|
|
6022
|
+
return units.flatMap((spans) => analyzeOverSpans(source, spans, planned, locale, mode, narrowTarget)).sort((a, b) => a.start - b.start);
|
|
6023
|
+
}
|
|
6024
|
+
function analyzeOverSpans(source, spans, planned, locale, mode, narrowTarget) {
|
|
6025
|
+
const normalized = normalizeSpans(spans);
|
|
6026
|
+
if (normalized.length === 0) return [];
|
|
6027
|
+
return runRulesRecording(
|
|
6028
|
+
concatenateSpans(source, normalized),
|
|
6029
|
+
planned,
|
|
6030
|
+
locale,
|
|
6031
|
+
mode,
|
|
6032
|
+
narrowTarget,
|
|
6033
|
+
originOfSpans(source, normalized),
|
|
6034
|
+
toCodePoints(source).length,
|
|
6035
|
+
(current, edits) => filterBoundaryEdits(current, edits, spanRangesOf(current))
|
|
6036
|
+
);
|
|
6037
|
+
}
|
|
6038
|
+
|
|
6039
|
+
// src/engine/protect.ts
|
|
6040
|
+
var LINE_TERMINATORS2 = /* @__PURE__ */ new Set([
|
|
6041
|
+
10,
|
|
6042
|
+
13,
|
|
6043
|
+
11,
|
|
6044
|
+
12,
|
|
6045
|
+
133,
|
|
6046
|
+
8232,
|
|
6047
|
+
8233
|
|
6048
|
+
]);
|
|
6049
|
+
function invalid(message) {
|
|
6050
|
+
throw new PolytypoError("POLYTYPO_INVALID_OPTION", message);
|
|
6051
|
+
}
|
|
6052
|
+
function resolveProtect(value, length) {
|
|
6053
|
+
if (value === void 0 || value === null) return [];
|
|
6054
|
+
if (!Array.isArray(value)) invalid("protect must be an array of { start, end } ranges.");
|
|
6055
|
+
const holes = [];
|
|
6056
|
+
let previousEnd = 0;
|
|
6057
|
+
for (const range of value) {
|
|
6058
|
+
if (typeof range !== "object" || range === null) invalid("protect entries must be objects.");
|
|
6059
|
+
const { start, end } = range;
|
|
6060
|
+
if (!Number.isInteger(start) || !Number.isInteger(end)) {
|
|
6061
|
+
invalid("protect start and end must be integers.");
|
|
6062
|
+
}
|
|
6063
|
+
const s = start;
|
|
6064
|
+
const e = end;
|
|
6065
|
+
if (s < 0 || e <= s) invalid(`protect range [${s}, ${e}) is empty or negative.`);
|
|
6066
|
+
if (s < previousEnd)
|
|
6067
|
+
invalid(`protect range [${s}, ${e}) overlaps or precedes the previous one.`);
|
|
6068
|
+
if (e > length)
|
|
6069
|
+
invalid(`protect range [${s}, ${e}) runs past the end of the input (${length}).`);
|
|
6070
|
+
const last = holes[holes.length - 1];
|
|
6071
|
+
if (last !== void 0 && last.end === s)
|
|
6072
|
+
holes[holes.length - 1] = { start: last.start, end: e };
|
|
6073
|
+
else holes.push({ start: s, end: e });
|
|
6074
|
+
previousEnd = e;
|
|
6075
|
+
}
|
|
6076
|
+
return holes;
|
|
6077
|
+
}
|
|
6078
|
+
function assertNoProtect(value, mode) {
|
|
6079
|
+
if (value === void 0 || value === null) return;
|
|
6080
|
+
if (Array.isArray(value) && value.length === 0) return;
|
|
6081
|
+
invalid(`protect is only available in text mode, not ${mode}.`);
|
|
6082
|
+
}
|
|
6083
|
+
function layout(cp, holes) {
|
|
6084
|
+
const array = [];
|
|
6085
|
+
const origin = [];
|
|
6086
|
+
let cursor = 0;
|
|
6087
|
+
for (const hole of holes) {
|
|
6088
|
+
for (let i = cursor; i < hole.start; i += 1) {
|
|
6089
|
+
array.push(cp[i]);
|
|
6090
|
+
origin.push(i);
|
|
6091
|
+
}
|
|
6092
|
+
let line = false;
|
|
6093
|
+
for (let i = hole.start; i < hole.end; i += 1) {
|
|
6094
|
+
if (LINE_TERMINATORS2.has(cp[i])) {
|
|
6095
|
+
line = true;
|
|
6096
|
+
break;
|
|
6097
|
+
}
|
|
6098
|
+
}
|
|
6099
|
+
array.push(line ? LINE_MARKER : MARKER);
|
|
6100
|
+
origin.push(NO_ORIGIN);
|
|
6101
|
+
cursor = hole.end;
|
|
6102
|
+
}
|
|
6103
|
+
for (let i = cursor; i < cp.length; i += 1) {
|
|
6104
|
+
array.push(cp[i]);
|
|
6105
|
+
origin.push(i);
|
|
6106
|
+
}
|
|
6107
|
+
return { array, origin };
|
|
6108
|
+
}
|
|
6109
|
+
function runProtectedMapped(input, holes, planned, locale, narrowTarget) {
|
|
6110
|
+
const cp = toCodePoints(input);
|
|
6111
|
+
const { array } = layout(cp, holes);
|
|
6112
|
+
const out = runRulesOverSpans(array, planned, locale, "text", narrowTarget);
|
|
6113
|
+
const result = [];
|
|
6114
|
+
const mapped = [];
|
|
6115
|
+
let hole = 0;
|
|
6116
|
+
for (const value of out) {
|
|
6117
|
+
if (isMarker(value)) {
|
|
6118
|
+
const h = holes[hole];
|
|
6119
|
+
const start = result.length;
|
|
6120
|
+
for (let i = h.start; i < h.end; i += 1) result.push(cp[i]);
|
|
6121
|
+
mapped.push({ start, end: result.length });
|
|
6122
|
+
hole += 1;
|
|
6123
|
+
continue;
|
|
6124
|
+
}
|
|
6125
|
+
result.push(value);
|
|
6126
|
+
}
|
|
6127
|
+
if (hole !== holes.length) {
|
|
6128
|
+
throw new PolytypoError(
|
|
6129
|
+
"POLYTYPO_RULE_CONTRACT",
|
|
6130
|
+
"boundary markers did not survive the pipeline."
|
|
6131
|
+
);
|
|
6132
|
+
}
|
|
6133
|
+
return { text: fromCodePoints(result), holes: mapped };
|
|
6134
|
+
}
|
|
6135
|
+
function runProtected(input, holes, planned, locale, narrowTarget) {
|
|
6136
|
+
return runProtectedMapped(input, holes, planned, locale, narrowTarget).text;
|
|
6137
|
+
}
|
|
6138
|
+
function analyzeProtected(input, holes, planned, locale, narrowTarget) {
|
|
6139
|
+
const cp = toCodePoints(input);
|
|
6140
|
+
const { array, origin } = layout(cp, holes);
|
|
6141
|
+
return runRulesRecording(
|
|
6142
|
+
array,
|
|
6143
|
+
planned,
|
|
6144
|
+
locale,
|
|
6145
|
+
"text",
|
|
6146
|
+
narrowTarget,
|
|
6147
|
+
origin,
|
|
6148
|
+
cp.length,
|
|
6149
|
+
(current, edits) => filterBoundaryEdits(current, edits, spanRangesOf(current))
|
|
6150
|
+
);
|
|
6151
|
+
}
|
|
6152
|
+
|
|
5834
6153
|
export {
|
|
5835
6154
|
PolytypoError,
|
|
5836
6155
|
toCodePoints,
|
|
5837
6156
|
fromCodePoints,
|
|
5838
6157
|
getLocaleData,
|
|
5839
6158
|
resolveNarrowTarget,
|
|
5840
|
-
MARKER,
|
|
5841
|
-
LINE_MARKER,
|
|
5842
|
-
isMarker,
|
|
5843
|
-
RULES,
|
|
5844
|
-
applyEdits,
|
|
5845
|
-
NO_ORIGIN,
|
|
5846
6159
|
planRules,
|
|
5847
6160
|
runRules,
|
|
5848
|
-
runRulesRecording
|
|
6161
|
+
runRulesRecording,
|
|
6162
|
+
runOverSpans,
|
|
6163
|
+
runOverUnits,
|
|
6164
|
+
analyzeOverUnits,
|
|
6165
|
+
analyzeOverSpans,
|
|
6166
|
+
resolveProtect,
|
|
6167
|
+
assertNoProtect,
|
|
6168
|
+
runProtected,
|
|
6169
|
+
analyzeProtected
|
|
5849
6170
|
};
|
|
5850
|
-
//# sourceMappingURL=chunk-
|
|
6171
|
+
//# sourceMappingURL=chunk-MF6PJO7O.js.map
|