rapier-markdown-kit 1.1.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/LICENSE +40 -0
- package/README.md +102 -0
- package/dist/agent/vendor/pretext/LICENSE +21 -0
- package/dist/agent/vendor/pretext/NOTICE +15 -0
- package/dist/agent/vendor/pretext/SOURCE.json +85 -0
- package/dist/agent/vendor/pretext/analysis.js +1234 -0
- package/dist/agent/vendor/pretext/bidi.js +151 -0
- package/dist/agent/vendor/pretext/generated/bidi-data.js +3831 -0
- package/dist/agent/vendor/pretext/layout.js +308 -0
- package/dist/agent/vendor/pretext/line-break.js +636 -0
- package/dist/agent/vendor/pretext/line-text.js +44 -0
- package/dist/agent/vendor/pretext/measurement.js +189 -0
- package/dist/agent/vendor/pretext/package.json +3 -0
- package/dist/agent/vendor/pretext/rich-inline.js +291 -0
- package/dist/agent/will.mjs +167 -0
- package/dist/kit/assets.mjs +3 -0
- package/dist/kit/conformance/01-inline.expected.json +82 -0
- package/dist/kit/conformance/01-inline.md +10 -0
- package/dist/kit/conformance/02-width-x-align.expected.json +83 -0
- package/dist/kit/conformance/02-width-x-align.md +12 -0
- package/dist/kit/conformance/03-wrap-around-silhouette.expected.json +177 -0
- package/dist/kit/conformance/03-wrap-around-silhouette.md +12 -0
- package/dist/kit/conformance/04-wrap-box.expected.json +173 -0
- package/dist/kit/conformance/04-wrap-box.md +12 -0
- package/dist/kit/conformance/05-behind.expected.json +122 -0
- package/dist/kit/conformance/05-behind.md +12 -0
- package/dist/kit/conformance/06-front.expected.json +122 -0
- package/dist/kit/conformance/06-front.md +12 -0
- package/dist/kit/conformance/07-rotate-raster.expected.json +179 -0
- package/dist/kit/conformance/07-rotate-raster.md +12 -0
- package/dist/kit/conformance/08-drawing-rotation.expected.json +188 -0
- package/dist/kit/conformance/08-drawing-rotation.md +12 -0
- package/dist/kit/conformance/09-drawing-ring-interior.expected.json +229 -0
- package/dist/kit/conformance/09-drawing-ring-interior.md +12 -0
- package/dist/kit/conformance/10-both-sides.expected.json +221 -0
- package/dist/kit/conformance/10-both-sides.md +10 -0
- package/dist/kit/conformance/11-neighbour-skips-image.expected.json +160 -0
- package/dist/kit/conformance/11-neighbour-skips-image.md +13 -0
- package/dist/kit/conformance/12-heading-barrier.expected.json +164 -0
- package/dist/kit/conformance/12-heading-barrier.md +12 -0
- package/dist/kit/conformance/13-rtl-text.expected.json +179 -0
- package/dist/kit/conformance/13-rtl-text.md +8 -0
- package/dist/kit/conformance/README.md +99 -0
- package/dist/kit/conformance/measurer.mjs +0 -0
- package/dist/kit/conformance/run.mjs +123 -0
- package/dist/kit/index.mjs +6 -0
- package/dist/kit/layout.mjs +2 -0
- package/dist/kit/marks.mjs +2 -0
- package/dist/kit/model.mjs +3 -0
- package/dist/kit/will.mjs +2 -0
- package/dist/layout/model.mjs +364 -0
- package/dist/spec/md-assets.mjs +323 -0
- package/dist/spec/md-layout.mjs +117 -0
- package/dist/spec/md-marks.mjs +78 -0
- package/package.json +33 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/*! Pretext 0.0.9 | MIT | Copyright (c) 2026 Pretext contributors */
|
|
2
|
+
import { latin1BidiTypes, nonLatin1BidiRanges } from './generated/bidi-data.js';
|
|
3
|
+
function classifyCodePoint(codePoint) {
|
|
4
|
+
if (codePoint <= 0x00FF) return latin1BidiTypes[codePoint];
|
|
5
|
+
let lo = 0;
|
|
6
|
+
let hi = nonLatin1BidiRanges.length - 1;
|
|
7
|
+
while(lo <= hi){
|
|
8
|
+
const mid = lo + hi >> 1;
|
|
9
|
+
const range = nonLatin1BidiRanges[mid];
|
|
10
|
+
if (codePoint < range[0]) {
|
|
11
|
+
hi = mid - 1;
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
if (codePoint > range[1]) {
|
|
15
|
+
lo = mid + 1;
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
return range[2];
|
|
19
|
+
}
|
|
20
|
+
return 'L';
|
|
21
|
+
}
|
|
22
|
+
function computeBidiLevels(str) {
|
|
23
|
+
const len = str.length;
|
|
24
|
+
if (len === 0) return null;
|
|
25
|
+
const types = new Array(len);
|
|
26
|
+
let paragraphHasBidi = false;
|
|
27
|
+
let paragraphStart = 0;
|
|
28
|
+
let levels = null;
|
|
29
|
+
for(let i = 0; i < len;){
|
|
30
|
+
const first = str.charCodeAt(i);
|
|
31
|
+
let codePoint = first;
|
|
32
|
+
let codeUnitLength = 1;
|
|
33
|
+
if (first >= 0xD800 && first <= 0xDBFF && i + 1 < len) {
|
|
34
|
+
const second = str.charCodeAt(i + 1);
|
|
35
|
+
if (second >= 0xDC00 && second <= 0xDFFF) {
|
|
36
|
+
codePoint = (first - 0xD800 << 10) + (second - 0xDC00) + 0x10000;
|
|
37
|
+
codeUnitLength = 2;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const t = classifyCodePoint(codePoint);
|
|
41
|
+
if (t === 'R' || t === 'AL' || t === 'AN') paragraphHasBidi = true;
|
|
42
|
+
for(let j = 0; j < codeUnitLength; j++){
|
|
43
|
+
types[i + j] = t;
|
|
44
|
+
}
|
|
45
|
+
if (t === 'B') {
|
|
46
|
+
if (paragraphHasBidi) {
|
|
47
|
+
levels ??= new Int8Array(len);
|
|
48
|
+
levels[i] = resolveParagraphLevels(types, levels, paragraphStart, i);
|
|
49
|
+
}
|
|
50
|
+
paragraphStart = i + codeUnitLength;
|
|
51
|
+
paragraphHasBidi = false;
|
|
52
|
+
}
|
|
53
|
+
i += codeUnitLength;
|
|
54
|
+
}
|
|
55
|
+
if (paragraphHasBidi) {
|
|
56
|
+
levels ??= new Int8Array(len);
|
|
57
|
+
resolveParagraphLevels(types, levels, paragraphStart, len);
|
|
58
|
+
}
|
|
59
|
+
return levels;
|
|
60
|
+
}
|
|
61
|
+
function resolveParagraphLevels(types, levels, start, end) {
|
|
62
|
+
let startLevel = 0;
|
|
63
|
+
for(let i = start; i < end; i++){
|
|
64
|
+
const t = types[i];
|
|
65
|
+
if (t === 'L') {
|
|
66
|
+
startLevel = 0;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
if (t === 'R' || t === 'AL') {
|
|
70
|
+
startLevel = 1;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const e = startLevel & 1 ? 'R' : 'L';
|
|
75
|
+
const sor = e;
|
|
76
|
+
let lastType = sor;
|
|
77
|
+
for(let i = start; i < end; i++){
|
|
78
|
+
if (types[i] === 'NSM') types[i] = lastType;
|
|
79
|
+
else lastType = types[i];
|
|
80
|
+
}
|
|
81
|
+
lastType = sor;
|
|
82
|
+
for(let i = start; i < end; i++){
|
|
83
|
+
const t = types[i];
|
|
84
|
+
if (t === 'EN') types[i] = lastType === 'AL' ? 'AN' : 'EN';
|
|
85
|
+
else if (t === 'R' || t === 'L' || t === 'AL') lastType = t;
|
|
86
|
+
}
|
|
87
|
+
for(let i = start; i < end; i++){
|
|
88
|
+
if (types[i] === 'AL') types[i] = 'R';
|
|
89
|
+
}
|
|
90
|
+
for(let i = start + 1; i < end - 1; i++){
|
|
91
|
+
if (types[i] === 'ES' && types[i - 1] === 'EN' && types[i + 1] === 'EN') {
|
|
92
|
+
types[i] = 'EN';
|
|
93
|
+
}
|
|
94
|
+
if (types[i] === 'CS' && (types[i - 1] === 'EN' || types[i - 1] === 'AN') && types[i + 1] === types[i - 1]) {
|
|
95
|
+
types[i] = types[i - 1];
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
for(let i = start; i < end; i++){
|
|
99
|
+
if (types[i] !== 'EN') continue;
|
|
100
|
+
let j;
|
|
101
|
+
for(j = i - 1; j >= start && types[j] === 'ET'; j--)types[j] = 'EN';
|
|
102
|
+
for(j = i + 1; j < end && types[j] === 'ET'; j++)types[j] = 'EN';
|
|
103
|
+
}
|
|
104
|
+
for(let i = start; i < end; i++){
|
|
105
|
+
const t = types[i];
|
|
106
|
+
if (t === 'WS' || t === 'ES' || t === 'ET' || t === 'CS') types[i] = 'ON';
|
|
107
|
+
}
|
|
108
|
+
lastType = sor;
|
|
109
|
+
for(let i = start; i < end; i++){
|
|
110
|
+
const t = types[i];
|
|
111
|
+
if (t === 'EN') types[i] = lastType === 'L' ? 'L' : 'EN';
|
|
112
|
+
else if (t === 'R' || t === 'L') lastType = t;
|
|
113
|
+
}
|
|
114
|
+
for(let i = start; i < end; i++){
|
|
115
|
+
if (types[i] !== 'ON') continue;
|
|
116
|
+
let runEnd = i + 1;
|
|
117
|
+
while(runEnd < end && types[runEnd] === 'ON')runEnd++;
|
|
118
|
+
const before = i > start ? types[i - 1] : sor;
|
|
119
|
+
const after = runEnd < end ? types[runEnd] : sor;
|
|
120
|
+
const bDir = before !== 'L' ? 'R' : 'L';
|
|
121
|
+
const aDir = after !== 'L' ? 'R' : 'L';
|
|
122
|
+
if (bDir === aDir) {
|
|
123
|
+
for(let j = i; j < runEnd; j++)types[j] = bDir;
|
|
124
|
+
}
|
|
125
|
+
i = runEnd - 1;
|
|
126
|
+
}
|
|
127
|
+
for(let i = start; i < end; i++){
|
|
128
|
+
if (types[i] === 'ON') types[i] = e;
|
|
129
|
+
}
|
|
130
|
+
for(let i = start; i < end; i++){
|
|
131
|
+
const t = types[i];
|
|
132
|
+
let level = startLevel;
|
|
133
|
+
if ((startLevel & 1) === 0) {
|
|
134
|
+
if (t === 'R') level++;
|
|
135
|
+
else if (t === 'AN' || t === 'EN') level += 2;
|
|
136
|
+
} else if (t === 'L' || t === 'AN' || t === 'EN') {
|
|
137
|
+
level++;
|
|
138
|
+
}
|
|
139
|
+
levels[i] = level;
|
|
140
|
+
}
|
|
141
|
+
return startLevel;
|
|
142
|
+
}
|
|
143
|
+
export function computeSegmentLevels(normalized, segStarts) {
|
|
144
|
+
const bidiLevels = computeBidiLevels(normalized);
|
|
145
|
+
if (bidiLevels === null) return null;
|
|
146
|
+
const segLevels = new Int8Array(segStarts.length);
|
|
147
|
+
for(let i = 0; i < segStarts.length; i++){
|
|
148
|
+
segLevels[i] = bidiLevels[segStarts[i]];
|
|
149
|
+
}
|
|
150
|
+
return segLevels;
|
|
151
|
+
}
|