@orkestrel/guide 0.0.32 → 0.0.34
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/dist/src/core/index.cjs +131 -5
- package/dist/src/core/index.cjs.map +1 -1
- package/dist/src/core/index.d.cts +84 -4
- package/dist/src/core/index.d.ts +84 -4
- package/dist/src/core/index.js +127 -6
- package/dist/src/core/index.js.map +1 -1
- package/package.json +9 -9
package/dist/src/core/index.cjs
CHANGED
|
@@ -111,6 +111,53 @@ var EXTERNAL_SCHEMES = Object.freeze([
|
|
|
111
111
|
"mailto:",
|
|
112
112
|
"tel:"
|
|
113
113
|
]);
|
|
114
|
+
/**
|
|
115
|
+
* Matches one character that occupies two terminal columns: an emoji presentation character other
|
|
116
|
+
* than a regional indicator, or a character of the East Asian wide and fullwidth classes.
|
|
117
|
+
*
|
|
118
|
+
* @remarks
|
|
119
|
+
* A regional indicator is outside this class because the formatter counts each as one column,
|
|
120
|
+
* which makes a flag pair two. The blocks are the formatter's Unicode tables, so an unassigned
|
|
121
|
+
* code point, a character the formatter's Unicode version classes differently from a later one,
|
|
122
|
+
* and a ligating cluster such as Arabic lam-alef, which the formatter counts one column, are the
|
|
123
|
+
* measure's known divergences. A character in {@link ZERO_WIDTH} counts none
|
|
124
|
+
* whatever this class holds, because the width measure tests that class first.
|
|
125
|
+
*/
|
|
126
|
+
var WIDE_CHARACTER = new RegExp([
|
|
127
|
+
String.raw`[[\p{Emoji_Presentation}--\p{Regional_Indicator}]`,
|
|
128
|
+
String.raw`\u{1100}-\u{115F}\u{2329}\u{232A}\u{2630}-\u{2637}\u{268A}-\u{268F}`,
|
|
129
|
+
String.raw`\u{2E80}-\u{2E99}\u{2E9B}-\u{2EF3}\u{2F00}-\u{2FD5}\u{2FF0}-\u{303E}`,
|
|
130
|
+
String.raw`\u{3041}-\u{3096}\u{3099}-\u{30FF}\u{3105}-\u{312F}\u{3131}-\u{318E}`,
|
|
131
|
+
String.raw`\u{3190}-\u{31E5}\u{31EF}-\u{321E}\u{3220}-\u{3247}\u{3250}-\u{A48C}`,
|
|
132
|
+
String.raw`\u{A490}-\u{A4C6}\u{A960}-\u{A97C}\u{AC00}-\u{D7A3}\u{F900}-\u{FAFF}`,
|
|
133
|
+
String.raw`\u{FE10}-\u{FE19}\u{FE30}-\u{FE52}\u{FE54}-\u{FE66}\u{FE68}-\u{FE6B}`,
|
|
134
|
+
String.raw`\u{FF01}-\u{FF60}\u{FFE0}-\u{FFE6}`,
|
|
135
|
+
String.raw`\u{16FE0}-\u{16FE3}\u{16FF0}-\u{16FF6}\u{17000}-\u{187FF}`,
|
|
136
|
+
String.raw`\u{18800}-\u{18CD5}\u{18CFF}-\u{18D1E}\u{18D80}-\u{18DF2}`,
|
|
137
|
+
String.raw`\u{1AFF0}-\u{1AFF3}\u{1AFF5}-\u{1AFFB}\u{1AFFD}\u{1AFFE}`,
|
|
138
|
+
String.raw`\u{1B000}-\u{1B122}\u{1B132}\u{1B150}-\u{1B152}\u{1B155}`,
|
|
139
|
+
String.raw`\u{1B164}-\u{1B167}\u{1B170}-\u{1B2FB}\u{1D300}-\u{1D356}`,
|
|
140
|
+
String.raw`\u{1D360}-\u{1D376}\u{1F200}\u{1F202}\u{1F210}-\u{1F219}`,
|
|
141
|
+
String.raw`\u{1F21B}-\u{1F22E}\u{1F230}\u{1F231}\u{1F237}\u{1F23B}`,
|
|
142
|
+
String.raw`\u{1F240}-\u{1F248}\u{1F250}\u{1F251}\u{1F260}-\u{1F265}`,
|
|
143
|
+
String.raw`\u{20000}-\u{2FFFD}\u{30000}-\u{3FFFD}]`
|
|
144
|
+
].join(""), "v");
|
|
145
|
+
/**
|
|
146
|
+
* Matches a character that occupies no terminal column: a nonspacing, enclosing, or extending
|
|
147
|
+
* mark, a format character such as a zero width space, a control character, and the Hangul
|
|
148
|
+
* medial and final jamo, less the format and mark characters the formatter counts one column.
|
|
149
|
+
*/
|
|
150
|
+
var ZERO_WIDTH = new RegExp([
|
|
151
|
+
String.raw`[[\p{Grapheme_Extend}\p{Cf}\p{Cc}\u{1160}-\u{11FF}\u{D7B0}-\u{D7C6}\u{D7CB}-\u{D7FB}`,
|
|
152
|
+
String.raw`\u{3164}\u{FFA0}]--[\u{600}-\u{604}\u{6DD}\u{2D7F}\u{FFF9}-\u{FFFB}`,
|
|
153
|
+
String.raw`\u{110BD}\u{110CD}\u{13430}-\u{1343F}]]`
|
|
154
|
+
].join(""), "v");
|
|
155
|
+
/**
|
|
156
|
+
* Matches a grapheme cluster the formatter counts two columns whole: a pictograph sequence joined
|
|
157
|
+
* by a zero width joiner, an emoji followed by a skin-tone modifier, an emoji followed by the emoji
|
|
158
|
+
* variation selector, or a keycap that carries that selector.
|
|
159
|
+
*/
|
|
160
|
+
var EMOJI_SEQUENCE = /\p{Extended_Pictographic}\u{200D}\p{Extended_Pictographic}|\p{Emoji_Modifier_Base}\p{Emoji_Modifier}|\p{Emoji}\u{FE0F}|[0-9#*]\u{FE0F}\u{20E3}/u;
|
|
114
161
|
// src/core/errors.ts
|
|
115
162
|
/** Carries a coded refusal of a guide, a manifest entry, or a module compile. */
|
|
116
163
|
var GuideError = class extends Error {
|
|
@@ -2982,6 +3029,79 @@ function buildTable(table, row, column, cell) {
|
|
|
2982
3029
|
};
|
|
2983
3030
|
}
|
|
2984
3031
|
/**
|
|
3032
|
+
* Measures how many terminal columns `text` occupies the way the checkout's formatter pads a
|
|
3033
|
+
* Markdown table cell: each grapheme cluster counts two columns when it is wide — a character
|
|
3034
|
+
* of the East Asian wide and fullwidth blocks, an emoji, or a sequence of them — and otherwise
|
|
3035
|
+
* one column per character that has a width, with marks, format characters, and control
|
|
3036
|
+
* characters counting none.
|
|
3037
|
+
*
|
|
3038
|
+
* @remarks
|
|
3039
|
+
* The count is of the cell's source text, so an escaped pipe counts two columns, as it does in the
|
|
3040
|
+
* file. An ambiguous-width character such as an arrow counts one column, the width the formatter
|
|
3041
|
+
* gives it.
|
|
3042
|
+
*
|
|
3043
|
+
* @param text - The cell's source text
|
|
3044
|
+
* @returns The columns `text` occupies
|
|
3045
|
+
*
|
|
3046
|
+
* @example
|
|
3047
|
+
* ```ts
|
|
3048
|
+
* computeCellWidth('`walk`') // 6
|
|
3049
|
+
* ```
|
|
3050
|
+
*/
|
|
3051
|
+
function computeCellWidth(text) {
|
|
3052
|
+
return Iterator.from(new Intl.Segmenter().segment(text)).reduce((total, { segment }) => EMOJI_SEQUENCE.test(segment) ? total + 2 : Iterator.from(segment).reduce((sum, character) => ZERO_WIDTH.test(character) ? sum : sum + (WIDE_CHARACTER.test(character) ? 2 : 1), total), 0);
|
|
3053
|
+
}
|
|
3054
|
+
/**
|
|
3055
|
+
* Renders `table` as the bytes the checkout's formatter writes for it: every column padded to
|
|
3056
|
+
* its widest cell, at least three columns wide, each cell justified to its column's alignment,
|
|
3057
|
+
* and a delimiter row of dashes the column's width carrying the alignment's colons.
|
|
3058
|
+
*
|
|
3059
|
+
* @remarks
|
|
3060
|
+
* `renderMarkdown` writes every cell one-space padded, so a rewritten table that passed straight
|
|
3061
|
+
* through it would fail the formatter's check and need a formatter pass. This render pads from
|
|
3062
|
+
* that output instead of re-deriving it, so the cell text is `renderMarkdown`'s and only the
|
|
3063
|
+
* padding is this function's: a cell is measured by {@link computeCellWidth}, a left or unaligned
|
|
3064
|
+
* cell pads on the right, a right-aligned cell on the left, and a centred cell on both sides with
|
|
3065
|
+
* the odd column on the right.
|
|
3066
|
+
*
|
|
3067
|
+
* @param table - The table to render
|
|
3068
|
+
* @returns The table's markdown source, with no trailing newline
|
|
3069
|
+
*
|
|
3070
|
+
* @example
|
|
3071
|
+
* ```ts
|
|
3072
|
+
* renderMarkdownTable({
|
|
3073
|
+
* element: 'table',
|
|
3074
|
+
* header: [[{ element: 'text', value: 'Name' }], [{ element: 'text', value: 'Summary' }]],
|
|
3075
|
+
* rows: [[[{ element: 'codeSpan', value: 'walk' }], [{ element: 'text', value: 'Walks.' }]]],
|
|
3076
|
+
* align: [null, null],
|
|
3077
|
+
* })
|
|
3078
|
+
* // '| Name | Summary |\n| ------ | ------- |\n| `walk` | Walks. |'
|
|
3079
|
+
* ```
|
|
3080
|
+
*/
|
|
3081
|
+
function renderMarkdownTable(table) {
|
|
3082
|
+
const [header = "", , ...body] = (0, _orkestrel_markdown.renderMarkdown)(table).split("\n");
|
|
3083
|
+
const rows = [header, ...body].map((line) => line.slice(2, -2).split(" | "));
|
|
3084
|
+
const widths = table.header.map((_, column) => Math.max(3, ...rows.map((cells) => computeCellWidth(cells[column] ?? ""))));
|
|
3085
|
+
const lines = rows.map((cells) => `| ${widths.map((width, column) => {
|
|
3086
|
+
const cell = cells[column] ?? "";
|
|
3087
|
+
const spare = width - computeCellWidth(cell);
|
|
3088
|
+
const align = table.align[column];
|
|
3089
|
+
const before = align === "right" ? spare : align === "center" ? Math.floor(spare / 2) : 0;
|
|
3090
|
+
return `${" ".repeat(before)}${cell}${" ".repeat(spare - before)}`;
|
|
3091
|
+
}).join(" | ")} |`);
|
|
3092
|
+
const delimiter = widths.map((width, column) => {
|
|
3093
|
+
const align = table.align[column];
|
|
3094
|
+
const left = align === "left" || align === "center" ? ":" : "-";
|
|
3095
|
+
const right = align === "right" || align === "center" ? ":" : "-";
|
|
3096
|
+
return `${left}${"-".repeat(width - 2)}${right}`;
|
|
3097
|
+
});
|
|
3098
|
+
return [
|
|
3099
|
+
lines[0],
|
|
3100
|
+
`| ${delimiter.join(" | ")} |`,
|
|
3101
|
+
...lines.slice(1)
|
|
3102
|
+
].join("\n");
|
|
3103
|
+
}
|
|
3104
|
+
/**
|
|
2985
3105
|
* Builds the fenced code block one `@example` block renders as — its code inside a fence
|
|
2986
3106
|
* carrying its language, and an untagged fence when the block names none.
|
|
2987
3107
|
*
|
|
@@ -3179,9 +3299,10 @@ function renderExample(example) {
|
|
|
3179
3299
|
* a rewrite would re-pad the whole table for no change; that identity reads both cells through
|
|
3180
3300
|
* {@link extractCellText} and {@link normalizeSummary}, so a caller passing text the compared form
|
|
3181
3301
|
* still moves is a fixed point on the second run rather than a row rewritten forever. The
|
|
3182
|
-
* rewritten table renders
|
|
3183
|
-
* formatter
|
|
3184
|
-
*
|
|
3302
|
+
* rewritten table renders through {@link renderMarkdownTable}, so every row of it is padded as the
|
|
3303
|
+
* checkout's formatter pads a table whatever padding it carried and the formatter's check passes
|
|
3304
|
+
* on the result, and a code span renders with every `|` written `\|` and a longer backtick fence
|
|
3305
|
+
* when its text holds a backtick.
|
|
3185
3306
|
*
|
|
3186
3307
|
* @param guide - The guide's markdown source
|
|
3187
3308
|
* @param key - The compared key naming the row
|
|
@@ -3192,7 +3313,7 @@ function renderExample(example) {
|
|
|
3192
3313
|
* @example
|
|
3193
3314
|
* ```ts
|
|
3194
3315
|
* replaceCell('## Surface\n\n| Name | Kind | Signature | Summary |\n| --- | --- | --- | --- |\n| `walk` | function | `() => void` | Walks. |', 'function walk', SUMMARY, buildCell('Walks a tree.'))
|
|
3195
|
-
* // '## Surface\n\n| Name
|
|
3316
|
+
* // '## Surface\n\n| Name | Kind | Signature | Summary |\n| ------ | -------- | ------------ | ------------- |\n| `walk` | function | `() => void` | Walks a tree. |'
|
|
3196
3317
|
* ```
|
|
3197
3318
|
*/
|
|
3198
3319
|
function replaceCell(guide, key, column, cell) {
|
|
@@ -3217,7 +3338,7 @@ function replaceCell(guide, key, column, cell) {
|
|
|
3217
3338
|
if (normalizeSummary(extractCellText(table.rows[index]?.[position] ?? [])) === normalizeSummary(extractCellText(cell))) return guide;
|
|
3218
3339
|
const span = markdown.span(table);
|
|
3219
3340
|
if (span === void 0) return void 0;
|
|
3220
|
-
return spliceSpan(guide, span, (
|
|
3341
|
+
return spliceSpan(guide, span, renderMarkdownTable(buildTable(table, index, position, cell)));
|
|
3221
3342
|
}
|
|
3222
3343
|
/**
|
|
3223
3344
|
* Replaces one titled fence in a guide's text and returns the whole guide back. The first fence
|
|
@@ -4644,6 +4765,7 @@ function createManifestEntryContract() {
|
|
|
4644
4765
|
return (0, _orkestrel_contract.createContract)(manifestEntryShape);
|
|
4645
4766
|
}
|
|
4646
4767
|
exports.DRIFT_CATEGORIES = DRIFT_CATEGORIES;
|
|
4768
|
+
exports.EMOJI_SEQUENCE = EMOJI_SEQUENCE;
|
|
4647
4769
|
exports.EXPORT_KEYWORDS = EXPORT_KEYWORDS;
|
|
4648
4770
|
exports.EXTERNAL_SCHEMES = EXTERNAL_SCHEMES;
|
|
4649
4771
|
exports.GUIDE_CODES = GUIDE_CODES;
|
|
@@ -4662,7 +4784,9 @@ exports.SURFACE_HEADER = SURFACE_HEADER;
|
|
|
4662
4784
|
exports.Source = Source;
|
|
4663
4785
|
exports.SourceManager = SourceManager;
|
|
4664
4786
|
exports.TESTS = TESTS;
|
|
4787
|
+
exports.WIDE_CHARACTER = WIDE_CHARACTER;
|
|
4665
4788
|
exports.WRAP_WIDTH = WRAP_WIDTH;
|
|
4789
|
+
exports.ZERO_WIDTH = ZERO_WIDTH;
|
|
4666
4790
|
exports.buildCell = buildCell;
|
|
4667
4791
|
exports.buildComment = buildComment;
|
|
4668
4792
|
exports.buildFence = buildFence;
|
|
@@ -4675,6 +4799,7 @@ exports.collectKeys = collectKeys;
|
|
|
4675
4799
|
exports.collectSummaries = collectSummaries;
|
|
4676
4800
|
exports.collectTitles = collectTitles;
|
|
4677
4801
|
exports.compareMembership = compareMembership;
|
|
4802
|
+
exports.computeCellWidth = computeCellWidth;
|
|
4678
4803
|
exports.computeDepths = computeDepths;
|
|
4679
4804
|
exports.computeDrift = computeDrift;
|
|
4680
4805
|
exports.computeModuleKey = computeModuleKey;
|
|
@@ -4750,6 +4875,7 @@ exports.normalizeIdentifier = normalizeIdentifier;
|
|
|
4750
4875
|
exports.normalizeSummary = normalizeSummary;
|
|
4751
4876
|
exports.parseManifest = parseManifest;
|
|
4752
4877
|
exports.renderExample = renderExample;
|
|
4878
|
+
exports.renderMarkdownTable = renderMarkdownTable;
|
|
4753
4879
|
exports.renderMember = renderMember;
|
|
4754
4880
|
exports.renderMethods = renderMethods;
|
|
4755
4881
|
exports.renderSurface = renderSurface;
|