polytypo 1.12.0 → 1.14.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-VQB2LXMW.cjs → chunk-322C3P5R.cjs} +22 -21
- package/dist/chunk-322C3P5R.cjs.map +1 -0
- package/dist/{chunk-3H6XONGO.js → chunk-HQCC44TB.js} +2 -2
- package/dist/{chunk-FRT6ATZR.cjs → chunk-LHB4LGNZ.cjs} +6 -6
- package/dist/{chunk-FRT6ATZR.cjs.map → chunk-LHB4LGNZ.cjs.map} +1 -1
- package/dist/chunk-LI552TEW.cjs +34 -0
- package/dist/chunk-LI552TEW.cjs.map +1 -0
- package/dist/{chunk-MDYQWNEL.js → chunk-MO5JWB5U.js} +2 -2
- package/dist/{chunk-IOW5V47B.js → chunk-MXNL2VZN.js} +8 -7
- package/dist/chunk-MXNL2VZN.js.map +1 -0
- package/dist/{chunk-QDF6EDLT.js → chunk-NVKII62N.js} +332 -9
- package/dist/chunk-NVKII62N.js.map +1 -0
- package/dist/{chunk-R2AZYV4E.cjs → chunk-OIYA4373.cjs} +326 -3
- package/dist/chunk-OIYA4373.cjs.map +1 -0
- package/dist/{chunk-PMCNXHAP.js → chunk-OVOWG5D6.js} +10 -9
- package/dist/{chunk-PMCNXHAP.js.map → chunk-OVOWG5D6.js.map} +1 -1
- package/dist/{chunk-BS2J3F7M.js → chunk-PTHKCPJ4.js} +2 -2
- package/dist/{chunk-S3EQ4IDS.js → chunk-PW54OWBC.js} +9 -2
- package/dist/chunk-PW54OWBC.js.map +1 -0
- package/dist/chunk-Q6WLYDP7.cjs +38 -0
- package/dist/chunk-Q6WLYDP7.cjs.map +1 -0
- package/dist/{chunk-5XVEBCNU.js → chunk-QQMGHBNF.js} +8 -7
- package/dist/chunk-QQMGHBNF.js.map +1 -0
- package/dist/chunk-ULWRPPEH.cjs +36 -0
- package/dist/chunk-ULWRPPEH.cjs.map +1 -0
- package/dist/{chunk-QZEJRXXP.cjs → chunk-UYAECAEW.cjs} +4 -4
- package/dist/{chunk-QZEJRXXP.cjs.map → chunk-UYAECAEW.cjs.map} +1 -1
- package/dist/{chunk-ZLR7P7VH.cjs → chunk-ZNCO7THZ.cjs} +3 -3
- package/dist/{chunk-ZLR7P7VH.cjs.map → chunk-ZNCO7THZ.cjs.map} +1 -1
- 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-3H6XONGO.js.map → chunk-HQCC44TB.js.map} +0 -0
- /package/dist/{chunk-MDYQWNEL.js.map → chunk-MO5JWB5U.js.map} +0 -0
- /package/dist/{chunk-BS2J3F7M.js.map → chunk-PTHKCPJ4.js.map} +0 -0
|
@@ -65,6 +65,7 @@ var KNOWN_LOCALES = [
|
|
|
65
65
|
"ro",
|
|
66
66
|
"ru",
|
|
67
67
|
"sk",
|
|
68
|
+
"sr",
|
|
68
69
|
"sv",
|
|
69
70
|
"tr",
|
|
70
71
|
"uk"
|
|
@@ -96,6 +97,7 @@ var LOCALES = {
|
|
|
96
97
|
ro: { locale: "ro", name: "Romanian", quotes: { primary: { open: "\u201E", close: "\u201D", innerSpace: "none" }, secondary: { open: "\xAB", close: "\xBB", innerSpace: "none" }, elisionIdioms: [], elisionClitics: { before: [], after: [] } }, dash: { parenthetical: "en-spaced", range: "none" }, ellipsis: { abbreviatedAfterTerminal: false }, hyphen: { prefixes: [], suffixes: [], compounds: [] }, nbsp: { beforePunctuation: [], narrowBeforePunctuation: [], afterShortWords: [], abbreviations: [], beforeUnits: ["km", "kg", "cm", "mm", "km/h", "\xB0C"], beforeNumber: ["art.", "nr."], beforeWord: [], afterSymbols: [], initialBinding: "single" } },
|
|
97
98
|
ru: { locale: "ru", name: "Russian", quotes: { primary: { open: "\xAB", close: "\xBB", innerSpace: "none" }, secondary: { open: "\u201E", close: "\u201C", innerSpace: "none" }, elisionIdioms: [], elisionClitics: { before: [], after: [] } }, dash: { parenthetical: "em-spaced", range: "em-tight" }, ellipsis: { abbreviatedAfterTerminal: true }, hyphen: { prefixes: ["\u043A\u043E\u0435-", "\u043A\u043E\u0439-"], suffixes: ["-\u0442\u043E", "-\u043B\u0438\u0431\u043E", "-\u043D\u0438\u0431\u0443\u0434\u044C", "-\u0442\u0430\u043A\u0438", "-\u043A\u0430"], compounds: ["\u0438\u0437-\u0437\u0430", "\u0438\u0437-\u043F\u043E\u0434"] }, nbsp: { beforePunctuation: [], narrowBeforePunctuation: [], afterShortWords: ["\u0430", "\u0432", "\u0438", "\u043A", "\u043E", "\u0441", "\u0443", "\u0432\u043E", "\u0434\u043E", "\u0437\u0430", "\u0438\u0437", "\u043A\u043E", "\u043D\u0430", "\u043E\u0431", "\u043E\u0442", "\u043F\u043E", "\u0441\u043E"], abbreviations: ["\u0438 \u0442. \u0434.", "\u0438 \u0442. \u043F.", "\u0442. \u0435.", "\u0438 \u0434\u0440."], beforeUnits: ["%", "\u2030", "\u20BD", "\xB0C", "\u043A\u043C", "\u0441\u043C", "\u043C\u043C", "\u043A\u0433", "\u0433.", "\u0433\u0433.", "\u0432.", "\u0432\u0432.", "\u0442\u044B\u0441.", "\u043C\u043B\u043D", "\u043C\u043B\u0440\u0434"], beforeNumber: [], beforeWord: ["\u0443\u043B.", "\u043F\u043B."], afterSymbols: ["\u2116", "\xA7"], initialBinding: "chain" } },
|
|
98
99
|
sk: { locale: "sk", name: "Slovak", quotes: { primary: { open: "\u201E", close: "\u201C", innerSpace: "none" }, secondary: { open: "\u201A", close: "\u2018", innerSpace: "none" }, elisionIdioms: [], elisionClitics: { before: [], after: [] } }, dash: { parenthetical: "en-spaced", range: "en-spaced" }, ellipsis: { abbreviatedAfterTerminal: false }, hyphen: { prefixes: [], suffixes: [], compounds: [] }, nbsp: { beforePunctuation: [], narrowBeforePunctuation: [], afterShortWords: [], abbreviations: ["t. j.", "a pod.", "a. s."], beforeUnits: ["%", "\u2030", "kg", "km", "km/s", "m/s", "min"], beforeNumber: ["\u010D.", "ods.", "s."], beforeWord: [], afterSymbols: ["\xA7"], initialBinding: "none" } },
|
|
100
|
+
sr: { locale: "sr", name: "Serbian", quotes: { primary: { open: "\u201E", close: "\u201D", innerSpace: "none" }, secondary: { open: "\u2019", close: "\u2019", innerSpace: "none" }, elisionIdioms: [], elisionClitics: { before: [], after: [] } }, dash: { parenthetical: "en-spaced", range: "en-tight" }, ellipsis: { abbreviatedAfterTerminal: false }, hyphen: { prefixes: [], suffixes: [], compounds: [] }, nbsp: { beforePunctuation: [], narrowBeforePunctuation: [], afterShortWords: [], abbreviations: [], beforeUnits: [], beforeNumber: [], beforeWord: [], afterSymbols: [], initialBinding: "none" } },
|
|
99
101
|
sv: { locale: "sv", name: "Swedish", quotes: { primary: { open: "\u201D", close: "\u201D", innerSpace: "none" }, secondary: { open: "\u2019", close: "\u2019", innerSpace: "none" }, elisionIdioms: [], elisionClitics: { before: [], after: [] } }, dash: { parenthetical: "en-spaced", range: "en-tight" }, ellipsis: { abbreviatedAfterTerminal: false }, hyphen: { prefixes: [], suffixes: [], compounds: [] }, nbsp: { beforePunctuation: [], narrowBeforePunctuation: [], afterShortWords: [], abbreviations: [], beforeUnits: ["%", "\u2030", "kr", "\u20AC", "kg", "g", "mg", "km", "m", "cm", "mm", "l", "dl", "cl", "ml", "kW", "kWh", "min", "sek", "tim", "h", "\xB0C"], beforeNumber: [], beforeWord: [], afterSymbols: ["\xA7"], initialBinding: "none" } },
|
|
100
102
|
tr: { locale: "tr", name: "Turkish", quotes: { primary: { open: "\u201C", close: "\u201D", innerSpace: "none" }, secondary: { open: "\u2018", close: "\u2019", innerSpace: "none" }, elisionIdioms: [], elisionClitics: { before: [], after: ["nin", "n\u0131n", "de", "da", "te", "ye", "yle", "n\u0131", "dan", "den", "lik", "nci", "\xFCm"] } }, dash: { parenthetical: "none", range: "none" }, ellipsis: { abbreviatedAfterTerminal: true }, hyphen: { prefixes: [], suffixes: [], compounds: [] }, nbsp: { beforePunctuation: [], narrowBeforePunctuation: [], afterShortWords: [], abbreviations: ["Kur. B\u015Fk.", "N\xF6. Sb."], beforeUnits: ["mm", "cm", "km", "kg", "mg", "hl", "m\xB2", "cm\xB2", "\xB0C", "ton"], beforeNumber: [], beforeWord: [], afterSymbols: [], initialBinding: "none" } },
|
|
101
103
|
uk: { locale: "uk", name: "Ukrainian", quotes: { primary: { open: "\xAB", close: "\xBB", innerSpace: "none" }, secondary: { open: "\u201C", close: "\u201D", innerSpace: "none" }, elisionIdioms: [], elisionClitics: { before: [], after: [] } }, dash: { parenthetical: "em-spaced", range: "em-tight" }, ellipsis: { abbreviatedAfterTerminal: true }, hyphen: { prefixes: ["\u0431\u0443\u0434\u044C-", "\u043A\u0430\u0437\u043D\u0430-", "\u0445\u0442\u043E\u0437\u043D\u0430-", "\u0431\u043E\u0437\u043D\u0430-"], suffixes: ["-\u0431\u043E", "-\u043D\u043E", "-\u043E\u0442", "-\u0442\u043E", "-\u0442\u0430\u043A\u0438", "-\u0431\u0443\u0434\u044C", "-\u043D\u0435\u0431\u0443\u0434\u044C"], compounds: ["\u0432\u0438\u0434-\u0432\u043E", "\u0433\u0440-\u043D", "\u0456\u043D-\u0442", "\u0440-\u043D", "\u0443\u043D-\u0442", "\u0444-\u043A\u0430", "\u0442-\u0432\u043E", "\u0437-\u0437\u0430", "\u0456\u0437-\u0437\u0430", "\u0437-\u043D\u0430\u0434", "\u0437-\u043F\u0435\u0440\u0435\u0434", "\u0437-\u043F\u0456\u0434", "\u0456\u0437-\u043F\u0456\u0434", "\u0437-\u043F\u043E\u0437\u0430", "\u0437-\u043F\u043E\u043C\u0456\u0436", "\u0437-\u043F\u043E\u043D\u0430\u0434", "\u0437-\u043F\u043E\u043F\u0456\u0434", "\u0437-\u043F\u043E\u0441\u0435\u0440\u0435\u0434", "\u0437-\u043F\u0440\u043E\u043C\u0456\u0436"] }, nbsp: { beforePunctuation: [], narrowBeforePunctuation: [], afterShortWords: [], abbreviations: ["\u0456 \u0442. \u0434.", "\u0456 \u0442. \u0456\u043D.", "\u0442\u0430 \u0456\u043D.", "\u043A\u0443\u0431. \u0441\u043C"], beforeUnits: ["%", "\u0433\u0430", "\u0433\u043E\u0434", "\u0434\u043C", "\u043A\u0411", "\u043A\u0412\u0442", "\u043A\u0433", "\u043A\u043C", "\u043C\u043C", "\u0441\u043C", "\u0445\u0432", "\u0412\u0442", "\u043A\u043C/\u0433\u043E\u0434", "\u043C/\u0441", "\u043C\u043B\u043D", "\u043C\u043B\u0440\u0434", "\u0442\u0440\u043B\u043D", "\u0433\u0440\u043D", "\u0440."], beforeNumber: [], beforeWord: ["\u0430\u043A\u0430\u0434.", "\u0434\u043E\u0446.", "\u043F\u0440\u043E\u0444."], afterSymbols: [], initialBinding: "chain" } }
|
|
@@ -5778,11 +5780,18 @@ function applyEditsToOrigin(origin, edits) {
|
|
|
5778
5780
|
for (let i = cursor; i < origin.length; i += 1) out.push(origin[i]);
|
|
5779
5781
|
return out;
|
|
5780
5782
|
}
|
|
5783
|
+
function endOf(origin, edit, inputLength) {
|
|
5784
|
+
for (let i = edit.end - 1; i >= edit.start; i -= 1) {
|
|
5785
|
+
const value = origin[i];
|
|
5786
|
+
if (value !== NO_ORIGIN) return value + 1;
|
|
5787
|
+
}
|
|
5788
|
+
return originAt(origin, edit.end, inputLength);
|
|
5789
|
+
}
|
|
5781
5790
|
function recordChanges(cp, edits, origin, inputLength, ruleId) {
|
|
5782
5791
|
return edits.map((edit) => ({
|
|
5783
5792
|
ruleId,
|
|
5784
5793
|
start: originAt(origin, edit.start, inputLength),
|
|
5785
|
-
end:
|
|
5794
|
+
end: endOf(origin, edit, inputLength),
|
|
5786
5795
|
before: fromCodePoints(cp.slice(edit.start, edit.end)),
|
|
5787
5796
|
after: fromCodePoints(edit.replacement)
|
|
5788
5797
|
}));
|
|
@@ -5831,20 +5840,334 @@ function runRulesRecording(cp, planned, locale, mode, narrowTarget, origin, inpu
|
|
|
5831
5840
|
return changes;
|
|
5832
5841
|
}
|
|
5833
5842
|
|
|
5843
|
+
// src/modes/spans.ts
|
|
5844
|
+
var SPACE5 = 32;
|
|
5845
|
+
var LINE_TERMINATORS = /* @__PURE__ */ new Set([
|
|
5846
|
+
10,
|
|
5847
|
+
13,
|
|
5848
|
+
11,
|
|
5849
|
+
12,
|
|
5850
|
+
133,
|
|
5851
|
+
8232,
|
|
5852
|
+
8233
|
|
5853
|
+
]);
|
|
5854
|
+
function gapIsLineBoundary(source, from, to) {
|
|
5855
|
+
for (let i = from; i < to; i += 1) {
|
|
5856
|
+
if (LINE_TERMINATORS.has(source.charCodeAt(i))) return true;
|
|
5857
|
+
}
|
|
5858
|
+
return false;
|
|
5859
|
+
}
|
|
5860
|
+
function normalizeSpans(spans) {
|
|
5861
|
+
const sorted = spans.filter((s) => s.end > s.start).sort((a, b) => a.start - b.start);
|
|
5862
|
+
const out = [];
|
|
5863
|
+
for (const span of sorted) {
|
|
5864
|
+
const last = out[out.length - 1];
|
|
5865
|
+
if (last === void 0) {
|
|
5866
|
+
out.push(span);
|
|
5867
|
+
continue;
|
|
5868
|
+
}
|
|
5869
|
+
if (span.start < last.end) {
|
|
5870
|
+
throw new PolytypoError(
|
|
5871
|
+
"POLYTYPO_RULE_CONTRACT",
|
|
5872
|
+
`mode extractor produced overlapping spans (${last.start}, ${last.end}) and (${span.start}, ${span.end})`
|
|
5873
|
+
);
|
|
5874
|
+
}
|
|
5875
|
+
if (span.start === last.end) {
|
|
5876
|
+
out[out.length - 1] = { start: last.start, end: span.end };
|
|
5877
|
+
continue;
|
|
5878
|
+
}
|
|
5879
|
+
out.push(span);
|
|
5880
|
+
}
|
|
5881
|
+
return out;
|
|
5882
|
+
}
|
|
5883
|
+
function concatenateSpans(source, spans) {
|
|
5884
|
+
const cp = [];
|
|
5885
|
+
let previous;
|
|
5886
|
+
for (const span of spans) {
|
|
5887
|
+
if (previous !== void 0) {
|
|
5888
|
+
cp.push(gapIsLineBoundary(source, previous.end, span.start) ? LINE_MARKER : MARKER);
|
|
5889
|
+
}
|
|
5890
|
+
for (const value of toCodePoints(source.slice(span.start, span.end))) cp.push(value);
|
|
5891
|
+
previous = span;
|
|
5892
|
+
}
|
|
5893
|
+
return cp;
|
|
5894
|
+
}
|
|
5895
|
+
function spanRangesOf(cp) {
|
|
5896
|
+
const ranges = [];
|
|
5897
|
+
let first = 0;
|
|
5898
|
+
for (let i = 0; i < cp.length; i += 1) {
|
|
5899
|
+
if (isMarker(cp[i])) {
|
|
5900
|
+
ranges.push({ first, last: i - 1 });
|
|
5901
|
+
first = i + 1;
|
|
5902
|
+
}
|
|
5903
|
+
}
|
|
5904
|
+
ranges.push({ first, last: cp.length - 1 });
|
|
5905
|
+
return ranges;
|
|
5906
|
+
}
|
|
5907
|
+
function spanContaining(ranges, p) {
|
|
5908
|
+
for (const range of ranges) {
|
|
5909
|
+
if (p >= range.first && p <= range.last + 1) return range;
|
|
5910
|
+
}
|
|
5911
|
+
return void 0;
|
|
5912
|
+
}
|
|
5913
|
+
function filterBoundaryEdits(cp, edits, ranges) {
|
|
5914
|
+
const out = [];
|
|
5915
|
+
for (const edit of edits) {
|
|
5916
|
+
let containsMarker = false;
|
|
5917
|
+
for (let i = edit.start; i < edit.end; i += 1) {
|
|
5918
|
+
if (isMarker(cp[i])) {
|
|
5919
|
+
containsMarker = true;
|
|
5920
|
+
break;
|
|
5921
|
+
}
|
|
5922
|
+
}
|
|
5923
|
+
if (containsMarker) continue;
|
|
5924
|
+
const p = edit.start;
|
|
5925
|
+
const q = edit.end - 1;
|
|
5926
|
+
const d = edit.end - edit.start;
|
|
5927
|
+
const r = edit.replacement.length;
|
|
5928
|
+
const span = spanContaining(ranges, p);
|
|
5929
|
+
if (span !== void 0 && (p === span.first || q === span.last)) {
|
|
5930
|
+
if (r > d) continue;
|
|
5931
|
+
const first = edit.replacement[0];
|
|
5932
|
+
const last = edit.replacement[r - 1];
|
|
5933
|
+
if (r > 0 && p === span.first && first === SPACE5 && cp[p] !== SPACE5) continue;
|
|
5934
|
+
if (r > 0 && q === span.last && last === SPACE5 && cp[q] !== SPACE5) continue;
|
|
5935
|
+
}
|
|
5936
|
+
out.push(edit);
|
|
5937
|
+
}
|
|
5938
|
+
return out;
|
|
5939
|
+
}
|
|
5940
|
+
function splitOnMarker(cp, expected) {
|
|
5941
|
+
const pieces = [[]];
|
|
5942
|
+
for (const value of cp) {
|
|
5943
|
+
if (isMarker(value)) {
|
|
5944
|
+
pieces.push([]);
|
|
5945
|
+
continue;
|
|
5946
|
+
}
|
|
5947
|
+
pieces[pieces.length - 1].push(value);
|
|
5948
|
+
}
|
|
5949
|
+
if (pieces.length !== expected) {
|
|
5950
|
+
throw new PolytypoError(
|
|
5951
|
+
"POLYTYPO_RULE_CONTRACT",
|
|
5952
|
+
`boundary markers did not survive the pipeline: expected ${expected} spans, found ${pieces.length}`
|
|
5953
|
+
);
|
|
5954
|
+
}
|
|
5955
|
+
return pieces;
|
|
5956
|
+
}
|
|
5957
|
+
function originOfSpans(source, spans) {
|
|
5958
|
+
const codePointIndexOf = new Array(source.length + 1);
|
|
5959
|
+
let cpIndex = 0;
|
|
5960
|
+
for (let i = 0; i < source.length; ) {
|
|
5961
|
+
codePointIndexOf[i] = cpIndex;
|
|
5962
|
+
const code = source.codePointAt(i);
|
|
5963
|
+
const width = code > 65535 ? 2 : 1;
|
|
5964
|
+
if (width === 2) codePointIndexOf[i + 1] = cpIndex;
|
|
5965
|
+
i += width;
|
|
5966
|
+
cpIndex += 1;
|
|
5967
|
+
}
|
|
5968
|
+
codePointIndexOf[source.length] = cpIndex;
|
|
5969
|
+
const origin = [];
|
|
5970
|
+
let previous;
|
|
5971
|
+
for (const span of spans) {
|
|
5972
|
+
if (previous !== void 0) origin.push(NO_ORIGIN);
|
|
5973
|
+
const base = codePointIndexOf[span.start];
|
|
5974
|
+
const length = toCodePoints(source.slice(span.start, span.end)).length;
|
|
5975
|
+
for (let k = 0; k < length; k += 1) origin.push(base + k);
|
|
5976
|
+
previous = span;
|
|
5977
|
+
}
|
|
5978
|
+
return origin;
|
|
5979
|
+
}
|
|
5980
|
+
|
|
5981
|
+
// src/engine/span-runner.ts
|
|
5982
|
+
function runRulesOverSpans(cp, planned, locale, mode, narrowTarget) {
|
|
5983
|
+
let current = cp;
|
|
5984
|
+
for (const id of planned) {
|
|
5985
|
+
const rule = RULES[id];
|
|
5986
|
+
if (rule === void 0) continue;
|
|
5987
|
+
const edits = rule.apply({ cp: current, locale, mode, narrowTarget });
|
|
5988
|
+
current = applyEdits(current, filterBoundaryEdits(current, edits, spanRangesOf(current)), id);
|
|
5989
|
+
}
|
|
5990
|
+
return current;
|
|
5991
|
+
}
|
|
5992
|
+
function replacementsOfUnit(source, spans, planned, locale, mode, narrowTarget) {
|
|
5993
|
+
const normalized = normalizeSpans(spans);
|
|
5994
|
+
if (normalized.length === 0) return [];
|
|
5995
|
+
const transformed = runRulesOverSpans(
|
|
5996
|
+
concatenateSpans(source, normalized),
|
|
5997
|
+
planned,
|
|
5998
|
+
locale,
|
|
5999
|
+
mode,
|
|
6000
|
+
narrowTarget
|
|
6001
|
+
);
|
|
6002
|
+
const pieces = splitOnMarker(transformed, normalized.length);
|
|
6003
|
+
return normalized.map((span, i) => ({ span, text: fromCodePoints(pieces[i]) }));
|
|
6004
|
+
}
|
|
6005
|
+
function emit2(source, replacements) {
|
|
6006
|
+
let out = "";
|
|
6007
|
+
let cursor = 0;
|
|
6008
|
+
for (const { span, text } of replacements) {
|
|
6009
|
+
const original = source.slice(span.start, span.end);
|
|
6010
|
+
out += source.slice(cursor, span.start);
|
|
6011
|
+
out += text === original ? original : text;
|
|
6012
|
+
cursor = span.end;
|
|
6013
|
+
}
|
|
6014
|
+
return out + source.slice(cursor);
|
|
6015
|
+
}
|
|
6016
|
+
function runOverSpans(source, spans, planned, locale, mode, narrowTarget) {
|
|
6017
|
+
return emit2(source, replacementsOfUnit(source, spans, planned, locale, mode, narrowTarget));
|
|
6018
|
+
}
|
|
6019
|
+
function runOverUnits(source, units, planned, locale, mode, narrowTarget) {
|
|
6020
|
+
const replacements = units.flatMap((spans) => replacementsOfUnit(source, spans, planned, locale, mode, narrowTarget)).sort((a, b) => a.span.start - b.span.start);
|
|
6021
|
+
return emit2(source, replacements);
|
|
6022
|
+
}
|
|
6023
|
+
function analyzeOverUnits(source, units, planned, locale, mode, narrowTarget) {
|
|
6024
|
+
return units.flatMap((spans) => analyzeOverSpans(source, spans, planned, locale, mode, narrowTarget)).sort((a, b) => a.start - b.start);
|
|
6025
|
+
}
|
|
6026
|
+
function analyzeOverSpans(source, spans, planned, locale, mode, narrowTarget) {
|
|
6027
|
+
const normalized = normalizeSpans(spans);
|
|
6028
|
+
if (normalized.length === 0) return [];
|
|
6029
|
+
return runRulesRecording(
|
|
6030
|
+
concatenateSpans(source, normalized),
|
|
6031
|
+
planned,
|
|
6032
|
+
locale,
|
|
6033
|
+
mode,
|
|
6034
|
+
narrowTarget,
|
|
6035
|
+
originOfSpans(source, normalized),
|
|
6036
|
+
toCodePoints(source).length,
|
|
6037
|
+
(current, edits) => filterBoundaryEdits(current, edits, spanRangesOf(current))
|
|
6038
|
+
);
|
|
6039
|
+
}
|
|
6040
|
+
|
|
6041
|
+
// src/engine/protect.ts
|
|
6042
|
+
var LINE_TERMINATORS2 = /* @__PURE__ */ new Set([
|
|
6043
|
+
10,
|
|
6044
|
+
13,
|
|
6045
|
+
11,
|
|
6046
|
+
12,
|
|
6047
|
+
133,
|
|
6048
|
+
8232,
|
|
6049
|
+
8233
|
|
6050
|
+
]);
|
|
6051
|
+
function invalid(message) {
|
|
6052
|
+
throw new PolytypoError("POLYTYPO_INVALID_OPTION", message);
|
|
6053
|
+
}
|
|
6054
|
+
function resolveProtect(value, length) {
|
|
6055
|
+
if (value === void 0 || value === null) return [];
|
|
6056
|
+
if (!Array.isArray(value)) invalid("protect must be an array of { start, end } ranges.");
|
|
6057
|
+
const holes = [];
|
|
6058
|
+
let previousEnd = 0;
|
|
6059
|
+
for (const range of value) {
|
|
6060
|
+
if (typeof range !== "object" || range === null) invalid("protect entries must be objects.");
|
|
6061
|
+
const { start, end } = range;
|
|
6062
|
+
if (!Number.isInteger(start) || !Number.isInteger(end)) {
|
|
6063
|
+
invalid("protect start and end must be integers.");
|
|
6064
|
+
}
|
|
6065
|
+
const s = start;
|
|
6066
|
+
const e = end;
|
|
6067
|
+
if (s < 0 || e <= s) invalid(`protect range [${s}, ${e}) is empty or negative.`);
|
|
6068
|
+
if (s < previousEnd)
|
|
6069
|
+
invalid(`protect range [${s}, ${e}) overlaps or precedes the previous one.`);
|
|
6070
|
+
if (e > length)
|
|
6071
|
+
invalid(`protect range [${s}, ${e}) runs past the end of the input (${length}).`);
|
|
6072
|
+
const last = holes[holes.length - 1];
|
|
6073
|
+
if (last !== void 0 && last.end === s)
|
|
6074
|
+
holes[holes.length - 1] = { start: last.start, end: e };
|
|
6075
|
+
else holes.push({ start: s, end: e });
|
|
6076
|
+
previousEnd = e;
|
|
6077
|
+
}
|
|
6078
|
+
return holes;
|
|
6079
|
+
}
|
|
6080
|
+
function assertNoProtect(value, mode) {
|
|
6081
|
+
if (value === void 0 || value === null) return;
|
|
6082
|
+
if (Array.isArray(value) && value.length === 0) return;
|
|
6083
|
+
invalid(`protect is only available in text mode, not ${mode}.`);
|
|
6084
|
+
}
|
|
6085
|
+
function layout(cp, holes) {
|
|
6086
|
+
const array = [];
|
|
6087
|
+
const origin = [];
|
|
6088
|
+
let cursor = 0;
|
|
6089
|
+
for (const hole of holes) {
|
|
6090
|
+
for (let i = cursor; i < hole.start; i += 1) {
|
|
6091
|
+
array.push(cp[i]);
|
|
6092
|
+
origin.push(i);
|
|
6093
|
+
}
|
|
6094
|
+
let line = false;
|
|
6095
|
+
for (let i = hole.start; i < hole.end; i += 1) {
|
|
6096
|
+
if (LINE_TERMINATORS2.has(cp[i])) {
|
|
6097
|
+
line = true;
|
|
6098
|
+
break;
|
|
6099
|
+
}
|
|
6100
|
+
}
|
|
6101
|
+
array.push(line ? LINE_MARKER : MARKER);
|
|
6102
|
+
origin.push(NO_ORIGIN);
|
|
6103
|
+
cursor = hole.end;
|
|
6104
|
+
}
|
|
6105
|
+
for (let i = cursor; i < cp.length; i += 1) {
|
|
6106
|
+
array.push(cp[i]);
|
|
6107
|
+
origin.push(i);
|
|
6108
|
+
}
|
|
6109
|
+
return { array, origin };
|
|
6110
|
+
}
|
|
6111
|
+
function runProtectedMapped(input, holes, planned, locale, narrowTarget) {
|
|
6112
|
+
const cp = toCodePoints(input);
|
|
6113
|
+
const { array } = layout(cp, holes);
|
|
6114
|
+
const out = runRulesOverSpans(array, planned, locale, "text", narrowTarget);
|
|
6115
|
+
const result = [];
|
|
6116
|
+
const mapped = [];
|
|
6117
|
+
let hole = 0;
|
|
6118
|
+
for (const value of out) {
|
|
6119
|
+
if (isMarker(value)) {
|
|
6120
|
+
const h = holes[hole];
|
|
6121
|
+
const start = result.length;
|
|
6122
|
+
for (let i = h.start; i < h.end; i += 1) result.push(cp[i]);
|
|
6123
|
+
mapped.push({ start, end: result.length });
|
|
6124
|
+
hole += 1;
|
|
6125
|
+
continue;
|
|
6126
|
+
}
|
|
6127
|
+
result.push(value);
|
|
6128
|
+
}
|
|
6129
|
+
if (hole !== holes.length) {
|
|
6130
|
+
throw new PolytypoError(
|
|
6131
|
+
"POLYTYPO_RULE_CONTRACT",
|
|
6132
|
+
"boundary markers did not survive the pipeline."
|
|
6133
|
+
);
|
|
6134
|
+
}
|
|
6135
|
+
return { text: fromCodePoints(result), holes: mapped };
|
|
6136
|
+
}
|
|
6137
|
+
function runProtected(input, holes, planned, locale, narrowTarget) {
|
|
6138
|
+
return runProtectedMapped(input, holes, planned, locale, narrowTarget).text;
|
|
6139
|
+
}
|
|
6140
|
+
function analyzeProtected(input, holes, planned, locale, narrowTarget) {
|
|
6141
|
+
const cp = toCodePoints(input);
|
|
6142
|
+
const { array, origin } = layout(cp, holes);
|
|
6143
|
+
return runRulesRecording(
|
|
6144
|
+
array,
|
|
6145
|
+
planned,
|
|
6146
|
+
locale,
|
|
6147
|
+
"text",
|
|
6148
|
+
narrowTarget,
|
|
6149
|
+
origin,
|
|
6150
|
+
cp.length,
|
|
6151
|
+
(current, edits) => filterBoundaryEdits(current, edits, spanRangesOf(current))
|
|
6152
|
+
);
|
|
6153
|
+
}
|
|
6154
|
+
|
|
5834
6155
|
export {
|
|
5835
6156
|
PolytypoError,
|
|
5836
6157
|
toCodePoints,
|
|
5837
6158
|
fromCodePoints,
|
|
5838
6159
|
getLocaleData,
|
|
5839
6160
|
resolveNarrowTarget,
|
|
5840
|
-
MARKER,
|
|
5841
|
-
LINE_MARKER,
|
|
5842
|
-
isMarker,
|
|
5843
|
-
RULES,
|
|
5844
|
-
applyEdits,
|
|
5845
|
-
NO_ORIGIN,
|
|
5846
6161
|
planRules,
|
|
5847
6162
|
runRules,
|
|
5848
|
-
runRulesRecording
|
|
6163
|
+
runRulesRecording,
|
|
6164
|
+
runOverSpans,
|
|
6165
|
+
runOverUnits,
|
|
6166
|
+
analyzeOverUnits,
|
|
6167
|
+
analyzeOverSpans,
|
|
6168
|
+
resolveProtect,
|
|
6169
|
+
assertNoProtect,
|
|
6170
|
+
runProtected,
|
|
6171
|
+
analyzeProtected
|
|
5849
6172
|
};
|
|
5850
|
-
//# sourceMappingURL=chunk-
|
|
6173
|
+
//# sourceMappingURL=chunk-NVKII62N.js.map
|